ReceiptController.php 301 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($verify)&&!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. $receipt->verify=$verify;
  388. $receipt->executeCopy=$executeDetail['staff'];
  389. $receipt->explanation=$explanation;
  390. $receipt->update();
  391. $receiptDetail=new receiptDetail();
  392. $receiptDetail->delete(array('where'=>'rid='.$rid));
  393. //报销详情
  394. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  395. $receiptDetail=new receiptDetail();
  396. $receiptDetail->staff=$this->staff[0]['sid'];
  397. $receiptDetail->item=$value['name'];
  398. $receiptDetail->itemCategory=$this->AGENCY;
  399. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  400. $receiptDetail->date=date("Y-m-d");
  401. $receiptDetail->cid=$cid;
  402. $receiptDetail->rid=$rid;
  403. $receiptDetail->status=4;
  404. $receiptDetail->insert();
  405. }
  406. //return "/referReceipt/".$rid;
  407. }
  408. return "/saeaBorad";
  409. }
  410. function remitApproval(){
  411. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  412. $status=isset($this->params['status'])?$this->params['status']:'';
  413. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  414. $month=$this->get_args('month')?$this->get_args('month'):"";
  415. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  416. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  417. if (empty($status))
  418. $status=$this->get_args('status')?$this->get_args('status'):2;
  419. $vidList=array();
  420. $button=0;
  421. Doo::loadModel('verify');
  422. Doo::loadModel('receipt');
  423. Doo::loadModel('staff');
  424. $staff=new staff();
  425. $receipt=new receipt();
  426. $verify=new verify();
  427. Doo::loadModel('L_category');
  428. $Lcategory=new L_category();
  429. Doo::loadModel('enclosur');
  430. $enclosur=new enclosur();
  431. //user verify ID
  432. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  433. foreach ($verifyDetail as $key=>$value){
  434. array_push($vidList, $value['vid']);
  435. }
  436. $vid=implode(",", $vidList);
  437. if(empty($verifyDetail))
  438. $vid=0;
  439. $categoryList=$Lcategory->find(array('asArray'=>true));
  440. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  441. $ap="";
  442. if($status==4){
  443. $ap=4;$status=2;
  444. }
  445. //get Receipt By verifyID status 2
  446. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  447. $Locate=0;$roleId=0;
  448. if($ap==4)
  449. $status=4;
  450. foreach ($receiptList as $key=>$value){
  451. $receiptList[$key]['Locate']=$Locate;$Locate++;
  452. $receiptList[$key]['reviseDetail']=array();
  453. if (!empty($value['reviseDetail']))
  454. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  455. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  456. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  457. $receiptList[$key]['category']=$categoryDetil['title'];
  458. //检测编辑状态
  459. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  460. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  461. $verifyStaff=json_decode($value['verifyStaff'],true);
  462. Doo::loadModel('role');
  463. $role=new role();
  464. //print_r($verifyList);
  465. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  466. foreach ($verifyList as $k=>$v){
  467. //init verifyStaff
  468. if ($v[1]=='ROLE'){
  469. if (!empty($verifyStaff)){
  470. $endStaffArray=end($verifyStaff);
  471. if ($v[0]==$endStaffArray['nextStaff']){
  472. $roleId=$v[0];
  473. }
  474. }
  475. $roleVerify=json_decode($v[3],true);
  476. $roleKey=$k;$roleArray=array();
  477. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  478. foreach ($roleVerify as $o=>$p){
  479. $staffID=explode ('_',$p);
  480. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  481. //print_r($staffID);
  482. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  483. array_push($roleArray, $exp);
  484. }
  485. $roleArrayCopy[$v[0]]=$roleArray;
  486. //$verifyList[$k]['roleArray']=$roleArray;
  487. }
  488. //print_r($roleArray);
  489. $verifyList[$k]['date']="";
  490. $verifyList[$k]['opinion']="";
  491. $verifyList[$k]['status']="";
  492. if (empty($verifyStaff)){
  493. $verifyList[$k]['date']="";
  494. $verifyList[$k]['opinion']="";
  495. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  496. $verifyList[$k]['status']=4;
  497. $button=4;$flag=false;
  498. }
  499. }else{
  500. foreach ($verifyStaff as $m=>$u){
  501. if ($v[0]==$m){
  502. $verifyList[$k]['date']=$u['date'];
  503. $verifyList[$k]['opinion']=$u['opinion'];
  504. $verifyList[$k]['status']=$u['status'];
  505. $flag=false;
  506. break;
  507. }
  508. }
  509. $endStaffArray=end($verifyStaff);
  510. if (isset($endStaffArray['ROLE'])){
  511. }else{
  512. $endKey=key($verifyStaff);
  513. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  514. $button=4;
  515. $verifyList[$k]['status']=4;
  516. }
  517. }
  518. }
  519. }
  520. $rolename['name']='';
  521. if (!empty($roleId)){
  522. Doo::loadModel('role');
  523. $role=new role();
  524. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  525. }
  526. if (!empty($verifyStaff))
  527. $endStaffArray=end($verifyStaff);
  528. $KOP=false;
  529. foreach ($roleArrayCopy as $P=>$A){
  530. foreach ( $A as $MKI=>$AVL){
  531. if (!empty($verifyStaff)){
  532. //&&$rolename['rid']==$endStaffArray['nextStaff']
  533. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  534. $button=4;
  535. $roleArrayCopy[$P][$MKI]['status']=4;
  536. }
  537. foreach ($verifyStaff as $m=>$u){
  538. $AVLFK=$AVL[0].'_R';
  539. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  540. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  541. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  542. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  543. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  544. break;
  545. }
  546. }
  547. }else{
  548. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  549. $button=4;
  550. $roleArrayCopy[$P][$MKI]['status']=4;
  551. }
  552. }
  553. //$roleArray[$MKI]['rolename']=$rolename['name'];
  554. $KOP=true;
  555. }
  556. }
  557. foreach ($roleArrayCopy as $k=>$v){
  558. foreach ($verifyList as $m=>$n){
  559. if ($n[0]==$k){
  560. array_splice($verifyList,$m,1,$v);
  561. }
  562. }
  563. }
  564. $receiptList[$key]['verifyList']= $verifyList;
  565. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  566. $receiptList[$key]['button']=$button;
  567. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  568. }
  569. $mothHtml="";
  570. for($i=1;$i<=12;$i++){
  571. if($month==$i)
  572. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  573. else
  574. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  575. }
  576. //获取审批日志
  577. Doo::loadModel('receiptLog');
  578. $receiptLog=new receiptLog();
  579. $rlList=array();
  580. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  581. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  582. if (!empty($rlInfo)){
  583. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  584. }
  585. $receiptList[0]['rlList']=$rlList;
  586. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  587. $enclosurHtml='';
  588. foreach ($enclosurList as $value){
  589. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  590. }
  591. //print_r($receiptList);
  592. $data['enclosurHtml']=$enclosurHtml;
  593. $data['rolename']=$rolename['name'];
  594. $data['datetij']=$tijdate['date'];
  595. $data['mothHtml']=$mothHtml;
  596. $data['rid']=$rid;
  597. $data['receiptList']=$receiptList;
  598. $data['receiptApprovalCount']=count($receiptList);
  599. $data['status']=$status;
  600. $data['year']=$year;
  601. $data['categoryList']=$categoryList;
  602. $data['staffList']=$staffList;
  603. $data['cid']=$cid;
  604. $data['sid']=$sid;
  605. $data['ap']=$ap;
  606. $data['memu']="receipt";
  607. $data['staff']=$this->staff;
  608. $data['receiptMemu']='approvalExpenses';
  609. $data['verifyId']=$this->verifyId;
  610. $data['executeId']=$this->executeId;
  611. $this->render ( "/admin/remitApproval", $data );
  612. }
  613. function saeaLoanAdd(){
  614. Doo::loadModel('verify');
  615. $verify=new verify();
  616. Doo::loadModel("role");
  617. $role=new role();
  618. Doo::loadModel('L_category');
  619. $lCategory=new L_category();
  620. $veList=$verify->find(array('asArray'=>true));
  621. foreach ($veList as $key=>$value){
  622. $v=json_decode($value['staff']);
  623. $list=array();
  624. foreach ($v as $n=>$m){
  625. if ($m['1']=='ROLE'){
  626. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  627. $v[$n][1]=$roleInfo['name'];
  628. array_push($list, $roleInfo['name']);
  629. }else{
  630. array_push($list, $v[$n][1]);
  631. }
  632. }
  633. $veList[$key]['staff']=implode('>', $list);
  634. }
  635. $data['category']=$lCategory->find(array('asArray'=>true));
  636. $data['veList']=$veList;
  637. $data['memu']="receipt";
  638. $data['staff']=$this->staff;
  639. $data['receiptMemu']='saeaBorad';
  640. $data['verifyId']=$this->verifyId;
  641. $data['executeId']=$this->executeId;
  642. $this->render ( "/admin/saeaLoanAdd", $data );
  643. }
  644. function saeaLoanAddDo(){
  645. $agency=$this->get_args('agency');
  646. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  647. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  648. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  649. //die;
  650. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  651. Doo::loadModel('receipt');
  652. Doo::loadModel('receiptDetail');
  653. Doo::loadModel('accountItem');
  654. $accountItem=new accountItem();
  655. $receipt=new receipt();
  656. Doo::loadModel('loanReceipt');
  657. $loanReceipt=new loanReceipt();
  658. Doo::loadModel('execute');
  659. $execute=new execute();
  660. Doo::loadModel('enclosur');
  661. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  662. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  663. // if(!empty($receiptDetail))
  664. // return "/referReceipt/".$receiptDetail['rid'];
  665. $aItem=$accountItem->find(array('asArray'=>true));
  666. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  667. $ag=$tr=$ta=$ot=0;
  668. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  669. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  670. $sum+=$agency;$agencySum+=$agency;
  671. $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, '.', ''));
  672. //借款数据备份
  673. $loanReceipt->loanItem=json_encode($accountJson);
  674. $loanReceipt->staff=$this->staff[0]['sid'];
  675. $loanReceipt->sum=number_format($sum, 2, '.', '');
  676. $loanReceipt->date=date("Y-m-d");
  677. $loanReceipt->cid=$cid;
  678. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  679. $loanReceipt->status=5;
  680. $loanReceipt->Rtype=1;
  681. $loanReceipt->verify=$verify;
  682. $receipt->receiptOrder=$receipt->receiptOrder;
  683. $loanReceipt->explanation=$explanation;
  684. $loanRid=$loanReceipt->insert();
  685. //报销单
  686. $receipt->loanItem=json_encode($accountJson);
  687. $receipt->staff=$this->staff[0]['sid'];
  688. $receipt->sum=number_format($sum, 2, '.', '');
  689. $receipt->date=date("Y-m-d");
  690. $receipt->cid=$cid;
  691. //特殊状态
  692. $receipt->status=5;
  693. $receipt->Rtype=1;
  694. $receipt->loanRid=$loanRid;
  695. //修改审批流程加入角色
  696. $receipt->verify=$verify;
  697. $receipt->executeCopy=$executeDetail['staff'];
  698. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  699. $receipt->explanation=$explanation;
  700. $rid=$receipt->insert();
  701. //执行数据备份
  702. // $executeCopy->rid=$rid;
  703. // $executeCopy->staff=$executeDetail['staff'];
  704. // $executeCopy->eid=$executeDetail['eid'];
  705. // $ecid=$executeCopy->insert();
  706. }
  707. return "/saeaBorad";
  708. }
  709. function saeaLoanEdi(){
  710. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  711. Doo::loadModel('verify');
  712. $verify=new verify();
  713. Doo::loadModel("role");
  714. $role=new role();
  715. Doo::loadModel('L_category');
  716. $lCategory=new L_category();
  717. Doo::loadModel('receipt');
  718. $receipt=new receipt();
  719. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  720. $veList=$verify->find(array('asArray'=>true));
  721. foreach ($veList as $key=>$value){
  722. $v=json_decode($value['staff']);
  723. $list=array();
  724. foreach ($v as $n=>$m){
  725. if ($m['1']=='ROLE'){
  726. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  727. $v[$n][1]=$roleInfo['name'];
  728. array_push($list, $roleInfo['name']);
  729. }else{
  730. array_push($list, $v[$n][1]);
  731. }
  732. }
  733. $veList[$key]['staff']=implode('>', $list);
  734. }
  735. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  736. $data['receiptInfo']=$receiptInfo;
  737. $data['category']=$lCategory->find(array('asArray'=>true));
  738. $data['veList']=$veList;
  739. $data['memu']="receipt";
  740. $data['staff']=$this->staff;
  741. $data['receiptMemu']='saeaBorad';
  742. $data['verifyId']=$this->verifyId;
  743. $data['executeId']=$this->executeId;
  744. $this->render ( "/admin/saeaLoanEdi", $data );
  745. }
  746. function saeaLoanEdiDo(){
  747. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  748. $agency=$this->get_args('agency');
  749. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  750. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  751. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  752. //die;
  753. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  754. Doo::loadModel('receipt');
  755. Doo::loadModel('receiptDetail');
  756. Doo::loadModel('accountItem');
  757. $accountItem=new accountItem();
  758. $receipt=new receipt();
  759. Doo::loadModel('loanReceipt');
  760. $loanReceipt=new loanReceipt();
  761. Doo::loadModel('enclosur');
  762. Doo::loadModel('execute');
  763. $execute=new execute();
  764. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  765. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 and rid='.$rid,'asArray'=>true));
  766. if(empty($receiptDetail))
  767. die('参数错误');
  768. $aItem=$accountItem->find(array('asArray'=>true));
  769. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  770. $ag=$tr=$ta=$ot=0;
  771. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  772. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  773. $sum+=$agency;$agencySum+=$agency;
  774. $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, '.', ''));
  775. //报销单
  776. $receipt->loanItem=json_encode($accountJson);
  777. $receipt->sum=number_format($sum, 2, '.', '');
  778. $receipt->cid=$cid;
  779. //特殊状态
  780. //修改审批流程加入角色
  781. $receipt->verify=$verify;
  782. $receipt->explanation=$explanation;
  783. $receipt->update(array('where'=>'rid='.$rid));
  784. //借款数据更新
  785. $loanReceipt->loanItem=json_encode($accountJson);
  786. $loanReceipt->sum=number_format($sum, 2, '.', '');
  787. $loanReceipt->cid=$cid;
  788. $loanReceipt->verify=$verify;
  789. $loanReceipt->explanation=$explanation;
  790. $receipt->executeCopy=$executeDetail['staff'];
  791. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  792. }
  793. return "/saeaBorad";
  794. }
  795. function saeaLoanReceiptAdd(){
  796. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  797. Doo::loadModel('receipt');
  798. $receipt=new receipt();
  799. Doo::loadModel('loanReceipt');
  800. $loanReceipt=new loanReceipt();
  801. Doo::loadModel('L_category');
  802. $Lcategory=new L_category();
  803. Doo::loadModel('verify');
  804. Doo::loadModel('statistics');
  805. $statistics=new statistics();
  806. $verify=new verify();
  807. Doo::loadModel('staff');
  808. $staff=new staff();
  809. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  810. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  811. $Locate=0;$roleId=0;$button=0;
  812. foreach ($receiptList as $key=>$value){
  813. $receiptList[$key]['Locate']=$Locate;$Locate++;
  814. $receiptList[$key]['reviseDetail']=array();
  815. if (!empty($value['reviseDetail']))
  816. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  817. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  818. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  819. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  820. $receiptList[$key]['category']=$categoryDetil['title'];
  821. //检测编辑状态
  822. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  823. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  824. $verifyStaff=json_decode($value['verifyStaff'],true);
  825. Doo::loadModel('role');
  826. $role=new role();
  827. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  828. foreach ($verifyList as $k=>$v){
  829. //init verifyStaff
  830. if ($v[1]=='ROLE'){
  831. if (!empty($verifyStaff)){
  832. $endStaffArray=end($verifyStaff);
  833. // if ($v[0]==$endStaffArray['nextStaff']){
  834. // $roleId=$v[0];
  835. // }
  836. }
  837. $roleVerify=json_decode($v[3],true);
  838. $roleKey=$k;$roleArray=array();
  839. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  840. foreach ($roleVerify as $o=>$p){
  841. $staffID=explode ('_',$p);
  842. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  843. //print_r($staffID);
  844. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  845. array_push($roleArray, $exp);
  846. }
  847. $roleArrayCopy[$v[0]]=$roleArray;
  848. //$verifyList[$k]['roleArray']=$roleArray;
  849. }
  850. $verifyList[$k]['date']="";
  851. $verifyList[$k]['opinion']="";
  852. $verifyList[$k]['status']="";
  853. if (empty($verifyStaff)){
  854. $verifyList[$k]['date']="";
  855. $verifyList[$k]['opinion']="";
  856. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  857. $verifyList[$k]['status']=4;
  858. $flag=false;
  859. }
  860. }else{
  861. foreach ($verifyStaff as $m=>$u){
  862. if ($v[0]==$m){
  863. $verifyList[$k]['date']=$u['date'];
  864. $verifyList[$k]['opinion']=$u['opinion'];
  865. $verifyList[$k]['status']=$u['status'];
  866. $flag=false;
  867. break;
  868. }
  869. }
  870. $endStaffArray=end($verifyStaff);
  871. if (isset($endStaffArray['ROLE'])){
  872. }else{
  873. // $endKey=key($verifyStaff);
  874. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  875. // $button=4;
  876. // $verifyList[$k]['status']=4;
  877. // }
  878. }
  879. }
  880. }
  881. $rolename['name']='';
  882. if (!empty($roleId)){
  883. Doo::loadModel('role');
  884. $role=new role();
  885. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  886. }
  887. if (!empty($verifyStaff))
  888. $endStaffArray=end($verifyStaff);
  889. $KOP=false;
  890. foreach ($roleArrayCopy as $P=>$A){
  891. foreach ( $A as $MKI=>$AVL){
  892. if (!empty($verifyStaff)){
  893. //&&$rolename['rid']==$endStaffArray['nextStaff']
  894. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  895. $button=4;
  896. $roleArrayCopy[$P][$MKI]['status']=4;
  897. }
  898. foreach ($verifyStaff as $m=>$u){
  899. $AVLFK=$AVL[0].'_R';
  900. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  901. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  902. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  903. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  904. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  905. break;
  906. }
  907. }
  908. }else{
  909. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  910. $button=4;
  911. $roleArrayCopy[$P][$MKI]['status']=4;
  912. }
  913. }
  914. //$roleArray[$MKI]['rolename']=$rolename['name'];
  915. $KOP=true;
  916. }
  917. }
  918. foreach ($roleArrayCopy as $k=>$v){
  919. foreach ($verifyList as $m=>$n){
  920. if ($n[0]==$k){
  921. array_splice($verifyList,$m,1,$v);
  922. }
  923. }
  924. }
  925. $receiptList[$key]['verifyList']=$verifyList;
  926. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  927. $receiptList[$key]['button']=$button;
  928. //
  929. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  930. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  931. }
  932. $data['receiptList']=$receiptList;
  933. Doo::loadModel('L_category');
  934. $lCategory=new L_category();
  935. Doo::loadModel('accountItem');
  936. $accountItem=new accountItem();
  937. $acItem=$accountItem->find(array('asArray'=>true));
  938. $veList=$verify->find(array('asArray'=>true));
  939. foreach ($veList as $key=>$value){
  940. $v=json_decode($value['staff']);
  941. $list=array();
  942. foreach ($v as $n=>$m){
  943. if ($m['1']=='ROLE'){
  944. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  945. $v[$n][1]=$roleInfo['name'];
  946. array_push($list, $roleInfo['name']);
  947. }else{
  948. array_push($list, $v[$n][1]);
  949. }
  950. }
  951. $veList[$key]['staff']=implode('>', $list);
  952. }
  953. $data['rid']=$rid;
  954. $data['category']=$lCategory->find(array('asArray'=>true));
  955. $data['veList']=$veList;
  956. $data['acItem']=$acItem;
  957. $data['memu']="receipt";
  958. $data['staff']=$this->staff;
  959. $data['receiptMemu']='saeaBorad';
  960. $data['verifyId']=$this->verifyId;
  961. $data['executeId']=$this->executeId;
  962. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  963. }
  964. function saeaLoanReceiptAddDo(){
  965. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  966. $agency=$this->get_args('agency');
  967. $travel=$this->get_args('travel');
  968. $train=$this->get_args('train');
  969. $other=$this->get_args('other');
  970. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  971. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  972. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  973. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  974. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  975. Doo::loadModel('receipt');
  976. Doo::loadModel('receiptDetail');
  977. Doo::loadModel('accountItem');
  978. $accountItem=new accountItem();
  979. $receipt=new receipt();
  980. Doo::loadModel('enclosur');
  981. Doo::loadModel('execute');
  982. $execute=new execute();
  983. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  984. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  985. // if(!empty($receiptDetail))
  986. // return "/referReceipt/".$receiptDetail['rid'];
  987. $aItem=$accountItem->find(array('asArray'=>true));
  988. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  989. $ag=$tr=$ta=$ot=0;
  990. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  991. foreach ($aItem as $key=>$value){
  992. if ($value['category']==$this->AGENCY){
  993. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  994. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  995. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  996. }
  997. $ag++;
  998. }
  999. if($value['category']==$this->TRAVEL){
  1000. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1001. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1002. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1003. }
  1004. $tr++;
  1005. }
  1006. if($value['category']==$this->TRAIN){
  1007. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1008. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1009. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1010. }
  1011. $ta++;
  1012. }
  1013. if($value['category']==$this->OTHER){
  1014. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1015. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1016. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1017. }
  1018. $ot++;
  1019. }
  1020. }
  1021. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1022. //报销单
  1023. $receipt->accountItem=json_encode($accountJson);
  1024. $receipt->staff=$this->staff[0]['sid'];
  1025. $receipt->loanSum=$receiptDet['sum'];
  1026. $receipt->sum=number_format($sum, 2, '.', '');
  1027. $receipt->date=date("Y-m-d");
  1028. $receipt->pastDate='';
  1029. $receipt->cid=$cid;
  1030. $receipt->status=7;
  1031. //修改审批流程加入角色
  1032. $receipt->verify=$verify;
  1033. $receipt->verifyStaff='';
  1034. $receipt->executeStaff='';
  1035. $receipt->executeCopy=$executeDetail['staff'];
  1036. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1037. $receipt->explanation=$explanation;
  1038. $receipt->update(array('where'=>'rid='.$rid));
  1039. //附件
  1040. if (!empty($enclosurName)){
  1041. $enclosurArray=explode('-', $enclosurName);
  1042. foreach ($enclosurArray as $value){
  1043. $enclosur=new enclosur();
  1044. $enclosur->name=$value;
  1045. $enclosur->rid=$rid;
  1046. $enclosur->insert();
  1047. }
  1048. //print_r($enclosurArray);die;
  1049. }
  1050. //报销详情
  1051. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1052. $receiptDetail=new receiptDetail();
  1053. $receiptDetail->staff=$this->staff[0]['sid'];
  1054. $receiptDetail->item=$value['name'];
  1055. $receiptDetail->itemCategory=$this->AGENCY;
  1056. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1057. $receiptDetail->date=date("Y-m-d");
  1058. $receiptDetail->cid=$cid;
  1059. $receiptDetail->rid=$rid;
  1060. $receiptDetail->status=4;
  1061. $receiptDetail->insert();
  1062. }
  1063. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1064. $receiptDetail=new receiptDetail();
  1065. $receiptDetail->staff=$this->staff[0]['sid'];
  1066. $receiptDetail->item=$value['name'];
  1067. $receiptDetail->itemCategory=$this->TRAVEL;
  1068. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1069. $receiptDetail->date=date("Y-m-d");
  1070. $receiptDetail->cid=$cid;
  1071. $receiptDetail->rid=$rid;
  1072. $receiptDetail->status=4;
  1073. $receiptDetail->insert();
  1074. }
  1075. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1076. $receiptDetail=new receiptDetail();
  1077. $receiptDetail->staff=$this->staff[0]['sid'];
  1078. $receiptDetail->item=$value['name'];
  1079. $receiptDetail->itemCategory=$this->TRAIN;
  1080. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1081. $receiptDetail->date=date("Y-m-d");
  1082. $receiptDetail->cid=$cid;
  1083. $receiptDetail->rid=$rid;
  1084. $receiptDetail->status=4;
  1085. $receiptDetail->insert();
  1086. }
  1087. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1088. $receiptDetail=new receiptDetail();
  1089. $receiptDetail->staff=$this->staff[0]['sid'];
  1090. $receiptDetail->item=$value['name'];
  1091. $receiptDetail->itemCategory=$this->OTHER;
  1092. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1093. $receiptDetail->date=date("Y-m-d");
  1094. $receiptDetail->cid=$cid;
  1095. $receiptDetail->rid=$rid;
  1096. $receiptDetail->status=4;
  1097. $receiptDetail->insert();
  1098. }
  1099. return "/saeaBorad";
  1100. }
  1101. return "/saeaLoanReceiptAdd/".$rid;
  1102. }
  1103. function saeaLoanReceiptEdi(){
  1104. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1105. //echo $rid;
  1106. Doo::loadModel('accountItem');
  1107. Doo::loadModel('verify');
  1108. Doo::loadModel('receipt');
  1109. $receipt=new receipt();
  1110. $verify=new verify();
  1111. $accountItem=new accountItem();
  1112. Doo::loadModel('L_category');
  1113. $Lcategory=new L_category();
  1114. Doo::loadModel("role");
  1115. $role=new role();
  1116. Doo::loadModel('loanReceipt');
  1117. $loanReceipt=new loanReceipt();
  1118. Doo::loadModel('staff');
  1119. $staff=new staff();
  1120. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1121. if(empty($receiptDetail))
  1122. return "/saeaBorad";
  1123. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1124. $Locate=0;$roleId=0;$button=0;
  1125. foreach ($receiptList as $key=>$value){
  1126. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1127. $receiptList[$key]['reviseDetail']=array();
  1128. if (!empty($value['reviseDetail']))
  1129. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1130. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1131. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1132. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1133. $receiptList[$key]['category']=$categoryDetil['title'];
  1134. //检测编辑状态
  1135. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1136. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1137. $verifyStaff=json_decode($value['verifyStaff'],true);
  1138. Doo::loadModel('role');
  1139. $role=new role();
  1140. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1141. foreach ($verifyList as $k=>$v){
  1142. //init verifyStaff
  1143. if ($v[1]=='ROLE'){
  1144. if (!empty($verifyStaff)){
  1145. $endStaffArray=end($verifyStaff);
  1146. // if ($v[0]==$endStaffArray['nextStaff']){
  1147. // $roleId=$v[0];
  1148. // }
  1149. }
  1150. $roleVerify=json_decode($v[3],true);
  1151. $roleKey=$k;$roleArray=array();
  1152. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1153. foreach ($roleVerify as $o=>$p){
  1154. $staffID=explode ('_',$p);
  1155. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1156. //print_r($staffID);
  1157. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1158. array_push($roleArray, $exp);
  1159. }
  1160. $roleArrayCopy[$v[0]]=$roleArray;
  1161. //$verifyList[$k]['roleArray']=$roleArray;
  1162. }
  1163. $verifyList[$k]['date']="";
  1164. $verifyList[$k]['opinion']="";
  1165. $verifyList[$k]['status']="";
  1166. if (empty($verifyStaff)){
  1167. $verifyList[$k]['date']="";
  1168. $verifyList[$k]['opinion']="";
  1169. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1170. $verifyList[$k]['status']=4;
  1171. $flag=false;
  1172. }
  1173. }else{
  1174. foreach ($verifyStaff as $m=>$u){
  1175. if ($v[0]==$m){
  1176. $verifyList[$k]['date']=$u['date'];
  1177. $verifyList[$k]['opinion']=$u['opinion'];
  1178. $verifyList[$k]['status']=$u['status'];
  1179. $flag=false;
  1180. break;
  1181. }
  1182. }
  1183. $endStaffArray=end($verifyStaff);
  1184. if (isset($endStaffArray['ROLE'])){
  1185. }else{
  1186. // $endKey=key($verifyStaff);
  1187. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1188. // $button=4;
  1189. // $verifyList[$k]['status']=4;
  1190. // }
  1191. }
  1192. }
  1193. }
  1194. $rolename['name']='';
  1195. if (!empty($roleId)){
  1196. Doo::loadModel('role');
  1197. $role=new role();
  1198. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1199. }
  1200. if (!empty($verifyStaff))
  1201. $endStaffArray=end($verifyStaff);
  1202. $KOP=false;
  1203. foreach ($roleArrayCopy as $P=>$A){
  1204. foreach ( $A as $MKI=>$AVL){
  1205. if (!empty($verifyStaff)){
  1206. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1207. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1208. $button=4;
  1209. $roleArrayCopy[$P][$MKI]['status']=4;
  1210. }
  1211. foreach ($verifyStaff as $m=>$u){
  1212. $AVLFK=$AVL[0].'_R';
  1213. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1214. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1215. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1216. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1217. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1218. break;
  1219. }
  1220. }
  1221. }else{
  1222. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1223. $button=4;
  1224. $roleArrayCopy[$P][$MKI]['status']=4;
  1225. }
  1226. }
  1227. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1228. $KOP=true;
  1229. }
  1230. }
  1231. foreach ($roleArrayCopy as $k=>$v){
  1232. foreach ($verifyList as $m=>$n){
  1233. if ($n[0]==$k){
  1234. array_splice($verifyList,$m,1,$v);
  1235. }
  1236. }
  1237. }
  1238. $receiptList[$key]['verifyList']=$verifyList;
  1239. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1240. $receiptList[$key]['button']=$button;
  1241. //
  1242. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1243. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1244. }
  1245. $data['receiptList']=$receiptList;
  1246. $acItem=$accountItem->find(array('asArray'=>true));
  1247. $veList=$verify->find(array('asArray'=>true));
  1248. foreach ($veList as $key=>$value){
  1249. $v=json_decode($value['staff']);
  1250. $list=array();
  1251. foreach ($v as $n=>$m){
  1252. if ($m['1']=='ROLE'){
  1253. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1254. $v[$n][1]=$roleInfo['name'];
  1255. array_push($list, $roleInfo['name']);
  1256. }else{
  1257. array_push($list, $v[$n][1]);
  1258. }
  1259. }
  1260. $veList[$key]['staff']=implode('>', $list);
  1261. }
  1262. //配置编辑信息
  1263. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1264. foreach ($acItem as $key=>$value){
  1265. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1266. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1267. $acItem[$key]['price']=$v['price'];
  1268. }
  1269. }
  1270. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1271. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1272. $acItem[$key]['price']=$v['price'];
  1273. }
  1274. }
  1275. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1276. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1277. $acItem[$key]['price']=$v['price'];
  1278. }
  1279. }
  1280. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1281. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1282. $acItem[$key]['price']=$v['price'];
  1283. }
  1284. }
  1285. }
  1286. $data['category']=$Lcategory->find(array('asArray'=>true));
  1287. $data['cSum']=$accountItemList['cSum'];
  1288. $data['sum']=$receiptDetail['sum'];
  1289. $data['receiptDetail']=$receiptDetail;
  1290. $data['veList']=$veList;
  1291. $data['acItem']=$acItem;
  1292. $data['memu']="receipt";
  1293. $data['staff']=$this->staff;
  1294. $data['receiptMemu']='saeaBorad';
  1295. $data['verify']=$receiptDetail['verify'];
  1296. $data['verifyId']=$this->verifyId;
  1297. $data['executeId']=$this->executeId;
  1298. $data['rid']=$rid;
  1299. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1300. }
  1301. function confirmation(){
  1302. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1303. Doo::loadModel('receipt');
  1304. Doo::loadModel('receiptDetail');
  1305. $receipt=new receipt();
  1306. $receiptDetail=new receiptDetail();
  1307. Doo::loadModel('statistics');
  1308. Doo::loadModel('itemStatistics');
  1309. $statistics=new statistics();
  1310. $itemStatistics=new itemStatistics();
  1311. Doo::loadModel("verify");
  1312. $verify=new verify();
  1313. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1314. if(empty($receiptDetailList))
  1315. return "/saeaBorad";
  1316. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1317. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1318. if (empty($receiptDetailList['nowStaff'])){
  1319. $nowStaff="";$nowStaffList=array();
  1320. if ($verifyDetail[0][1]=='ROLE'){
  1321. $vStaffString=json_decode($verifyDetail[0][3]);
  1322. foreach ($vStaffString as $key=>$value){
  1323. $staffK=explode("_", $value);
  1324. array_push($nowStaffList, $staffK[0]);
  1325. }
  1326. $nowStaff=implode(',', $nowStaffList);
  1327. }else{
  1328. $nowStaff=$verifyDetail[0][0];
  1329. }
  1330. $receipt->nowStaff=$nowStaff;
  1331. }
  1332. // echo $nowStaff;
  1333. // print_r($verifyDetail);die;
  1334. $receipt->rid=$receiptDetailList['rid'];
  1335. $receipt->status=2;
  1336. $receipt->update();
  1337. //操作日志
  1338. Doo::loadModel("receiptLog");
  1339. $receiptLog=new receiptLog();
  1340. $verify=new verify();
  1341. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1342. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1343. $jd=json_decode($vr['staff']);$roleId=0;
  1344. foreach ($jd as $key=>$value){
  1345. if ($value[1]=='ROLE'){
  1346. $pos = strpos($value[3], $this->staff[0]['sid']);
  1347. if ($pos !== false) {
  1348. $roleId=$value[0];
  1349. }
  1350. }
  1351. }
  1352. //审批日志
  1353. //echo $roleId;die;
  1354. if (!empty($roleId)){
  1355. Doo::loadModel("role");
  1356. $role=new role();
  1357. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1358. $receiptLog->rolename=$roleInfo['name'];
  1359. }
  1360. $receiptLog->username=$this->staff[0]['username'];
  1361. $receiptLog->uid=$this->staff[0]['sid'];
  1362. $receiptLog->date=date("Y-m-d");
  1363. $receiptLog->opinion='提交审批';
  1364. $receiptLog->img=$this->staff[0]['avatar'];
  1365. $receiptLog->status=2;
  1366. $receiptLog->rid=$rid;
  1367. $receiptLog->insert();
  1368. return "/expenses";
  1369. }
  1370. function expenses(){
  1371. $item=isset($this->params['item'])?$this->params['item']:"";
  1372. if(empty($item))
  1373. $item=$this->get_args('item')?$this->get_args('item'):"";
  1374. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1375. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1376. Doo::loadModel('receipt');
  1377. $receipt=new receipt();
  1378. Doo::loadModel('L_category');
  1379. $Lcategory=new L_category();
  1380. Doo::loadModel('verify');
  1381. Doo::loadModel('statistics');
  1382. $statistics=new statistics();
  1383. $verify=new verify();
  1384. Doo::loadModel('staff');
  1385. $staff=new staff();
  1386. $condition="";
  1387. if($item=="expenses")
  1388. $condition=" and Rtype=1 ";
  1389. elseif ($item=="receipts")
  1390. $condition=" and Rtype=0 ";
  1391. elseif ($item=="remits")
  1392. $condition=" and Rtype=2 ";
  1393. $dateCondition=" and Year(date) =".$year;
  1394. if(!empty($moth)){
  1395. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1396. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1397. }else
  1398. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1399. if(empty($stList))
  1400. $stList=array('rePrice'=>0,'agPrice'=>0);
  1401. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  1402. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  1403. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1404. $Locate=0;$roleId=0;$button=0;
  1405. foreach ($receiptList as $key=>$value){
  1406. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1407. $receiptList[$key]['reviseDetail']=array();
  1408. if (!empty($value['reviseDetail']))
  1409. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1410. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1411. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1412. $receiptList[$key]['category']=$categoryDetil['title'];
  1413. //检测编辑状态
  1414. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1415. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1416. $verifyStaff=json_decode($value['verifyStaff'],true);
  1417. Doo::loadModel('role');
  1418. $role=new role();
  1419. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1420. foreach ($verifyList as $k=>$v){
  1421. //init verifyStaff
  1422. if ($v[1]=='ROLE'){
  1423. if (!empty($verifyStaff)){
  1424. $endStaffArray=end($verifyStaff);
  1425. // if ($v[0]==$endStaffArray['nextStaff']){
  1426. // $roleId=$v[0];
  1427. // }
  1428. }
  1429. $roleVerify=json_decode($v[3],true);
  1430. $roleKey=$k;$roleArray=array();
  1431. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1432. foreach ($roleVerify as $o=>$p){
  1433. $staffID=explode ('_',$p);
  1434. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1435. //print_r($staffID);
  1436. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1437. array_push($roleArray, $exp);
  1438. }
  1439. $roleArrayCopy[$v[0]]=$roleArray;
  1440. //$verifyList[$k]['roleArray']=$roleArray;
  1441. }
  1442. $verifyList[$k]['date']="";
  1443. $verifyList[$k]['opinion']="";
  1444. $verifyList[$k]['status']="";
  1445. if (empty($verifyStaff)){
  1446. $verifyList[$k]['date']="";
  1447. $verifyList[$k]['opinion']="";
  1448. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1449. $verifyList[$k]['status']=4;
  1450. $flag=false;
  1451. }
  1452. }else{
  1453. foreach ($verifyStaff as $m=>$u){
  1454. if ($v[0]==$m){
  1455. $verifyList[$k]['date']=$u['date'];
  1456. $verifyList[$k]['opinion']=$u['opinion'];
  1457. $verifyList[$k]['status']=$u['status'];
  1458. $flag=false;
  1459. break;
  1460. }
  1461. }
  1462. $endStaffArray=end($verifyStaff);
  1463. if (isset($endStaffArray['ROLE'])){
  1464. }else{
  1465. // $endKey=key($verifyStaff);
  1466. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1467. // $button=4;
  1468. // $verifyList[$k]['status']=4;
  1469. // }
  1470. }
  1471. }
  1472. }
  1473. $rolename['name']='';
  1474. if (!empty($roleId)){
  1475. Doo::loadModel('role');
  1476. $role=new role();
  1477. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1478. }
  1479. if (!empty($verifyStaff))
  1480. $endStaffArray=end($verifyStaff);
  1481. $KOP=false;
  1482. foreach ($roleArrayCopy as $P=>$A){
  1483. foreach ( $A as $MKI=>$AVL){
  1484. if (!empty($verifyStaff)){
  1485. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1486. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1487. $button=4;
  1488. $roleArrayCopy[$P][$MKI]['status']=4;
  1489. }
  1490. foreach ($verifyStaff as $m=>$u){
  1491. $AVLFK=$AVL[0].'_R';
  1492. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1493. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1494. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1495. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1496. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1497. break;
  1498. }
  1499. }
  1500. }else{
  1501. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1502. $button=4;
  1503. $roleArrayCopy[$P][$MKI]['status']=4;
  1504. }
  1505. }
  1506. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1507. $KOP=true;
  1508. }
  1509. }
  1510. foreach ($roleArrayCopy as $k=>$v){
  1511. foreach ($verifyList as $m=>$n){
  1512. if ($n[0]==$k){
  1513. array_splice($verifyList,$m,1,$v);
  1514. }
  1515. }
  1516. }
  1517. $receiptList[$key]['verifyList']=$verifyList;
  1518. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1519. $receiptList[$key]['button']=$button;
  1520. }
  1521. //print_r($receiptList);die;
  1522. $mothHtml="";
  1523. for($i=1;$i<=12;$i++){
  1524. if($moth==$i)
  1525. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1526. else
  1527. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1528. }
  1529. $data['mothHtml']=$mothHtml;
  1530. $data['receiptList']=$receiptList;
  1531. $data['memu']="receipt";
  1532. $data['staff']=$this->staff;
  1533. $data['receiptMemu']='expenses';
  1534. $data['verifyId']=$this->verifyId;
  1535. $data['executeId']=$this->executeId;
  1536. $data['item']=$item;
  1537. $data['year']=$year;
  1538. $this->render ( "/admin/expenses", $data );
  1539. }
  1540. function expensesCollect(){
  1541. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1542. Doo::loadModel('receipt');
  1543. $receipt=new receipt();
  1544. Doo::loadModel('L_category');
  1545. $Lcategory=new L_category();
  1546. Doo::loadModel('verify');
  1547. Doo::loadModel('statistics');
  1548. $statistics=new statistics();
  1549. $verify=new verify();
  1550. Doo::loadModel('staff');
  1551. $staff=new staff();
  1552. Doo::loadModel('loanReceipt');
  1553. $loanReceipt=new loanReceipt();
  1554. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1555. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1556. $Locate=0;$roleId=0;$button=0;
  1557. foreach ($loanList as $key=>$value){
  1558. $loanList[$key]['Locate']=$Locate;$Locate++;
  1559. $loanList[$key]['reviseDetail']=array();
  1560. if (!empty($value['reviseDetail']))
  1561. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1562. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1563. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1564. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1565. $loanList[$key]['category']=$categoryDetil['title'];
  1566. //检测编辑状态
  1567. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1568. $verifyList['staff']=$value['verifyBreakup'];
  1569. else
  1570. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1571. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1572. $verifyStaff=json_decode($value['verifyStaff'],true);
  1573. Doo::loadModel('role');
  1574. $role=new role();
  1575. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1576. foreach ($verifyList as $k=>$v){
  1577. //init verifyStaff
  1578. if ($v[1]=='ROLE'){
  1579. if (!empty($verifyStaff)){
  1580. $endStaffArray=end($verifyStaff);
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify=json_decode($v[3],true);
  1586. $roleKey=$k;$roleArray=array();
  1587. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1588. foreach ($roleVerify as $o=>$p){
  1589. $staffID=explode ('_',$p);
  1590. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1591. //print_r($staffID);
  1592. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1593. array_push($roleArray, $exp);
  1594. }
  1595. $roleArrayCopy[$v[0]]=$roleArray;
  1596. //$verifyList[$k]['roleArray']=$roleArray;
  1597. }
  1598. $verifyList[$k]['date']="";
  1599. $verifyList[$k]['opinion']="";
  1600. $verifyList[$k]['status']="";
  1601. if (empty($verifyStaff)){
  1602. $verifyList[$k]['date']="";
  1603. $verifyList[$k]['opinion']="";
  1604. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1605. $verifyList[$k]['status']=4;
  1606. $flag=false;
  1607. }
  1608. }else{
  1609. foreach ($verifyStaff as $m=>$u){
  1610. if ($v[0]==$m){
  1611. $verifyList[$k]['date']=$u['date'];
  1612. $verifyList[$k]['opinion']=$u['opinion'];
  1613. $verifyList[$k]['status']=$u['status'];
  1614. $flag=false;
  1615. break;
  1616. }
  1617. }
  1618. $endStaffArray=end($verifyStaff);
  1619. if (isset($endStaffArray['ROLE'])){
  1620. }else{
  1621. // $endKey=key($verifyStaff);
  1622. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1623. // $button=4;
  1624. // $verifyList[$k]['status']=4;
  1625. // }
  1626. }
  1627. }
  1628. }
  1629. $rolename['name']='';
  1630. if (!empty($roleId)){
  1631. Doo::loadModel('role');
  1632. $role=new role();
  1633. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1634. }
  1635. if (!empty($verifyStaff))
  1636. $endStaffArray=end($verifyStaff);
  1637. $KOP=false;
  1638. foreach ($roleArrayCopy as $P=>$A){
  1639. foreach ( $A as $MKI=>$AVL){
  1640. if (!empty($verifyStaff)){
  1641. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1642. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1643. $button=4;
  1644. $roleArrayCopy[$P][$MKI]['status']=4;
  1645. }
  1646. foreach ($verifyStaff as $m=>$u){
  1647. $AVLFK=$AVL[0].'_R';
  1648. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1649. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1650. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1651. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1652. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1653. break;
  1654. }
  1655. }
  1656. }else{
  1657. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1658. $button=4;
  1659. $roleArrayCopy[$P][$MKI]['status']=4;
  1660. }
  1661. }
  1662. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1663. $KOP=true;
  1664. }
  1665. }
  1666. foreach ($roleArrayCopy as $k=>$v){
  1667. foreach ($verifyList as $m=>$n){
  1668. if ($n[0]==$k){
  1669. array_splice($verifyList,$m,1,$v);
  1670. }
  1671. }
  1672. }
  1673. $loanList[$key]['verifyList']=$verifyList;
  1674. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1675. $loanList[$key]['button']=$button;
  1676. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1677. }
  1678. $data['loanList']=$loanList;
  1679. $Locate=0;$roleId=0;$button=0;
  1680. foreach ($receiptList as $key=>$value){
  1681. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1682. $receiptList[$key]['reviseDetail']=array();
  1683. if (!empty($value['reviseDetail']))
  1684. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1685. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1686. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1687. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1688. $receiptList[$key]['category']=$categoryDetil['title'];
  1689. //检测编辑状态
  1690. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1691. if($value['status']==8&&$value['Rtype']==1)
  1692. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1693. else
  1694. $verifyList['staff']=$value['verifyBreakup'];
  1695. }else
  1696. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1697. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1698. $verifyStaff=json_decode($value['verifyStaff'],true);
  1699. Doo::loadModel('role');
  1700. $role=new role();
  1701. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1702. foreach ($verifyList as $k=>$v){
  1703. //init verifyStaff
  1704. if ($v[1]=='ROLE'){
  1705. if (!empty($verifyStaff)){
  1706. $endStaffArray=end($verifyStaff);
  1707. // if ($v[0]==$endStaffArray['nextStaff']){
  1708. // $roleId=$v[0];
  1709. // }
  1710. }
  1711. $roleVerify=json_decode($v[3],true);
  1712. $roleKey=$k;$roleArray=array();
  1713. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1714. foreach ($roleVerify as $o=>$p){
  1715. $staffID=explode ('_',$p);
  1716. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1717. //print_r($staffID);
  1718. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1719. array_push($roleArray, $exp);
  1720. }
  1721. $roleArrayCopy[$v[0]]=$roleArray;
  1722. //$verifyList[$k]['roleArray']=$roleArray;
  1723. }
  1724. $verifyList[$k]['date']="";
  1725. $verifyList[$k]['opinion']="";
  1726. $verifyList[$k]['status']="";
  1727. if (empty($verifyStaff)){
  1728. $verifyList[$k]['date']="";
  1729. $verifyList[$k]['opinion']="";
  1730. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1731. $verifyList[$k]['status']=4;
  1732. $flag=false;
  1733. }
  1734. }else{
  1735. foreach ($verifyStaff as $m=>$u){
  1736. if ($v[0]==$m){
  1737. $verifyList[$k]['date']=$u['date'];
  1738. $verifyList[$k]['opinion']=$u['opinion'];
  1739. $verifyList[$k]['status']=$u['status'];
  1740. $flag=false;
  1741. break;
  1742. }
  1743. }
  1744. $endStaffArray=end($verifyStaff);
  1745. if (isset($endStaffArray['ROLE'])){
  1746. }else{
  1747. // $endKey=key($verifyStaff);
  1748. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1749. // $button=4;
  1750. // $verifyList[$k]['status']=4;
  1751. // }
  1752. }
  1753. }
  1754. }
  1755. $rolename['name']='';
  1756. if (!empty($roleId)){
  1757. Doo::loadModel('role');
  1758. $role=new role();
  1759. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1760. }
  1761. if (!empty($verifyStaff))
  1762. $endStaffArray=end($verifyStaff);
  1763. $KOP=false;
  1764. foreach ($roleArrayCopy as $P=>$A){
  1765. foreach ( $A as $MKI=>$AVL){
  1766. if (!empty($verifyStaff)){
  1767. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1768. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1769. $button=4;
  1770. $roleArrayCopy[$P][$MKI]['status']=4;
  1771. }
  1772. foreach ($verifyStaff as $m=>$u){
  1773. $AVLFK=$AVL[0].'_R';
  1774. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1775. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1776. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1777. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1778. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1779. break;
  1780. }
  1781. }
  1782. }else{
  1783. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1784. $button=4;
  1785. $roleArrayCopy[$P][$MKI]['status']=4;
  1786. }
  1787. }
  1788. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1789. $KOP=true;
  1790. }
  1791. }
  1792. foreach ($roleArrayCopy as $k=>$v){
  1793. foreach ($verifyList as $m=>$n){
  1794. if ($n[0]==$k){
  1795. array_splice($verifyList,$m,1,$v);
  1796. }
  1797. }
  1798. }
  1799. $receiptList[$key]['verifyList']=$verifyList;
  1800. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1801. $receiptList[$key]['button']=$button;
  1802. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1803. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1804. $relust=$value['sum']-$value['loanSum'];
  1805. $receiptList[$key]['relust']=$relust;
  1806. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1807. }
  1808. $data['receiptList']=$receiptList;
  1809. $data['memu']="receipt";
  1810. $data['staff']=$this->staff;
  1811. $data['receiptMemu']='expenses';
  1812. $data['verifyId']=$this->verifyId;
  1813. $data['executeId']=$this->executeId;
  1814. $this->render ( "/admin/expensesCollect", $data );
  1815. }
  1816. function approvalExpenses(){
  1817. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1818. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1819. $month=$this->get_args('month')?$this->get_args('month'):"";
  1820. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1821. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1822. if (empty($status))
  1823. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1824. $page_size=12;
  1825. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1826. $vidList=array();
  1827. $button=0;
  1828. Doo::loadModel('verify');
  1829. $verify=new verify();
  1830. Doo::loadModel('receipt');
  1831. $receipt=new receipt();
  1832. Doo::loadModel('staff');
  1833. $staff=new staff();
  1834. Doo::loadModel('L_category');
  1835. $Lcategory=new L_category();
  1836. //user verify ID
  1837. $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));
  1838. foreach ($verifyDetail as $key=>$value){
  1839. array_push($vidList, $value['vid']);
  1840. }
  1841. $vid=implode(",", $vidList);
  1842. if(empty($verifyDetail))
  1843. $vid=0;
  1844. // if ($status==0)
  1845. // $dateCondition="";
  1846. // else
  1847. $dateCondition=" and Year(date) =".$year;
  1848. if(!empty($month))
  1849. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1850. $categoryList=$Lcategory->find(array('asArray'=>true));
  1851. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1852. $cateCondition="";$staffCondition="";$approvalCondition="";
  1853. if (!empty($cid))
  1854. $cateCondition=' and cid='.$cid;
  1855. if(!empty($sid)){
  1856. $staffCondition=' and staff='.$sid;
  1857. $cateCondition="";
  1858. }
  1859. $approvalCondition=" and status=".$status;
  1860. if($status==2){
  1861. //查找角色审批人
  1862. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1863. }
  1864. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1865. $approvalCondition=' and status=2 ';
  1866. }
  1867. if($status==1){
  1868. $approvalCondition=' and (status='.$status.' or status=6) ';
  1869. }
  1870. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1871. $pageinfo['page']=array('previous'=>'');
  1872. if ($status==0){
  1873. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1874. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1875. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1876. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1877. }else
  1878. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1879. ,'desc'=>'rid','asArray'=>true));
  1880. $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
  1881. ,'desc'=>'rid','asArray'=>true));
  1882. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1883. //print_r($pageinfo);
  1884. $Locate=0;
  1885. foreach ($receiptList as $key=>$value){
  1886. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1887. $receiptList[$key]['reviseDetail']=array();
  1888. if (!empty($value['reviseDetail']))
  1889. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1890. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1891. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1892. $receiptList[$key]['category']=$categoryDetil['title'];
  1893. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1894. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1895. $verifyStaff=json_decode($value['verifyStaff'],true);
  1896. foreach ($verifyList as $k=>$v){
  1897. //init verifyStaff
  1898. $verifyList[$k]['date']="";
  1899. $verifyList[$k]['opinion']="";
  1900. $verifyList[$k]['status']="";
  1901. if (empty($verifyStaff)){
  1902. $verifyList[$k]['date']="";
  1903. $verifyList[$k]['opinion']="";
  1904. if ($v[0]==$this->staff[0]['sid']){
  1905. $verifyList[$k]['status']=4;
  1906. $button=4;
  1907. }
  1908. }else{
  1909. $flag=true;
  1910. foreach ($verifyStaff as $m=>$u){
  1911. if ($v[0]==$m){
  1912. $verifyList[$k]['date']=$u['date'];
  1913. $verifyList[$k]['opinion']=$u['opinion'];
  1914. $verifyList[$k]['status']=$u['status'];
  1915. $flag=false;
  1916. break;
  1917. }
  1918. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1919. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1920. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1921. }
  1922. if($flag){//检测可编辑
  1923. if($v[0]==$this->staff[0]['sid']){
  1924. $verifyList[$k]['status']=4;$button=4;
  1925. }
  1926. }
  1927. }
  1928. }
  1929. $receiptList[$key]['verifyList']=$verifyList;
  1930. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1931. $receiptList[$key]['button']=$button;
  1932. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1933. }
  1934. //print_r($receiptList);die;
  1935. //$data['verifyDetail']=$verifyDetail;
  1936. $mothHtml="";
  1937. for($i=1;$i<=12;$i++){
  1938. if($month==$i)
  1939. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1940. else
  1941. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1942. }
  1943. $data['mothHtml']=$mothHtml;
  1944. $data['page']=$pageinfo;
  1945. $data['receiptList']=$receiptList;
  1946. $data['receiptApprovalCount']=count($rLRes);
  1947. $data['status']=$status;
  1948. $data['year']=$year;
  1949. $data['categoryList']=$categoryList;
  1950. $data['staffList']=$staffList;
  1951. $data['cid']=$cid;
  1952. $data['sid']=$sid;
  1953. //print_r($receiptList);
  1954. $data['memu']="receipt";
  1955. $data['staff']=$this->staff;
  1956. $data['receiptMemu']='approvalExpenses';
  1957. $data['verifyId']=$this->verifyId;
  1958. $data['executeId']=$this->executeId;
  1959. $this->render ( "/admin/approvalExpenses", $data );
  1960. }
  1961. function expensesDoc(){
  1962. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1963. Doo::loadModel('receipt');
  1964. $receipt=new receipt();
  1965. Doo::loadModel('L_category');
  1966. $Lcategory=new L_category();
  1967. Doo::loadModel('verify');
  1968. Doo::loadModel('statistics');
  1969. $statistics=new statistics();
  1970. $verify=new verify();
  1971. Doo::loadModel('staff');
  1972. $staff=new staff();
  1973. Doo::loadModel('loanReceipt');
  1974. $loanReceipt=new loanReceipt();
  1975. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1976. $loanList=array();
  1977. if (!empty($receiptList))
  1978. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1979. $Locate=0;$roleId=0;$button=0;
  1980. foreach ($loanList as $key=>$value){
  1981. $loanList[$key]['Locate']=$Locate;$Locate++;
  1982. $loanList[$key]['reviseDetail']=array();
  1983. if (!empty($value['reviseDetail']))
  1984. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1985. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1986. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1987. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1988. $loanList[$key]['category']=$categoryDetil['title'];
  1989. //检测编辑状态
  1990. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1991. $verifyList['staff']=$value['verifyBreakup'];
  1992. else
  1993. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1994. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1995. $verifyStaff=json_decode($value['verifyStaff'],true);
  1996. Doo::loadModel('role');
  1997. $role=new role();
  1998. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1999. foreach ($verifyList as $k=>$v){
  2000. //init verifyStaff
  2001. if ($v[1]=='ROLE'){
  2002. if (!empty($verifyStaff)){
  2003. $endStaffArray=end($verifyStaff);
  2004. // if ($v[0]==$endStaffArray['nextStaff']){
  2005. // $roleId=$v[0];
  2006. // }
  2007. }
  2008. $roleVerify=json_decode($v[3],true);
  2009. $roleKey=$k;$roleArray=array();
  2010. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2011. foreach ($roleVerify as $o=>$p){
  2012. $staffID=explode ('_',$p);
  2013. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2014. //print_r($staffID);
  2015. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2016. array_push($roleArray, $exp);
  2017. }
  2018. $roleArrayCopy[$v[0]]=$roleArray;
  2019. //$verifyList[$k]['roleArray']=$roleArray;
  2020. }
  2021. $verifyList[$k]['date']="";
  2022. $verifyList[$k]['opinion']="";
  2023. $verifyList[$k]['status']="";
  2024. if (empty($verifyStaff)){
  2025. $verifyList[$k]['date']="";
  2026. $verifyList[$k]['opinion']="";
  2027. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2028. $verifyList[$k]['status']=4;
  2029. $flag=false;
  2030. }
  2031. }else{
  2032. foreach ($verifyStaff as $m=>$u){
  2033. if ($v[0]==$m){
  2034. $verifyList[$k]['date']=$u['date'];
  2035. $verifyList[$k]['opinion']=$u['opinion'];
  2036. $verifyList[$k]['status']=$u['status'];
  2037. $flag=false;
  2038. break;
  2039. }
  2040. }
  2041. $endStaffArray=end($verifyStaff);
  2042. if (isset($endStaffArray['ROLE'])){
  2043. }else{
  2044. // $endKey=key($verifyStaff);
  2045. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2046. // $button=4;
  2047. // $verifyList[$k]['status']=4;
  2048. // }
  2049. }
  2050. }
  2051. }
  2052. $rolename['name']='';
  2053. if (!empty($roleId)){
  2054. Doo::loadModel('role');
  2055. $role=new role();
  2056. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2057. }
  2058. if (!empty($verifyStaff))
  2059. $endStaffArray=end($verifyStaff);
  2060. $KOP=false;
  2061. foreach ($roleArrayCopy as $P=>$A){
  2062. foreach ( $A as $MKI=>$AVL){
  2063. if (!empty($verifyStaff)){
  2064. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2065. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2066. $button=4;
  2067. $roleArrayCopy[$P][$MKI]['status']=4;
  2068. }
  2069. foreach ($verifyStaff as $m=>$u){
  2070. $AVLFK=$AVL[0].'_R';
  2071. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2072. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2073. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2074. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2075. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2076. break;
  2077. }
  2078. }
  2079. }else{
  2080. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2081. $button=4;
  2082. $roleArrayCopy[$P][$MKI]['status']=4;
  2083. }
  2084. }
  2085. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2086. $KOP=true;
  2087. }
  2088. }
  2089. foreach ($roleArrayCopy as $k=>$v){
  2090. foreach ($verifyList as $m=>$n){
  2091. if ($n[0]==$k){
  2092. array_splice($verifyList,$m,1,$v);
  2093. }
  2094. }
  2095. }
  2096. $loanList[$key]['verifyList']=$verifyList;
  2097. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2098. $loanList[$key]['button']=$button;
  2099. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2100. }
  2101. $data['loanList']=$loanList;
  2102. //print_r($loanList);
  2103. $Locate=0;$roleId=0;$button=0;
  2104. foreach ($receiptList as $key=>$value){
  2105. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2106. $receiptList[$key]['reviseDetail']=array();
  2107. if (!empty($value['reviseDetail']))
  2108. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2109. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2110. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2111. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2112. $receiptList[$key]['category']=$categoryDetil['title'];
  2113. //检测编辑状态
  2114. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2115. $verifyList['staff']=$value['verifyBreakup'];
  2116. }else
  2117. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2118. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2119. $verifyStaff=json_decode($value['verifyStaff'],true);
  2120. Doo::loadModel('role');
  2121. $role=new role();
  2122. if ($verifyList==NULL)
  2123. $verifyList=array();
  2124. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2125. foreach ($verifyList as $k=>$v){
  2126. //init verifyStaff
  2127. if ($v[1]=='ROLE'){
  2128. if (!empty($verifyStaff)){
  2129. $endStaffArray=end($verifyStaff);
  2130. // if ($v[0]==$endStaffArray['nextStaff']){
  2131. // $roleId=$v[0];
  2132. // }
  2133. }
  2134. $roleVerify=json_decode($v[3],true);
  2135. $roleKey=$k;$roleArray=array();
  2136. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2137. foreach ($roleVerify as $o=>$p){
  2138. $staffID=explode ('_',$p);
  2139. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2140. //print_r($staffID);
  2141. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2142. array_push($roleArray, $exp);
  2143. }
  2144. $roleArrayCopy[$v[0]]=$roleArray;
  2145. //$verifyList[$k]['roleArray']=$roleArray;
  2146. }
  2147. $verifyList[$k]['date']="";
  2148. $verifyList[$k]['opinion']="";
  2149. $verifyList[$k]['status']="";
  2150. if (empty($verifyStaff)){
  2151. $verifyList[$k]['date']="";
  2152. $verifyList[$k]['opinion']="";
  2153. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2154. $verifyList[$k]['status']=4;
  2155. $flag=false;
  2156. }
  2157. }else{
  2158. foreach ($verifyStaff as $m=>$u){
  2159. if ($v[0]==$m){
  2160. $verifyList[$k]['date']=$u['date'];
  2161. $verifyList[$k]['opinion']=$u['opinion'];
  2162. $verifyList[$k]['status']=$u['status'];
  2163. $flag=false;
  2164. break;
  2165. }
  2166. }
  2167. $endStaffArray=end($verifyStaff);
  2168. if (isset($endStaffArray['ROLE'])){
  2169. }else{
  2170. // $endKey=key($verifyStaff);
  2171. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2172. // $button=4;
  2173. // $verifyList[$k]['status']=4;
  2174. // }
  2175. }
  2176. }
  2177. }
  2178. $rolename['name']='';
  2179. if (!empty($roleId)){
  2180. Doo::loadModel('role');
  2181. $role=new role();
  2182. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2183. }
  2184. if (!empty($verifyStaff))
  2185. $endStaffArray=end($verifyStaff);
  2186. $KOP=false;
  2187. foreach ($roleArrayCopy as $P=>$A){
  2188. foreach ( $A as $MKI=>$AVL){
  2189. if (!empty($verifyStaff)){
  2190. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2191. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2192. $button=4;
  2193. $roleArrayCopy[$P][$MKI]['status']=4;
  2194. }
  2195. foreach ($verifyStaff as $m=>$u){
  2196. $AVLFK=$AVL[0].'_R';
  2197. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2198. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2199. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2200. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2201. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2202. break;
  2203. }
  2204. }
  2205. }else{
  2206. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2207. $button=4;
  2208. $roleArrayCopy[$P][$MKI]['status']=4;
  2209. }
  2210. }
  2211. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2212. $KOP=true;
  2213. }
  2214. }
  2215. foreach ($roleArrayCopy as $k=>$v){
  2216. foreach ($verifyList as $m=>$n){
  2217. if ($n[0]==$k){
  2218. array_splice($verifyList,$m,1,$v);
  2219. }
  2220. }
  2221. }
  2222. $receiptList[$key]['verifyList']=$verifyList;
  2223. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2224. $receiptList[$key]['button']=$button;
  2225. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2226. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2227. }
  2228. //获取审批日志
  2229. Doo::loadModel('receiptLog');
  2230. $receiptLog=new receiptLog();
  2231. $rlList=array();
  2232. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2233. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2234. if (!empty($rlInfo)){
  2235. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2236. }
  2237. $receiptList[0]['rlList']=$rlList;
  2238. $data['receiptList']=$receiptList;
  2239. $data['memu']="receipt";
  2240. $data['staff']=$this->staff;
  2241. $data['receiptMemu']='approvalExpenses';
  2242. $data['verifyId']=$this->verifyId;
  2243. $data['executeId']=$this->executeId;
  2244. $this->render ( "/admin/expensesDoc", $data );
  2245. }
  2246. function expensesEdi(){
  2247. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2248. $status=isset($this->params['status'])?$this->params['status']:'';
  2249. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2250. $month=$this->get_args('month')?$this->get_args('month'):"";
  2251. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2252. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2253. if (empty($status))
  2254. $status=$this->get_args('status')?$this->get_args('status'):2;
  2255. $vidList=array();
  2256. $button=0;
  2257. Doo::loadModel('verify');
  2258. Doo::loadModel('receipt');
  2259. Doo::loadModel('staff');
  2260. $staff=new staff();
  2261. $receipt=new receipt();
  2262. $verify=new verify();
  2263. Doo::loadModel('L_category');
  2264. $Lcategory=new L_category();
  2265. Doo::loadModel('enclosur');
  2266. $enclosur=new enclosur();
  2267. //user verify ID
  2268. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2269. foreach ($verifyDetail as $key=>$value){
  2270. array_push($vidList, $value['vid']);
  2271. }
  2272. $vid=implode(",", $vidList);
  2273. if(empty($verifyDetail))
  2274. $vid=0;
  2275. $categoryList=$Lcategory->find(array('asArray'=>true));
  2276. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2277. $ap="";
  2278. if($status==4){
  2279. $ap=4;$status=2;
  2280. }
  2281. //get Receipt By verifyID status 2
  2282. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2283. $Locate=0;$roleId=0;
  2284. if($ap==4)
  2285. $status=4;
  2286. foreach ($receiptList as $key=>$value){
  2287. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2288. $receiptList[$key]['reviseDetail']=array();
  2289. if (!empty($value['reviseDetail']))
  2290. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2291. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2292. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2293. $receiptList[$key]['category']=$categoryDetil['title'];
  2294. //检测编辑状态
  2295. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2296. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2297. $verifyStaff=json_decode($value['verifyStaff'],true);
  2298. Doo::loadModel('role');
  2299. $role=new role();
  2300. //print_r($verifyList);
  2301. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2302. foreach ($verifyList as $k=>$v){
  2303. //init verifyStaff
  2304. if ($v[1]=='ROLE'){
  2305. if (!empty($verifyStaff)){
  2306. $endStaffArray=end($verifyStaff);
  2307. if ($v[0]==$endStaffArray['nextStaff']){
  2308. $roleId=$v[0];
  2309. }
  2310. }
  2311. $roleVerify=json_decode($v[3],true);
  2312. $roleKey=$k;$roleArray=array();
  2313. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2314. foreach ($roleVerify as $o=>$p){
  2315. $staffID=explode ('_',$p);
  2316. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2317. //print_r($staffID);
  2318. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2319. array_push($roleArray, $exp);
  2320. }
  2321. $roleArrayCopy[$v[0]]=$roleArray;
  2322. //$verifyList[$k]['roleArray']=$roleArray;
  2323. }
  2324. //print_r($roleArray);
  2325. $verifyList[$k]['date']="";
  2326. $verifyList[$k]['opinion']="";
  2327. $verifyList[$k]['status']="";
  2328. if (empty($verifyStaff)){
  2329. $verifyList[$k]['date']="";
  2330. $verifyList[$k]['opinion']="";
  2331. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2332. $verifyList[$k]['status']=4;
  2333. $button=4;$flag=false;
  2334. }
  2335. }else{
  2336. foreach ($verifyStaff as $m=>$u){
  2337. if ($v[0]==$m){
  2338. $verifyList[$k]['date']=$u['date'];
  2339. $verifyList[$k]['opinion']=$u['opinion'];
  2340. $verifyList[$k]['status']=$u['status'];
  2341. $flag=false;
  2342. break;
  2343. }
  2344. }
  2345. $endStaffArray=end($verifyStaff);
  2346. if (isset($endStaffArray['ROLE'])){
  2347. }else{
  2348. $endKey=key($verifyStaff);
  2349. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2350. $button=4;
  2351. $verifyList[$k]['status']=4;
  2352. }
  2353. }
  2354. }
  2355. }
  2356. $rolename['name']='';
  2357. if (!empty($roleId)){
  2358. Doo::loadModel('role');
  2359. $role=new role();
  2360. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2361. }
  2362. if (!empty($verifyStaff))
  2363. $endStaffArray=end($verifyStaff);
  2364. $KOP=false;
  2365. foreach ($roleArrayCopy as $P=>$A){
  2366. foreach ( $A as $MKI=>$AVL){
  2367. if (!empty($verifyStaff)){
  2368. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2369. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2370. $button=4;
  2371. $roleArrayCopy[$P][$MKI]['status']=4;
  2372. }
  2373. foreach ($verifyStaff as $m=>$u){
  2374. $AVLFK=$AVL[0].'_R';
  2375. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2376. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2377. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2378. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2379. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2380. break;
  2381. }
  2382. }
  2383. }else{
  2384. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2385. $button=4;
  2386. $roleArrayCopy[$P][$MKI]['status']=4;
  2387. }
  2388. }
  2389. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2390. $KOP=true;
  2391. }
  2392. }
  2393. // print_r($roleArrayCopy);
  2394. // echo $roleKey;
  2395. foreach ($roleArrayCopy as $k=>$v){
  2396. foreach ($verifyList as $m=>$n){
  2397. if ($n[0]==$k){
  2398. array_splice($verifyList,$m,1,$v);
  2399. }
  2400. }
  2401. }
  2402. $receiptList[$key]['verifyList']=$verifyList;
  2403. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2404. $receiptList[$key]['button']=$button;
  2405. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2406. }
  2407. //$data['verifyDetail']=$verifyDetail;
  2408. $mothHtml="";
  2409. for($i=1;$i<=12;$i++){
  2410. if($month==$i)
  2411. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2412. else
  2413. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2414. }
  2415. //获取审批日志
  2416. Doo::loadModel('receiptLog');
  2417. $receiptLog=new receiptLog();
  2418. $rlList=array();
  2419. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2420. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2421. if (!empty($rlInfo)){
  2422. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2423. }
  2424. $receiptList[0]['rlList']=$rlList;
  2425. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2426. $enclosurHtml='';
  2427. foreach ($enclosurList as $value){
  2428. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2429. }
  2430. //print_r($receiptList);
  2431. $data['rid']=$rid;
  2432. $data['enclosurHtml']=$enclosurHtml;
  2433. $data['rolename']=$rolename['name'];
  2434. $data['datetij']=$tijdate['date'];
  2435. $data['mothHtml']=$mothHtml;
  2436. $data['receiptList']=$receiptList;
  2437. $data['receiptApprovalCount']=count($receiptList);
  2438. $data['status']=$status;
  2439. $data['year']=$year;
  2440. $data['categoryList']=$categoryList;
  2441. $data['staffList']=$staffList;
  2442. $data['cid']=$cid;
  2443. $data['sid']=$sid;
  2444. $data['ap']=$ap;
  2445. $data['memu']="receipt";
  2446. $data['staff']=$this->staff;
  2447. $data['receiptMemu']='approvalExpenses';
  2448. $data['verifyId']=$this->verifyId;
  2449. $data['executeId']=$this->executeId;
  2450. $this->render ( "/admin/expensesEdi", $data );
  2451. }
  2452. function expensesDefray(){
  2453. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2454. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2455. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2456. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2457. if(!empty($rid)){
  2458. Doo::loadModel("verify");
  2459. $verify=new verify();
  2460. Doo::loadModel("receiptDetail");
  2461. $receiptDetailObj=new receiptDetail();
  2462. Doo::loadModel("itemStatistics");
  2463. Doo::loadModel("statistics");
  2464. $statistics=new statistics();
  2465. $itemStatistics=new itemStatistics();
  2466. Doo::loadModel("receipt");
  2467. $receipt=new receipt();
  2468. Doo::loadModel("loanReceipt");
  2469. $loanReceipt=new loanReceipt();
  2470. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2471. if (empty($receiptDetail))
  2472. return "/approval";
  2473. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2474. $verifyString=$verifyDetail['staff'];
  2475. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2476. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2477. if(empty($opinion)){
  2478. if ($status==3)
  2479. $opinion="终止";
  2480. else
  2481. $opinion="同意支付";
  2482. }
  2483. $nowStaff=0;$nowStaffList=array();
  2484. if(empty($verifyStaff)){
  2485. //还需加入是否已经进入角色审批
  2486. if ($verifyDetail[0][1]=='ROLE'){
  2487. //print_r($verifyDetail);echo "ddd";
  2488. $vStaffString=json_decode($verifyDetail[0][3]);
  2489. foreach ($vStaffString as $key=>$value){
  2490. $staffK=explode("_", $value);
  2491. if ($staffK[0]!=$this->staff[0]['sid'])
  2492. array_push($nowStaffList, $staffK[0]);
  2493. }
  2494. //print_r($verifyDetail);
  2495. //die;
  2496. $nowStaff=implode(',', $nowStaffList);
  2497. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2498. }else{
  2499. if ($verifyDetail[1][1]=='ROLE'){
  2500. $vStaffString=json_decode($verifyDetail[1][3]);
  2501. //echo "dd";
  2502. foreach ($vStaffString as $key=>$value){
  2503. $staffK=explode("_", $value);
  2504. array_push($nowStaffList, $staffK[0]);
  2505. }
  2506. $nowStaff=implode(',', $nowStaffList);
  2507. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2508. }else{
  2509. $nowStaff=$verifyDetail[1][0];
  2510. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2511. }
  2512. }
  2513. if($status==3)
  2514. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2515. $vStaffString=json_encode($verifyStaff);
  2516. $receipt->nowStaff=$nowStaff;
  2517. $receipt->verifyStaff=$vStaffString;
  2518. $loanReceipt->nowStaff=$nowStaff;
  2519. $loanReceipt->verifyStaff=$vStaffString;
  2520. }else{
  2521. $VS=end($verifyStaff);
  2522. //非角色审批
  2523. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2524. $nextStaff=0;$roleSTF=false;
  2525. foreach ($verifyDetail as $key=>$value){
  2526. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2527. if (isset($verifyDetail[$key+1])){
  2528. $nextStaff=$verifyDetail[$key+1][0];
  2529. if ($verifyDetail[$key+1][1]=='ROLE')
  2530. $roleSTF=true;
  2531. }
  2532. break;
  2533. }
  2534. }
  2535. if (!$roleSTF){
  2536. $nowStaff=$nextStaff;
  2537. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2538. }else{
  2539. //获取角色下的所有用户ID
  2540. $nowStaffList=array();
  2541. foreach ($verifyDetail as $vfk){
  2542. if ($vfk[1]=='ROLE'){
  2543. $vStaffString=json_decode($vfk[3]);
  2544. foreach ($vStaffString as $key=>$value){
  2545. $staffK=explode("_", $value);
  2546. array_push($nowStaffList, $staffK[0]);
  2547. }
  2548. }
  2549. }
  2550. $nowStaff=implode(',', $nowStaffList);
  2551. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2552. }
  2553. if($status==3){
  2554. $verifyStaff['final']=$status;
  2555. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2556. }
  2557. $vStaffString=json_encode($verifyStaff);
  2558. $receipt->nowStaff=$nowStaff;
  2559. $receipt->verifyStaff=$vStaffString;
  2560. $loanReceipt->nowStaff=$nowStaff;
  2561. $loanReceipt->verifyStaff=$vStaffString;
  2562. }
  2563. //角色审批
  2564. if (isset($VS['ROLE'])){
  2565. //找出角色人 当前审批角色组
  2566. $verifyJSStaff=array();$nowStaffList2=array();
  2567. foreach ($verifyDetail as $key=>$value){
  2568. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2569. $verifyJSStaff=json_decode($value[3]);
  2570. foreach ($verifyJSStaff as $m){
  2571. $staffK=explode("_", $m);
  2572. array_push($nowStaffList2, $staffK[0]);
  2573. }
  2574. // print_r($nowStaffList2);
  2575. }
  2576. }
  2577. $RoleVerifyStaff=array();
  2578. foreach ($verifyStaff as $key=>$value){
  2579. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2580. foreach ($nowStaffList2 as $m) {
  2581. if ($key==$m."_R")
  2582. $RoleVerifyStaff[$key]=$value;
  2583. }
  2584. }
  2585. }
  2586. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2587. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2588. //下一个审批人ID
  2589. $nextStaff=0;$falg=false;
  2590. foreach ($verifyDetail as $key=>$value){
  2591. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2592. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2593. $falg=true;
  2594. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2595. foreach ($vStaffString as $v){
  2596. $staffK=explode("_", $v);
  2597. array_push($nowStaffList, $staffK[0]);
  2598. }
  2599. $nowStaff=implode(',', $nowStaffList);
  2600. $nextStaff=$verifyDetail[$key+1][0];
  2601. }elseif(isset($verifyDetail[$key+1])){
  2602. $nextStaff=$verifyDetail[$key+1][0];
  2603. $nowStaff=$nextStaff;
  2604. }else
  2605. $nowStaff='';
  2606. break;
  2607. }
  2608. }
  2609. if ($falg)
  2610. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2611. else
  2612. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2613. // print_r($verifyStaff);
  2614. // echo $nowStaff;die;
  2615. }else{ //进入下一个角色或者审批人
  2616. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2617. //
  2618. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2619. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2620. // print_r($verifyStaff);
  2621. // die;
  2622. }
  2623. if($status==3){
  2624. $verifyStaff['final']=$status;
  2625. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2626. }
  2627. $vStaffString=json_encode($verifyStaff);
  2628. $receipt->verifyStaff=$vStaffString;
  2629. $receipt->nowStaff=$nowStaff;
  2630. $loanReceipt->nowStaff=$nowStaff;
  2631. $loanReceipt->verifyStaff=$vStaffString;
  2632. //die;
  2633. //}
  2634. // print_r($verifyStaff);
  2635. // die;
  2636. }
  2637. //print_r($verifyStaff);die;
  2638. }
  2639. //print_r($verifyDetail);
  2640. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2641. foreach ($verifyDetail as $k=>$v){
  2642. if ($v[1]=='ROLE'){
  2643. $roleId=$v[0];
  2644. $roleVerify=json_decode($v[3],true);
  2645. $roleKey=$k;$roleArray=array();
  2646. foreach ($roleVerify as $o=>$p){
  2647. $staffID=explode ('_',$p);
  2648. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2649. array_push($roleArray, $exp);
  2650. }
  2651. $verifyDetailCopy[$v[0]]=$roleArray;
  2652. }
  2653. }
  2654. //print_r($verifyDetail);
  2655. foreach ($verifyDetailCopy as $k=>$v){
  2656. foreach ($verifyDetail as $m=>$n){
  2657. if ($n[0]==$k){
  2658. array_splice($verifyDetail,$m,1,$v);
  2659. }
  2660. }
  2661. }
  2662. //审批日志
  2663. if (!isset($verifyStaff['final'])){
  2664. Doo::loadModel("receiptLog");
  2665. $receiptLog=new receiptLog();
  2666. if (!empty($roleId)){
  2667. Doo::loadModel("role");
  2668. $role=new role();
  2669. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2670. $receiptLog->rolename=$roleInfo['name'];
  2671. }
  2672. $receiptLog->username=$this->staff[0]['username'];
  2673. $receiptLog->uid=$this->staff[0]['sid'];
  2674. $receiptLog->date=date("Y-m-d");
  2675. $receiptLog->opinion=$opinion;
  2676. $receiptLog->img=$this->staff[0]['avatar'];
  2677. $receiptLog->status=1;
  2678. $receiptLog->rid=$rid;
  2679. $receiptLog->insert();
  2680. }
  2681. if (isset($verifyStaff['final'])){//rDetail
  2682. $receipt->status=3;
  2683. $receipt->verifyBreakup=$verifyString;
  2684. $receiptDetailObj->status=3;
  2685. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2686. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2687. $receipt->status=6;
  2688. $receipt->pastDate=date("Y-m-d");
  2689. $receipt->isBK=1;
  2690. $loanReceipt->verifyBreakup=$verifyString;
  2691. $loanReceipt->status=1;
  2692. $loanReceipt->pastDate=date("Y-m-d");
  2693. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2694. }
  2695. $receipt->update(array('where'=>' rid = '.$rid));
  2696. return "/approvalExpenses/2";
  2697. }
  2698. }
  2699. function implement(){
  2700. Doo::loadModel('receipt');
  2701. $receipt=new receipt();
  2702. Doo::loadModel('L_category');
  2703. $Lcategory=new L_category();
  2704. Doo::loadModel('verify');
  2705. $verify=new verify();
  2706. Doo::loadModel('staff');
  2707. $staff=new staff();
  2708. Doo::loadModel("execute");
  2709. $execute=new execute();
  2710. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2711. Doo::loadModel('loanReceipt');
  2712. $loanReceipt=new loanReceipt();
  2713. //print_r($receiptList);
  2714. $loanList=array();
  2715. if (!isset($receiptList))
  2716. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2717. $Locate=0;$roleId=0;$button=0;
  2718. foreach ($loanList as $key=>$value){
  2719. $loanList[$key]['Locate']=$Locate;$Locate++;
  2720. $loanList[$key]['reviseDetail']=array();
  2721. if (!empty($value['reviseDetail']))
  2722. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2723. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2724. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2725. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2726. $loanList[$key]['category']=$categoryDetil['title'];
  2727. //检测编辑状态
  2728. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2729. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2730. $verifyStaff=json_decode($value['verifyStaff'],true);
  2731. Doo::loadModel('role');
  2732. $role=new role();
  2733. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2734. foreach ($verifyList as $k=>$v){
  2735. //init verifyStaff
  2736. if ($v[1]=='ROLE'){
  2737. if (!empty($verifyStaff)){
  2738. $endStaffArray=end($verifyStaff);
  2739. // if ($v[0]==$endStaffArray['nextStaff']){
  2740. // $roleId=$v[0];
  2741. // }
  2742. }
  2743. $roleVerify=json_decode($v[3],true);
  2744. $roleKey=$k;$roleArray=array();
  2745. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2746. foreach ($roleVerify as $o=>$p){
  2747. $staffID=explode ('_',$p);
  2748. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2749. //print_r($staffID);
  2750. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2751. array_push($roleArray, $exp);
  2752. }
  2753. $roleArrayCopy[$v[0]]=$roleArray;
  2754. //$verifyList[$k]['roleArray']=$roleArray;
  2755. }
  2756. $verifyList[$k]['date']="";
  2757. $verifyList[$k]['opinion']="";
  2758. $verifyList[$k]['status']="";
  2759. if (empty($verifyStaff)){
  2760. $verifyList[$k]['date']="";
  2761. $verifyList[$k]['opinion']="";
  2762. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2763. $verifyList[$k]['status']=4;
  2764. $flag=false;
  2765. }
  2766. }else{
  2767. foreach ($verifyStaff as $m=>$u){
  2768. if ($v[0]==$m){
  2769. $verifyList[$k]['date']=$u['date'];
  2770. $verifyList[$k]['opinion']=$u['opinion'];
  2771. $verifyList[$k]['status']=$u['status'];
  2772. $flag=false;
  2773. break;
  2774. }
  2775. }
  2776. $endStaffArray=end($verifyStaff);
  2777. if (isset($endStaffArray['ROLE'])){
  2778. }else{
  2779. // $endKey=key($verifyStaff);
  2780. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2781. // $button=4;
  2782. // $verifyList[$k]['status']=4;
  2783. // }
  2784. }
  2785. }
  2786. }
  2787. $rolename['name']='';
  2788. if (!empty($roleId)){
  2789. Doo::loadModel('role');
  2790. $role=new role();
  2791. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2792. }
  2793. if (!empty($verifyStaff))
  2794. $endStaffArray=end($verifyStaff);
  2795. $KOP=false;
  2796. foreach ($roleArrayCopy as $P=>$A){
  2797. foreach ( $A as $MKI=>$AVL){
  2798. if (!empty($verifyStaff)){
  2799. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2800. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2801. $button=4;
  2802. $roleArrayCopy[$P][$MKI]['status']=4;
  2803. }
  2804. foreach ($verifyStaff as $m=>$u){
  2805. $AVLFK=$AVL[0].'_R';
  2806. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2807. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2808. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2809. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2810. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2811. break;
  2812. }
  2813. }
  2814. }else{
  2815. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2816. $button=4;
  2817. $roleArrayCopy[$P][$MKI]['status']=4;
  2818. }
  2819. }
  2820. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2821. $KOP=true;
  2822. }
  2823. }
  2824. foreach ($roleArrayCopy as $k=>$v){
  2825. foreach ($verifyList as $m=>$n){
  2826. if ($n[0]==$k){
  2827. array_splice($verifyList,$m,1,$v);
  2828. }
  2829. }
  2830. }
  2831. $loanList[$key]['verifyList']=$verifyList;
  2832. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2833. }
  2834. $data['loanList']=$loanList;
  2835. $Locate=0;$roleId=0;$button=0;
  2836. foreach ($receiptList as $key=>$value){
  2837. $button2=0;
  2838. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2839. $receiptList[$key]['reviseDetail']=array();
  2840. if (!empty($value['reviseDetail']))
  2841. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2842. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2843. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2844. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2845. $receiptList[$key]['category']=$categoryDetil['title'];
  2846. $executeList=json_decode($value['executeCopy'],true);
  2847. $executeStaff=array();
  2848. if (!empty($value['executeStaff'] ))
  2849. $executeStaff=json_decode($value['executeStaff'],true);
  2850. if (isset($executeList)){
  2851. foreach ($executeList as $op=>$lo){
  2852. $executeList[$op]['date']="";
  2853. $executeList[$op]['opinion']="";
  2854. $executeList[$op]['status']="";
  2855. foreach ($executeStaff as $m=>$u){
  2856. if ($lo[0]==$m){
  2857. $executeList[$op]['date']=$u['date'];
  2858. $executeList[$op]['opinion']=$u['opinion'];
  2859. $executeList[$op]['status']=$u['status'];
  2860. break;
  2861. }
  2862. }
  2863. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2864. $button2=1;
  2865. $executeList[$op]['status']=4;
  2866. }
  2867. }
  2868. }
  2869. //检测编辑状态
  2870. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2871. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2872. $verifyStaff=json_decode($value['verifyStaff'],true);
  2873. Doo::loadModel('role');
  2874. $role=new role();
  2875. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2876. foreach ($verifyList as $k=>$v){
  2877. //init verifyStaff
  2878. if ($v[1]=='ROLE'){
  2879. if (!empty($verifyStaff)){
  2880. $endStaffArray=end($verifyStaff);
  2881. // if ($v[0]==$endStaffArray['nextStaff']){
  2882. // $roleId=$v[0];
  2883. // }
  2884. }
  2885. $roleVerify=json_decode($v[3],true);
  2886. $roleKey=$k;$roleArray=array();
  2887. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2888. foreach ($roleVerify as $o=>$p){
  2889. $staffID=explode ('_',$p);
  2890. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2891. //print_r($staffID);
  2892. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2893. array_push($roleArray, $exp);
  2894. }
  2895. $roleArrayCopy[$v[0]]=$roleArray;
  2896. //$verifyList[$k]['roleArray']=$roleArray;
  2897. }
  2898. $verifyList[$k]['date']="";
  2899. $verifyList[$k]['opinion']="";
  2900. $verifyList[$k]['status']="";
  2901. if (empty($verifyStaff)){
  2902. $verifyList[$k]['date']="";
  2903. $verifyList[$k]['opinion']="";
  2904. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2905. $verifyList[$k]['status']=4;
  2906. $flag=false;
  2907. }
  2908. }else{
  2909. foreach ($verifyStaff as $m=>$u){
  2910. if ($v[0]==$m){
  2911. $verifyList[$k]['date']=$u['date'];
  2912. $verifyList[$k]['opinion']=$u['opinion'];
  2913. $verifyList[$k]['status']=$u['status'];
  2914. $flag=false;
  2915. break;
  2916. }
  2917. }
  2918. $endStaffArray=end($verifyStaff);
  2919. if (isset($endStaffArray['ROLE'])){
  2920. }else{
  2921. }
  2922. }
  2923. }
  2924. $rolename['name']='';
  2925. if (!empty($roleId)){
  2926. Doo::loadModel('role');
  2927. $role=new role();
  2928. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2929. }
  2930. if (!empty($verifyStaff))
  2931. $endStaffArray=end($verifyStaff);
  2932. $KOP=false;
  2933. foreach ($roleArrayCopy as $P=>$A){
  2934. foreach ( $A as $MKI=>$AVL){
  2935. if (!empty($verifyStaff)){
  2936. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2937. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2938. $button=4;
  2939. $roleArrayCopy[$P][$MKI]['status']=4;
  2940. }
  2941. foreach ($verifyStaff as $m=>$u){
  2942. $AVLFK=$AVL[0].'_R';
  2943. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2944. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2945. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2946. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2947. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2948. break;
  2949. }
  2950. }
  2951. }else{
  2952. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2953. $button=4;
  2954. $roleArrayCopy[$P][$MKI]['status']=4;
  2955. }
  2956. }
  2957. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2958. $KOP=true;
  2959. }
  2960. }
  2961. foreach ($roleArrayCopy as $k=>$v){
  2962. foreach ($verifyList as $m=>$n){
  2963. if ($n[0]==$k){
  2964. array_splice($verifyList,$m,1,$v);
  2965. }
  2966. }
  2967. }
  2968. $receiptList[$key]['executeList']=$executeList;
  2969. $receiptList[$key]['verifyList']=$verifyList;
  2970. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2971. $receiptList[$key]['button2']=$button2;
  2972. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2973. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2974. $relust=$value['sum']-$value['loanSum'];
  2975. $receiptList[$key]['relust']=$relust;
  2976. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  2977. }
  2978. //print_r($receiptList[$key]['executeList']);
  2979. $data['receiptList']=$receiptList;
  2980. $data['memu']="receipt";
  2981. $data['staff']=$this->staff;
  2982. $data['receiptMemu']='implement';
  2983. $data['verifyId']=$this->verifyId;
  2984. $data['executeId']=$this->executeId;
  2985. $this->render ( "/admin/implement", $data );
  2986. }
  2987. function implementDo(){
  2988. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2989. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2990. if (!empty($rid)){
  2991. Doo::loadModel('receipt');
  2992. $receipt=new receipt();
  2993. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  2994. $executeCopy=json_decode($rinfo['executeCopy'],true);
  2995. $executeStaff=json_decode($rinfo['executeStaff'],true);
  2996. if(empty($executeStaff)){
  2997. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  2998. }else{
  2999. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3000. }
  3001. if (count($executeStaff)==count($executeCopy)){
  3002. $receipt->executeStaff=json_encode($executeStaff);
  3003. $receipt->status=8;
  3004. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3005. $receipt->status=9;
  3006. $receipt->executeDate= date("Y-m-d");
  3007. }else{
  3008. $receipt->executeStaff=json_encode($executeStaff);
  3009. }
  3010. $receipt->update(array('where'=>'rid='.$rid));
  3011. }
  3012. return "/implement";
  3013. }
  3014. function receiptburEdi(){
  3015. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3016. $status=isset($this->params['status'])?$this->params['status']:'';
  3017. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3018. $month=$this->get_args('month')?$this->get_args('month'):"";
  3019. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3020. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3021. if (empty($status))
  3022. $status=$this->get_args('status')?$this->get_args('status'):2;
  3023. $vidList=array();
  3024. $button=0;
  3025. Doo::loadModel('verify');
  3026. Doo::loadModel('receipt');
  3027. Doo::loadModel('staff');
  3028. $staff=new staff();
  3029. $receipt=new receipt();
  3030. $verify=new verify();
  3031. Doo::loadModel('L_category');
  3032. $Lcategory=new L_category();
  3033. Doo::loadModel('enclosur');
  3034. $enclosur=new enclosur();
  3035. Doo::loadModel('loanReceipt');
  3036. $loanReceipt=new loanReceipt();
  3037. //user verify ID
  3038. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3039. foreach ($verifyDetail as $key=>$value){
  3040. array_push($vidList, $value['vid']);
  3041. }
  3042. $vid=implode(",", $vidList);
  3043. if(empty($verifyDetail))
  3044. $vid=0;
  3045. $categoryList=$Lcategory->find(array('asArray'=>true));
  3046. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3047. $ap="";
  3048. if($status==4){
  3049. $ap=4;$status=2;
  3050. }
  3051. //get Receipt By verifyID status 2
  3052. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3053. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3054. $Locate=0;$roleId=0;$button=0;
  3055. foreach ($loanList as $key=>$value){
  3056. $loanList[$key]['Locate']=$Locate;$Locate++;
  3057. $loanList[$key]['reviseDetail']=array();
  3058. if (!empty($value['reviseDetail']))
  3059. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3060. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3061. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3062. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3063. $loanList[$key]['category']=$categoryDetil['title'];
  3064. //检测编辑状态
  3065. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3066. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3067. $verifyStaff=json_decode($value['verifyStaff'],true);
  3068. Doo::loadModel('role');
  3069. $role=new role();
  3070. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3071. foreach ($verifyList as $k=>$v){
  3072. //init verifyStaff
  3073. if ($v[1]=='ROLE'){
  3074. if (!empty($verifyStaff)){
  3075. $endStaffArray=end($verifyStaff);
  3076. }
  3077. $roleVerify=json_decode($v[3],true);
  3078. $roleKey=$k;$roleArray=array();
  3079. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3080. foreach ($roleVerify as $o=>$p){
  3081. $staffID=explode ('_',$p);
  3082. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3083. //print_r($staffID);
  3084. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3085. array_push($roleArray, $exp);
  3086. }
  3087. $roleArrayCopy[$v[0]]=$roleArray;
  3088. //$verifyList[$k]['roleArray']=$roleArray;
  3089. }
  3090. $verifyList[$k]['date']="";
  3091. $verifyList[$k]['opinion']="";
  3092. $verifyList[$k]['status']="";
  3093. if (empty($verifyStaff)){
  3094. $verifyList[$k]['date']="";
  3095. $verifyList[$k]['opinion']="";
  3096. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3097. $verifyList[$k]['status']=4;
  3098. $flag=false;
  3099. }
  3100. }else{
  3101. foreach ($verifyStaff as $m=>$u){
  3102. if ($v[0]==$m){
  3103. $verifyList[$k]['date']=$u['date'];
  3104. $verifyList[$k]['opinion']=$u['opinion'];
  3105. $verifyList[$k]['status']=$u['status'];
  3106. $flag=false;
  3107. break;
  3108. }
  3109. }
  3110. $endStaffArray=end($verifyStaff);
  3111. if (isset($endStaffArray['ROLE'])){
  3112. }else{
  3113. }
  3114. }
  3115. }
  3116. $rolename['name']='';
  3117. if (!empty($roleId)){
  3118. Doo::loadModel('role');
  3119. $role=new role();
  3120. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3121. }
  3122. if (!empty($verifyStaff))
  3123. $endStaffArray=end($verifyStaff);
  3124. $KOP=false;
  3125. foreach ($roleArrayCopy as $P=>$A){
  3126. foreach ( $A as $MKI=>$AVL){
  3127. if (!empty($verifyStaff)){
  3128. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3129. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3130. $button=4;
  3131. $roleArrayCopy[$P][$MKI]['status']=4;
  3132. }
  3133. foreach ($verifyStaff as $m=>$u){
  3134. $AVLFK=$AVL[0].'_R';
  3135. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3136. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3137. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3138. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3139. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3140. break;
  3141. }
  3142. }
  3143. }else{
  3144. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3145. $button=4;
  3146. $roleArrayCopy[$P][$MKI]['status']=4;
  3147. }
  3148. }
  3149. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3150. $KOP=true;
  3151. }
  3152. }
  3153. foreach ($roleArrayCopy as $k=>$v){
  3154. foreach ($verifyList as $m=>$n){
  3155. if ($n[0]==$k){
  3156. array_splice($verifyList,$m,1,$v);
  3157. }
  3158. }
  3159. }
  3160. $loanList[$key]['verifyList']=$verifyList;
  3161. }
  3162. $htmlLoan='';
  3163. if (isset($loanList[0])){
  3164. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3165. if ($value['status']==1)
  3166. $htmlLoan.='<li class="done" >';
  3167. elseif ($value['status']==3)
  3168. $htmlLoan.='<li class="undone" >';
  3169. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3170. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3171. if (isset($value['rolename']))
  3172. $htmlLoan.=$value['rolename'];
  3173. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3174. }
  3175. $data['loanDate']=$loanList[0]['date'];
  3176. }
  3177. $data['htmlLoan']=$htmlLoan;
  3178. //print_r($loanList);
  3179. $Locate=0;$roleId=0;$button=0;
  3180. if($ap==4)
  3181. $status=4;
  3182. foreach ($receiptList as $key=>$value){
  3183. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3184. $receiptList[$key]['reviseDetail']=array();
  3185. if (!empty($value['reviseDetail']))
  3186. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3187. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3188. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3189. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3190. $receiptList[$key]['category']=$categoryDetil['title'];
  3191. //检测编辑状态
  3192. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3193. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3194. $verifyStaff=json_decode($value['verifyStaff'],true);
  3195. Doo::loadModel('role');
  3196. $role=new role();
  3197. //print_r($verifyList);
  3198. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3199. foreach ($verifyList as $k=>$v){
  3200. //init verifyStaff
  3201. if ($v[1]=='ROLE'){
  3202. if (!empty($verifyStaff)){
  3203. $endStaffArray=end($verifyStaff);
  3204. if ($v[0]==$endStaffArray['nextStaff']){
  3205. $roleId=$v[0];
  3206. }
  3207. }
  3208. $roleVerify=json_decode($v[3],true);
  3209. $roleKey=$k;$roleArray=array();
  3210. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3211. foreach ($roleVerify as $o=>$p){
  3212. $staffID=explode ('_',$p);
  3213. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3214. //print_r($staffID);
  3215. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3216. array_push($roleArray, $exp);
  3217. }
  3218. $roleArrayCopy[$v[0]]=$roleArray;
  3219. //$verifyList[$k]['roleArray']=$roleArray;
  3220. }
  3221. //print_r($roleArray);
  3222. $verifyList[$k]['date']="";
  3223. $verifyList[$k]['opinion']="";
  3224. $verifyList[$k]['status']="";
  3225. if (empty($verifyStaff)){
  3226. $verifyList[$k]['date']="";
  3227. $verifyList[$k]['opinion']="";
  3228. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3229. $verifyList[$k]['status']=4;
  3230. $button=4;$flag=false;
  3231. }
  3232. }else{
  3233. foreach ($verifyStaff as $m=>$u){
  3234. if ($v[0]==$m){
  3235. $verifyList[$k]['date']=$u['date'];
  3236. $verifyList[$k]['opinion']=$u['opinion'];
  3237. $verifyList[$k]['status']=$u['status'];
  3238. $flag=false;
  3239. break;
  3240. }
  3241. }
  3242. $endStaffArray=end($verifyStaff);
  3243. if (isset($endStaffArray['ROLE'])){
  3244. }else{
  3245. $endKey=key($verifyStaff);
  3246. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3247. $button=4;
  3248. $verifyList[$k]['status']=4;
  3249. }
  3250. }
  3251. }
  3252. }
  3253. $rolename['name']='';
  3254. if (!empty($roleId)){
  3255. Doo::loadModel('role');
  3256. $role=new role();
  3257. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3258. }
  3259. if (!empty($verifyStaff))
  3260. $endStaffArray=end($verifyStaff);
  3261. $KOP=false;
  3262. foreach ($roleArrayCopy as $P=>$A){
  3263. foreach ( $A as $MKI=>$AVL){
  3264. if (!empty($verifyStaff)){
  3265. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3266. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3267. $button=4;
  3268. $roleArrayCopy[$P][$MKI]['status']=4;
  3269. }
  3270. foreach ($verifyStaff as $m=>$u){
  3271. $AVLFK=$AVL[0].'_R';
  3272. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3273. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3274. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3275. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3276. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3277. break;
  3278. }
  3279. }
  3280. }else{
  3281. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3282. $button=4;
  3283. $roleArrayCopy[$P][$MKI]['status']=4;
  3284. }
  3285. }
  3286. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3287. $KOP=true;
  3288. }
  3289. }
  3290. foreach ($roleArrayCopy as $k=>$v){
  3291. foreach ($verifyList as $m=>$n){
  3292. if ($n[0]==$k){
  3293. array_splice($verifyList,$m,1,$v);
  3294. }
  3295. }
  3296. }
  3297. //print_r($verifyList);
  3298. $receiptList[$key]['verifyList']=$verifyList;
  3299. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3300. $receiptList[$key]['button']=$button;
  3301. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3302. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3303. $relust=$value['sum']-$value['loanSum'];
  3304. $receiptList[$key]['relust']=$relust;
  3305. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3306. }
  3307. //print_r($receiptList);die;
  3308. //$data['verifyDetail']=$verifyDetail;
  3309. $mothHtml="";
  3310. for($i=1;$i<=12;$i++){
  3311. if($month==$i)
  3312. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3313. else
  3314. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3315. }
  3316. //获取审批日志
  3317. Doo::loadModel('receiptLog');
  3318. $receiptLog=new receiptLog();
  3319. $rlList=array();
  3320. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3321. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3322. if (!empty($rlInfo)){
  3323. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3324. }
  3325. //echo $rid;
  3326. //print_r($receiptList);
  3327. $receiptList[0]['rlList']=$rlList;
  3328. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3329. $enclosurHtml='';
  3330. foreach ($enclosurList as $value){
  3331. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3332. }
  3333. $data['enclosurHtml']=$enclosurHtml;
  3334. $data['rolename']=$rolename['name'];
  3335. // $data['datetij']=$tijdate['date'];
  3336. $data['mothHtml']=$mothHtml;
  3337. //print_r($receiptList);
  3338. $data['rid']=$rid;
  3339. $data['tijdate']=$tijdate['date'];
  3340. $data['receiptList']=$receiptList;
  3341. $data['receiptApprovalCount']=count($receiptList);
  3342. $data['status']=$status;
  3343. $data['year']=$year;
  3344. $data['categoryList']=$categoryList;
  3345. $data['staffList']=$staffList;
  3346. $data['cid']=$cid;
  3347. $data['sid']=$sid;
  3348. $data['ap']=$ap;
  3349. $data['memu']="receipt";
  3350. $data['staff']=$this->staff;
  3351. $data['receiptMemu']='approvalExpenses';
  3352. $data['verifyId']=$this->verifyId;
  3353. $data['executeId']=$this->executeId;
  3354. $this->render ( "/admin/receiptburEdi", $data );
  3355. }
  3356. function hisImplement(){
  3357. $item=isset($this->params['item'])?$this->params['item']:"";
  3358. if(empty($item))
  3359. $item=$this->get_args('item')?$this->get_args('item'):"";
  3360. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3361. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3362. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3363. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3364. Doo::loadModel('receipt');
  3365. $receipt=new receipt();
  3366. Doo::loadModel('L_category');
  3367. $Lcategory=new L_category();
  3368. Doo::loadModel('verify');
  3369. Doo::loadModel('statistics');
  3370. $statistics=new statistics();
  3371. $verify=new verify();
  3372. Doo::loadModel('staff');
  3373. $staff=new staff();
  3374. $condition="";
  3375. if($item=="expenses")
  3376. $condition=" and Rtype=1 ";
  3377. elseif ($item=="receipts")
  3378. $condition=" and Rtype=0 ";
  3379. elseif ($item=="remits")
  3380. $condition=" and Rtype=2 ";
  3381. $sopString="";
  3382. $dateCondition=" and Year(executeDate) =".$year;
  3383. if($moth!='MONTH'){
  3384. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3385. }
  3386. if($day!='DAY')
  3387. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3388. if ($sop!='SOP')
  3389. $sopString=" and staff=".$sop;
  3390. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3391. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3392. //员工筛选
  3393. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3394. $sopStaff=array();
  3395. foreach ($receiptList2 as $key=>$value){
  3396. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3397. $sopStaff[$value['staff']]=$staffDetail['username'];
  3398. }
  3399. $Locate=0;$roleId=0;$button=0;
  3400. foreach ($receiptList as $key=>$value){
  3401. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3402. $receiptList[$key]['reviseDetail']=array();
  3403. if (!empty($value['reviseDetail']))
  3404. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3405. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3406. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3407. $receiptList[$key]['category']=$categoryDetil['title'];
  3408. //检测编辑状态
  3409. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3410. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3411. $verifyStaff=json_decode($value['verifyStaff'],true);
  3412. Doo::loadModel('role');
  3413. $role=new role();
  3414. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3415. foreach ($verifyList as $k=>$v){
  3416. //init verifyStaff
  3417. if ($v[1]=='ROLE'){
  3418. if (!empty($verifyStaff)){
  3419. $endStaffArray=end($verifyStaff);
  3420. }
  3421. $roleVerify=json_decode($v[3],true);
  3422. $roleKey=$k;$roleArray=array();
  3423. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3424. foreach ($roleVerify as $o=>$p){
  3425. $staffID=explode ('_',$p);
  3426. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3427. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3428. array_push($roleArray, $exp);
  3429. }
  3430. $roleArrayCopy[$v[0]]=$roleArray;
  3431. }
  3432. $verifyList[$k]['date']="";
  3433. $verifyList[$k]['opinion']="";
  3434. $verifyList[$k]['status']="";
  3435. if (empty($verifyStaff)){
  3436. $verifyList[$k]['date']="";
  3437. $verifyList[$k]['opinion']="";
  3438. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3439. $verifyList[$k]['status']=4;
  3440. $flag=false;
  3441. }
  3442. }else{
  3443. foreach ($verifyStaff as $m=>$u){
  3444. if ($v[0]==$m){
  3445. $verifyList[$k]['date']=$u['date'];
  3446. $verifyList[$k]['opinion']=$u['opinion'];
  3447. $verifyList[$k]['status']=$u['status'];
  3448. $flag=false;
  3449. break;
  3450. }
  3451. }
  3452. $endStaffArray=end($verifyStaff);
  3453. }
  3454. }
  3455. $rolename['name']='';
  3456. if (!empty($roleId)){
  3457. Doo::loadModel('role');
  3458. $role=new role();
  3459. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3460. }
  3461. if (!empty($verifyStaff))
  3462. $endStaffArray=end($verifyStaff);
  3463. $KOP=false;
  3464. foreach ($roleArrayCopy as $P=>$A){
  3465. foreach ( $A as $MKI=>$AVL){
  3466. if (!empty($verifyStaff)){
  3467. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3468. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3469. $button=4;
  3470. $roleArrayCopy[$P][$MKI]['status']=4;
  3471. }
  3472. foreach ($verifyStaff as $m=>$u){
  3473. $AVLFK=$AVL[0].'_R';
  3474. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3475. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3476. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3477. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3478. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3479. break;
  3480. }
  3481. }
  3482. }else{
  3483. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3484. $button=4;
  3485. $roleArrayCopy[$P][$MKI]['status']=4;
  3486. }
  3487. }
  3488. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3489. $KOP=true;
  3490. }
  3491. }
  3492. foreach ($roleArrayCopy as $k=>$v){
  3493. foreach ($verifyList as $m=>$n){
  3494. if ($n[0]==$k){
  3495. array_splice($verifyList,$m,1,$v);
  3496. }
  3497. }
  3498. }
  3499. $receiptList[$key]['verifyList']=$verifyList;
  3500. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3501. $receiptList[$key]['button']=$button;
  3502. }
  3503. //print_r($sopStaff);
  3504. $mothHtml="";
  3505. for($i=1;$i<=12;$i++){
  3506. if($moth==$i)
  3507. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3508. else
  3509. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3510. }
  3511. $dayHtml="";
  3512. if ($day!="DAY"||$moth!="MONTH"){
  3513. for($i = 1; $i <= 31; $i ++) {
  3514. if($day==$i)
  3515. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3516. else
  3517. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3518. }
  3519. }
  3520. $sopHtml="";
  3521. foreach ($sopStaff as $key=>$value){
  3522. if($sop==$key)
  3523. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3524. else
  3525. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3526. }
  3527. $data['sopHtml']=$sopHtml;
  3528. $data['dayHtml']=$dayHtml;
  3529. $data['mothHtml']=$mothHtml;
  3530. $data['receiptList']=$receiptList;
  3531. $data['memu']="receipt";
  3532. $data['staff']=$this->staff;
  3533. $data['receiptMemu']='implement';
  3534. $data['verifyId']=$this->verifyId;
  3535. $data['executeId']=$this->executeId;
  3536. $data['item']=$item;
  3537. $data['year']=$year;
  3538. $data['moth']=$moth;
  3539. $data['day']=$day;
  3540. $data['sop']=$sop;
  3541. $this->render ( "/admin/hisImplement", $data );
  3542. }
  3543. function ajaxExamine(){
  3544. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3545. Doo::loadModel('receipt');
  3546. $receipt=new receipt();
  3547. if (!empty($rid)){
  3548. $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
  3549. ,'asArray'=>true));
  3550. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3551. }
  3552. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3553. }
  3554. function myReceipt(){
  3555. //all approval past withdraw
  3556. $item=isset($this->params['item'])?$this->params['item']:"";
  3557. if(empty($item))
  3558. $item=$this->get_args('item')?$this->get_args('item'):"";
  3559. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3560. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3561. Doo::loadModel('receipt');
  3562. $receipt=new receipt();
  3563. //pre-loaded
  3564. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3565. //have cache
  3566. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3567. if(!empty($moth))//yearPage
  3568. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3569. $this->showCache($path);
  3570. }
  3571. Doo::loadModel('L_category');
  3572. $Lcategory=new L_category();
  3573. Doo::loadModel('verify');
  3574. Doo::loadModel('statistics');
  3575. $statistics=new statistics();
  3576. $verify=new verify();
  3577. Doo::loadModel('staff');
  3578. $staff=new staff();
  3579. $condition=" and status!=0 ";
  3580. if($item=="approval")
  3581. $condition=" and status=2 ";
  3582. elseif ($item=="withdraw")
  3583. $condition=" and status=3 ";
  3584. elseif ($item=="past")
  3585. $condition=" and status=1 ";
  3586. elseif ($item=="whdw")
  3587. $condition=" and status=4 ";
  3588. $dateCondition=" and Year(date) =".$year;
  3589. if(!empty($moth)){
  3590. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3591. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3592. }else
  3593. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3594. if(empty($stList))
  3595. $stList=array('rePrice'=>0,'agPrice'=>0);
  3596. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3597. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3598. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3599. $Locate=0;$roleId=0;$button=0;
  3600. foreach ($receiptList as $key=>$value){
  3601. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3602. $receiptList[$key]['reviseDetail']=array();
  3603. if (!empty($value['reviseDetail']))
  3604. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3605. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3606. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3607. $receiptList[$key]['category']=$categoryDetil['title'];
  3608. //检测编辑状态
  3609. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3610. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3611. $verifyStaff=json_decode($value['verifyStaff'],true);
  3612. Doo::loadModel('role');
  3613. $role=new role();
  3614. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3615. foreach ($verifyList as $k=>$v){
  3616. //init verifyStaff
  3617. if ($v[1]=='ROLE'){
  3618. if (!empty($verifyStaff)){
  3619. $endStaffArray=end($verifyStaff);
  3620. // if ($v[0]==$endStaffArray['nextStaff']){
  3621. // $roleId=$v[0];
  3622. // }
  3623. }
  3624. $roleVerify=json_decode($v[3],true);
  3625. $roleKey=$k;$roleArray=array();
  3626. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3627. foreach ($roleVerify as $o=>$p){
  3628. $staffID=explode ('_',$p);
  3629. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3630. //print_r($staffID);
  3631. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3632. array_push($roleArray, $exp);
  3633. }
  3634. $roleArrayCopy[$v[0]]=$roleArray;
  3635. //$verifyList[$k]['roleArray']=$roleArray;
  3636. }
  3637. $verifyList[$k]['date']="";
  3638. $verifyList[$k]['opinion']="";
  3639. $verifyList[$k]['status']="";
  3640. if (empty($verifyStaff)){
  3641. $verifyList[$k]['date']="";
  3642. $verifyList[$k]['opinion']="";
  3643. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3644. $verifyList[$k]['status']=4;
  3645. $flag=false;
  3646. }
  3647. }else{
  3648. foreach ($verifyStaff as $m=>$u){
  3649. if ($v[0]==$m){
  3650. $verifyList[$k]['date']=$u['date'];
  3651. $verifyList[$k]['opinion']=$u['opinion'];
  3652. $verifyList[$k]['status']=$u['status'];
  3653. $flag=false;
  3654. break;
  3655. }
  3656. }
  3657. $endStaffArray=end($verifyStaff);
  3658. if (isset($endStaffArray['ROLE'])){
  3659. }else{
  3660. // $endKey=key($verifyStaff);
  3661. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3662. // $button=4;
  3663. // $verifyList[$k]['status']=4;
  3664. // }
  3665. }
  3666. }
  3667. }
  3668. $rolename['name']='';
  3669. if (!empty($roleId)){
  3670. Doo::loadModel('role');
  3671. $role=new role();
  3672. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3673. }
  3674. if (!empty($verifyStaff))
  3675. $endStaffArray=end($verifyStaff);
  3676. $KOP=false;
  3677. foreach ($roleArrayCopy as $P=>$A){
  3678. foreach ( $A as $MKI=>$AVL){
  3679. if (!empty($verifyStaff)){
  3680. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3681. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3682. $button=4;
  3683. $roleArrayCopy[$P][$MKI]['status']=4;
  3684. }
  3685. foreach ($verifyStaff as $m=>$u){
  3686. $AVLFK=$AVL[0].'_R';
  3687. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3688. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3689. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3690. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3691. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3692. break;
  3693. }
  3694. }
  3695. }else{
  3696. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3697. $button=4;
  3698. $roleArrayCopy[$P][$MKI]['status']=4;
  3699. }
  3700. }
  3701. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3702. $KOP=true;
  3703. }
  3704. }
  3705. foreach ($roleArrayCopy as $k=>$v){
  3706. foreach ($verifyList as $m=>$n){
  3707. if ($n[0]==$k){
  3708. array_splice($verifyList,$m,1,$v);
  3709. }
  3710. }
  3711. }
  3712. $receiptList[$key]['verifyList']=$verifyList;
  3713. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3714. $receiptList[$key]['button']=$button;
  3715. }
  3716. //print_r($receiptList);die;
  3717. $mothHtml="";
  3718. for($i=1;$i<=12;$i++){
  3719. if($moth==$i)
  3720. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3721. else
  3722. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3723. }
  3724. $data['mothHtml']=$mothHtml;
  3725. $data['receiptList']=$receiptList;
  3726. $data['memu']="receipt";
  3727. $data['staff']=$this->staff;
  3728. $data['receiptMemu']='receipt';
  3729. $data['verifyId']=$this->verifyId;
  3730. $data['executeId']=$this->executeId;
  3731. $data['item']=$item;
  3732. $data['year']=$year;
  3733. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3734. //sufficient condition to generate cache
  3735. if(empty($moth)&&($year<date("Y"))){
  3736. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3737. if(empty($receiptList)){ //generated files
  3738. ob_start();
  3739. $this->render ( "/admin/saea_myList", $data );
  3740. $this->cacheFile($path);die;
  3741. // $content = ob_get_contents();
  3742. // $fp = fopen($path, "w");
  3743. // fwrite($fp, $content);
  3744. // fclose($fp);
  3745. }
  3746. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3747. $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));
  3748. if(empty($receiptList)){ //generated files
  3749. ob_start();
  3750. $this->render ( "/admin/saea_myList", $data );
  3751. $this->cacheFile($path);die;
  3752. }
  3753. }
  3754. }
  3755. $this->render ( "/admin/saea_myList", $data );
  3756. }
  3757. function saeaCreate(){
  3758. Doo::loadModel('accountItem');
  3759. Doo::loadModel('verify');
  3760. Doo::loadModel('receipt');
  3761. Doo::loadModel('L_category');
  3762. $lCategory=new L_category();
  3763. $receipt=new receipt();
  3764. $verify=new verify();
  3765. $accountItem=new accountItem();
  3766. Doo::loadModel("role");
  3767. $role=new role();
  3768. $acItem=$accountItem->find(array('asArray'=>true));
  3769. $veList=$verify->find(array('asArray'=>true));
  3770. foreach ($veList as $key=>$value){
  3771. $v=json_decode($value['staff']);
  3772. $list=array();
  3773. foreach ($v as $n=>$m){
  3774. if ($m['1']=='ROLE'){
  3775. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3776. $v[$n][1]=$roleInfo['name'];
  3777. array_push($list, $roleInfo['name']);
  3778. }else{
  3779. array_push($list, $v[$n][1]);
  3780. }
  3781. }
  3782. $veList[$key]['staff']=implode('>', $list);
  3783. }
  3784. $data['category']=$lCategory->find(array('asArray'=>true));
  3785. $data['veList']=$veList;
  3786. $data['acItem']=$acItem;
  3787. $data['memu']="receipt";
  3788. $data['staff']=$this->staff;
  3789. $data['receiptMemu']='saeaBorad';
  3790. $data['verifyId']=$this->verifyId;
  3791. $data['executeId']=$this->executeId;
  3792. $this->render ( "/admin/saea_create", $data );
  3793. }
  3794. function addReceipt(){
  3795. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3796. $agency=$this->get_args('agency');
  3797. $travel=$this->get_args('travel');
  3798. $train=$this->get_args('train');
  3799. $other=$this->get_args('other');
  3800. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3801. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3802. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3803. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3804. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3805. Doo::loadModel('receipt');
  3806. Doo::loadModel('receiptDetail');
  3807. Doo::loadModel('accountItem');
  3808. $accountItem=new accountItem();
  3809. $receipt=new receipt();
  3810. Doo::loadModel('enclosur');
  3811. Doo::loadModel('execute');
  3812. $execute=new execute();
  3813. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3814. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3815. // if(!empty($receiptDetail))
  3816. // return "/referReceipt/".$receiptDetail['rid'];
  3817. $aItem=$accountItem->find(array('asArray'=>true));
  3818. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3819. $ag=$tr=$ta=$ot=0;
  3820. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3821. foreach ($aItem as $key=>$value){
  3822. if ($value['category']==$this->AGENCY){
  3823. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3824. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3825. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3826. }
  3827. $ag++;
  3828. }
  3829. if($value['category']==$this->TRAVEL){
  3830. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3831. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3832. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3833. }
  3834. $tr++;
  3835. }
  3836. if($value['category']==$this->TRAIN){
  3837. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3838. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3839. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3840. }
  3841. $ta++;
  3842. }
  3843. if($value['category']==$this->OTHER){
  3844. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3845. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3846. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3847. }
  3848. $ot++;
  3849. }
  3850. }
  3851. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3852. //报销单
  3853. $receipt->accountItem=json_encode($accountJson);
  3854. $receipt->staff=$this->staff[0]['sid'];
  3855. $receipt->sum=number_format($sum, 2, '.', '');
  3856. $receipt->date=date("Y-m-d");
  3857. $receipt->cid=$cid;
  3858. $receipt->status=5;
  3859. //修改审批流程加入角色
  3860. $receipt->verify=$verify;
  3861. $receipt->executeCopy=$executeDetail['staff'];
  3862. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3863. $receipt->explanation=$explanation;
  3864. $rid=$receipt->insert();
  3865. //附件
  3866. if (!empty($enclosurName)){
  3867. $enclosurArray=explode('-', $enclosurName);
  3868. foreach ($enclosurArray as $value){
  3869. $enclosur=new enclosur();
  3870. $enclosur->name=$value;
  3871. $enclosur->rid=$rid;
  3872. $enclosur->insert();
  3873. }
  3874. //print_r($enclosurArray);die;
  3875. }
  3876. //报销详情
  3877. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3878. $receiptDetail=new receiptDetail();
  3879. $receiptDetail->staff=$this->staff[0]['sid'];
  3880. $receiptDetail->item=$value['name'];
  3881. $receiptDetail->itemCategory=$this->AGENCY;
  3882. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3883. $receiptDetail->date=date("Y-m-d");
  3884. $receiptDetail->cid=$cid;
  3885. $receiptDetail->rid=$rid;
  3886. $receiptDetail->status=4;
  3887. $receiptDetail->insert();
  3888. }
  3889. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3890. $receiptDetail=new receiptDetail();
  3891. $receiptDetail->staff=$this->staff[0]['sid'];
  3892. $receiptDetail->item=$value['name'];
  3893. $receiptDetail->itemCategory=$this->TRAVEL;
  3894. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3895. $receiptDetail->date=date("Y-m-d");
  3896. $receiptDetail->cid=$cid;
  3897. $receiptDetail->rid=$rid;
  3898. $receiptDetail->status=4;
  3899. $receiptDetail->insert();
  3900. }
  3901. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3902. $receiptDetail=new receiptDetail();
  3903. $receiptDetail->staff=$this->staff[0]['sid'];
  3904. $receiptDetail->item=$value['name'];
  3905. $receiptDetail->itemCategory=$this->TRAIN;
  3906. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3907. $receiptDetail->date=date("Y-m-d");
  3908. $receiptDetail->cid=$cid;
  3909. $receiptDetail->rid=$rid;
  3910. $receiptDetail->status=4;
  3911. $receiptDetail->insert();
  3912. }
  3913. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3914. $receiptDetail=new receiptDetail();
  3915. $receiptDetail->staff=$this->staff[0]['sid'];
  3916. $receiptDetail->item=$value['name'];
  3917. $receiptDetail->itemCategory=$this->OTHER;
  3918. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3919. $receiptDetail->date=date("Y-m-d");
  3920. $receiptDetail->cid=$cid;
  3921. $receiptDetail->rid=$rid;
  3922. $receiptDetail->status=4;
  3923. $receiptDetail->insert();
  3924. }
  3925. //return "/referReceipt/".$rid;
  3926. }
  3927. return "/saeaBorad";
  3928. }
  3929. function referReceipt(){
  3930. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3931. Doo::loadModel('receipt');
  3932. Doo::loadModel('verify');
  3933. $verify=new verify();
  3934. $receipt=new receipt();
  3935. Doo::loadModel('L_category');
  3936. $lCategory=new L_category();
  3937. Doo::loadModel("role");
  3938. $role=new role();
  3939. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3940. if(empty($receiptDetail))
  3941. return "/addReceipt";
  3942. foreach ($receiptDetail as $key=>$value){
  3943. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  3944. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3945. $v=json_decode($veList['staff']);
  3946. array_push($v[0], $veList['description']);
  3947. foreach ($v as $n=>$m){
  3948. if ($m['1']=='ROLE'){
  3949. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3950. $v[$n][1]=$roleInfo['name'];
  3951. }
  3952. }
  3953. $receiptDetail[$key]['staff']=$v;
  3954. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3955. $receiptDetail[$key]['category']=$category['title'];
  3956. }
  3957. //print_r($receiptDetail);
  3958. $data['receiptDetail']=$receiptDetail;
  3959. $data['memu']="receipt";
  3960. $data['staff']=$this->staff;
  3961. $data['receiptMemu']='saeaCreate';
  3962. $data['verifyId']=$this->verifyId;
  3963. $data['executeId']=$this->executeId;
  3964. $this->render ( "/admin/saea_confirm", $data );
  3965. }
  3966. function editReceipt(){
  3967. //edit status 4
  3968. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3969. //echo $rid;
  3970. Doo::loadModel('accountItem');
  3971. Doo::loadModel('verify');
  3972. Doo::loadModel('receipt');
  3973. $receipt=new receipt();
  3974. $verify=new verify();
  3975. $accountItem=new accountItem();
  3976. Doo::loadModel('L_category');
  3977. $lCategory=new L_category();
  3978. Doo::loadModel("role");
  3979. $role=new role();
  3980. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  3981. if(empty($receiptDetail))
  3982. return "/saeaCreate";
  3983. $acItem=$accountItem->find(array('asArray'=>true));
  3984. $veList=$verify->find(array('asArray'=>true));
  3985. foreach ($veList as $key=>$value){
  3986. $v=json_decode($value['staff']);
  3987. $list=array();
  3988. foreach ($v as $n=>$m){
  3989. if ($m['1']=='ROLE'){
  3990. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3991. $v[$n][1]=$roleInfo['name'];
  3992. array_push($list, $roleInfo['name']);
  3993. }else{
  3994. array_push($list, $v[$n][1]);
  3995. }
  3996. }
  3997. $veList[$key]['staff']=implode('>', $list);
  3998. }
  3999. //配置编辑信息
  4000. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4001. foreach ($acItem as $key=>$value){
  4002. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4003. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4004. $acItem[$key]['price']=$v['price'];
  4005. }
  4006. }
  4007. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4008. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4009. $acItem[$key]['price']=$v['price'];
  4010. }
  4011. }
  4012. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4013. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4014. $acItem[$key]['price']=$v['price'];
  4015. }
  4016. }
  4017. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4018. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4019. $acItem[$key]['price']=$v['price'];
  4020. }
  4021. }
  4022. }
  4023. $data['category']=$lCategory->find(array('asArray'=>true));
  4024. $data['cSum']=$accountItemList['cSum'];
  4025. $data['sum']=$receiptDetail['sum'];
  4026. $data['receiptDetail']=$receiptDetail;
  4027. $data['veList']=$veList;
  4028. $data['acItem']=$acItem;
  4029. $data['memu']="receipt";
  4030. $data['staff']=$this->staff;
  4031. $data['receiptMemu']='saeaBorad';
  4032. $data['verify']=$receiptDetail['verify'];
  4033. $data['verifyId']=$this->verifyId;
  4034. $data['executeId']=$this->executeId;
  4035. $data['rid']=$rid;
  4036. $this->render ( "/admin/saea_edit", $data );
  4037. }
  4038. function updateReceipt(){
  4039. $agency=$this->get_args('agency');
  4040. $travel=$this->get_args('travel');
  4041. $train=$this->get_args('train');
  4042. $other=$this->get_args('other');
  4043. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4044. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4045. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4046. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4047. if(!empty($verify)&&!empty($explanation)){
  4048. Doo::loadModel('receipt');
  4049. Doo::loadModel('receiptDetail');
  4050. Doo::loadModel('accountItem');
  4051. $accountItem=new accountItem();
  4052. $receipt=new receipt();
  4053. Doo::loadModel('execute');
  4054. $execute=new execute();
  4055. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4056. if(empty($receiptDetail))
  4057. return "/saeaBorad";
  4058. if ($receiptDetail['Rtype']==1)
  4059. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4060. else
  4061. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4062. $aItem=$accountItem->find(array('asArray'=>true));
  4063. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4064. $ag=$tr=$ta=$ot=0;
  4065. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4066. foreach ($aItem as $key=>$value){
  4067. if ($value['category']==$this->AGENCY){
  4068. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4069. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4070. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4071. }
  4072. $ag++;
  4073. }
  4074. if($value['category']==$this->TRAVEL){
  4075. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4076. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4077. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4078. }
  4079. $tr++;
  4080. }
  4081. if($value['category']==$this->TRAIN){
  4082. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4083. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4084. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4085. }
  4086. $ta++;
  4087. }
  4088. if($value['category']==$this->OTHER){
  4089. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4090. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4091. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4092. }
  4093. $ot++;
  4094. }
  4095. }
  4096. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4097. //报销单
  4098. $rid=$receipt->rid=$receiptDetail['rid'];
  4099. $receipt->accountItem=json_encode($accountJson);
  4100. $receipt->staff=$this->staff[0]['sid'];
  4101. $receipt->sum=number_format($sum, 2, '.', '');
  4102. $receipt->date=date("Y-m-d");
  4103. $receipt->cid=$cid;
  4104. if (($receiptDetail['status']!=4)){
  4105. if ($receiptDetail['Rtype']==1)
  4106. $receipt->status=7;
  4107. else
  4108. $receipt->status=5;
  4109. }
  4110. $receipt->verify=$verify;
  4111. $receipt->executeCopy=$executeDetail['staff'];
  4112. $receipt->explanation=$explanation;
  4113. $receipt->update();
  4114. $receiptDetail=new receiptDetail();
  4115. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4116. //报销详情
  4117. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4118. $receiptDetail=new receiptDetail();
  4119. $receiptDetail->staff=$this->staff[0]['sid'];
  4120. $receiptDetail->item=$value['name'];
  4121. $receiptDetail->itemCategory=$this->AGENCY;
  4122. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4123. $receiptDetail->date=date("Y-m-d");
  4124. $receiptDetail->cid=$cid;
  4125. $receiptDetail->rid=$rid;
  4126. $receiptDetail->status=4;
  4127. $receiptDetail->insert();
  4128. }
  4129. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4130. $receiptDetail=new receiptDetail();
  4131. $receiptDetail->staff=$this->staff[0]['sid'];
  4132. $receiptDetail->item=$value['name'];
  4133. $receiptDetail->itemCategory=$this->TRAVEL;
  4134. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4135. $receiptDetail->date=date("Y-m-d");
  4136. $receiptDetail->cid=$cid;
  4137. $receiptDetail->rid=$rid;
  4138. $receiptDetail->status=4;
  4139. $receiptDetail->insert();
  4140. }
  4141. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4142. $receiptDetail=new receiptDetail();
  4143. $receiptDetail->staff=$this->staff[0]['sid'];
  4144. $receiptDetail->item=$value['name'];
  4145. $receiptDetail->itemCategory=$this->TRAIN;
  4146. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4147. $receiptDetail->date=date("Y-m-d");
  4148. $receiptDetail->cid=$cid;
  4149. $receiptDetail->rid=$rid;
  4150. $receiptDetail->status=4;
  4151. $receiptDetail->insert();
  4152. }
  4153. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4154. $receiptDetail=new receiptDetail();
  4155. $receiptDetail->staff=$this->staff[0]['sid'];
  4156. $receiptDetail->item=$value['name'];
  4157. $receiptDetail->itemCategory=$this->OTHER;
  4158. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4159. $receiptDetail->date=date("Y-m-d");
  4160. $receiptDetail->cid=$cid;
  4161. $receiptDetail->rid=$rid;
  4162. $receiptDetail->status=4;
  4163. $receiptDetail->insert();
  4164. }
  4165. //return "/referReceipt/".$rid;
  4166. }
  4167. return "/saeaBorad";
  4168. }
  4169. function approvedReceipt(){
  4170. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4171. Doo::loadModel('receipt');
  4172. Doo::loadModel('receiptDetail');
  4173. $receipt=new receipt();
  4174. $receiptDetail=new receiptDetail();
  4175. Doo::loadModel('statistics');
  4176. Doo::loadModel('itemStatistics');
  4177. $statistics=new statistics();
  4178. $itemStatistics=new itemStatistics();
  4179. Doo::loadModel("verify");
  4180. $verify=new verify();
  4181. //审批状态的判定
  4182. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4183. if(empty($receiptDetailList))
  4184. return "/saeaBorad";
  4185. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4186. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4187. if (empty($receiptDetailList['nowStaff'])){
  4188. $nowStaff="";$nowStaffList=array();
  4189. if ($verifyDetail[0][1]=='ROLE'){
  4190. $vStaffString=json_decode($verifyDetail[0][3]);
  4191. foreach ($vStaffString as $key=>$value){
  4192. $staffK=explode("_", $value);
  4193. array_push($nowStaffList, $staffK[0]);
  4194. }
  4195. $nowStaff=implode(',', $nowStaffList);
  4196. }else{
  4197. $nowStaff=$verifyDetail[0][0];
  4198. }
  4199. $receipt->nowStaff=$nowStaff;
  4200. }
  4201. // echo $nowStaff;
  4202. // print_r($verifyDetail);die;
  4203. $receipt->rid=$receiptDetailList['rid'];
  4204. $receipt->date=date("Y-m-d");
  4205. $receipt->status=2;
  4206. $receipt->update();
  4207. $receiptDetail->status=2;
  4208. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4209. Doo::loadModel("receiptLog");
  4210. $receiptLog=new receiptLog();
  4211. Doo::loadModel("verify");
  4212. $verify=new verify();
  4213. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4214. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4215. $jd=json_decode($vr['staff']);$roleId=0;
  4216. foreach ($jd as $key=>$value){
  4217. if ($value[1]=='ROLE'){
  4218. $pos = strpos($value[3], $this->staff[0]['sid']);
  4219. if ($pos !== false) {
  4220. $roleId=$value[0];
  4221. }
  4222. }
  4223. }
  4224. //审批日志
  4225. //echo $roleId;die;
  4226. if (!empty($roleId)){
  4227. Doo::loadModel("role");
  4228. $role=new role();
  4229. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4230. $receiptLog->rolename=$roleInfo['name'];
  4231. }
  4232. $receiptLog->username=$this->staff[0]['username'];
  4233. $receiptLog->uid=$this->staff[0]['sid'];
  4234. $receiptLog->date=date("Y-m-d");
  4235. $receiptLog->opinion='提交审批';
  4236. $receiptLog->img=$this->staff[0]['avatar'];
  4237. $receiptLog->status=2;
  4238. $receiptLog->rid=$rid;
  4239. $receiptLog->insert();
  4240. //statistics item
  4241. $dateArray=explode("-", $receiptDetailList['date']);
  4242. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4243. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4244. //print_r($accountItem['cSum']['agencySum']);die;
  4245. // foreach ($accountItem['cSum'] as $key=>$value){
  4246. // if($key=="agencySum"){
  4247. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4248. // if(empty($iStatistics)){
  4249. // $itemStatistics->cid=$this->staff[0]['cid'];
  4250. // $itemStatistics->staff=$this->staff[0]['sid'];
  4251. // $itemStatistics->price=$value;
  4252. // $itemStatistics->itemCategory=$this->AGENCY;
  4253. // $itemStatistics->date=date("Y-m-d");
  4254. // $itemStatistics->insert();
  4255. // }else{
  4256. // if (!empty($value)){
  4257. // $itemStatistics->price=$value+$iStatistics['price'];
  4258. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4259. // }
  4260. // }
  4261. // }elseif($key=="travelSum"){
  4262. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4263. // if(empty($iStatistics)){
  4264. // $itemStatistics->cid=$this->staff[0]['cid'];
  4265. // $itemStatistics->staff=$this->staff[0]['sid'];
  4266. // $itemStatistics->price=$value;
  4267. // $itemStatistics->itemCategory=$this->TRAVEL;
  4268. // $itemStatistics->date=date("Y-m-d");
  4269. // $itemStatistics->insert();
  4270. // }else{
  4271. // if (!empty($value)){
  4272. // $itemStatistics->price=$value+$iStatistics['price'];
  4273. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4274. // }
  4275. // }
  4276. // }elseif($key=="trainSum"){
  4277. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4278. // if(empty($iStatistics)){
  4279. // $itemStatistics->cid=$this->staff[0]['cid'];
  4280. // $itemStatistics->staff=$this->staff[0]['sid'];
  4281. // $itemStatistics->price=$value;
  4282. // $itemStatistics->itemCategory=$this->TRAIN;
  4283. // $itemStatistics->date=date("Y-m-d");
  4284. // $itemStatistics->insert();
  4285. // }else{
  4286. // if (!empty($value)){
  4287. // $itemStatistics->price=$value+$iStatistics['price'];
  4288. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4289. // }
  4290. // }
  4291. // }elseif($key=="otherSum"){
  4292. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4293. // if(empty($iStatistics)){
  4294. // $itemStatistics->cid=$this->staff[0]['cid'];
  4295. // $itemStatistics->staff=$this->staff[0]['sid'];
  4296. // $itemStatistics->price=$value;
  4297. // $itemStatistics->itemCategory=$this->OTHER;
  4298. // $itemStatistics->date=date("Y-m-d");
  4299. // $itemStatistics->insert();
  4300. // }else{
  4301. // if (!empty($value)){
  4302. // $itemStatistics->price=$value+$iStatistics['price'];
  4303. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4304. // }
  4305. // }
  4306. // }
  4307. // }
  4308. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4309. if(empty($stat)){
  4310. $statistics->date=date("Y-m-d");
  4311. $statistics->cid=$this->staff[0]['cid'];
  4312. $statistics->staff=$this->staff[0]['sid'];
  4313. $statistics->agPrice=0;
  4314. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4315. $statistics->insert();
  4316. }else{
  4317. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4318. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4319. }
  4320. return "/expenses";
  4321. }
  4322. function approval(){
  4323. $status=isset($this->params['status'])?$this->params['status']:'';
  4324. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4325. $month=$this->get_args('month')?$this->get_args('month'):"";
  4326. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4327. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4328. if (empty($status))
  4329. $status=$this->get_args('status')?$this->get_args('status'):2;
  4330. $vidList=array();
  4331. $button=0;
  4332. Doo::loadModel('verify');
  4333. $verify=new verify();
  4334. Doo::loadModel('receipt');
  4335. $receipt=new receipt();
  4336. Doo::loadModel('staff');
  4337. $staff=new staff();
  4338. Doo::loadModel('L_category');
  4339. $Lcategory=new L_category();
  4340. //user verify ID
  4341. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4342. foreach ($verifyDetail as $key=>$value){
  4343. array_push($vidList, $value['vid']);
  4344. }
  4345. $vid=implode(",", $vidList);
  4346. if(empty($verifyDetail))
  4347. $vid=0;
  4348. /*
  4349. */
  4350. $dateCondition=" and Year(date) =".$year;
  4351. if(!empty($month))
  4352. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4353. $categoryList=$Lcategory->find(array('asArray'=>true));
  4354. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4355. $cateCondition="";$staffCondition="";$approvalCondition="";
  4356. if (!empty($cid))
  4357. $cateCondition=' and cid='.$cid;
  4358. if(!empty($sid)){
  4359. $staffCondition=' and staff='.$sid;
  4360. $cateCondition="";
  4361. }
  4362. // elseif($status==1){
  4363. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4364. // }
  4365. if($status==2){
  4366. //查找角色审批人
  4367. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4368. }
  4369. $ap="";
  4370. if($status==4){
  4371. $ap=4;$status=2;
  4372. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4373. }
  4374. if($status==5){
  4375. $status=4;$ap=5;
  4376. }
  4377. //echo $vid;
  4378. //get Receipt By verifyID status 2 .$approvalCondition
  4379. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4380. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4381. ,'desc'=>'rid','asArray'=>true));
  4382. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4383. $Locate=0;
  4384. if($ap==4)
  4385. $status=4;
  4386. elseif ($ap==5)
  4387. $status=5;
  4388. foreach ($receiptList as $key=>$value){
  4389. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4390. $receiptList[$key]['reviseDetail']=array();
  4391. if (!empty($value['reviseDetail']))
  4392. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4393. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4394. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4395. $receiptList[$key]['category']=$categoryDetil['title'];
  4396. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4397. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4398. $verifyStaff=json_decode($value['verifyStaff'],true);
  4399. foreach ($verifyList as $k=>$v){
  4400. //init verifyStaff
  4401. $verifyList[$k]['date']="";
  4402. $verifyList[$k]['opinion']="";
  4403. $verifyList[$k]['status']="";
  4404. if (empty($verifyStaff)){
  4405. $verifyList[$k]['date']="";
  4406. $verifyList[$k]['opinion']="";
  4407. if ($v[0]==$this->staff[0]['sid']){
  4408. $verifyList[$k]['status']=4;
  4409. $button=4;
  4410. }
  4411. }else{
  4412. $flag=true;
  4413. foreach ($verifyStaff as $m=>$u){
  4414. if ($v[0]==$m){
  4415. $verifyList[$k]['date']=$u['date'];
  4416. $verifyList[$k]['opinion']=$u['opinion'];
  4417. $verifyList[$k]['status']=$u['status'];
  4418. $flag=false;
  4419. break;
  4420. }
  4421. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4422. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4423. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4424. }
  4425. if($flag){//检测可编辑
  4426. if($v[0]==$this->staff[0]['sid']){
  4427. $verifyList[$k]['status']=4;$button=4;
  4428. }
  4429. }
  4430. }
  4431. }
  4432. $receiptList[$key]['verifyList']=$verifyList;
  4433. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4434. $receiptList[$key]['button']=$button;
  4435. }
  4436. //print_r($receiptList);die;
  4437. //$data['verifyDetail']=$verifyDetail;
  4438. $mothHtml="";
  4439. for($i=1;$i<=12;$i++){
  4440. if($month==$i)
  4441. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4442. else
  4443. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4444. }
  4445. $data['mothHtml']=$mothHtml;
  4446. $data['receiptList']=$receiptList;
  4447. $data['receiptApprovalCount']=count($receiptList);
  4448. $data['status']=$status;
  4449. $data['year']=$year;
  4450. $data['categoryList']=$categoryList;
  4451. $data['staffList']=$staffList;
  4452. $data['cid']=$cid;
  4453. $data['sid']=$sid;
  4454. $data['ap']=$ap;
  4455. $data['memu']="receipt";
  4456. $data['staff']=$this->staff;
  4457. $data['receiptMemu']='approval';
  4458. $data['verifyId']=$this->verifyId;
  4459. $data['executeId']=$this->executeId;
  4460. $this->render ( "/admin/saea_reportList", $data );
  4461. }
  4462. function approvalDetails(){
  4463. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4464. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4465. $month=$this->get_args('month')?$this->get_args('month'):"";
  4466. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4467. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4468. Doo::loadModel('verify');
  4469. $verify=new verify();
  4470. Doo::loadModel('receipt');
  4471. $receipt=new receipt();
  4472. Doo::loadModel('staff');
  4473. $staff=new staff();
  4474. Doo::loadModel('L_category');
  4475. $Lcategory=new L_category();
  4476. Doo::loadModel('enclosur');
  4477. $enclosur=new enclosur();
  4478. $vidList=array();
  4479. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4480. foreach ($verifyDetail as $key=>$value){
  4481. array_push($vidList, $value['vid']);
  4482. }
  4483. $vid=implode(",", $vidList);
  4484. if(empty($verifyDetail))
  4485. $vid=0;
  4486. $categoryList=$Lcategory->find(array('asArray'=>true));
  4487. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4488. $ap=0;
  4489. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4490. $Locate=0;$roleId=0;$button=0;
  4491. foreach ($receiptList as $key=>$value){
  4492. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4493. $receiptList[$key]['reviseDetail']=array();
  4494. if (!empty($value['reviseDetail']))
  4495. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4496. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4497. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4498. $receiptList[$key]['category']=$categoryDetil['title'];
  4499. //检测编辑状态
  4500. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4501. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4502. $verifyStaff=json_decode($value['verifyStaff'],true);
  4503. Doo::loadModel('role');
  4504. $role=new role();
  4505. //print_r($verifyList);
  4506. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4507. foreach ($verifyList as $k=>$v){
  4508. //init verifyStaff
  4509. if ($v[1]=='ROLE'){
  4510. if (!empty($verifyStaff)){
  4511. $endStaffArray=end($verifyStaff);
  4512. if ($v[0]==$endStaffArray['nextStaff']){
  4513. $roleId=$v[0];
  4514. }
  4515. }
  4516. $roleVerify=json_decode($v[3],true);
  4517. $roleKey=$k;$roleArray=array();
  4518. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4519. foreach ($roleVerify as $o=>$p){
  4520. $staffID=explode ('_',$p);
  4521. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4522. //print_r($staffID);
  4523. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4524. array_push($roleArray, $exp);
  4525. }
  4526. $roleArrayCopy[$v[0]]=$roleArray;
  4527. //$verifyList[$k]['roleArray']=$roleArray;
  4528. }
  4529. //print_r($roleArray);
  4530. $verifyList[$k]['date']="";
  4531. $verifyList[$k]['opinion']="";
  4532. $verifyList[$k]['status']="";
  4533. if (empty($verifyStaff)){
  4534. $verifyList[$k]['date']="";
  4535. $verifyList[$k]['opinion']="";
  4536. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4537. $verifyList[$k]['status']=4;
  4538. $button=4;$flag=false;
  4539. }
  4540. }else{
  4541. foreach ($verifyStaff as $m=>$u){
  4542. if ($v[0]==$m){
  4543. $verifyList[$k]['date']=$u['date'];
  4544. $verifyList[$k]['opinion']=$u['opinion'];
  4545. $verifyList[$k]['status']=$u['status'];
  4546. $flag=false;
  4547. break;
  4548. }
  4549. }
  4550. $endStaffArray=end($verifyStaff);
  4551. if (isset($endStaffArray['ROLE'])){
  4552. }else{
  4553. $endKey=key($verifyStaff);
  4554. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4555. $button=4;
  4556. $verifyList[$k]['status']=4;
  4557. }
  4558. }
  4559. }
  4560. }
  4561. $rolename['name']='';
  4562. if (!empty($roleId)){
  4563. Doo::loadModel('role');
  4564. $role=new role();
  4565. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4566. }
  4567. if (!empty($verifyStaff))
  4568. $endStaffArray=end($verifyStaff);
  4569. $KOP=false;
  4570. foreach ($roleArrayCopy as $P=>$A){
  4571. foreach ( $A as $MKI=>$AVL){
  4572. if (!empty($verifyStaff)){
  4573. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4574. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4575. $button=4;
  4576. $roleArrayCopy[$P][$MKI]['status']=4;
  4577. }
  4578. foreach ($verifyStaff as $m=>$u){
  4579. $AVLFK=$AVL[0].'_R';
  4580. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4581. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4582. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4583. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4584. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4585. break;
  4586. }
  4587. }
  4588. }else{
  4589. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4590. $button=4;
  4591. $roleArrayCopy[$P][$MKI]['status']=4;
  4592. }
  4593. }
  4594. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4595. $KOP=true;
  4596. }
  4597. }
  4598. foreach ($roleArrayCopy as $k=>$v){
  4599. foreach ($verifyList as $m=>$n){
  4600. if ($n[0]==$k){
  4601. array_splice($verifyList,$m,1,$v);
  4602. }
  4603. }
  4604. }
  4605. $receiptList[$key]['verifyList']=$verifyList;
  4606. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4607. $receiptList[$key]['button']=$button;
  4608. }
  4609. $mothHtml="";
  4610. for($i=1;$i<=12;$i++){
  4611. if($month==$i)
  4612. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4613. else
  4614. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4615. }
  4616. //获取审批日志
  4617. Doo::loadModel('receiptLog');
  4618. $receiptLog=new receiptLog();
  4619. $rlList=array();
  4620. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4621. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4622. if (!empty($rlInfo)){
  4623. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4624. }
  4625. $receiptList[0]['rlList']=$rlList;
  4626. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4627. $enclosurHtml='';
  4628. foreach ($enclosurList as $value){
  4629. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4630. }
  4631. $data['enclosurHtml']=$enclosurHtml;
  4632. $data['rolename']=$rolename['name'];
  4633. $data['datetij']=$tijdate['date'];
  4634. $data['mothHtml']=$mothHtml;
  4635. $data['receiptList']=$receiptList;
  4636. $data['receiptApprovalCount']=count($receiptList);
  4637. $data['year']=$year;
  4638. $data['categoryList']=$categoryList;
  4639. $data['staffList']=$staffList;
  4640. $data['cid']=$cid;
  4641. $data['sid']=$sid;
  4642. $data['status']=0;
  4643. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4644. $ap=4;
  4645. }else
  4646. $data['status']=$receiptList[0]['status'];
  4647. if ($receiptList[0]['status']==4){
  4648. $data['status']=5;
  4649. $ap=0;
  4650. }
  4651. $data['ap']=$ap;
  4652. $data['memu']="receipt";
  4653. $data['staff']=$this->staff;
  4654. $data['receiptMemu']='approval';
  4655. $data['verifyId']=$this->verifyId;
  4656. $data['executeId']=$this->executeId;
  4657. $this->render ( "/admin/saeaReportListReport", $data );
  4658. }
  4659. function approvalEdi(){
  4660. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4661. $status=isset($this->params['status'])?$this->params['status']:'';
  4662. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4663. $month=$this->get_args('month')?$this->get_args('month'):"";
  4664. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4665. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4666. if (empty($status))
  4667. $status=$this->get_args('status')?$this->get_args('status'):2;
  4668. $vidList=array();
  4669. $button=0;
  4670. Doo::loadModel('verify');
  4671. Doo::loadModel('receipt');
  4672. Doo::loadModel('staff');
  4673. $staff=new staff();
  4674. $receipt=new receipt();
  4675. $verify=new verify();
  4676. Doo::loadModel('L_category');
  4677. $Lcategory=new L_category();
  4678. Doo::loadModel('enclosur');
  4679. $enclosur=new enclosur();
  4680. //user verify ID
  4681. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4682. foreach ($verifyDetail as $key=>$value){
  4683. array_push($vidList, $value['vid']);
  4684. }
  4685. $vid=implode(",", $vidList);
  4686. if(empty($verifyDetail))
  4687. $vid=0;
  4688. $categoryList=$Lcategory->find(array('asArray'=>true));
  4689. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4690. $ap="";
  4691. if($status==4){
  4692. $ap=4;$status=2;
  4693. }
  4694. //get Receipt By verifyID status 2
  4695. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4696. $Locate=0;$roleId=0;
  4697. if($ap==4)
  4698. $status=4;
  4699. foreach ($receiptList as $key=>$value){
  4700. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4701. $receiptList[$key]['reviseDetail']=array();
  4702. if (!empty($value['reviseDetail']))
  4703. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4704. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4705. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4706. $receiptList[$key]['category']=$categoryDetil['title'];
  4707. //检测编辑状态
  4708. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4709. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4710. $verifyStaff=json_decode($value['verifyStaff'],true);
  4711. // print_r($verifyList);
  4712. //
  4713. // if (empty($verifyStaff)){
  4714. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4715. // $verifyList[0]['status']=4;$button=4;
  4716. // }
  4717. //
  4718. // }else{
  4719. //
  4720. // }
  4721. // die;
  4722. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4723. // echo array_search("green",$a);
  4724. //
  4725. Doo::loadModel('role');
  4726. $role=new role();
  4727. //print_r($verifyList);
  4728. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4729. foreach ($verifyList as $k=>$v){
  4730. //init verifyStaff
  4731. if ($v[1]=='ROLE'){
  4732. if (!empty($verifyStaff)){
  4733. $endStaffArray=end($verifyStaff);
  4734. if ($v[0]==$endStaffArray['nextStaff']){
  4735. $roleId=$v[0];
  4736. }
  4737. }
  4738. $roleVerify=json_decode($v[3],true);
  4739. $roleKey=$k;$roleArray=array();
  4740. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4741. foreach ($roleVerify as $o=>$p){
  4742. $staffID=explode ('_',$p);
  4743. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4744. //print_r($staffID);
  4745. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4746. array_push($roleArray, $exp);
  4747. }
  4748. $roleArrayCopy[$v[0]]=$roleArray;
  4749. //$verifyList[$k]['roleArray']=$roleArray;
  4750. }
  4751. //print_r($roleArray);
  4752. $verifyList[$k]['date']="";
  4753. $verifyList[$k]['opinion']="";
  4754. $verifyList[$k]['status']="";
  4755. if (empty($verifyStaff)){
  4756. $verifyList[$k]['date']="";
  4757. $verifyList[$k]['opinion']="";
  4758. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4759. $verifyList[$k]['status']=4;
  4760. $button=4;$flag=false;
  4761. }
  4762. }else{
  4763. foreach ($verifyStaff as $m=>$u){
  4764. if ($v[0]==$m){
  4765. $verifyList[$k]['date']=$u['date'];
  4766. $verifyList[$k]['opinion']=$u['opinion'];
  4767. $verifyList[$k]['status']=$u['status'];
  4768. $flag=false;
  4769. break;
  4770. }
  4771. }
  4772. $endStaffArray=end($verifyStaff);
  4773. if (isset($endStaffArray['ROLE'])){
  4774. }else{
  4775. $endKey=key($verifyStaff);
  4776. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4777. $button=4;
  4778. $verifyList[$k]['status']=4;
  4779. }
  4780. }
  4781. //print_r($endStaffArray);die;
  4782. // if (empty($verifyStaff)){
  4783. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4784. // $verifyList[$k]['status']=4;$button=4;
  4785. // }
  4786. //
  4787. // }else{
  4788. //
  4789. // }
  4790. // if($flag){//检测可编辑
  4791. // if($v[0]==$this->staff[0]['sid']){
  4792. // $verifyList[$k]['status']=4;$button=4;
  4793. // }
  4794. // }
  4795. }
  4796. }
  4797. $rolename['name']='';
  4798. if (!empty($roleId)){
  4799. Doo::loadModel('role');
  4800. $role=new role();
  4801. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4802. }
  4803. if (!empty($verifyStaff))
  4804. $endStaffArray=end($verifyStaff);
  4805. $KOP=false;
  4806. foreach ($roleArrayCopy as $P=>$A){
  4807. foreach ( $A as $MKI=>$AVL){
  4808. if (!empty($verifyStaff)){
  4809. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4810. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4811. $button=4;
  4812. $roleArrayCopy[$P][$MKI]['status']=4;
  4813. }
  4814. foreach ($verifyStaff as $m=>$u){
  4815. $AVLFK=$AVL[0].'_R';
  4816. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4817. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4818. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4819. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4820. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4821. break;
  4822. }
  4823. }
  4824. }else{
  4825. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4826. $button=4;
  4827. $roleArrayCopy[$P][$MKI]['status']=4;
  4828. }
  4829. }
  4830. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4831. $KOP=true;
  4832. }
  4833. }
  4834. // print_r($roleArrayCopy);
  4835. // echo $roleKey;
  4836. foreach ($roleArrayCopy as $k=>$v){
  4837. foreach ($verifyList as $m=>$n){
  4838. if ($n[0]==$k){
  4839. array_splice($verifyList,$m,1,$v);
  4840. }
  4841. }
  4842. }
  4843. // if ($KOP)
  4844. // array_splice($verifyList,$roleKey,1,$roleArray);
  4845. //print_r($verifyList);
  4846. $receiptList[$key]['verifyList']=$verifyList;
  4847. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4848. $receiptList[$key]['button']=$button;
  4849. }
  4850. //$data['verifyDetail']=$verifyDetail;
  4851. $mothHtml="";
  4852. for($i=1;$i<=12;$i++){
  4853. if($month==$i)
  4854. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4855. else
  4856. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4857. }
  4858. //获取审批日志
  4859. Doo::loadModel('receiptLog');
  4860. $receiptLog=new receiptLog();
  4861. $rlList=array();
  4862. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4863. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4864. if (!empty($rlInfo)){
  4865. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4866. }
  4867. $receiptList[0]['rlList']=$rlList;
  4868. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4869. $enclosurHtml='';
  4870. foreach ($enclosurList as $value){
  4871. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4872. }
  4873. $data['enclosurHtml']=$enclosurHtml;
  4874. $data['rolename']=$rolename['name'];
  4875. $data['datetij']=$tijdate['date'];
  4876. $data['mothHtml']=$mothHtml;
  4877. $data['receiptList']=$receiptList;
  4878. $data['receiptApprovalCount']=count($receiptList);
  4879. $data['status']=$status;
  4880. $data['year']=$year;
  4881. $data['categoryList']=$categoryList;
  4882. $data['staffList']=$staffList;
  4883. $data['cid']=$cid;
  4884. $data['sid']=$sid;
  4885. $data['ap']=$ap;
  4886. $data['memu']="receipt";
  4887. $data['staff']=$this->staff;
  4888. $data['receiptMemu']='approval';
  4889. $data['verifyId']=$this->verifyId;
  4890. $data['executeId']=$this->executeId;
  4891. $this->render ( "/admin/saeaReportListReport", $data );
  4892. }
  4893. function remittance(){
  4894. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4895. $month=$this->get_args('month')?$this->get_args('month'):"";
  4896. Doo::loadModel('receipt');
  4897. $receipt=new receipt();
  4898. Doo::loadModel('staff');
  4899. $staff=new staff();
  4900. $dateCondition=" and Year(pastDate) =".$year;
  4901. if(!empty($month))
  4902. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4903. //get Receipt By verifyID status 1
  4904. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4905. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4906. $dataList=array();
  4907. foreach ($dateList as $d=>$a){
  4908. $dataList[$a['pastDate']]=array();$daySum=0;
  4909. foreach ($receiptList as $key=>$value){
  4910. if($a['pastDate']==$value['pastDate']){
  4911. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4912. $list=array();$html="";
  4913. foreach ($oderList as $v){
  4914. array_push($list, $v['receiptOrder']);
  4915. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4916. }
  4917. $receiptList[$key]['receiptOrder']=$html;
  4918. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4919. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4920. $receiptList[$key]['username']=$sinfo['username'];
  4921. $daySum+=$value['sum'];
  4922. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4923. }
  4924. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4925. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4926. }
  4927. }
  4928. //print_r($dataList);
  4929. $data['dataList']=$dataList;
  4930. $mothHtml="";
  4931. for($i=1;$i<=12;$i++){
  4932. if($month==$i)
  4933. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4934. else
  4935. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4936. }
  4937. $data['year']=$year;
  4938. $data['mothHtml']=$mothHtml;
  4939. $data['memu']="receipt";
  4940. $data['staff']=$this->staff;
  4941. $data['receiptMemu']='approval';
  4942. $data['verifyId']=$this->verifyId;
  4943. $data['executeId']=$this->executeId;
  4944. $this->render ( "/admin/saeaReportListPay", $data );
  4945. }
  4946. function revocationAdjustment(){
  4947. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  4948. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  4949. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4950. //echo $price;die;
  4951. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  4952. Doo::loadModel('receipt');
  4953. $receipt=new receipt();
  4954. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4955. if (empty($receiptDetail['reviseDetail']))
  4956. return "/approval";
  4957. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  4958. $RD=array();
  4959. foreach ($reviseDetail as $key=>$value){
  4960. if ($value['price']==$price&&$value['sid']==$sid)
  4961. continue;
  4962. array_push($RD, $value);
  4963. }
  4964. $reviseDetailString=json_encode($RD);
  4965. $receipt->reviseDetail=$reviseDetailString;
  4966. $receipt->sum=$receiptDetail['sum']-$price;
  4967. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  4968. $receipt->update(array('where'=>'rid='.$rid));
  4969. }
  4970. //approvalEdi/37
  4971. return "/approvalEdi/".$rid;
  4972. }
  4973. function updateApprovalReceipt(){
  4974. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  4975. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  4976. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4977. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  4978. if(!empty($rid)){
  4979. Doo::loadModel("verify");
  4980. $verify=new verify();
  4981. Doo::loadModel("receiptDetail");
  4982. $receiptDetailObj=new receiptDetail();
  4983. Doo::loadModel("itemStatistics");
  4984. Doo::loadModel("statistics");
  4985. $statistics=new statistics();
  4986. $itemStatistics=new itemStatistics();
  4987. Doo::loadModel("receipt");
  4988. $receipt=new receipt();
  4989. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  4990. if (empty($receiptDetail))
  4991. return "/approval";
  4992. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  4993. $verifyString=$verifyDetail['staff'];
  4994. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4995. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  4996. if(empty($opinion)){
  4997. if ($status==3)
  4998. $opinion="终止";
  4999. else
  5000. $opinion="同意支付";
  5001. }
  5002. $nowStaff=0;$nowStaffList=array();
  5003. if(empty($verifyStaff)){
  5004. //还需加入是否已经进入角色审批
  5005. if ($verifyDetail[0][1]=='ROLE'){
  5006. $vStaffString=json_decode($verifyDetail[0][3]);
  5007. foreach ($vStaffString as $key=>$value){
  5008. $staffK=explode("_", $value);
  5009. if ($staffK[0]!=$this->staff[0]['sid'])
  5010. array_push($nowStaffList, $staffK[0]);
  5011. }
  5012. //print_r($verifyDetail);
  5013. //die;
  5014. if (!empty($nowStaffList)){
  5015. $nowStaff=implode(',', $nowStaffList);
  5016. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5017. }else{
  5018. $nowStaff=$verifyDetail[1][0];
  5019. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5020. }
  5021. }else{
  5022. if ($verifyDetail[1][1]=='ROLE'){
  5023. $vStaffString=json_decode($verifyDetail[1][3]);
  5024. //echo "dd";
  5025. foreach ($vStaffString as $key=>$value){
  5026. $staffK=explode("_", $value);
  5027. array_push($nowStaffList, $staffK[0]);
  5028. }
  5029. $nowStaff=implode(',', $nowStaffList);
  5030. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5031. }else{
  5032. $nowStaff=$verifyDetail[1][0];
  5033. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5034. }
  5035. }
  5036. if($status==3)
  5037. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5038. $vStaffString=json_encode($verifyStaff);
  5039. $receipt->nowStaff=$nowStaff;
  5040. $receipt->verifyStaff=$vStaffString;
  5041. }else{
  5042. $VS=end($verifyStaff);
  5043. //非角色审批
  5044. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5045. $nextStaff=0;$roleSTF=false;
  5046. foreach ($verifyDetail as $key=>$value){
  5047. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5048. if (isset($verifyDetail[$key+1])){
  5049. $nextStaff=$verifyDetail[$key+1][0];
  5050. if ($verifyDetail[$key+1][1]=='ROLE')
  5051. $roleSTF=true;
  5052. }
  5053. break;
  5054. }
  5055. }
  5056. if (!$roleSTF){
  5057. $nowStaff=$nextStaff;
  5058. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5059. }else{
  5060. //获取角色下的所有用户ID
  5061. $nowStaffList=array();
  5062. foreach ($verifyDetail as $vfk){
  5063. if ($vfk[1]=='ROLE'){
  5064. $vStaffString=json_decode($vfk[3]);
  5065. foreach ($vStaffString as $key=>$value){
  5066. $staffK=explode("_", $value);
  5067. array_push($nowStaffList, $staffK[0]);
  5068. }
  5069. }
  5070. }
  5071. $nowStaff=implode(',', $nowStaffList);
  5072. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5073. }
  5074. if($status==3){
  5075. $verifyStaff['final']=$status;
  5076. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5077. }
  5078. $vStaffString=json_encode($verifyStaff);
  5079. $receipt->nowStaff=$nowStaff;
  5080. $receipt->verifyStaff=$vStaffString;
  5081. }
  5082. //角色审批
  5083. if (isset($VS['ROLE'])){
  5084. //找出角色人 当前审批角色组
  5085. $verifyJSStaff=array();$nowStaffList2=array();
  5086. foreach ($verifyDetail as $key=>$value){
  5087. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5088. $verifyJSStaff=json_decode($value[3]);
  5089. foreach ($verifyJSStaff as $m){
  5090. $staffK=explode("_", $m);
  5091. array_push($nowStaffList2, $staffK[0]);
  5092. }
  5093. // print_r($nowStaffList2);
  5094. }
  5095. }
  5096. $RoleVerifyStaff=array();
  5097. foreach ($verifyStaff as $key=>$value){
  5098. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5099. foreach ($nowStaffList2 as $m) {
  5100. if ($key==$m."_R")
  5101. $RoleVerifyStaff[$key]=$value;
  5102. }
  5103. }
  5104. }
  5105. // print_r($verifyStaff);
  5106. // print_r($nowStaffList2);
  5107. // print_r($RoleVerifyStaff);
  5108. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5109. //print_r($verifyJSStaff);
  5110. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5111. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5112. //下一个审批人ID
  5113. $nextStaff=0;$falg=false;
  5114. foreach ($verifyDetail as $key=>$value){
  5115. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5116. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5117. $falg=true;
  5118. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5119. foreach ($vStaffString as $v){
  5120. $staffK=explode("_", $v);
  5121. array_push($nowStaffList, $staffK[0]);
  5122. }
  5123. $nowStaff=implode(',', $nowStaffList);
  5124. $nextStaff=$verifyDetail[$key+1][0];
  5125. }elseif(isset($verifyDetail[$key+1])){
  5126. $nextStaff=$verifyDetail[$key+1][0];
  5127. $nowStaff=$nextStaff;
  5128. }else
  5129. $nowStaff='';
  5130. break;
  5131. }
  5132. }
  5133. if ($falg)
  5134. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5135. else
  5136. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5137. // print_r($verifyStaff);
  5138. // echo $nowStaff;die;
  5139. }else{ //进入下一个角色或者审批人
  5140. /*
  5141. */
  5142. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5143. //
  5144. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5145. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5146. // print_r($verifyStaff);
  5147. // die;
  5148. }
  5149. if($status==3){
  5150. $verifyStaff['final']=$status;
  5151. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5152. }
  5153. $vStaffString=json_encode($verifyStaff);
  5154. $receipt->verifyStaff=$vStaffString;
  5155. $receipt->nowStaff=$nowStaff;
  5156. //die;
  5157. //}
  5158. // print_r($verifyStaff);
  5159. // die;
  5160. }
  5161. //print_r($verifyStaff);die;
  5162. }
  5163. //print_r($verifyDetail);
  5164. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5165. foreach ($verifyDetail as $k=>$v){
  5166. if ($v[1]=='ROLE'){
  5167. $roleId=$v[0];
  5168. $roleVerify=json_decode($v[3],true);
  5169. $roleKey=$k;$roleArray=array();
  5170. foreach ($roleVerify as $o=>$p){
  5171. $staffID=explode ('_',$p);
  5172. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5173. array_push($roleArray, $exp);
  5174. }
  5175. $verifyDetailCopy[$v[0]]=$roleArray;
  5176. }
  5177. }
  5178. //print_r($verifyDetail);
  5179. foreach ($verifyDetailCopy as $k=>$v){
  5180. foreach ($verifyDetail as $m=>$n){
  5181. if ($n[0]==$k){
  5182. array_splice($verifyDetail,$m,1,$v);
  5183. }
  5184. }
  5185. }
  5186. // die;
  5187. // if (!empty($roleArray))
  5188. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5189. // echo $roleId;
  5190. // print_r($verifyStaff);
  5191. // print_r($verifyDetail);
  5192. // die;
  5193. Doo::loadModel("receiptLog");
  5194. $receiptLog=new receiptLog();
  5195. //审批日志
  5196. if (!isset($verifyStaff['final'])){
  5197. if (!empty($roleId)){
  5198. Doo::loadModel("role");
  5199. $role=new role();
  5200. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5201. $receiptLog->rolename=$roleInfo['name'];
  5202. }
  5203. $receiptLog->username=$this->staff[0]['username'];
  5204. $receiptLog->uid=$this->staff[0]['sid'];
  5205. $receiptLog->date=date("Y-m-d");
  5206. $receiptLog->opinion=$opinion;
  5207. $receiptLog->img=$this->staff[0]['avatar'];
  5208. $receiptLog->status=1;
  5209. $receiptLog->rid=$rid;
  5210. $receiptLog->insert();
  5211. }
  5212. if (isset($verifyStaff['final'])){//rDetail
  5213. $receipt->verifyBreakup=$verifyString;
  5214. $receipt->status=3;
  5215. $receiptDetailObj->status=3;
  5216. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5217. if (!empty($roleId)){
  5218. Doo::loadModel("role");
  5219. $role=new role();
  5220. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5221. $receiptLog->rolename=$roleInfo['name'];
  5222. }
  5223. $receiptLog->username=$this->staff[0]['username'];
  5224. $receiptLog->uid=$this->staff[0]['sid'];
  5225. $receiptLog->date=date("Y-m-d");
  5226. $receiptLog->opinion=$opinion;
  5227. $receiptLog->img=$this->staff[0]['avatar'];
  5228. $receiptLog->status=3;
  5229. $receiptLog->rid=$rid;
  5230. $receiptLog->insert();
  5231. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5232. $receipt->status=1;$reviseSum=0;
  5233. $receipt->verifyBreakup=$verifyString;
  5234. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5235. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5236. foreach ($reviseDetail as $key=>$value){
  5237. $receiptDetailObj=new receiptDetail();
  5238. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5239. $receiptDetailObj->item=$value['description'];
  5240. $receiptDetailObj->itemCategory="报销金额调整";
  5241. $receiptDetailObj->price=$value['price'];
  5242. $receiptDetailObj->date=$receiptDetail['date'];
  5243. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5244. $receiptDetailObj->rid=$rid;
  5245. $receiptDetailObj->status=1;
  5246. $receiptDetailObj->insert();
  5247. $reviseSum+=$value['price'];
  5248. }
  5249. $itemStatistics=new itemStatistics();
  5250. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5251. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5252. $itemStatistics->price=$reviseSum;
  5253. $itemStatistics->itemCategory="报销金额调整";
  5254. $itemStatistics->date=$receiptDetail['date'];
  5255. $itemStatistics->insert();
  5256. }
  5257. $receiptDetailObj=new receiptDetail();
  5258. $receiptDetailObj->status=1;
  5259. $receiptDetailObj->pastDate=date("Y-m-d");
  5260. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5261. $dateArray=explode("-", $receiptDetail['date']);
  5262. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5263. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5264. if(empty($stat)){
  5265. $statistics->date=$receiptDetail['date'];
  5266. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5267. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5268. $statistics->agPrice=$receiptDetail['sum'];
  5269. $statistics->rePrice=$reviseSum;
  5270. $statistics->insert();
  5271. }else{
  5272. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5273. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5274. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5275. }
  5276. $dateArray=explode("-", $receiptDetail['date']);
  5277. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5278. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5279. foreach ($accountItem['cSum'] as $key=>$value){
  5280. if($key=="agencySum"){
  5281. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5282. if(empty($iStatistics)){
  5283. $itemStatistics->cid=$receiptDetail['cid'];;
  5284. $itemStatistics->staff=$receiptDetail['staff'];
  5285. $itemStatistics->price=$value;
  5286. $itemStatistics->itemCategory=$this->AGENCY;
  5287. $itemStatistics->date=$receiptDetail['date'];
  5288. $itemStatistics->insert();
  5289. }else{
  5290. if (!empty($value)){
  5291. $itemStatistics->price=$value+$iStatistics['price'];
  5292. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5293. }
  5294. }
  5295. }elseif($key=="travelSum"){
  5296. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5297. if(empty($iStatistics)){
  5298. $itemStatistics->cid=$receiptDetail['cid'];
  5299. $itemStatistics->staff=$receiptDetail['staff'];
  5300. $itemStatistics->price=$value;
  5301. $itemStatistics->itemCategory=$this->TRAVEL;
  5302. $itemStatistics->date=$receiptDetail['date'];
  5303. $itemStatistics->insert();
  5304. }else{
  5305. if (!empty($value)){
  5306. $itemStatistics->price=$value+$iStatistics['price'];
  5307. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5308. }
  5309. }
  5310. }elseif($key=="trainSum"){
  5311. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5312. if(empty($iStatistics)){
  5313. $itemStatistics->cid=$receiptDetail['cid'];
  5314. $itemStatistics->staff=$receiptDetail['staff'];
  5315. $itemStatistics->price=$value;
  5316. $itemStatistics->itemCategory=$this->TRAIN;
  5317. $itemStatistics->date=$receiptDetail['date'];
  5318. $itemStatistics->insert();
  5319. }else{
  5320. if (!empty($value)){
  5321. $itemStatistics->price=$value+$iStatistics['price'];
  5322. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5323. }
  5324. }
  5325. }elseif($key=="otherSum"){
  5326. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5327. if(empty($iStatistics)){
  5328. $itemStatistics->cid=$receiptDetail['cid'];
  5329. $itemStatistics->staff=$receiptDetail['staff'];
  5330. $itemStatistics->price=$value;
  5331. $itemStatistics->itemCategory=$this->OTHER;
  5332. $itemStatistics->date=$receiptDetail['date'];
  5333. $itemStatistics->insert();
  5334. }else{
  5335. if (!empty($value)){
  5336. $itemStatistics->price=$value+$iStatistics['price'];
  5337. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5338. }
  5339. }
  5340. }
  5341. }
  5342. $receipt->pastDate=date("Y-m-d");
  5343. }
  5344. $receipt->update(array('where'=>' rid = '.$rid));
  5345. return "/approvalExpenses/2";
  5346. }
  5347. }
  5348. function expensesRetreats(){
  5349. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5350. if (!empty($rid)){
  5351. //操作记录
  5352. Doo::loadModel("receipt");
  5353. $receipt=new receipt();
  5354. Doo::loadModel("receiptLog");
  5355. $receiptLog=new receiptLog();
  5356. Doo::loadModel("verify");
  5357. $verify=new verify();
  5358. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5359. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5360. $jd=json_decode($vr['staff']);$roleId=0;
  5361. foreach ($jd as $key=>$value){
  5362. if ($value[1]=='ROLE'){
  5363. $pos = strpos($value[3], $this->staff[0]['sid']);
  5364. if ($pos !== false) {
  5365. $roleId=$value[0];
  5366. }
  5367. }
  5368. }
  5369. //审批日志
  5370. //echo $roleId;die;
  5371. if (!empty($roleId)){
  5372. Doo::loadModel("role");
  5373. $role=new role();
  5374. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5375. $receiptLog->rolename=$roleInfo['name'];
  5376. }
  5377. $receiptLog->username=$this->staff[0]['username'];
  5378. $receiptLog->uid=$this->staff[0]['sid'];
  5379. $receiptLog->date=date("Y-m-d");
  5380. $receiptLog->opinion='撤回';
  5381. $receiptLog->img=$this->staff[0]['avatar'];
  5382. $receiptLog->status=4;
  5383. $receiptLog->rid=$rid;
  5384. $receiptLog->insert();
  5385. $receipt->status=4;
  5386. $receipt->update(array('where'=>'rid='.$rid));
  5387. }
  5388. //echo "ddd";
  5389. return '/approvalExpenses';
  5390. }
  5391. function updateCheReceipt(){
  5392. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5393. if (!empty($rid)){
  5394. //操作记录
  5395. Doo::loadModel("receipt");
  5396. $receipt=new receipt();
  5397. Doo::loadModel("receiptLog");
  5398. $receiptLog=new receiptLog();
  5399. Doo::loadModel("verify");
  5400. $verify=new verify();
  5401. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5402. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5403. $jd=json_decode($vr['staff']);$roleId=0;
  5404. foreach ($jd as $key=>$value){
  5405. if ($value[1]=='ROLE'){
  5406. $pos = strpos($value[3], $this->staff[0]['sid']);
  5407. if ($pos !== false) {
  5408. $roleId=$value[0];
  5409. }
  5410. }
  5411. }
  5412. //审批日志
  5413. //echo $roleId;die;
  5414. if (!empty($roleId)){
  5415. Doo::loadModel("role");
  5416. $role=new role();
  5417. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5418. $receiptLog->rolename=$roleInfo['name'];
  5419. }
  5420. $receiptLog->username=$this->staff[0]['username'];
  5421. $receiptLog->uid=$this->staff[0]['sid'];
  5422. $receiptLog->date=date("Y-m-d");
  5423. $receiptLog->opinion='撤回';
  5424. $receiptLog->img=$this->staff[0]['avatar'];
  5425. $receiptLog->status=4;
  5426. $receiptLog->rid=$rid;
  5427. $receiptLog->insert();
  5428. $receipt->status=4;
  5429. $receipt->update(array('where'=>'rid='.$rid));
  5430. }
  5431. //echo "ddd";
  5432. return '/saeaBorad';
  5433. }
  5434. function revisePrice(){
  5435. $description=$this->get_args('description')?$this->get_args('description'):"";
  5436. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5437. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5438. //echo $price;die;
  5439. if (!empty($rid)){
  5440. Doo::loadModel("receipt");
  5441. $receipt=new receipt();
  5442. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5443. if (empty($receiptDetail))
  5444. return "/approval";
  5445. $reviseDetail=array();
  5446. if (empty($receiptDetail['reviseDetail'])){
  5447. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5448. $reviseDetailString=json_encode($reviseDetail);
  5449. $receipt->reviseDetail=$reviseDetailString;
  5450. $receipt->revisePrice=$price;
  5451. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5452. }else{
  5453. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5454. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5455. $reviseDetailString=json_encode($reviseDetail);
  5456. $receipt->reviseDetail=$reviseDetailString;
  5457. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5458. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5459. }
  5460. $receipt->update(array('where'=>'rid='.$rid));
  5461. }
  5462. return '/approvalEdi/'.$rid;
  5463. }
  5464. function personalCollect(){
  5465. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5466. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5467. $this->showCache($path);
  5468. Doo::loadModel("receiptDetail");
  5469. Doo::loadModel("itemStatistics");
  5470. Doo::loadModel('statistics');
  5471. $statistics=new statistics();
  5472. $itemStatistics=new itemStatistics();
  5473. $receiptDetail=new receiptDetail();
  5474. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5475. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5476. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5477. //create collect html
  5478. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5479. $adjustment=array();
  5480. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5481. array_push($collectArray['日常相关费用'], $collectHtml);
  5482. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5483. array_push($collectArray['差旅相关费用'], $collectHtml);
  5484. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5485. array_push($collectArray['培训班费用'], $collectHtml);
  5486. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5487. array_push($collectArray['其他'], $collectHtml);
  5488. $data['collectArray']=$collectArray;
  5489. //statistics html
  5490. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5491. if(empty($stList))
  5492. $stList=array('rePrice'=>0,'agPrice'=>0);
  5493. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5494. //Adjustment price html
  5495. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5496. array_push($adjustment, $collectHtml);
  5497. $data['adjustment']=$adjustment;
  5498. //total price html
  5499. $collectHtml="";$total=0;
  5500. for ($i=1;$i<=12;$i++){
  5501. $sumPrice=0;
  5502. foreach ($receiptCollectList as $key=>$value){
  5503. if($value['month']==$i){
  5504. $sumPrice+=$value['price'];
  5505. }
  5506. }
  5507. if ($sumPrice==0)
  5508. $collectHtml.='<td class="taR">-</td>';
  5509. else
  5510. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5511. $total+=$sumPrice;
  5512. }
  5513. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5514. $data['totalPrice']=$collectHtml;
  5515. $data['year']=$year;
  5516. $data['totalYear']=$total;
  5517. $data['memu']="receipt";
  5518. $data['staff']=$this->staff;
  5519. $data['receiptMemu']='personalCollect';
  5520. $data['verifyId']=$this->verifyId;
  5521. $data['executeId']=$this->executeId;
  5522. //year staff status 2,4
  5523. if($year<date("Y")){
  5524. Doo::loadModel('receipt');
  5525. $receipt=new receipt();
  5526. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5527. if(empty($receiptList)){
  5528. ob_start();
  5529. $this->render ( "/admin/saea_slist_collect", $data );
  5530. $this->cacheFile($path);die;
  5531. }
  5532. }
  5533. $this->render ( "/admin/saea_slist_collect", $data );
  5534. }
  5535. function personalCollectDetail(){
  5536. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5537. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5538. $this->showCache($path);
  5539. Doo::loadModel("receiptDetail");
  5540. Doo::loadModel("itemStatistics");
  5541. Doo::loadModel('statistics');
  5542. Doo::loadModel('accountItem');
  5543. $accountItem=new accountItem();
  5544. $statistics=new statistics();
  5545. $itemStatistics=new itemStatistics();
  5546. $receiptDetail=new receiptDetail();
  5547. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5548. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5549. $accountList=$accountItem->find(array('asArray'=>true));
  5550. //create CollectDetail HTML
  5551. $collectHtml=array();
  5552. foreach ($accountList as $key=>$value){
  5553. $html="";$asum=0;
  5554. for ($i=1;$i<=12;$i++){
  5555. $falg=true;
  5556. foreach ($receiptCollectList as $v) {
  5557. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5558. $asum+=$v['price'];
  5559. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5560. }
  5561. }
  5562. if($falg)
  5563. $html.='<td class="taR">-</td>';
  5564. }
  5565. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5566. $collectHtml[$value['category']][$value['name']]=$html;
  5567. }
  5568. $data['collectHtml']=$collectHtml;
  5569. //create Adjustment price html
  5570. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5571. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5572. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5573. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5574. array_push($collectArray['日常相关费用'], $collectHtml);
  5575. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5576. array_push($collectArray['差旅相关费用'], $collectHtml);
  5577. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5578. array_push($collectArray['培训班费用'], $collectHtml);
  5579. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5580. array_push($collectArray['其他'], $collectHtml);
  5581. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5582. array_push($adjustment, $collectHtml);
  5583. //total price html
  5584. $collectHtml="";$total=0;
  5585. for ($i=1;$i<=12;$i++){
  5586. $sumPrice=0;
  5587. foreach ($receiptCollectList as $key=>$value){
  5588. if($value['month']==$i){
  5589. $sumPrice+=$value['price'];
  5590. }
  5591. }
  5592. if ($sumPrice==0)
  5593. $collectHtml.='<td class="taR">-</td>';
  5594. else
  5595. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5596. $total+=$sumPrice;
  5597. }
  5598. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5599. //statistics html
  5600. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5601. if(empty($stList))
  5602. $stList=array('rePrice'=>0,'agPrice'=>0);
  5603. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5604. $data['collectArray']=$collectArray;
  5605. $data['adjustment']=$adjustment;
  5606. $data['totalPrice']=$collectHtml;
  5607. $data['totalYear']=$total;
  5608. $data['year']=$year;
  5609. $data['memu']="receipt";
  5610. $data['staff']=$this->staff;
  5611. $data['receiptMemu']='personalCollect';
  5612. $data['verifyId']=$this->verifyId;
  5613. $data['executeId']=$this->executeId;
  5614. //year staff status 2,4
  5615. if($year<date("Y")){
  5616. Doo::loadModel('receipt');
  5617. $receipt=new receipt();
  5618. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5619. if(empty($receiptList)){
  5620. ob_start();
  5621. $this->render ( "/admin/saeaCollectArticles", $data );
  5622. $this->cacheFile($path);die;
  5623. }
  5624. }
  5625. $this->render ( "/admin/saeaCollectArticles", $data );
  5626. }
  5627. function companyCategoryCollect(){
  5628. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5629. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5630. $this->showCache($path);
  5631. Doo::loadModel('L_category');
  5632. Doo::loadModel('itemStatistics');
  5633. Doo::loadModel('statistics');
  5634. $statistics=new statistics();
  5635. $Lcategory=new L_category();
  5636. $itemStatistics=new itemStatistics();
  5637. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5638. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5639. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5640. //ceatre companyCollectHtml
  5641. foreach ($LcategoryList as $value){
  5642. $html="";$asum=0;
  5643. for ($i=1;$i<=12;$i++){
  5644. $falg=true;
  5645. foreach ($itemStatisticsList as $v){
  5646. if($value['cid']==$v['cid']&&$i==$v['month']){
  5647. $asum+=$v['price'];
  5648. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5649. }
  5650. }
  5651. if($falg)
  5652. $html.='<td class="taR">-</td>';
  5653. }
  5654. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5655. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5656. }
  5657. $data['companyHtml']=$collectHtml;
  5658. //total price html
  5659. $collectHtml="";$total=0;
  5660. for ($i=1;$i<=12;$i++){
  5661. $sumPrice=0;
  5662. foreach ($itemStatisticsList as $key=>$value){
  5663. if($value['month']==$i){
  5664. $sumPrice+=$value['price'];
  5665. }
  5666. }
  5667. if ($sumPrice==0)
  5668. $collectHtml.='<td class="taR">-</td>';
  5669. else
  5670. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5671. $total+=$sumPrice;
  5672. }
  5673. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5674. $data['companyTotalHtml']=$collectHtml;
  5675. $data['total']=$total;
  5676. //statistics html
  5677. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5678. if(empty($stList))
  5679. $stList=array('rePrice'=>0,'agPrice'=>0);
  5680. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5681. $data['year']=$year;
  5682. $data['memu']="receipt";
  5683. $data['staff']=$this->staff;
  5684. $data['receiptMemu']='companyCategoryCollect';
  5685. $data['verifyId']=$this->verifyId;
  5686. $data['executeId']=$this->executeId;
  5687. //year staff status 2,4
  5688. if($year<date("Y")){
  5689. Doo::loadModel('receipt');
  5690. $receipt=new receipt();
  5691. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5692. if(empty($receiptList)){
  5693. ob_start();
  5694. $this->render ( "/admin/saeaCompanyCollect", $data );
  5695. $this->cacheFile($path);die;
  5696. }
  5697. }
  5698. $this->render ( "/admin/saeaCompanyCollect", $data );
  5699. }
  5700. function categoryCollectDetail(){
  5701. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5702. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5703. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5704. $this->showCache($path);
  5705. Doo::loadModel('statistics');
  5706. $statistics=new statistics();
  5707. Doo::loadModel("receiptDetail");
  5708. $receiptDetail=new receiptDetail();
  5709. Doo::loadModel('L_category');
  5710. $Lcategory=new L_category();
  5711. Doo::loadModel('accountItem');
  5712. $accountItem=new accountItem();
  5713. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5714. if ($cid==0){
  5715. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5716. if ($cid==0)
  5717. $cid=$LcategoryList[0]['cid'];
  5718. }
  5719. $data['LcategoryList']=$LcategoryList;
  5720. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5721. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5722. $accountList=$accountItem->find(array('asArray'=>true));
  5723. //create CollectDetail HTML
  5724. $collectHtml=array();
  5725. foreach ($accountList as $key=>$value){
  5726. $html="";$asum=0;
  5727. for ($i=1;$i<=12;$i++){
  5728. $falg=true;
  5729. foreach ($receiptCollectList as $v) {
  5730. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5731. $asum+=$v['price'];
  5732. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5733. }
  5734. }
  5735. if($falg)
  5736. $html.='<td class="taR">-</td>';
  5737. }
  5738. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5739. $collectHtml[$value['category']][$value['name']]=$html;
  5740. }
  5741. $data['collectHtml']=$collectHtml;
  5742. //create Adjustment price html
  5743. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5744. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5745. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5746. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5747. array_push($collectArray['日常相关费用'], $collectHtml);
  5748. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5749. array_push($collectArray['差旅相关费用'], $collectHtml);
  5750. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5751. array_push($collectArray['培训班费用'], $collectHtml);
  5752. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5753. array_push($collectArray['其他'], $collectHtml);
  5754. $data['collectArray']=$collectArray;
  5755. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5756. array_push($adjustment, $collectHtml);
  5757. $data['adjustment']=$adjustment;
  5758. //total price html
  5759. $collectHtml="";$total=0;
  5760. for ($i=1;$i<=12;$i++){
  5761. $sumPrice=0;
  5762. foreach ($receiptCollectList as $key=>$value){
  5763. if($value['month']==$i){
  5764. $sumPrice+=$value['price'];
  5765. }
  5766. }
  5767. if ($sumPrice==0)
  5768. $collectHtml.='<td class="taR">-</td>';
  5769. else
  5770. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5771. $total+=$sumPrice;
  5772. }
  5773. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5774. //statistics html
  5775. $stList=$statistics->statisticsByCid($year,$cid);
  5776. if(empty($stList))
  5777. $stList=array('rePrice'=>0,'agPrice'=>0);
  5778. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5779. $data['totalYear']=$total;
  5780. $data['year']=$year;
  5781. $data['cid']=$cid;
  5782. $data['memu']="receipt";
  5783. $data['staff']=$this->staff;
  5784. $data['receiptMemu']='companyCategoryCollect';
  5785. $data['verifyId']=$this->verifyId;
  5786. $data['executeId']=$this->executeId;
  5787. //year staff status 2,4
  5788. if($year<date("Y")){
  5789. Doo::loadModel('receipt');
  5790. $receipt=new receipt();
  5791. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5792. if(empty($receiptList)){
  5793. ob_start();
  5794. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5795. $this->cacheFile($path);die;
  5796. }
  5797. }
  5798. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5799. }
  5800. function staffCollect(){
  5801. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5802. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5803. //$this->showCache($path);
  5804. Doo::loadModel('statistics');
  5805. $statistics=new statistics();
  5806. Doo::loadModel("receiptDetail");
  5807. $receiptDetail=new receiptDetail();
  5808. Doo::loadModel('L_category');
  5809. $Lcategory=new L_category();
  5810. Doo::loadModel('accountItem');
  5811. $accountItem=new accountItem();
  5812. Doo::loadModel('staff');
  5813. $staff=new staff();
  5814. Doo::loadModel('itemStatistics');
  5815. $itemStatistics=new itemStatistics();
  5816. /*
  5817. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5818. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5819. if(empty($stList))
  5820. $stList=array('rePrice'=>0,'agPrice'=>0);
  5821. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5822. */
  5823. //statistics html
  5824. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5825. if(empty($stList))
  5826. $stList=array('rePrice'=>0,'agPrice'=>0);
  5827. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5828. //---
  5829. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5830. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5831. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5832. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5833. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5834. //print_r($itemStatisticsList);die;
  5835. //ceatre companyCollectHtml
  5836. foreach ($categoryList as $vlu){
  5837. $count=$vlu['count']+1;
  5838. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5839. $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;
  5840. foreach ($staffList as $value){
  5841. if ($vlu['cid']==$value['cid']){
  5842. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5843. $asum=0;
  5844. for ($i=1;$i<=12;$i++){
  5845. $falg=true;
  5846. foreach ($itemStatisticsList as $v){
  5847. if($value['sid']==$v['staff']&&$i==$v['month']){
  5848. if ($v['month']==1)
  5849. $m1+=$v['price'];
  5850. if ($v['month']==2)
  5851. $m2+=$v['price'];
  5852. if ($v['month']==3)
  5853. $m3+=$v['price'];
  5854. if ($v['month']==4)
  5855. $m4+=$v['price'];
  5856. if ($v['month']==5)
  5857. $m5+=$v['price'];
  5858. if ($v['month']==6)
  5859. $m6+=$v['price'];
  5860. if ($v['month']==7)
  5861. $m7+=$v['price'];
  5862. if ($v['month']==8)
  5863. $m8+=$v['price'];
  5864. if ($v['month']==9)
  5865. $m9+=$v['price'];
  5866. if ($v['month']==10)
  5867. $m10+=$v['price'];
  5868. if ($v['month']==11)
  5869. $m11+=$v['price'];
  5870. if ($v['month']==12)
  5871. $m12+=$v['price'];
  5872. $asum+=$v['price'];
  5873. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5874. }
  5875. }
  5876. if($falg)
  5877. $html.='<td class="taR">-</td>';
  5878. }
  5879. $m13+=$asum;
  5880. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5881. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5882. $html="";
  5883. }
  5884. }
  5885. $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>
  5886. <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>
  5887. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5888. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5889. }
  5890. $data['companyHtml']=$collectHtml;
  5891. //total price html
  5892. $collectHtml="";$total=0;
  5893. for ($i=1;$i<=12;$i++){
  5894. $sumPrice=0;
  5895. foreach ($itemStatisticsList as $key=>$value){
  5896. if($value['month']==$i){
  5897. $sumPrice+=$value['price'];
  5898. }
  5899. }
  5900. if ($sumPrice==0)
  5901. $collectHtml.='<td class="taR">-</td>';
  5902. else
  5903. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5904. $total+=$sumPrice;
  5905. }
  5906. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5907. $data['companyTotalHtml']=$collectHtml;
  5908. $data['total']=$total;
  5909. $data['year']=$year;
  5910. $data['memu']="receipt";
  5911. $data['staff']=$this->staff;
  5912. $data['receiptMemu']='companyCategoryCollect';
  5913. $data['verifyId']=$this->verifyId;
  5914. $data['executeId']=$this->executeId;
  5915. if ($year<=date("Y")){
  5916. Doo::loadModel('receipt');
  5917. $receipt=new receipt();
  5918. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5919. if(empty($receiptList)){ //generated files
  5920. ob_start();
  5921. $this->render ( "/admin/saeaStaffCollectB", $data );
  5922. $this->cacheFile($path);die;
  5923. }
  5924. }
  5925. $this->render ( "/admin/saeaStaffCollectB", $data );
  5926. }
  5927. function staffCollectBak(){
  5928. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5929. $month=$this->get_args('month')?$this->get_args('month'):1;
  5930. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  5931. $this->showCache($path);
  5932. Doo::loadModel('statistics');
  5933. $statistics=new statistics();
  5934. Doo::loadModel("receiptDetail");
  5935. $receiptDetail=new receiptDetail();
  5936. Doo::loadModel('L_category');
  5937. $Lcategory=new L_category();
  5938. Doo::loadModel('accountItem');
  5939. $accountItem=new accountItem();
  5940. Doo::loadModel('staff');
  5941. $staff=new staff();
  5942. Doo::loadModel('itemStatistics');
  5943. $itemStatistics=new itemStatistics();
  5944. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5945. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  5946. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5947. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  5948. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5949. $staffList=$staff->find(array('asArray'=>true));
  5950. $htmlArray=array();
  5951. foreach ($LcategoryList as $value){
  5952. $htmlArray[$value['title']]=array();
  5953. foreach ($staffList as $v){
  5954. if($value['cid']==$v['cid']){
  5955. $html="";$falg=true;$staffSumPrice=0;
  5956. foreach ($itemStatisticsList as $a){
  5957. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  5958. if(empty($a['price'])){
  5959. $html.='<td class="taR">-</td>';$falg=false;break;
  5960. }else{
  5961. $staffSumPrice+=$a['price'];
  5962. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5963. }
  5964. }
  5965. }
  5966. if ($falg){
  5967. $html.='<td class="taR">-</td>';$falg=true;
  5968. }
  5969. $falg=true;
  5970. foreach ($itemStatisticsList as $a){
  5971. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  5972. if(empty($a['price'])){
  5973. $html.='<td class="taR">-</td>';$falg=false;break;
  5974. }else{
  5975. $staffSumPrice+=$a['price'];
  5976. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5977. }
  5978. }
  5979. }
  5980. if ($falg){
  5981. $html.='<td class="taR">-</td>';$falg=true;
  5982. }
  5983. $falg=true;
  5984. foreach ($itemStatisticsList as $a){
  5985. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  5986. if(empty($a['price'])){
  5987. $html.='<td class="taR">-</td>';$falg=false;break;
  5988. }else{
  5989. $staffSumPrice+=$a['price'];
  5990. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  5991. }
  5992. }
  5993. }
  5994. if ($falg){
  5995. $html.='<td class="taR">-</td>';$falg=true;
  5996. }
  5997. $falg=true;
  5998. foreach ($itemStatisticsList as $a){
  5999. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6000. if(!empty($a['price'])){
  6001. $staffSumPrice+=$a['price'];
  6002. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6003. }else{
  6004. $html.='<td class="taR">-</td>';$falg=false;break;
  6005. }
  6006. }
  6007. }
  6008. if ($falg){
  6009. $html.='<td class="taR">-</td>';$falg=true;
  6010. }
  6011. $falg=true;
  6012. foreach ($itemStatisticsList as $a){
  6013. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6014. if(!empty($a['price'])){
  6015. $staffSumPrice+=$a['price'];
  6016. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6017. }else{
  6018. $html.='<td class="taR">-</td>';$falg=false;break;
  6019. }
  6020. }
  6021. }
  6022. if ($falg){
  6023. $html.='<td class="taR">-</td>';$falg=true;
  6024. }
  6025. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6026. $htmlArray[$value['title']][$v['username']]=$html;
  6027. }
  6028. }
  6029. /*-- ---*/
  6030. //合计费用
  6031. $cateHtml="";$catePrice=0;$cateFalg=true;
  6032. foreach ($itemCategoryList as $l){
  6033. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6034. if(empty($l['price'])){
  6035. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6036. }else{
  6037. $catePrice+=$l['price'];
  6038. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6039. }
  6040. }
  6041. }
  6042. if ($cateFalg){
  6043. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6044. }
  6045. $cateFalg=true;
  6046. foreach ($itemCategoryList as $l){
  6047. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6048. if(empty($l['price'])){
  6049. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6050. }else{
  6051. $catePrice+=$l['price'];
  6052. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6053. }
  6054. }
  6055. }
  6056. if ($cateFalg){
  6057. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6058. }
  6059. $cateFalg=true;
  6060. foreach ($itemCategoryList as $l){
  6061. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6062. if(empty($l['price'])){
  6063. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6064. }else{
  6065. $catePrice+=$l['price'];
  6066. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6067. }
  6068. }
  6069. }
  6070. if ($cateFalg){
  6071. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6072. }
  6073. $cateFalg=true;
  6074. foreach ($itemCategoryList as $l){
  6075. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6076. if(empty($l['price'])){
  6077. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6078. }else{
  6079. $catePrice+=$l['price'];
  6080. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6081. }
  6082. }
  6083. }
  6084. if ($cateFalg){
  6085. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6086. }
  6087. $cateFalg=true;
  6088. foreach ($itemCategoryList as $l){
  6089. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6090. if(empty($l['price'])){
  6091. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6092. }else{
  6093. $catePrice+=$l['price'];
  6094. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6095. }
  6096. }
  6097. }
  6098. if ($cateFalg){
  6099. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6100. }
  6101. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6102. $htmlArray[$value['title']]['合计']=$cateHtml;
  6103. /*-- ---*/
  6104. }
  6105. //print_r($htmlArray);die;
  6106. $data['htmlArray']=$htmlArray;
  6107. //statistics html
  6108. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6109. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6110. if(empty($stList))
  6111. $stList=array('rePrice'=>0,'agPrice'=>0);
  6112. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6113. $monthHtml="";
  6114. for ($i=1;$i<=12;$i++){
  6115. if ($i==$month)
  6116. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6117. else
  6118. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6119. }
  6120. $data['monthHtml']=$monthHtml;
  6121. $data['year']=$year;
  6122. $data['month']=$month;
  6123. $data['memu']="receipt";
  6124. $data['staff']=$this->staff;
  6125. $data['receiptMemu']='companyCategoryCollect';
  6126. $data['verifyId']=$this->verifyId;
  6127. $data['executeId']=$this->executeId;
  6128. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6129. Doo::loadModel('receipt');
  6130. $receipt=new receipt();
  6131. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6132. if(empty($receiptList)){ //generated files
  6133. ob_start();
  6134. $this->render ( "/admin/saeaStaffCollect", $data );
  6135. $this->cacheFile($path);die;
  6136. }
  6137. }
  6138. $this->render ( "/admin/saeaStaffCollect", $data );
  6139. }
  6140. function lyt(){
  6141. Doo::loadModel("receiptDetail");
  6142. $receiptDetail=new receiptDetail();
  6143. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6144. foreach ($receiptCollectList as $key=>$value){
  6145. $receiptDetail=new receiptDetail();
  6146. $receiptDetail->pastDate=$value['date'];
  6147. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6148. }
  6149. }
  6150. function staffCollectMonthDetail(){
  6151. $year=$this->get_args('year')?$this->get_args('year'):"";
  6152. $month=$this->get_args('month')?$this->get_args('month'):"";
  6153. if(!$year)
  6154. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6155. if(!$month)
  6156. $month=isset($this->params['month'])?$this->params['month']:1;
  6157. Doo::loadModel('staff');
  6158. $staff=new staff();
  6159. Doo::loadModel("receiptDetail");
  6160. $receiptDetail=new receiptDetail();
  6161. Doo::loadModel('accountItem');
  6162. $accountItem=new accountItem();
  6163. Doo::loadModel('statistics');
  6164. $statistics=new statistics();
  6165. Doo::loadModel('L_category');
  6166. $lCategory=new L_category();
  6167. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6168. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6169. $list=array();
  6170. foreach ($categoryList as $vlu){
  6171. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6172. $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;
  6173. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6174. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6175. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6176. $s1=0;
  6177. $m1=0;
  6178. foreach ($staffList as $value){
  6179. if ($vlu['cid']==$value['cid']){
  6180. //pastDate
  6181. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6182. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6183. // if ($value['sid']==42){
  6184. // print_r($receiptCollectList);die;
  6185. // }
  6186. if(!empty($receiptCollectList)){
  6187. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6188. $html="";
  6189. $psum=0;
  6190. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6191. foreach ($item as $va){
  6192. $falg=true;
  6193. foreach ($receiptCollectList as $v){
  6194. if($v['itemCategory']=='日常相关费用'){
  6195. if($v['item']==$va){
  6196. if ($va=='市内交通费')
  6197. $r1+=$v['price'];
  6198. if ($va=='市内出租费')
  6199. $r2+=$v['price'];
  6200. if ($va=='办事处房租')
  6201. $r3+=$v['price'];
  6202. if ($va=='电话费')
  6203. $r4+=$v['price'];
  6204. if ($va=='水费')
  6205. $r5+=$v['price'];
  6206. if ($va=='电费')
  6207. $r6+=$v['price'];
  6208. if ($va=='办公费用')
  6209. $r7+=$v['price'];
  6210. if ($va=='邮寄费')
  6211. $r8+=$v['price'];
  6212. if ($va=='其他费用')
  6213. $r9+=$v['price'];
  6214. if ($va=='车辆费用')
  6215. $r10+=$v['price'];
  6216. if ($va=='广告费')
  6217. $r11+=$v['price'];
  6218. if ($va=='团队建设费')
  6219. $r13+=$v['price'];
  6220. if ($va=='物业管理费')
  6221. $r14+=$v['price'];
  6222. if ($va=='宽带费')
  6223. $r15+=$v['price'];
  6224. $psum+=$v['price'];
  6225. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6226. }
  6227. }
  6228. }
  6229. if($falg)
  6230. $html.='<td class="taR">-</td>';
  6231. }
  6232. $r12+=$psum;
  6233. if(!empty($psum))
  6234. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6235. else
  6236. $psum='<td class="colGreen taR">-</td>';
  6237. $receiptL['日常相关费用']=$psum.$html;
  6238. /*-----------------------------------*/
  6239. $html="";
  6240. $psum=0;
  6241. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6242. foreach ($item as $va){
  6243. $falg=true;
  6244. foreach ($receiptCollectList as $v){
  6245. if($v['itemCategory']=='差旅相关费用'){
  6246. if($v['item']==$va){
  6247. if ($va=='往来交通费')
  6248. $c1+=$v['price'];
  6249. if ($va=='市内交通费')
  6250. $c2+=$v['price'];
  6251. if ($va=='出差住宿费')
  6252. $c3+=$v['price'];
  6253. if ($va=='出差补助')
  6254. $c4+=$v['price'];
  6255. if ($va=='其他费用')
  6256. $c5+=$v['price'];
  6257. $psum+=$v['price'];
  6258. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6259. }
  6260. }
  6261. }
  6262. if($falg)
  6263. $html.='<td class="taR">-</td>';
  6264. }
  6265. $c6+=$psum;
  6266. if(!empty($psum))
  6267. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6268. else
  6269. $psum='<td class="colGreen taR">-</td>';
  6270. $receiptL['差旅相关费用']=$psum.$html;
  6271. /*-------------------------------------*/
  6272. $html="";
  6273. $psum=0;
  6274. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6275. foreach ($item as $va){
  6276. $falg=true;
  6277. foreach ($receiptCollectList as $v){
  6278. if($v['itemCategory']=='培训班费用'){
  6279. if($v['item']==$va){
  6280. if ($va=='场租费')
  6281. $p1+=$v['price'];
  6282. if ($va=='薪酬')
  6283. $p2+=$v['price'];
  6284. if ($va=='住宿费')
  6285. $p3+=$v['price'];
  6286. if ($va=='交通费')
  6287. $p4+=$v['price'];
  6288. if ($va=='餐饮费')
  6289. $p5+=$v['price'];
  6290. if ($va=='办公费')
  6291. $p6+=$v['price'];
  6292. if ($va=='公关费')
  6293. $p7+=$v['price'];
  6294. if ($va=='其他')
  6295. $p8+=$v['price'];
  6296. $psum+=$v['price'];
  6297. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6298. }
  6299. }
  6300. }
  6301. if($falg)
  6302. $html.='<td class="taR">-</td>';
  6303. }
  6304. $p9+=$psum;
  6305. if(!empty($psum))
  6306. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6307. else
  6308. $psum='<td class="colGreen taR">-</td>';
  6309. $receiptL['培训班费用']=$psum.$html;
  6310. /*-------------------------------------*/
  6311. $html="";
  6312. $psum=0;
  6313. $item=array('公关费','广告费','借款','可自加费用');
  6314. foreach ($item as $va){
  6315. $falg=true;
  6316. foreach ($receiptCollectList as $v){
  6317. if($v['itemCategory']=='其他'){
  6318. // if ($value['sid']==42){
  6319. //
  6320. // echo var_dump($v['item']);
  6321. // echo var_dump($va);
  6322. // echo var_dump($v['item']==" ".$va);
  6323. // echo $v['item']."==".$va."/<br/>";
  6324. // //print_r( $receiptCollectList);//echo $va;
  6325. // }
  6326. if(trim($v['item'])==$va){
  6327. if ($va=='公关费')
  6328. $t1+=$v['price'];
  6329. if ($va=='广告费'){
  6330. $t2+=$v['price'];
  6331. }
  6332. if ($va=='借款')
  6333. $t3+=$v['price'];
  6334. if ($va=='可自加费用')
  6335. $t4+=$v['price'];
  6336. $psum+=$v['price'];
  6337. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6338. }
  6339. }
  6340. }
  6341. if($falg)
  6342. $html.='<td class="taR">-</td>';
  6343. }
  6344. $t5+=$psum;
  6345. if(!empty($psum))
  6346. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6347. else
  6348. $psum='<td class="colGreen taR">-</td>';
  6349. $receiptL['其他']=$psum.$html;
  6350. /*-------------------------------------*/
  6351. $html="";
  6352. $psum=0;
  6353. foreach ($receiptCollectList as $v){
  6354. if($v['itemCategory']=='报销金额调整'){
  6355. if (!empty($v['price'])){
  6356. $psum+=$v['price'];
  6357. }
  6358. }
  6359. }
  6360. $s1+=$psum;
  6361. if(!empty($psum))
  6362. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6363. else
  6364. $psum='<td class="taR colOrange">-</td>';
  6365. $receiptL['报销金额调整']=$psum.$html;
  6366. }else{
  6367. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6368. <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>
  6369. <td class="taR">-</td><td class="taR">-</td>';
  6370. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6371. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6372. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6373. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6374. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6375. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6376. }
  6377. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6378. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6379. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6380. if(!empty($monthStaffPrice[0]['price'])){
  6381. $m1+=$monthStaffPrice[0]['price'];
  6382. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6383. }else
  6384. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6385. $list[$value['username']]=$receiptL;
  6386. }
  6387. }
  6388. $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>
  6389. <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>
  6390. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6391. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6392. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6393. $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>
  6394. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6395. $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>';
  6396. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6397. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6398. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6399. }
  6400. $data['list']=$list;
  6401. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6402. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6403. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6404. //statistics html
  6405. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6406. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6407. if(empty($stList))
  6408. $stList=array('rePrice'=>0,'agPrice'=>0);
  6409. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6410. $monthHtml="";
  6411. for ($i=1;$i<=12;$i++){
  6412. if ($i==$month)
  6413. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6414. else
  6415. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6416. }
  6417. $data['monthHtml']=$monthHtml;
  6418. $data['year']=$year;
  6419. $data['month']=$month;
  6420. $data['memu']="receipt";
  6421. $data['staff']=$this->staff;
  6422. $data['receiptMemu']='companyCategoryCollect';
  6423. $data['verifyId']=$this->verifyId;
  6424. $data['executeId']=$this->executeId;
  6425. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6426. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6427. }
  6428. function staffCollectMonthDetail2(){
  6429. $year=$this->get_args('year')?$this->get_args('year'):"";
  6430. $month=$this->get_args('month')?$this->get_args('month'):"";
  6431. if(!$year)
  6432. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6433. if(!$month)
  6434. $month=isset($this->params['month'])?$this->params['month']:1;
  6435. Doo::loadModel('staff');
  6436. $staff=new staff();
  6437. Doo::loadModel("receiptDetail");
  6438. $receiptDetail=new receiptDetail();
  6439. Doo::loadModel('accountItem');
  6440. $accountItem=new accountItem();
  6441. Doo::loadModel('statistics');
  6442. $statistics=new statistics();
  6443. Doo::loadModel('L_category');
  6444. $lCategory=new L_category();
  6445. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6446. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6447. $list=array();
  6448. foreach ($categoryList as $vlu){
  6449. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6450. $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;
  6451. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6452. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6453. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6454. $s1=0;
  6455. $m1=0;
  6456. foreach ($staffList as $value){
  6457. if ($vlu['cid']==$value['cid']){
  6458. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6459. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6460. if(!empty($receiptCollectList)){
  6461. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6462. $html="";
  6463. $psum=0;
  6464. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6465. foreach ($item as $va){
  6466. $falg=true;
  6467. foreach ($receiptCollectList as $v){
  6468. if($v['itemCategory']=='日常相关费用'){
  6469. if($v['item']==$va){
  6470. if ($va=='市内交通费')
  6471. $r1+=$v['price'];
  6472. if ($va=='市内出租费')
  6473. $r2+=$v['price'];
  6474. if ($va=='办事处房租')
  6475. $r3+=$v['price'];
  6476. if ($va=='电话费')
  6477. $r4+=$v['price'];
  6478. if ($va=='水费')
  6479. $r5+=$v['price'];
  6480. if ($va=='电费')
  6481. $r6+=$v['price'];
  6482. if ($va=='办公费用')
  6483. $r7+=$v['price'];
  6484. if ($va=='邮寄费')
  6485. $r8+=$v['price'];
  6486. if ($va=='其他费用')
  6487. $r9+=$v['price'];
  6488. if ($va=='车辆费用')
  6489. $r10+=$v['price'];
  6490. if ($va=='广告费')
  6491. $r11+=$v['price'];
  6492. if ($va=='团队建设费')
  6493. $r13+=$v['price'];
  6494. if ($va=='物业管理费')
  6495. $r14+=$v['price'];
  6496. if ($va=='宽带费')
  6497. $r15+=$v['price'];
  6498. $psum+=$v['price'];
  6499. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6500. }
  6501. }
  6502. }
  6503. if($falg)
  6504. $html.='<td class="taR">-</td>';
  6505. }
  6506. $r12+=$psum;
  6507. if(!empty($psum))
  6508. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6509. else
  6510. $psum='<td class="colGreen taR">-</td>';
  6511. $receiptL['日常相关费用']=$psum.$html;
  6512. /*-----------------------------------*/
  6513. $html="";
  6514. $psum=0;
  6515. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6516. foreach ($item as $va){
  6517. $falg=true;
  6518. foreach ($receiptCollectList as $v){
  6519. if($v['itemCategory']=='差旅相关费用'){
  6520. if($v['item']==$va){
  6521. if ($va=='往来交通费')
  6522. $c1+=$v['price'];
  6523. if ($va=='市内交通费')
  6524. $c2+=$v['price'];
  6525. if ($va=='出差住宿费')
  6526. $c3+=$v['price'];
  6527. if ($va=='出差补助')
  6528. $c4+=$v['price'];
  6529. if ($va=='其他费用')
  6530. $c5+=$v['price'];
  6531. $psum+=$v['price'];
  6532. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6533. }
  6534. }
  6535. }
  6536. if($falg)
  6537. $html.='<td class="taR">-</td>';
  6538. }
  6539. $c6+=$psum;
  6540. if(!empty($psum))
  6541. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6542. else
  6543. $psum='<td class="colGreen taR">-</td>';
  6544. $receiptL['差旅相关费用']=$psum.$html;
  6545. /*-------------------------------------*/
  6546. $html="";
  6547. $psum=0;
  6548. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6549. foreach ($item as $va){
  6550. $falg=true;
  6551. foreach ($receiptCollectList as $v){
  6552. if($v['itemCategory']=='培训班费用'){
  6553. if($v['item']==$va){
  6554. if ($va=='场租费')
  6555. $p1+=$v['price'];
  6556. if ($va=='薪酬')
  6557. $p2+=$v['price'];
  6558. if ($va=='住宿费')
  6559. $p3+=$v['price'];
  6560. if ($va=='交通费')
  6561. $p4+=$v['price'];
  6562. if ($va=='餐饮费')
  6563. $p5+=$v['price'];
  6564. if ($va=='办公费')
  6565. $p6+=$v['price'];
  6566. if ($va=='公关费')
  6567. $p7+=$v['price'];
  6568. if ($va=='其他')
  6569. $p8+=$v['price'];
  6570. $psum+=$v['price'];
  6571. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6572. }
  6573. }
  6574. }
  6575. if($falg)
  6576. $html.='<td class="taR">-</td>';
  6577. }
  6578. $p9+=$psum;
  6579. if(!empty($psum))
  6580. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6581. else
  6582. $psum='<td class="colGreen taR">-</td>';
  6583. $receiptL['培训班费用']=$psum.$html;
  6584. /*-------------------------------------*/
  6585. $html="";
  6586. $psum=0;
  6587. $item=array('公关费','广告费','借款','可自加费用');
  6588. foreach ($item as $va){
  6589. $falg=true;
  6590. foreach ($receiptCollectList as $v){
  6591. if($v['itemCategory']=='其他'){
  6592. if($v['item']==$va){
  6593. if ($va=='公关费')
  6594. $t1+=$v['price'];
  6595. if ($va=='广告费')
  6596. $t2+=$v['price'];
  6597. if ($va=='借款')
  6598. $t3+=$v['price'];
  6599. if ($va=='可自加费用')
  6600. $t4+=$v['price'];
  6601. $psum+=$v['price'];
  6602. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6603. }
  6604. }
  6605. }
  6606. if($falg)
  6607. $html.='<td class="taR">-</td>';
  6608. }
  6609. $t5+=$psum;
  6610. if(!empty($psum))
  6611. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6612. else
  6613. $psum='<td class="colGreen taR">-</td>';
  6614. $receiptL['其他']=$psum.$html;
  6615. /*-------------------------------------*/
  6616. $html="";
  6617. $psum=0;
  6618. foreach ($receiptCollectList as $v){
  6619. if($v['itemCategory']=='报销金额调整'){
  6620. if (!empty($v['price'])){
  6621. $psum+=$v['price'];
  6622. }
  6623. }
  6624. }
  6625. $s1+=$psum;
  6626. if(!empty($psum))
  6627. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6628. else
  6629. $psum='<td class="taR colOrange">-</td>';
  6630. $receiptL['报销金额调整']=$psum.$html;
  6631. }else{
  6632. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6633. <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>';
  6634. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6635. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6636. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6637. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6638. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6639. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6640. }
  6641. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6642. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6643. if(!empty($monthStaffPrice[0]['price'])){
  6644. $m1+=$monthStaffPrice[0]['price'];
  6645. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6646. }else
  6647. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6648. $list[$value['username']]=$receiptL;
  6649. }
  6650. }
  6651. $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>
  6652. <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>
  6653. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6654. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6655. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6656. $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>
  6657. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6658. $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>';
  6659. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6660. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6661. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6662. }
  6663. $data['list']=$list;
  6664. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6665. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6666. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6667. //statistics html
  6668. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6669. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6670. if(empty($stList))
  6671. $stList=array('rePrice'=>0,'agPrice'=>0);
  6672. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6673. $monthHtml="";
  6674. for ($i=1;$i<=12;$i++){
  6675. if ($i==$month)
  6676. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6677. else
  6678. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6679. }
  6680. $data['monthHtml']=$monthHtml;
  6681. $data['year']=$year;
  6682. $data['month']=$month;
  6683. $data['memu']="receipt";
  6684. $data['staff']=$this->staff;
  6685. $data['receiptMemu']='companyCategoryCollect';
  6686. $data['verifyId']=$this->verifyId;
  6687. $data['executeId']=$this->executeId;
  6688. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6689. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6690. }
  6691. function companyMonthCollectDetail(){
  6692. $year=$this->get_args('year')?$this->get_args('year'):"";
  6693. $month=$this->get_args('month')?$this->get_args('month'):"";
  6694. if(!$year)
  6695. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6696. if(!$month)
  6697. $month=isset($this->params['month'])?$this->params['month']:1;
  6698. Doo::loadModel('staff');
  6699. $staff=new staff();
  6700. Doo::loadModel("receiptDetail");
  6701. $receiptDetail=new receiptDetail();
  6702. Doo::loadModel('accountItem');
  6703. $accountItem=new accountItem();
  6704. Doo::loadModel('statistics');
  6705. $statistics=new statistics();
  6706. Doo::loadModel('L_category');
  6707. $lCategory=new L_category();
  6708. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6709. $categoryList=$lCategory->find(array('asArray'=>true));
  6710. $list=array();
  6711. foreach ($categoryList as $value){
  6712. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6713. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6714. if(!empty($receiptCollectList)){
  6715. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6716. $html="";
  6717. $psum=0;
  6718. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6719. foreach ($item as $va){
  6720. $falg=true;
  6721. foreach ($receiptCollectList as $v){
  6722. if($v['itemCategory']=='日常相关费用'){
  6723. if($v['item']==$va){
  6724. $psum+=$v['price'];
  6725. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6726. }
  6727. }
  6728. }
  6729. if($falg)
  6730. $html.='<td class="taR">-</td>';
  6731. }
  6732. if(!empty($psum))
  6733. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6734. else
  6735. $psum='<td class="colGreen taR">-</td>';
  6736. $receiptL['日常相关费用']=$psum.$html;
  6737. /*-----------------------------------*/
  6738. $html="";
  6739. $psum=0;
  6740. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6741. foreach ($item as $va){
  6742. $falg=true;
  6743. foreach ($receiptCollectList as $v){
  6744. if($v['itemCategory']=='差旅相关费用'){
  6745. if($v['item']==$va){
  6746. $psum+=$v['price'];
  6747. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6748. }
  6749. }
  6750. }
  6751. if($falg)
  6752. $html.='<td class="taR">-</td>';
  6753. }
  6754. if(!empty($psum))
  6755. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6756. else
  6757. $psum='<td class="colGreen taR">-</td>';
  6758. $receiptL['差旅相关费用']=$psum.$html;
  6759. /*-------------------------------------*/
  6760. $html="";
  6761. $psum=0;
  6762. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6763. foreach ($item as $va){
  6764. $falg=true;
  6765. foreach ($receiptCollectList as $v){
  6766. if($v['itemCategory']=='培训班费用'){
  6767. if($v['item']==$va){
  6768. $psum+=$v['price'];
  6769. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6770. }
  6771. }
  6772. }
  6773. if($falg)
  6774. $html.='<td class="taR">-</td>';
  6775. }
  6776. if(!empty($psum))
  6777. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6778. else
  6779. $psum='<td class="colGreen taR">-</td>';
  6780. $receiptL['培训班费用']=$psum.$html;
  6781. /*-------------------------------------*/
  6782. $html="";
  6783. $psum=0;
  6784. $item=array('公关费','广告费','借款','可自加费用');
  6785. foreach ($item as $va){
  6786. $falg=true;
  6787. foreach ($receiptCollectList as $v){
  6788. if($v['itemCategory']=='其他'){
  6789. if($v['item']==$va){
  6790. $psum+=$v['price'];
  6791. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6792. }
  6793. }
  6794. }
  6795. if($falg)
  6796. $html.='<td class="taR">-</td>';
  6797. }
  6798. if(!empty($psum))
  6799. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6800. else
  6801. $psum='<td class="colGreen taR">-</td>';
  6802. $receiptL['其他']=$psum.$html;
  6803. /*-------------------------------------*/
  6804. $html="";
  6805. $psum=0;
  6806. foreach ($receiptCollectList as $v){
  6807. if($v['itemCategory']=='报销金额调整'){
  6808. if (!empty($v['price']))
  6809. $psum+=$v['price'];
  6810. }
  6811. }
  6812. if(!empty($psum))
  6813. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6814. else
  6815. $psum='<td class="taR colOrange">-</td>';
  6816. $receiptL['报销金额调整']=$psum.$html;
  6817. }else{
  6818. $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>
  6819. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6820. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6821. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6822. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6823. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6824. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6825. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6826. }
  6827. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6828. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6829. if(!empty($monthStaffPrice[0]['price']))
  6830. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6831. else
  6832. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6833. $list[$value['title']]=$receiptL;
  6834. }
  6835. $data['list']=$list;
  6836. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6837. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6838. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6839. //print_r($data['monthPriceHtml']);
  6840. // foreach ($data['monthPriceHtml'] as $value){
  6841. // echo $value;
  6842. // }
  6843. // die;
  6844. //statistics html
  6845. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6846. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6847. if(empty($stList))
  6848. $stList=array('rePrice'=>0,'agPrice'=>0);
  6849. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6850. $monthHtml="";
  6851. for ($i=1;$i<=12;$i++){
  6852. if ($i==$month)
  6853. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6854. else
  6855. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6856. }
  6857. $data['monthHtml']=$monthHtml;
  6858. $data['year']=$year;
  6859. $data['month']=$month;
  6860. $data['memu']="receipt";
  6861. $data['staff']=$this->staff;
  6862. $data['receiptMemu']='companyCategoryCollect';
  6863. $data['verifyId']=$this->verifyId;
  6864. $data['executeId']=$this->executeId;
  6865. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6866. }
  6867. function staffCollectDetail(){
  6868. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6869. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6870. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6871. if(!$staffname){
  6872. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6873. $staffname= urldecode($staffname);
  6874. }
  6875. Doo::loadModel('staff');
  6876. $staff=new staff();
  6877. Doo::loadModel("receiptDetail");
  6878. $receiptDetail=new receiptDetail();
  6879. Doo::loadModel('accountItem');
  6880. $accountItem=new accountItem();
  6881. Doo::loadModel('statistics');
  6882. $statistics=new statistics();
  6883. Doo::loadModel('L_category');
  6884. $lCategory=new L_category();
  6885. $staffList=$staff->find(array('asArray'=>true));
  6886. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6887. foreach ($staffList as $value){
  6888. if ($value['username']==$staffname&&$value['username']!='admin'){
  6889. $stTitle=$value['category'].'-'.$value['username'];
  6890. $staffId=$value['sid'];
  6891. $cid=$value['cid'];
  6892. $ocid=$value['cid'];
  6893. if (!empty($value['othercid']))
  6894. $cid=$value['cid'].','.$value['othercid'];
  6895. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6896. }elseif ($value['username']!='admin')
  6897. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6898. }
  6899. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6900. if(empty($pcid))
  6901. $pcid=$ocid;
  6902. $data['ocid']=$pcid;
  6903. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6904. $this->showCache($path);
  6905. //
  6906. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6907. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6908. $accountList=$accountItem->find(array('asArray'=>true));
  6909. //create CollectDetail HTML
  6910. $collectHtml=array();
  6911. foreach ($accountList as $key=>$value){
  6912. $html="";$asum=0;
  6913. for ($i=1;$i<=12;$i++){
  6914. $falg=true;
  6915. foreach ($receiptCollectList as $v) {
  6916. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6917. $asum+=$v['price'];
  6918. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6919. }
  6920. }
  6921. if($falg)
  6922. $html.='<td class="taR">-</td>';
  6923. }
  6924. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  6925. $collectHtml[$value['category']][$value['name']]=$html;
  6926. }
  6927. $data['collectHtml']=$collectHtml;
  6928. //create Adjustment price html
  6929. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  6930. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  6931. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6932. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  6933. array_push($collectArray['日常相关费用'], $collectHtml);
  6934. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  6935. array_push($collectArray['差旅相关费用'], $collectHtml);
  6936. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  6937. array_push($collectArray['培训班费用'], $collectHtml);
  6938. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  6939. array_push($collectArray['其他'], $collectHtml);
  6940. $data['collectArray']=$collectArray;
  6941. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  6942. array_push($adjustment, $collectHtml);
  6943. $data['adjustment']=$adjustment;
  6944. //total price html
  6945. $collectHtml="";$total=0;
  6946. for ($i=1;$i<=12;$i++){
  6947. $sumPrice=0;
  6948. foreach ($receiptCollectList as $key=>$value){
  6949. if($value['month']==$i){
  6950. $sumPrice+=$value['price'];
  6951. }
  6952. }
  6953. if ($sumPrice==0)
  6954. $collectHtml.='<td class="taR">-</td>';
  6955. else
  6956. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  6957. $total+=$sumPrice;
  6958. }
  6959. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  6960. //statistics html
  6961. $stList=$statistics->statisticsByYear($year,$staffId);
  6962. if(empty($stList))
  6963. $stList=array('rePrice'=>0,'agPrice'=>0);
  6964. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6965. $data['totalPrice']=$collectHtml;
  6966. $data['totalYear']=$total;
  6967. $data['stHtml']=$stHtml;
  6968. $data['year']=$year;
  6969. $data['stTitle']=$stTitle;
  6970. $data['memu']="receipt";
  6971. $data['staff']=$this->staff;
  6972. $data['receiptMemu']='companyCategoryCollect';
  6973. $data['verifyId']=$this->verifyId;
  6974. $data['executeId']=$this->executeId;
  6975. if ($year<date("Y")){
  6976. Doo::loadModel('receipt');
  6977. $receipt=new receipt();
  6978. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6979. if(empty($receiptList)){ //generated files
  6980. ob_start();
  6981. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6982. $this->cacheFile($path);die;
  6983. }
  6984. }
  6985. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  6986. }
  6987. function BUGFLAG(){
  6988. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  6989. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  6990. $month=$this->get_args('month')?$this->get_args('month'):"";
  6991. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  6992. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  6993. if (empty($status))
  6994. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  6995. $page_size=12;
  6996. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  6997. $vidList=array();
  6998. $button=0;
  6999. Doo::loadModel('verify');
  7000. $verify=new verify();
  7001. Doo::loadModel('receipt');
  7002. $receipt=new receipt();
  7003. Doo::loadModel('staff');
  7004. $staff=new staff();
  7005. Doo::loadModel('L_category');
  7006. $Lcategory=new L_category();
  7007. $dateCondition=" and Year(date) =".$year;
  7008. if(!empty($month))
  7009. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7010. $categoryList=$Lcategory->find(array('asArray'=>true));
  7011. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7012. $cateCondition="";$staffCondition="";$approvalCondition="";
  7013. if (!empty($cid))
  7014. $cateCondition=' and cid='.$cid;
  7015. if(!empty($sid)){
  7016. $staffCondition=' and staff='.$sid;
  7017. $cateCondition="";
  7018. }
  7019. $approvalCondition=" and status=".$status;
  7020. if($status==2){
  7021. //查找角色审批人
  7022. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7023. }
  7024. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7025. $approvalCondition=' and status=2 ';
  7026. }
  7027. if($status==1){
  7028. $approvalCondition=' and (status='.$status.' or status=6) ';
  7029. }
  7030. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7031. $pageinfo['page']=array('previous'=>'');
  7032. if ($status==0){
  7033. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7034. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7035. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7036. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7037. }else
  7038. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7039. ,'desc'=>'rid','asArray'=>true));
  7040. $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
  7041. ,'desc'=>'rid','asArray'=>true));
  7042. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7043. //print_r($pageinfo);
  7044. $Locate=0;
  7045. foreach ($receiptList as $key=>$value){
  7046. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7047. $receiptList[$key]['reviseDetail']=array();
  7048. if (!empty($value['reviseDetail']))
  7049. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7050. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7051. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7052. $receiptList[$key]['category']=$categoryDetil['title'];
  7053. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7054. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7055. $verifyStaff=json_decode($value['verifyStaff'],true);
  7056. foreach ($verifyList as $k=>$v){
  7057. //init verifyStaff
  7058. $verifyList[$k]['date']="";
  7059. $verifyList[$k]['opinion']="";
  7060. $verifyList[$k]['status']="";
  7061. if (empty($verifyStaff)){
  7062. $verifyList[$k]['date']="";
  7063. $verifyList[$k]['opinion']="";
  7064. if ($v[0]==$this->staff[0]['sid']){
  7065. $verifyList[$k]['status']=4;
  7066. $button=4;
  7067. }
  7068. }else{
  7069. $flag=true;
  7070. foreach ($verifyStaff as $m=>$u){
  7071. if ($v[0]==$m){
  7072. $verifyList[$k]['date']=$u['date'];
  7073. $verifyList[$k]['opinion']=$u['opinion'];
  7074. $verifyList[$k]['status']=$u['status'];
  7075. $flag=false;
  7076. break;
  7077. }
  7078. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7079. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7080. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7081. }
  7082. if($flag){//检测可编辑
  7083. if($v[0]==$this->staff[0]['sid']){
  7084. $verifyList[$k]['status']=4;$button=4;
  7085. }
  7086. }
  7087. }
  7088. }
  7089. $receiptList[$key]['verifyList']=$verifyList;
  7090. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7091. $receiptList[$key]['button']=$button;
  7092. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7093. }
  7094. //print_r($receiptList);die;
  7095. //$data['verifyDetail']=$verifyDetail;
  7096. $mothHtml="";
  7097. for($i=1;$i<=12;$i++){
  7098. if($month==$i)
  7099. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7100. else
  7101. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7102. }
  7103. $data['mothHtml']=$mothHtml;
  7104. $data['page']=$pageinfo;
  7105. $data['receiptList']=$receiptList;
  7106. $data['receiptApprovalCount']=count($rLRes);
  7107. $data['status']=$status;
  7108. $data['year']=$year;
  7109. $data['categoryList']=$categoryList;
  7110. $data['staffList']=$staffList;
  7111. $data['cid']=$cid;
  7112. $data['sid']=$sid;
  7113. //print_r($receiptList);
  7114. $data['memu']="receipt";
  7115. $data['staff']=$this->staff;
  7116. $data['receiptMemu']='approvalExpenses';
  7117. $data['verifyId']=$this->verifyId;
  7118. $data['executeId']=$this->executeId;
  7119. $this->render ( "/admin/FALG", $data );
  7120. }
  7121. function ajaxGetReceiptOrder(){
  7122. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7123. if (!empty($receiptOrder)){
  7124. Doo::loadModel('receipt');
  7125. $receipt=new receipt();
  7126. Doo::loadModel ( 'staff' );
  7127. $staff = new staff ();
  7128. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7129. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7130. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7131. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7132. </tbody></table><table class="table table table-bordered"><tbody>';
  7133. foreach ($verifyStaff as $key=>$value){
  7134. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7135. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7136. }
  7137. $html.='</tbody></table></div></div>';
  7138. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7139. }
  7140. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7141. }
  7142. function _getMonthCollectDetail($receiptCollectList){
  7143. if(!empty($receiptCollectList)){
  7144. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7145. $html="";
  7146. $psum=0;
  7147. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7148. foreach ($item as $value){
  7149. $falg=true;
  7150. foreach ($receiptCollectList as $v){
  7151. if($v['itemCategory']=='日常相关费用'){
  7152. if($v['item']==$value){
  7153. $psum+=$v['price'];
  7154. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7155. }
  7156. }
  7157. }
  7158. if($falg)
  7159. $html.='<td class="taR">-</td>';
  7160. }
  7161. if(!empty($psum))
  7162. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7163. else
  7164. $psum='<td class="colGreen taR">-</td>';
  7165. $receiptL['日常相关费用']=$psum.$html;
  7166. /*-----------------------------------*/
  7167. $html="";
  7168. $psum=0;
  7169. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7170. foreach ($item as $value){
  7171. $falg=true;
  7172. foreach ($receiptCollectList as $v){
  7173. if($v['itemCategory']=='差旅相关费用'){
  7174. if($v['item']==$value){
  7175. $psum+=$v['price'];
  7176. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7177. }
  7178. }
  7179. }
  7180. if($falg)
  7181. $html.='<td class="taR">-</td>';
  7182. }
  7183. if(!empty($psum))
  7184. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7185. else
  7186. $psum='<td class="colGreen taR">-</td>';
  7187. $receiptL['差旅相关费用']=$psum.$html;
  7188. /*-------------------------------------*/
  7189. $html="";
  7190. $psum=0;
  7191. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7192. foreach ($item as $value){
  7193. $falg=true;
  7194. foreach ($receiptCollectList as $v){
  7195. if($v['itemCategory']=='培训班费用'){
  7196. if($v['item']==$value){
  7197. $psum+=$v['price'];
  7198. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7199. }
  7200. }
  7201. }
  7202. if($falg)
  7203. $html.='<td class="taR">-</td>';
  7204. }
  7205. if(!empty($psum))
  7206. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7207. else
  7208. $psum='<td class="colGreen taR">-</td>';
  7209. $receiptL['培训班费用']=$psum.$html;
  7210. /*-------------------------------------*/
  7211. $html="";
  7212. $psum=0;
  7213. $item=array('公关费','广告费','借款','可自加费用');
  7214. foreach ($item as $value){
  7215. $falg=true;
  7216. foreach ($receiptCollectList as $v){
  7217. if($v['itemCategory']=='其他'){
  7218. if($v['item']==$value){
  7219. $psum+=$v['price'];
  7220. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7221. }
  7222. }
  7223. }
  7224. if($falg)
  7225. $html.='<td class="taR">-</td>';
  7226. }
  7227. if(!empty($psum))
  7228. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7229. else
  7230. $psum='<td class="colGreen taR">-</td>';
  7231. $receiptL['其他']=$psum.$html;
  7232. /*-------------------------------------*/
  7233. $html="";
  7234. $psum=0;
  7235. foreach ($receiptCollectList as $v){
  7236. if($v['itemCategory']=='报销金额调整'){
  7237. if (!empty($v['price']))
  7238. $psum+=$v['price'];
  7239. }
  7240. }
  7241. if(!empty($psum))
  7242. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7243. else
  7244. $psum='<td class="taR colOrange">-</td>';
  7245. $receiptL['报销金额调整']=$psum.$html;
  7246. }else{
  7247. $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>
  7248. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7249. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7250. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7251. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7252. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7253. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7254. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7255. }
  7256. return $receiptL;
  7257. }
  7258. function eMail(){
  7259. Doo::loadModel('staff');
  7260. $staff=new staff();
  7261. Doo::loadModel('receipt');
  7262. $receipt=new receipt();
  7263. Doo::loadModel('L_category');
  7264. $Lcategory=new L_category();
  7265. Doo::loadModel("verify");
  7266. $verify=new verify();
  7267. $staffList=$staff->find(array('asArray'=>true));
  7268. foreach ($staffList as $key=>$value){
  7269. if($value['username']!='admin'){
  7270. //提交人
  7271. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7272. if(!empty($receiptList)){
  7273. $html='<br><div><style></style>
  7274. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7275. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7276. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7277. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7278. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7279. <tbody><tr>
  7280. <td style="padding: 0 40px;" align="left">
  7281. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7282. </td></tr><tr>
  7283. <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>
  7284. </tr>
  7285. </tbody> </table></td> </tr> <tr><td>
  7286. <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">
  7287. <tbody> <tr><td>
  7288. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7289. 以下报销单完成了审批,等着收款吧:</p>
  7290. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7291. foreach ($receiptList as $k=>$v){
  7292. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7293. $html.='
  7294. <tr>
  7295. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7296. <td align="left">
  7297. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7298. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7299. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7300. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7301. </tr>';
  7302. }
  7303. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7304. <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>
  7305. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7306. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7307. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7308. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7309. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7310. $receipt=new receipt();
  7311. $receipt->notice=1;
  7312. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7313. }
  7314. }
  7315. //审批人
  7316. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7317. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7318. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7319. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7320. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7321. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7322. <tbody><tr><td style="padding: 0 40px;" align="left">
  7323. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7324. </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>
  7325. </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">
  7326. <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>
  7327. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7328. foreach ($verifyList as $k=>$v){
  7329. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7330. foreach ($receiptList as $r=>$l){
  7331. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7332. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7333. $html.='
  7334. <tr>
  7335. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7336. <td align="left">
  7337. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7338. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7339. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7340. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7341. </tr>';
  7342. }
  7343. }
  7344. $html.='
  7345. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7346. <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>
  7347. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7348. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7349. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7350. // $receipt=new receipt();
  7351. // $receipt->notice=1;
  7352. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7353. }
  7354. }
  7355. }
  7356. }
  7357. // Email发送函数
  7358. function SMail($toemail, $subject, $contents) {
  7359. Doo::loadClass('class.phpmailer');
  7360. $mail = new PHPMailer();
  7361. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7362. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7363. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7364. $mail->Password = "cDO1GjtY1seH"; //密码
  7365. $mail->CharSet = "UTF8";
  7366. $mail->SMTPAuth = true;
  7367. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7368. $mail->Mailer = "smtp";
  7369. $mail->Port = 25;
  7370. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7371. $mail->MsgHTML($contents);
  7372. $mail->AddAddress($toemail);
  7373. $mail->CharSet = "UTF-8";
  7374. return $mail->Send();
  7375. }
  7376. function swfupload(){
  7377. $POST_MAX_SIZE = ini_get('post_max_size');
  7378. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7379. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7380. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7381. header("HTTP/1.1 500 Internal Server Error");
  7382. echo "POST exceeded maximum allowed size.";
  7383. exit(0);
  7384. }
  7385. // Settings
  7386. $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)
  7387. $upload_name = "Filedata";
  7388. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7389. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7390. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7391. // Other variables
  7392. $MAX_FILENAME_LENGTH = 260;
  7393. $file_name = "";
  7394. $file_extension = "";
  7395. $uploadErrors = array(
  7396. 0=>"文件上传成功",
  7397. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7398. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7399. 3=>"上传的文件仅为部分文件",
  7400. 4=>"没有文件上传",
  7401. 6=>"缺少临时文件夹"
  7402. );
  7403. $nk= time();
  7404. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7405. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7406. echo "文件无法保存.";
  7407. exit(0);
  7408. }
  7409. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7410. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7411. exit(0);
  7412. }
  7413. function _GetFileEXT($filename) {
  7414. $pics = explode ( '.', $filename );
  7415. $num = count ( $pics );
  7416. return $pics [$num - 1];
  7417. }
  7418. /**
  7419. * 获取get或者POST值
  7420. * @param string $name 属性名称
  7421. * @return fixed 值
  7422. */
  7423. function get_args($name) {
  7424. if (isset ( $_GET [$name] )) {
  7425. if (is_array ( $_GET [$name] ))
  7426. return $_GET [$name];
  7427. else
  7428. return addslashes ( $_GET [$name] );
  7429. } elseif (isset ( $_POST [$name] )) {
  7430. if (is_array ( $_POST [$name] ))
  7431. return $_POST [$name];
  7432. else
  7433. return addslashes ( $_POST [$name] );
  7434. } else
  7435. return false;
  7436. }
  7437. function num_to_rmb($num){
  7438. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7439. $c2 = "分角元拾佰仟万拾佰仟亿";
  7440. //精确到分后面就不要了,所以只留两个小数位
  7441. $num = round($num, 2);
  7442. //将数字转化为整数
  7443. $num = $num * 100;
  7444. if (strlen($num) > 10) {
  7445. return "金额太大,请检查";
  7446. }
  7447. $i = 0;
  7448. $c = "";
  7449. while (1) {
  7450. if ($i == 0) {
  7451. //获取最后一位数字
  7452. $n = substr($num, strlen($num)-1, 1);
  7453. } else {
  7454. $n = $num % 10;
  7455. }
  7456. //每次将最后一位数字转化为中文
  7457. $p1 = substr($c1, 3 * $n, 3);
  7458. $p2 = substr($c2, 3 * $i, 3);
  7459. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7460. $c = $p1 . $p2 . $c;
  7461. } else {
  7462. $c = $p1 . $c;
  7463. }
  7464. $i = $i + 1;
  7465. //去掉数字最后一位了
  7466. $num = $num / 10;
  7467. $num = (int)$num;
  7468. //结束循环
  7469. if ($num == 0) {
  7470. break;
  7471. }
  7472. }
  7473. $j = 0;
  7474. $slen = strlen($c);
  7475. while ($j < $slen) {
  7476. //utf8一个汉字相当3个字符
  7477. $m = substr($c, $j, 6);
  7478. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7479. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7480. $left = substr($c, 0, $j);
  7481. $right = substr($c, $j + 3);
  7482. $c = $left . $right;
  7483. $j = $j-3;
  7484. $slen = $slen-3;
  7485. }
  7486. $j = $j + 3;
  7487. }
  7488. //这个是为了去掉类似23.0中最后一个“零”字
  7489. if (substr($c, strlen($c)-3, 3) == '零') {
  7490. $c = substr($c, 0, strlen($c)-3);
  7491. }
  7492. //将处理的汉字加上“整”
  7493. if (empty($c)) {
  7494. return "零元整";
  7495. }else{
  7496. return $c . "整";
  7497. }
  7498. }
  7499. /**
  7500. * 获得分页数据
  7501. * @param unknown_type $table
  7502. * @param unknown_type $condition
  7503. * @param unknown_type $on_page
  7504. * @param unknown_type $page_size
  7505. */
  7506. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7507. $page_c = "";
  7508. $page ['previous'] = $this->get_previous ( $on_page );
  7509. $page ['on_page'] = $on_page;
  7510. $total_count = $this->get_table_count ( $table, $condition );
  7511. $total = intval ( $total_count / $page_size );
  7512. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7513. $page ['total_data'] = $total_count;
  7514. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7515. $i = 1;
  7516. $page_max = 1;
  7517. $page_width=3;
  7518. if ($on_page >= $page_width) {
  7519. $page_max = intval ( $on_page / $page_width ) + 1;
  7520. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7521. }
  7522. for(; $i <= $page ['total_page']; $i ++) {
  7523. if ($i == $on_page)
  7524. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7525. else
  7526. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7527. if ($i == ($page_width * $page_max))
  7528. break;
  7529. }
  7530. $page ['page'] = $page_c;
  7531. $page ['lower'] = (-- $on_page) * $page_size;
  7532. return $page;
  7533. }
  7534. /**
  7535. * 获取总页数
  7536. * @param unknown_type $table
  7537. * @param unknown_type $condition
  7538. */
  7539. public function get_table_count($table = "", $condition = "") {
  7540. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7541. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7542. //echo $sql;die;
  7543. $query = Doo::db ()->query ( $sql );
  7544. $result = $query->fetch ();
  7545. return $result ['count'];
  7546. }
  7547. /**
  7548. * 获取上一页
  7549. * @param unknown_type $on_page
  7550. */
  7551. function get_previous($on_page = 1) {
  7552. return $on_page != 0 ? $on_page - 1 : $on_page;
  7553. }
  7554. }
  7555. ?>