ReceiptController.php 302 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. public $AGENCY="日常相关费用";
  12. public $TRAVEL="差旅相关费用";
  13. public $TRAIN="培训班费用";
  14. public $OTHER="其他";
  15. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  19. private function showCache($path){
  20. if(file_exists($path)){
  21. echo "<!DOCTYPE html>";
  22. include $path;die;
  23. }
  24. }
  25. private function cacheFile($path){
  26. $content = ob_get_contents();
  27. $fp = fopen($path, "w");
  28. fwrite($fp, $content);
  29. fclose($fp);
  30. }
  31. private function getExeCount(){
  32. Doo::loadModel('receipt');
  33. $receipt=new receipt();
  34. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  35. return count($receiptList);
  36. }
  37. private function getReceiptCount(){
  38. $status=2;
  39. $year=date('Y');
  40. Doo::loadModel('receipt');
  41. $receipt=new receipt();
  42. $dateCondition=" and Year(date) =".$year;
  43. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  44. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  45. return count($receiptList);
  46. }
  47. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  48. $collectHtml="";$sumPrice=0.00;
  49. for ($i=1;$i<=12;$i++){
  50. $falg=true;
  51. foreach ($receiptCollectList as $key=>$value){
  52. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  53. $sumPrice+=$value['price'];
  54. if ($classType=="b"){
  55. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  56. }else{
  57. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  58. }
  59. }
  60. }
  61. if ($falg)
  62. $collectHtml.='<td class="taR">-</td>';
  63. }
  64. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  65. return $collectHtml;
  66. }
  67. function __construct() {
  68. if(isset($_COOKIE["staff"])){
  69. if(!empty($_COOKIE["staff"])){
  70. Doo::loadModel ( 'staff' );
  71. Doo::loadModel('verify');
  72. $verify=new verify();
  73. $staff = new staff ();
  74. Doo::loadModel("execute");
  75. $execute=new execute();
  76. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  77. $list=array();
  78. //判断角色的审批权限
  79. foreach ($verifyList as $key=>$value){
  80. $ver=json_decode($value['staff']);
  81. foreach ($ver as $k=>$v){
  82. if ($v[1]=='ROLE'){
  83. $roleList=json_decode($v[3]);
  84. foreach ($roleList as $t=>$g){
  85. $gList=explode("_", $g);
  86. array_push($list, $gList[0]);
  87. //print_r($list);
  88. }
  89. }else
  90. array_push($list, $v[0]);
  91. }
  92. }
  93. //判断执行人的审批权限
  94. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  95. $list2=array();
  96. foreach ($executeList as $key=>$value){
  97. $ver=json_decode($value['staff']);
  98. foreach ($ver as $k=>$v){
  99. array_push($list2, $v[0]);
  100. }
  101. }
  102. $eidList=file_get_contents("protected/config/execute/execute.ini");
  103. $eidList=array_filter(explode(",", $eidList));
  104. $this->executeId= array_merge($list2,$eidList);
  105. $this->verifyId=$list;
  106. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  107. self::$NEW= $this->getReceiptCount();
  108. self::$NEW2= $this->getExeCount();
  109. return "/";
  110. }
  111. }
  112. Doo::loadCore ( 'uri/DooUriRouter' );
  113. $router = new DooUriRouter ();
  114. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  115. if($routeRs['1']!="login"){
  116. header ( 'Content-Type:text/html;charset=utf-8' );
  117. @header ( "Location: /login" );
  118. }
  119. }
  120. function saeaBorad(){
  121. Doo::loadModel('receipt');
  122. Doo::loadModel('verify');
  123. $verify=new verify();
  124. $receipt=new receipt();
  125. Doo::loadModel('L_category');
  126. $lCategory=new L_category();
  127. Doo::loadModel("role");
  128. $role=new role();
  129. Doo::loadModel("receiptLog");
  130. $receiptLog=new receiptLog();
  131. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  132. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  133. foreach ($receiptDetail as $key=>$value){
  134. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  135. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  136. $v=json_decode($veList['staff']);
  137. array_push($v[0], $veList['description']);
  138. foreach ($v as $n=>$m){
  139. if ($m['1']=='ROLE'){
  140. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  141. $v[$n][1]=$roleInfo['name'];
  142. }
  143. }
  144. $receiptDetail[$key]['staff']=$v;
  145. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  146. $receiptDetail[$key]['category']=$category['title'];
  147. }
  148. //print_r($receiptLogList);
  149. $data['receiptLogList']=$receiptLogList;
  150. $data['receiptDetail']=$receiptDetail;
  151. $data['memu']="receipt";
  152. $data['staff']=$this->staff;
  153. $data['receiptMemu']='saeaBorad';
  154. $data['verifyId']=$this->verifyId;
  155. $data['executeId']=$this->executeId;
  156. $this->render ( "/admin/saeaBorad", $data );
  157. }
  158. function remitAdd(){
  159. Doo::loadModel('accountItem');
  160. Doo::loadModel('verify');
  161. Doo::loadModel('receipt');
  162. Doo::loadModel('L_category');
  163. $lCategory=new L_category();
  164. $receipt=new receipt();
  165. $verify=new verify();
  166. $accountItem=new accountItem();
  167. Doo::loadModel("role");
  168. $role=new role();
  169. $acItem=$accountItem->find(array('asArray'=>true));
  170. $veList=$verify->find(array('asArray'=>true));
  171. foreach ($veList as $key=>$value){
  172. $v=json_decode($value['staff']);
  173. $list=array();
  174. foreach ($v as $n=>$m){
  175. if ($m['1']=='ROLE'){
  176. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  177. $v[$n][1]=$roleInfo['name'];
  178. array_push($list, $roleInfo['name']);
  179. }else{
  180. array_push($list, $v[$n][1]);
  181. }
  182. }
  183. $veList[$key]['staff']=implode('>', $list);
  184. }
  185. $data['category']=$lCategory->find(array('asArray'=>true));
  186. $data['veList']=$veList;
  187. $data['acItem']=$acItem;
  188. $data['memu']="receipt";
  189. $data['staff']=$this->staff;
  190. $data['receiptMemu']='saeaBorad';
  191. $data['verifyId']=$this->verifyId;
  192. $data['executeId']=$this->executeId;
  193. $this->render ( "/admin/remitAdd", $data );
  194. }
  195. function remitAddDo(){
  196. $agency=$this->get_args('agency');
  197. $travel=$this->get_args('travel');
  198. $train=$this->get_args('train');
  199. $other=$this->get_args('other');
  200. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  201. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  202. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  203. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  204. //print_r($agency);die;
  205. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  206. Doo::loadModel('receipt');
  207. Doo::loadModel('receiptDetail');
  208. Doo::loadModel('accountItem');
  209. $accountItem=new accountItem();
  210. $receipt=new receipt();
  211. Doo::loadModel('enclosur');
  212. Doo::loadModel('execute');
  213. $execute=new execute();
  214. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  215. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  216. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  217. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  218. $ag=$tr=$ta=$ot=0;
  219. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  220. foreach ($aItem as $key=>$value){
  221. if ($value['category']==$this->AGENCY){
  222. if (isset($agency[$ag])){
  223. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  224. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  225. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  226. }
  227. }
  228. $ag++;
  229. }
  230. }
  231. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  232. //报销单
  233. $receipt->accountItem=json_encode($accountJson);
  234. $receipt->staff=$this->staff[0]['sid'];
  235. $receipt->sum=number_format($sum, 2, '.', '');
  236. $receipt->date=date("Y-m-d");
  237. $receipt->cid=$cid;
  238. $receipt->status=5;
  239. $receipt->Rtype=2;
  240. //修改审批流程加入角色
  241. $receipt->verify=$verify;
  242. $receipt->executeCopy=$executeDetail['staff'];
  243. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  244. $receipt->explanation=$explanation;
  245. $rid=$receipt->insert();
  246. //附件
  247. if (!empty($enclosurName)){
  248. $enclosurArray=explode('-', $enclosurName);
  249. foreach ($enclosurArray as $value){
  250. $enclosur=new enclosur();
  251. $enclosur->name=$value;
  252. $enclosur->rid=$rid;
  253. $enclosur->insert();
  254. }
  255. //print_r($enclosurArray);die;
  256. }
  257. //报销详情
  258. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  259. $receiptDetail=new receiptDetail();
  260. $receiptDetail->staff=$this->staff[0]['sid'];
  261. $receiptDetail->item=$value['name'];
  262. $receiptDetail->itemCategory=$this->AGENCY;
  263. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  264. $receiptDetail->date=date("Y-m-d");
  265. $receiptDetail->cid=$cid;
  266. $receiptDetail->rid=$rid;
  267. $receiptDetail->status=4;
  268. $receiptDetail->insert();
  269. }
  270. }
  271. return "/saeaBorad";
  272. }
  273. function remitEdit(){
  274. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  275. //echo $rid;
  276. Doo::loadModel('accountItem');
  277. Doo::loadModel('verify');
  278. Doo::loadModel('receipt');
  279. $receipt=new receipt();
  280. $verify=new verify();
  281. $accountItem=new accountItem();
  282. Doo::loadModel('L_category');
  283. $lCategory=new L_category();
  284. Doo::loadModel("role");
  285. $role=new role();
  286. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  287. if(empty($receiptDetail))
  288. return "/saeaCreate";
  289. $acItem=$accountItem->find(array('asArray'=>true));
  290. $veList=$verify->find(array('asArray'=>true));
  291. foreach ($veList as $key=>$value){
  292. $v=json_decode($value['staff']);
  293. $list=array();
  294. foreach ($v as $n=>$m){
  295. if ($m['1']=='ROLE'){
  296. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  297. $v[$n][1]=$roleInfo['name'];
  298. array_push($list, $roleInfo['name']);
  299. }else{
  300. array_push($list, $v[$n][1]);
  301. }
  302. }
  303. $veList[$key]['staff']=implode('>', $list);
  304. }
  305. //配置编辑信息
  306. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  307. foreach ($acItem as $key=>$value){
  308. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  309. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  310. $acItem[$key]['price']=$v['price'];
  311. }
  312. }
  313. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  314. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  315. $acItem[$key]['price']=$v['price'];
  316. }
  317. }
  318. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  319. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  320. $acItem[$key]['price']=$v['price'];
  321. }
  322. }
  323. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  324. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  325. $acItem[$key]['price']=$v['price'];
  326. }
  327. }
  328. }
  329. $data['category']=$lCategory->find(array('asArray'=>true));
  330. $data['cSum']=$accountItemList['cSum'];
  331. $data['sum']=$receiptDetail['sum'];
  332. $data['receiptDetail']=$receiptDetail;
  333. $data['veList']=$veList;
  334. $data['acItem']=$acItem;
  335. $data['memu']="receipt";
  336. $data['staff']=$this->staff;
  337. $data['receiptMemu']='saeaBorad';
  338. $data['verify']=$receiptDetail['verify'];
  339. $data['verifyId']=$this->verifyId;
  340. $data['executeId']=$this->executeId;
  341. $data['rid']=$rid;
  342. $this->render ( "/admin/remitEdit", $data );
  343. }
  344. function remitEdiDo(){
  345. $agency=$this->get_args('agency');
  346. $travel=$this->get_args('travel');
  347. $train=$this->get_args('train');
  348. $other=$this->get_args('other');
  349. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  350. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  351. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  352. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  353. if(!empty($verify)&&!empty($explanation)){
  354. Doo::loadModel('receipt');
  355. Doo::loadModel('receiptDetail');
  356. Doo::loadModel('accountItem');
  357. $accountItem=new accountItem();
  358. $receipt=new receipt();
  359. Doo::loadModel('execute');
  360. $execute=new execute();
  361. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  362. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  363. if(empty($receiptDetail))
  364. return "/saeaBorad";
  365. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  366. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  367. $ag=$tr=$ta=$ot=0;
  368. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  369. foreach ($aItem as $key=>$value){
  370. if ($value['category']==$this->AGENCY){
  371. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  372. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  373. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  374. }
  375. $ag++;
  376. }
  377. }
  378. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  379. //报销单
  380. $rid=$receipt->rid=$receiptDetail['rid'];
  381. $receipt->accountItem=json_encode($accountJson);
  382. $receipt->staff=$this->staff[0]['sid'];
  383. $receipt->sum=number_format($sum, 2, '.', '');
  384. $receipt->date=date("Y-m-d");
  385. $receipt->cid=$cid;
  386. if ($receiptDetail['Rtype']==1)
  387. $receipt->status=7;
  388. else
  389. $receipt->status=5;
  390. $receipt->verify=$verify;
  391. $receipt->executeCopy=$executeDetail['staff'];
  392. $receipt->explanation=$explanation;
  393. $receipt->update();
  394. $receiptDetail=new receiptDetail();
  395. $receiptDetail->delete(array('where'=>'rid='.$rid));
  396. //报销详情
  397. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  398. $receiptDetail=new receiptDetail();
  399. $receiptDetail->staff=$this->staff[0]['sid'];
  400. $receiptDetail->item=$value['name'];
  401. $receiptDetail->itemCategory=$this->AGENCY;
  402. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  403. $receiptDetail->date=date("Y-m-d");
  404. $receiptDetail->cid=$cid;
  405. $receiptDetail->rid=$rid;
  406. $receiptDetail->status=4;
  407. $receiptDetail->insert();
  408. }
  409. //return "/referReceipt/".$rid;
  410. }
  411. return "/saeaBorad";
  412. }
  413. function remitApproval(){
  414. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  415. $status=isset($this->params['status'])?$this->params['status']:'';
  416. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  417. $month=$this->get_args('month')?$this->get_args('month'):"";
  418. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  419. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  420. if (empty($status))
  421. $status=$this->get_args('status')?$this->get_args('status'):2;
  422. $vidList=array();
  423. $button=0;
  424. Doo::loadModel('verify');
  425. Doo::loadModel('receipt');
  426. Doo::loadModel('staff');
  427. $staff=new staff();
  428. $receipt=new receipt();
  429. $verify=new verify();
  430. Doo::loadModel('L_category');
  431. $Lcategory=new L_category();
  432. Doo::loadModel('enclosur');
  433. $enclosur=new enclosur();
  434. //user verify ID
  435. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  436. foreach ($verifyDetail as $key=>$value){
  437. array_push($vidList, $value['vid']);
  438. }
  439. $vid=implode(",", $vidList);
  440. if(empty($verifyDetail))
  441. $vid=0;
  442. $categoryList=$Lcategory->find(array('asArray'=>true));
  443. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  444. $ap="";
  445. if($status==4){
  446. $ap=4;$status=2;
  447. }
  448. //get Receipt By verifyID status 2
  449. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  450. $Locate=0;$roleId=0;
  451. if($ap==4)
  452. $status=4;
  453. foreach ($receiptList as $key=>$value){
  454. $receiptList[$key]['Locate']=$Locate;$Locate++;
  455. $receiptList[$key]['reviseDetail']=array();
  456. if (!empty($value['reviseDetail']))
  457. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  458. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  459. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  460. $receiptList[$key]['category']=$categoryDetil['title'];
  461. //检测编辑状态
  462. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  463. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  464. $verifyStaff=json_decode($value['verifyStaff'],true);
  465. Doo::loadModel('role');
  466. $role=new role();
  467. //print_r($verifyList);
  468. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  469. foreach ($verifyList as $k=>$v){
  470. //init verifyStaff
  471. if ($v[1]=='ROLE'){
  472. if (!empty($verifyStaff)){
  473. $endStaffArray=end($verifyStaff);
  474. if ($v[0]==$endStaffArray['nextStaff']){
  475. $roleId=$v[0];
  476. }
  477. }
  478. $roleVerify=json_decode($v[3],true);
  479. $roleKey=$k;$roleArray=array();
  480. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  481. foreach ($roleVerify as $o=>$p){
  482. $staffID=explode ('_',$p);
  483. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  484. //print_r($staffID);
  485. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  486. array_push($roleArray, $exp);
  487. }
  488. $roleArrayCopy[$v[0]]=$roleArray;
  489. //$verifyList[$k]['roleArray']=$roleArray;
  490. }
  491. //print_r($roleArray);
  492. $verifyList[$k]['date']="";
  493. $verifyList[$k]['opinion']="";
  494. $verifyList[$k]['status']="";
  495. if (empty($verifyStaff)){
  496. $verifyList[$k]['date']="";
  497. $verifyList[$k]['opinion']="";
  498. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  499. $verifyList[$k]['status']=4;
  500. $button=4;$flag=false;
  501. }
  502. }else{
  503. foreach ($verifyStaff as $m=>$u){
  504. if ($v[0]==$m){
  505. $verifyList[$k]['date']=$u['date'];
  506. $verifyList[$k]['opinion']=$u['opinion'];
  507. $verifyList[$k]['status']=$u['status'];
  508. $flag=false;
  509. break;
  510. }
  511. }
  512. $endStaffArray=end($verifyStaff);
  513. if (isset($endStaffArray['ROLE'])){
  514. }else{
  515. $endKey=key($verifyStaff);
  516. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  517. $button=4;
  518. $verifyList[$k]['status']=4;
  519. }
  520. }
  521. }
  522. }
  523. $rolename['name']='';
  524. if (!empty($roleId)){
  525. Doo::loadModel('role');
  526. $role=new role();
  527. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  528. }
  529. if (!empty($verifyStaff))
  530. $endStaffArray=end($verifyStaff);
  531. $KOP=false;
  532. foreach ($roleArrayCopy as $P=>$A){
  533. foreach ( $A as $MKI=>$AVL){
  534. if (!empty($verifyStaff)){
  535. //&&$rolename['rid']==$endStaffArray['nextStaff']
  536. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  537. $button=4;
  538. $roleArrayCopy[$P][$MKI]['status']=4;
  539. }
  540. foreach ($verifyStaff as $m=>$u){
  541. $AVLFK=$AVL[0].'_R';
  542. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  543. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  544. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  545. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  546. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  547. break;
  548. }
  549. }
  550. }else{
  551. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  552. $button=4;
  553. $roleArrayCopy[$P][$MKI]['status']=4;
  554. }
  555. }
  556. //$roleArray[$MKI]['rolename']=$rolename['name'];
  557. $KOP=true;
  558. }
  559. }
  560. foreach ($roleArrayCopy as $k=>$v){
  561. foreach ($verifyList as $m=>$n){
  562. if ($n[0]==$k){
  563. array_splice($verifyList,$m,1,$v);
  564. }
  565. }
  566. }
  567. $receiptList[$key]['verifyList']= $verifyList;
  568. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  569. $receiptList[$key]['button']=$button;
  570. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  571. }
  572. $mothHtml="";
  573. for($i=1;$i<=12;$i++){
  574. if($month==$i)
  575. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  576. else
  577. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  578. }
  579. //获取审批日志
  580. Doo::loadModel('receiptLog');
  581. $receiptLog=new receiptLog();
  582. $rlList=array();
  583. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  584. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  585. if (!empty($rlInfo)){
  586. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  587. }
  588. $receiptList[0]['rlList']=$rlList;
  589. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  590. $enclosurHtml='';
  591. foreach ($enclosurList as $value){
  592. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  593. }
  594. //print_r($receiptList);
  595. $data['enclosurHtml']=$enclosurHtml;
  596. $data['rolename']=$rolename['name'];
  597. $data['datetij']=$tijdate['date'];
  598. $data['mothHtml']=$mothHtml;
  599. $data['rid']=$rid;
  600. $data['receiptList']=$receiptList;
  601. $data['receiptApprovalCount']=count($receiptList);
  602. $data['status']=$status;
  603. $data['year']=$year;
  604. $data['categoryList']=$categoryList;
  605. $data['staffList']=$staffList;
  606. $data['cid']=$cid;
  607. $data['sid']=$sid;
  608. $data['ap']=$ap;
  609. $data['memu']="receipt";
  610. $data['staff']=$this->staff;
  611. $data['receiptMemu']='approvalExpenses';
  612. $data['verifyId']=$this->verifyId;
  613. $data['executeId']=$this->executeId;
  614. $this->render ( "/admin/remitApproval", $data );
  615. }
  616. function saeaLoanAdd(){
  617. Doo::loadModel('verify');
  618. $verify=new verify();
  619. Doo::loadModel("role");
  620. $role=new role();
  621. Doo::loadModel('L_category');
  622. $lCategory=new L_category();
  623. $veList=$verify->find(array('asArray'=>true));
  624. foreach ($veList as $key=>$value){
  625. $v=json_decode($value['staff']);
  626. $list=array();
  627. foreach ($v as $n=>$m){
  628. if ($m['1']=='ROLE'){
  629. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  630. $v[$n][1]=$roleInfo['name'];
  631. array_push($list, $roleInfo['name']);
  632. }else{
  633. array_push($list, $v[$n][1]);
  634. }
  635. }
  636. $veList[$key]['staff']=implode('>', $list);
  637. }
  638. $data['category']=$lCategory->find(array('asArray'=>true));
  639. $data['veList']=$veList;
  640. $data['memu']="receipt";
  641. $data['staff']=$this->staff;
  642. $data['receiptMemu']='saeaBorad';
  643. $data['verifyId']=$this->verifyId;
  644. $data['executeId']=$this->executeId;
  645. $this->render ( "/admin/saeaLoanAdd", $data );
  646. }
  647. function saeaLoanAddDo(){
  648. $agency=$this->get_args('agency');
  649. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  650. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  651. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  652. //die;
  653. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  654. Doo::loadModel('receipt');
  655. Doo::loadModel('receiptDetail');
  656. Doo::loadModel('accountItem');
  657. $accountItem=new accountItem();
  658. $receipt=new receipt();
  659. Doo::loadModel('loanReceipt');
  660. $loanReceipt=new loanReceipt();
  661. Doo::loadModel('execute');
  662. $execute=new execute();
  663. Doo::loadModel('enclosur');
  664. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  665. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  666. // if(!empty($receiptDetail))
  667. // return "/referReceipt/".$receiptDetail['rid'];
  668. $aItem=$accountItem->find(array('asArray'=>true));
  669. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  670. $ag=$tr=$ta=$ot=0;
  671. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  672. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  673. $sum+=$agency;$agencySum+=$agency;
  674. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  675. //借款数据备份
  676. $loanReceipt->loanItem=json_encode($accountJson);
  677. $loanReceipt->staff=$this->staff[0]['sid'];
  678. $loanReceipt->sum=number_format($sum, 2, '.', '');
  679. $loanReceipt->date=date("Y-m-d");
  680. $loanReceipt->cid=$cid;
  681. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  682. $loanReceipt->status=5;
  683. $loanReceipt->Rtype=1;
  684. $loanReceipt->verify=$verify;
  685. $receipt->receiptOrder=$receipt->receiptOrder;
  686. $loanReceipt->explanation=$explanation;
  687. $loanRid=$loanReceipt->insert();
  688. //报销单
  689. $receipt->loanItem=json_encode($accountJson);
  690. $receipt->staff=$this->staff[0]['sid'];
  691. $receipt->sum=number_format($sum, 2, '.', '');
  692. $receipt->date=date("Y-m-d");
  693. $receipt->cid=$cid;
  694. //特殊状态
  695. $receipt->status=5;
  696. $receipt->Rtype=1;
  697. $receipt->loanRid=$loanRid;
  698. //修改审批流程加入角色
  699. $receipt->verify=$verify;
  700. $receipt->executeCopy=$executeDetail['staff'];
  701. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  702. $receipt->explanation=$explanation;
  703. $rid=$receipt->insert();
  704. //执行数据备份
  705. // $executeCopy->rid=$rid;
  706. // $executeCopy->staff=$executeDetail['staff'];
  707. // $executeCopy->eid=$executeDetail['eid'];
  708. // $ecid=$executeCopy->insert();
  709. }
  710. return "/saeaBorad";
  711. }
  712. function saeaLoanEdi(){
  713. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  714. Doo::loadModel('verify');
  715. $verify=new verify();
  716. Doo::loadModel("role");
  717. $role=new role();
  718. Doo::loadModel('L_category');
  719. $lCategory=new L_category();
  720. Doo::loadModel('receipt');
  721. $receipt=new receipt();
  722. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  723. $veList=$verify->find(array('asArray'=>true));
  724. foreach ($veList as $key=>$value){
  725. $v=json_decode($value['staff']);
  726. $list=array();
  727. foreach ($v as $n=>$m){
  728. if ($m['1']=='ROLE'){
  729. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  730. $v[$n][1]=$roleInfo['name'];
  731. array_push($list, $roleInfo['name']);
  732. }else{
  733. array_push($list, $v[$n][1]);
  734. }
  735. }
  736. $veList[$key]['staff']=implode('>', $list);
  737. }
  738. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  739. $data['receiptInfo']=$receiptInfo;
  740. $data['category']=$lCategory->find(array('asArray'=>true));
  741. $data['veList']=$veList;
  742. $data['memu']="receipt";
  743. $data['staff']=$this->staff;
  744. $data['receiptMemu']='saeaBorad';
  745. $data['verifyId']=$this->verifyId;
  746. $data['executeId']=$this->executeId;
  747. $this->render ( "/admin/saeaLoanEdi", $data );
  748. }
  749. function saeaLoanEdiDo(){
  750. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  751. $agency=$this->get_args('agency');
  752. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  753. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  754. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  755. //die;
  756. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  757. Doo::loadModel('receipt');
  758. Doo::loadModel('receiptDetail');
  759. Doo::loadModel('accountItem');
  760. $accountItem=new accountItem();
  761. $receipt=new receipt();
  762. Doo::loadModel('loanReceipt');
  763. $loanReceipt=new loanReceipt();
  764. Doo::loadModel('enclosur');
  765. Doo::loadModel('execute');
  766. $execute=new execute();
  767. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  768. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  769. if(empty($receiptDetail))
  770. die('参数错误');
  771. $aItem=$accountItem->find(array('asArray'=>true));
  772. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  773. $ag=$tr=$ta=$ot=0;
  774. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  775. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  776. $sum+=$agency;$agencySum+=$agency;
  777. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  778. //报销单
  779. $receipt->loanItem=json_encode($accountJson);
  780. $receipt->sum=number_format($sum, 2, '.', '');
  781. $receipt->cid=$cid;
  782. //特殊状态
  783. //修改审批流程加入角色
  784. $receipt->verify=$verify;
  785. $receipt->explanation=$explanation;
  786. $receipt->update(array('where'=>'rid='.$rid));
  787. //借款数据更新
  788. $loanReceipt->loanItem=json_encode($accountJson);
  789. $loanReceipt->sum=number_format($sum, 2, '.', '');
  790. $loanReceipt->cid=$cid;
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1405. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1406. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1407. $Locate=0;$roleId=0;$button=0;
  1408. foreach ($receiptList as $key=>$value){
  1409. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1410. $receiptList[$key]['reviseDetail']=array();
  1411. if (!empty($value['reviseDetail']))
  1412. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1413. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1414. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1415. $receiptList[$key]['category']=$categoryDetil['title'];
  1416. //检测编辑状态
  1417. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1418. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1419. $verifyStaff=json_decode($value['verifyStaff'],true);
  1420. Doo::loadModel('role');
  1421. $role=new role();
  1422. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1423. foreach ($verifyList as $k=>$v){
  1424. //init verifyStaff
  1425. if ($v[1]=='ROLE'){
  1426. if (!empty($verifyStaff)){
  1427. $endStaffArray=end($verifyStaff);
  1428. // if ($v[0]==$endStaffArray['nextStaff']){
  1429. // $roleId=$v[0];
  1430. // }
  1431. }
  1432. $roleVerify=json_decode($v[3],true);
  1433. $roleKey=$k;$roleArray=array();
  1434. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1435. foreach ($roleVerify as $o=>$p){
  1436. $staffID=explode ('_',$p);
  1437. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1438. //print_r($staffID);
  1439. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1440. array_push($roleArray, $exp);
  1441. }
  1442. $roleArrayCopy[$v[0]]=$roleArray;
  1443. //$verifyList[$k]['roleArray']=$roleArray;
  1444. }
  1445. $verifyList[$k]['date']="";
  1446. $verifyList[$k]['opinion']="";
  1447. $verifyList[$k]['status']="";
  1448. if (empty($verifyStaff)){
  1449. $verifyList[$k]['date']="";
  1450. $verifyList[$k]['opinion']="";
  1451. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1452. $verifyList[$k]['status']=4;
  1453. $flag=false;
  1454. }
  1455. }else{
  1456. foreach ($verifyStaff as $m=>$u){
  1457. if ($v[0]==$m){
  1458. $verifyList[$k]['date']=$u['date'];
  1459. $verifyList[$k]['opinion']=$u['opinion'];
  1460. $verifyList[$k]['status']=$u['status'];
  1461. $flag=false;
  1462. break;
  1463. }
  1464. }
  1465. $endStaffArray=end($verifyStaff);
  1466. if (isset($endStaffArray['ROLE'])){
  1467. }else{
  1468. // $endKey=key($verifyStaff);
  1469. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1470. // $button=4;
  1471. // $verifyList[$k]['status']=4;
  1472. // }
  1473. }
  1474. }
  1475. }
  1476. $rolename['name']='';
  1477. if (!empty($roleId)){
  1478. Doo::loadModel('role');
  1479. $role=new role();
  1480. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1481. }
  1482. if (!empty($verifyStaff))
  1483. $endStaffArray=end($verifyStaff);
  1484. $KOP=false;
  1485. foreach ($roleArrayCopy as $P=>$A){
  1486. foreach ( $A as $MKI=>$AVL){
  1487. if (!empty($verifyStaff)){
  1488. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1489. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1490. $button=4;
  1491. $roleArrayCopy[$P][$MKI]['status']=4;
  1492. }
  1493. foreach ($verifyStaff as $m=>$u){
  1494. $AVLFK=$AVL[0].'_R';
  1495. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1496. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1497. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1498. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1499. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1500. break;
  1501. }
  1502. }
  1503. }else{
  1504. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1505. $button=4;
  1506. $roleArrayCopy[$P][$MKI]['status']=4;
  1507. }
  1508. }
  1509. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1510. $KOP=true;
  1511. }
  1512. }
  1513. foreach ($roleArrayCopy as $k=>$v){
  1514. foreach ($verifyList as $m=>$n){
  1515. if ($n[0]==$k){
  1516. array_splice($verifyList,$m,1,$v);
  1517. }
  1518. }
  1519. }
  1520. $receiptList[$key]['verifyList']=$verifyList;
  1521. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1522. $receiptList[$key]['button']=$button;
  1523. }
  1524. //print_r($receiptList);die;
  1525. $mothHtml="";
  1526. for($i=1;$i<=12;$i++){
  1527. if($moth==$i)
  1528. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1529. else
  1530. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1531. }
  1532. $data['mothHtml']=$mothHtml;
  1533. $data['receiptList']=$receiptList;
  1534. $data['memu']="receipt";
  1535. $data['staff']=$this->staff;
  1536. $data['receiptMemu']='expenses';
  1537. $data['verifyId']=$this->verifyId;
  1538. $data['executeId']=$this->executeId;
  1539. $data['item']=$item;
  1540. $data['year']=$year;
  1541. $this->render ( "/admin/expenses", $data );
  1542. }
  1543. function expensesCollect(){
  1544. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1545. Doo::loadModel('receipt');
  1546. $receipt=new receipt();
  1547. Doo::loadModel('L_category');
  1548. $Lcategory=new L_category();
  1549. Doo::loadModel('verify');
  1550. Doo::loadModel('statistics');
  1551. $statistics=new statistics();
  1552. $verify=new verify();
  1553. Doo::loadModel('staff');
  1554. $staff=new staff();
  1555. Doo::loadModel('loanReceipt');
  1556. $loanReceipt=new loanReceipt();
  1557. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1558. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1559. $Locate=0;$roleId=0;$button=0;
  1560. foreach ($loanList as $key=>$value){
  1561. $loanList[$key]['Locate']=$Locate;$Locate++;
  1562. $loanList[$key]['reviseDetail']=array();
  1563. if (!empty($value['reviseDetail']))
  1564. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1565. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1566. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1567. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1568. $loanList[$key]['category']=$categoryDetil['title'];
  1569. //检测编辑状态
  1570. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1571. $verifyList['staff']=$value['verifyBreakup'];
  1572. else
  1573. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1574. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1575. $verifyStaff=json_decode($value['verifyStaff'],true);
  1576. Doo::loadModel('role');
  1577. $role=new role();
  1578. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1579. foreach ($verifyList as $k=>$v){
  1580. //init verifyStaff
  1581. if ($v[1]=='ROLE'){
  1582. if (!empty($verifyStaff)){
  1583. $endStaffArray=end($verifyStaff);
  1584. // if ($v[0]==$endStaffArray['nextStaff']){
  1585. // $roleId=$v[0];
  1586. // }
  1587. }
  1588. $roleVerify=json_decode($v[3],true);
  1589. $roleKey=$k;$roleArray=array();
  1590. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1591. foreach ($roleVerify as $o=>$p){
  1592. $staffID=explode ('_',$p);
  1593. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1594. //print_r($staffID);
  1595. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1596. array_push($roleArray, $exp);
  1597. }
  1598. $roleArrayCopy[$v[0]]=$roleArray;
  1599. //$verifyList[$k]['roleArray']=$roleArray;
  1600. }
  1601. $verifyList[$k]['date']="";
  1602. $verifyList[$k]['opinion']="";
  1603. $verifyList[$k]['status']="";
  1604. if (empty($verifyStaff)){
  1605. $verifyList[$k]['date']="";
  1606. $verifyList[$k]['opinion']="";
  1607. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1608. $verifyList[$k]['status']=4;
  1609. $flag=false;
  1610. }
  1611. }else{
  1612. foreach ($verifyStaff as $m=>$u){
  1613. if ($v[0]==$m){
  1614. $verifyList[$k]['date']=$u['date'];
  1615. $verifyList[$k]['opinion']=$u['opinion'];
  1616. $verifyList[$k]['status']=$u['status'];
  1617. $flag=false;
  1618. break;
  1619. }
  1620. }
  1621. $endStaffArray=end($verifyStaff);
  1622. if (isset($endStaffArray['ROLE'])){
  1623. }else{
  1624. // $endKey=key($verifyStaff);
  1625. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1626. // $button=4;
  1627. // $verifyList[$k]['status']=4;
  1628. // }
  1629. }
  1630. }
  1631. }
  1632. $rolename['name']='';
  1633. if (!empty($roleId)){
  1634. Doo::loadModel('role');
  1635. $role=new role();
  1636. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1637. }
  1638. if (!empty($verifyStaff))
  1639. $endStaffArray=end($verifyStaff);
  1640. $KOP=false;
  1641. foreach ($roleArrayCopy as $P=>$A){
  1642. foreach ( $A as $MKI=>$AVL){
  1643. if (!empty($verifyStaff)){
  1644. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1645. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1646. $button=4;
  1647. $roleArrayCopy[$P][$MKI]['status']=4;
  1648. }
  1649. foreach ($verifyStaff as $m=>$u){
  1650. $AVLFK=$AVL[0].'_R';
  1651. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1652. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1653. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1654. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1655. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1656. break;
  1657. }
  1658. }
  1659. }else{
  1660. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1661. $button=4;
  1662. $roleArrayCopy[$P][$MKI]['status']=4;
  1663. }
  1664. }
  1665. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1666. $KOP=true;
  1667. }
  1668. }
  1669. foreach ($roleArrayCopy as $k=>$v){
  1670. foreach ($verifyList as $m=>$n){
  1671. if ($n[0]==$k){
  1672. array_splice($verifyList,$m,1,$v);
  1673. }
  1674. }
  1675. }
  1676. $loanList[$key]['verifyList']=$verifyList;
  1677. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1678. $loanList[$key]['button']=$button;
  1679. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1680. }
  1681. $data['loanList']=$loanList;
  1682. $Locate=0;$roleId=0;$button=0;
  1683. foreach ($receiptList as $key=>$value){
  1684. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1685. $receiptList[$key]['reviseDetail']=array();
  1686. if (!empty($value['reviseDetail']))
  1687. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1688. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1689. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1690. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1691. $receiptList[$key]['category']=$categoryDetil['title'];
  1692. //检测编辑状态
  1693. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1694. if($value['status']==8&&$value['Rtype']==1)
  1695. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1696. else
  1697. $verifyList['staff']=$value['verifyBreakup'];
  1698. }else
  1699. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1700. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1701. $verifyStaff=json_decode($value['verifyStaff'],true);
  1702. Doo::loadModel('role');
  1703. $role=new role();
  1704. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1705. foreach ($verifyList as $k=>$v){
  1706. //init verifyStaff
  1707. if ($v[1]=='ROLE'){
  1708. if (!empty($verifyStaff)){
  1709. $endStaffArray=end($verifyStaff);
  1710. // if ($v[0]==$endStaffArray['nextStaff']){
  1711. // $roleId=$v[0];
  1712. // }
  1713. }
  1714. $roleVerify=json_decode($v[3],true);
  1715. $roleKey=$k;$roleArray=array();
  1716. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1717. foreach ($roleVerify as $o=>$p){
  1718. $staffID=explode ('_',$p);
  1719. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1720. //print_r($staffID);
  1721. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1722. array_push($roleArray, $exp);
  1723. }
  1724. $roleArrayCopy[$v[0]]=$roleArray;
  1725. //$verifyList[$k]['roleArray']=$roleArray;
  1726. }
  1727. $verifyList[$k]['date']="";
  1728. $verifyList[$k]['opinion']="";
  1729. $verifyList[$k]['status']="";
  1730. if (empty($verifyStaff)){
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1734. $verifyList[$k]['status']=4;
  1735. $flag=false;
  1736. }
  1737. }else{
  1738. foreach ($verifyStaff as $m=>$u){
  1739. if ($v[0]==$m){
  1740. $verifyList[$k]['date']=$u['date'];
  1741. $verifyList[$k]['opinion']=$u['opinion'];
  1742. $verifyList[$k]['status']=$u['status'];
  1743. $flag=false;
  1744. break;
  1745. }
  1746. }
  1747. $endStaffArray=end($verifyStaff);
  1748. if (isset($endStaffArray['ROLE'])){
  1749. }else{
  1750. // $endKey=key($verifyStaff);
  1751. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1752. // $button=4;
  1753. // $verifyList[$k]['status']=4;
  1754. // }
  1755. }
  1756. }
  1757. }
  1758. $rolename['name']='';
  1759. if (!empty($roleId)){
  1760. Doo::loadModel('role');
  1761. $role=new role();
  1762. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1763. }
  1764. if (!empty($verifyStaff))
  1765. $endStaffArray=end($verifyStaff);
  1766. $KOP=false;
  1767. foreach ($roleArrayCopy as $P=>$A){
  1768. foreach ( $A as $MKI=>$AVL){
  1769. if (!empty($verifyStaff)){
  1770. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1771. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1772. $button=4;
  1773. $roleArrayCopy[$P][$MKI]['status']=4;
  1774. }
  1775. foreach ($verifyStaff as $m=>$u){
  1776. $AVLFK=$AVL[0].'_R';
  1777. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1778. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1779. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1780. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1781. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1782. break;
  1783. }
  1784. }
  1785. }else{
  1786. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1787. $button=4;
  1788. $roleArrayCopy[$P][$MKI]['status']=4;
  1789. }
  1790. }
  1791. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1792. $KOP=true;
  1793. }
  1794. }
  1795. foreach ($roleArrayCopy as $k=>$v){
  1796. foreach ($verifyList as $m=>$n){
  1797. if ($n[0]==$k){
  1798. array_splice($verifyList,$m,1,$v);
  1799. }
  1800. }
  1801. }
  1802. $receiptList[$key]['verifyList']=$verifyList;
  1803. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1804. $receiptList[$key]['button']=$button;
  1805. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1806. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1807. $relust=$value['sum']-$value['loanSum'];
  1808. $receiptList[$key]['relust']=$relust;
  1809. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1810. }
  1811. $data['receiptList']=$receiptList;
  1812. $data['memu']="receipt";
  1813. $data['staff']=$this->staff;
  1814. $data['receiptMemu']='expenses';
  1815. $data['verifyId']=$this->verifyId;
  1816. $data['executeId']=$this->executeId;
  1817. $this->render ( "/admin/expensesCollect", $data );
  1818. }
  1819. function approvalExpenses(){
  1820. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1821. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1822. $month=$this->get_args('month')?$this->get_args('month'):"";
  1823. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1824. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1825. if (empty($status))
  1826. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1827. $page_size=12;
  1828. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1829. $vidList=array();
  1830. $button=0;
  1831. Doo::loadModel('verify');
  1832. $verify=new verify();
  1833. Doo::loadModel('receipt');
  1834. $receipt=new receipt();
  1835. Doo::loadModel('staff');
  1836. $staff=new staff();
  1837. Doo::loadModel('L_category');
  1838. $Lcategory=new L_category();
  1839. //user verify ID
  1840. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1841. foreach ($verifyDetail as $key=>$value){
  1842. array_push($vidList, $value['vid']);
  1843. }
  1844. $vid=implode(",", $vidList);
  1845. if(empty($verifyDetail))
  1846. $vid=0;
  1847. // if ($status==0)
  1848. // $dateCondition="";
  1849. // else
  1850. $dateCondition=" and Year(date) =".$year;
  1851. if(!empty($month))
  1852. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1853. $categoryList=$Lcategory->find(array('asArray'=>true));
  1854. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1855. $cateCondition="";$staffCondition="";$approvalCondition="";
  1856. if (!empty($cid))
  1857. $cateCondition=' and cid='.$cid;
  1858. if(!empty($sid)){
  1859. $staffCondition=' and staff='.$sid;
  1860. $cateCondition="";
  1861. }
  1862. $approvalCondition=" and status=".$status;
  1863. if($status==2){
  1864. //查找角色审批人
  1865. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1866. }
  1867. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1868. $approvalCondition=' and status=2 ';
  1869. }
  1870. if($status==1){
  1871. $approvalCondition=' and (status='.$status.' or status=6) ';
  1872. }
  1873. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1874. $pageinfo['page']=array('previous'=>'');
  1875. if ($status==0){
  1876. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1877. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1878. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1879. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1880. }else
  1881. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1882. ,'desc'=>'rid','asArray'=>true));
  1883. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1884. ,'desc'=>'rid','asArray'=>true));
  1885. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1886. //print_r($pageinfo);
  1887. $Locate=0;
  1888. foreach ($receiptList as $key=>$value){
  1889. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1890. $receiptList[$key]['reviseDetail']=array();
  1891. if (!empty($value['reviseDetail']))
  1892. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1893. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1894. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1895. $receiptList[$key]['category']=$categoryDetil['title'];
  1896. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1897. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1898. $verifyStaff=json_decode($value['verifyStaff'],true);
  1899. foreach ($verifyList as $k=>$v){
  1900. //init verifyStaff
  1901. $verifyList[$k]['date']="";
  1902. $verifyList[$k]['opinion']="";
  1903. $verifyList[$k]['status']="";
  1904. if (empty($verifyStaff)){
  1905. $verifyList[$k]['date']="";
  1906. $verifyList[$k]['opinion']="";
  1907. if ($v[0]==$this->staff[0]['sid']){
  1908. $verifyList[$k]['status']=4;
  1909. $button=4;
  1910. }
  1911. }else{
  1912. $flag=true;
  1913. foreach ($verifyStaff as $m=>$u){
  1914. if ($v[0]==$m){
  1915. $verifyList[$k]['date']=$u['date'];
  1916. $verifyList[$k]['opinion']=$u['opinion'];
  1917. $verifyList[$k]['status']=$u['status'];
  1918. $flag=false;
  1919. break;
  1920. }
  1921. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1922. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1923. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1924. }
  1925. if($flag){//检测可编辑
  1926. if($v[0]==$this->staff[0]['sid']){
  1927. $verifyList[$k]['status']=4;$button=4;
  1928. }
  1929. }
  1930. }
  1931. }
  1932. $receiptList[$key]['verifyList']=$verifyList;
  1933. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1934. $receiptList[$key]['button']=$button;
  1935. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1936. }
  1937. //print_r($receiptList);die;
  1938. //$data['verifyDetail']=$verifyDetail;
  1939. $mothHtml="";
  1940. for($i=1;$i<=12;$i++){
  1941. if($month==$i)
  1942. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1943. else
  1944. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1945. }
  1946. $data['mothHtml']=$mothHtml;
  1947. $data['page']=$pageinfo;
  1948. $data['receiptList']=$receiptList;
  1949. $data['receiptApprovalCount']=count($rLRes);
  1950. $data['status']=$status;
  1951. $data['year']=$year;
  1952. $data['categoryList']=$categoryList;
  1953. $data['staffList']=$staffList;
  1954. $data['cid']=$cid;
  1955. $data['sid']=$sid;
  1956. //print_r($receiptList);
  1957. $data['memu']="receipt";
  1958. $data['staff']=$this->staff;
  1959. $data['receiptMemu']='approvalExpenses';
  1960. $data['verifyId']=$this->verifyId;
  1961. $data['executeId']=$this->executeId;
  1962. $this->render ( "/admin/approvalExpenses", $data );
  1963. }
  1964. function expensesDoc(){
  1965. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1966. Doo::loadModel('receipt');
  1967. $receipt=new receipt();
  1968. Doo::loadModel('L_category');
  1969. $Lcategory=new L_category();
  1970. Doo::loadModel('verify');
  1971. Doo::loadModel('statistics');
  1972. $statistics=new statistics();
  1973. $verify=new verify();
  1974. Doo::loadModel('staff');
  1975. $staff=new staff();
  1976. Doo::loadModel('loanReceipt');
  1977. $loanReceipt=new loanReceipt();
  1978. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1979. $loanList=array();
  1980. if (!empty($receiptList))
  1981. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1982. $Locate=0;$roleId=0;$button=0;
  1983. foreach ($loanList as $key=>$value){
  1984. $loanList[$key]['Locate']=$Locate;$Locate++;
  1985. $loanList[$key]['reviseDetail']=array();
  1986. if (!empty($value['reviseDetail']))
  1987. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1988. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1989. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1990. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1991. $loanList[$key]['category']=$categoryDetil['title'];
  1992. //检测编辑状态
  1993. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1994. $verifyList['staff']=$value['verifyBreakup'];
  1995. else
  1996. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1997. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1998. $verifyStaff=json_decode($value['verifyStaff'],true);
  1999. Doo::loadModel('role');
  2000. $role=new role();
  2001. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2002. foreach ($verifyList as $k=>$v){
  2003. //init verifyStaff
  2004. if ($v[1]=='ROLE'){
  2005. if (!empty($verifyStaff)){
  2006. $endStaffArray=end($verifyStaff);
  2007. // if ($v[0]==$endStaffArray['nextStaff']){
  2008. // $roleId=$v[0];
  2009. // }
  2010. }
  2011. $roleVerify=json_decode($v[3],true);
  2012. $roleKey=$k;$roleArray=array();
  2013. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2014. foreach ($roleVerify as $o=>$p){
  2015. $staffID=explode ('_',$p);
  2016. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2017. //print_r($staffID);
  2018. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2019. array_push($roleArray, $exp);
  2020. }
  2021. $roleArrayCopy[$v[0]]=$roleArray;
  2022. //$verifyList[$k]['roleArray']=$roleArray;
  2023. }
  2024. $verifyList[$k]['date']="";
  2025. $verifyList[$k]['opinion']="";
  2026. $verifyList[$k]['status']="";
  2027. if (empty($verifyStaff)){
  2028. $verifyList[$k]['date']="";
  2029. $verifyList[$k]['opinion']="";
  2030. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2031. $verifyList[$k]['status']=4;
  2032. $flag=false;
  2033. }
  2034. }else{
  2035. foreach ($verifyStaff as $m=>$u){
  2036. if ($v[0]==$m){
  2037. $verifyList[$k]['date']=$u['date'];
  2038. $verifyList[$k]['opinion']=$u['opinion'];
  2039. $verifyList[$k]['status']=$u['status'];
  2040. $flag=false;
  2041. break;
  2042. }
  2043. }
  2044. $endStaffArray=end($verifyStaff);
  2045. if (isset($endStaffArray['ROLE'])){
  2046. }else{
  2047. // $endKey=key($verifyStaff);
  2048. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2049. // $button=4;
  2050. // $verifyList[$k]['status']=4;
  2051. // }
  2052. }
  2053. }
  2054. }
  2055. $rolename['name']='';
  2056. if (!empty($roleId)){
  2057. Doo::loadModel('role');
  2058. $role=new role();
  2059. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2060. }
  2061. if (!empty($verifyStaff))
  2062. $endStaffArray=end($verifyStaff);
  2063. $KOP=false;
  2064. foreach ($roleArrayCopy as $P=>$A){
  2065. foreach ( $A as $MKI=>$AVL){
  2066. if (!empty($verifyStaff)){
  2067. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2068. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2069. $button=4;
  2070. $roleArrayCopy[$P][$MKI]['status']=4;
  2071. }
  2072. foreach ($verifyStaff as $m=>$u){
  2073. $AVLFK=$AVL[0].'_R';
  2074. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2075. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2076. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2077. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2078. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2079. break;
  2080. }
  2081. }
  2082. }else{
  2083. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2084. $button=4;
  2085. $roleArrayCopy[$P][$MKI]['status']=4;
  2086. }
  2087. }
  2088. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2089. $KOP=true;
  2090. }
  2091. }
  2092. foreach ($roleArrayCopy as $k=>$v){
  2093. foreach ($verifyList as $m=>$n){
  2094. if ($n[0]==$k){
  2095. array_splice($verifyList,$m,1,$v);
  2096. }
  2097. }
  2098. }
  2099. $loanList[$key]['verifyList']=$verifyList;
  2100. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2101. $loanList[$key]['button']=$button;
  2102. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2103. }
  2104. $data['loanList']=$loanList;
  2105. //print_r($loanList);
  2106. $Locate=0;$roleId=0;$button=0;
  2107. foreach ($receiptList as $key=>$value){
  2108. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2109. $receiptList[$key]['reviseDetail']=array();
  2110. if (!empty($value['reviseDetail']))
  2111. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2112. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2113. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2114. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2115. $receiptList[$key]['category']=$categoryDetil['title'];
  2116. //检测编辑状态
  2117. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2118. $verifyList['staff']=$value['verifyBreakup'];
  2119. }else
  2120. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2121. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2122. $verifyStaff=json_decode($value['verifyStaff'],true);
  2123. Doo::loadModel('role');
  2124. $role=new role();
  2125. if ($verifyList==NULL)
  2126. $verifyList=array();
  2127. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2128. foreach ($verifyList as $k=>$v){
  2129. //init verifyStaff
  2130. if ($v[1]=='ROLE'){
  2131. if (!empty($verifyStaff)){
  2132. $endStaffArray=end($verifyStaff);
  2133. // if ($v[0]==$endStaffArray['nextStaff']){
  2134. // $roleId=$v[0];
  2135. // }
  2136. }
  2137. $roleVerify=json_decode($v[3],true);
  2138. $roleKey=$k;$roleArray=array();
  2139. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2140. foreach ($roleVerify as $o=>$p){
  2141. $staffID=explode ('_',$p);
  2142. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2143. //print_r($staffID);
  2144. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2145. array_push($roleArray, $exp);
  2146. }
  2147. $roleArrayCopy[$v[0]]=$roleArray;
  2148. //$verifyList[$k]['roleArray']=$roleArray;
  2149. }
  2150. $verifyList[$k]['date']="";
  2151. $verifyList[$k]['opinion']="";
  2152. $verifyList[$k]['status']="";
  2153. if (empty($verifyStaff)){
  2154. $verifyList[$k]['date']="";
  2155. $verifyList[$k]['opinion']="";
  2156. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2157. $verifyList[$k]['status']=4;
  2158. $flag=false;
  2159. }
  2160. }else{
  2161. foreach ($verifyStaff as $m=>$u){
  2162. if ($v[0]==$m){
  2163. $verifyList[$k]['date']=$u['date'];
  2164. $verifyList[$k]['opinion']=$u['opinion'];
  2165. $verifyList[$k]['status']=$u['status'];
  2166. $flag=false;
  2167. break;
  2168. }
  2169. }
  2170. $endStaffArray=end($verifyStaff);
  2171. if (isset($endStaffArray['ROLE'])){
  2172. }else{
  2173. // $endKey=key($verifyStaff);
  2174. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2175. // $button=4;
  2176. // $verifyList[$k]['status']=4;
  2177. // }
  2178. }
  2179. }
  2180. }
  2181. $rolename['name']='';
  2182. if (!empty($roleId)){
  2183. Doo::loadModel('role');
  2184. $role=new role();
  2185. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2186. }
  2187. if (!empty($verifyStaff))
  2188. $endStaffArray=end($verifyStaff);
  2189. $KOP=false;
  2190. foreach ($roleArrayCopy as $P=>$A){
  2191. foreach ( $A as $MKI=>$AVL){
  2192. if (!empty($verifyStaff)){
  2193. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2194. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2195. $button=4;
  2196. $roleArrayCopy[$P][$MKI]['status']=4;
  2197. }
  2198. foreach ($verifyStaff as $m=>$u){
  2199. $AVLFK=$AVL[0].'_R';
  2200. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2201. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2202. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2203. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2204. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2205. break;
  2206. }
  2207. }
  2208. }else{
  2209. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2210. $button=4;
  2211. $roleArrayCopy[$P][$MKI]['status']=4;
  2212. }
  2213. }
  2214. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2215. $KOP=true;
  2216. }
  2217. }
  2218. foreach ($roleArrayCopy as $k=>$v){
  2219. foreach ($verifyList as $m=>$n){
  2220. if ($n[0]==$k){
  2221. array_splice($verifyList,$m,1,$v);
  2222. }
  2223. }
  2224. }
  2225. $receiptList[$key]['verifyList']=$verifyList;
  2226. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2227. $receiptList[$key]['button']=$button;
  2228. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2229. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2230. }
  2231. //获取审批日志
  2232. Doo::loadModel('receiptLog');
  2233. $receiptLog=new receiptLog();
  2234. $rlList=array();
  2235. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2236. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2237. if (!empty($rlInfo)){
  2238. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2239. }
  2240. $receiptList[0]['rlList']=$rlList;
  2241. $data['receiptList']=$receiptList;
  2242. $data['memu']="receipt";
  2243. $data['staff']=$this->staff;
  2244. $data['receiptMemu']='approvalExpenses';
  2245. $data['verifyId']=$this->verifyId;
  2246. $data['executeId']=$this->executeId;
  2247. $this->render ( "/admin/expensesDoc", $data );
  2248. }
  2249. function expensesEdi(){
  2250. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2251. $status=isset($this->params['status'])?$this->params['status']:'';
  2252. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2253. $month=$this->get_args('month')?$this->get_args('month'):"";
  2254. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2255. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2256. if (empty($status))
  2257. $status=$this->get_args('status')?$this->get_args('status'):2;
  2258. $vidList=array();
  2259. $button=0;
  2260. Doo::loadModel('verify');
  2261. Doo::loadModel('receipt');
  2262. Doo::loadModel('staff');
  2263. $staff=new staff();
  2264. $receipt=new receipt();
  2265. $verify=new verify();
  2266. Doo::loadModel('L_category');
  2267. $Lcategory=new L_category();
  2268. Doo::loadModel('enclosur');
  2269. $enclosur=new enclosur();
  2270. //user verify ID
  2271. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2272. foreach ($verifyDetail as $key=>$value){
  2273. array_push($vidList, $value['vid']);
  2274. }
  2275. $vid=implode(",", $vidList);
  2276. if(empty($verifyDetail))
  2277. $vid=0;
  2278. $categoryList=$Lcategory->find(array('asArray'=>true));
  2279. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2280. $ap="";
  2281. if($status==4){
  2282. $ap=4;$status=2;
  2283. }
  2284. //get Receipt By verifyID status 2
  2285. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2286. $Locate=0;$roleId=0;
  2287. if($ap==4)
  2288. $status=4;
  2289. foreach ($receiptList as $key=>$value){
  2290. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2291. $receiptList[$key]['reviseDetail']=array();
  2292. if (!empty($value['reviseDetail']))
  2293. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2294. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2295. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2296. $receiptList[$key]['category']=$categoryDetil['title'];
  2297. //检测编辑状态
  2298. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2299. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2300. $verifyStaff=json_decode($value['verifyStaff'],true);
  2301. Doo::loadModel('role');
  2302. $role=new role();
  2303. //print_r($verifyList);
  2304. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2305. foreach ($verifyList as $k=>$v){
  2306. //init verifyStaff
  2307. if ($v[1]=='ROLE'){
  2308. if (!empty($verifyStaff)){
  2309. $endStaffArray=end($verifyStaff);
  2310. if ($v[0]==$endStaffArray['nextStaff']){
  2311. $roleId=$v[0];
  2312. }
  2313. }
  2314. $roleVerify=json_decode($v[3],true);
  2315. $roleKey=$k;$roleArray=array();
  2316. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2317. foreach ($roleVerify as $o=>$p){
  2318. $staffID=explode ('_',$p);
  2319. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2320. //print_r($staffID);
  2321. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2322. array_push($roleArray, $exp);
  2323. }
  2324. $roleArrayCopy[$v[0]]=$roleArray;
  2325. //$verifyList[$k]['roleArray']=$roleArray;
  2326. }
  2327. //print_r($roleArray);
  2328. $verifyList[$k]['date']="";
  2329. $verifyList[$k]['opinion']="";
  2330. $verifyList[$k]['status']="";
  2331. if (empty($verifyStaff)){
  2332. $verifyList[$k]['date']="";
  2333. $verifyList[$k]['opinion']="";
  2334. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2335. $verifyList[$k]['status']=4;
  2336. $button=4;$flag=false;
  2337. }
  2338. }else{
  2339. foreach ($verifyStaff as $m=>$u){
  2340. if ($v[0]==$m){
  2341. $verifyList[$k]['date']=$u['date'];
  2342. $verifyList[$k]['opinion']=$u['opinion'];
  2343. $verifyList[$k]['status']=$u['status'];
  2344. $flag=false;
  2345. break;
  2346. }
  2347. }
  2348. $endStaffArray=end($verifyStaff);
  2349. if (isset($endStaffArray['ROLE'])){
  2350. }else{
  2351. $endKey=key($verifyStaff);
  2352. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2353. $button=4;
  2354. $verifyList[$k]['status']=4;
  2355. }
  2356. }
  2357. }
  2358. }
  2359. $rolename['name']='';
  2360. if (!empty($roleId)){
  2361. Doo::loadModel('role');
  2362. $role=new role();
  2363. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2364. }
  2365. if (!empty($verifyStaff))
  2366. $endStaffArray=end($verifyStaff);
  2367. $KOP=false;
  2368. foreach ($roleArrayCopy as $P=>$A){
  2369. foreach ( $A as $MKI=>$AVL){
  2370. if (!empty($verifyStaff)){
  2371. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2372. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2373. $button=4;
  2374. $roleArrayCopy[$P][$MKI]['status']=4;
  2375. }
  2376. foreach ($verifyStaff as $m=>$u){
  2377. $AVLFK=$AVL[0].'_R';
  2378. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2379. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2380. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2381. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2382. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2383. break;
  2384. }
  2385. }
  2386. }else{
  2387. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2388. $button=4;
  2389. $roleArrayCopy[$P][$MKI]['status']=4;
  2390. }
  2391. }
  2392. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2393. $KOP=true;
  2394. }
  2395. }
  2396. // print_r($roleArrayCopy);
  2397. // echo $roleKey;
  2398. foreach ($roleArrayCopy as $k=>$v){
  2399. foreach ($verifyList as $m=>$n){
  2400. if ($n[0]==$k){
  2401. array_splice($verifyList,$m,1,$v);
  2402. }
  2403. }
  2404. }
  2405. $receiptList[$key]['verifyList']=$verifyList;
  2406. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2407. $receiptList[$key]['button']=$button;
  2408. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2409. }
  2410. //$data['verifyDetail']=$verifyDetail;
  2411. $mothHtml="";
  2412. for($i=1;$i<=12;$i++){
  2413. if($month==$i)
  2414. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2415. else
  2416. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2417. }
  2418. //获取审批日志
  2419. Doo::loadModel('receiptLog');
  2420. $receiptLog=new receiptLog();
  2421. $rlList=array();
  2422. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2423. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2424. if (!empty($rlInfo)){
  2425. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2426. }
  2427. $receiptList[0]['rlList']=$rlList;
  2428. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2429. $enclosurHtml='';
  2430. foreach ($enclosurList as $value){
  2431. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2432. }
  2433. //print_r($receiptList);
  2434. $data['rid']=$rid;
  2435. $data['enclosurHtml']=$enclosurHtml;
  2436. $data['rolename']=$rolename['name'];
  2437. $data['datetij']=$tijdate['date'];
  2438. $data['mothHtml']=$mothHtml;
  2439. $data['receiptList']=$receiptList;
  2440. $data['receiptApprovalCount']=count($receiptList);
  2441. $data['status']=$status;
  2442. $data['year']=$year;
  2443. $data['categoryList']=$categoryList;
  2444. $data['staffList']=$staffList;
  2445. $data['cid']=$cid;
  2446. $data['sid']=$sid;
  2447. $data['ap']=$ap;
  2448. $data['memu']="receipt";
  2449. $data['staff']=$this->staff;
  2450. $data['receiptMemu']='approvalExpenses';
  2451. $data['verifyId']=$this->verifyId;
  2452. $data['executeId']=$this->executeId;
  2453. $this->render ( "/admin/expensesEdi", $data );
  2454. }
  2455. function expensesDefray(){
  2456. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2457. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2458. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2459. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2460. if(!empty($rid)){
  2461. Doo::loadModel("verify");
  2462. $verify=new verify();
  2463. Doo::loadModel("receiptDetail");
  2464. $receiptDetailObj=new receiptDetail();
  2465. Doo::loadModel("itemStatistics");
  2466. Doo::loadModel("statistics");
  2467. $statistics=new statistics();
  2468. $itemStatistics=new itemStatistics();
  2469. Doo::loadModel("receipt");
  2470. $receipt=new receipt();
  2471. Doo::loadModel("loanReceipt");
  2472. $loanReceipt=new loanReceipt();
  2473. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2474. if (empty($receiptDetail))
  2475. return "/approval";
  2476. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2477. $verifyString=$verifyDetail['staff'];
  2478. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2479. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2480. if(empty($opinion)){
  2481. if ($status==3)
  2482. $opinion="终止";
  2483. else
  2484. $opinion="同意支付";
  2485. }
  2486. $nowStaff=0;$nowStaffList=array();
  2487. if(empty($verifyStaff)){
  2488. //还需加入是否已经进入角色审批
  2489. if ($verifyDetail[0][1]=='ROLE'){
  2490. //print_r($verifyDetail);echo "ddd";
  2491. $vStaffString=json_decode($verifyDetail[0][3]);
  2492. foreach ($vStaffString as $key=>$value){
  2493. $staffK=explode("_", $value);
  2494. if ($staffK[0]!=$this->staff[0]['sid'])
  2495. array_push($nowStaffList, $staffK[0]);
  2496. }
  2497. //print_r($verifyDetail);
  2498. //die;
  2499. $nowStaff=implode(',', $nowStaffList);
  2500. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2501. }else{
  2502. if ($verifyDetail[1][1]=='ROLE'){
  2503. $vStaffString=json_decode($verifyDetail[1][3]);
  2504. //echo "dd";
  2505. foreach ($vStaffString as $key=>$value){
  2506. $staffK=explode("_", $value);
  2507. array_push($nowStaffList, $staffK[0]);
  2508. }
  2509. $nowStaff=implode(',', $nowStaffList);
  2510. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2511. }else{
  2512. $nowStaff=$verifyDetail[1][0];
  2513. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2514. }
  2515. }
  2516. if($status==3)
  2517. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2518. $vStaffString=json_encode($verifyStaff);
  2519. $receipt->nowStaff=$nowStaff;
  2520. $receipt->verifyStaff=$vStaffString;
  2521. $loanReceipt->nowStaff=$nowStaff;
  2522. $loanReceipt->verifyStaff=$vStaffString;
  2523. }else{
  2524. $VS=end($verifyStaff);
  2525. //非角色审批
  2526. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2527. $nextStaff=0;$roleSTF=false;
  2528. foreach ($verifyDetail as $key=>$value){
  2529. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2530. if (isset($verifyDetail[$key+1])){
  2531. $nextStaff=$verifyDetail[$key+1][0];
  2532. if ($verifyDetail[$key+1][1]=='ROLE')
  2533. $roleSTF=true;
  2534. }
  2535. break;
  2536. }
  2537. }
  2538. if (!$roleSTF){
  2539. $nowStaff=$nextStaff;
  2540. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2541. }else{
  2542. //获取角色下的所有用户ID
  2543. $nowStaffList=array();
  2544. foreach ($verifyDetail as $vfk){
  2545. if ($vfk[1]=='ROLE'){
  2546. $vStaffString=json_decode($vfk[3]);
  2547. foreach ($vStaffString as $key=>$value){
  2548. $staffK=explode("_", $value);
  2549. array_push($nowStaffList, $staffK[0]);
  2550. }
  2551. }
  2552. }
  2553. $nowStaff=implode(',', $nowStaffList);
  2554. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2555. }
  2556. if($status==3){
  2557. $verifyStaff['final']=$status;
  2558. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2559. }
  2560. $vStaffString=json_encode($verifyStaff);
  2561. $receipt->nowStaff=$nowStaff;
  2562. $receipt->verifyStaff=$vStaffString;
  2563. $loanReceipt->nowStaff=$nowStaff;
  2564. $loanReceipt->verifyStaff=$vStaffString;
  2565. }
  2566. //角色审批
  2567. if (isset($VS['ROLE'])){
  2568. //找出角色人 当前审批角色组
  2569. $verifyJSStaff=array();$nowStaffList2=array();
  2570. foreach ($verifyDetail as $key=>$value){
  2571. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2572. $verifyJSStaff=json_decode($value[3]);
  2573. foreach ($verifyJSStaff as $m){
  2574. $staffK=explode("_", $m);
  2575. array_push($nowStaffList2, $staffK[0]);
  2576. }
  2577. // print_r($nowStaffList2);
  2578. }
  2579. }
  2580. $RoleVerifyStaff=array();
  2581. foreach ($verifyStaff as $key=>$value){
  2582. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2583. foreach ($nowStaffList2 as $m) {
  2584. if ($key==$m."_R")
  2585. $RoleVerifyStaff[$key]=$value;
  2586. }
  2587. }
  2588. }
  2589. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2590. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2591. //下一个审批人ID
  2592. $nextStaff=0;$falg=false;
  2593. foreach ($verifyDetail as $key=>$value){
  2594. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2595. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2596. $falg=true;
  2597. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2598. foreach ($vStaffString as $v){
  2599. $staffK=explode("_", $v);
  2600. array_push($nowStaffList, $staffK[0]);
  2601. }
  2602. $nowStaff=implode(',', $nowStaffList);
  2603. $nextStaff=$verifyDetail[$key+1][0];
  2604. }elseif(isset($verifyDetail[$key+1])){
  2605. $nextStaff=$verifyDetail[$key+1][0];
  2606. $nowStaff=$nextStaff;
  2607. }else
  2608. $nowStaff='';
  2609. break;
  2610. }
  2611. }
  2612. if ($falg)
  2613. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2614. else
  2615. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2616. // print_r($verifyStaff);
  2617. // echo $nowStaff;die;
  2618. }else{ //进入下一个角色或者审批人
  2619. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2620. //
  2621. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2622. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2623. // print_r($verifyStaff);
  2624. // die;
  2625. }
  2626. if($status==3){
  2627. $verifyStaff['final']=$status;
  2628. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2629. }
  2630. $vStaffString=json_encode($verifyStaff);
  2631. $receipt->verifyStaff=$vStaffString;
  2632. $receipt->nowStaff=$nowStaff;
  2633. $loanReceipt->nowStaff=$nowStaff;
  2634. $loanReceipt->verifyStaff=$vStaffString;
  2635. //die;
  2636. //}
  2637. // print_r($verifyStaff);
  2638. // die;
  2639. }
  2640. //print_r($verifyStaff);die;
  2641. }
  2642. //print_r($verifyDetail);
  2643. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2644. foreach ($verifyDetail as $k=>$v){
  2645. if ($v[1]=='ROLE'){
  2646. $roleId=$v[0];
  2647. $roleVerify=json_decode($v[3],true);
  2648. $roleKey=$k;$roleArray=array();
  2649. foreach ($roleVerify as $o=>$p){
  2650. $staffID=explode ('_',$p);
  2651. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2652. array_push($roleArray, $exp);
  2653. }
  2654. $verifyDetailCopy[$v[0]]=$roleArray;
  2655. }
  2656. }
  2657. //print_r($verifyDetail);
  2658. foreach ($verifyDetailCopy as $k=>$v){
  2659. foreach ($verifyDetail as $m=>$n){
  2660. if ($n[0]==$k){
  2661. array_splice($verifyDetail,$m,1,$v);
  2662. }
  2663. }
  2664. }
  2665. //审批日志
  2666. if (!isset($verifyStaff['final'])){
  2667. Doo::loadModel("receiptLog");
  2668. $receiptLog=new receiptLog();
  2669. if (!empty($roleId)){
  2670. Doo::loadModel("role");
  2671. $role=new role();
  2672. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2673. $receiptLog->rolename=$roleInfo['name'];
  2674. }
  2675. $receiptLog->username=$this->staff[0]['username'];
  2676. $receiptLog->uid=$this->staff[0]['sid'];
  2677. $receiptLog->date=date("Y-m-d");
  2678. $receiptLog->opinion=$opinion;
  2679. $receiptLog->img=$this->staff[0]['avatar'];
  2680. $receiptLog->status=1;
  2681. $receiptLog->rid=$rid;
  2682. $receiptLog->insert();
  2683. }
  2684. if (isset($verifyStaff['final'])){//rDetail
  2685. $receipt->status=3;
  2686. $receipt->verifyBreakup=$verifyString;
  2687. $receiptDetailObj->status=3;
  2688. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2689. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2690. $receipt->status=6;
  2691. $receipt->pastDate=date("Y-m-d");
  2692. $receipt->isBK=1;
  2693. $loanReceipt->verifyBreakup=$verifyString;
  2694. $loanReceipt->status=1;
  2695. $loanReceipt->pastDate=date("Y-m-d");
  2696. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2697. }
  2698. $receipt->update(array('where'=>' rid = '.$rid));
  2699. return "/approvalExpenses/2";
  2700. }
  2701. }
  2702. function implement(){
  2703. Doo::loadModel('receipt');
  2704. $receipt=new receipt();
  2705. Doo::loadModel('L_category');
  2706. $Lcategory=new L_category();
  2707. Doo::loadModel('verify');
  2708. $verify=new verify();
  2709. Doo::loadModel('staff');
  2710. $staff=new staff();
  2711. Doo::loadModel("execute");
  2712. $execute=new execute();
  2713. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2714. Doo::loadModel('loanReceipt');
  2715. $loanReceipt=new loanReceipt();
  2716. //print_r($receiptList);
  2717. $loanList=array();
  2718. if (!isset($receiptList))
  2719. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2720. $Locate=0;$roleId=0;$button=0;
  2721. foreach ($loanList as $key=>$value){
  2722. $loanList[$key]['Locate']=$Locate;$Locate++;
  2723. $loanList[$key]['reviseDetail']=array();
  2724. if (!empty($value['reviseDetail']))
  2725. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2726. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2727. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2728. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2729. $loanList[$key]['category']=$categoryDetil['title'];
  2730. //检测编辑状态
  2731. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2732. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2733. $verifyStaff=json_decode($value['verifyStaff'],true);
  2734. Doo::loadModel('role');
  2735. $role=new role();
  2736. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2737. foreach ($verifyList as $k=>$v){
  2738. //init verifyStaff
  2739. if ($v[1]=='ROLE'){
  2740. if (!empty($verifyStaff)){
  2741. $endStaffArray=end($verifyStaff);
  2742. // if ($v[0]==$endStaffArray['nextStaff']){
  2743. // $roleId=$v[0];
  2744. // }
  2745. }
  2746. $roleVerify=json_decode($v[3],true);
  2747. $roleKey=$k;$roleArray=array();
  2748. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2749. foreach ($roleVerify as $o=>$p){
  2750. $staffID=explode ('_',$p);
  2751. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2752. //print_r($staffID);
  2753. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2754. array_push($roleArray, $exp);
  2755. }
  2756. $roleArrayCopy[$v[0]]=$roleArray;
  2757. //$verifyList[$k]['roleArray']=$roleArray;
  2758. }
  2759. $verifyList[$k]['date']="";
  2760. $verifyList[$k]['opinion']="";
  2761. $verifyList[$k]['status']="";
  2762. if (empty($verifyStaff)){
  2763. $verifyList[$k]['date']="";
  2764. $verifyList[$k]['opinion']="";
  2765. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2766. $verifyList[$k]['status']=4;
  2767. $flag=false;
  2768. }
  2769. }else{
  2770. foreach ($verifyStaff as $m=>$u){
  2771. if ($v[0]==$m){
  2772. $verifyList[$k]['date']=$u['date'];
  2773. $verifyList[$k]['opinion']=$u['opinion'];
  2774. $verifyList[$k]['status']=$u['status'];
  2775. $flag=false;
  2776. break;
  2777. }
  2778. }
  2779. $endStaffArray=end($verifyStaff);
  2780. if (isset($endStaffArray['ROLE'])){
  2781. }else{
  2782. // $endKey=key($verifyStaff);
  2783. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2784. // $button=4;
  2785. // $verifyList[$k]['status']=4;
  2786. // }
  2787. }
  2788. }
  2789. }
  2790. $rolename['name']='';
  2791. if (!empty($roleId)){
  2792. Doo::loadModel('role');
  2793. $role=new role();
  2794. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2795. }
  2796. if (!empty($verifyStaff))
  2797. $endStaffArray=end($verifyStaff);
  2798. $KOP=false;
  2799. foreach ($roleArrayCopy as $P=>$A){
  2800. foreach ( $A as $MKI=>$AVL){
  2801. if (!empty($verifyStaff)){
  2802. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2803. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2804. $button=4;
  2805. $roleArrayCopy[$P][$MKI]['status']=4;
  2806. }
  2807. foreach ($verifyStaff as $m=>$u){
  2808. $AVLFK=$AVL[0].'_R';
  2809. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2810. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2811. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2812. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2813. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2814. break;
  2815. }
  2816. }
  2817. }else{
  2818. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2819. $button=4;
  2820. $roleArrayCopy[$P][$MKI]['status']=4;
  2821. }
  2822. }
  2823. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2824. $KOP=true;
  2825. }
  2826. }
  2827. foreach ($roleArrayCopy as $k=>$v){
  2828. foreach ($verifyList as $m=>$n){
  2829. if ($n[0]==$k){
  2830. array_splice($verifyList,$m,1,$v);
  2831. }
  2832. }
  2833. }
  2834. $loanList[$key]['verifyList']=$verifyList;
  2835. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2836. }
  2837. $data['loanList']=$loanList;
  2838. $Locate=0;$roleId=0;$button=0;
  2839. foreach ($receiptList as $key=>$value){
  2840. $button2=0;
  2841. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2842. $receiptList[$key]['reviseDetail']=array();
  2843. if (!empty($value['reviseDetail']))
  2844. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2845. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2846. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2847. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2848. $receiptList[$key]['category']=$categoryDetil['title'];
  2849. $executeList=json_decode($value['executeCopy'],true);
  2850. $executeStaff=array();
  2851. if (!empty($value['executeStaff'] ))
  2852. $executeStaff=json_decode($value['executeStaff'],true);
  2853. if (isset($executeList)){
  2854. foreach ($executeList as $op=>$lo){
  2855. $executeList[$op]['date']="";
  2856. $executeList[$op]['opinion']="";
  2857. $executeList[$op]['status']="";
  2858. foreach ($executeStaff as $m=>$u){
  2859. if ($lo[0]==$m){
  2860. $executeList[$op]['date']=$u['date'];
  2861. $executeList[$op]['opinion']=$u['opinion'];
  2862. $executeList[$op]['status']=$u['status'];
  2863. break;
  2864. }
  2865. }
  2866. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2867. $button2=1;
  2868. $executeList[$op]['status']=4;
  2869. }
  2870. }
  2871. }
  2872. //检测编辑状态
  2873. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2874. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2875. $verifyStaff=json_decode($value['verifyStaff'],true);
  2876. Doo::loadModel('role');
  2877. $role=new role();
  2878. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2879. foreach ($verifyList as $k=>$v){
  2880. //init verifyStaff
  2881. if ($v[1]=='ROLE'){
  2882. if (!empty($verifyStaff)){
  2883. $endStaffArray=end($verifyStaff);
  2884. // if ($v[0]==$endStaffArray['nextStaff']){
  2885. // $roleId=$v[0];
  2886. // }
  2887. }
  2888. $roleVerify=json_decode($v[3],true);
  2889. $roleKey=$k;$roleArray=array();
  2890. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2891. foreach ($roleVerify as $o=>$p){
  2892. $staffID=explode ('_',$p);
  2893. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2894. //print_r($staffID);
  2895. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2896. array_push($roleArray, $exp);
  2897. }
  2898. $roleArrayCopy[$v[0]]=$roleArray;
  2899. //$verifyList[$k]['roleArray']=$roleArray;
  2900. }
  2901. $verifyList[$k]['date']="";
  2902. $verifyList[$k]['opinion']="";
  2903. $verifyList[$k]['status']="";
  2904. if (empty($verifyStaff)){
  2905. $verifyList[$k]['date']="";
  2906. $verifyList[$k]['opinion']="";
  2907. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2908. $verifyList[$k]['status']=4;
  2909. $flag=false;
  2910. }
  2911. }else{
  2912. foreach ($verifyStaff as $m=>$u){
  2913. if ($v[0]==$m){
  2914. $verifyList[$k]['date']=$u['date'];
  2915. $verifyList[$k]['opinion']=$u['opinion'];
  2916. $verifyList[$k]['status']=$u['status'];
  2917. $flag=false;
  2918. break;
  2919. }
  2920. }
  2921. $endStaffArray=end($verifyStaff);
  2922. if (isset($endStaffArray['ROLE'])){
  2923. }else{
  2924. }
  2925. }
  2926. }
  2927. $rolename['name']='';
  2928. if (!empty($roleId)){
  2929. Doo::loadModel('role');
  2930. $role=new role();
  2931. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2932. }
  2933. if (!empty($verifyStaff))
  2934. $endStaffArray=end($verifyStaff);
  2935. $KOP=false;
  2936. foreach ($roleArrayCopy as $P=>$A){
  2937. foreach ( $A as $MKI=>$AVL){
  2938. if (!empty($verifyStaff)){
  2939. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2940. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2941. $button=4;
  2942. $roleArrayCopy[$P][$MKI]['status']=4;
  2943. }
  2944. foreach ($verifyStaff as $m=>$u){
  2945. $AVLFK=$AVL[0].'_R';
  2946. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2947. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2948. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2949. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2950. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2951. break;
  2952. }
  2953. }
  2954. }else{
  2955. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2956. $button=4;
  2957. $roleArrayCopy[$P][$MKI]['status']=4;
  2958. }
  2959. }
  2960. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2961. $KOP=true;
  2962. }
  2963. }
  2964. foreach ($roleArrayCopy as $k=>$v){
  2965. foreach ($verifyList as $m=>$n){
  2966. if ($n[0]==$k){
  2967. array_splice($verifyList,$m,1,$v);
  2968. }
  2969. }
  2970. }
  2971. $receiptList[$key]['executeList']=$executeList;
  2972. $receiptList[$key]['verifyList']=$verifyList;
  2973. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2974. $receiptList[$key]['button2']=$button2;
  2975. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2976. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2977. $relust=$value['sum']-$value['loanSum'];
  2978. $receiptList[$key]['relust']=$relust;
  2979. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2980. }
  2981. //print_r($receiptList[$key]['executeList']);
  2982. $data['receiptList']=$receiptList;
  2983. $data['memu']="receipt";
  2984. $data['staff']=$this->staff;
  2985. $data['receiptMemu']='implement';
  2986. $data['verifyId']=$this->verifyId;
  2987. $data['executeId']=$this->executeId;
  2988. $this->render ( "/admin/implement", $data );
  2989. }
  2990. function implementDo(){
  2991. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2992. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2993. if (!empty($rid)){
  2994. Doo::loadModel('receipt');
  2995. $receipt=new receipt();
  2996. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2997. $executeCopy=json_decode($rinfo['executeCopy'],true);
  2998. $executeStaff=json_decode($rinfo['executeStaff'],true);
  2999. if(empty($executeStaff)){
  3000. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3001. }else{
  3002. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3003. }
  3004. if (count($executeStaff)==count($executeCopy)){
  3005. $receipt->executeStaff=json_encode($executeStaff);
  3006. $receipt->status=8;
  3007. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3008. $receipt->status=9;
  3009. $receipt->executeDate= date("Y-m-d");
  3010. }else{
  3011. $receipt->executeStaff=json_encode($executeStaff);
  3012. }
  3013. $receipt->update(array('where'=>'rid='.$rid));
  3014. }
  3015. return "/implement";
  3016. }
  3017. function receiptburEdi(){
  3018. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3019. $status=isset($this->params['status'])?$this->params['status']:'';
  3020. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3021. $month=$this->get_args('month')?$this->get_args('month'):"";
  3022. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3023. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3024. if (empty($status))
  3025. $status=$this->get_args('status')?$this->get_args('status'):2;
  3026. $vidList=array();
  3027. $button=0;
  3028. Doo::loadModel('verify');
  3029. Doo::loadModel('receipt');
  3030. Doo::loadModel('staff');
  3031. $staff=new staff();
  3032. $receipt=new receipt();
  3033. $verify=new verify();
  3034. Doo::loadModel('L_category');
  3035. $Lcategory=new L_category();
  3036. Doo::loadModel('enclosur');
  3037. $enclosur=new enclosur();
  3038. Doo::loadModel('loanReceipt');
  3039. $loanReceipt=new loanReceipt();
  3040. //user verify ID
  3041. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3042. foreach ($verifyDetail as $key=>$value){
  3043. array_push($vidList, $value['vid']);
  3044. }
  3045. $vid=implode(",", $vidList);
  3046. if(empty($verifyDetail))
  3047. $vid=0;
  3048. $categoryList=$Lcategory->find(array('asArray'=>true));
  3049. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3050. $ap="";
  3051. if($status==4){
  3052. $ap=4;$status=2;
  3053. }
  3054. //get Receipt By verifyID status 2
  3055. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3056. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3057. $Locate=0;$roleId=0;$button=0;
  3058. foreach ($loanList as $key=>$value){
  3059. $loanList[$key]['Locate']=$Locate;$Locate++;
  3060. $loanList[$key]['reviseDetail']=array();
  3061. if (!empty($value['reviseDetail']))
  3062. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3063. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3064. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3065. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3066. $loanList[$key]['category']=$categoryDetil['title'];
  3067. //检测编辑状态
  3068. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3069. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3070. $verifyStaff=json_decode($value['verifyStaff'],true);
  3071. Doo::loadModel('role');
  3072. $role=new role();
  3073. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3074. foreach ($verifyList as $k=>$v){
  3075. //init verifyStaff
  3076. if ($v[1]=='ROLE'){
  3077. if (!empty($verifyStaff)){
  3078. $endStaffArray=end($verifyStaff);
  3079. }
  3080. $roleVerify=json_decode($v[3],true);
  3081. $roleKey=$k;$roleArray=array();
  3082. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3083. foreach ($roleVerify as $o=>$p){
  3084. $staffID=explode ('_',$p);
  3085. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3086. //print_r($staffID);
  3087. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3088. array_push($roleArray, $exp);
  3089. }
  3090. $roleArrayCopy[$v[0]]=$roleArray;
  3091. //$verifyList[$k]['roleArray']=$roleArray;
  3092. }
  3093. $verifyList[$k]['date']="";
  3094. $verifyList[$k]['opinion']="";
  3095. $verifyList[$k]['status']="";
  3096. if (empty($verifyStaff)){
  3097. $verifyList[$k]['date']="";
  3098. $verifyList[$k]['opinion']="";
  3099. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3100. $verifyList[$k]['status']=4;
  3101. $flag=false;
  3102. }
  3103. }else{
  3104. foreach ($verifyStaff as $m=>$u){
  3105. if ($v[0]==$m){
  3106. $verifyList[$k]['date']=$u['date'];
  3107. $verifyList[$k]['opinion']=$u['opinion'];
  3108. $verifyList[$k]['status']=$u['status'];
  3109. $flag=false;
  3110. break;
  3111. }
  3112. }
  3113. $endStaffArray=end($verifyStaff);
  3114. if (isset($endStaffArray['ROLE'])){
  3115. }else{
  3116. }
  3117. }
  3118. }
  3119. $rolename['name']='';
  3120. if (!empty($roleId)){
  3121. Doo::loadModel('role');
  3122. $role=new role();
  3123. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3124. }
  3125. if (!empty($verifyStaff))
  3126. $endStaffArray=end($verifyStaff);
  3127. $KOP=false;
  3128. foreach ($roleArrayCopy as $P=>$A){
  3129. foreach ( $A as $MKI=>$AVL){
  3130. if (!empty($verifyStaff)){
  3131. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3132. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3133. $button=4;
  3134. $roleArrayCopy[$P][$MKI]['status']=4;
  3135. }
  3136. foreach ($verifyStaff as $m=>$u){
  3137. $AVLFK=$AVL[0].'_R';
  3138. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3139. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3140. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3141. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3142. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3143. break;
  3144. }
  3145. }
  3146. }else{
  3147. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3148. $button=4;
  3149. $roleArrayCopy[$P][$MKI]['status']=4;
  3150. }
  3151. }
  3152. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3153. $KOP=true;
  3154. }
  3155. }
  3156. foreach ($roleArrayCopy as $k=>$v){
  3157. foreach ($verifyList as $m=>$n){
  3158. if ($n[0]==$k){
  3159. array_splice($verifyList,$m,1,$v);
  3160. }
  3161. }
  3162. }
  3163. $loanList[$key]['verifyList']=$verifyList;
  3164. }
  3165. $htmlLoan='';
  3166. if (isset($loanList[0])){
  3167. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3168. if ($value['status']==1)
  3169. $htmlLoan.='<li class="done" >';
  3170. elseif ($value['status']==3)
  3171. $htmlLoan.='<li class="undone" >';
  3172. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3173. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3174. if (isset($value['rolename']))
  3175. $htmlLoan.=$value['rolename'];
  3176. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3177. }
  3178. $data['loanDate']=$loanList[0]['date'];
  3179. }
  3180. $data['htmlLoan']=$htmlLoan;
  3181. /*
  3182. <!-- loop loanList.0.verifyList -->
  3183. <li <!-- if {{loanList' value.status}}==1 --> class="done" <!-- elseif {{loanList' value.status}}==3 --> class="undone" <!-- endif -->>
  3184. <div class="avtra"><img src="{{loanList' value.2}}_2.jpg"></div>
  3185. <div class="comment">
  3186. <p class="colGray"><span class="fR">{{loanList' value.date}}</span>{{loanList' value.1}}<!-- if isset({{loanList' value.rolename}}) --> ({{loanList' value.rolename}}) <!-- endif --></p>
  3187. <p>{{loanList' value.opinion}}</p>
  3188. </div>
  3189. </li>
  3190. <!-- endloop -->
  3191. */
  3192. //print_r($loanList);
  3193. $Locate=0;$roleId=0;
  3194. if($ap==4)
  3195. $status=4;
  3196. foreach ($receiptList as $key=>$value){
  3197. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3198. $receiptList[$key]['reviseDetail']=array();
  3199. if (!empty($value['reviseDetail']))
  3200. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3201. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3202. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3203. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3204. $receiptList[$key]['category']=$categoryDetil['title'];
  3205. //检测编辑状态
  3206. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3207. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3208. $verifyStaff=json_decode($value['verifyStaff'],true);
  3209. Doo::loadModel('role');
  3210. $role=new role();
  3211. //print_r($verifyList);
  3212. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3213. foreach ($verifyList as $k=>$v){
  3214. //init verifyStaff
  3215. if ($v[1]=='ROLE'){
  3216. if (!empty($verifyStaff)){
  3217. $endStaffArray=end($verifyStaff);
  3218. if ($v[0]==$endStaffArray['nextStaff']){
  3219. $roleId=$v[0];
  3220. }
  3221. }
  3222. $roleVerify=json_decode($v[3],true);
  3223. $roleKey=$k;$roleArray=array();
  3224. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3225. foreach ($roleVerify as $o=>$p){
  3226. $staffID=explode ('_',$p);
  3227. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3228. //print_r($staffID);
  3229. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3230. array_push($roleArray, $exp);
  3231. }
  3232. $roleArrayCopy[$v[0]]=$roleArray;
  3233. //$verifyList[$k]['roleArray']=$roleArray;
  3234. }
  3235. //print_r($roleArray);
  3236. $verifyList[$k]['date']="";
  3237. $verifyList[$k]['opinion']="";
  3238. $verifyList[$k]['status']="";
  3239. if (empty($verifyStaff)){
  3240. $verifyList[$k]['date']="";
  3241. $verifyList[$k]['opinion']="";
  3242. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3243. $verifyList[$k]['status']=4;
  3244. $button=4;$flag=false;
  3245. }
  3246. }else{
  3247. foreach ($verifyStaff as $m=>$u){
  3248. if ($v[0]==$m){
  3249. $verifyList[$k]['date']=$u['date'];
  3250. $verifyList[$k]['opinion']=$u['opinion'];
  3251. $verifyList[$k]['status']=$u['status'];
  3252. $flag=false;
  3253. break;
  3254. }
  3255. }
  3256. $endStaffArray=end($verifyStaff);
  3257. if (isset($endStaffArray['ROLE'])){
  3258. }else{
  3259. $endKey=key($verifyStaff);
  3260. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3261. $button=4;
  3262. $verifyList[$k]['status']=4;
  3263. }
  3264. }
  3265. }
  3266. }
  3267. $rolename['name']='';
  3268. if (!empty($roleId)){
  3269. Doo::loadModel('role');
  3270. $role=new role();
  3271. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3272. }
  3273. if (!empty($verifyStaff))
  3274. $endStaffArray=end($verifyStaff);
  3275. $KOP=false;
  3276. foreach ($roleArrayCopy as $P=>$A){
  3277. foreach ( $A as $MKI=>$AVL){
  3278. if (!empty($verifyStaff)){
  3279. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3280. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3281. $button=4;
  3282. $roleArrayCopy[$P][$MKI]['status']=4;
  3283. }
  3284. foreach ($verifyStaff as $m=>$u){
  3285. $AVLFK=$AVL[0].'_R';
  3286. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3287. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3288. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3289. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3290. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3291. break;
  3292. }
  3293. }
  3294. }else{
  3295. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3296. $button=4;
  3297. $roleArrayCopy[$P][$MKI]['status']=4;
  3298. }
  3299. }
  3300. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3301. $KOP=true;
  3302. }
  3303. }
  3304. foreach ($roleArrayCopy as $k=>$v){
  3305. foreach ($verifyList as $m=>$n){
  3306. if ($n[0]==$k){
  3307. array_splice($verifyList,$m,1,$v);
  3308. }
  3309. }
  3310. }
  3311. //print_r($verifyList);
  3312. $receiptList[$key]['verifyList']=$verifyList;
  3313. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3314. $receiptList[$key]['button']=$button;
  3315. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3316. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3317. $relust=$value['sum']-$value['loanSum'];
  3318. $receiptList[$key]['relust']=$relust;
  3319. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3320. }
  3321. //$data['verifyDetail']=$verifyDetail;
  3322. $mothHtml="";
  3323. for($i=1;$i<=12;$i++){
  3324. if($month==$i)
  3325. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3326. else
  3327. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3328. }
  3329. //获取审批日志
  3330. Doo::loadModel('receiptLog');
  3331. $receiptLog=new receiptLog();
  3332. $rlList=array();
  3333. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3334. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3335. if (!empty($rlInfo)){
  3336. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3337. }
  3338. //echo $rid;
  3339. //print_r($receiptList);
  3340. $receiptList[0]['rlList']=$rlList;
  3341. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3342. $enclosurHtml='';
  3343. foreach ($enclosurList as $value){
  3344. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3345. }
  3346. $data['enclosurHtml']=$enclosurHtml;
  3347. $data['rolename']=$rolename['name'];
  3348. // $data['datetij']=$tijdate['date'];
  3349. $data['mothHtml']=$mothHtml;
  3350. //print_r($receiptList);
  3351. $data['rid']=$rid;
  3352. $data['tijdate']=$tijdate['date'];
  3353. $data['receiptList']=$receiptList;
  3354. $data['receiptApprovalCount']=count($receiptList);
  3355. $data['status']=$status;
  3356. $data['year']=$year;
  3357. $data['categoryList']=$categoryList;
  3358. $data['staffList']=$staffList;
  3359. $data['cid']=$cid;
  3360. $data['sid']=$sid;
  3361. $data['ap']=$ap;
  3362. $data['memu']="receipt";
  3363. $data['staff']=$this->staff;
  3364. $data['receiptMemu']='approvalExpenses';
  3365. $data['verifyId']=$this->verifyId;
  3366. $data['executeId']=$this->executeId;
  3367. $this->render ( "/admin/receiptburEdi", $data );
  3368. }
  3369. function hisImplement(){
  3370. $item=isset($this->params['item'])?$this->params['item']:"";
  3371. if(empty($item))
  3372. $item=$this->get_args('item')?$this->get_args('item'):"";
  3373. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3374. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3375. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3376. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3377. Doo::loadModel('receipt');
  3378. $receipt=new receipt();
  3379. Doo::loadModel('L_category');
  3380. $Lcategory=new L_category();
  3381. Doo::loadModel('verify');
  3382. Doo::loadModel('statistics');
  3383. $statistics=new statistics();
  3384. $verify=new verify();
  3385. Doo::loadModel('staff');
  3386. $staff=new staff();
  3387. $condition="";
  3388. if($item=="expenses")
  3389. $condition=" and Rtype=1 ";
  3390. elseif ($item=="receipts")
  3391. $condition=" and Rtype=0 ";
  3392. elseif ($item=="remits")
  3393. $condition=" and Rtype=2 ";
  3394. $sopString="";
  3395. $dateCondition=" and Year(executeDate) =".$year;
  3396. if($moth!='MONTH'){
  3397. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3398. }
  3399. if($day!='DAY')
  3400. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3401. if ($sop!='SOP')
  3402. $sopString=" and staff=".$sop;
  3403. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3404. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3405. //员工筛选
  3406. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3407. $sopStaff=array();
  3408. foreach ($receiptList2 as $key=>$value){
  3409. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3410. $sopStaff[$value['staff']]=$staffDetail['username'];
  3411. }
  3412. $Locate=0;$roleId=0;$button=0;
  3413. foreach ($receiptList as $key=>$value){
  3414. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3415. $receiptList[$key]['reviseDetail']=array();
  3416. if (!empty($value['reviseDetail']))
  3417. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3418. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3419. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3420. $receiptList[$key]['category']=$categoryDetil['title'];
  3421. //检测编辑状态
  3422. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3423. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3424. $verifyStaff=json_decode($value['verifyStaff'],true);
  3425. Doo::loadModel('role');
  3426. $role=new role();
  3427. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3428. foreach ($verifyList as $k=>$v){
  3429. //init verifyStaff
  3430. if ($v[1]=='ROLE'){
  3431. if (!empty($verifyStaff)){
  3432. $endStaffArray=end($verifyStaff);
  3433. }
  3434. $roleVerify=json_decode($v[3],true);
  3435. $roleKey=$k;$roleArray=array();
  3436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3437. foreach ($roleVerify as $o=>$p){
  3438. $staffID=explode ('_',$p);
  3439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3440. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3441. array_push($roleArray, $exp);
  3442. }
  3443. $roleArrayCopy[$v[0]]=$roleArray;
  3444. }
  3445. $verifyList[$k]['date']="";
  3446. $verifyList[$k]['opinion']="";
  3447. $verifyList[$k]['status']="";
  3448. if (empty($verifyStaff)){
  3449. $verifyList[$k]['date']="";
  3450. $verifyList[$k]['opinion']="";
  3451. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3452. $verifyList[$k]['status']=4;
  3453. $flag=false;
  3454. }
  3455. }else{
  3456. foreach ($verifyStaff as $m=>$u){
  3457. if ($v[0]==$m){
  3458. $verifyList[$k]['date']=$u['date'];
  3459. $verifyList[$k]['opinion']=$u['opinion'];
  3460. $verifyList[$k]['status']=$u['status'];
  3461. $flag=false;
  3462. break;
  3463. }
  3464. }
  3465. $endStaffArray=end($verifyStaff);
  3466. }
  3467. }
  3468. $rolename['name']='';
  3469. if (!empty($roleId)){
  3470. Doo::loadModel('role');
  3471. $role=new role();
  3472. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3473. }
  3474. if (!empty($verifyStaff))
  3475. $endStaffArray=end($verifyStaff);
  3476. $KOP=false;
  3477. foreach ($roleArrayCopy as $P=>$A){
  3478. foreach ( $A as $MKI=>$AVL){
  3479. if (!empty($verifyStaff)){
  3480. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3481. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3482. $button=4;
  3483. $roleArrayCopy[$P][$MKI]['status']=4;
  3484. }
  3485. foreach ($verifyStaff as $m=>$u){
  3486. $AVLFK=$AVL[0].'_R';
  3487. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3488. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3489. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3490. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3491. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3492. break;
  3493. }
  3494. }
  3495. }else{
  3496. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3497. $button=4;
  3498. $roleArrayCopy[$P][$MKI]['status']=4;
  3499. }
  3500. }
  3501. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3502. $KOP=true;
  3503. }
  3504. }
  3505. foreach ($roleArrayCopy as $k=>$v){
  3506. foreach ($verifyList as $m=>$n){
  3507. if ($n[0]==$k){
  3508. array_splice($verifyList,$m,1,$v);
  3509. }
  3510. }
  3511. }
  3512. $receiptList[$key]['verifyList']=$verifyList;
  3513. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3514. $receiptList[$key]['button']=$button;
  3515. }
  3516. //print_r($sopStaff);
  3517. $mothHtml="";
  3518. for($i=1;$i<=12;$i++){
  3519. if($moth==$i)
  3520. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3521. else
  3522. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3523. }
  3524. $dayHtml="";
  3525. if ($day!="DAY"||$moth!="MONTH"){
  3526. for($i = 1; $i <= 31; $i ++) {
  3527. if($day==$i)
  3528. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3529. else
  3530. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3531. }
  3532. }
  3533. $sopHtml="";
  3534. foreach ($sopStaff as $key=>$value){
  3535. if($sop==$key)
  3536. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3537. else
  3538. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3539. }
  3540. $data['sopHtml']=$sopHtml;
  3541. $data['dayHtml']=$dayHtml;
  3542. $data['mothHtml']=$mothHtml;
  3543. $data['receiptList']=$receiptList;
  3544. $data['memu']="receipt";
  3545. $data['staff']=$this->staff;
  3546. $data['receiptMemu']='implement';
  3547. $data['verifyId']=$this->verifyId;
  3548. $data['executeId']=$this->executeId;
  3549. $data['item']=$item;
  3550. $data['year']=$year;
  3551. $data['moth']=$moth;
  3552. $data['day']=$day;
  3553. $data['sop']=$sop;
  3554. $this->render ( "/admin/hisImplement", $data );
  3555. }
  3556. function ajaxExamine(){
  3557. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3558. Doo::loadModel('receipt');
  3559. $receipt=new receipt();
  3560. if (!empty($rid)){
  3561. $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
  3562. ,'asArray'=>true));
  3563. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3564. }
  3565. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3566. }
  3567. function myReceipt(){
  3568. //all approval past withdraw
  3569. $item=isset($this->params['item'])?$this->params['item']:"";
  3570. if(empty($item))
  3571. $item=$this->get_args('item')?$this->get_args('item'):"";
  3572. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3573. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3574. Doo::loadModel('receipt');
  3575. $receipt=new receipt();
  3576. //pre-loaded
  3577. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3578. //have cache
  3579. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3580. if(!empty($moth))//yearPage
  3581. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3582. $this->showCache($path);
  3583. }
  3584. Doo::loadModel('L_category');
  3585. $Lcategory=new L_category();
  3586. Doo::loadModel('verify');
  3587. Doo::loadModel('statistics');
  3588. $statistics=new statistics();
  3589. $verify=new verify();
  3590. Doo::loadModel('staff');
  3591. $staff=new staff();
  3592. $condition=" and status!=0 ";
  3593. if($item=="approval")
  3594. $condition=" and status=2 ";
  3595. elseif ($item=="withdraw")
  3596. $condition=" and status=3 ";
  3597. elseif ($item=="past")
  3598. $condition=" and status=1 ";
  3599. elseif ($item=="whdw")
  3600. $condition=" and status=4 ";
  3601. $dateCondition=" and Year(date) =".$year;
  3602. if(!empty($moth)){
  3603. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3604. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3605. }else
  3606. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3607. if(empty($stList))
  3608. $stList=array('rePrice'=>0,'agPrice'=>0);
  3609. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3610. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3611. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3612. $Locate=0;$roleId=0;$button=0;
  3613. foreach ($receiptList as $key=>$value){
  3614. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3615. $receiptList[$key]['reviseDetail']=array();
  3616. if (!empty($value['reviseDetail']))
  3617. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3618. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3619. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3620. $receiptList[$key]['category']=$categoryDetil['title'];
  3621. //检测编辑状态
  3622. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3623. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3624. $verifyStaff=json_decode($value['verifyStaff'],true);
  3625. Doo::loadModel('role');
  3626. $role=new role();
  3627. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3628. foreach ($verifyList as $k=>$v){
  3629. //init verifyStaff
  3630. if ($v[1]=='ROLE'){
  3631. if (!empty($verifyStaff)){
  3632. $endStaffArray=end($verifyStaff);
  3633. // if ($v[0]==$endStaffArray['nextStaff']){
  3634. // $roleId=$v[0];
  3635. // }
  3636. }
  3637. $roleVerify=json_decode($v[3],true);
  3638. $roleKey=$k;$roleArray=array();
  3639. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3640. foreach ($roleVerify as $o=>$p){
  3641. $staffID=explode ('_',$p);
  3642. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3643. //print_r($staffID);
  3644. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3645. array_push($roleArray, $exp);
  3646. }
  3647. $roleArrayCopy[$v[0]]=$roleArray;
  3648. //$verifyList[$k]['roleArray']=$roleArray;
  3649. }
  3650. $verifyList[$k]['date']="";
  3651. $verifyList[$k]['opinion']="";
  3652. $verifyList[$k]['status']="";
  3653. if (empty($verifyStaff)){
  3654. $verifyList[$k]['date']="";
  3655. $verifyList[$k]['opinion']="";
  3656. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3657. $verifyList[$k]['status']=4;
  3658. $flag=false;
  3659. }
  3660. }else{
  3661. foreach ($verifyStaff as $m=>$u){
  3662. if ($v[0]==$m){
  3663. $verifyList[$k]['date']=$u['date'];
  3664. $verifyList[$k]['opinion']=$u['opinion'];
  3665. $verifyList[$k]['status']=$u['status'];
  3666. $flag=false;
  3667. break;
  3668. }
  3669. }
  3670. $endStaffArray=end($verifyStaff);
  3671. if (isset($endStaffArray['ROLE'])){
  3672. }else{
  3673. // $endKey=key($verifyStaff);
  3674. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3675. // $button=4;
  3676. // $verifyList[$k]['status']=4;
  3677. // }
  3678. }
  3679. }
  3680. }
  3681. $rolename['name']='';
  3682. if (!empty($roleId)){
  3683. Doo::loadModel('role');
  3684. $role=new role();
  3685. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3686. }
  3687. if (!empty($verifyStaff))
  3688. $endStaffArray=end($verifyStaff);
  3689. $KOP=false;
  3690. foreach ($roleArrayCopy as $P=>$A){
  3691. foreach ( $A as $MKI=>$AVL){
  3692. if (!empty($verifyStaff)){
  3693. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3694. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3695. $button=4;
  3696. $roleArrayCopy[$P][$MKI]['status']=4;
  3697. }
  3698. foreach ($verifyStaff as $m=>$u){
  3699. $AVLFK=$AVL[0].'_R';
  3700. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3701. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3702. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3703. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3704. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3705. break;
  3706. }
  3707. }
  3708. }else{
  3709. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3710. $button=4;
  3711. $roleArrayCopy[$P][$MKI]['status']=4;
  3712. }
  3713. }
  3714. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3715. $KOP=true;
  3716. }
  3717. }
  3718. foreach ($roleArrayCopy as $k=>$v){
  3719. foreach ($verifyList as $m=>$n){
  3720. if ($n[0]==$k){
  3721. array_splice($verifyList,$m,1,$v);
  3722. }
  3723. }
  3724. }
  3725. $receiptList[$key]['verifyList']=$verifyList;
  3726. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3727. $receiptList[$key]['button']=$button;
  3728. }
  3729. //print_r($receiptList);die;
  3730. $mothHtml="";
  3731. for($i=1;$i<=12;$i++){
  3732. if($moth==$i)
  3733. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3734. else
  3735. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3736. }
  3737. $data['mothHtml']=$mothHtml;
  3738. $data['receiptList']=$receiptList;
  3739. $data['memu']="receipt";
  3740. $data['staff']=$this->staff;
  3741. $data['receiptMemu']='receipt';
  3742. $data['verifyId']=$this->verifyId;
  3743. $data['executeId']=$this->executeId;
  3744. $data['item']=$item;
  3745. $data['year']=$year;
  3746. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3747. //sufficient condition to generate cache
  3748. if(empty($moth)&&($year<date("Y"))){
  3749. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3750. if(empty($receiptList)){ //generated files
  3751. ob_start();
  3752. $this->render ( "/admin/saea_myList", $data );
  3753. $this->cacheFile($path);die;
  3754. // $content = ob_get_contents();
  3755. // $fp = fopen($path, "w");
  3756. // fwrite($fp, $content);
  3757. // fclose($fp);
  3758. }
  3759. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3760. $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));
  3761. if(empty($receiptList)){ //generated files
  3762. ob_start();
  3763. $this->render ( "/admin/saea_myList", $data );
  3764. $this->cacheFile($path);die;
  3765. }
  3766. }
  3767. }
  3768. $this->render ( "/admin/saea_myList", $data );
  3769. }
  3770. function saeaCreate(){
  3771. Doo::loadModel('accountItem');
  3772. Doo::loadModel('verify');
  3773. Doo::loadModel('receipt');
  3774. Doo::loadModel('L_category');
  3775. $lCategory=new L_category();
  3776. $receipt=new receipt();
  3777. $verify=new verify();
  3778. $accountItem=new accountItem();
  3779. Doo::loadModel("role");
  3780. $role=new role();
  3781. $acItem=$accountItem->find(array('asArray'=>true));
  3782. $veList=$verify->find(array('asArray'=>true));
  3783. foreach ($veList as $key=>$value){
  3784. $v=json_decode($value['staff']);
  3785. $list=array();
  3786. foreach ($v as $n=>$m){
  3787. if ($m['1']=='ROLE'){
  3788. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3789. $v[$n][1]=$roleInfo['name'];
  3790. array_push($list, $roleInfo['name']);
  3791. }else{
  3792. array_push($list, $v[$n][1]);
  3793. }
  3794. }
  3795. $veList[$key]['staff']=implode('>', $list);
  3796. }
  3797. $data['category']=$lCategory->find(array('asArray'=>true));
  3798. $data['veList']=$veList;
  3799. $data['acItem']=$acItem;
  3800. $data['memu']="receipt";
  3801. $data['staff']=$this->staff;
  3802. $data['receiptMemu']='saeaBorad';
  3803. $data['verifyId']=$this->verifyId;
  3804. $data['executeId']=$this->executeId;
  3805. $this->render ( "/admin/saea_create", $data );
  3806. }
  3807. function addReceipt(){
  3808. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3809. $agency=$this->get_args('agency');
  3810. $travel=$this->get_args('travel');
  3811. $train=$this->get_args('train');
  3812. $other=$this->get_args('other');
  3813. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3814. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3815. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3816. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3817. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3818. Doo::loadModel('receipt');
  3819. Doo::loadModel('receiptDetail');
  3820. Doo::loadModel('accountItem');
  3821. $accountItem=new accountItem();
  3822. $receipt=new receipt();
  3823. Doo::loadModel('enclosur');
  3824. Doo::loadModel('execute');
  3825. $execute=new execute();
  3826. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3827. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3828. // if(!empty($receiptDetail))
  3829. // return "/referReceipt/".$receiptDetail['rid'];
  3830. $aItem=$accountItem->find(array('asArray'=>true));
  3831. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3832. $ag=$tr=$ta=$ot=0;
  3833. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3834. foreach ($aItem as $key=>$value){
  3835. if ($value['category']==$this->AGENCY){
  3836. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3837. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3838. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3839. }
  3840. $ag++;
  3841. }
  3842. if($value['category']==$this->TRAVEL){
  3843. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3844. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3845. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3846. }
  3847. $tr++;
  3848. }
  3849. if($value['category']==$this->TRAIN){
  3850. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3851. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3852. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3853. }
  3854. $ta++;
  3855. }
  3856. if($value['category']==$this->OTHER){
  3857. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3858. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3859. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3860. }
  3861. $ot++;
  3862. }
  3863. }
  3864. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3865. //报销单
  3866. $receipt->accountItem=json_encode($accountJson);
  3867. $receipt->staff=$this->staff[0]['sid'];
  3868. $receipt->sum=number_format($sum, 2, '.', '');
  3869. $receipt->date=date("Y-m-d");
  3870. $receipt->cid=$cid;
  3871. $receipt->status=5;
  3872. //修改审批流程加入角色
  3873. $receipt->verify=$verify;
  3874. $receipt->executeCopy=$executeDetail['staff'];
  3875. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3876. $receipt->explanation=$explanation;
  3877. $rid=$receipt->insert();
  3878. //附件
  3879. if (!empty($enclosurName)){
  3880. $enclosurArray=explode('-', $enclosurName);
  3881. foreach ($enclosurArray as $value){
  3882. $enclosur=new enclosur();
  3883. $enclosur->name=$value;
  3884. $enclosur->rid=$rid;
  3885. $enclosur->insert();
  3886. }
  3887. //print_r($enclosurArray);die;
  3888. }
  3889. //报销详情
  3890. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3891. $receiptDetail=new receiptDetail();
  3892. $receiptDetail->staff=$this->staff[0]['sid'];
  3893. $receiptDetail->item=$value['name'];
  3894. $receiptDetail->itemCategory=$this->AGENCY;
  3895. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3896. $receiptDetail->date=date("Y-m-d");
  3897. $receiptDetail->cid=$cid;
  3898. $receiptDetail->rid=$rid;
  3899. $receiptDetail->status=4;
  3900. $receiptDetail->insert();
  3901. }
  3902. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3903. $receiptDetail=new receiptDetail();
  3904. $receiptDetail->staff=$this->staff[0]['sid'];
  3905. $receiptDetail->item=$value['name'];
  3906. $receiptDetail->itemCategory=$this->TRAVEL;
  3907. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3908. $receiptDetail->date=date("Y-m-d");
  3909. $receiptDetail->cid=$cid;
  3910. $receiptDetail->rid=$rid;
  3911. $receiptDetail->status=4;
  3912. $receiptDetail->insert();
  3913. }
  3914. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3915. $receiptDetail=new receiptDetail();
  3916. $receiptDetail->staff=$this->staff[0]['sid'];
  3917. $receiptDetail->item=$value['name'];
  3918. $receiptDetail->itemCategory=$this->TRAIN;
  3919. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3920. $receiptDetail->date=date("Y-m-d");
  3921. $receiptDetail->cid=$cid;
  3922. $receiptDetail->rid=$rid;
  3923. $receiptDetail->status=4;
  3924. $receiptDetail->insert();
  3925. }
  3926. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3927. $receiptDetail=new receiptDetail();
  3928. $receiptDetail->staff=$this->staff[0]['sid'];
  3929. $receiptDetail->item=$value['name'];
  3930. $receiptDetail->itemCategory=$this->OTHER;
  3931. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3932. $receiptDetail->date=date("Y-m-d");
  3933. $receiptDetail->cid=$cid;
  3934. $receiptDetail->rid=$rid;
  3935. $receiptDetail->status=4;
  3936. $receiptDetail->insert();
  3937. }
  3938. //return "/referReceipt/".$rid;
  3939. }
  3940. return "/saeaBorad";
  3941. }
  3942. function referReceipt(){
  3943. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3944. Doo::loadModel('receipt');
  3945. Doo::loadModel('verify');
  3946. $verify=new verify();
  3947. $receipt=new receipt();
  3948. Doo::loadModel('L_category');
  3949. $lCategory=new L_category();
  3950. Doo::loadModel("role");
  3951. $role=new role();
  3952. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3953. if(empty($receiptDetail))
  3954. return "/addReceipt";
  3955. foreach ($receiptDetail as $key=>$value){
  3956. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3957. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3958. $v=json_decode($veList['staff']);
  3959. array_push($v[0], $veList['description']);
  3960. foreach ($v as $n=>$m){
  3961. if ($m['1']=='ROLE'){
  3962. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3963. $v[$n][1]=$roleInfo['name'];
  3964. }
  3965. }
  3966. $receiptDetail[$key]['staff']=$v;
  3967. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3968. $receiptDetail[$key]['category']=$category['title'];
  3969. }
  3970. //print_r($receiptDetail);
  3971. $data['receiptDetail']=$receiptDetail;
  3972. $data['memu']="receipt";
  3973. $data['staff']=$this->staff;
  3974. $data['receiptMemu']='saeaCreate';
  3975. $data['verifyId']=$this->verifyId;
  3976. $data['executeId']=$this->executeId;
  3977. $this->render ( "/admin/saea_confirm", $data );
  3978. }
  3979. function editReceipt(){
  3980. //edit status 4
  3981. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3982. //echo $rid;
  3983. Doo::loadModel('accountItem');
  3984. Doo::loadModel('verify');
  3985. Doo::loadModel('receipt');
  3986. $receipt=new receipt();
  3987. $verify=new verify();
  3988. $accountItem=new accountItem();
  3989. Doo::loadModel('L_category');
  3990. $lCategory=new L_category();
  3991. Doo::loadModel("role");
  3992. $role=new role();
  3993. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3994. if(empty($receiptDetail))
  3995. return "/saeaCreate";
  3996. $acItem=$accountItem->find(array('asArray'=>true));
  3997. $veList=$verify->find(array('asArray'=>true));
  3998. foreach ($veList as $key=>$value){
  3999. $v=json_decode($value['staff']);
  4000. $list=array();
  4001. foreach ($v as $n=>$m){
  4002. if ($m['1']=='ROLE'){
  4003. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4004. $v[$n][1]=$roleInfo['name'];
  4005. array_push($list, $roleInfo['name']);
  4006. }else{
  4007. array_push($list, $v[$n][1]);
  4008. }
  4009. }
  4010. $veList[$key]['staff']=implode('>', $list);
  4011. }
  4012. //配置编辑信息
  4013. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4014. foreach ($acItem as $key=>$value){
  4015. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4016. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4017. $acItem[$key]['price']=$v['price'];
  4018. }
  4019. }
  4020. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4021. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4022. $acItem[$key]['price']=$v['price'];
  4023. }
  4024. }
  4025. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4026. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4027. $acItem[$key]['price']=$v['price'];
  4028. }
  4029. }
  4030. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4031. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4032. $acItem[$key]['price']=$v['price'];
  4033. }
  4034. }
  4035. }
  4036. $data['category']=$lCategory->find(array('asArray'=>true));
  4037. $data['cSum']=$accountItemList['cSum'];
  4038. $data['sum']=$receiptDetail['sum'];
  4039. $data['receiptDetail']=$receiptDetail;
  4040. $data['veList']=$veList;
  4041. $data['acItem']=$acItem;
  4042. $data['memu']="receipt";
  4043. $data['staff']=$this->staff;
  4044. $data['receiptMemu']='saeaBorad';
  4045. $data['verify']=$receiptDetail['verify'];
  4046. $data['verifyId']=$this->verifyId;
  4047. $data['executeId']=$this->executeId;
  4048. $data['rid']=$rid;
  4049. $this->render ( "/admin/saea_edit", $data );
  4050. }
  4051. function updateReceipt(){
  4052. $agency=$this->get_args('agency');
  4053. $travel=$this->get_args('travel');
  4054. $train=$this->get_args('train');
  4055. $other=$this->get_args('other');
  4056. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4057. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4058. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4059. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4060. if(!empty($verify)&&!empty($explanation)){
  4061. Doo::loadModel('receipt');
  4062. Doo::loadModel('receiptDetail');
  4063. Doo::loadModel('accountItem');
  4064. $accountItem=new accountItem();
  4065. $receipt=new receipt();
  4066. Doo::loadModel('execute');
  4067. $execute=new execute();
  4068. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4069. if(empty($receiptDetail))
  4070. return "/saeaBorad";
  4071. if ($receiptDetail['Rtype']==1)
  4072. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4073. else
  4074. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4075. $aItem=$accountItem->find(array('asArray'=>true));
  4076. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4077. $ag=$tr=$ta=$ot=0;
  4078. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4079. foreach ($aItem as $key=>$value){
  4080. if ($value['category']==$this->AGENCY){
  4081. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4082. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4083. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4084. }
  4085. $ag++;
  4086. }
  4087. if($value['category']==$this->TRAVEL){
  4088. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4089. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4090. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4091. }
  4092. $tr++;
  4093. }
  4094. if($value['category']==$this->TRAIN){
  4095. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4096. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4097. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4098. }
  4099. $ta++;
  4100. }
  4101. if($value['category']==$this->OTHER){
  4102. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4103. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4104. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4105. }
  4106. $ot++;
  4107. }
  4108. }
  4109. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4110. //报销单
  4111. $rid=$receipt->rid=$receiptDetail['rid'];
  4112. $receipt->accountItem=json_encode($accountJson);
  4113. $receipt->staff=$this->staff[0]['sid'];
  4114. $receipt->sum=number_format($sum, 2, '.', '');
  4115. $receipt->date=date("Y-m-d");
  4116. $receipt->cid=$cid;
  4117. if (($receiptDetail['status']!=4)){
  4118. if ($receiptDetail['Rtype']==1)
  4119. $receipt->status=7;
  4120. else
  4121. $receipt->status=5;
  4122. }
  4123. $receipt->verify=$verify;
  4124. $receipt->executeCopy=$executeDetail['staff'];
  4125. $receipt->explanation=$explanation;
  4126. $receipt->update();
  4127. $receiptDetail=new receiptDetail();
  4128. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4129. //报销详情
  4130. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4131. $receiptDetail=new receiptDetail();
  4132. $receiptDetail->staff=$this->staff[0]['sid'];
  4133. $receiptDetail->item=$value['name'];
  4134. $receiptDetail->itemCategory=$this->AGENCY;
  4135. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4136. $receiptDetail->date=date("Y-m-d");
  4137. $receiptDetail->cid=$cid;
  4138. $receiptDetail->rid=$rid;
  4139. $receiptDetail->status=4;
  4140. $receiptDetail->insert();
  4141. }
  4142. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4143. $receiptDetail=new receiptDetail();
  4144. $receiptDetail->staff=$this->staff[0]['sid'];
  4145. $receiptDetail->item=$value['name'];
  4146. $receiptDetail->itemCategory=$this->TRAVEL;
  4147. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4148. $receiptDetail->date=date("Y-m-d");
  4149. $receiptDetail->cid=$cid;
  4150. $receiptDetail->rid=$rid;
  4151. $receiptDetail->status=4;
  4152. $receiptDetail->insert();
  4153. }
  4154. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4155. $receiptDetail=new receiptDetail();
  4156. $receiptDetail->staff=$this->staff[0]['sid'];
  4157. $receiptDetail->item=$value['name'];
  4158. $receiptDetail->itemCategory=$this->TRAIN;
  4159. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4160. $receiptDetail->date=date("Y-m-d");
  4161. $receiptDetail->cid=$cid;
  4162. $receiptDetail->rid=$rid;
  4163. $receiptDetail->status=4;
  4164. $receiptDetail->insert();
  4165. }
  4166. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4167. $receiptDetail=new receiptDetail();
  4168. $receiptDetail->staff=$this->staff[0]['sid'];
  4169. $receiptDetail->item=$value['name'];
  4170. $receiptDetail->itemCategory=$this->OTHER;
  4171. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4172. $receiptDetail->date=date("Y-m-d");
  4173. $receiptDetail->cid=$cid;
  4174. $receiptDetail->rid=$rid;
  4175. $receiptDetail->status=4;
  4176. $receiptDetail->insert();
  4177. }
  4178. //return "/referReceipt/".$rid;
  4179. }
  4180. return "/saeaBorad";
  4181. }
  4182. function approvedReceipt(){
  4183. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4184. Doo::loadModel('receipt');
  4185. Doo::loadModel('receiptDetail');
  4186. $receipt=new receipt();
  4187. $receiptDetail=new receiptDetail();
  4188. Doo::loadModel('statistics');
  4189. Doo::loadModel('itemStatistics');
  4190. $statistics=new statistics();
  4191. $itemStatistics=new itemStatistics();
  4192. Doo::loadModel("verify");
  4193. $verify=new verify();
  4194. //审批状态的判定
  4195. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4196. if(empty($receiptDetailList))
  4197. return "/saeaBorad";
  4198. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4199. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4200. if (empty($receiptDetailList['nowStaff'])){
  4201. $nowStaff="";$nowStaffList=array();
  4202. if ($verifyDetail[0][1]=='ROLE'){
  4203. $vStaffString=json_decode($verifyDetail[0][3]);
  4204. foreach ($vStaffString as $key=>$value){
  4205. $staffK=explode("_", $value);
  4206. array_push($nowStaffList, $staffK[0]);
  4207. }
  4208. $nowStaff=implode(',', $nowStaffList);
  4209. }else{
  4210. $nowStaff=$verifyDetail[0][0];
  4211. }
  4212. $receipt->nowStaff=$nowStaff;
  4213. }
  4214. // echo $nowStaff;
  4215. // print_r($verifyDetail);die;
  4216. $receipt->rid=$receiptDetailList['rid'];
  4217. $receipt->date=date("Y-m-d");
  4218. $receipt->status=2;
  4219. $receipt->update();
  4220. $receiptDetail->status=2;
  4221. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4222. Doo::loadModel("receiptLog");
  4223. $receiptLog=new receiptLog();
  4224. Doo::loadModel("verify");
  4225. $verify=new verify();
  4226. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4227. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4228. $jd=json_decode($vr['staff']);$roleId=0;
  4229. foreach ($jd as $key=>$value){
  4230. if ($value[1]=='ROLE'){
  4231. $pos = strpos($value[3], $this->staff[0]['sid']);
  4232. if ($pos !== false) {
  4233. $roleId=$value[0];
  4234. }
  4235. }
  4236. }
  4237. //审批日志
  4238. //echo $roleId;die;
  4239. if (!empty($roleId)){
  4240. Doo::loadModel("role");
  4241. $role=new role();
  4242. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4243. $receiptLog->rolename=$roleInfo['name'];
  4244. }
  4245. $receiptLog->username=$this->staff[0]['username'];
  4246. $receiptLog->uid=$this->staff[0]['sid'];
  4247. $receiptLog->date=date("Y-m-d");
  4248. $receiptLog->opinion='提交审批';
  4249. $receiptLog->img=$this->staff[0]['avatar'];
  4250. $receiptLog->status=2;
  4251. $receiptLog->rid=$rid;
  4252. $receiptLog->insert();
  4253. //statistics item
  4254. $dateArray=explode("-", $receiptDetailList['date']);
  4255. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4256. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4257. //print_r($accountItem['cSum']['agencySum']);die;
  4258. // foreach ($accountItem['cSum'] as $key=>$value){
  4259. // if($key=="agencySum"){
  4260. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4261. // if(empty($iStatistics)){
  4262. // $itemStatistics->cid=$this->staff[0]['cid'];
  4263. // $itemStatistics->staff=$this->staff[0]['sid'];
  4264. // $itemStatistics->price=$value;
  4265. // $itemStatistics->itemCategory=$this->AGENCY;
  4266. // $itemStatistics->date=date("Y-m-d");
  4267. // $itemStatistics->insert();
  4268. // }else{
  4269. // if (!empty($value)){
  4270. // $itemStatistics->price=$value+$iStatistics['price'];
  4271. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4272. // }
  4273. // }
  4274. // }elseif($key=="travelSum"){
  4275. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4276. // if(empty($iStatistics)){
  4277. // $itemStatistics->cid=$this->staff[0]['cid'];
  4278. // $itemStatistics->staff=$this->staff[0]['sid'];
  4279. // $itemStatistics->price=$value;
  4280. // $itemStatistics->itemCategory=$this->TRAVEL;
  4281. // $itemStatistics->date=date("Y-m-d");
  4282. // $itemStatistics->insert();
  4283. // }else{
  4284. // if (!empty($value)){
  4285. // $itemStatistics->price=$value+$iStatistics['price'];
  4286. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4287. // }
  4288. // }
  4289. // }elseif($key=="trainSum"){
  4290. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4291. // if(empty($iStatistics)){
  4292. // $itemStatistics->cid=$this->staff[0]['cid'];
  4293. // $itemStatistics->staff=$this->staff[0]['sid'];
  4294. // $itemStatistics->price=$value;
  4295. // $itemStatistics->itemCategory=$this->TRAIN;
  4296. // $itemStatistics->date=date("Y-m-d");
  4297. // $itemStatistics->insert();
  4298. // }else{
  4299. // if (!empty($value)){
  4300. // $itemStatistics->price=$value+$iStatistics['price'];
  4301. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4302. // }
  4303. // }
  4304. // }elseif($key=="otherSum"){
  4305. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4306. // if(empty($iStatistics)){
  4307. // $itemStatistics->cid=$this->staff[0]['cid'];
  4308. // $itemStatistics->staff=$this->staff[0]['sid'];
  4309. // $itemStatistics->price=$value;
  4310. // $itemStatistics->itemCategory=$this->OTHER;
  4311. // $itemStatistics->date=date("Y-m-d");
  4312. // $itemStatistics->insert();
  4313. // }else{
  4314. // if (!empty($value)){
  4315. // $itemStatistics->price=$value+$iStatistics['price'];
  4316. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4317. // }
  4318. // }
  4319. // }
  4320. // }
  4321. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4322. if(empty($stat)){
  4323. $statistics->date=date("Y-m-d");
  4324. $statistics->cid=$this->staff[0]['cid'];
  4325. $statistics->staff=$this->staff[0]['sid'];
  4326. $statistics->agPrice=0;
  4327. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4328. $statistics->insert();
  4329. }else{
  4330. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4331. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4332. }
  4333. return "/expenses";
  4334. }
  4335. function approval(){
  4336. $status=isset($this->params['status'])?$this->params['status']:'';
  4337. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4338. $month=$this->get_args('month')?$this->get_args('month'):"";
  4339. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4340. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4341. if (empty($status))
  4342. $status=$this->get_args('status')?$this->get_args('status'):2;
  4343. $vidList=array();
  4344. $button=0;
  4345. Doo::loadModel('verify');
  4346. $verify=new verify();
  4347. Doo::loadModel('receipt');
  4348. $receipt=new receipt();
  4349. Doo::loadModel('staff');
  4350. $staff=new staff();
  4351. Doo::loadModel('L_category');
  4352. $Lcategory=new L_category();
  4353. //user verify ID
  4354. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4355. foreach ($verifyDetail as $key=>$value){
  4356. array_push($vidList, $value['vid']);
  4357. }
  4358. $vid=implode(",", $vidList);
  4359. if(empty($verifyDetail))
  4360. $vid=0;
  4361. /*
  4362. */
  4363. $dateCondition=" and Year(date) =".$year;
  4364. if(!empty($month))
  4365. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4366. $categoryList=$Lcategory->find(array('asArray'=>true));
  4367. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4368. $cateCondition="";$staffCondition="";$approvalCondition="";
  4369. if (!empty($cid))
  4370. $cateCondition=' and cid='.$cid;
  4371. if(!empty($sid)){
  4372. $staffCondition=' and staff='.$sid;
  4373. $cateCondition="";
  4374. }
  4375. // elseif($status==1){
  4376. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4377. // }
  4378. if($status==2){
  4379. //查找角色审批人
  4380. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4381. }
  4382. $ap="";
  4383. if($status==4){
  4384. $ap=4;$status=2;
  4385. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4386. }
  4387. if($status==5){
  4388. $status=4;$ap=5;
  4389. }
  4390. //echo $vid;
  4391. //get Receipt By verifyID status 2 .$approvalCondition
  4392. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4393. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4394. ,'desc'=>'rid','asArray'=>true));
  4395. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4396. $Locate=0;
  4397. if($ap==4)
  4398. $status=4;
  4399. elseif ($ap==5)
  4400. $status=5;
  4401. foreach ($receiptList as $key=>$value){
  4402. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4403. $receiptList[$key]['reviseDetail']=array();
  4404. if (!empty($value['reviseDetail']))
  4405. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4406. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4407. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4408. $receiptList[$key]['category']=$categoryDetil['title'];
  4409. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4410. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4411. $verifyStaff=json_decode($value['verifyStaff'],true);
  4412. foreach ($verifyList as $k=>$v){
  4413. //init verifyStaff
  4414. $verifyList[$k]['date']="";
  4415. $verifyList[$k]['opinion']="";
  4416. $verifyList[$k]['status']="";
  4417. if (empty($verifyStaff)){
  4418. $verifyList[$k]['date']="";
  4419. $verifyList[$k]['opinion']="";
  4420. if ($v[0]==$this->staff[0]['sid']){
  4421. $verifyList[$k]['status']=4;
  4422. $button=4;
  4423. }
  4424. }else{
  4425. $flag=true;
  4426. foreach ($verifyStaff as $m=>$u){
  4427. if ($v[0]==$m){
  4428. $verifyList[$k]['date']=$u['date'];
  4429. $verifyList[$k]['opinion']=$u['opinion'];
  4430. $verifyList[$k]['status']=$u['status'];
  4431. $flag=false;
  4432. break;
  4433. }
  4434. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4435. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4436. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4437. }
  4438. if($flag){//检测可编辑
  4439. if($v[0]==$this->staff[0]['sid']){
  4440. $verifyList[$k]['status']=4;$button=4;
  4441. }
  4442. }
  4443. }
  4444. }
  4445. $receiptList[$key]['verifyList']=$verifyList;
  4446. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4447. $receiptList[$key]['button']=$button;
  4448. }
  4449. //print_r($receiptList);die;
  4450. //$data['verifyDetail']=$verifyDetail;
  4451. $mothHtml="";
  4452. for($i=1;$i<=12;$i++){
  4453. if($month==$i)
  4454. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4455. else
  4456. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4457. }
  4458. $data['mothHtml']=$mothHtml;
  4459. $data['receiptList']=$receiptList;
  4460. $data['receiptApprovalCount']=count($receiptList);
  4461. $data['status']=$status;
  4462. $data['year']=$year;
  4463. $data['categoryList']=$categoryList;
  4464. $data['staffList']=$staffList;
  4465. $data['cid']=$cid;
  4466. $data['sid']=$sid;
  4467. $data['ap']=$ap;
  4468. $data['memu']="receipt";
  4469. $data['staff']=$this->staff;
  4470. $data['receiptMemu']='approval';
  4471. $data['verifyId']=$this->verifyId;
  4472. $data['executeId']=$this->executeId;
  4473. $this->render ( "/admin/saea_reportList", $data );
  4474. }
  4475. function approvalDetails(){
  4476. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4477. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4478. $month=$this->get_args('month')?$this->get_args('month'):"";
  4479. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4480. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4481. Doo::loadModel('verify');
  4482. $verify=new verify();
  4483. Doo::loadModel('receipt');
  4484. $receipt=new receipt();
  4485. Doo::loadModel('staff');
  4486. $staff=new staff();
  4487. Doo::loadModel('L_category');
  4488. $Lcategory=new L_category();
  4489. Doo::loadModel('enclosur');
  4490. $enclosur=new enclosur();
  4491. $vidList=array();
  4492. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4493. foreach ($verifyDetail as $key=>$value){
  4494. array_push($vidList, $value['vid']);
  4495. }
  4496. $vid=implode(",", $vidList);
  4497. if(empty($verifyDetail))
  4498. $vid=0;
  4499. $categoryList=$Lcategory->find(array('asArray'=>true));
  4500. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4501. $ap=0;
  4502. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4503. $Locate=0;$roleId=0;$button=0;
  4504. foreach ($receiptList as $key=>$value){
  4505. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4506. $receiptList[$key]['reviseDetail']=array();
  4507. if (!empty($value['reviseDetail']))
  4508. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4509. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4510. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4511. $receiptList[$key]['category']=$categoryDetil['title'];
  4512. //检测编辑状态
  4513. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4514. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4515. $verifyStaff=json_decode($value['verifyStaff'],true);
  4516. Doo::loadModel('role');
  4517. $role=new role();
  4518. //print_r($verifyList);
  4519. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4520. foreach ($verifyList as $k=>$v){
  4521. //init verifyStaff
  4522. if ($v[1]=='ROLE'){
  4523. if (!empty($verifyStaff)){
  4524. $endStaffArray=end($verifyStaff);
  4525. if ($v[0]==$endStaffArray['nextStaff']){
  4526. $roleId=$v[0];
  4527. }
  4528. }
  4529. $roleVerify=json_decode($v[3],true);
  4530. $roleKey=$k;$roleArray=array();
  4531. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4532. foreach ($roleVerify as $o=>$p){
  4533. $staffID=explode ('_',$p);
  4534. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4535. //print_r($staffID);
  4536. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4537. array_push($roleArray, $exp);
  4538. }
  4539. $roleArrayCopy[$v[0]]=$roleArray;
  4540. //$verifyList[$k]['roleArray']=$roleArray;
  4541. }
  4542. //print_r($roleArray);
  4543. $verifyList[$k]['date']="";
  4544. $verifyList[$k]['opinion']="";
  4545. $verifyList[$k]['status']="";
  4546. if (empty($verifyStaff)){
  4547. $verifyList[$k]['date']="";
  4548. $verifyList[$k]['opinion']="";
  4549. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4550. $verifyList[$k]['status']=4;
  4551. $button=4;$flag=false;
  4552. }
  4553. }else{
  4554. foreach ($verifyStaff as $m=>$u){
  4555. if ($v[0]==$m){
  4556. $verifyList[$k]['date']=$u['date'];
  4557. $verifyList[$k]['opinion']=$u['opinion'];
  4558. $verifyList[$k]['status']=$u['status'];
  4559. $flag=false;
  4560. break;
  4561. }
  4562. }
  4563. $endStaffArray=end($verifyStaff);
  4564. if (isset($endStaffArray['ROLE'])){
  4565. }else{
  4566. $endKey=key($verifyStaff);
  4567. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4568. $button=4;
  4569. $verifyList[$k]['status']=4;
  4570. }
  4571. }
  4572. }
  4573. }
  4574. $rolename['name']='';
  4575. if (!empty($roleId)){
  4576. Doo::loadModel('role');
  4577. $role=new role();
  4578. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4579. }
  4580. if (!empty($verifyStaff))
  4581. $endStaffArray=end($verifyStaff);
  4582. $KOP=false;
  4583. foreach ($roleArrayCopy as $P=>$A){
  4584. foreach ( $A as $MKI=>$AVL){
  4585. if (!empty($verifyStaff)){
  4586. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4587. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4588. $button=4;
  4589. $roleArrayCopy[$P][$MKI]['status']=4;
  4590. }
  4591. foreach ($verifyStaff as $m=>$u){
  4592. $AVLFK=$AVL[0].'_R';
  4593. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4594. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4595. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4596. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4597. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4598. break;
  4599. }
  4600. }
  4601. }else{
  4602. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4603. $button=4;
  4604. $roleArrayCopy[$P][$MKI]['status']=4;
  4605. }
  4606. }
  4607. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4608. $KOP=true;
  4609. }
  4610. }
  4611. foreach ($roleArrayCopy as $k=>$v){
  4612. foreach ($verifyList as $m=>$n){
  4613. if ($n[0]==$k){
  4614. array_splice($verifyList,$m,1,$v);
  4615. }
  4616. }
  4617. }
  4618. $receiptList[$key]['verifyList']=$verifyList;
  4619. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4620. $receiptList[$key]['button']=$button;
  4621. }
  4622. $mothHtml="";
  4623. for($i=1;$i<=12;$i++){
  4624. if($month==$i)
  4625. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4626. else
  4627. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4628. }
  4629. //获取审批日志
  4630. Doo::loadModel('receiptLog');
  4631. $receiptLog=new receiptLog();
  4632. $rlList=array();
  4633. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4634. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4635. if (!empty($rlInfo)){
  4636. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4637. }
  4638. $receiptList[0]['rlList']=$rlList;
  4639. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4640. $enclosurHtml='';
  4641. foreach ($enclosurList as $value){
  4642. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4643. }
  4644. $data['enclosurHtml']=$enclosurHtml;
  4645. $data['rolename']=$rolename['name'];
  4646. $data['datetij']=$tijdate['date'];
  4647. $data['mothHtml']=$mothHtml;
  4648. $data['receiptList']=$receiptList;
  4649. $data['receiptApprovalCount']=count($receiptList);
  4650. $data['year']=$year;
  4651. $data['categoryList']=$categoryList;
  4652. $data['staffList']=$staffList;
  4653. $data['cid']=$cid;
  4654. $data['sid']=$sid;
  4655. $data['status']=0;
  4656. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4657. $ap=4;
  4658. }else
  4659. $data['status']=$receiptList[0]['status'];
  4660. if ($receiptList[0]['status']==4){
  4661. $data['status']=5;
  4662. $ap=0;
  4663. }
  4664. $data['ap']=$ap;
  4665. $data['memu']="receipt";
  4666. $data['staff']=$this->staff;
  4667. $data['receiptMemu']='approval';
  4668. $data['verifyId']=$this->verifyId;
  4669. $data['executeId']=$this->executeId;
  4670. $this->render ( "/admin/saeaReportListReport", $data );
  4671. }
  4672. function approvalEdi(){
  4673. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4674. $status=isset($this->params['status'])?$this->params['status']:'';
  4675. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4676. $month=$this->get_args('month')?$this->get_args('month'):"";
  4677. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4678. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4679. if (empty($status))
  4680. $status=$this->get_args('status')?$this->get_args('status'):2;
  4681. $vidList=array();
  4682. $button=0;
  4683. Doo::loadModel('verify');
  4684. Doo::loadModel('receipt');
  4685. Doo::loadModel('staff');
  4686. $staff=new staff();
  4687. $receipt=new receipt();
  4688. $verify=new verify();
  4689. Doo::loadModel('L_category');
  4690. $Lcategory=new L_category();
  4691. Doo::loadModel('enclosur');
  4692. $enclosur=new enclosur();
  4693. //user verify ID
  4694. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4695. foreach ($verifyDetail as $key=>$value){
  4696. array_push($vidList, $value['vid']);
  4697. }
  4698. $vid=implode(",", $vidList);
  4699. if(empty($verifyDetail))
  4700. $vid=0;
  4701. $categoryList=$Lcategory->find(array('asArray'=>true));
  4702. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4703. $ap="";
  4704. if($status==4){
  4705. $ap=4;$status=2;
  4706. }
  4707. //get Receipt By verifyID status 2
  4708. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4709. $Locate=0;$roleId=0;
  4710. if($ap==4)
  4711. $status=4;
  4712. foreach ($receiptList as $key=>$value){
  4713. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4714. $receiptList[$key]['reviseDetail']=array();
  4715. if (!empty($value['reviseDetail']))
  4716. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4717. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4718. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4719. $receiptList[$key]['category']=$categoryDetil['title'];
  4720. //检测编辑状态
  4721. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4722. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4723. $verifyStaff=json_decode($value['verifyStaff'],true);
  4724. // print_r($verifyList);
  4725. //
  4726. // if (empty($verifyStaff)){
  4727. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4728. // $verifyList[0]['status']=4;$button=4;
  4729. // }
  4730. //
  4731. // }else{
  4732. //
  4733. // }
  4734. // die;
  4735. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4736. // echo array_search("green",$a);
  4737. //
  4738. Doo::loadModel('role');
  4739. $role=new role();
  4740. //print_r($verifyList);
  4741. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4742. foreach ($verifyList as $k=>$v){
  4743. //init verifyStaff
  4744. if ($v[1]=='ROLE'){
  4745. if (!empty($verifyStaff)){
  4746. $endStaffArray=end($verifyStaff);
  4747. if ($v[0]==$endStaffArray['nextStaff']){
  4748. $roleId=$v[0];
  4749. }
  4750. }
  4751. $roleVerify=json_decode($v[3],true);
  4752. $roleKey=$k;$roleArray=array();
  4753. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4754. foreach ($roleVerify as $o=>$p){
  4755. $staffID=explode ('_',$p);
  4756. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4757. //print_r($staffID);
  4758. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4759. array_push($roleArray, $exp);
  4760. }
  4761. $roleArrayCopy[$v[0]]=$roleArray;
  4762. //$verifyList[$k]['roleArray']=$roleArray;
  4763. }
  4764. //print_r($roleArray);
  4765. $verifyList[$k]['date']="";
  4766. $verifyList[$k]['opinion']="";
  4767. $verifyList[$k]['status']="";
  4768. if (empty($verifyStaff)){
  4769. $verifyList[$k]['date']="";
  4770. $verifyList[$k]['opinion']="";
  4771. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4772. $verifyList[$k]['status']=4;
  4773. $button=4;$flag=false;
  4774. }
  4775. }else{
  4776. foreach ($verifyStaff as $m=>$u){
  4777. if ($v[0]==$m){
  4778. $verifyList[$k]['date']=$u['date'];
  4779. $verifyList[$k]['opinion']=$u['opinion'];
  4780. $verifyList[$k]['status']=$u['status'];
  4781. $flag=false;
  4782. break;
  4783. }
  4784. }
  4785. $endStaffArray=end($verifyStaff);
  4786. if (isset($endStaffArray['ROLE'])){
  4787. }else{
  4788. $endKey=key($verifyStaff);
  4789. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4790. $button=4;
  4791. $verifyList[$k]['status']=4;
  4792. }
  4793. }
  4794. //print_r($endStaffArray);die;
  4795. // if (empty($verifyStaff)){
  4796. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4797. // $verifyList[$k]['status']=4;$button=4;
  4798. // }
  4799. //
  4800. // }else{
  4801. //
  4802. // }
  4803. // if($flag){//检测可编辑
  4804. // if($v[0]==$this->staff[0]['sid']){
  4805. // $verifyList[$k]['status']=4;$button=4;
  4806. // }
  4807. // }
  4808. }
  4809. }
  4810. $rolename['name']='';
  4811. if (!empty($roleId)){
  4812. Doo::loadModel('role');
  4813. $role=new role();
  4814. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4815. }
  4816. if (!empty($verifyStaff))
  4817. $endStaffArray=end($verifyStaff);
  4818. $KOP=false;
  4819. foreach ($roleArrayCopy as $P=>$A){
  4820. foreach ( $A as $MKI=>$AVL){
  4821. if (!empty($verifyStaff)){
  4822. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4823. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4824. $button=4;
  4825. $roleArrayCopy[$P][$MKI]['status']=4;
  4826. }
  4827. foreach ($verifyStaff as $m=>$u){
  4828. $AVLFK=$AVL[0].'_R';
  4829. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4830. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4831. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4832. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4833. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4834. break;
  4835. }
  4836. }
  4837. }else{
  4838. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4839. $button=4;
  4840. $roleArrayCopy[$P][$MKI]['status']=4;
  4841. }
  4842. }
  4843. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4844. $KOP=true;
  4845. }
  4846. }
  4847. // print_r($roleArrayCopy);
  4848. // echo $roleKey;
  4849. foreach ($roleArrayCopy as $k=>$v){
  4850. foreach ($verifyList as $m=>$n){
  4851. if ($n[0]==$k){
  4852. array_splice($verifyList,$m,1,$v);
  4853. }
  4854. }
  4855. }
  4856. // if ($KOP)
  4857. // array_splice($verifyList,$roleKey,1,$roleArray);
  4858. //print_r($verifyList);
  4859. $receiptList[$key]['verifyList']=$verifyList;
  4860. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4861. $receiptList[$key]['button']=$button;
  4862. }
  4863. //$data['verifyDetail']=$verifyDetail;
  4864. $mothHtml="";
  4865. for($i=1;$i<=12;$i++){
  4866. if($month==$i)
  4867. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4868. else
  4869. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4870. }
  4871. //获取审批日志
  4872. Doo::loadModel('receiptLog');
  4873. $receiptLog=new receiptLog();
  4874. $rlList=array();
  4875. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4876. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4877. if (!empty($rlInfo)){
  4878. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4879. }
  4880. $receiptList[0]['rlList']=$rlList;
  4881. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4882. $enclosurHtml='';
  4883. foreach ($enclosurList as $value){
  4884. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4885. }
  4886. $data['enclosurHtml']=$enclosurHtml;
  4887. $data['rolename']=$rolename['name'];
  4888. $data['datetij']=$tijdate['date'];
  4889. $data['mothHtml']=$mothHtml;
  4890. $data['receiptList']=$receiptList;
  4891. $data['receiptApprovalCount']=count($receiptList);
  4892. $data['status']=$status;
  4893. $data['year']=$year;
  4894. $data['categoryList']=$categoryList;
  4895. $data['staffList']=$staffList;
  4896. $data['cid']=$cid;
  4897. $data['sid']=$sid;
  4898. $data['ap']=$ap;
  4899. $data['memu']="receipt";
  4900. $data['staff']=$this->staff;
  4901. $data['receiptMemu']='approval';
  4902. $data['verifyId']=$this->verifyId;
  4903. $data['executeId']=$this->executeId;
  4904. $this->render ( "/admin/saeaReportListReport", $data );
  4905. }
  4906. function remittance(){
  4907. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4908. $month=$this->get_args('month')?$this->get_args('month'):"";
  4909. Doo::loadModel('receipt');
  4910. $receipt=new receipt();
  4911. Doo::loadModel('staff');
  4912. $staff=new staff();
  4913. $dateCondition=" and Year(pastDate) =".$year;
  4914. if(!empty($month))
  4915. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4916. //get Receipt By verifyID status 1
  4917. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4918. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4919. $dataList=array();
  4920. foreach ($dateList as $d=>$a){
  4921. $dataList[$a['pastDate']]=array();$daySum=0;
  4922. foreach ($receiptList as $key=>$value){
  4923. if($a['pastDate']==$value['pastDate']){
  4924. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4925. $list=array();$html="";
  4926. foreach ($oderList as $v){
  4927. array_push($list, $v['receiptOrder']);
  4928. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4929. }
  4930. $receiptList[$key]['receiptOrder']=$html;
  4931. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4932. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4933. $receiptList[$key]['username']=$sinfo['username'];
  4934. $daySum+=$value['sum'];
  4935. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4936. }
  4937. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4938. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4939. }
  4940. }
  4941. //print_r($dataList);
  4942. $data['dataList']=$dataList;
  4943. $mothHtml="";
  4944. for($i=1;$i<=12;$i++){
  4945. if($month==$i)
  4946. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4947. else
  4948. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4949. }
  4950. $data['year']=$year;
  4951. $data['mothHtml']=$mothHtml;
  4952. $data['memu']="receipt";
  4953. $data['staff']=$this->staff;
  4954. $data['receiptMemu']='approval';
  4955. $data['verifyId']=$this->verifyId;
  4956. $data['executeId']=$this->executeId;
  4957. $this->render ( "/admin/saeaReportListPay", $data );
  4958. }
  4959. function revocationAdjustment(){
  4960. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4961. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4962. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4963. //echo $price;die;
  4964. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4965. Doo::loadModel('receipt');
  4966. $receipt=new receipt();
  4967. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4968. if (empty($receiptDetail['reviseDetail']))
  4969. return "/approval";
  4970. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4971. $RD=array();
  4972. foreach ($reviseDetail as $key=>$value){
  4973. if ($value['price']==$price&&$value['sid']==$sid)
  4974. continue;
  4975. array_push($RD, $value);
  4976. }
  4977. $reviseDetailString=json_encode($RD);
  4978. $receipt->reviseDetail=$reviseDetailString;
  4979. $receipt->sum=$receiptDetail['sum']-$price;
  4980. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4981. $receipt->update(array('where'=>'rid='.$rid));
  4982. }
  4983. //approvalEdi/37
  4984. return "/approvalEdi/".$rid;
  4985. }
  4986. function updateApprovalReceipt(){
  4987. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4988. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4989. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4990. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4991. if(!empty($rid)){
  4992. Doo::loadModel("verify");
  4993. $verify=new verify();
  4994. Doo::loadModel("receiptDetail");
  4995. $receiptDetailObj=new receiptDetail();
  4996. Doo::loadModel("itemStatistics");
  4997. Doo::loadModel("statistics");
  4998. $statistics=new statistics();
  4999. $itemStatistics=new itemStatistics();
  5000. Doo::loadModel("receipt");
  5001. $receipt=new receipt();
  5002. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5003. if (empty($receiptDetail))
  5004. return "/approval";
  5005. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5006. $verifyString=$verifyDetail['staff'];
  5007. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5008. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5009. if(empty($opinion)){
  5010. if ($status==3)
  5011. $opinion="终止";
  5012. else
  5013. $opinion="同意支付";
  5014. }
  5015. $nowStaff=0;$nowStaffList=array();
  5016. if(empty($verifyStaff)){
  5017. //还需加入是否已经进入角色审批
  5018. if ($verifyDetail[0][1]=='ROLE'){
  5019. //print_r($verifyDetail);echo "ddd";
  5020. $vStaffString=json_decode($verifyDetail[0][3]);
  5021. foreach ($vStaffString as $key=>$value){
  5022. $staffK=explode("_", $value);
  5023. if ($staffK[0]!=$this->staff[0]['sid'])
  5024. array_push($nowStaffList, $staffK[0]);
  5025. }
  5026. //print_r($verifyDetail);
  5027. //die;
  5028. $nowStaff=implode(',', $nowStaffList);
  5029. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5030. }else{
  5031. if ($verifyDetail[1][1]=='ROLE'){
  5032. $vStaffString=json_decode($verifyDetail[1][3]);
  5033. //echo "dd";
  5034. foreach ($vStaffString as $key=>$value){
  5035. $staffK=explode("_", $value);
  5036. array_push($nowStaffList, $staffK[0]);
  5037. }
  5038. $nowStaff=implode(',', $nowStaffList);
  5039. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5040. }else{
  5041. $nowStaff=$verifyDetail[1][0];
  5042. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5043. }
  5044. }
  5045. if($status==3)
  5046. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5047. $vStaffString=json_encode($verifyStaff);
  5048. $receipt->nowStaff=$nowStaff;
  5049. $receipt->verifyStaff=$vStaffString;
  5050. }else{
  5051. $VS=end($verifyStaff);
  5052. //非角色审批
  5053. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5054. $nextStaff=0;$roleSTF=false;
  5055. foreach ($verifyDetail as $key=>$value){
  5056. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5057. if (isset($verifyDetail[$key+1])){
  5058. $nextStaff=$verifyDetail[$key+1][0];
  5059. if ($verifyDetail[$key+1][1]=='ROLE')
  5060. $roleSTF=true;
  5061. }
  5062. break;
  5063. }
  5064. }
  5065. if (!$roleSTF){
  5066. $nowStaff=$nextStaff;
  5067. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5068. }else{
  5069. //获取角色下的所有用户ID
  5070. $nowStaffList=array();
  5071. foreach ($verifyDetail as $vfk){
  5072. if ($vfk[1]=='ROLE'){
  5073. $vStaffString=json_decode($vfk[3]);
  5074. foreach ($vStaffString as $key=>$value){
  5075. $staffK=explode("_", $value);
  5076. array_push($nowStaffList, $staffK[0]);
  5077. }
  5078. }
  5079. }
  5080. $nowStaff=implode(',', $nowStaffList);
  5081. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5082. }
  5083. if($status==3){
  5084. $verifyStaff['final']=$status;
  5085. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5086. }
  5087. $vStaffString=json_encode($verifyStaff);
  5088. $receipt->nowStaff=$nowStaff;
  5089. $receipt->verifyStaff=$vStaffString;
  5090. }
  5091. //角色审批
  5092. if (isset($VS['ROLE'])){
  5093. //找出角色人 当前审批角色组
  5094. $verifyJSStaff=array();$nowStaffList2=array();
  5095. foreach ($verifyDetail as $key=>$value){
  5096. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5097. $verifyJSStaff=json_decode($value[3]);
  5098. foreach ($verifyJSStaff as $m){
  5099. $staffK=explode("_", $m);
  5100. array_push($nowStaffList2, $staffK[0]);
  5101. }
  5102. // print_r($nowStaffList2);
  5103. }
  5104. }
  5105. $RoleVerifyStaff=array();
  5106. foreach ($verifyStaff as $key=>$value){
  5107. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5108. foreach ($nowStaffList2 as $m) {
  5109. if ($key==$m."_R")
  5110. $RoleVerifyStaff[$key]=$value;
  5111. }
  5112. }
  5113. }
  5114. // print_r($verifyStaff);
  5115. // print_r($nowStaffList2);
  5116. // print_r($RoleVerifyStaff);
  5117. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5118. //print_r($verifyJSStaff);
  5119. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5120. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5121. //下一个审批人ID
  5122. $nextStaff=0;$falg=false;
  5123. foreach ($verifyDetail as $key=>$value){
  5124. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5125. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5126. $falg=true;
  5127. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5128. foreach ($vStaffString as $v){
  5129. $staffK=explode("_", $v);
  5130. array_push($nowStaffList, $staffK[0]);
  5131. }
  5132. $nowStaff=implode(',', $nowStaffList);
  5133. $nextStaff=$verifyDetail[$key+1][0];
  5134. }elseif(isset($verifyDetail[$key+1])){
  5135. $nextStaff=$verifyDetail[$key+1][0];
  5136. $nowStaff=$nextStaff;
  5137. }else
  5138. $nowStaff='';
  5139. break;
  5140. }
  5141. }
  5142. if ($falg)
  5143. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5144. else
  5145. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5146. // print_r($verifyStaff);
  5147. // echo $nowStaff;die;
  5148. }else{ //进入下一个角色或者审批人
  5149. /*
  5150. */
  5151. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5152. //
  5153. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5154. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5155. // print_r($verifyStaff);
  5156. // die;
  5157. }
  5158. if($status==3){
  5159. $verifyStaff['final']=$status;
  5160. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5161. }
  5162. $vStaffString=json_encode($verifyStaff);
  5163. $receipt->verifyStaff=$vStaffString;
  5164. $receipt->nowStaff=$nowStaff;
  5165. //die;
  5166. //}
  5167. // print_r($verifyStaff);
  5168. // die;
  5169. }
  5170. //print_r($verifyStaff);die;
  5171. }
  5172. //print_r($verifyDetail);
  5173. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5174. foreach ($verifyDetail as $k=>$v){
  5175. if ($v[1]=='ROLE'){
  5176. $roleId=$v[0];
  5177. $roleVerify=json_decode($v[3],true);
  5178. $roleKey=$k;$roleArray=array();
  5179. foreach ($roleVerify as $o=>$p){
  5180. $staffID=explode ('_',$p);
  5181. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5182. array_push($roleArray, $exp);
  5183. }
  5184. $verifyDetailCopy[$v[0]]=$roleArray;
  5185. }
  5186. }
  5187. //print_r($verifyDetail);
  5188. foreach ($verifyDetailCopy as $k=>$v){
  5189. foreach ($verifyDetail as $m=>$n){
  5190. if ($n[0]==$k){
  5191. array_splice($verifyDetail,$m,1,$v);
  5192. }
  5193. }
  5194. }
  5195. // die;
  5196. // if (!empty($roleArray))
  5197. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5198. // echo $roleId;
  5199. // print_r($verifyStaff);
  5200. // print_r($verifyDetail);
  5201. // die;
  5202. Doo::loadModel("receiptLog");
  5203. $receiptLog=new receiptLog();
  5204. //审批日志
  5205. if (!isset($verifyStaff['final'])){
  5206. if (!empty($roleId)){
  5207. Doo::loadModel("role");
  5208. $role=new role();
  5209. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5210. $receiptLog->rolename=$roleInfo['name'];
  5211. }
  5212. $receiptLog->username=$this->staff[0]['username'];
  5213. $receiptLog->uid=$this->staff[0]['sid'];
  5214. $receiptLog->date=date("Y-m-d");
  5215. $receiptLog->opinion=$opinion;
  5216. $receiptLog->img=$this->staff[0]['avatar'];
  5217. $receiptLog->status=1;
  5218. $receiptLog->rid=$rid;
  5219. $receiptLog->insert();
  5220. }
  5221. if (isset($verifyStaff['final'])){//rDetail
  5222. $receipt->verifyBreakup=$verifyString;
  5223. $receipt->status=3;
  5224. $receiptDetailObj->status=3;
  5225. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5226. if (!empty($roleId)){
  5227. Doo::loadModel("role");
  5228. $role=new role();
  5229. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5230. $receiptLog->rolename=$roleInfo['name'];
  5231. }
  5232. $receiptLog->username=$this->staff[0]['username'];
  5233. $receiptLog->uid=$this->staff[0]['sid'];
  5234. $receiptLog->date=date("Y-m-d");
  5235. $receiptLog->opinion=$opinion;
  5236. $receiptLog->img=$this->staff[0]['avatar'];
  5237. $receiptLog->status=3;
  5238. $receiptLog->rid=$rid;
  5239. $receiptLog->insert();
  5240. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5241. $receipt->status=1;$reviseSum=0;
  5242. $receipt->verifyBreakup=$verifyString;
  5243. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5244. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5245. foreach ($reviseDetail as $key=>$value){
  5246. $receiptDetailObj=new receiptDetail();
  5247. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5248. $receiptDetailObj->item=$value['description'];
  5249. $receiptDetailObj->itemCategory="报销金额调整";
  5250. $receiptDetailObj->price=$value['price'];
  5251. $receiptDetailObj->date=$receiptDetail['date'];
  5252. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5253. $receiptDetailObj->rid=$rid;
  5254. $receiptDetailObj->status=1;
  5255. $receiptDetailObj->insert();
  5256. $reviseSum+=$value['price'];
  5257. }
  5258. $itemStatistics=new itemStatistics();
  5259. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5260. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5261. $itemStatistics->price=$reviseSum;
  5262. $itemStatistics->itemCategory="报销金额调整";
  5263. $itemStatistics->date=$receiptDetail['date'];
  5264. $itemStatistics->insert();
  5265. }
  5266. $receiptDetailObj=new receiptDetail();
  5267. $receiptDetailObj->status=1;
  5268. $receiptDetailObj->pastDate=date("Y-m-d");
  5269. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5270. $dateArray=explode("-", $receiptDetail['date']);
  5271. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5272. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5273. if(empty($stat)){
  5274. $statistics->date=$receiptDetail['date'];
  5275. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5276. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5277. $statistics->agPrice=$receiptDetail['sum'];
  5278. $statistics->rePrice=$reviseSum;
  5279. $statistics->insert();
  5280. }else{
  5281. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5282. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5283. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5284. }
  5285. $dateArray=explode("-", $receiptDetail['date']);
  5286. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5287. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5288. foreach ($accountItem['cSum'] as $key=>$value){
  5289. if($key=="agencySum"){
  5290. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5291. if(empty($iStatistics)){
  5292. $itemStatistics->cid=$receiptDetail['cid'];;
  5293. $itemStatistics->staff=$receiptDetail['staff'];
  5294. $itemStatistics->price=$value;
  5295. $itemStatistics->itemCategory=$this->AGENCY;
  5296. $itemStatistics->date=$receiptDetail['date'];
  5297. $itemStatistics->insert();
  5298. }else{
  5299. if (!empty($value)){
  5300. $itemStatistics->price=$value+$iStatistics['price'];
  5301. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5302. }
  5303. }
  5304. }elseif($key=="travelSum"){
  5305. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5306. if(empty($iStatistics)){
  5307. $itemStatistics->cid=$receiptDetail['cid'];
  5308. $itemStatistics->staff=$receiptDetail['staff'];
  5309. $itemStatistics->price=$value;
  5310. $itemStatistics->itemCategory=$this->TRAVEL;
  5311. $itemStatistics->date=$receiptDetail['date'];
  5312. $itemStatistics->insert();
  5313. }else{
  5314. if (!empty($value)){
  5315. $itemStatistics->price=$value+$iStatistics['price'];
  5316. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5317. }
  5318. }
  5319. }elseif($key=="trainSum"){
  5320. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5321. if(empty($iStatistics)){
  5322. $itemStatistics->cid=$receiptDetail['cid'];
  5323. $itemStatistics->staff=$receiptDetail['staff'];
  5324. $itemStatistics->price=$value;
  5325. $itemStatistics->itemCategory=$this->TRAIN;
  5326. $itemStatistics->date=$receiptDetail['date'];
  5327. $itemStatistics->insert();
  5328. }else{
  5329. if (!empty($value)){
  5330. $itemStatistics->price=$value+$iStatistics['price'];
  5331. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5332. }
  5333. }
  5334. }elseif($key=="otherSum"){
  5335. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5336. if(empty($iStatistics)){
  5337. $itemStatistics->cid=$receiptDetail['cid'];
  5338. $itemStatistics->staff=$receiptDetail['staff'];
  5339. $itemStatistics->price=$value;
  5340. $itemStatistics->itemCategory=$this->OTHER;
  5341. $itemStatistics->date=$receiptDetail['date'];
  5342. $itemStatistics->insert();
  5343. }else{
  5344. if (!empty($value)){
  5345. $itemStatistics->price=$value+$iStatistics['price'];
  5346. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5347. }
  5348. }
  5349. }
  5350. }
  5351. $receipt->pastDate=date("Y-m-d");
  5352. }
  5353. $receipt->update(array('where'=>' rid = '.$rid));
  5354. return "/approvalExpenses/2";
  5355. }
  5356. }
  5357. function expensesRetreats(){
  5358. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5359. if (!empty($rid)){
  5360. //操作记录
  5361. Doo::loadModel("receipt");
  5362. $receipt=new receipt();
  5363. Doo::loadModel("receiptLog");
  5364. $receiptLog=new receiptLog();
  5365. Doo::loadModel("verify");
  5366. $verify=new verify();
  5367. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5368. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5369. $jd=json_decode($vr['staff']);$roleId=0;
  5370. foreach ($jd as $key=>$value){
  5371. if ($value[1]=='ROLE'){
  5372. $pos = strpos($value[3], $this->staff[0]['sid']);
  5373. if ($pos !== false) {
  5374. $roleId=$value[0];
  5375. }
  5376. }
  5377. }
  5378. //审批日志
  5379. //echo $roleId;die;
  5380. if (!empty($roleId)){
  5381. Doo::loadModel("role");
  5382. $role=new role();
  5383. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5384. $receiptLog->rolename=$roleInfo['name'];
  5385. }
  5386. $receiptLog->username=$this->staff[0]['username'];
  5387. $receiptLog->uid=$this->staff[0]['sid'];
  5388. $receiptLog->date=date("Y-m-d");
  5389. $receiptLog->opinion='撤回';
  5390. $receiptLog->img=$this->staff[0]['avatar'];
  5391. $receiptLog->status=4;
  5392. $receiptLog->rid=$rid;
  5393. $receiptLog->insert();
  5394. $receipt->status=4;
  5395. $receipt->update(array('where'=>'rid='.$rid));
  5396. }
  5397. //echo "ddd";
  5398. return '/approvalExpenses';
  5399. }
  5400. function updateCheReceipt(){
  5401. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5402. if (!empty($rid)){
  5403. //操作记录
  5404. Doo::loadModel("receipt");
  5405. $receipt=new receipt();
  5406. Doo::loadModel("receiptLog");
  5407. $receiptLog=new receiptLog();
  5408. Doo::loadModel("verify");
  5409. $verify=new verify();
  5410. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5411. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5412. $jd=json_decode($vr['staff']);$roleId=0;
  5413. foreach ($jd as $key=>$value){
  5414. if ($value[1]=='ROLE'){
  5415. $pos = strpos($value[3], $this->staff[0]['sid']);
  5416. if ($pos !== false) {
  5417. $roleId=$value[0];
  5418. }
  5419. }
  5420. }
  5421. //审批日志
  5422. //echo $roleId;die;
  5423. if (!empty($roleId)){
  5424. Doo::loadModel("role");
  5425. $role=new role();
  5426. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5427. $receiptLog->rolename=$roleInfo['name'];
  5428. }
  5429. $receiptLog->username=$this->staff[0]['username'];
  5430. $receiptLog->uid=$this->staff[0]['sid'];
  5431. $receiptLog->date=date("Y-m-d");
  5432. $receiptLog->opinion='撤回';
  5433. $receiptLog->img=$this->staff[0]['avatar'];
  5434. $receiptLog->status=4;
  5435. $receiptLog->rid=$rid;
  5436. $receiptLog->insert();
  5437. $receipt->status=4;
  5438. $receipt->update(array('where'=>'rid='.$rid));
  5439. }
  5440. //echo "ddd";
  5441. return '/saeaBorad';
  5442. }
  5443. function revisePrice(){
  5444. $description=$this->get_args('description')?$this->get_args('description'):"";
  5445. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5446. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5447. //echo $price;die;
  5448. if (!empty($rid)){
  5449. Doo::loadModel("receipt");
  5450. $receipt=new receipt();
  5451. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5452. if (empty($receiptDetail))
  5453. return "/approval";
  5454. $reviseDetail=array();
  5455. if (empty($receiptDetail['reviseDetail'])){
  5456. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5457. $reviseDetailString=json_encode($reviseDetail);
  5458. $receipt->reviseDetail=$reviseDetailString;
  5459. $receipt->revisePrice=$price;
  5460. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5461. }else{
  5462. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5463. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5464. $reviseDetailString=json_encode($reviseDetail);
  5465. $receipt->reviseDetail=$reviseDetailString;
  5466. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5467. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5468. }
  5469. $receipt->update(array('where'=>'rid='.$rid));
  5470. }
  5471. return '/approvalEdi/'.$rid;
  5472. }
  5473. function personalCollect(){
  5474. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5475. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5476. $this->showCache($path);
  5477. Doo::loadModel("receiptDetail");
  5478. Doo::loadModel("itemStatistics");
  5479. Doo::loadModel('statistics');
  5480. $statistics=new statistics();
  5481. $itemStatistics=new itemStatistics();
  5482. $receiptDetail=new receiptDetail();
  5483. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5484. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5485. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5486. //create collect html
  5487. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5488. $adjustment=array();
  5489. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5490. array_push($collectArray['日常相关费用'], $collectHtml);
  5491. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5492. array_push($collectArray['差旅相关费用'], $collectHtml);
  5493. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5494. array_push($collectArray['培训班费用'], $collectHtml);
  5495. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5496. array_push($collectArray['其他'], $collectHtml);
  5497. $data['collectArray']=$collectArray;
  5498. //statistics html
  5499. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5500. if(empty($stList))
  5501. $stList=array('rePrice'=>0,'agPrice'=>0);
  5502. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5503. //Adjustment price html
  5504. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5505. array_push($adjustment, $collectHtml);
  5506. $data['adjustment']=$adjustment;
  5507. //total price html
  5508. $collectHtml="";$total=0;
  5509. for ($i=1;$i<=12;$i++){
  5510. $sumPrice=0;
  5511. foreach ($receiptCollectList as $key=>$value){
  5512. if($value['month']==$i){
  5513. $sumPrice+=$value['price'];
  5514. }
  5515. }
  5516. if ($sumPrice==0)
  5517. $collectHtml.='<td class="taR">-</td>';
  5518. else
  5519. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5520. $total+=$sumPrice;
  5521. }
  5522. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5523. $data['totalPrice']=$collectHtml;
  5524. $data['year']=$year;
  5525. $data['totalYear']=$total;
  5526. $data['memu']="receipt";
  5527. $data['staff']=$this->staff;
  5528. $data['receiptMemu']='personalCollect';
  5529. $data['verifyId']=$this->verifyId;
  5530. $data['executeId']=$this->executeId;
  5531. //year staff status 2,4
  5532. if($year<date("Y")){
  5533. Doo::loadModel('receipt');
  5534. $receipt=new receipt();
  5535. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5536. if(empty($receiptList)){
  5537. ob_start();
  5538. $this->render ( "/admin/saea_slist_collect", $data );
  5539. $this->cacheFile($path);die;
  5540. }
  5541. }
  5542. $this->render ( "/admin/saea_slist_collect", $data );
  5543. }
  5544. function personalCollectDetail(){
  5545. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5546. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5547. $this->showCache($path);
  5548. Doo::loadModel("receiptDetail");
  5549. Doo::loadModel("itemStatistics");
  5550. Doo::loadModel('statistics');
  5551. Doo::loadModel('accountItem');
  5552. $accountItem=new accountItem();
  5553. $statistics=new statistics();
  5554. $itemStatistics=new itemStatistics();
  5555. $receiptDetail=new receiptDetail();
  5556. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5557. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5558. $accountList=$accountItem->find(array('asArray'=>true));
  5559. //create CollectDetail HTML
  5560. $collectHtml=array();
  5561. foreach ($accountList as $key=>$value){
  5562. $html="";$asum=0;
  5563. for ($i=1;$i<=12;$i++){
  5564. $falg=true;
  5565. foreach ($receiptCollectList as $v) {
  5566. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5567. $asum+=$v['price'];
  5568. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5569. }
  5570. }
  5571. if($falg)
  5572. $html.='<td class="taR">-</td>';
  5573. }
  5574. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5575. $collectHtml[$value['category']][$value['name']]=$html;
  5576. }
  5577. $data['collectHtml']=$collectHtml;
  5578. //create Adjustment price html
  5579. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5580. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5581. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5582. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5583. array_push($collectArray['日常相关费用'], $collectHtml);
  5584. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5585. array_push($collectArray['差旅相关费用'], $collectHtml);
  5586. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5587. array_push($collectArray['培训班费用'], $collectHtml);
  5588. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5589. array_push($collectArray['其他'], $collectHtml);
  5590. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5591. array_push($adjustment, $collectHtml);
  5592. //total price html
  5593. $collectHtml="";$total=0;
  5594. for ($i=1;$i<=12;$i++){
  5595. $sumPrice=0;
  5596. foreach ($receiptCollectList as $key=>$value){
  5597. if($value['month']==$i){
  5598. $sumPrice+=$value['price'];
  5599. }
  5600. }
  5601. if ($sumPrice==0)
  5602. $collectHtml.='<td class="taR">-</td>';
  5603. else
  5604. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5605. $total+=$sumPrice;
  5606. }
  5607. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5608. //statistics html
  5609. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5610. if(empty($stList))
  5611. $stList=array('rePrice'=>0,'agPrice'=>0);
  5612. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5613. $data['collectArray']=$collectArray;
  5614. $data['adjustment']=$adjustment;
  5615. $data['totalPrice']=$collectHtml;
  5616. $data['totalYear']=$total;
  5617. $data['year']=$year;
  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/saeaCollectArticles", $data );
  5631. $this->cacheFile($path);die;
  5632. }
  5633. }
  5634. $this->render ( "/admin/saeaCollectArticles", $data );
  5635. }
  5636. function companyCategoryCollect(){
  5637. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5638. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5639. $this->showCache($path);
  5640. Doo::loadModel('L_category');
  5641. Doo::loadModel('itemStatistics');
  5642. Doo::loadModel('statistics');
  5643. $statistics=new statistics();
  5644. $Lcategory=new L_category();
  5645. $itemStatistics=new itemStatistics();
  5646. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5647. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5648. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5649. //ceatre companyCollectHtml
  5650. foreach ($LcategoryList as $value){
  5651. $html="";$asum=0;
  5652. for ($i=1;$i<=12;$i++){
  5653. $falg=true;
  5654. foreach ($itemStatisticsList as $v){
  5655. if($value['cid']==$v['cid']&&$i==$v['month']){
  5656. $asum+=$v['price'];
  5657. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5658. }
  5659. }
  5660. if($falg)
  5661. $html.='<td class="taR">-</td>';
  5662. }
  5663. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5664. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5665. }
  5666. $data['companyHtml']=$collectHtml;
  5667. //total price html
  5668. $collectHtml="";$total=0;
  5669. for ($i=1;$i<=12;$i++){
  5670. $sumPrice=0;
  5671. foreach ($itemStatisticsList as $key=>$value){
  5672. if($value['month']==$i){
  5673. $sumPrice+=$value['price'];
  5674. }
  5675. }
  5676. if ($sumPrice==0)
  5677. $collectHtml.='<td class="taR">-</td>';
  5678. else
  5679. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5680. $total+=$sumPrice;
  5681. }
  5682. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5683. $data['companyTotalHtml']=$collectHtml;
  5684. $data['total']=$total;
  5685. //statistics html
  5686. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5687. if(empty($stList))
  5688. $stList=array('rePrice'=>0,'agPrice'=>0);
  5689. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5690. $data['year']=$year;
  5691. $data['memu']="receipt";
  5692. $data['staff']=$this->staff;
  5693. $data['receiptMemu']='companyCategoryCollect';
  5694. $data['verifyId']=$this->verifyId;
  5695. $data['executeId']=$this->executeId;
  5696. //year staff status 2,4
  5697. if($year<date("Y")){
  5698. Doo::loadModel('receipt');
  5699. $receipt=new receipt();
  5700. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5701. if(empty($receiptList)){
  5702. ob_start();
  5703. $this->render ( "/admin/saeaCompanyCollect", $data );
  5704. $this->cacheFile($path);die;
  5705. }
  5706. }
  5707. $this->render ( "/admin/saeaCompanyCollect", $data );
  5708. }
  5709. function categoryCollectDetail(){
  5710. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5711. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5712. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5713. $this->showCache($path);
  5714. Doo::loadModel('statistics');
  5715. $statistics=new statistics();
  5716. Doo::loadModel("receiptDetail");
  5717. $receiptDetail=new receiptDetail();
  5718. Doo::loadModel('L_category');
  5719. $Lcategory=new L_category();
  5720. Doo::loadModel('accountItem');
  5721. $accountItem=new accountItem();
  5722. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5723. if ($cid==0){
  5724. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5725. if ($cid==0)
  5726. $cid=$LcategoryList[0]['cid'];
  5727. }
  5728. $data['LcategoryList']=$LcategoryList;
  5729. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5730. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5731. $accountList=$accountItem->find(array('asArray'=>true));
  5732. //create CollectDetail HTML
  5733. $collectHtml=array();
  5734. foreach ($accountList as $key=>$value){
  5735. $html="";$asum=0;
  5736. for ($i=1;$i<=12;$i++){
  5737. $falg=true;
  5738. foreach ($receiptCollectList as $v) {
  5739. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5740. $asum+=$v['price'];
  5741. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5742. }
  5743. }
  5744. if($falg)
  5745. $html.='<td class="taR">-</td>';
  5746. }
  5747. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5748. $collectHtml[$value['category']][$value['name']]=$html;
  5749. }
  5750. $data['collectHtml']=$collectHtml;
  5751. //create Adjustment price html
  5752. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5753. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5754. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5755. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5756. array_push($collectArray['日常相关费用'], $collectHtml);
  5757. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5758. array_push($collectArray['差旅相关费用'], $collectHtml);
  5759. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5760. array_push($collectArray['培训班费用'], $collectHtml);
  5761. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5762. array_push($collectArray['其他'], $collectHtml);
  5763. $data['collectArray']=$collectArray;
  5764. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5765. array_push($adjustment, $collectHtml);
  5766. $data['adjustment']=$adjustment;
  5767. //total price html
  5768. $collectHtml="";$total=0;
  5769. for ($i=1;$i<=12;$i++){
  5770. $sumPrice=0;
  5771. foreach ($receiptCollectList as $key=>$value){
  5772. if($value['month']==$i){
  5773. $sumPrice+=$value['price'];
  5774. }
  5775. }
  5776. if ($sumPrice==0)
  5777. $collectHtml.='<td class="taR">-</td>';
  5778. else
  5779. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5780. $total+=$sumPrice;
  5781. }
  5782. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5783. //statistics html
  5784. $stList=$statistics->statisticsByCid($year,$cid);
  5785. if(empty($stList))
  5786. $stList=array('rePrice'=>0,'agPrice'=>0);
  5787. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5788. $data['totalYear']=$total;
  5789. $data['year']=$year;
  5790. $data['cid']=$cid;
  5791. $data['memu']="receipt";
  5792. $data['staff']=$this->staff;
  5793. $data['receiptMemu']='companyCategoryCollect';
  5794. $data['verifyId']=$this->verifyId;
  5795. $data['executeId']=$this->executeId;
  5796. //year staff status 2,4
  5797. if($year<date("Y")){
  5798. Doo::loadModel('receipt');
  5799. $receipt=new receipt();
  5800. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5801. if(empty($receiptList)){
  5802. ob_start();
  5803. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5804. $this->cacheFile($path);die;
  5805. }
  5806. }
  5807. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5808. }
  5809. function staffCollect(){
  5810. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5811. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5812. //$this->showCache($path);
  5813. Doo::loadModel('statistics');
  5814. $statistics=new statistics();
  5815. Doo::loadModel("receiptDetail");
  5816. $receiptDetail=new receiptDetail();
  5817. Doo::loadModel('L_category');
  5818. $Lcategory=new L_category();
  5819. Doo::loadModel('accountItem');
  5820. $accountItem=new accountItem();
  5821. Doo::loadModel('staff');
  5822. $staff=new staff();
  5823. Doo::loadModel('itemStatistics');
  5824. $itemStatistics=new itemStatistics();
  5825. /*
  5826. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5827. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5828. if(empty($stList))
  5829. $stList=array('rePrice'=>0,'agPrice'=>0);
  5830. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5831. */
  5832. //statistics html
  5833. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5834. if(empty($stList))
  5835. $stList=array('rePrice'=>0,'agPrice'=>0);
  5836. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5837. //---
  5838. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5839. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5840. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5841. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5842. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5843. //print_r($itemStatisticsList);die;
  5844. //ceatre companyCollectHtml
  5845. foreach ($categoryList as $vlu){
  5846. $count=$vlu['count']+1;
  5847. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5848. $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;
  5849. foreach ($staffList as $value){
  5850. if ($vlu['cid']==$value['cid']){
  5851. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5852. $asum=0;
  5853. for ($i=1;$i<=12;$i++){
  5854. $falg=true;
  5855. foreach ($itemStatisticsList as $v){
  5856. if($value['sid']==$v['staff']&&$i==$v['month']){
  5857. if ($v['month']==1)
  5858. $m1+=$v['price'];
  5859. if ($v['month']==2)
  5860. $m2+=$v['price'];
  5861. if ($v['month']==3)
  5862. $m3+=$v['price'];
  5863. if ($v['month']==4)
  5864. $m4+=$v['price'];
  5865. if ($v['month']==5)
  5866. $m5+=$v['price'];
  5867. if ($v['month']==6)
  5868. $m6+=$v['price'];
  5869. if ($v['month']==7)
  5870. $m7+=$v['price'];
  5871. if ($v['month']==8)
  5872. $m8+=$v['price'];
  5873. if ($v['month']==9)
  5874. $m9+=$v['price'];
  5875. if ($v['month']==10)
  5876. $m10+=$v['price'];
  5877. if ($v['month']==11)
  5878. $m11+=$v['price'];
  5879. if ($v['month']==12)
  5880. $m12+=$v['price'];
  5881. $asum+=$v['price'];
  5882. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5883. }
  5884. }
  5885. if($falg)
  5886. $html.='<td class="taR">-</td>';
  5887. }
  5888. $m13+=$asum;
  5889. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5890. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5891. $html="";
  5892. }
  5893. }
  5894. $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>
  5895. <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>
  5896. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5897. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5898. }
  5899. $data['companyHtml']=$collectHtml;
  5900. //total price html
  5901. $collectHtml="";$total=0;
  5902. for ($i=1;$i<=12;$i++){
  5903. $sumPrice=0;
  5904. foreach ($itemStatisticsList as $key=>$value){
  5905. if($value['month']==$i){
  5906. $sumPrice+=$value['price'];
  5907. }
  5908. }
  5909. if ($sumPrice==0)
  5910. $collectHtml.='<td class="taR">-</td>';
  5911. else
  5912. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5913. $total+=$sumPrice;
  5914. }
  5915. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5916. $data['companyTotalHtml']=$collectHtml;
  5917. $data['total']=$total;
  5918. $data['year']=$year;
  5919. $data['memu']="receipt";
  5920. $data['staff']=$this->staff;
  5921. $data['receiptMemu']='companyCategoryCollect';
  5922. $data['verifyId']=$this->verifyId;
  5923. $data['executeId']=$this->executeId;
  5924. if ($year<=date("Y")){
  5925. Doo::loadModel('receipt');
  5926. $receipt=new receipt();
  5927. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5928. if(empty($receiptList)){ //generated files
  5929. ob_start();
  5930. $this->render ( "/admin/saeaStaffCollectB", $data );
  5931. $this->cacheFile($path);die;
  5932. }
  5933. }
  5934. $this->render ( "/admin/saeaStaffCollectB", $data );
  5935. }
  5936. function staffCollectBak(){
  5937. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5938. $month=$this->get_args('month')?$this->get_args('month'):1;
  5939. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5940. $this->showCache($path);
  5941. Doo::loadModel('statistics');
  5942. $statistics=new statistics();
  5943. Doo::loadModel("receiptDetail");
  5944. $receiptDetail=new receiptDetail();
  5945. Doo::loadModel('L_category');
  5946. $Lcategory=new L_category();
  5947. Doo::loadModel('accountItem');
  5948. $accountItem=new accountItem();
  5949. Doo::loadModel('staff');
  5950. $staff=new staff();
  5951. Doo::loadModel('itemStatistics');
  5952. $itemStatistics=new itemStatistics();
  5953. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5954. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5955. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5956. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5957. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5958. $staffList=$staff->find(array('asArray'=>true));
  5959. $htmlArray=array();
  5960. foreach ($LcategoryList as $value){
  5961. $htmlArray[$value['title']]=array();
  5962. foreach ($staffList as $v){
  5963. if($value['cid']==$v['cid']){
  5964. $html="";$falg=true;$staffSumPrice=0;
  5965. foreach ($itemStatisticsList as $a){
  5966. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5967. if(empty($a['price'])){
  5968. $html.='<td class="taR">-</td>';$falg=false;break;
  5969. }else{
  5970. $staffSumPrice+=$a['price'];
  5971. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5972. }
  5973. }
  5974. }
  5975. if ($falg){
  5976. $html.='<td class="taR">-</td>';$falg=true;
  5977. }
  5978. $falg=true;
  5979. foreach ($itemStatisticsList as $a){
  5980. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5981. if(empty($a['price'])){
  5982. $html.='<td class="taR">-</td>';$falg=false;break;
  5983. }else{
  5984. $staffSumPrice+=$a['price'];
  5985. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5986. }
  5987. }
  5988. }
  5989. if ($falg){
  5990. $html.='<td class="taR">-</td>';$falg=true;
  5991. }
  5992. $falg=true;
  5993. foreach ($itemStatisticsList as $a){
  5994. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5995. if(empty($a['price'])){
  5996. $html.='<td class="taR">-</td>';$falg=false;break;
  5997. }else{
  5998. $staffSumPrice+=$a['price'];
  5999. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6000. }
  6001. }
  6002. }
  6003. if ($falg){
  6004. $html.='<td class="taR">-</td>';$falg=true;
  6005. }
  6006. $falg=true;
  6007. foreach ($itemStatisticsList as $a){
  6008. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6009. if(!empty($a['price'])){
  6010. $staffSumPrice+=$a['price'];
  6011. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6012. }else{
  6013. $html.='<td class="taR">-</td>';$falg=false;break;
  6014. }
  6015. }
  6016. }
  6017. if ($falg){
  6018. $html.='<td class="taR">-</td>';$falg=true;
  6019. }
  6020. $falg=true;
  6021. foreach ($itemStatisticsList as $a){
  6022. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6023. if(!empty($a['price'])){
  6024. $staffSumPrice+=$a['price'];
  6025. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6026. }else{
  6027. $html.='<td class="taR">-</td>';$falg=false;break;
  6028. }
  6029. }
  6030. }
  6031. if ($falg){
  6032. $html.='<td class="taR">-</td>';$falg=true;
  6033. }
  6034. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6035. $htmlArray[$value['title']][$v['username']]=$html;
  6036. }
  6037. }
  6038. /*-- ---*/
  6039. //合计费用
  6040. $cateHtml="";$catePrice=0;$cateFalg=true;
  6041. foreach ($itemCategoryList as $l){
  6042. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6043. if(empty($l['price'])){
  6044. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6045. }else{
  6046. $catePrice+=$l['price'];
  6047. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6048. }
  6049. }
  6050. }
  6051. if ($cateFalg){
  6052. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6053. }
  6054. $cateFalg=true;
  6055. foreach ($itemCategoryList as $l){
  6056. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6057. if(empty($l['price'])){
  6058. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6059. }else{
  6060. $catePrice+=$l['price'];
  6061. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6062. }
  6063. }
  6064. }
  6065. if ($cateFalg){
  6066. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6067. }
  6068. $cateFalg=true;
  6069. foreach ($itemCategoryList as $l){
  6070. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6071. if(empty($l['price'])){
  6072. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6073. }else{
  6074. $catePrice+=$l['price'];
  6075. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6076. }
  6077. }
  6078. }
  6079. if ($cateFalg){
  6080. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6081. }
  6082. $cateFalg=true;
  6083. foreach ($itemCategoryList as $l){
  6084. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6085. if(empty($l['price'])){
  6086. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6087. }else{
  6088. $catePrice+=$l['price'];
  6089. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6090. }
  6091. }
  6092. }
  6093. if ($cateFalg){
  6094. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6095. }
  6096. $cateFalg=true;
  6097. foreach ($itemCategoryList as $l){
  6098. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6099. if(empty($l['price'])){
  6100. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6101. }else{
  6102. $catePrice+=$l['price'];
  6103. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6104. }
  6105. }
  6106. }
  6107. if ($cateFalg){
  6108. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6109. }
  6110. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6111. $htmlArray[$value['title']]['合计']=$cateHtml;
  6112. /*-- ---*/
  6113. }
  6114. //print_r($htmlArray);die;
  6115. $data['htmlArray']=$htmlArray;
  6116. //statistics html
  6117. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6118. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6119. if(empty($stList))
  6120. $stList=array('rePrice'=>0,'agPrice'=>0);
  6121. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6122. $monthHtml="";
  6123. for ($i=1;$i<=12;$i++){
  6124. if ($i==$month)
  6125. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6126. else
  6127. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6128. }
  6129. $data['monthHtml']=$monthHtml;
  6130. $data['year']=$year;
  6131. $data['month']=$month;
  6132. $data['memu']="receipt";
  6133. $data['staff']=$this->staff;
  6134. $data['receiptMemu']='companyCategoryCollect';
  6135. $data['verifyId']=$this->verifyId;
  6136. $data['executeId']=$this->executeId;
  6137. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6138. Doo::loadModel('receipt');
  6139. $receipt=new receipt();
  6140. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6141. if(empty($receiptList)){ //generated files
  6142. ob_start();
  6143. $this->render ( "/admin/saeaStaffCollect", $data );
  6144. $this->cacheFile($path);die;
  6145. }
  6146. }
  6147. $this->render ( "/admin/saeaStaffCollect", $data );
  6148. }
  6149. function lyt(){
  6150. Doo::loadModel("receiptDetail");
  6151. $receiptDetail=new receiptDetail();
  6152. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6153. foreach ($receiptCollectList as $key=>$value){
  6154. $receiptDetail=new receiptDetail();
  6155. $receiptDetail->pastDate=$value['date'];
  6156. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6157. }
  6158. }
  6159. function staffCollectMonthDetail(){
  6160. $year=$this->get_args('year')?$this->get_args('year'):"";
  6161. $month=$this->get_args('month')?$this->get_args('month'):"";
  6162. if(!$year)
  6163. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6164. if(!$month)
  6165. $month=isset($this->params['month'])?$this->params['month']:1;
  6166. Doo::loadModel('staff');
  6167. $staff=new staff();
  6168. Doo::loadModel("receiptDetail");
  6169. $receiptDetail=new receiptDetail();
  6170. Doo::loadModel('accountItem');
  6171. $accountItem=new accountItem();
  6172. Doo::loadModel('statistics');
  6173. $statistics=new statistics();
  6174. Doo::loadModel('L_category');
  6175. $lCategory=new L_category();
  6176. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6177. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6178. $list=array();
  6179. foreach ($categoryList as $vlu){
  6180. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6181. $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;
  6182. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6183. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6184. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6185. $s1=0;
  6186. $m1=0;
  6187. foreach ($staffList as $value){
  6188. if ($vlu['cid']==$value['cid']){
  6189. //pastDate
  6190. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6191. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6192. // if ($value['sid']==42){
  6193. // print_r($receiptCollectList);die;
  6194. // }
  6195. if(!empty($receiptCollectList)){
  6196. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6197. $html="";
  6198. $psum=0;
  6199. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6200. foreach ($item as $va){
  6201. $falg=true;
  6202. foreach ($receiptCollectList as $v){
  6203. if($v['itemCategory']=='日常相关费用'){
  6204. if($v['item']==$va){
  6205. if ($va=='市内交通费')
  6206. $r1+=$v['price'];
  6207. if ($va=='市内出租费')
  6208. $r2+=$v['price'];
  6209. if ($va=='办事处房租')
  6210. $r3+=$v['price'];
  6211. if ($va=='电话费')
  6212. $r4+=$v['price'];
  6213. if ($va=='水费')
  6214. $r5+=$v['price'];
  6215. if ($va=='电费')
  6216. $r6+=$v['price'];
  6217. if ($va=='办公费用')
  6218. $r7+=$v['price'];
  6219. if ($va=='邮寄费')
  6220. $r8+=$v['price'];
  6221. if ($va=='其他费用')
  6222. $r9+=$v['price'];
  6223. if ($va=='车辆费用')
  6224. $r10+=$v['price'];
  6225. if ($va=='广告费')
  6226. $r11+=$v['price'];
  6227. if ($va=='团队建设费')
  6228. $r13+=$v['price'];
  6229. if ($va=='物业管理费')
  6230. $r14+=$v['price'];
  6231. if ($va=='宽带费')
  6232. $r15+=$v['price'];
  6233. $psum+=$v['price'];
  6234. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6235. }
  6236. }
  6237. }
  6238. if($falg)
  6239. $html.='<td class="taR">-</td>';
  6240. }
  6241. $r12+=$psum;
  6242. if(!empty($psum))
  6243. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6244. else
  6245. $psum='<td class="colGreen taR">-</td>';
  6246. $receiptL['日常相关费用']=$psum.$html;
  6247. /*-----------------------------------*/
  6248. $html="";
  6249. $psum=0;
  6250. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6251. foreach ($item as $va){
  6252. $falg=true;
  6253. foreach ($receiptCollectList as $v){
  6254. if($v['itemCategory']=='差旅相关费用'){
  6255. if($v['item']==$va){
  6256. if ($va=='往来交通费')
  6257. $c1+=$v['price'];
  6258. if ($va=='市内交通费')
  6259. $c2+=$v['price'];
  6260. if ($va=='出差住宿费')
  6261. $c3+=$v['price'];
  6262. if ($va=='出差补助')
  6263. $c4+=$v['price'];
  6264. if ($va=='其他费用')
  6265. $c5+=$v['price'];
  6266. $psum+=$v['price'];
  6267. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6268. }
  6269. }
  6270. }
  6271. if($falg)
  6272. $html.='<td class="taR">-</td>';
  6273. }
  6274. $c6+=$psum;
  6275. if(!empty($psum))
  6276. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6277. else
  6278. $psum='<td class="colGreen taR">-</td>';
  6279. $receiptL['差旅相关费用']=$psum.$html;
  6280. /*-------------------------------------*/
  6281. $html="";
  6282. $psum=0;
  6283. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6284. foreach ($item as $va){
  6285. $falg=true;
  6286. foreach ($receiptCollectList as $v){
  6287. if($v['itemCategory']=='培训班费用'){
  6288. if($v['item']==$va){
  6289. if ($va=='场租费')
  6290. $p1+=$v['price'];
  6291. if ($va=='薪酬')
  6292. $p2+=$v['price'];
  6293. if ($va=='住宿费')
  6294. $p3+=$v['price'];
  6295. if ($va=='交通费')
  6296. $p4+=$v['price'];
  6297. if ($va=='餐饮费')
  6298. $p5+=$v['price'];
  6299. if ($va=='办公费')
  6300. $p6+=$v['price'];
  6301. if ($va=='公关费')
  6302. $p7+=$v['price'];
  6303. if ($va=='其他')
  6304. $p8+=$v['price'];
  6305. $psum+=$v['price'];
  6306. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6307. }
  6308. }
  6309. }
  6310. if($falg)
  6311. $html.='<td class="taR">-</td>';
  6312. }
  6313. $p9+=$psum;
  6314. if(!empty($psum))
  6315. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6316. else
  6317. $psum='<td class="colGreen taR">-</td>';
  6318. $receiptL['培训班费用']=$psum.$html;
  6319. /*-------------------------------------*/
  6320. $html="";
  6321. $psum=0;
  6322. $item=array('公关费','广告费','借款','可自加费用');
  6323. foreach ($item as $va){
  6324. $falg=true;
  6325. foreach ($receiptCollectList as $v){
  6326. if($v['itemCategory']=='其他'){
  6327. // if ($value['sid']==42){
  6328. //
  6329. // echo var_dump($v['item']);
  6330. // echo var_dump($va);
  6331. // echo var_dump($v['item']==" ".$va);
  6332. // echo $v['item']."==".$va."/<br/>";
  6333. // //print_r( $receiptCollectList);//echo $va;
  6334. // }
  6335. if(trim($v['item'])==$va){
  6336. if ($va=='公关费')
  6337. $t1+=$v['price'];
  6338. if ($va=='广告费'){
  6339. $t2+=$v['price'];
  6340. }
  6341. if ($va=='借款')
  6342. $t3+=$v['price'];
  6343. if ($va=='可自加费用')
  6344. $t4+=$v['price'];
  6345. $psum+=$v['price'];
  6346. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6347. }
  6348. }
  6349. }
  6350. if($falg)
  6351. $html.='<td class="taR">-</td>';
  6352. }
  6353. $t5+=$psum;
  6354. if(!empty($psum))
  6355. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6356. else
  6357. $psum='<td class="colGreen taR">-</td>';
  6358. $receiptL['其他']=$psum.$html;
  6359. /*-------------------------------------*/
  6360. $html="";
  6361. $psum=0;
  6362. foreach ($receiptCollectList as $v){
  6363. if($v['itemCategory']=='报销金额调整'){
  6364. if (!empty($v['price'])){
  6365. $psum+=$v['price'];
  6366. }
  6367. }
  6368. }
  6369. $s1+=$psum;
  6370. if(!empty($psum))
  6371. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6372. else
  6373. $psum='<td class="taR colOrange">-</td>';
  6374. $receiptL['报销金额调整']=$psum.$html;
  6375. }else{
  6376. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6377. <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>
  6378. <td class="taR">-</td><td class="taR">-</td>';
  6379. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6380. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6381. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6382. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6383. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6384. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6385. }
  6386. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6387. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6388. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6389. if(!empty($monthStaffPrice[0]['price'])){
  6390. $m1+=$monthStaffPrice[0]['price'];
  6391. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6392. }else
  6393. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6394. $list[$value['username']]=$receiptL;
  6395. }
  6396. }
  6397. $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>
  6398. <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>
  6399. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6400. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6401. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6402. $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>
  6403. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6404. $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>';
  6405. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6406. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6407. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6408. }
  6409. $data['list']=$list;
  6410. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6411. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6412. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6413. //statistics html
  6414. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6415. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6416. if(empty($stList))
  6417. $stList=array('rePrice'=>0,'agPrice'=>0);
  6418. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6419. $monthHtml="";
  6420. for ($i=1;$i<=12;$i++){
  6421. if ($i==$month)
  6422. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6423. else
  6424. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6425. }
  6426. $data['monthHtml']=$monthHtml;
  6427. $data['year']=$year;
  6428. $data['month']=$month;
  6429. $data['memu']="receipt";
  6430. $data['staff']=$this->staff;
  6431. $data['receiptMemu']='companyCategoryCollect';
  6432. $data['verifyId']=$this->verifyId;
  6433. $data['executeId']=$this->executeId;
  6434. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6435. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6436. }
  6437. function staffCollectMonthDetail2(){
  6438. $year=$this->get_args('year')?$this->get_args('year'):"";
  6439. $month=$this->get_args('month')?$this->get_args('month'):"";
  6440. if(!$year)
  6441. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6442. if(!$month)
  6443. $month=isset($this->params['month'])?$this->params['month']:1;
  6444. Doo::loadModel('staff');
  6445. $staff=new staff();
  6446. Doo::loadModel("receiptDetail");
  6447. $receiptDetail=new receiptDetail();
  6448. Doo::loadModel('accountItem');
  6449. $accountItem=new accountItem();
  6450. Doo::loadModel('statistics');
  6451. $statistics=new statistics();
  6452. Doo::loadModel('L_category');
  6453. $lCategory=new L_category();
  6454. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6455. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6456. $list=array();
  6457. foreach ($categoryList as $vlu){
  6458. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6459. $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;
  6460. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6461. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6462. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6463. $s1=0;
  6464. $m1=0;
  6465. foreach ($staffList as $value){
  6466. if ($vlu['cid']==$value['cid']){
  6467. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6468. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6469. if(!empty($receiptCollectList)){
  6470. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6471. $html="";
  6472. $psum=0;
  6473. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6474. foreach ($item as $va){
  6475. $falg=true;
  6476. foreach ($receiptCollectList as $v){
  6477. if($v['itemCategory']=='日常相关费用'){
  6478. if($v['item']==$va){
  6479. if ($va=='市内交通费')
  6480. $r1+=$v['price'];
  6481. if ($va=='市内出租费')
  6482. $r2+=$v['price'];
  6483. if ($va=='办事处房租')
  6484. $r3+=$v['price'];
  6485. if ($va=='电话费')
  6486. $r4+=$v['price'];
  6487. if ($va=='水费')
  6488. $r5+=$v['price'];
  6489. if ($va=='电费')
  6490. $r6+=$v['price'];
  6491. if ($va=='办公费用')
  6492. $r7+=$v['price'];
  6493. if ($va=='邮寄费')
  6494. $r8+=$v['price'];
  6495. if ($va=='其他费用')
  6496. $r9+=$v['price'];
  6497. if ($va=='车辆费用')
  6498. $r10+=$v['price'];
  6499. if ($va=='广告费')
  6500. $r11+=$v['price'];
  6501. if ($va=='团队建设费')
  6502. $r13+=$v['price'];
  6503. if ($va=='物业管理费')
  6504. $r14+=$v['price'];
  6505. if ($va=='宽带费')
  6506. $r15+=$v['price'];
  6507. $psum+=$v['price'];
  6508. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6509. }
  6510. }
  6511. }
  6512. if($falg)
  6513. $html.='<td class="taR">-</td>';
  6514. }
  6515. $r12+=$psum;
  6516. if(!empty($psum))
  6517. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6518. else
  6519. $psum='<td class="colGreen taR">-</td>';
  6520. $receiptL['日常相关费用']=$psum.$html;
  6521. /*-----------------------------------*/
  6522. $html="";
  6523. $psum=0;
  6524. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6525. foreach ($item as $va){
  6526. $falg=true;
  6527. foreach ($receiptCollectList as $v){
  6528. if($v['itemCategory']=='差旅相关费用'){
  6529. if($v['item']==$va){
  6530. if ($va=='往来交通费')
  6531. $c1+=$v['price'];
  6532. if ($va=='市内交通费')
  6533. $c2+=$v['price'];
  6534. if ($va=='出差住宿费')
  6535. $c3+=$v['price'];
  6536. if ($va=='出差补助')
  6537. $c4+=$v['price'];
  6538. if ($va=='其他费用')
  6539. $c5+=$v['price'];
  6540. $psum+=$v['price'];
  6541. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6542. }
  6543. }
  6544. }
  6545. if($falg)
  6546. $html.='<td class="taR">-</td>';
  6547. }
  6548. $c6+=$psum;
  6549. if(!empty($psum))
  6550. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6551. else
  6552. $psum='<td class="colGreen taR">-</td>';
  6553. $receiptL['差旅相关费用']=$psum.$html;
  6554. /*-------------------------------------*/
  6555. $html="";
  6556. $psum=0;
  6557. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6558. foreach ($item as $va){
  6559. $falg=true;
  6560. foreach ($receiptCollectList as $v){
  6561. if($v['itemCategory']=='培训班费用'){
  6562. if($v['item']==$va){
  6563. if ($va=='场租费')
  6564. $p1+=$v['price'];
  6565. if ($va=='薪酬')
  6566. $p2+=$v['price'];
  6567. if ($va=='住宿费')
  6568. $p3+=$v['price'];
  6569. if ($va=='交通费')
  6570. $p4+=$v['price'];
  6571. if ($va=='餐饮费')
  6572. $p5+=$v['price'];
  6573. if ($va=='办公费')
  6574. $p6+=$v['price'];
  6575. if ($va=='公关费')
  6576. $p7+=$v['price'];
  6577. if ($va=='其他')
  6578. $p8+=$v['price'];
  6579. $psum+=$v['price'];
  6580. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6581. }
  6582. }
  6583. }
  6584. if($falg)
  6585. $html.='<td class="taR">-</td>';
  6586. }
  6587. $p9+=$psum;
  6588. if(!empty($psum))
  6589. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6590. else
  6591. $psum='<td class="colGreen taR">-</td>';
  6592. $receiptL['培训班费用']=$psum.$html;
  6593. /*-------------------------------------*/
  6594. $html="";
  6595. $psum=0;
  6596. $item=array('公关费','广告费','借款','可自加费用');
  6597. foreach ($item as $va){
  6598. $falg=true;
  6599. foreach ($receiptCollectList as $v){
  6600. if($v['itemCategory']=='其他'){
  6601. if($v['item']==$va){
  6602. if ($va=='公关费')
  6603. $t1+=$v['price'];
  6604. if ($va=='广告费')
  6605. $t2+=$v['price'];
  6606. if ($va=='借款')
  6607. $t3+=$v['price'];
  6608. if ($va=='可自加费用')
  6609. $t4+=$v['price'];
  6610. $psum+=$v['price'];
  6611. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6612. }
  6613. }
  6614. }
  6615. if($falg)
  6616. $html.='<td class="taR">-</td>';
  6617. }
  6618. $t5+=$psum;
  6619. if(!empty($psum))
  6620. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6621. else
  6622. $psum='<td class="colGreen taR">-</td>';
  6623. $receiptL['其他']=$psum.$html;
  6624. /*-------------------------------------*/
  6625. $html="";
  6626. $psum=0;
  6627. foreach ($receiptCollectList as $v){
  6628. if($v['itemCategory']=='报销金额调整'){
  6629. if (!empty($v['price'])){
  6630. $psum+=$v['price'];
  6631. }
  6632. }
  6633. }
  6634. $s1+=$psum;
  6635. if(!empty($psum))
  6636. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6637. else
  6638. $psum='<td class="taR colOrange">-</td>';
  6639. $receiptL['报销金额调整']=$psum.$html;
  6640. }else{
  6641. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6642. <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>';
  6643. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6644. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6645. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6646. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6647. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6648. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6649. }
  6650. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6651. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6652. if(!empty($monthStaffPrice[0]['price'])){
  6653. $m1+=$monthStaffPrice[0]['price'];
  6654. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6655. }else
  6656. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6657. $list[$value['username']]=$receiptL;
  6658. }
  6659. }
  6660. $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>
  6661. <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>
  6662. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6663. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6664. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6665. $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>
  6666. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6667. $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>';
  6668. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6669. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6670. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6671. }
  6672. $data['list']=$list;
  6673. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6674. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6675. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6676. //statistics html
  6677. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6678. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6679. if(empty($stList))
  6680. $stList=array('rePrice'=>0,'agPrice'=>0);
  6681. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6682. $monthHtml="";
  6683. for ($i=1;$i<=12;$i++){
  6684. if ($i==$month)
  6685. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6686. else
  6687. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6688. }
  6689. $data['monthHtml']=$monthHtml;
  6690. $data['year']=$year;
  6691. $data['month']=$month;
  6692. $data['memu']="receipt";
  6693. $data['staff']=$this->staff;
  6694. $data['receiptMemu']='companyCategoryCollect';
  6695. $data['verifyId']=$this->verifyId;
  6696. $data['executeId']=$this->executeId;
  6697. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6698. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6699. }
  6700. function companyMonthCollectDetail(){
  6701. $year=$this->get_args('year')?$this->get_args('year'):"";
  6702. $month=$this->get_args('month')?$this->get_args('month'):"";
  6703. if(!$year)
  6704. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6705. if(!$month)
  6706. $month=isset($this->params['month'])?$this->params['month']:1;
  6707. Doo::loadModel('staff');
  6708. $staff=new staff();
  6709. Doo::loadModel("receiptDetail");
  6710. $receiptDetail=new receiptDetail();
  6711. Doo::loadModel('accountItem');
  6712. $accountItem=new accountItem();
  6713. Doo::loadModel('statistics');
  6714. $statistics=new statistics();
  6715. Doo::loadModel('L_category');
  6716. $lCategory=new L_category();
  6717. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6718. $categoryList=$lCategory->find(array('asArray'=>true));
  6719. $list=array();
  6720. foreach ($categoryList as $value){
  6721. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6722. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6723. if(!empty($receiptCollectList)){
  6724. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6725. $html="";
  6726. $psum=0;
  6727. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6728. foreach ($item as $va){
  6729. $falg=true;
  6730. foreach ($receiptCollectList as $v){
  6731. if($v['itemCategory']=='日常相关费用'){
  6732. if($v['item']==$va){
  6733. $psum+=$v['price'];
  6734. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6735. }
  6736. }
  6737. }
  6738. if($falg)
  6739. $html.='<td class="taR">-</td>';
  6740. }
  6741. if(!empty($psum))
  6742. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6743. else
  6744. $psum='<td class="colGreen taR">-</td>';
  6745. $receiptL['日常相关费用']=$psum.$html;
  6746. /*-----------------------------------*/
  6747. $html="";
  6748. $psum=0;
  6749. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6750. foreach ($item as $va){
  6751. $falg=true;
  6752. foreach ($receiptCollectList as $v){
  6753. if($v['itemCategory']=='差旅相关费用'){
  6754. if($v['item']==$va){
  6755. $psum+=$v['price'];
  6756. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6757. }
  6758. }
  6759. }
  6760. if($falg)
  6761. $html.='<td class="taR">-</td>';
  6762. }
  6763. if(!empty($psum))
  6764. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6765. else
  6766. $psum='<td class="colGreen taR">-</td>';
  6767. $receiptL['差旅相关费用']=$psum.$html;
  6768. /*-------------------------------------*/
  6769. $html="";
  6770. $psum=0;
  6771. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6772. foreach ($item as $va){
  6773. $falg=true;
  6774. foreach ($receiptCollectList as $v){
  6775. if($v['itemCategory']=='培训班费用'){
  6776. if($v['item']==$va){
  6777. $psum+=$v['price'];
  6778. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6779. }
  6780. }
  6781. }
  6782. if($falg)
  6783. $html.='<td class="taR">-</td>';
  6784. }
  6785. if(!empty($psum))
  6786. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6787. else
  6788. $psum='<td class="colGreen taR">-</td>';
  6789. $receiptL['培训班费用']=$psum.$html;
  6790. /*-------------------------------------*/
  6791. $html="";
  6792. $psum=0;
  6793. $item=array('公关费','广告费','借款','可自加费用');
  6794. foreach ($item as $va){
  6795. $falg=true;
  6796. foreach ($receiptCollectList as $v){
  6797. if($v['itemCategory']=='其他'){
  6798. if($v['item']==$va){
  6799. $psum+=$v['price'];
  6800. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6801. }
  6802. }
  6803. }
  6804. if($falg)
  6805. $html.='<td class="taR">-</td>';
  6806. }
  6807. if(!empty($psum))
  6808. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6809. else
  6810. $psum='<td class="colGreen taR">-</td>';
  6811. $receiptL['其他']=$psum.$html;
  6812. /*-------------------------------------*/
  6813. $html="";
  6814. $psum=0;
  6815. foreach ($receiptCollectList as $v){
  6816. if($v['itemCategory']=='报销金额调整'){
  6817. if (!empty($v['price']))
  6818. $psum+=$v['price'];
  6819. }
  6820. }
  6821. if(!empty($psum))
  6822. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6823. else
  6824. $psum='<td class="taR colOrange">-</td>';
  6825. $receiptL['报销金额调整']=$psum.$html;
  6826. }else{
  6827. $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>
  6828. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6829. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6830. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6831. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6832. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6833. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6834. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6835. }
  6836. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6837. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6838. if(!empty($monthStaffPrice[0]['price']))
  6839. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6840. else
  6841. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6842. $list[$value['title']]=$receiptL;
  6843. }
  6844. $data['list']=$list;
  6845. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6846. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6847. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6848. //print_r($data['monthPriceHtml']);
  6849. // foreach ($data['monthPriceHtml'] as $value){
  6850. // echo $value;
  6851. // }
  6852. // die;
  6853. //statistics html
  6854. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6855. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6856. if(empty($stList))
  6857. $stList=array('rePrice'=>0,'agPrice'=>0);
  6858. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6859. $monthHtml="";
  6860. for ($i=1;$i<=12;$i++){
  6861. if ($i==$month)
  6862. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6863. else
  6864. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6865. }
  6866. $data['monthHtml']=$monthHtml;
  6867. $data['year']=$year;
  6868. $data['month']=$month;
  6869. $data['memu']="receipt";
  6870. $data['staff']=$this->staff;
  6871. $data['receiptMemu']='companyCategoryCollect';
  6872. $data['verifyId']=$this->verifyId;
  6873. $data['executeId']=$this->executeId;
  6874. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6875. }
  6876. function staffCollectDetail(){
  6877. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6878. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6879. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6880. if(!$staffname){
  6881. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6882. $staffname= urldecode($staffname);
  6883. }
  6884. Doo::loadModel('staff');
  6885. $staff=new staff();
  6886. Doo::loadModel("receiptDetail");
  6887. $receiptDetail=new receiptDetail();
  6888. Doo::loadModel('accountItem');
  6889. $accountItem=new accountItem();
  6890. Doo::loadModel('statistics');
  6891. $statistics=new statistics();
  6892. Doo::loadModel('L_category');
  6893. $lCategory=new L_category();
  6894. $staffList=$staff->find(array('asArray'=>true));
  6895. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6896. foreach ($staffList as $value){
  6897. if ($value['username']==$staffname&&$value['username']!='admin'){
  6898. $stTitle=$value['category'].'-'.$value['username'];
  6899. $staffId=$value['sid'];
  6900. $cid=$value['cid'];
  6901. $ocid=$value['cid'];
  6902. if (!empty($value['othercid']))
  6903. $cid=$value['cid'].','.$value['othercid'];
  6904. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6905. }elseif ($value['username']!='admin')
  6906. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6907. }
  6908. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6909. if(empty($pcid))
  6910. $pcid=$ocid;
  6911. $data['ocid']=$pcid;
  6912. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6913. $this->showCache($path);
  6914. //
  6915. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6916. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6917. $accountList=$accountItem->find(array('asArray'=>true));
  6918. //create CollectDetail HTML
  6919. $collectHtml=array();
  6920. foreach ($accountList as $key=>$value){
  6921. $html="";$asum=0;
  6922. for ($i=1;$i<=12;$i++){
  6923. $falg=true;
  6924. foreach ($receiptCollectList as $v) {
  6925. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6926. $asum+=$v['price'];
  6927. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6928. }
  6929. }
  6930. if($falg)
  6931. $html.='<td class="taR">-</td>';
  6932. }
  6933. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6934. $collectHtml[$value['category']][$value['name']]=$html;
  6935. }
  6936. $data['collectHtml']=$collectHtml;
  6937. //create Adjustment price html
  6938. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6939. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6940. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6941. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6942. array_push($collectArray['日常相关费用'], $collectHtml);
  6943. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6944. array_push($collectArray['差旅相关费用'], $collectHtml);
  6945. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6946. array_push($collectArray['培训班费用'], $collectHtml);
  6947. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6948. array_push($collectArray['其他'], $collectHtml);
  6949. $data['collectArray']=$collectArray;
  6950. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6951. array_push($adjustment, $collectHtml);
  6952. $data['adjustment']=$adjustment;
  6953. //total price html
  6954. $collectHtml="";$total=0;
  6955. for ($i=1;$i<=12;$i++){
  6956. $sumPrice=0;
  6957. foreach ($receiptCollectList as $key=>$value){
  6958. if($value['month']==$i){
  6959. $sumPrice+=$value['price'];
  6960. }
  6961. }
  6962. if ($sumPrice==0)
  6963. $collectHtml.='<td class="taR">-</td>';
  6964. else
  6965. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6966. $total+=$sumPrice;
  6967. }
  6968. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6969. //statistics html
  6970. $stList=$statistics->statisticsByYear($year,$staffId);
  6971. if(empty($stList))
  6972. $stList=array('rePrice'=>0,'agPrice'=>0);
  6973. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6974. $data['totalPrice']=$collectHtml;
  6975. $data['totalYear']=$total;
  6976. $data['stHtml']=$stHtml;
  6977. $data['year']=$year;
  6978. $data['stTitle']=$stTitle;
  6979. $data['memu']="receipt";
  6980. $data['staff']=$this->staff;
  6981. $data['receiptMemu']='companyCategoryCollect';
  6982. $data['verifyId']=$this->verifyId;
  6983. $data['executeId']=$this->executeId;
  6984. if ($year<date("Y")){
  6985. Doo::loadModel('receipt');
  6986. $receipt=new receipt();
  6987. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6988. if(empty($receiptList)){ //generated files
  6989. ob_start();
  6990. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6991. $this->cacheFile($path);die;
  6992. }
  6993. }
  6994. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6995. }
  6996. function BUGFLAG(){
  6997. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  6998. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  6999. $month=$this->get_args('month')?$this->get_args('month'):"";
  7000. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7001. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7002. if (empty($status))
  7003. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7004. $page_size=12;
  7005. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7006. $vidList=array();
  7007. $button=0;
  7008. Doo::loadModel('verify');
  7009. $verify=new verify();
  7010. Doo::loadModel('receipt');
  7011. $receipt=new receipt();
  7012. Doo::loadModel('staff');
  7013. $staff=new staff();
  7014. Doo::loadModel('L_category');
  7015. $Lcategory=new L_category();
  7016. $dateCondition=" and Year(date) =".$year;
  7017. if(!empty($month))
  7018. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7019. $categoryList=$Lcategory->find(array('asArray'=>true));
  7020. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7021. $cateCondition="";$staffCondition="";$approvalCondition="";
  7022. if (!empty($cid))
  7023. $cateCondition=' and cid='.$cid;
  7024. if(!empty($sid)){
  7025. $staffCondition=' and staff='.$sid;
  7026. $cateCondition="";
  7027. }
  7028. $approvalCondition=" and status=".$status;
  7029. if($status==2){
  7030. //查找角色审批人
  7031. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7032. }
  7033. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7034. $approvalCondition=' and status=2 ';
  7035. }
  7036. if($status==1){
  7037. $approvalCondition=' and (status='.$status.' or status=6) ';
  7038. }
  7039. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7040. $pageinfo['page']=array('previous'=>'');
  7041. if ($status==0){
  7042. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7043. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7044. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7045. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7046. }else
  7047. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7048. ,'desc'=>'rid','asArray'=>true));
  7049. $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
  7050. ,'desc'=>'rid','asArray'=>true));
  7051. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7052. //print_r($pageinfo);
  7053. $Locate=0;
  7054. foreach ($receiptList as $key=>$value){
  7055. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7056. $receiptList[$key]['reviseDetail']=array();
  7057. if (!empty($value['reviseDetail']))
  7058. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7059. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7060. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7061. $receiptList[$key]['category']=$categoryDetil['title'];
  7062. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7063. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7064. $verifyStaff=json_decode($value['verifyStaff'],true);
  7065. foreach ($verifyList as $k=>$v){
  7066. //init verifyStaff
  7067. $verifyList[$k]['date']="";
  7068. $verifyList[$k]['opinion']="";
  7069. $verifyList[$k]['status']="";
  7070. if (empty($verifyStaff)){
  7071. $verifyList[$k]['date']="";
  7072. $verifyList[$k]['opinion']="";
  7073. if ($v[0]==$this->staff[0]['sid']){
  7074. $verifyList[$k]['status']=4;
  7075. $button=4;
  7076. }
  7077. }else{
  7078. $flag=true;
  7079. foreach ($verifyStaff as $m=>$u){
  7080. if ($v[0]==$m){
  7081. $verifyList[$k]['date']=$u['date'];
  7082. $verifyList[$k]['opinion']=$u['opinion'];
  7083. $verifyList[$k]['status']=$u['status'];
  7084. $flag=false;
  7085. break;
  7086. }
  7087. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7088. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7089. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7090. }
  7091. if($flag){//检测可编辑
  7092. if($v[0]==$this->staff[0]['sid']){
  7093. $verifyList[$k]['status']=4;$button=4;
  7094. }
  7095. }
  7096. }
  7097. }
  7098. $receiptList[$key]['verifyList']=$verifyList;
  7099. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7100. $receiptList[$key]['button']=$button;
  7101. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7102. }
  7103. //print_r($receiptList);die;
  7104. //$data['verifyDetail']=$verifyDetail;
  7105. $mothHtml="";
  7106. for($i=1;$i<=12;$i++){
  7107. if($month==$i)
  7108. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7109. else
  7110. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7111. }
  7112. $data['mothHtml']=$mothHtml;
  7113. $data['page']=$pageinfo;
  7114. $data['receiptList']=$receiptList;
  7115. $data['receiptApprovalCount']=count($rLRes);
  7116. $data['status']=$status;
  7117. $data['year']=$year;
  7118. $data['categoryList']=$categoryList;
  7119. $data['staffList']=$staffList;
  7120. $data['cid']=$cid;
  7121. $data['sid']=$sid;
  7122. //print_r($receiptList);
  7123. $data['memu']="receipt";
  7124. $data['staff']=$this->staff;
  7125. $data['receiptMemu']='approvalExpenses';
  7126. $data['verifyId']=$this->verifyId;
  7127. $data['executeId']=$this->executeId;
  7128. $this->render ( "/admin/FALG", $data );
  7129. }
  7130. function ajaxGetReceiptOrder(){
  7131. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7132. if (!empty($receiptOrder)){
  7133. Doo::loadModel('receipt');
  7134. $receipt=new receipt();
  7135. Doo::loadModel ( 'staff' );
  7136. $staff = new staff ();
  7137. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7138. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7139. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7140. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7141. </tbody></table><table class="table table table-bordered"><tbody>';
  7142. foreach ($verifyStaff as $key=>$value){
  7143. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7144. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7145. }
  7146. $html.='</tbody></table></div></div>';
  7147. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7148. }
  7149. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7150. }
  7151. function _getMonthCollectDetail($receiptCollectList){
  7152. if(!empty($receiptCollectList)){
  7153. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7154. $html="";
  7155. $psum=0;
  7156. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7157. foreach ($item as $value){
  7158. $falg=true;
  7159. foreach ($receiptCollectList as $v){
  7160. if($v['itemCategory']=='日常相关费用'){
  7161. if($v['item']==$value){
  7162. $psum+=$v['price'];
  7163. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7164. }
  7165. }
  7166. }
  7167. if($falg)
  7168. $html.='<td class="taR">-</td>';
  7169. }
  7170. if(!empty($psum))
  7171. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7172. else
  7173. $psum='<td class="colGreen taR">-</td>';
  7174. $receiptL['日常相关费用']=$psum.$html;
  7175. /*-----------------------------------*/
  7176. $html="";
  7177. $psum=0;
  7178. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7179. foreach ($item as $value){
  7180. $falg=true;
  7181. foreach ($receiptCollectList as $v){
  7182. if($v['itemCategory']=='差旅相关费用'){
  7183. if($v['item']==$value){
  7184. $psum+=$v['price'];
  7185. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7186. }
  7187. }
  7188. }
  7189. if($falg)
  7190. $html.='<td class="taR">-</td>';
  7191. }
  7192. if(!empty($psum))
  7193. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7194. else
  7195. $psum='<td class="colGreen taR">-</td>';
  7196. $receiptL['差旅相关费用']=$psum.$html;
  7197. /*-------------------------------------*/
  7198. $html="";
  7199. $psum=0;
  7200. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7201. foreach ($item as $value){
  7202. $falg=true;
  7203. foreach ($receiptCollectList as $v){
  7204. if($v['itemCategory']=='培训班费用'){
  7205. if($v['item']==$value){
  7206. $psum+=$v['price'];
  7207. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7208. }
  7209. }
  7210. }
  7211. if($falg)
  7212. $html.='<td class="taR">-</td>';
  7213. }
  7214. if(!empty($psum))
  7215. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7216. else
  7217. $psum='<td class="colGreen taR">-</td>';
  7218. $receiptL['培训班费用']=$psum.$html;
  7219. /*-------------------------------------*/
  7220. $html="";
  7221. $psum=0;
  7222. $item=array('公关费','广告费','借款','可自加费用');
  7223. foreach ($item as $value){
  7224. $falg=true;
  7225. foreach ($receiptCollectList as $v){
  7226. if($v['itemCategory']=='其他'){
  7227. if($v['item']==$value){
  7228. $psum+=$v['price'];
  7229. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7230. }
  7231. }
  7232. }
  7233. if($falg)
  7234. $html.='<td class="taR">-</td>';
  7235. }
  7236. if(!empty($psum))
  7237. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7238. else
  7239. $psum='<td class="colGreen taR">-</td>';
  7240. $receiptL['其他']=$psum.$html;
  7241. /*-------------------------------------*/
  7242. $html="";
  7243. $psum=0;
  7244. foreach ($receiptCollectList as $v){
  7245. if($v['itemCategory']=='报销金额调整'){
  7246. if (!empty($v['price']))
  7247. $psum+=$v['price'];
  7248. }
  7249. }
  7250. if(!empty($psum))
  7251. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7252. else
  7253. $psum='<td class="taR colOrange">-</td>';
  7254. $receiptL['报销金额调整']=$psum.$html;
  7255. }else{
  7256. $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>
  7257. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7258. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7259. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7260. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7261. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7262. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7263. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7264. }
  7265. return $receiptL;
  7266. }
  7267. function eMail(){
  7268. Doo::loadModel('staff');
  7269. $staff=new staff();
  7270. Doo::loadModel('receipt');
  7271. $receipt=new receipt();
  7272. Doo::loadModel('L_category');
  7273. $Lcategory=new L_category();
  7274. Doo::loadModel("verify");
  7275. $verify=new verify();
  7276. $staffList=$staff->find(array('asArray'=>true));
  7277. foreach ($staffList as $key=>$value){
  7278. if($value['username']!='admin'){
  7279. //提交人
  7280. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7281. if(!empty($receiptList)){
  7282. $html='<br><div><style></style>
  7283. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7284. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7285. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7286. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7287. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7288. <tbody><tr>
  7289. <td style="padding: 0 40px;" align="left">
  7290. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7291. </td></tr><tr>
  7292. <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>
  7293. </tr>
  7294. </tbody> </table></td> </tr> <tr><td>
  7295. <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">
  7296. <tbody> <tr><td>
  7297. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7298. 以下报销单完成了审批,等着收款吧:</p>
  7299. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7300. foreach ($receiptList as $k=>$v){
  7301. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7302. $html.='
  7303. <tr>
  7304. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7305. <td align="left">
  7306. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7307. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7308. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7309. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7310. </tr>';
  7311. }
  7312. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7313. <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>
  7314. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7315. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7316. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7317. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7318. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7319. $receipt=new receipt();
  7320. $receipt->notice=1;
  7321. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7322. }
  7323. }
  7324. //审批人
  7325. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7326. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7327. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7328. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7329. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7330. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7331. <tbody><tr><td style="padding: 0 40px;" align="left">
  7332. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7333. </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>
  7334. </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">
  7335. <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>
  7336. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7337. foreach ($verifyList as $k=>$v){
  7338. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7339. foreach ($receiptList as $r=>$l){
  7340. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7341. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7342. $html.='
  7343. <tr>
  7344. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7345. <td align="left">
  7346. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7347. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7348. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7349. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7350. </tr>';
  7351. }
  7352. }
  7353. $html.='
  7354. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7355. <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>
  7356. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7357. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7358. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7359. // $receipt=new receipt();
  7360. // $receipt->notice=1;
  7361. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7362. }
  7363. }
  7364. }
  7365. }
  7366. // Email发送函数
  7367. function SMail($toemail, $subject, $contents) {
  7368. Doo::loadClass('class.phpmailer');
  7369. $mail = new PHPMailer();
  7370. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7371. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7372. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7373. $mail->Password = "cDO1GjtY1seH"; //密码
  7374. $mail->CharSet = "UTF8";
  7375. $mail->SMTPAuth = true;
  7376. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7377. $mail->Mailer = "smtp";
  7378. $mail->Port = 25;
  7379. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7380. $mail->MsgHTML($contents);
  7381. $mail->AddAddress($toemail);
  7382. $mail->CharSet = "UTF-8";
  7383. return $mail->Send();
  7384. }
  7385. function swfupload(){
  7386. $POST_MAX_SIZE = ini_get('post_max_size');
  7387. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7388. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7389. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7390. header("HTTP/1.1 500 Internal Server Error");
  7391. echo "POST exceeded maximum allowed size.";
  7392. exit(0);
  7393. }
  7394. // Settings
  7395. $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)
  7396. $upload_name = "Filedata";
  7397. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7398. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7399. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7400. // Other variables
  7401. $MAX_FILENAME_LENGTH = 260;
  7402. $file_name = "";
  7403. $file_extension = "";
  7404. $uploadErrors = array(
  7405. 0=>"文件上传成功",
  7406. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7407. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7408. 3=>"上传的文件仅为部分文件",
  7409. 4=>"没有文件上传",
  7410. 6=>"缺少临时文件夹"
  7411. );
  7412. $nk= time();
  7413. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7414. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7415. echo "文件无法保存.";
  7416. exit(0);
  7417. }
  7418. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7419. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7420. exit(0);
  7421. }
  7422. function _GetFileEXT($filename) {
  7423. $pics = explode ( '.', $filename );
  7424. $num = count ( $pics );
  7425. return $pics [$num - 1];
  7426. }
  7427. /**
  7428. * 获取get或者POST值
  7429. * @param string $name 属性名称
  7430. * @return fixed 值
  7431. */
  7432. function get_args($name) {
  7433. if (isset ( $_GET [$name] )) {
  7434. if (is_array ( $_GET [$name] ))
  7435. return $_GET [$name];
  7436. else
  7437. return addslashes ( $_GET [$name] );
  7438. } elseif (isset ( $_POST [$name] )) {
  7439. if (is_array ( $_POST [$name] ))
  7440. return $_POST [$name];
  7441. else
  7442. return addslashes ( $_POST [$name] );
  7443. } else
  7444. return false;
  7445. }
  7446. function num_to_rmb($num){
  7447. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7448. $c2 = "分角元拾佰仟万拾佰仟亿";
  7449. //精确到分后面就不要了,所以只留两个小数位
  7450. $num = round($num, 2);
  7451. //将数字转化为整数
  7452. $num = $num * 100;
  7453. if (strlen($num) > 10) {
  7454. return "金额太大,请检查";
  7455. }
  7456. $i = 0;
  7457. $c = "";
  7458. while (1) {
  7459. if ($i == 0) {
  7460. //获取最后一位数字
  7461. $n = substr($num, strlen($num)-1, 1);
  7462. } else {
  7463. $n = $num % 10;
  7464. }
  7465. //每次将最后一位数字转化为中文
  7466. $p1 = substr($c1, 3 * $n, 3);
  7467. $p2 = substr($c2, 3 * $i, 3);
  7468. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7469. $c = $p1 . $p2 . $c;
  7470. } else {
  7471. $c = $p1 . $c;
  7472. }
  7473. $i = $i + 1;
  7474. //去掉数字最后一位了
  7475. $num = $num / 10;
  7476. $num = (int)$num;
  7477. //结束循环
  7478. if ($num == 0) {
  7479. break;
  7480. }
  7481. }
  7482. $j = 0;
  7483. $slen = strlen($c);
  7484. while ($j < $slen) {
  7485. //utf8一个汉字相当3个字符
  7486. $m = substr($c, $j, 6);
  7487. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7488. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7489. $left = substr($c, 0, $j);
  7490. $right = substr($c, $j + 3);
  7491. $c = $left . $right;
  7492. $j = $j-3;
  7493. $slen = $slen-3;
  7494. }
  7495. $j = $j + 3;
  7496. }
  7497. //这个是为了去掉类似23.0中最后一个“零”字
  7498. if (substr($c, strlen($c)-3, 3) == '零') {
  7499. $c = substr($c, 0, strlen($c)-3);
  7500. }
  7501. //将处理的汉字加上“整”
  7502. if (empty($c)) {
  7503. return "零元整";
  7504. }else{
  7505. return $c . "整";
  7506. }
  7507. }
  7508. /**
  7509. * 获得分页数据
  7510. * @param unknown_type $table
  7511. * @param unknown_type $condition
  7512. * @param unknown_type $on_page
  7513. * @param unknown_type $page_size
  7514. */
  7515. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7516. $page_c = "";
  7517. $page ['previous'] = $this->get_previous ( $on_page );
  7518. $page ['on_page'] = $on_page;
  7519. $total_count = $this->get_table_count ( $table, $condition );
  7520. $total = intval ( $total_count / $page_size );
  7521. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7522. $page ['total_data'] = $total_count;
  7523. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7524. $i = 1;
  7525. $page_max = 1;
  7526. $page_width=3;
  7527. if ($on_page >= $page_width) {
  7528. $page_max = intval ( $on_page / $page_width ) + 1;
  7529. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7530. }
  7531. for(; $i <= $page ['total_page']; $i ++) {
  7532. if ($i == $on_page)
  7533. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7534. else
  7535. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7536. if ($i == ($page_width * $page_max))
  7537. break;
  7538. }
  7539. $page ['page'] = $page_c;
  7540. $page ['lower'] = (-- $on_page) * $page_size;
  7541. return $page;
  7542. }
  7543. /**
  7544. * 获取总页数
  7545. * @param unknown_type $table
  7546. * @param unknown_type $condition
  7547. */
  7548. public function get_table_count($table = "", $condition = "") {
  7549. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7550. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7551. //echo $sql;die;
  7552. $query = Doo::db ()->query ( $sql );
  7553. $result = $query->fetch ();
  7554. return $result ['count'];
  7555. }
  7556. /**
  7557. * 获取上一页
  7558. * @param unknown_type $on_page
  7559. */
  7560. function get_previous($on_page = 1) {
  7561. return $on_page != 0 ? $on_page - 1 : $on_page;
  7562. }
  7563. }
  7564. ?>