ReceiptController.php 305 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. if ($receiptDetail['status']!=4&&!empty($verify))
  388. $receipt->verify=$verify;
  389. $receipt->executeCopy=$executeDetail['staff'];
  390. $receipt->explanation=$explanation;
  391. $receipt->update();
  392. $receiptDetail=new receiptDetail();
  393. $receiptDetail->delete(array('where'=>'rid='.$rid));
  394. //报销详情
  395. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  396. $receiptDetail=new receiptDetail();
  397. $receiptDetail->staff=$this->staff[0]['sid'];
  398. $receiptDetail->item=$value['name'];
  399. $receiptDetail->itemCategory=$this->AGENCY;
  400. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  401. $receiptDetail->date=date("Y-m-d");
  402. $receiptDetail->cid=$cid;
  403. $receiptDetail->rid=$rid;
  404. $receiptDetail->status=4;
  405. $receiptDetail->insert();
  406. }
  407. //return "/referReceipt/".$rid;
  408. }
  409. return "/saeaBorad";
  410. }
  411. function remitApproval(){
  412. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  413. $status=isset($this->params['status'])?$this->params['status']:'';
  414. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  415. $month=$this->get_args('month')?$this->get_args('month'):"";
  416. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  417. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  418. if (empty($status))
  419. $status=$this->get_args('status')?$this->get_args('status'):2;
  420. $vidList=array();
  421. $button=0;
  422. Doo::loadModel('verify');
  423. Doo::loadModel('receipt');
  424. Doo::loadModel('staff');
  425. $staff=new staff();
  426. $receipt=new receipt();
  427. $verify=new verify();
  428. Doo::loadModel('L_category');
  429. $Lcategory=new L_category();
  430. Doo::loadModel('enclosur');
  431. $enclosur=new enclosur();
  432. //user verify ID
  433. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  434. foreach ($verifyDetail as $key=>$value){
  435. array_push($vidList, $value['vid']);
  436. }
  437. $vid=implode(",", $vidList);
  438. if(empty($verifyDetail))
  439. $vid=0;
  440. $categoryList=$Lcategory->find(array('asArray'=>true));
  441. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  442. $ap="";
  443. if($status==4){
  444. $ap=4;$status=2;
  445. }
  446. //get Receipt By verifyID status 2
  447. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  448. $Locate=0;$roleId=0;
  449. if($ap==4)
  450. $status=4;
  451. foreach ($receiptList as $key=>$value){
  452. $receiptList[$key]['Locate']=$Locate;$Locate++;
  453. $receiptList[$key]['reviseDetail']=array();
  454. if (!empty($value['reviseDetail']))
  455. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  456. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  457. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  458. $receiptList[$key]['category']=$categoryDetil['title'];
  459. //检测编辑状态
  460. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  461. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  462. $verifyStaff=json_decode($value['verifyStaff'],true);
  463. Doo::loadModel('role');
  464. $role=new role();
  465. //print_r($verifyList);
  466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  467. foreach ($verifyList as $k=>$v){
  468. //init verifyStaff
  469. if ($v[1]=='ROLE'){
  470. if (!empty($verifyStaff)){
  471. $endStaffArray=end($verifyStaff);
  472. if ($v[0]==$endStaffArray['nextStaff']){
  473. $roleId=$v[0];
  474. }
  475. }
  476. $roleVerify=json_decode($v[3],true);
  477. $roleKey=$k;$roleArray=array();
  478. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  479. foreach ($roleVerify as $o=>$p){
  480. $staffID=explode ('_',$p);
  481. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  482. //print_r($staffID);
  483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  484. array_push($roleArray, $exp);
  485. }
  486. $roleArrayCopy[$v[0]]=$roleArray;
  487. //$verifyList[$k]['roleArray']=$roleArray;
  488. }
  489. //print_r($roleArray);
  490. $verifyList[$k]['date']="";
  491. $verifyList[$k]['opinion']="";
  492. $verifyList[$k]['status']="";
  493. if (empty($verifyStaff)){
  494. $verifyList[$k]['date']="";
  495. $verifyList[$k]['opinion']="";
  496. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  497. $verifyList[$k]['status']=4;
  498. $button=4;$flag=false;
  499. }
  500. }else{
  501. foreach ($verifyStaff as $m=>$u){
  502. if ($v[0]==$m){
  503. $verifyList[$k]['date']=$u['date'];
  504. $verifyList[$k]['opinion']=$u['opinion'];
  505. $verifyList[$k]['status']=$u['status'];
  506. $flag=false;
  507. break;
  508. }
  509. }
  510. $endStaffArray=end($verifyStaff);
  511. if (isset($endStaffArray['ROLE'])){
  512. }else{
  513. $endKey=key($verifyStaff);
  514. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  515. $button=4;
  516. $verifyList[$k]['status']=4;
  517. }
  518. }
  519. }
  520. }
  521. $rolename['name']='';
  522. if (!empty($roleId)){
  523. Doo::loadModel('role');
  524. $role=new role();
  525. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  526. }
  527. if (!empty($verifyStaff))
  528. $endStaffArray=end($verifyStaff);
  529. $KOP=false;
  530. foreach ($roleArrayCopy as $P=>$A){
  531. foreach ( $A as $MKI=>$AVL){
  532. if (!empty($verifyStaff)){
  533. //&&$rolename['rid']==$endStaffArray['nextStaff']
  534. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  535. $button=4;
  536. $roleArrayCopy[$P][$MKI]['status']=4;
  537. }
  538. foreach ($verifyStaff as $m=>$u){
  539. $AVLFK=$AVL[0].'_R';
  540. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  541. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  542. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  543. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  544. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  545. break;
  546. }
  547. }
  548. }else{
  549. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  550. $button=4;
  551. $roleArrayCopy[$P][$MKI]['status']=4;
  552. }
  553. }
  554. //$roleArray[$MKI]['rolename']=$rolename['name'];
  555. $KOP=true;
  556. }
  557. }
  558. foreach ($roleArrayCopy as $k=>$v){
  559. foreach ($verifyList as $m=>$n){
  560. if ($n[0]==$k){
  561. array_splice($verifyList,$m,1,$v);
  562. }
  563. }
  564. }
  565. $receiptList[$key]['verifyList']= $verifyList;
  566. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  567. $receiptList[$key]['button']=$button;
  568. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  569. }
  570. $mothHtml="";
  571. for($i=1;$i<=12;$i++){
  572. if($month==$i)
  573. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  574. else
  575. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  576. }
  577. //获取审批日志
  578. Doo::loadModel('receiptLog');
  579. $receiptLog=new receiptLog();
  580. $rlList=array();
  581. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  582. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  583. if (!empty($rlInfo)){
  584. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  585. }
  586. $receiptList[0]['rlList']=$rlList;
  587. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  588. $enclosurHtml='';
  589. foreach ($enclosurList as $value){
  590. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  591. }
  592. //print_r($receiptList);
  593. $data['enclosurHtml']=$enclosurHtml;
  594. $data['rolename']=$rolename['name'];
  595. $data['datetij']=$tijdate['date'];
  596. $data['mothHtml']=$mothHtml;
  597. $data['rid']=$rid;
  598. $data['receiptList']=$receiptList;
  599. $data['receiptApprovalCount']=count($receiptList);
  600. $data['status']=$status;
  601. $data['year']=$year;
  602. $data['categoryList']=$categoryList;
  603. $data['staffList']=$staffList;
  604. $data['cid']=$cid;
  605. $data['sid']=$sid;
  606. $data['ap']=$ap;
  607. $data['memu']="receipt";
  608. $data['staff']=$this->staff;
  609. $data['receiptMemu']='approvalExpenses';
  610. $data['verifyId']=$this->verifyId;
  611. $data['executeId']=$this->executeId;
  612. $this->render ( "/admin/remitApproval", $data );
  613. }
  614. function saeaLoanAdd(){
  615. Doo::loadModel('verify');
  616. $verify=new verify();
  617. Doo::loadModel("role");
  618. $role=new role();
  619. Doo::loadModel('L_category');
  620. $lCategory=new L_category();
  621. $veList=$verify->find(array('asArray'=>true));
  622. foreach ($veList as $key=>$value){
  623. $v=json_decode($value['staff']);
  624. $list=array();
  625. foreach ($v as $n=>$m){
  626. if ($m['1']=='ROLE'){
  627. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  628. $v[$n][1]=$roleInfo['name'];
  629. array_push($list, $roleInfo['name']);
  630. }else{
  631. array_push($list, $v[$n][1]);
  632. }
  633. }
  634. $veList[$key]['staff']=implode('>', $list);
  635. }
  636. $data['category']=$lCategory->find(array('asArray'=>true));
  637. $data['veList']=$veList;
  638. $data['memu']="receipt";
  639. $data['staff']=$this->staff;
  640. $data['receiptMemu']='saeaBorad';
  641. $data['verifyId']=$this->verifyId;
  642. $data['executeId']=$this->executeId;
  643. $this->render ( "/admin/saeaLoanAdd", $data );
  644. }
  645. function saeaLoanAddDo(){
  646. $agency=$this->get_args('agency');
  647. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  648. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  649. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  650. //die;
  651. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  652. Doo::loadModel('receipt');
  653. Doo::loadModel('receiptDetail');
  654. Doo::loadModel('accountItem');
  655. $accountItem=new accountItem();
  656. $receipt=new receipt();
  657. Doo::loadModel('loanReceipt');
  658. $loanReceipt=new loanReceipt();
  659. Doo::loadModel('execute');
  660. $execute=new execute();
  661. Doo::loadModel('enclosur');
  662. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  663. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  664. // if(!empty($receiptDetail))
  665. // return "/referReceipt/".$receiptDetail['rid'];
  666. $aItem=$accountItem->find(array('asArray'=>true));
  667. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  668. $ag=$tr=$ta=$ot=0;
  669. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  670. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  671. $sum+=$agency;$agencySum+=$agency;
  672. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  673. //借款数据备份
  674. $loanReceipt->loanItem=json_encode($accountJson);
  675. $loanReceipt->staff=$this->staff[0]['sid'];
  676. $loanReceipt->sum=number_format($sum, 2, '.', '');
  677. $loanReceipt->date=date("Y-m-d");
  678. $loanReceipt->cid=$cid;
  679. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  680. $loanReceipt->status=5;
  681. $loanReceipt->Rtype=1;
  682. $loanReceipt->verify=$verify;
  683. $receipt->receiptOrder=$receipt->receiptOrder;
  684. $loanReceipt->explanation=$explanation;
  685. $loanRid=$loanReceipt->insert();
  686. //报销单
  687. $receipt->loanItem=json_encode($accountJson);
  688. $receipt->staff=$this->staff[0]['sid'];
  689. $receipt->sum=number_format($sum, 2, '.', '');
  690. $receipt->date=date("Y-m-d");
  691. $receipt->cid=$cid;
  692. //特殊状态
  693. $receipt->status=5;
  694. $receipt->Rtype=1;
  695. $receipt->loanRid=$loanRid;
  696. //修改审批流程加入角色
  697. $receipt->verify=$verify;
  698. $receipt->executeCopy=$executeDetail['staff'];
  699. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  700. $receipt->explanation=$explanation;
  701. $rid=$receipt->insert();
  702. //执行数据备份
  703. // $executeCopy->rid=$rid;
  704. // $executeCopy->staff=$executeDetail['staff'];
  705. // $executeCopy->eid=$executeDetail['eid'];
  706. // $ecid=$executeCopy->insert();
  707. }
  708. return "/saeaBorad";
  709. }
  710. function saeaLoanEdi(){
  711. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  712. Doo::loadModel('verify');
  713. $verify=new verify();
  714. Doo::loadModel("role");
  715. $role=new role();
  716. Doo::loadModel('L_category');
  717. $lCategory=new L_category();
  718. Doo::loadModel('receipt');
  719. $receipt=new receipt();
  720. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  721. $veList=$verify->find(array('asArray'=>true));
  722. foreach ($veList as $key=>$value){
  723. $v=json_decode($value['staff']);
  724. $list=array();
  725. foreach ($v as $n=>$m){
  726. if ($m['1']=='ROLE'){
  727. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  728. $v[$n][1]=$roleInfo['name'];
  729. array_push($list, $roleInfo['name']);
  730. }else{
  731. array_push($list, $v[$n][1]);
  732. }
  733. }
  734. $veList[$key]['staff']=implode('>', $list);
  735. }
  736. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  737. $data['receiptInfo']=$receiptInfo;
  738. $data['category']=$lCategory->find(array('asArray'=>true));
  739. $data['veList']=$veList;
  740. $data['memu']="receipt";
  741. $data['staff']=$this->staff;
  742. $data['receiptMemu']='saeaBorad';
  743. $data['verifyId']=$this->verifyId;
  744. $data['executeId']=$this->executeId;
  745. $this->render ( "/admin/saeaLoanEdi", $data );
  746. }
  747. function saeaLoanEdiDo(){
  748. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  749. $agency=$this->get_args('agency');
  750. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  751. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  752. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  753. //die;
  754. if(!empty($cid)&&!empty($explanation)&&!empty($rid)){
  755. Doo::loadModel('receipt');
  756. Doo::loadModel('receiptDetail');
  757. Doo::loadModel('accountItem');
  758. $accountItem=new accountItem();
  759. $receipt=new receipt();
  760. Doo::loadModel('loanReceipt');
  761. $loanReceipt=new loanReceipt();
  762. Doo::loadModel('enclosur');
  763. Doo::loadModel('execute');
  764. $execute=new execute();
  765. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  766. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=5 or status=4) and rid='.$rid,'asArray'=>true));
  767. if(empty($receiptDetail))
  768. die('参数错误');
  769. $aItem=$accountItem->find(array('asArray'=>true));
  770. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  771. $ag=$tr=$ta=$ot=0;
  772. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  773. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  774. $sum+=$agency;$agencySum+=$agency;
  775. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  776. //报销单
  777. $receipt->loanItem=json_encode($accountJson);
  778. $receipt->sum=number_format($sum, 2, '.', '');
  779. $receipt->cid=$cid;
  780. //特殊状态
  781. //修改审批流程加入角色
  782. if ($receiptDetail['status']!=4)
  783. $receipt->verify=$verify;
  784. $receipt->explanation=$explanation;
  785. $receipt->update(array('where'=>'rid='.$rid));
  786. //借款数据更新
  787. $loanReceipt->loanItem=json_encode($accountJson);
  788. $loanReceipt->sum=number_format($sum, 2, '.', '');
  789. $loanReceipt->cid=$cid;
  790. if ($receiptDetail['status']!=4)
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($dateCondition,$this->staff[0]['sid']);
  1405. if(!isset($noPassSum['sum']))
  1406. $noPassSum['sum']=0;
  1407. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($noPassSum['sum']));
  1408. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1409. $Locate=0;$roleId=0;$button=0;
  1410. foreach ($receiptList as $key=>$value){
  1411. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1412. $receiptList[$key]['reviseDetail']=array();
  1413. if (!empty($value['reviseDetail']))
  1414. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1415. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1416. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1417. $receiptList[$key]['category']=$categoryDetil['title'];
  1418. //检测编辑状态
  1419. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1420. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1421. $verifyStaff=json_decode($value['verifyStaff'],true);
  1422. Doo::loadModel('role');
  1423. $role=new role();
  1424. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1425. foreach ($verifyList as $k=>$v){
  1426. //init verifyStaff
  1427. if ($v[1]=='ROLE'){
  1428. if (!empty($verifyStaff)){
  1429. $endStaffArray=end($verifyStaff);
  1430. // if ($v[0]==$endStaffArray['nextStaff']){
  1431. // $roleId=$v[0];
  1432. // }
  1433. }
  1434. $roleVerify=json_decode($v[3],true);
  1435. $roleKey=$k;$roleArray=array();
  1436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1437. foreach ($roleVerify as $o=>$p){
  1438. $staffID=explode ('_',$p);
  1439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1440. //print_r($staffID);
  1441. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1442. array_push($roleArray, $exp);
  1443. }
  1444. $roleArrayCopy[$v[0]]=$roleArray;
  1445. //$verifyList[$k]['roleArray']=$roleArray;
  1446. }
  1447. $verifyList[$k]['date']="";
  1448. $verifyList[$k]['opinion']="";
  1449. $verifyList[$k]['status']="";
  1450. if (empty($verifyStaff)){
  1451. $verifyList[$k]['date']="";
  1452. $verifyList[$k]['opinion']="";
  1453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1454. $verifyList[$k]['status']=4;
  1455. $flag=false;
  1456. }
  1457. }else{
  1458. foreach ($verifyStaff as $m=>$u){
  1459. if ($v[0]==$m){
  1460. $verifyList[$k]['date']=$u['date'];
  1461. $verifyList[$k]['opinion']=$u['opinion'];
  1462. $verifyList[$k]['status']=$u['status'];
  1463. $flag=false;
  1464. break;
  1465. }
  1466. }
  1467. $endStaffArray=end($verifyStaff);
  1468. if (isset($endStaffArray['ROLE'])){
  1469. }else{
  1470. // $endKey=key($verifyStaff);
  1471. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1472. // $button=4;
  1473. // $verifyList[$k]['status']=4;
  1474. // }
  1475. }
  1476. }
  1477. }
  1478. $rolename['name']='';
  1479. if (!empty($roleId)){
  1480. Doo::loadModel('role');
  1481. $role=new role();
  1482. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1483. }
  1484. if (!empty($verifyStaff))
  1485. $endStaffArray=end($verifyStaff);
  1486. $KOP=false;
  1487. foreach ($roleArrayCopy as $P=>$A){
  1488. foreach ( $A as $MKI=>$AVL){
  1489. if (!empty($verifyStaff)){
  1490. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1491. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1492. $button=4;
  1493. $roleArrayCopy[$P][$MKI]['status']=4;
  1494. }
  1495. foreach ($verifyStaff as $m=>$u){
  1496. $AVLFK=$AVL[0].'_R';
  1497. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1498. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1499. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1500. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1501. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1502. break;
  1503. }
  1504. }
  1505. }else{
  1506. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1507. $button=4;
  1508. $roleArrayCopy[$P][$MKI]['status']=4;
  1509. }
  1510. }
  1511. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1512. $KOP=true;
  1513. }
  1514. }
  1515. foreach ($roleArrayCopy as $k=>$v){
  1516. foreach ($verifyList as $m=>$n){
  1517. if ($n[0]==$k){
  1518. array_splice($verifyList,$m,1,$v);
  1519. }
  1520. }
  1521. }
  1522. $receiptList[$key]['verifyList']=$verifyList;
  1523. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1524. $receiptList[$key]['button']=$button;
  1525. }
  1526. //print_r($receiptList);die;
  1527. $mothHtml="";
  1528. for($i=1;$i<=12;$i++){
  1529. if($moth==$i)
  1530. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1531. else
  1532. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1533. }
  1534. $data['mothHtml']=$mothHtml;
  1535. $data['receiptList']=$receiptList;
  1536. $data['memu']="receipt";
  1537. $data['staff']=$this->staff;
  1538. $data['receiptMemu']='expenses';
  1539. $data['verifyId']=$this->verifyId;
  1540. $data['executeId']=$this->executeId;
  1541. $data['item']=$item;
  1542. $data['year']=$year;
  1543. $this->render ( "/admin/expenses", $data );
  1544. }
  1545. function expensesCollect(){
  1546. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1547. Doo::loadModel('receipt');
  1548. $receipt=new receipt();
  1549. Doo::loadModel('L_category');
  1550. $Lcategory=new L_category();
  1551. Doo::loadModel('verify');
  1552. Doo::loadModel('statistics');
  1553. $statistics=new statistics();
  1554. $verify=new verify();
  1555. Doo::loadModel('staff');
  1556. $staff=new staff();
  1557. Doo::loadModel('loanReceipt');
  1558. $loanReceipt=new loanReceipt();
  1559. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1560. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1561. /*
  1562. $Locate=0;$roleId=0;$button=0;
  1563. foreach ($loanList as $key=>$value){
  1564. $loanList[$key]['Locate']=$Locate;$Locate++;
  1565. $loanList[$key]['reviseDetail']=array();
  1566. if (!empty($value['reviseDetail']))
  1567. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1568. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1569. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1570. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1571. $loanList[$key]['category']=$categoryDetil['title'];
  1572. //检测编辑状态
  1573. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1574. $verifyList['staff']=$value['verifyBreakup'];
  1575. else
  1576. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1577. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1578. $verifyStaff=json_decode($value['verifyStaff'],true);
  1579. Doo::loadModel('role');
  1580. $role=new role();
  1581. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1582. foreach ($verifyList as $k=>$v){
  1583. //init verifyStaff
  1584. if ($v[1]=='ROLE'){
  1585. if (!empty($verifyStaff)){
  1586. $endStaffArray=end($verifyStaff);
  1587. // if ($v[0]==$endStaffArray['nextStaff']){
  1588. // $roleId=$v[0];
  1589. // }
  1590. }
  1591. $roleVerify=json_decode($v[3],true);
  1592. $roleKey=$k;$roleArray=array();
  1593. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1594. foreach ($roleVerify as $o=>$p){
  1595. $staffID=explode ('_',$p);
  1596. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1597. //print_r($staffID);
  1598. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1599. array_push($roleArray, $exp);
  1600. }
  1601. $roleArrayCopy[$v[0]]=$roleArray;
  1602. //$verifyList[$k]['roleArray']=$roleArray;
  1603. }
  1604. $verifyList[$k]['date']="";
  1605. $verifyList[$k]['opinion']="";
  1606. $verifyList[$k]['status']="";
  1607. if (empty($verifyStaff)){
  1608. $verifyList[$k]['date']="";
  1609. $verifyList[$k]['opinion']="";
  1610. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1611. $verifyList[$k]['status']=4;
  1612. $flag=false;
  1613. }
  1614. }else{
  1615. foreach ($verifyStaff as $m=>$u){
  1616. if ($v[0]==$m){
  1617. $verifyList[$k]['date']=$u['date'];
  1618. $verifyList[$k]['opinion']=$u['opinion'];
  1619. $verifyList[$k]['status']=$u['status'];
  1620. $flag=false;
  1621. break;
  1622. }
  1623. }
  1624. $endStaffArray=end($verifyStaff);
  1625. if (isset($endStaffArray['ROLE'])){
  1626. }else{
  1627. // $endKey=key($verifyStaff);
  1628. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1629. // $button=4;
  1630. // $verifyList[$k]['status']=4;
  1631. // }
  1632. }
  1633. }
  1634. }
  1635. $rolename['name']='';
  1636. if (!empty($roleId)){
  1637. Doo::loadModel('role');
  1638. $role=new role();
  1639. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1640. }
  1641. if (!empty($verifyStaff))
  1642. $endStaffArray=end($verifyStaff);
  1643. $KOP=false;
  1644. foreach ($roleArrayCopy as $P=>$A){
  1645. foreach ( $A as $MKI=>$AVL){
  1646. if (!empty($verifyStaff)){
  1647. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1648. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1649. $button=4;
  1650. $roleArrayCopy[$P][$MKI]['status']=4;
  1651. }
  1652. foreach ($verifyStaff as $m=>$u){
  1653. $AVLFK=$AVL[0].'_R';
  1654. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1655. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1656. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1657. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1658. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1659. break;
  1660. }
  1661. }
  1662. }else{
  1663. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1664. $button=4;
  1665. $roleArrayCopy[$P][$MKI]['status']=4;
  1666. }
  1667. }
  1668. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1669. $KOP=true;
  1670. }
  1671. }
  1672. foreach ($roleArrayCopy as $k=>$v){
  1673. foreach ($verifyList as $m=>$n){
  1674. if ($n[0]==$k){
  1675. array_splice($verifyList,$m,1,$v);
  1676. }
  1677. }
  1678. }
  1679. $loanList[$key]['verifyList']=$verifyList;
  1680. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1681. $loanList[$key]['button']=$button;
  1682. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1683. }
  1684. $data['loanList']=$loanList;
  1685. */
  1686. $Locate=0;$roleId=0;$button=0;
  1687. foreach ($receiptList as $key=>$value){
  1688. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1689. $receiptList[$key]['reviseDetail']=array();
  1690. if (!empty($value['reviseDetail']))
  1691. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1692. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1693. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1694. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1695. $receiptList[$key]['category']=$categoryDetil['title'];
  1696. //检测编辑状态
  1697. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1698. if($value['status']==8&&$value['Rtype']==1)
  1699. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1700. else
  1701. $verifyList['staff']=$value['verifyBreakup'];
  1702. }else
  1703. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1704. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1705. $verifyStaff=json_decode($value['verifyStaff'],true);
  1706. Doo::loadModel('role');
  1707. $role=new role();
  1708. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1709. foreach ($verifyList as $k=>$v){
  1710. //init verifyStaff
  1711. if ($v[1]=='ROLE'){
  1712. if (!empty($verifyStaff)){
  1713. $endStaffArray=end($verifyStaff);
  1714. // if ($v[0]==$endStaffArray['nextStaff']){
  1715. // $roleId=$v[0];
  1716. // }
  1717. }
  1718. $roleVerify=json_decode($v[3],true);
  1719. $roleKey=$k;$roleArray=array();
  1720. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1721. foreach ($roleVerify as $o=>$p){
  1722. $staffID=explode ('_',$p);
  1723. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1724. //print_r($staffID);
  1725. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1726. array_push($roleArray, $exp);
  1727. }
  1728. $roleArrayCopy[$v[0]]=$roleArray;
  1729. //$verifyList[$k]['roleArray']=$roleArray;
  1730. }
  1731. $verifyList[$k]['date']="";
  1732. $verifyList[$k]['opinion']="";
  1733. $verifyList[$k]['status']="";
  1734. if (empty($verifyStaff)){
  1735. $verifyList[$k]['date']="";
  1736. $verifyList[$k]['opinion']="";
  1737. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1738. $verifyList[$k]['status']=4;
  1739. $flag=false;
  1740. }
  1741. }else{
  1742. foreach ($verifyStaff as $m=>$u){
  1743. if ($v[0]==$m){
  1744. $verifyList[$k]['date']=$u['date'];
  1745. $verifyList[$k]['opinion']=$u['opinion'];
  1746. $verifyList[$k]['status']=$u['status'];
  1747. $flag=false;
  1748. break;
  1749. }
  1750. }
  1751. $endStaffArray=end($verifyStaff);
  1752. if (isset($endStaffArray['ROLE'])){
  1753. }else{
  1754. // $endKey=key($verifyStaff);
  1755. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1756. // $button=4;
  1757. // $verifyList[$k]['status']=4;
  1758. // }
  1759. }
  1760. }
  1761. }
  1762. $rolename['name']='';
  1763. if (!empty($roleId)){
  1764. Doo::loadModel('role');
  1765. $role=new role();
  1766. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1767. }
  1768. if (!empty($verifyStaff))
  1769. $endStaffArray=end($verifyStaff);
  1770. $KOP=false;
  1771. foreach ($roleArrayCopy as $P=>$A){
  1772. foreach ( $A as $MKI=>$AVL){
  1773. if (!empty($verifyStaff)){
  1774. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1775. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1776. $button=4;
  1777. $roleArrayCopy[$P][$MKI]['status']=4;
  1778. }
  1779. foreach ($verifyStaff as $m=>$u){
  1780. $AVLFK=$AVL[0].'_R';
  1781. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1782. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1783. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1784. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1785. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1786. break;
  1787. }
  1788. }
  1789. }else{
  1790. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1791. $button=4;
  1792. $roleArrayCopy[$P][$MKI]['status']=4;
  1793. }
  1794. }
  1795. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1796. $KOP=true;
  1797. }
  1798. }
  1799. foreach ($roleArrayCopy as $k=>$v){
  1800. foreach ($verifyList as $m=>$n){
  1801. if ($n[0]==$k){
  1802. array_splice($verifyList,$m,1,$v);
  1803. }
  1804. }
  1805. }
  1806. //费用执行人相关数据
  1807. $executeCopy=json_decode($value['executeCopy'],true);
  1808. $executeStaff=json_decode($value['executeStaff'],true);
  1809. foreach ($executeCopy as $k=>$v){
  1810. $executeCopy[$k]['date']='';
  1811. $executeCopy[$k]['opinion']='';
  1812. $executeCopy[$k]['status']='';
  1813. if (!empty($executeStaff))
  1814. foreach ($executeStaff as $m=>$u){
  1815. if ($v[0]==$m){
  1816. $executeCopy[$k]['date']=$u['date'];
  1817. $executeCopy[$k]['opinion']=$u['opinion'];
  1818. $executeCopy[$k]['status']=$u['status'];
  1819. break;
  1820. }
  1821. }
  1822. }
  1823. $receiptList[$key]['executeCopy']=$executeCopy;
  1824. $receiptList[$key]['verifyList']=$verifyList;
  1825. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1826. $receiptList[$key]['button']=$button;
  1827. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1828. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1829. $relust=$value['sum']-$value['loanSum'];
  1830. $receiptList[$key]['relust']=$relust;
  1831. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1832. }
  1833. //print_r($receiptList);
  1834. $data['receiptList']=$receiptList;
  1835. $data['memu']="receipt";
  1836. $data['staff']=$this->staff;
  1837. $data['receiptMemu']='expenses';
  1838. $data['verifyId']=$this->verifyId;
  1839. $data['executeId']=$this->executeId;
  1840. $this->render ( "/admin/expensesCollect", $data );
  1841. }
  1842. function approvalExpenses(){
  1843. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1844. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1845. $month=$this->get_args('month')?$this->get_args('month'):"";
  1846. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1847. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1848. if (empty($status))
  1849. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1850. $page_size=12;
  1851. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1852. $vidList=array();
  1853. $button=0;
  1854. Doo::loadModel('verify');
  1855. $verify=new verify();
  1856. Doo::loadModel('receipt');
  1857. $receipt=new receipt();
  1858. Doo::loadModel('staff');
  1859. $staff=new staff();
  1860. Doo::loadModel('L_category');
  1861. $Lcategory=new L_category();
  1862. //user verify ID
  1863. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1864. foreach ($verifyDetail as $key=>$value){
  1865. array_push($vidList, $value['vid']);
  1866. }
  1867. $vid=implode(",", $vidList);
  1868. if(empty($verifyDetail))
  1869. $vid=0;
  1870. // if ($status==0)
  1871. // $dateCondition="";
  1872. // else
  1873. $dateCondition=" and Year(date) =".$year;
  1874. if(!empty($month))
  1875. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1876. $categoryList=$Lcategory->find(array('asArray'=>true));
  1877. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1878. $cateCondition="";$staffCondition="";$approvalCondition="";
  1879. if (!empty($cid))
  1880. $cateCondition=' and cid='.$cid;
  1881. if(!empty($sid)){
  1882. $staffCondition=' and staff='.$sid;
  1883. $cateCondition="";
  1884. }
  1885. $approvalCondition=" and status=".$status;
  1886. if($status==2){
  1887. //查找角色审批人
  1888. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1889. }
  1890. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1891. $approvalCondition=' and status=2 ';
  1892. }
  1893. if($status==1){
  1894. $approvalCondition=' and (status='.$status.' or status=6) ';
  1895. }
  1896. if($status==8){
  1897. $approvalCondition=' and (status='.$status.' or status=9) ';
  1898. }
  1899. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1900. $pageinfo['page']=array('previous'=>'');
  1901. if ($status==0){
  1902. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1903. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1904. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1905. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1906. }else
  1907. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1908. ,'desc'=>'rid','asArray'=>true));
  1909. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1910. ,'desc'=>'rid','asArray'=>true));
  1911. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1912. //print_r($pageinfo);
  1913. $Locate=0;
  1914. foreach ($receiptList as $key=>$value){
  1915. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1916. $receiptList[$key]['reviseDetail']=array();
  1917. if (!empty($value['reviseDetail']))
  1918. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1919. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1920. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1921. $receiptList[$key]['category']=$categoryDetil['title'];
  1922. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1923. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1924. $verifyStaff=json_decode($value['verifyStaff'],true);
  1925. foreach ($verifyList as $k=>$v){
  1926. //init verifyStaff
  1927. $verifyList[$k]['date']="";
  1928. $verifyList[$k]['opinion']="";
  1929. $verifyList[$k]['status']="";
  1930. if (empty($verifyStaff)){
  1931. $verifyList[$k]['date']="";
  1932. $verifyList[$k]['opinion']="";
  1933. if ($v[0]==$this->staff[0]['sid']){
  1934. $verifyList[$k]['status']=4;
  1935. $button=4;
  1936. }
  1937. }else{
  1938. $flag=true;
  1939. foreach ($verifyStaff as $m=>$u){
  1940. if ($v[0]==$m){
  1941. $verifyList[$k]['date']=$u['date'];
  1942. $verifyList[$k]['opinion']=$u['opinion'];
  1943. $verifyList[$k]['status']=$u['status'];
  1944. $flag=false;
  1945. break;
  1946. }
  1947. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1948. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1949. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1950. }
  1951. if($flag){//检测可编辑
  1952. if($v[0]==$this->staff[0]['sid']){
  1953. $verifyList[$k]['status']=4;$button=4;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. $receiptList[$key]['verifyList']=$verifyList;
  1959. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1960. $receiptList[$key]['button']=$button;
  1961. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1962. }
  1963. //print_r($receiptList);die;
  1964. //$data['verifyDetail']=$verifyDetail;
  1965. $mothHtml="";
  1966. for($i=1;$i<=12;$i++){
  1967. if($month==$i)
  1968. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1969. else
  1970. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1971. }
  1972. $data['mothHtml']=$mothHtml;
  1973. $data['page']=$pageinfo;
  1974. $data['receiptList']=$receiptList;
  1975. $data['receiptApprovalCount']=count($rLRes);
  1976. $data['status']=$status;
  1977. $data['year']=$year;
  1978. $data['categoryList']=$categoryList;
  1979. $data['staffList']=$staffList;
  1980. $data['cid']=$cid;
  1981. $data['sid']=$sid;
  1982. //print_r($receiptList);
  1983. $data['memu']="receipt";
  1984. $data['staff']=$this->staff;
  1985. $data['receiptMemu']='approvalExpenses';
  1986. $data['verifyId']=$this->verifyId;
  1987. $data['executeId']=$this->executeId;
  1988. $this->render ( "/admin/approvalExpenses", $data );
  1989. }
  1990. function expensesDoc(){
  1991. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1992. Doo::loadModel('receipt');
  1993. $receipt=new receipt();
  1994. Doo::loadModel('L_category');
  1995. $Lcategory=new L_category();
  1996. Doo::loadModel('verify');
  1997. Doo::loadModel('statistics');
  1998. $statistics=new statistics();
  1999. $verify=new verify();
  2000. Doo::loadModel('staff');
  2001. $staff=new staff();
  2002. Doo::loadModel('loanReceipt');
  2003. $loanReceipt=new loanReceipt();
  2004. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  2005. $loanList=array();
  2006. if (!empty($receiptList))
  2007. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2008. $Locate=0;$roleId=0;$button=0;
  2009. foreach ($loanList as $key=>$value){
  2010. $loanList[$key]['Locate']=$Locate;$Locate++;
  2011. $loanList[$key]['reviseDetail']=array();
  2012. if (!empty($value['reviseDetail']))
  2013. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2014. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2015. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2016. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2017. $loanList[$key]['category']=$categoryDetil['title'];
  2018. //检测编辑状态
  2019. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2020. $verifyList['staff']=$value['verifyBreakup'];
  2021. else
  2022. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2023. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2024. $verifyStaff=json_decode($value['verifyStaff'],true);
  2025. Doo::loadModel('role');
  2026. $role=new role();
  2027. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2028. foreach ($verifyList as $k=>$v){
  2029. //init verifyStaff
  2030. if ($v[1]=='ROLE'){
  2031. if (!empty($verifyStaff)){
  2032. $endStaffArray=end($verifyStaff);
  2033. // if ($v[0]==$endStaffArray['nextStaff']){
  2034. // $roleId=$v[0];
  2035. // }
  2036. }
  2037. $roleVerify=json_decode($v[3],true);
  2038. $roleKey=$k;$roleArray=array();
  2039. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2040. foreach ($roleVerify as $o=>$p){
  2041. $staffID=explode ('_',$p);
  2042. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2043. //print_r($staffID);
  2044. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2045. array_push($roleArray, $exp);
  2046. }
  2047. $roleArrayCopy[$v[0]]=$roleArray;
  2048. //$verifyList[$k]['roleArray']=$roleArray;
  2049. }
  2050. $verifyList[$k]['date']="";
  2051. $verifyList[$k]['opinion']="";
  2052. $verifyList[$k]['status']="";
  2053. if (empty($verifyStaff)){
  2054. $verifyList[$k]['date']="";
  2055. $verifyList[$k]['opinion']="";
  2056. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2057. $verifyList[$k]['status']=4;
  2058. $flag=false;
  2059. }
  2060. }else{
  2061. foreach ($verifyStaff as $m=>$u){
  2062. if ($v[0]==$m){
  2063. $verifyList[$k]['date']=$u['date'];
  2064. $verifyList[$k]['opinion']=$u['opinion'];
  2065. $verifyList[$k]['status']=$u['status'];
  2066. $flag=false;
  2067. break;
  2068. }
  2069. }
  2070. $endStaffArray=end($verifyStaff);
  2071. if (isset($endStaffArray['ROLE'])){
  2072. }else{
  2073. // $endKey=key($verifyStaff);
  2074. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2075. // $button=4;
  2076. // $verifyList[$k]['status']=4;
  2077. // }
  2078. }
  2079. }
  2080. }
  2081. $rolename['name']='';
  2082. if (!empty($roleId)){
  2083. Doo::loadModel('role');
  2084. $role=new role();
  2085. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2086. }
  2087. if (!empty($verifyStaff))
  2088. $endStaffArray=end($verifyStaff);
  2089. $KOP=false;
  2090. foreach ($roleArrayCopy as $P=>$A){
  2091. foreach ( $A as $MKI=>$AVL){
  2092. if (!empty($verifyStaff)){
  2093. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2094. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2095. $button=4;
  2096. $roleArrayCopy[$P][$MKI]['status']=4;
  2097. }
  2098. foreach ($verifyStaff as $m=>$u){
  2099. $AVLFK=$AVL[0].'_R';
  2100. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2101. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2102. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2103. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2104. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2105. break;
  2106. }
  2107. }
  2108. }else{
  2109. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2110. $button=4;
  2111. $roleArrayCopy[$P][$MKI]['status']=4;
  2112. }
  2113. }
  2114. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2115. $KOP=true;
  2116. }
  2117. }
  2118. foreach ($roleArrayCopy as $k=>$v){
  2119. foreach ($verifyList as $m=>$n){
  2120. if ($n[0]==$k){
  2121. array_splice($verifyList,$m,1,$v);
  2122. }
  2123. }
  2124. }
  2125. $loanList[$key]['verifyList']=$verifyList;
  2126. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2127. $loanList[$key]['button']=$button;
  2128. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2129. }
  2130. $data['loanList']=$loanList;
  2131. //print_r($loanList);
  2132. $Locate=0;$roleId=0;$button=0;
  2133. foreach ($receiptList as $key=>$value){
  2134. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2135. $receiptList[$key]['reviseDetail']=array();
  2136. if (!empty($value['reviseDetail']))
  2137. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2138. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2139. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2140. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2141. $receiptList[$key]['category']=$categoryDetil['title'];
  2142. //检测编辑状态
  2143. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2144. $verifyList['staff']=$value['verifyBreakup'];
  2145. }else
  2146. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2147. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2148. $verifyStaff=json_decode($value['verifyStaff'],true);
  2149. Doo::loadModel('role');
  2150. $role=new role();
  2151. if ($verifyList==NULL)
  2152. $verifyList=array();
  2153. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2154. foreach ($verifyList as $k=>$v){
  2155. //init verifyStaff
  2156. if ($v[1]=='ROLE'){
  2157. if (!empty($verifyStaff)){
  2158. $endStaffArray=end($verifyStaff);
  2159. // if ($v[0]==$endStaffArray['nextStaff']){
  2160. // $roleId=$v[0];
  2161. // }
  2162. }
  2163. $roleVerify=json_decode($v[3],true);
  2164. $roleKey=$k;$roleArray=array();
  2165. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2166. foreach ($roleVerify as $o=>$p){
  2167. $staffID=explode ('_',$p);
  2168. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2169. //print_r($staffID);
  2170. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2171. array_push($roleArray, $exp);
  2172. }
  2173. $roleArrayCopy[$v[0]]=$roleArray;
  2174. //$verifyList[$k]['roleArray']=$roleArray;
  2175. }
  2176. $verifyList[$k]['date']="";
  2177. $verifyList[$k]['opinion']="";
  2178. $verifyList[$k]['status']="";
  2179. if (empty($verifyStaff)){
  2180. $verifyList[$k]['date']="";
  2181. $verifyList[$k]['opinion']="";
  2182. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2183. $verifyList[$k]['status']=4;
  2184. $flag=false;
  2185. }
  2186. }else{
  2187. foreach ($verifyStaff as $m=>$u){
  2188. if ($v[0]==$m){
  2189. $verifyList[$k]['date']=$u['date'];
  2190. $verifyList[$k]['opinion']=$u['opinion'];
  2191. $verifyList[$k]['status']=$u['status'];
  2192. $flag=false;
  2193. break;
  2194. }
  2195. }
  2196. $endStaffArray=end($verifyStaff);
  2197. if (isset($endStaffArray['ROLE'])){
  2198. }else{
  2199. // $endKey=key($verifyStaff);
  2200. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2201. // $button=4;
  2202. // $verifyList[$k]['status']=4;
  2203. // }
  2204. }
  2205. }
  2206. }
  2207. $rolename['name']='';
  2208. if (!empty($roleId)){
  2209. Doo::loadModel('role');
  2210. $role=new role();
  2211. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2212. }
  2213. if (!empty($verifyStaff))
  2214. $endStaffArray=end($verifyStaff);
  2215. $KOP=false;
  2216. foreach ($roleArrayCopy as $P=>$A){
  2217. foreach ( $A as $MKI=>$AVL){
  2218. if (!empty($verifyStaff)){
  2219. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2220. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2221. $button=4;
  2222. $roleArrayCopy[$P][$MKI]['status']=4;
  2223. }
  2224. foreach ($verifyStaff as $m=>$u){
  2225. $AVLFK=$AVL[0].'_R';
  2226. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2227. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2228. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2229. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2230. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2231. break;
  2232. }
  2233. }
  2234. }else{
  2235. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2236. $button=4;
  2237. $roleArrayCopy[$P][$MKI]['status']=4;
  2238. }
  2239. }
  2240. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2241. $KOP=true;
  2242. }
  2243. }
  2244. foreach ($roleArrayCopy as $k=>$v){
  2245. foreach ($verifyList as $m=>$n){
  2246. if ($n[0]==$k){
  2247. array_splice($verifyList,$m,1,$v);
  2248. }
  2249. }
  2250. }
  2251. //费用执行人相关数据
  2252. $executeCopy=json_decode($value['executeCopy'],true);
  2253. $executeStaff=json_decode($value['executeStaff'],true);
  2254. foreach ($executeCopy as $k=>$v){
  2255. $executeCopy[$k]['date']='';
  2256. $executeCopy[$k]['opinion']='';
  2257. $executeCopy[$k]['status']='';
  2258. if (!empty($executeStaff))
  2259. foreach ($executeStaff as $m=>$u){
  2260. if ($v[0]==$m){
  2261. $executeCopy[$k]['date']=$u['date'];
  2262. $executeCopy[$k]['opinion']=$u['opinion'];
  2263. $executeCopy[$k]['status']=$u['status'];
  2264. break;
  2265. }
  2266. }
  2267. }
  2268. $receiptList[$key]['executeCopy']=$executeCopy;
  2269. $receiptList[$key]['verifyList']=$verifyList;
  2270. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2271. $receiptList[$key]['button']=$button;
  2272. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2273. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2274. }
  2275. //print_r($receiptList);
  2276. //获取审批日志
  2277. Doo::loadModel('receiptLog');
  2278. $receiptLog=new receiptLog();
  2279. $rlList=array();
  2280. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2281. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2282. if (!empty($rlInfo)){
  2283. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2284. }
  2285. $receiptList[0]['rlList']=$rlList;
  2286. $data['receiptList']=$receiptList;
  2287. $data['memu']="receipt";
  2288. $data['staff']=$this->staff;
  2289. $data['receiptMemu']='approvalExpenses';
  2290. $data['verifyId']=$this->verifyId;
  2291. $data['executeId']=$this->executeId;
  2292. $this->render ( "/admin/expensesDoc", $data );
  2293. }
  2294. function expensesEdi(){
  2295. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2296. $status=isset($this->params['status'])?$this->params['status']:'';
  2297. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2298. $month=$this->get_args('month')?$this->get_args('month'):"";
  2299. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2300. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2301. if (empty($status))
  2302. $status=$this->get_args('status')?$this->get_args('status'):2;
  2303. $vidList=array();
  2304. $button=0;
  2305. Doo::loadModel('verify');
  2306. Doo::loadModel('receipt');
  2307. Doo::loadModel('staff');
  2308. $staff=new staff();
  2309. $receipt=new receipt();
  2310. $verify=new verify();
  2311. Doo::loadModel('L_category');
  2312. $Lcategory=new L_category();
  2313. Doo::loadModel('enclosur');
  2314. $enclosur=new enclosur();
  2315. //user verify ID
  2316. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2317. foreach ($verifyDetail as $key=>$value){
  2318. array_push($vidList, $value['vid']);
  2319. }
  2320. $vid=implode(",", $vidList);
  2321. if(empty($verifyDetail))
  2322. $vid=0;
  2323. $categoryList=$Lcategory->find(array('asArray'=>true));
  2324. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2325. $ap="";
  2326. if($status==4){
  2327. $ap=4;$status=2;
  2328. }
  2329. //get Receipt By verifyID status 2
  2330. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2331. $Locate=0;$roleId=0;
  2332. if($ap==4)
  2333. $status=4;
  2334. foreach ($receiptList as $key=>$value){
  2335. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2336. $receiptList[$key]['reviseDetail']=array();
  2337. if (!empty($value['reviseDetail']))
  2338. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2339. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2340. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2341. $receiptList[$key]['category']=$categoryDetil['title'];
  2342. //检测编辑状态
  2343. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2344. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2345. $verifyStaff=json_decode($value['verifyStaff'],true);
  2346. Doo::loadModel('role');
  2347. $role=new role();
  2348. //print_r($verifyList);
  2349. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2350. foreach ($verifyList as $k=>$v){
  2351. //init verifyStaff
  2352. if ($v[1]=='ROLE'){
  2353. if (!empty($verifyStaff)){
  2354. $endStaffArray=end($verifyStaff);
  2355. if ($v[0]==$endStaffArray['nextStaff']){
  2356. $roleId=$v[0];
  2357. }
  2358. }
  2359. $roleVerify=json_decode($v[3],true);
  2360. $roleKey=$k;$roleArray=array();
  2361. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2362. foreach ($roleVerify as $o=>$p){
  2363. $staffID=explode ('_',$p);
  2364. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2365. //print_r($staffID);
  2366. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2367. array_push($roleArray, $exp);
  2368. }
  2369. $roleArrayCopy[$v[0]]=$roleArray;
  2370. //$verifyList[$k]['roleArray']=$roleArray;
  2371. }
  2372. //print_r($roleArray);
  2373. $verifyList[$k]['date']="";
  2374. $verifyList[$k]['opinion']="";
  2375. $verifyList[$k]['status']="";
  2376. if (empty($verifyStaff)){
  2377. $verifyList[$k]['date']="";
  2378. $verifyList[$k]['opinion']="";
  2379. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2380. $verifyList[$k]['status']=4;
  2381. $button=4;$flag=false;
  2382. }
  2383. }else{
  2384. foreach ($verifyStaff as $m=>$u){
  2385. if ($v[0]==$m){
  2386. $verifyList[$k]['date']=$u['date'];
  2387. $verifyList[$k]['opinion']=$u['opinion'];
  2388. $verifyList[$k]['status']=$u['status'];
  2389. $flag=false;
  2390. break;
  2391. }
  2392. }
  2393. $endStaffArray=end($verifyStaff);
  2394. if (isset($endStaffArray['ROLE'])){
  2395. }else{
  2396. $endKey=key($verifyStaff);
  2397. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2398. $button=4;
  2399. $verifyList[$k]['status']=4;
  2400. }
  2401. }
  2402. }
  2403. }
  2404. $rolename['name']='';
  2405. if (!empty($roleId)){
  2406. Doo::loadModel('role');
  2407. $role=new role();
  2408. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2409. }
  2410. if (!empty($verifyStaff))
  2411. $endStaffArray=end($verifyStaff);
  2412. $KOP=false;
  2413. foreach ($roleArrayCopy as $P=>$A){
  2414. foreach ( $A as $MKI=>$AVL){
  2415. if (!empty($verifyStaff)){
  2416. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2417. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2418. $button=4;
  2419. $roleArrayCopy[$P][$MKI]['status']=4;
  2420. }
  2421. foreach ($verifyStaff as $m=>$u){
  2422. $AVLFK=$AVL[0].'_R';
  2423. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2424. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2425. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2426. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2427. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2428. break;
  2429. }
  2430. }
  2431. }else{
  2432. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2433. $button=4;
  2434. $roleArrayCopy[$P][$MKI]['status']=4;
  2435. }
  2436. }
  2437. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2438. $KOP=true;
  2439. }
  2440. }
  2441. // print_r($roleArrayCopy);
  2442. // echo $roleKey;
  2443. foreach ($roleArrayCopy as $k=>$v){
  2444. foreach ($verifyList as $m=>$n){
  2445. if ($n[0]==$k){
  2446. array_splice($verifyList,$m,1,$v);
  2447. }
  2448. }
  2449. }
  2450. $receiptList[$key]['verifyList']=$verifyList;
  2451. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2452. $receiptList[$key]['button']=$button;
  2453. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2454. }
  2455. //$data['verifyDetail']=$verifyDetail;
  2456. $mothHtml="";
  2457. for($i=1;$i<=12;$i++){
  2458. if($month==$i)
  2459. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2460. else
  2461. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2462. }
  2463. //获取审批日志
  2464. Doo::loadModel('receiptLog');
  2465. $receiptLog=new receiptLog();
  2466. $rlList=array();
  2467. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2468. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2469. if (!empty($rlInfo)){
  2470. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2471. }
  2472. $receiptList[0]['rlList']=$rlList;
  2473. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2474. $enclosurHtml='';
  2475. foreach ($enclosurList as $value){
  2476. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2477. }
  2478. //print_r($receiptList);
  2479. $data['rid']=$rid;
  2480. $data['enclosurHtml']=$enclosurHtml;
  2481. $data['rolename']=$rolename['name'];
  2482. $data['datetij']=$tijdate['date'];
  2483. $data['mothHtml']=$mothHtml;
  2484. $data['receiptList']=$receiptList;
  2485. $data['receiptApprovalCount']=count($receiptList);
  2486. $data['status']=$status;
  2487. $data['year']=$year;
  2488. $data['categoryList']=$categoryList;
  2489. $data['staffList']=$staffList;
  2490. $data['cid']=$cid;
  2491. $data['sid']=$sid;
  2492. $data['ap']=$ap;
  2493. $data['memu']="receipt";
  2494. $data['staff']=$this->staff;
  2495. $data['receiptMemu']='approvalExpenses';
  2496. $data['verifyId']=$this->verifyId;
  2497. $data['executeId']=$this->executeId;
  2498. $this->render ( "/admin/expensesEdi", $data );
  2499. }
  2500. function expensesDefray(){
  2501. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2502. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2503. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2504. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2505. if(!empty($rid)){
  2506. Doo::loadModel("verify");
  2507. $verify=new verify();
  2508. Doo::loadModel("receiptDetail");
  2509. $receiptDetailObj=new receiptDetail();
  2510. Doo::loadModel("itemStatistics");
  2511. Doo::loadModel("statistics");
  2512. $statistics=new statistics();
  2513. $itemStatistics=new itemStatistics();
  2514. Doo::loadModel("receipt");
  2515. $receipt=new receipt();
  2516. Doo::loadModel("loanReceipt");
  2517. $loanReceipt=new loanReceipt();
  2518. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2519. if (empty($receiptDetail))
  2520. return "/approval";
  2521. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2522. $verifyString=$verifyDetail['staff'];
  2523. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2524. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2525. if(empty($opinion)){
  2526. if ($status==3)
  2527. $opinion="终止";
  2528. else
  2529. $opinion="同意支付";
  2530. }
  2531. $nowStaff=0;$nowStaffList=array();
  2532. if(empty($verifyStaff)){
  2533. //还需加入是否已经进入角色审批
  2534. if ($verifyDetail[0][1]=='ROLE'){
  2535. //print_r($verifyDetail);echo "ddd";
  2536. $vStaffString=json_decode($verifyDetail[0][3]);
  2537. foreach ($vStaffString as $key=>$value){
  2538. $staffK=explode("_", $value);
  2539. if ($staffK[0]!=$this->staff[0]['sid'])
  2540. array_push($nowStaffList, $staffK[0]);
  2541. }
  2542. //print_r($verifyDetail);
  2543. //die;
  2544. if (!empty($nowStaffList)){
  2545. $nowStaff=implode(',', $nowStaffList);
  2546. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2547. }else{
  2548. $nowStaff=$verifyDetail[1][0];
  2549. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2550. }
  2551. }else{
  2552. if ($verifyDetail[1][1]=='ROLE'){
  2553. $vStaffString=json_decode($verifyDetail[1][3]);
  2554. //echo "dd";
  2555. foreach ($vStaffString as $key=>$value){
  2556. $staffK=explode("_", $value);
  2557. array_push($nowStaffList, $staffK[0]);
  2558. }
  2559. $nowStaff=implode(',', $nowStaffList);
  2560. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2561. }else{
  2562. $nowStaff=$verifyDetail[1][0];
  2563. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2564. }
  2565. }
  2566. if($status==3)
  2567. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2568. $vStaffString=json_encode($verifyStaff);
  2569. $receipt->nowStaff=$nowStaff;
  2570. $receipt->verifyStaff=$vStaffString;
  2571. $loanReceipt->nowStaff=$nowStaff;
  2572. $loanReceipt->verifyStaff=$vStaffString;
  2573. }else{
  2574. $VS=end($verifyStaff);
  2575. //非角色审批
  2576. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2577. $nextStaff=0;$roleSTF=false;
  2578. foreach ($verifyDetail as $key=>$value){
  2579. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2580. if (isset($verifyDetail[$key+1])){
  2581. $nextStaff=$verifyDetail[$key+1][0];
  2582. if ($verifyDetail[$key+1][1]=='ROLE')
  2583. $roleSTF=true;
  2584. }
  2585. break;
  2586. }
  2587. }
  2588. if (!$roleSTF){
  2589. $nowStaff=$nextStaff;
  2590. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2591. }else{
  2592. //获取角色下的所有用户ID
  2593. $nowStaffList=array();
  2594. foreach ($verifyDetail as $vfk){
  2595. if ($vfk[1]=='ROLE'){
  2596. $vStaffString=json_decode($vfk[3]);
  2597. foreach ($vStaffString as $key=>$value){
  2598. $staffK=explode("_", $value);
  2599. array_push($nowStaffList, $staffK[0]);
  2600. }
  2601. }
  2602. }
  2603. $nowStaff=implode(',', $nowStaffList);
  2604. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2605. }
  2606. if($status==3){
  2607. $verifyStaff['final']=$status;
  2608. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2609. }
  2610. $vStaffString=json_encode($verifyStaff);
  2611. $receipt->nowStaff=$nowStaff;
  2612. $receipt->verifyStaff=$vStaffString;
  2613. $loanReceipt->nowStaff=$nowStaff;
  2614. $loanReceipt->verifyStaff=$vStaffString;
  2615. }
  2616. //角色审批
  2617. if (isset($VS['ROLE'])){
  2618. //找出角色人 当前审批角色组
  2619. $verifyJSStaff=array();$nowStaffList2=array();
  2620. foreach ($verifyDetail as $key=>$value){
  2621. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2622. $verifyJSStaff=json_decode($value[3]);
  2623. foreach ($verifyJSStaff as $m){
  2624. $staffK=explode("_", $m);
  2625. array_push($nowStaffList2, $staffK[0]);
  2626. }
  2627. // print_r($nowStaffList2);
  2628. }
  2629. }
  2630. $RoleVerifyStaff=array();
  2631. foreach ($verifyStaff as $key=>$value){
  2632. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2633. foreach ($nowStaffList2 as $m) {
  2634. if ($key==$m."_R")
  2635. $RoleVerifyStaff[$key]=$value;
  2636. }
  2637. }
  2638. }
  2639. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2640. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2641. //下一个审批人ID
  2642. $nextStaff=0;$falg=false;
  2643. foreach ($verifyDetail as $key=>$value){
  2644. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2645. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2646. $falg=true;
  2647. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2648. foreach ($vStaffString as $v){
  2649. $staffK=explode("_", $v);
  2650. array_push($nowStaffList, $staffK[0]);
  2651. }
  2652. $nowStaff=implode(',', $nowStaffList);
  2653. $nextStaff=$verifyDetail[$key+1][0];
  2654. }elseif(isset($verifyDetail[$key+1])){
  2655. $nextStaff=$verifyDetail[$key+1][0];
  2656. $nowStaff=$nextStaff;
  2657. }else
  2658. $nowStaff='';
  2659. break;
  2660. }
  2661. }
  2662. if ($falg)
  2663. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2664. else
  2665. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2666. // print_r($verifyStaff);
  2667. // echo $nowStaff;die;
  2668. }else{ //进入下一个角色或者审批人
  2669. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2670. //
  2671. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2672. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2673. // print_r($verifyStaff);
  2674. // die;
  2675. }
  2676. if($status==3){
  2677. $verifyStaff['final']=$status;
  2678. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2679. }
  2680. $vStaffString=json_encode($verifyStaff);
  2681. $receipt->verifyStaff=$vStaffString;
  2682. $receipt->nowStaff=$nowStaff;
  2683. $loanReceipt->nowStaff=$nowStaff;
  2684. $loanReceipt->verifyStaff=$vStaffString;
  2685. //die;
  2686. //}
  2687. // print_r($verifyStaff);
  2688. // die;
  2689. }
  2690. //print_r($verifyStaff);die;
  2691. }
  2692. //print_r($verifyDetail);
  2693. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2694. foreach ($verifyDetail as $k=>$v){
  2695. if ($v[1]=='ROLE'){
  2696. $roleId=$v[0];
  2697. $roleVerify=json_decode($v[3],true);
  2698. $roleKey=$k;$roleArray=array();
  2699. foreach ($roleVerify as $o=>$p){
  2700. $staffID=explode ('_',$p);
  2701. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2702. array_push($roleArray, $exp);
  2703. }
  2704. $verifyDetailCopy[$v[0]]=$roleArray;
  2705. }
  2706. }
  2707. //print_r($verifyDetail);
  2708. foreach ($verifyDetailCopy as $k=>$v){
  2709. foreach ($verifyDetail as $m=>$n){
  2710. if ($n[0]==$k){
  2711. array_splice($verifyDetail,$m,1,$v);
  2712. }
  2713. }
  2714. }
  2715. //审批日志
  2716. if (!isset($verifyStaff['final'])){
  2717. Doo::loadModel("receiptLog");
  2718. $receiptLog=new receiptLog();
  2719. if (!empty($roleId)){
  2720. Doo::loadModel("role");
  2721. $role=new role();
  2722. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2723. $receiptLog->rolename=$roleInfo['name'];
  2724. }
  2725. $receiptLog->username=$this->staff[0]['username'];
  2726. $receiptLog->uid=$this->staff[0]['sid'];
  2727. $receiptLog->date=date("Y-m-d");
  2728. $receiptLog->opinion=$opinion;
  2729. $receiptLog->img=$this->staff[0]['avatar'];
  2730. $receiptLog->status=1;
  2731. $receiptLog->rid=$rid;
  2732. $receiptLog->insert();
  2733. }
  2734. if (isset($verifyStaff['final'])){//rDetail
  2735. $receipt->status=3;
  2736. $receipt->verifyBreakup=$verifyString;
  2737. $receiptDetailObj->status=3;
  2738. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2739. //微信企业号通知
  2740. $this->setWXMsg($rid,3);
  2741. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2742. $receipt->status=6;
  2743. $receipt->pastDate=date("Y-m-d");
  2744. $receipt->isBK=1;
  2745. $loanReceipt->verifyBreakup=$verifyString;
  2746. $loanReceipt->status=1;
  2747. $loanReceipt->pastDate=date("Y-m-d");
  2748. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2749. //微信企业号通知
  2750. $this->setWXMsg($rid,1);
  2751. }
  2752. $receipt->update(array('where'=>' rid = '.$rid));
  2753. return "/approvalExpenses/2";
  2754. }
  2755. }
  2756. function implement(){
  2757. Doo::loadModel('receipt');
  2758. $receipt=new receipt();
  2759. Doo::loadModel('L_category');
  2760. $Lcategory=new L_category();
  2761. Doo::loadModel('verify');
  2762. $verify=new verify();
  2763. Doo::loadModel('staff');
  2764. $staff=new staff();
  2765. Doo::loadModel("execute");
  2766. $execute=new execute();
  2767. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2768. Doo::loadModel('loanReceipt');
  2769. $loanReceipt=new loanReceipt();
  2770. //print_r($receiptList);
  2771. $loanList=array();
  2772. if (!isset($receiptList))
  2773. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2774. $Locate=0;$roleId=0;$button=0;
  2775. foreach ($loanList as $key=>$value){
  2776. $loanList[$key]['Locate']=$Locate;$Locate++;
  2777. $loanList[$key]['reviseDetail']=array();
  2778. if (!empty($value['reviseDetail']))
  2779. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2780. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2781. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2782. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2783. $loanList[$key]['category']=$categoryDetil['title'];
  2784. //检测编辑状态
  2785. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2786. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2787. $verifyStaff=json_decode($value['verifyStaff'],true);
  2788. Doo::loadModel('role');
  2789. $role=new role();
  2790. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2791. foreach ($verifyList as $k=>$v){
  2792. //init verifyStaff
  2793. if ($v[1]=='ROLE'){
  2794. if (!empty($verifyStaff)){
  2795. $endStaffArray=end($verifyStaff);
  2796. // if ($v[0]==$endStaffArray['nextStaff']){
  2797. // $roleId=$v[0];
  2798. // }
  2799. }
  2800. $roleVerify=json_decode($v[3],true);
  2801. $roleKey=$k;$roleArray=array();
  2802. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2803. foreach ($roleVerify as $o=>$p){
  2804. $staffID=explode ('_',$p);
  2805. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2806. //print_r($staffID);
  2807. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2808. array_push($roleArray, $exp);
  2809. }
  2810. $roleArrayCopy[$v[0]]=$roleArray;
  2811. //$verifyList[$k]['roleArray']=$roleArray;
  2812. }
  2813. $verifyList[$k]['date']="";
  2814. $verifyList[$k]['opinion']="";
  2815. $verifyList[$k]['status']="";
  2816. if (empty($verifyStaff)){
  2817. $verifyList[$k]['date']="";
  2818. $verifyList[$k]['opinion']="";
  2819. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2820. $verifyList[$k]['status']=4;
  2821. $flag=false;
  2822. }
  2823. }else{
  2824. foreach ($verifyStaff as $m=>$u){
  2825. if ($v[0]==$m){
  2826. $verifyList[$k]['date']=$u['date'];
  2827. $verifyList[$k]['opinion']=$u['opinion'];
  2828. $verifyList[$k]['status']=$u['status'];
  2829. $flag=false;
  2830. break;
  2831. }
  2832. }
  2833. $endStaffArray=end($verifyStaff);
  2834. if (isset($endStaffArray['ROLE'])){
  2835. }else{
  2836. // $endKey=key($verifyStaff);
  2837. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2838. // $button=4;
  2839. // $verifyList[$k]['status']=4;
  2840. // }
  2841. }
  2842. }
  2843. }
  2844. $rolename['name']='';
  2845. if (!empty($roleId)){
  2846. Doo::loadModel('role');
  2847. $role=new role();
  2848. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2849. }
  2850. if (!empty($verifyStaff))
  2851. $endStaffArray=end($verifyStaff);
  2852. $KOP=false;
  2853. foreach ($roleArrayCopy as $P=>$A){
  2854. foreach ( $A as $MKI=>$AVL){
  2855. if (!empty($verifyStaff)){
  2856. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2857. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2858. $button=4;
  2859. $roleArrayCopy[$P][$MKI]['status']=4;
  2860. }
  2861. foreach ($verifyStaff as $m=>$u){
  2862. $AVLFK=$AVL[0].'_R';
  2863. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2864. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2865. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2866. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2867. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2868. break;
  2869. }
  2870. }
  2871. }else{
  2872. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2873. $button=4;
  2874. $roleArrayCopy[$P][$MKI]['status']=4;
  2875. }
  2876. }
  2877. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2878. $KOP=true;
  2879. }
  2880. }
  2881. foreach ($roleArrayCopy as $k=>$v){
  2882. foreach ($verifyList as $m=>$n){
  2883. if ($n[0]==$k){
  2884. array_splice($verifyList,$m,1,$v);
  2885. }
  2886. }
  2887. }
  2888. $loanList[$key]['verifyList']=$verifyList;
  2889. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2890. }
  2891. $data['loanList']=$loanList;
  2892. $Locate=0;$roleId=0;$button=0;
  2893. foreach ($receiptList as $key=>$value){
  2894. $button2=0;
  2895. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2896. $receiptList[$key]['reviseDetail']=array();
  2897. if (!empty($value['reviseDetail']))
  2898. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2899. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2900. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2901. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2902. $receiptList[$key]['category']=$categoryDetil['title'];
  2903. $executeList=json_decode($value['executeCopy'],true);
  2904. $executeStaff=array();
  2905. if (!empty($value['executeStaff'] ))
  2906. $executeStaff=json_decode($value['executeStaff'],true);
  2907. if (isset($executeList)){
  2908. foreach ($executeList as $op=>$lo){
  2909. $executeList[$op]['date']="";
  2910. $executeList[$op]['opinion']="";
  2911. $executeList[$op]['status']="";
  2912. foreach ($executeStaff as $m=>$u){
  2913. if ($lo[0]==$m){
  2914. $executeList[$op]['date']=$u['date'];
  2915. $executeList[$op]['opinion']=$u['opinion'];
  2916. $executeList[$op]['status']=$u['status'];
  2917. break;
  2918. }
  2919. }
  2920. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2921. $button2=1;
  2922. $executeList[$op]['status']=4;
  2923. }
  2924. }
  2925. }
  2926. //检测编辑状态
  2927. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2928. $verifyList['staff']=$value['verifyBreakup'];
  2929. }else
  2930. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2931. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2932. $verifyStaff=json_decode($value['verifyStaff'],true);
  2933. Doo::loadModel('role');
  2934. $role=new role();
  2935. if ($verifyList==NULL)
  2936. $verifyList=array();
  2937. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2938. foreach ($verifyList as $k=>$v){
  2939. //init verifyStaff
  2940. if ($v[1]=='ROLE'){
  2941. if (!empty($verifyStaff)){
  2942. $endStaffArray=end($verifyStaff);
  2943. // if ($v[0]==$endStaffArray['nextStaff']){
  2944. // $roleId=$v[0];
  2945. // }
  2946. }
  2947. $roleVerify=json_decode($v[3],true);
  2948. $roleKey=$k;$roleArray=array();
  2949. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2950. foreach ($roleVerify as $o=>$p){
  2951. $staffID=explode ('_',$p);
  2952. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2953. //print_r($staffID);
  2954. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2955. array_push($roleArray, $exp);
  2956. }
  2957. $roleArrayCopy[$v[0]]=$roleArray;
  2958. //$verifyList[$k]['roleArray']=$roleArray;
  2959. }
  2960. $verifyList[$k]['date']="";
  2961. $verifyList[$k]['opinion']="";
  2962. $verifyList[$k]['status']="";
  2963. if (empty($verifyStaff)){
  2964. $verifyList[$k]['date']="";
  2965. $verifyList[$k]['opinion']="";
  2966. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2967. $verifyList[$k]['status']=4;
  2968. $flag=false;
  2969. }
  2970. }else{
  2971. foreach ($verifyStaff as $m=>$u){
  2972. if ($v[0]==$m){
  2973. $verifyList[$k]['date']=$u['date'];
  2974. $verifyList[$k]['opinion']=$u['opinion'];
  2975. $verifyList[$k]['status']=$u['status'];
  2976. $flag=false;
  2977. break;
  2978. }
  2979. }
  2980. $endStaffArray=end($verifyStaff);
  2981. if (isset($endStaffArray['ROLE'])){
  2982. }else{
  2983. // $endKey=key($verifyStaff);
  2984. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2985. // $button=4;
  2986. // $verifyList[$k]['status']=4;
  2987. // }
  2988. }
  2989. }
  2990. }
  2991. $rolename['name']='';
  2992. if (!empty($roleId)){
  2993. Doo::loadModel('role');
  2994. $role=new role();
  2995. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2996. }
  2997. if (!empty($verifyStaff))
  2998. $endStaffArray=end($verifyStaff);
  2999. $KOP=false;
  3000. foreach ($roleArrayCopy as $P=>$A){
  3001. foreach ( $A as $MKI=>$AVL){
  3002. if (!empty($verifyStaff)){
  3003. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3004. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3005. $button=4;
  3006. $roleArrayCopy[$P][$MKI]['status']=4;
  3007. }
  3008. foreach ($verifyStaff as $m=>$u){
  3009. $AVLFK=$AVL[0].'_R';
  3010. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3011. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3012. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3013. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3014. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3015. break;
  3016. }
  3017. }
  3018. }else{
  3019. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3020. $button=4;
  3021. $roleArrayCopy[$P][$MKI]['status']=4;
  3022. }
  3023. }
  3024. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3025. $KOP=true;
  3026. }
  3027. }
  3028. foreach ($roleArrayCopy as $k=>$v){
  3029. foreach ($verifyList as $m=>$n){
  3030. if ($n[0]==$k){
  3031. array_splice($verifyList,$m,1,$v);
  3032. }
  3033. }
  3034. }
  3035. $receiptList[$key]['verifyList']=$verifyList;
  3036. $receiptList[$key]['executeList']=$executeList;
  3037. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3038. $receiptList[$key]['button2']=$button2;
  3039. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3040. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3041. $relust=$value['sum']-$value['loanSum'];
  3042. $receiptList[$key]['relust']=$relust;
  3043. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3044. }
  3045. //print_r($receiptList[$key]['executeList']);
  3046. $data['receiptList']=$receiptList;
  3047. $data['memu']="receipt";
  3048. $data['staff']=$this->staff;
  3049. $data['receiptMemu']='implement';
  3050. $data['verifyId']=$this->verifyId;
  3051. $data['executeId']=$this->executeId;
  3052. $this->render ( "/admin/implement", $data );
  3053. }
  3054. function implementDo(){
  3055. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3056. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3057. if (!empty($rid)){
  3058. Doo::loadModel('receipt');
  3059. $receipt=new receipt();
  3060. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3061. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3062. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3063. if(empty($executeStaff)){
  3064. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3065. }else{
  3066. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3067. }
  3068. if (count($executeStaff)==count($executeCopy)){
  3069. $receipt->executeStaff=json_encode($executeStaff);
  3070. $receipt->status=8;
  3071. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3072. $receipt->status=9;
  3073. $receipt->executeDate= date("Y-m-d");
  3074. }else{
  3075. $receipt->executeStaff=json_encode($executeStaff);
  3076. }
  3077. $receipt->update(array('where'=>'rid='.$rid));
  3078. }
  3079. return "/implement";
  3080. }
  3081. function receiptburEdi(){
  3082. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3083. $status=isset($this->params['status'])?$this->params['status']:'';
  3084. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3085. $month=$this->get_args('month')?$this->get_args('month'):"";
  3086. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3087. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3088. if (empty($status))
  3089. $status=$this->get_args('status')?$this->get_args('status'):2;
  3090. $vidList=array();
  3091. $button=0;
  3092. Doo::loadModel('verify');
  3093. Doo::loadModel('receipt');
  3094. Doo::loadModel('staff');
  3095. $staff=new staff();
  3096. $receipt=new receipt();
  3097. $verify=new verify();
  3098. Doo::loadModel('L_category');
  3099. $Lcategory=new L_category();
  3100. Doo::loadModel('enclosur');
  3101. $enclosur=new enclosur();
  3102. Doo::loadModel('loanReceipt');
  3103. $loanReceipt=new loanReceipt();
  3104. //user verify ID
  3105. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3106. foreach ($verifyDetail as $key=>$value){
  3107. array_push($vidList, $value['vid']);
  3108. }
  3109. $vid=implode(",", $vidList);
  3110. if(empty($verifyDetail))
  3111. $vid=0;
  3112. $categoryList=$Lcategory->find(array('asArray'=>true));
  3113. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3114. $ap="";
  3115. if($status==4){
  3116. $ap=4;$status=2;
  3117. }
  3118. //get Receipt By verifyID status 2
  3119. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3120. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3121. $Locate=0;$roleId=0;$button=0;
  3122. foreach ($loanList as $key=>$value){
  3123. $loanList[$key]['Locate']=$Locate;$Locate++;
  3124. $loanList[$key]['reviseDetail']=array();
  3125. if (!empty($value['reviseDetail']))
  3126. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3127. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3128. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3129. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3130. $loanList[$key]['category']=$categoryDetil['title'];
  3131. //检测编辑状态
  3132. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3133. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3134. $verifyStaff=json_decode($value['verifyStaff'],true);
  3135. Doo::loadModel('role');
  3136. $role=new role();
  3137. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3138. foreach ($verifyList as $k=>$v){
  3139. //init verifyStaff
  3140. if ($v[1]=='ROLE'){
  3141. if (!empty($verifyStaff)){
  3142. $endStaffArray=end($verifyStaff);
  3143. }
  3144. $roleVerify=json_decode($v[3],true);
  3145. $roleKey=$k;$roleArray=array();
  3146. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3147. foreach ($roleVerify as $o=>$p){
  3148. $staffID=explode ('_',$p);
  3149. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3150. //print_r($staffID);
  3151. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3152. array_push($roleArray, $exp);
  3153. }
  3154. $roleArrayCopy[$v[0]]=$roleArray;
  3155. //$verifyList[$k]['roleArray']=$roleArray;
  3156. }
  3157. $verifyList[$k]['date']="";
  3158. $verifyList[$k]['opinion']="";
  3159. $verifyList[$k]['status']="";
  3160. if (empty($verifyStaff)){
  3161. $verifyList[$k]['date']="";
  3162. $verifyList[$k]['opinion']="";
  3163. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3164. $verifyList[$k]['status']=4;
  3165. $flag=false;
  3166. }
  3167. }else{
  3168. foreach ($verifyStaff as $m=>$u){
  3169. if ($v[0]==$m){
  3170. $verifyList[$k]['date']=$u['date'];
  3171. $verifyList[$k]['opinion']=$u['opinion'];
  3172. $verifyList[$k]['status']=$u['status'];
  3173. $flag=false;
  3174. break;
  3175. }
  3176. }
  3177. $endStaffArray=end($verifyStaff);
  3178. if (isset($endStaffArray['ROLE'])){
  3179. }else{
  3180. }
  3181. }
  3182. }
  3183. $rolename['name']='';
  3184. if (!empty($roleId)){
  3185. Doo::loadModel('role');
  3186. $role=new role();
  3187. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3188. }
  3189. if (!empty($verifyStaff))
  3190. $endStaffArray=end($verifyStaff);
  3191. $KOP=false;
  3192. foreach ($roleArrayCopy as $P=>$A){
  3193. foreach ( $A as $MKI=>$AVL){
  3194. if (!empty($verifyStaff)){
  3195. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3196. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3197. $button=4;
  3198. $roleArrayCopy[$P][$MKI]['status']=4;
  3199. }
  3200. foreach ($verifyStaff as $m=>$u){
  3201. $AVLFK=$AVL[0].'_R';
  3202. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3203. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3204. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3205. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3206. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3207. break;
  3208. }
  3209. }
  3210. }else{
  3211. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3212. $button=4;
  3213. $roleArrayCopy[$P][$MKI]['status']=4;
  3214. }
  3215. }
  3216. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3217. $KOP=true;
  3218. }
  3219. }
  3220. foreach ($roleArrayCopy as $k=>$v){
  3221. foreach ($verifyList as $m=>$n){
  3222. if ($n[0]==$k){
  3223. array_splice($verifyList,$m,1,$v);
  3224. }
  3225. }
  3226. }
  3227. $loanList[$key]['verifyList']=$verifyList;
  3228. }
  3229. $htmlLoan='';
  3230. if (isset($loanList[0])){
  3231. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3232. if ($value['status']==1)
  3233. $htmlLoan.='<li class="done" >';
  3234. elseif ($value['status']==3)
  3235. $htmlLoan.='<li class="undone" >';
  3236. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3237. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3238. if (isset($value['rolename']))
  3239. $htmlLoan.=$value['rolename'];
  3240. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3241. }
  3242. $data['loanDate']=$loanList[0]['date'];
  3243. }
  3244. $data['htmlLoan']=$htmlLoan;
  3245. //print_r($loanList);
  3246. $Locate=0;$roleId=0;$button=0;
  3247. if($ap==4)
  3248. $status=4;
  3249. foreach ($receiptList as $key=>$value){
  3250. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3251. $receiptList[$key]['reviseDetail']=array();
  3252. if (!empty($value['reviseDetail']))
  3253. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3254. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3255. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3256. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3257. $receiptList[$key]['category']=$categoryDetil['title'];
  3258. //检测编辑状态
  3259. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3260. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3261. $verifyStaff=json_decode($value['verifyStaff'],true);
  3262. Doo::loadModel('role');
  3263. $role=new role();
  3264. //print_r($verifyList);
  3265. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3266. foreach ($verifyList as $k=>$v){
  3267. //init verifyStaff
  3268. if ($v[1]=='ROLE'){
  3269. if (!empty($verifyStaff)){
  3270. $endStaffArray=end($verifyStaff);
  3271. if ($v[0]==$endStaffArray['nextStaff']){
  3272. $roleId=$v[0];
  3273. }
  3274. }
  3275. $roleVerify=json_decode($v[3],true);
  3276. $roleKey=$k;$roleArray=array();
  3277. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3278. foreach ($roleVerify as $o=>$p){
  3279. $staffID=explode ('_',$p);
  3280. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3281. //print_r($staffID);
  3282. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3283. array_push($roleArray, $exp);
  3284. }
  3285. $roleArrayCopy[$v[0]]=$roleArray;
  3286. //$verifyList[$k]['roleArray']=$roleArray;
  3287. }
  3288. //print_r($roleArray);
  3289. $verifyList[$k]['date']="";
  3290. $verifyList[$k]['opinion']="";
  3291. $verifyList[$k]['status']="";
  3292. if (empty($verifyStaff)){
  3293. $verifyList[$k]['date']="";
  3294. $verifyList[$k]['opinion']="";
  3295. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3296. $verifyList[$k]['status']=4;
  3297. $button=4;$flag=false;
  3298. }
  3299. }else{
  3300. foreach ($verifyStaff as $m=>$u){
  3301. if ($v[0]==$m){
  3302. $verifyList[$k]['date']=$u['date'];
  3303. $verifyList[$k]['opinion']=$u['opinion'];
  3304. $verifyList[$k]['status']=$u['status'];
  3305. $flag=false;
  3306. break;
  3307. }
  3308. }
  3309. $endStaffArray=end($verifyStaff);
  3310. if (isset($endStaffArray['ROLE'])){
  3311. }else{
  3312. $endKey=key($verifyStaff);
  3313. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3314. $button=4;
  3315. $verifyList[$k]['status']=4;
  3316. }
  3317. }
  3318. }
  3319. }
  3320. $rolename['name']='';
  3321. if (!empty($roleId)){
  3322. Doo::loadModel('role');
  3323. $role=new role();
  3324. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3325. }
  3326. if (!empty($verifyStaff))
  3327. $endStaffArray=end($verifyStaff);
  3328. $KOP=false;
  3329. foreach ($roleArrayCopy as $P=>$A){
  3330. foreach ( $A as $MKI=>$AVL){
  3331. if (!empty($verifyStaff)){
  3332. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3333. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3334. $button=4;
  3335. $roleArrayCopy[$P][$MKI]['status']=4;
  3336. }
  3337. foreach ($verifyStaff as $m=>$u){
  3338. $AVLFK=$AVL[0].'_R';
  3339. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3340. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3341. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3342. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3343. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3344. break;
  3345. }
  3346. }
  3347. }else{
  3348. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3349. $button=4;
  3350. $roleArrayCopy[$P][$MKI]['status']=4;
  3351. }
  3352. }
  3353. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3354. $KOP=true;
  3355. }
  3356. }
  3357. foreach ($roleArrayCopy as $k=>$v){
  3358. foreach ($verifyList as $m=>$n){
  3359. if ($n[0]==$k){
  3360. array_splice($verifyList,$m,1,$v);
  3361. }
  3362. }
  3363. }
  3364. //print_r($verifyList);
  3365. $receiptList[$key]['verifyList']=$verifyList;
  3366. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3367. $receiptList[$key]['button']=$button;
  3368. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3369. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3370. $relust=$value['sum']-$value['loanSum'];
  3371. $receiptList[$key]['relust']=$relust;
  3372. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3373. }
  3374. //print_r($receiptList);die;
  3375. //$data['verifyDetail']=$verifyDetail;
  3376. $mothHtml="";
  3377. for($i=1;$i<=12;$i++){
  3378. if($month==$i)
  3379. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3380. else
  3381. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3382. }
  3383. //获取审批日志
  3384. Doo::loadModel('receiptLog');
  3385. $receiptLog=new receiptLog();
  3386. $rlList=array();
  3387. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3388. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3389. if (!empty($rlInfo)){
  3390. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3391. }
  3392. //echo $rid;
  3393. //print_r($receiptList);
  3394. $receiptList[0]['rlList']=$rlList;
  3395. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3396. $enclosurHtml='';
  3397. foreach ($enclosurList as $value){
  3398. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3399. }
  3400. $data['enclosurHtml']=$enclosurHtml;
  3401. $data['rolename']=$rolename['name'];
  3402. // $data['datetij']=$tijdate['date'];
  3403. $data['mothHtml']=$mothHtml;
  3404. //print_r($receiptList);
  3405. $data['rid']=$rid;
  3406. $data['tijdate']=$tijdate['date'];
  3407. $data['receiptList']=$receiptList;
  3408. $data['receiptApprovalCount']=count($receiptList);
  3409. $data['status']=$status;
  3410. $data['year']=$year;
  3411. $data['categoryList']=$categoryList;
  3412. $data['staffList']=$staffList;
  3413. $data['cid']=$cid;
  3414. $data['sid']=$sid;
  3415. $data['ap']=$ap;
  3416. $data['memu']="receipt";
  3417. $data['staff']=$this->staff;
  3418. $data['receiptMemu']='approvalExpenses';
  3419. $data['verifyId']=$this->verifyId;
  3420. $data['executeId']=$this->executeId;
  3421. $this->render ( "/admin/receiptburEdi", $data );
  3422. }
  3423. function hisImplement(){
  3424. $item=isset($this->params['item'])?$this->params['item']:"";
  3425. if(empty($item))
  3426. $item=$this->get_args('item')?$this->get_args('item'):"";
  3427. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3428. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3429. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3430. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3431. Doo::loadModel('receipt');
  3432. $receipt=new receipt();
  3433. Doo::loadModel('L_category');
  3434. $Lcategory=new L_category();
  3435. Doo::loadModel('verify');
  3436. Doo::loadModel('statistics');
  3437. $statistics=new statistics();
  3438. $verify=new verify();
  3439. Doo::loadModel('staff');
  3440. $staff=new staff();
  3441. $condition="";
  3442. if($item=="expenses")
  3443. $condition=" and Rtype=1 ";
  3444. elseif ($item=="receipts")
  3445. $condition=" and Rtype=0 ";
  3446. elseif ($item=="remits")
  3447. $condition=" and Rtype=2 ";
  3448. $sopString="";
  3449. $dateCondition=" and Year(executeDate) =".$year;
  3450. if($moth!='MONTH'){
  3451. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3452. }
  3453. if($day!='DAY')
  3454. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3455. if ($sop!='SOP')
  3456. $sopString=" and staff=".$sop;
  3457. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3458. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3459. //员工筛选
  3460. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3461. $sopStaff=array();
  3462. foreach ($receiptList2 as $key=>$value){
  3463. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3464. $sopStaff[$value['staff']]=$staffDetail['username'];
  3465. }
  3466. $Locate=0;$roleId=0;$button=0;
  3467. foreach ($receiptList as $key=>$value){
  3468. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3469. $receiptList[$key]['reviseDetail']=array();
  3470. if (!empty($value['reviseDetail']))
  3471. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3472. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3473. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3474. $receiptList[$key]['category']=$categoryDetil['title'];
  3475. //检测编辑状态
  3476. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3477. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3478. $verifyStaff=json_decode($value['verifyStaff'],true);
  3479. Doo::loadModel('role');
  3480. $role=new role();
  3481. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3482. foreach ($verifyList as $k=>$v){
  3483. //init verifyStaff
  3484. if ($v[1]=='ROLE'){
  3485. if (!empty($verifyStaff)){
  3486. $endStaffArray=end($verifyStaff);
  3487. }
  3488. $roleVerify=json_decode($v[3],true);
  3489. $roleKey=$k;$roleArray=array();
  3490. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3491. foreach ($roleVerify as $o=>$p){
  3492. $staffID=explode ('_',$p);
  3493. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3494. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3495. array_push($roleArray, $exp);
  3496. }
  3497. $roleArrayCopy[$v[0]]=$roleArray;
  3498. }
  3499. $verifyList[$k]['date']="";
  3500. $verifyList[$k]['opinion']="";
  3501. $verifyList[$k]['status']="";
  3502. if (empty($verifyStaff)){
  3503. $verifyList[$k]['date']="";
  3504. $verifyList[$k]['opinion']="";
  3505. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3506. $verifyList[$k]['status']=4;
  3507. $flag=false;
  3508. }
  3509. }else{
  3510. foreach ($verifyStaff as $m=>$u){
  3511. if ($v[0]==$m){
  3512. $verifyList[$k]['date']=$u['date'];
  3513. $verifyList[$k]['opinion']=$u['opinion'];
  3514. $verifyList[$k]['status']=$u['status'];
  3515. $flag=false;
  3516. break;
  3517. }
  3518. }
  3519. $endStaffArray=end($verifyStaff);
  3520. }
  3521. }
  3522. $rolename['name']='';
  3523. if (!empty($roleId)){
  3524. Doo::loadModel('role');
  3525. $role=new role();
  3526. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3527. }
  3528. if (!empty($verifyStaff))
  3529. $endStaffArray=end($verifyStaff);
  3530. $KOP=false;
  3531. foreach ($roleArrayCopy as $P=>$A){
  3532. foreach ( $A as $MKI=>$AVL){
  3533. if (!empty($verifyStaff)){
  3534. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3535. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3536. $button=4;
  3537. $roleArrayCopy[$P][$MKI]['status']=4;
  3538. }
  3539. foreach ($verifyStaff as $m=>$u){
  3540. $AVLFK=$AVL[0].'_R';
  3541. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3542. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3543. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3544. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3545. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3546. break;
  3547. }
  3548. }
  3549. }else{
  3550. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3551. $button=4;
  3552. $roleArrayCopy[$P][$MKI]['status']=4;
  3553. }
  3554. }
  3555. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3556. $KOP=true;
  3557. }
  3558. }
  3559. foreach ($roleArrayCopy as $k=>$v){
  3560. foreach ($verifyList as $m=>$n){
  3561. if ($n[0]==$k){
  3562. array_splice($verifyList,$m,1,$v);
  3563. }
  3564. }
  3565. }
  3566. $receiptList[$key]['verifyList']=$verifyList;
  3567. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3568. $receiptList[$key]['button']=$button;
  3569. }
  3570. //print_r($sopStaff);
  3571. $mothHtml="";
  3572. for($i=1;$i<=12;$i++){
  3573. if($moth==$i)
  3574. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3575. else
  3576. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3577. }
  3578. $dayHtml="";
  3579. if ($day!="DAY"||$moth!="MONTH"){
  3580. for($i = 1; $i <= 31; $i ++) {
  3581. if($day==$i)
  3582. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3583. else
  3584. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3585. }
  3586. }
  3587. $sopHtml="";
  3588. foreach ($sopStaff as $key=>$value){
  3589. if($sop==$key)
  3590. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3591. else
  3592. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3593. }
  3594. $data['sopHtml']=$sopHtml;
  3595. $data['dayHtml']=$dayHtml;
  3596. $data['mothHtml']=$mothHtml;
  3597. $data['receiptList']=$receiptList;
  3598. $data['memu']="receipt";
  3599. $data['staff']=$this->staff;
  3600. $data['receiptMemu']='implement';
  3601. $data['verifyId']=$this->verifyId;
  3602. $data['executeId']=$this->executeId;
  3603. $data['item']=$item;
  3604. $data['year']=$year;
  3605. $data['moth']=$moth;
  3606. $data['day']=$day;
  3607. $data['sop']=$sop;
  3608. $this->render ( "/admin/hisImplement", $data );
  3609. }
  3610. function ajaxExamine(){
  3611. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3612. Doo::loadModel('receipt');
  3613. $receipt=new receipt();
  3614. if (!empty($rid)){
  3615. $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
  3616. ,'asArray'=>true));
  3617. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3618. }
  3619. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3620. }
  3621. /*
  3622. * 废弃
  3623. */
  3624. function myReceipt(){
  3625. //all approval past withdraw
  3626. $item=isset($this->params['item'])?$this->params['item']:"";
  3627. if(empty($item))
  3628. $item=$this->get_args('item')?$this->get_args('item'):"";
  3629. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3630. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3631. Doo::loadModel('receipt');
  3632. $receipt=new receipt();
  3633. //pre-loaded
  3634. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3635. //have cache
  3636. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3637. if(!empty($moth))//yearPage
  3638. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3639. $this->showCache($path);
  3640. }
  3641. Doo::loadModel('L_category');
  3642. $Lcategory=new L_category();
  3643. Doo::loadModel('verify');
  3644. Doo::loadModel('statistics');
  3645. $statistics=new statistics();
  3646. $verify=new verify();
  3647. Doo::loadModel('staff');
  3648. $staff=new staff();
  3649. $condition=" and status!=0 ";
  3650. if($item=="approval")
  3651. $condition=" and status=2 ";
  3652. elseif ($item=="withdraw")
  3653. $condition=" and status=3 ";
  3654. elseif ($item=="past")
  3655. $condition=" and status=1 ";
  3656. elseif ($item=="whdw")
  3657. $condition=" and status=4 ";
  3658. $dateCondition=" and Year(date) =".$year;
  3659. if(!empty($moth)){
  3660. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3661. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3662. }else
  3663. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3664. if(empty($stList))
  3665. $stList=array('rePrice'=>0,'agPrice'=>0);
  3666. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3667. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3668. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3669. $Locate=0;$roleId=0;$button=0;
  3670. foreach ($receiptList as $key=>$value){
  3671. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3672. $receiptList[$key]['reviseDetail']=array();
  3673. if (!empty($value['reviseDetail']))
  3674. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3675. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3676. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3677. $receiptList[$key]['category']=$categoryDetil['title'];
  3678. //检测编辑状态
  3679. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3680. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3681. $verifyStaff=json_decode($value['verifyStaff'],true);
  3682. Doo::loadModel('role');
  3683. $role=new role();
  3684. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3685. foreach ($verifyList as $k=>$v){
  3686. //init verifyStaff
  3687. if ($v[1]=='ROLE'){
  3688. if (!empty($verifyStaff)){
  3689. $endStaffArray=end($verifyStaff);
  3690. // if ($v[0]==$endStaffArray['nextStaff']){
  3691. // $roleId=$v[0];
  3692. // }
  3693. }
  3694. $roleVerify=json_decode($v[3],true);
  3695. $roleKey=$k;$roleArray=array();
  3696. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3697. foreach ($roleVerify as $o=>$p){
  3698. $staffID=explode ('_',$p);
  3699. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3700. //print_r($staffID);
  3701. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3702. array_push($roleArray, $exp);
  3703. }
  3704. $roleArrayCopy[$v[0]]=$roleArray;
  3705. //$verifyList[$k]['roleArray']=$roleArray;
  3706. }
  3707. $verifyList[$k]['date']="";
  3708. $verifyList[$k]['opinion']="";
  3709. $verifyList[$k]['status']="";
  3710. if (empty($verifyStaff)){
  3711. $verifyList[$k]['date']="";
  3712. $verifyList[$k]['opinion']="";
  3713. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3714. $verifyList[$k]['status']=4;
  3715. $flag=false;
  3716. }
  3717. }else{
  3718. foreach ($verifyStaff as $m=>$u){
  3719. if ($v[0]==$m){
  3720. $verifyList[$k]['date']=$u['date'];
  3721. $verifyList[$k]['opinion']=$u['opinion'];
  3722. $verifyList[$k]['status']=$u['status'];
  3723. $flag=false;
  3724. break;
  3725. }
  3726. }
  3727. $endStaffArray=end($verifyStaff);
  3728. if (isset($endStaffArray['ROLE'])){
  3729. }else{
  3730. // $endKey=key($verifyStaff);
  3731. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3732. // $button=4;
  3733. // $verifyList[$k]['status']=4;
  3734. // }
  3735. }
  3736. }
  3737. }
  3738. $rolename['name']='';
  3739. if (!empty($roleId)){
  3740. Doo::loadModel('role');
  3741. $role=new role();
  3742. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3743. }
  3744. if (!empty($verifyStaff))
  3745. $endStaffArray=end($verifyStaff);
  3746. $KOP=false;
  3747. foreach ($roleArrayCopy as $P=>$A){
  3748. foreach ( $A as $MKI=>$AVL){
  3749. if (!empty($verifyStaff)){
  3750. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3751. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3752. $button=4;
  3753. $roleArrayCopy[$P][$MKI]['status']=4;
  3754. }
  3755. foreach ($verifyStaff as $m=>$u){
  3756. $AVLFK=$AVL[0].'_R';
  3757. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3758. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3759. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3760. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3761. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3762. break;
  3763. }
  3764. }
  3765. }else{
  3766. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3767. $button=4;
  3768. $roleArrayCopy[$P][$MKI]['status']=4;
  3769. }
  3770. }
  3771. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3772. $KOP=true;
  3773. }
  3774. }
  3775. foreach ($roleArrayCopy as $k=>$v){
  3776. foreach ($verifyList as $m=>$n){
  3777. if ($n[0]==$k){
  3778. array_splice($verifyList,$m,1,$v);
  3779. }
  3780. }
  3781. }
  3782. $receiptList[$key]['verifyList']=$verifyList;
  3783. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3784. $receiptList[$key]['button']=$button;
  3785. }
  3786. //print_r($receiptList);die;
  3787. $mothHtml="";
  3788. for($i=1;$i<=12;$i++){
  3789. if($moth==$i)
  3790. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3791. else
  3792. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3793. }
  3794. $data['mothHtml']=$mothHtml;
  3795. $data['receiptList']=$receiptList;
  3796. $data['memu']="receipt";
  3797. $data['staff']=$this->staff;
  3798. $data['receiptMemu']='receipt';
  3799. $data['verifyId']=$this->verifyId;
  3800. $data['executeId']=$this->executeId;
  3801. $data['item']=$item;
  3802. $data['year']=$year;
  3803. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3804. //sufficient condition to generate cache
  3805. if(empty($moth)&&($year<date("Y"))){
  3806. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3807. if(empty($receiptList)){ //generated files
  3808. ob_start();
  3809. $this->render ( "/admin/saea_myList", $data );
  3810. $this->cacheFile($path);die;
  3811. // $content = ob_get_contents();
  3812. // $fp = fopen($path, "w");
  3813. // fwrite($fp, $content);
  3814. // fclose($fp);
  3815. }
  3816. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3817. $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));
  3818. if(empty($receiptList)){ //generated files
  3819. ob_start();
  3820. $this->render ( "/admin/saea_myList", $data );
  3821. $this->cacheFile($path);die;
  3822. }
  3823. }
  3824. }
  3825. $this->render ( "/admin/saea_myList", $data );
  3826. }
  3827. function saeaCreate(){
  3828. Doo::loadModel('accountItem');
  3829. Doo::loadModel('verify');
  3830. Doo::loadModel('receipt');
  3831. Doo::loadModel('L_category');
  3832. $lCategory=new L_category();
  3833. $receipt=new receipt();
  3834. $verify=new verify();
  3835. $accountItem=new accountItem();
  3836. Doo::loadModel("role");
  3837. $role=new role();
  3838. $acItem=$accountItem->find(array('asArray'=>true));
  3839. $veList=$verify->find(array('asArray'=>true));
  3840. foreach ($veList as $key=>$value){
  3841. $v=json_decode($value['staff']);
  3842. $list=array();
  3843. foreach ($v as $n=>$m){
  3844. if ($m['1']=='ROLE'){
  3845. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3846. $v[$n][1]=$roleInfo['name'];
  3847. array_push($list, $roleInfo['name']);
  3848. }else{
  3849. array_push($list, $v[$n][1]);
  3850. }
  3851. }
  3852. $veList[$key]['staff']=implode('>', $list);
  3853. }
  3854. $data['category']=$lCategory->find(array('asArray'=>true));
  3855. $data['veList']=$veList;
  3856. $data['acItem']=$acItem;
  3857. $data['memu']="receipt";
  3858. $data['staff']=$this->staff;
  3859. $data['receiptMemu']='saeaBorad';
  3860. $data['verifyId']=$this->verifyId;
  3861. $data['executeId']=$this->executeId;
  3862. $this->render ( "/admin/saea_create", $data );
  3863. }
  3864. function addReceipt(){
  3865. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3866. $agency=$this->get_args('agency');
  3867. $travel=$this->get_args('travel');
  3868. $train=$this->get_args('train');
  3869. $other=$this->get_args('other');
  3870. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3871. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3872. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3873. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3874. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3875. Doo::loadModel('receipt');
  3876. Doo::loadModel('receiptDetail');
  3877. Doo::loadModel('accountItem');
  3878. $accountItem=new accountItem();
  3879. $receipt=new receipt();
  3880. Doo::loadModel('enclosur');
  3881. Doo::loadModel('execute');
  3882. $execute=new execute();
  3883. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3884. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3885. // if(!empty($receiptDetail))
  3886. // return "/referReceipt/".$receiptDetail['rid'];
  3887. $aItem=$accountItem->find(array('asArray'=>true));
  3888. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3889. $ag=$tr=$ta=$ot=0;
  3890. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3891. foreach ($aItem as $key=>$value){
  3892. if ($value['category']==$this->AGENCY){
  3893. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3894. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3895. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3896. }
  3897. $ag++;
  3898. }
  3899. if($value['category']==$this->TRAVEL){
  3900. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3901. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3902. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3903. }
  3904. $tr++;
  3905. }
  3906. if($value['category']==$this->TRAIN){
  3907. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3908. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3909. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3910. }
  3911. $ta++;
  3912. }
  3913. if($value['category']==$this->OTHER){
  3914. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3915. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3916. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3917. }
  3918. $ot++;
  3919. }
  3920. }
  3921. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3922. //报销单
  3923. $receipt->accountItem=json_encode($accountJson);
  3924. $receipt->staff=$this->staff[0]['sid'];
  3925. $receipt->sum=number_format($sum, 2, '.', '');
  3926. $receipt->date=date("Y-m-d");
  3927. $receipt->cid=$cid;
  3928. $receipt->status=5;
  3929. //修改审批流程加入角色
  3930. $receipt->verify=$verify;
  3931. $receipt->executeCopy=$executeDetail['staff'];
  3932. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3933. $receipt->explanation=$explanation;
  3934. $rid=$receipt->insert();
  3935. //附件
  3936. if (!empty($enclosurName)){
  3937. $enclosurArray=explode('-', $enclosurName);
  3938. foreach ($enclosurArray as $value){
  3939. $enclosur=new enclosur();
  3940. $enclosur->name=$value;
  3941. $enclosur->rid=$rid;
  3942. $enclosur->insert();
  3943. }
  3944. //print_r($enclosurArray);die;
  3945. }
  3946. //报销详情
  3947. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3948. $receiptDetail=new receiptDetail();
  3949. $receiptDetail->staff=$this->staff[0]['sid'];
  3950. $receiptDetail->item=$value['name'];
  3951. $receiptDetail->itemCategory=$this->AGENCY;
  3952. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3953. $receiptDetail->date=date("Y-m-d");
  3954. $receiptDetail->cid=$cid;
  3955. $receiptDetail->rid=$rid;
  3956. $receiptDetail->status=4;
  3957. $receiptDetail->insert();
  3958. }
  3959. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3960. $receiptDetail=new receiptDetail();
  3961. $receiptDetail->staff=$this->staff[0]['sid'];
  3962. $receiptDetail->item=$value['name'];
  3963. $receiptDetail->itemCategory=$this->TRAVEL;
  3964. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3965. $receiptDetail->date=date("Y-m-d");
  3966. $receiptDetail->cid=$cid;
  3967. $receiptDetail->rid=$rid;
  3968. $receiptDetail->status=4;
  3969. $receiptDetail->insert();
  3970. }
  3971. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3972. $receiptDetail=new receiptDetail();
  3973. $receiptDetail->staff=$this->staff[0]['sid'];
  3974. $receiptDetail->item=$value['name'];
  3975. $receiptDetail->itemCategory=$this->TRAIN;
  3976. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3977. $receiptDetail->date=date("Y-m-d");
  3978. $receiptDetail->cid=$cid;
  3979. $receiptDetail->rid=$rid;
  3980. $receiptDetail->status=4;
  3981. $receiptDetail->insert();
  3982. }
  3983. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3984. $receiptDetail=new receiptDetail();
  3985. $receiptDetail->staff=$this->staff[0]['sid'];
  3986. $receiptDetail->item=$value['name'];
  3987. $receiptDetail->itemCategory=$this->OTHER;
  3988. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3989. $receiptDetail->date=date("Y-m-d");
  3990. $receiptDetail->cid=$cid;
  3991. $receiptDetail->rid=$rid;
  3992. $receiptDetail->status=4;
  3993. $receiptDetail->insert();
  3994. }
  3995. //return "/referReceipt/".$rid;
  3996. }
  3997. return "/saeaBorad";
  3998. }
  3999. function referReceipt(){
  4000. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4001. Doo::loadModel('receipt');
  4002. Doo::loadModel('verify');
  4003. $verify=new verify();
  4004. $receipt=new receipt();
  4005. Doo::loadModel('L_category');
  4006. $lCategory=new L_category();
  4007. Doo::loadModel("role");
  4008. $role=new role();
  4009. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  4010. if(empty($receiptDetail))
  4011. return "/addReceipt";
  4012. foreach ($receiptDetail as $key=>$value){
  4013. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  4014. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4015. $v=json_decode($veList['staff']);
  4016. array_push($v[0], $veList['description']);
  4017. foreach ($v as $n=>$m){
  4018. if ($m['1']=='ROLE'){
  4019. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4020. $v[$n][1]=$roleInfo['name'];
  4021. }
  4022. }
  4023. $receiptDetail[$key]['staff']=$v;
  4024. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4025. $receiptDetail[$key]['category']=$category['title'];
  4026. }
  4027. //print_r($receiptDetail);
  4028. $data['receiptDetail']=$receiptDetail;
  4029. $data['memu']="receipt";
  4030. $data['staff']=$this->staff;
  4031. $data['receiptMemu']='saeaCreate';
  4032. $data['verifyId']=$this->verifyId;
  4033. $data['executeId']=$this->executeId;
  4034. $this->render ( "/admin/saea_confirm", $data );
  4035. }
  4036. function editReceipt(){
  4037. //edit status 4
  4038. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4039. //echo $rid;
  4040. Doo::loadModel('accountItem');
  4041. Doo::loadModel('verify');
  4042. Doo::loadModel('receipt');
  4043. $receipt=new receipt();
  4044. $verify=new verify();
  4045. $accountItem=new accountItem();
  4046. Doo::loadModel('L_category');
  4047. $lCategory=new L_category();
  4048. Doo::loadModel("role");
  4049. $role=new role();
  4050. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4051. if(empty($receiptDetail))
  4052. return "/saeaCreate";
  4053. $acItem=$accountItem->find(array('asArray'=>true));
  4054. $veList=$verify->find(array('asArray'=>true));
  4055. foreach ($veList as $key=>$value){
  4056. $v=json_decode($value['staff']);
  4057. $list=array();
  4058. foreach ($v as $n=>$m){
  4059. if ($m['1']=='ROLE'){
  4060. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4061. $v[$n][1]=$roleInfo['name'];
  4062. array_push($list, $roleInfo['name']);
  4063. }else{
  4064. array_push($list, $v[$n][1]);
  4065. }
  4066. }
  4067. $veList[$key]['staff']=implode('>', $list);
  4068. }
  4069. //配置编辑信息
  4070. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4071. foreach ($acItem as $key=>$value){
  4072. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4073. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4074. $acItem[$key]['price']=$v['price'];
  4075. }
  4076. }
  4077. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4078. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4079. $acItem[$key]['price']=$v['price'];
  4080. }
  4081. }
  4082. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4083. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4084. $acItem[$key]['price']=$v['price'];
  4085. }
  4086. }
  4087. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4088. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4089. $acItem[$key]['price']=$v['price'];
  4090. }
  4091. }
  4092. }
  4093. $data['category']=$lCategory->find(array('asArray'=>true));
  4094. $data['cSum']=$accountItemList['cSum'];
  4095. $data['sum']=$receiptDetail['sum'];
  4096. $data['receiptDetail']=$receiptDetail;
  4097. $data['veList']=$veList;
  4098. $data['acItem']=$acItem;
  4099. $data['memu']="receipt";
  4100. $data['staff']=$this->staff;
  4101. $data['receiptMemu']='saeaBorad';
  4102. $data['verify']=$receiptDetail['verify'];
  4103. $data['verifyId']=$this->verifyId;
  4104. $data['executeId']=$this->executeId;
  4105. $data['rid']=$rid;
  4106. $this->render ( "/admin/saea_edit", $data );
  4107. }
  4108. function updateReceipt(){
  4109. $agency=$this->get_args('agency');
  4110. $travel=$this->get_args('travel');
  4111. $train=$this->get_args('train');
  4112. $other=$this->get_args('other');
  4113. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4114. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4115. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4116. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4117. if(!empty($explanation)){
  4118. Doo::loadModel('receipt');
  4119. Doo::loadModel('receiptDetail');
  4120. Doo::loadModel('accountItem');
  4121. $accountItem=new accountItem();
  4122. $receipt=new receipt();
  4123. Doo::loadModel('execute');
  4124. $execute=new execute();
  4125. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4126. if(empty($receiptDetail))
  4127. return "/saeaBorad";
  4128. if ($receiptDetail['Rtype']==1)
  4129. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4130. else
  4131. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4132. $aItem=$accountItem->find(array('asArray'=>true));
  4133. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4134. $ag=$tr=$ta=$ot=0;
  4135. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4136. foreach ($aItem as $key=>$value){
  4137. if ($value['category']==$this->AGENCY){
  4138. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4139. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4140. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4141. }
  4142. $ag++;
  4143. }
  4144. if($value['category']==$this->TRAVEL){
  4145. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4146. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4147. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4148. }
  4149. $tr++;
  4150. }
  4151. if($value['category']==$this->TRAIN){
  4152. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4153. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4154. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4155. }
  4156. $ta++;
  4157. }
  4158. if($value['category']==$this->OTHER){
  4159. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4160. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4161. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4162. }
  4163. $ot++;
  4164. }
  4165. }
  4166. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4167. //报销单
  4168. $rid=$receipt->rid=$receiptDetail['rid'];
  4169. $receipt->accountItem=json_encode($accountJson);
  4170. $receipt->staff=$this->staff[0]['sid'];
  4171. $receipt->sum=number_format($sum, 2, '.', '');
  4172. $receipt->date=date("Y-m-d");
  4173. $receipt->cid=$cid;
  4174. if (($receiptDetail['status']!=4)){
  4175. if ($receiptDetail['Rtype']==1)
  4176. $receipt->status=7;
  4177. else
  4178. $receipt->status=5;
  4179. }
  4180. if ($receiptDetail!=4&&!empty($verify))
  4181. $receipt->verify=$verify;
  4182. $receipt->executeCopy=$executeDetail['staff'];
  4183. $receipt->explanation=$explanation;
  4184. $receipt->update();
  4185. $receiptDetail=new receiptDetail();
  4186. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4187. //报销详情
  4188. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4189. $receiptDetail=new receiptDetail();
  4190. $receiptDetail->staff=$this->staff[0]['sid'];
  4191. $receiptDetail->item=$value['name'];
  4192. $receiptDetail->itemCategory=$this->AGENCY;
  4193. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4194. $receiptDetail->date=date("Y-m-d");
  4195. $receiptDetail->cid=$cid;
  4196. $receiptDetail->rid=$rid;
  4197. $receiptDetail->status=4;
  4198. $receiptDetail->insert();
  4199. }
  4200. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4201. $receiptDetail=new receiptDetail();
  4202. $receiptDetail->staff=$this->staff[0]['sid'];
  4203. $receiptDetail->item=$value['name'];
  4204. $receiptDetail->itemCategory=$this->TRAVEL;
  4205. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4206. $receiptDetail->date=date("Y-m-d");
  4207. $receiptDetail->cid=$cid;
  4208. $receiptDetail->rid=$rid;
  4209. $receiptDetail->status=4;
  4210. $receiptDetail->insert();
  4211. }
  4212. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4213. $receiptDetail=new receiptDetail();
  4214. $receiptDetail->staff=$this->staff[0]['sid'];
  4215. $receiptDetail->item=$value['name'];
  4216. $receiptDetail->itemCategory=$this->TRAIN;
  4217. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4218. $receiptDetail->date=date("Y-m-d");
  4219. $receiptDetail->cid=$cid;
  4220. $receiptDetail->rid=$rid;
  4221. $receiptDetail->status=4;
  4222. $receiptDetail->insert();
  4223. }
  4224. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4225. $receiptDetail=new receiptDetail();
  4226. $receiptDetail->staff=$this->staff[0]['sid'];
  4227. $receiptDetail->item=$value['name'];
  4228. $receiptDetail->itemCategory=$this->OTHER;
  4229. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4230. $receiptDetail->date=date("Y-m-d");
  4231. $receiptDetail->cid=$cid;
  4232. $receiptDetail->rid=$rid;
  4233. $receiptDetail->status=4;
  4234. $receiptDetail->insert();
  4235. }
  4236. //return "/referReceipt/".$rid;
  4237. }
  4238. return "/saeaBorad";
  4239. }
  4240. function approvedReceipt(){
  4241. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4242. Doo::loadModel('receipt');
  4243. Doo::loadModel('receiptDetail');
  4244. $receipt=new receipt();
  4245. $receiptDetail=new receiptDetail();
  4246. Doo::loadModel('statistics');
  4247. Doo::loadModel('itemStatistics');
  4248. $statistics=new statistics();
  4249. $itemStatistics=new itemStatistics();
  4250. Doo::loadModel("verify");
  4251. $verify=new verify();
  4252. //审批状态的判定
  4253. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4254. if(empty($receiptDetailList))
  4255. return "/saeaBorad";
  4256. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4257. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4258. if (empty($receiptDetailList['nowStaff'])){
  4259. $nowStaff="";$nowStaffList=array();
  4260. if ($verifyDetail[0][1]=='ROLE'){
  4261. $vStaffString=json_decode($verifyDetail[0][3]);
  4262. foreach ($vStaffString as $key=>$value){
  4263. $staffK=explode("_", $value);
  4264. array_push($nowStaffList, $staffK[0]);
  4265. }
  4266. $nowStaff=implode(',', $nowStaffList);
  4267. }else{
  4268. $nowStaff=$verifyDetail[0][0];
  4269. }
  4270. $receipt->nowStaff=$nowStaff;
  4271. }
  4272. // echo $nowStaff;
  4273. // print_r($verifyDetail);die;
  4274. $receipt->rid=$receiptDetailList['rid'];
  4275. $receipt->date=date("Y-m-d");
  4276. $receipt->status=2;
  4277. $receipt->update();
  4278. $receiptDetail->status=2;
  4279. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4280. Doo::loadModel("receiptLog");
  4281. $receiptLog=new receiptLog();
  4282. Doo::loadModel("verify");
  4283. $verify=new verify();
  4284. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4285. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4286. $jd=json_decode($vr['staff']);$roleId=0;
  4287. foreach ($jd as $key=>$value){
  4288. if ($value[1]=='ROLE'){
  4289. $pos = strpos($value[3], $this->staff[0]['sid']);
  4290. if ($pos !== false) {
  4291. $roleId=$value[0];
  4292. }
  4293. }
  4294. }
  4295. //审批日志
  4296. //echo $roleId;die;
  4297. if (!empty($roleId)){
  4298. Doo::loadModel("role");
  4299. $role=new role();
  4300. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4301. $receiptLog->rolename=$roleInfo['name'];
  4302. }
  4303. $receiptLog->username=$this->staff[0]['username'];
  4304. $receiptLog->uid=$this->staff[0]['sid'];
  4305. $receiptLog->date=date("Y-m-d");
  4306. $receiptLog->opinion='提交审批';
  4307. $receiptLog->img=$this->staff[0]['avatar'];
  4308. $receiptLog->status=2;
  4309. $receiptLog->rid=$rid;
  4310. $receiptLog->insert();
  4311. //statistics item
  4312. $dateArray=explode("-", $receiptDetailList['date']);
  4313. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4314. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4315. //print_r($accountItem['cSum']['agencySum']);die;
  4316. // foreach ($accountItem['cSum'] as $key=>$value){
  4317. // if($key=="agencySum"){
  4318. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4319. // if(empty($iStatistics)){
  4320. // $itemStatistics->cid=$this->staff[0]['cid'];
  4321. // $itemStatistics->staff=$this->staff[0]['sid'];
  4322. // $itemStatistics->price=$value;
  4323. // $itemStatistics->itemCategory=$this->AGENCY;
  4324. // $itemStatistics->date=date("Y-m-d");
  4325. // $itemStatistics->insert();
  4326. // }else{
  4327. // if (!empty($value)){
  4328. // $itemStatistics->price=$value+$iStatistics['price'];
  4329. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4330. // }
  4331. // }
  4332. // }elseif($key=="travelSum"){
  4333. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4334. // if(empty($iStatistics)){
  4335. // $itemStatistics->cid=$this->staff[0]['cid'];
  4336. // $itemStatistics->staff=$this->staff[0]['sid'];
  4337. // $itemStatistics->price=$value;
  4338. // $itemStatistics->itemCategory=$this->TRAVEL;
  4339. // $itemStatistics->date=date("Y-m-d");
  4340. // $itemStatistics->insert();
  4341. // }else{
  4342. // if (!empty($value)){
  4343. // $itemStatistics->price=$value+$iStatistics['price'];
  4344. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4345. // }
  4346. // }
  4347. // }elseif($key=="trainSum"){
  4348. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4349. // if(empty($iStatistics)){
  4350. // $itemStatistics->cid=$this->staff[0]['cid'];
  4351. // $itemStatistics->staff=$this->staff[0]['sid'];
  4352. // $itemStatistics->price=$value;
  4353. // $itemStatistics->itemCategory=$this->TRAIN;
  4354. // $itemStatistics->date=date("Y-m-d");
  4355. // $itemStatistics->insert();
  4356. // }else{
  4357. // if (!empty($value)){
  4358. // $itemStatistics->price=$value+$iStatistics['price'];
  4359. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4360. // }
  4361. // }
  4362. // }elseif($key=="otherSum"){
  4363. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4364. // if(empty($iStatistics)){
  4365. // $itemStatistics->cid=$this->staff[0]['cid'];
  4366. // $itemStatistics->staff=$this->staff[0]['sid'];
  4367. // $itemStatistics->price=$value;
  4368. // $itemStatistics->itemCategory=$this->OTHER;
  4369. // $itemStatistics->date=date("Y-m-d");
  4370. // $itemStatistics->insert();
  4371. // }else{
  4372. // if (!empty($value)){
  4373. // $itemStatistics->price=$value+$iStatistics['price'];
  4374. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4375. // }
  4376. // }
  4377. // }
  4378. // }
  4379. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4380. if(empty($stat)){
  4381. $statistics->date=date("Y-m-d");
  4382. $statistics->cid=$this->staff[0]['cid'];
  4383. $statistics->staff=$this->staff[0]['sid'];
  4384. $statistics->agPrice=0;
  4385. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4386. $statistics->insert();
  4387. }else{
  4388. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4389. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4390. }
  4391. return "/expenses";
  4392. }
  4393. function approval(){
  4394. $status=isset($this->params['status'])?$this->params['status']:'';
  4395. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4396. $month=$this->get_args('month')?$this->get_args('month'):"";
  4397. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4398. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4399. if (empty($status))
  4400. $status=$this->get_args('status')?$this->get_args('status'):2;
  4401. $vidList=array();
  4402. $button=0;
  4403. Doo::loadModel('verify');
  4404. $verify=new verify();
  4405. Doo::loadModel('receipt');
  4406. $receipt=new receipt();
  4407. Doo::loadModel('staff');
  4408. $staff=new staff();
  4409. Doo::loadModel('L_category');
  4410. $Lcategory=new L_category();
  4411. //user verify ID
  4412. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4413. foreach ($verifyDetail as $key=>$value){
  4414. array_push($vidList, $value['vid']);
  4415. }
  4416. $vid=implode(",", $vidList);
  4417. if(empty($verifyDetail))
  4418. $vid=0;
  4419. /*
  4420. */
  4421. $dateCondition=" and Year(date) =".$year;
  4422. if(!empty($month))
  4423. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4424. $categoryList=$Lcategory->find(array('asArray'=>true));
  4425. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4426. $cateCondition="";$staffCondition="";$approvalCondition="";
  4427. if (!empty($cid))
  4428. $cateCondition=' and cid='.$cid;
  4429. if(!empty($sid)){
  4430. $staffCondition=' and staff='.$sid;
  4431. $cateCondition="";
  4432. }
  4433. // elseif($status==1){
  4434. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4435. // }
  4436. if($status==2){
  4437. //查找角色审批人
  4438. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4439. }
  4440. $ap="";
  4441. if($status==4){
  4442. $ap=4;$status=2;
  4443. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4444. }
  4445. if($status==5){
  4446. $status=4;$ap=5;
  4447. }
  4448. //echo $vid;
  4449. //get Receipt By verifyID status 2 .$approvalCondition
  4450. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4451. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4452. ,'desc'=>'rid','asArray'=>true));
  4453. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4454. $Locate=0;
  4455. if($ap==4)
  4456. $status=4;
  4457. elseif ($ap==5)
  4458. $status=5;
  4459. foreach ($receiptList as $key=>$value){
  4460. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4461. $receiptList[$key]['reviseDetail']=array();
  4462. if (!empty($value['reviseDetail']))
  4463. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4464. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4465. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4466. $receiptList[$key]['category']=$categoryDetil['title'];
  4467. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4468. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4469. $verifyStaff=json_decode($value['verifyStaff'],true);
  4470. foreach ($verifyList as $k=>$v){
  4471. //init verifyStaff
  4472. $verifyList[$k]['date']="";
  4473. $verifyList[$k]['opinion']="";
  4474. $verifyList[$k]['status']="";
  4475. if (empty($verifyStaff)){
  4476. $verifyList[$k]['date']="";
  4477. $verifyList[$k]['opinion']="";
  4478. if ($v[0]==$this->staff[0]['sid']){
  4479. $verifyList[$k]['status']=4;
  4480. $button=4;
  4481. }
  4482. }else{
  4483. $flag=true;
  4484. foreach ($verifyStaff as $m=>$u){
  4485. if ($v[0]==$m){
  4486. $verifyList[$k]['date']=$u['date'];
  4487. $verifyList[$k]['opinion']=$u['opinion'];
  4488. $verifyList[$k]['status']=$u['status'];
  4489. $flag=false;
  4490. break;
  4491. }
  4492. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4493. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4494. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4495. }
  4496. if($flag){//检测可编辑
  4497. if($v[0]==$this->staff[0]['sid']){
  4498. $verifyList[$k]['status']=4;$button=4;
  4499. }
  4500. }
  4501. }
  4502. }
  4503. $receiptList[$key]['verifyList']=$verifyList;
  4504. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4505. $receiptList[$key]['button']=$button;
  4506. }
  4507. //print_r($receiptList);die;
  4508. //$data['verifyDetail']=$verifyDetail;
  4509. $mothHtml="";
  4510. for($i=1;$i<=12;$i++){
  4511. if($month==$i)
  4512. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4513. else
  4514. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4515. }
  4516. $data['mothHtml']=$mothHtml;
  4517. $data['receiptList']=$receiptList;
  4518. $data['receiptApprovalCount']=count($receiptList);
  4519. $data['status']=$status;
  4520. $data['year']=$year;
  4521. $data['categoryList']=$categoryList;
  4522. $data['staffList']=$staffList;
  4523. $data['cid']=$cid;
  4524. $data['sid']=$sid;
  4525. $data['ap']=$ap;
  4526. $data['memu']="receipt";
  4527. $data['staff']=$this->staff;
  4528. $data['receiptMemu']='approval';
  4529. $data['verifyId']=$this->verifyId;
  4530. $data['executeId']=$this->executeId;
  4531. $this->render ( "/admin/saea_reportList", $data );
  4532. }
  4533. function approvalDetails(){
  4534. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4535. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4536. $month=$this->get_args('month')?$this->get_args('month'):"";
  4537. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4538. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4539. Doo::loadModel('verify');
  4540. $verify=new verify();
  4541. Doo::loadModel('receipt');
  4542. $receipt=new receipt();
  4543. Doo::loadModel('staff');
  4544. $staff=new staff();
  4545. Doo::loadModel('L_category');
  4546. $Lcategory=new L_category();
  4547. Doo::loadModel('enclosur');
  4548. $enclosur=new enclosur();
  4549. $vidList=array();
  4550. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4551. foreach ($verifyDetail as $key=>$value){
  4552. array_push($vidList, $value['vid']);
  4553. }
  4554. $vid=implode(",", $vidList);
  4555. if(empty($verifyDetail))
  4556. $vid=0;
  4557. $categoryList=$Lcategory->find(array('asArray'=>true));
  4558. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4559. $ap=0;
  4560. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4561. $Locate=0;$roleId=0;$button=0;
  4562. foreach ($receiptList as $key=>$value){
  4563. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4564. $receiptList[$key]['reviseDetail']=array();
  4565. if (!empty($value['reviseDetail']))
  4566. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4567. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4568. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4569. $receiptList[$key]['category']=$categoryDetil['title'];
  4570. //检测编辑状态
  4571. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4572. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4573. $verifyStaff=json_decode($value['verifyStaff'],true);
  4574. Doo::loadModel('role');
  4575. $role=new role();
  4576. //print_r($verifyList);
  4577. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4578. foreach ($verifyList as $k=>$v){
  4579. //init verifyStaff
  4580. if ($v[1]=='ROLE'){
  4581. if (!empty($verifyStaff)){
  4582. $endStaffArray=end($verifyStaff);
  4583. if ($v[0]==$endStaffArray['nextStaff']){
  4584. $roleId=$v[0];
  4585. }
  4586. }
  4587. $roleVerify=json_decode($v[3],true);
  4588. $roleKey=$k;$roleArray=array();
  4589. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4590. foreach ($roleVerify as $o=>$p){
  4591. $staffID=explode ('_',$p);
  4592. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4593. //print_r($staffID);
  4594. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4595. array_push($roleArray, $exp);
  4596. }
  4597. $roleArrayCopy[$v[0]]=$roleArray;
  4598. //$verifyList[$k]['roleArray']=$roleArray;
  4599. }
  4600. //print_r($roleArray);
  4601. $verifyList[$k]['date']="";
  4602. $verifyList[$k]['opinion']="";
  4603. $verifyList[$k]['status']="";
  4604. if (empty($verifyStaff)){
  4605. $verifyList[$k]['date']="";
  4606. $verifyList[$k]['opinion']="";
  4607. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4608. $verifyList[$k]['status']=4;
  4609. $button=4;$flag=false;
  4610. }
  4611. }else{
  4612. foreach ($verifyStaff as $m=>$u){
  4613. if ($v[0]==$m){
  4614. $verifyList[$k]['date']=$u['date'];
  4615. $verifyList[$k]['opinion']=$u['opinion'];
  4616. $verifyList[$k]['status']=$u['status'];
  4617. $flag=false;
  4618. break;
  4619. }
  4620. }
  4621. $endStaffArray=end($verifyStaff);
  4622. if (isset($endStaffArray['ROLE'])){
  4623. }else{
  4624. $endKey=key($verifyStaff);
  4625. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4626. $button=4;
  4627. $verifyList[$k]['status']=4;
  4628. }
  4629. }
  4630. }
  4631. }
  4632. $rolename['name']='';
  4633. if (!empty($roleId)){
  4634. Doo::loadModel('role');
  4635. $role=new role();
  4636. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4637. }
  4638. if (!empty($verifyStaff))
  4639. $endStaffArray=end($verifyStaff);
  4640. $KOP=false;
  4641. foreach ($roleArrayCopy as $P=>$A){
  4642. foreach ( $A as $MKI=>$AVL){
  4643. if (!empty($verifyStaff)){
  4644. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4645. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4646. $button=4;
  4647. $roleArrayCopy[$P][$MKI]['status']=4;
  4648. }
  4649. foreach ($verifyStaff as $m=>$u){
  4650. $AVLFK=$AVL[0].'_R';
  4651. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4652. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4653. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4654. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4655. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4656. break;
  4657. }
  4658. }
  4659. }else{
  4660. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4661. $button=4;
  4662. $roleArrayCopy[$P][$MKI]['status']=4;
  4663. }
  4664. }
  4665. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4666. $KOP=true;
  4667. }
  4668. }
  4669. foreach ($roleArrayCopy as $k=>$v){
  4670. foreach ($verifyList as $m=>$n){
  4671. if ($n[0]==$k){
  4672. array_splice($verifyList,$m,1,$v);
  4673. }
  4674. }
  4675. }
  4676. $receiptList[$key]['verifyList']=$verifyList;
  4677. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4678. $receiptList[$key]['button']=$button;
  4679. }
  4680. $mothHtml="";
  4681. for($i=1;$i<=12;$i++){
  4682. if($month==$i)
  4683. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4684. else
  4685. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4686. }
  4687. //获取审批日志
  4688. Doo::loadModel('receiptLog');
  4689. $receiptLog=new receiptLog();
  4690. $rlList=array();
  4691. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4692. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4693. if (!empty($rlInfo)){
  4694. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4695. }
  4696. $receiptList[0]['rlList']=$rlList;
  4697. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4698. $enclosurHtml='';
  4699. foreach ($enclosurList as $value){
  4700. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4701. }
  4702. $data['enclosurHtml']=$enclosurHtml;
  4703. $data['rolename']=$rolename['name'];
  4704. $data['datetij']=$tijdate['date'];
  4705. $data['mothHtml']=$mothHtml;
  4706. $data['receiptList']=$receiptList;
  4707. $data['receiptApprovalCount']=count($receiptList);
  4708. $data['year']=$year;
  4709. $data['categoryList']=$categoryList;
  4710. $data['staffList']=$staffList;
  4711. $data['cid']=$cid;
  4712. $data['sid']=$sid;
  4713. $data['status']=0;
  4714. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4715. $ap=4;
  4716. }else
  4717. $data['status']=$receiptList[0]['status'];
  4718. if ($receiptList[0]['status']==4){
  4719. $data['status']=5;
  4720. $ap=0;
  4721. }
  4722. $data['ap']=$ap;
  4723. $data['memu']="receipt";
  4724. $data['staff']=$this->staff;
  4725. $data['receiptMemu']='approval';
  4726. $data['verifyId']=$this->verifyId;
  4727. $data['executeId']=$this->executeId;
  4728. $this->render ( "/admin/saeaReportListReport", $data );
  4729. }
  4730. function approvalEdi(){
  4731. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4732. $status=isset($this->params['status'])?$this->params['status']:'';
  4733. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4734. $month=$this->get_args('month')?$this->get_args('month'):"";
  4735. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4736. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4737. if (empty($status))
  4738. $status=$this->get_args('status')?$this->get_args('status'):2;
  4739. $vidList=array();
  4740. $button=0;
  4741. Doo::loadModel('verify');
  4742. Doo::loadModel('receipt');
  4743. Doo::loadModel('staff');
  4744. $staff=new staff();
  4745. $receipt=new receipt();
  4746. $verify=new verify();
  4747. Doo::loadModel('L_category');
  4748. $Lcategory=new L_category();
  4749. Doo::loadModel('enclosur');
  4750. $enclosur=new enclosur();
  4751. //user verify ID
  4752. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4753. foreach ($verifyDetail as $key=>$value){
  4754. array_push($vidList, $value['vid']);
  4755. }
  4756. $vid=implode(",", $vidList);
  4757. if(empty($verifyDetail))
  4758. $vid=0;
  4759. $categoryList=$Lcategory->find(array('asArray'=>true));
  4760. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4761. $ap="";
  4762. if($status==4){
  4763. $ap=4;$status=2;
  4764. }
  4765. //get Receipt By verifyID status 2
  4766. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4767. $Locate=0;$roleId=0;
  4768. if($ap==4)
  4769. $status=4;
  4770. foreach ($receiptList as $key=>$value){
  4771. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4772. $receiptList[$key]['reviseDetail']=array();
  4773. if (!empty($value['reviseDetail']))
  4774. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4775. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4776. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4777. $receiptList[$key]['category']=$categoryDetil['title'];
  4778. //检测编辑状态
  4779. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4780. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4781. $verifyStaff=json_decode($value['verifyStaff'],true);
  4782. // print_r($verifyList);
  4783. //
  4784. // if (empty($verifyStaff)){
  4785. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4786. // $verifyList[0]['status']=4;$button=4;
  4787. // }
  4788. //
  4789. // }else{
  4790. //
  4791. // }
  4792. // die;
  4793. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4794. // echo array_search("green",$a);
  4795. //
  4796. Doo::loadModel('role');
  4797. $role=new role();
  4798. //print_r($verifyList);
  4799. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4800. foreach ($verifyList as $k=>$v){
  4801. //init verifyStaff
  4802. if ($v[1]=='ROLE'){
  4803. if (!empty($verifyStaff)){
  4804. $endStaffArray=end($verifyStaff);
  4805. if ($v[0]==$endStaffArray['nextStaff']){
  4806. $roleId=$v[0];
  4807. }
  4808. }
  4809. $roleVerify=json_decode($v[3],true);
  4810. $roleKey=$k;$roleArray=array();
  4811. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4812. foreach ($roleVerify as $o=>$p){
  4813. $staffID=explode ('_',$p);
  4814. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4815. //print_r($staffID);
  4816. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4817. array_push($roleArray, $exp);
  4818. }
  4819. $roleArrayCopy[$v[0]]=$roleArray;
  4820. //$verifyList[$k]['roleArray']=$roleArray;
  4821. }
  4822. //print_r($roleArray);
  4823. $verifyList[$k]['date']="";
  4824. $verifyList[$k]['opinion']="";
  4825. $verifyList[$k]['status']="";
  4826. if (empty($verifyStaff)){
  4827. $verifyList[$k]['date']="";
  4828. $verifyList[$k]['opinion']="";
  4829. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4830. $verifyList[$k]['status']=4;
  4831. $button=4;$flag=false;
  4832. }
  4833. }else{
  4834. foreach ($verifyStaff as $m=>$u){
  4835. if ($v[0]==$m){
  4836. $verifyList[$k]['date']=$u['date'];
  4837. $verifyList[$k]['opinion']=$u['opinion'];
  4838. $verifyList[$k]['status']=$u['status'];
  4839. $flag=false;
  4840. break;
  4841. }
  4842. }
  4843. $endStaffArray=end($verifyStaff);
  4844. if (isset($endStaffArray['ROLE'])){
  4845. }else{
  4846. $endKey=key($verifyStaff);
  4847. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4848. $button=4;
  4849. $verifyList[$k]['status']=4;
  4850. }
  4851. }
  4852. //print_r($endStaffArray);die;
  4853. // if (empty($verifyStaff)){
  4854. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4855. // $verifyList[$k]['status']=4;$button=4;
  4856. // }
  4857. //
  4858. // }else{
  4859. //
  4860. // }
  4861. // if($flag){//检测可编辑
  4862. // if($v[0]==$this->staff[0]['sid']){
  4863. // $verifyList[$k]['status']=4;$button=4;
  4864. // }
  4865. // }
  4866. }
  4867. }
  4868. $rolename['name']='';
  4869. if (!empty($roleId)){
  4870. Doo::loadModel('role');
  4871. $role=new role();
  4872. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4873. }
  4874. if (!empty($verifyStaff))
  4875. $endStaffArray=end($verifyStaff);
  4876. $KOP=false;
  4877. foreach ($roleArrayCopy as $P=>$A){
  4878. foreach ( $A as $MKI=>$AVL){
  4879. if (!empty($verifyStaff)){
  4880. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4881. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4882. $button=4;
  4883. $roleArrayCopy[$P][$MKI]['status']=4;
  4884. }
  4885. foreach ($verifyStaff as $m=>$u){
  4886. $AVLFK=$AVL[0].'_R';
  4887. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4888. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4889. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4890. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4891. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4892. break;
  4893. }
  4894. }
  4895. }else{
  4896. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4897. $button=4;
  4898. $roleArrayCopy[$P][$MKI]['status']=4;
  4899. }
  4900. }
  4901. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4902. $KOP=true;
  4903. }
  4904. }
  4905. // print_r($roleArrayCopy);
  4906. // echo $roleKey;
  4907. foreach ($roleArrayCopy as $k=>$v){
  4908. foreach ($verifyList as $m=>$n){
  4909. if ($n[0]==$k){
  4910. array_splice($verifyList,$m,1,$v);
  4911. }
  4912. }
  4913. }
  4914. // if ($KOP)
  4915. // array_splice($verifyList,$roleKey,1,$roleArray);
  4916. //print_r($verifyList);
  4917. $receiptList[$key]['verifyList']=$verifyList;
  4918. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4919. $receiptList[$key]['button']=$button;
  4920. }
  4921. //$data['verifyDetail']=$verifyDetail;
  4922. $mothHtml="";
  4923. for($i=1;$i<=12;$i++){
  4924. if($month==$i)
  4925. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4926. else
  4927. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4928. }
  4929. //获取审批日志
  4930. Doo::loadModel('receiptLog');
  4931. $receiptLog=new receiptLog();
  4932. $rlList=array();
  4933. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4934. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4935. if (!empty($rlInfo)){
  4936. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4937. }
  4938. $receiptList[0]['rlList']=$rlList;
  4939. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4940. $enclosurHtml='';
  4941. foreach ($enclosurList as $value){
  4942. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4943. }
  4944. $data['enclosurHtml']=$enclosurHtml;
  4945. $data['rolename']=$rolename['name'];
  4946. $data['datetij']=$tijdate['date'];
  4947. $data['mothHtml']=$mothHtml;
  4948. $data['receiptList']=$receiptList;
  4949. $data['receiptApprovalCount']=count($receiptList);
  4950. $data['status']=$status;
  4951. $data['year']=$year;
  4952. $data['categoryList']=$categoryList;
  4953. $data['staffList']=$staffList;
  4954. $data['cid']=$cid;
  4955. $data['sid']=$sid;
  4956. $data['ap']=$ap;
  4957. $data['memu']="receipt";
  4958. $data['staff']=$this->staff;
  4959. $data['receiptMemu']='approval';
  4960. $data['verifyId']=$this->verifyId;
  4961. $data['executeId']=$this->executeId;
  4962. $this->render ( "/admin/saeaReportListReport", $data );
  4963. }
  4964. function remittance(){
  4965. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4966. $month=$this->get_args('month')?$this->get_args('month'):"";
  4967. Doo::loadModel('receipt');
  4968. $receipt=new receipt();
  4969. Doo::loadModel('staff');
  4970. $staff=new staff();
  4971. $dateCondition=" and Year(pastDate) =".$year;
  4972. if(!empty($month))
  4973. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4974. //get Receipt By verifyID status 1
  4975. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4976. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4977. $dataList=array();
  4978. foreach ($dateList as $d=>$a){
  4979. $dataList[$a['pastDate']]=array();$daySum=0;
  4980. foreach ($receiptList as $key=>$value){
  4981. if($a['pastDate']==$value['pastDate']){
  4982. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4983. $list=array();$html="";
  4984. foreach ($oderList as $v){
  4985. array_push($list, $v['receiptOrder']);
  4986. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4987. }
  4988. $receiptList[$key]['receiptOrder']=$html;
  4989. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4990. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4991. $receiptList[$key]['username']=$sinfo['username'];
  4992. $daySum+=$value['sum'];
  4993. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4994. }
  4995. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4996. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4997. }
  4998. }
  4999. //print_r($dataList);
  5000. $data['dataList']=$dataList;
  5001. $mothHtml="";
  5002. for($i=1;$i<=12;$i++){
  5003. if($month==$i)
  5004. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  5005. else
  5006. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  5007. }
  5008. $data['year']=$year;
  5009. $data['mothHtml']=$mothHtml;
  5010. $data['memu']="receipt";
  5011. $data['staff']=$this->staff;
  5012. $data['receiptMemu']='approval';
  5013. $data['verifyId']=$this->verifyId;
  5014. $data['executeId']=$this->executeId;
  5015. $this->render ( "/admin/saeaReportListPay", $data );
  5016. }
  5017. function revocationAdjustment(){
  5018. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5019. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5020. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5021. //echo $price;die;
  5022. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5023. Doo::loadModel('receipt');
  5024. $receipt=new receipt();
  5025. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5026. if (empty($receiptDetail['reviseDetail']))
  5027. return "/approval";
  5028. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5029. $RD=array();
  5030. foreach ($reviseDetail as $key=>$value){
  5031. if ($value['price']==$price&&$value['sid']==$sid)
  5032. continue;
  5033. array_push($RD, $value);
  5034. }
  5035. $reviseDetailString=json_encode($RD);
  5036. $receipt->reviseDetail=$reviseDetailString;
  5037. $receipt->sum=$receiptDetail['sum']-$price;
  5038. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5039. $receipt->update(array('where'=>'rid='.$rid));
  5040. }
  5041. //approvalEdi/37
  5042. return "/approvalEdi/".$rid;
  5043. }
  5044. function updateApprovalReceipt(){
  5045. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5046. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5047. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5048. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5049. if(!empty($rid)){
  5050. Doo::loadModel("verify");
  5051. $verify=new verify();
  5052. Doo::loadModel("receiptDetail");
  5053. $receiptDetailObj=new receiptDetail();
  5054. Doo::loadModel("itemStatistics");
  5055. Doo::loadModel("statistics");
  5056. $statistics=new statistics();
  5057. $itemStatistics=new itemStatistics();
  5058. Doo::loadModel("receipt");
  5059. $receipt=new receipt();
  5060. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5061. if (empty($receiptDetail))
  5062. return "/approval";
  5063. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5064. $verifyString=$verifyDetail['staff'];
  5065. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5066. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5067. if(empty($opinion)){
  5068. if ($status==3)
  5069. $opinion="终止";
  5070. else
  5071. $opinion="同意支付";
  5072. }
  5073. $nowStaff=0;$nowStaffList=array();
  5074. if(empty($verifyStaff)){
  5075. //还需加入是否已经进入角色审批
  5076. if ($verifyDetail[0][1]=='ROLE'){
  5077. $vStaffString=json_decode($verifyDetail[0][3]);
  5078. foreach ($vStaffString as $key=>$value){
  5079. $staffK=explode("_", $value);
  5080. if ($staffK[0]!=$this->staff[0]['sid'])
  5081. array_push($nowStaffList, $staffK[0]);
  5082. }
  5083. //print_r($verifyDetail);
  5084. //die;
  5085. if (!empty($nowStaffList)){
  5086. $nowStaff=implode(',', $nowStaffList);
  5087. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5088. }else{
  5089. $nowStaff=$verifyDetail[1][0];
  5090. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5091. }
  5092. }else{
  5093. if ($verifyDetail[1][1]=='ROLE'){
  5094. $vStaffString=json_decode($verifyDetail[1][3]);
  5095. //echo "dd";
  5096. foreach ($vStaffString as $key=>$value){
  5097. $staffK=explode("_", $value);
  5098. array_push($nowStaffList, $staffK[0]);
  5099. }
  5100. $nowStaff=implode(',', $nowStaffList);
  5101. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5102. }else{
  5103. $nowStaff=$verifyDetail[1][0];
  5104. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5105. }
  5106. }
  5107. if($status==3)
  5108. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5109. $vStaffString=json_encode($verifyStaff);
  5110. $receipt->nowStaff=$nowStaff;
  5111. $receipt->verifyStaff=$vStaffString;
  5112. }else{
  5113. $VS=end($verifyStaff);
  5114. //非角色审批
  5115. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5116. $nextStaff=0;$roleSTF=false;
  5117. foreach ($verifyDetail as $key=>$value){
  5118. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5119. if (isset($verifyDetail[$key+1])){
  5120. $nextStaff=$verifyDetail[$key+1][0];
  5121. if ($verifyDetail[$key+1][1]=='ROLE')
  5122. $roleSTF=true;
  5123. }
  5124. break;
  5125. }
  5126. }
  5127. if (!$roleSTF){
  5128. $nowStaff=$nextStaff;
  5129. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5130. }else{
  5131. //获取角色下的所有用户ID
  5132. $nowStaffList=array();
  5133. foreach ($verifyDetail as $vfk){
  5134. if ($vfk[1]=='ROLE'){
  5135. $vStaffString=json_decode($vfk[3]);
  5136. foreach ($vStaffString as $key=>$value){
  5137. $staffK=explode("_", $value);
  5138. array_push($nowStaffList, $staffK[0]);
  5139. }
  5140. }
  5141. }
  5142. $nowStaff=implode(',', $nowStaffList);
  5143. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5144. }
  5145. if($status==3){
  5146. $verifyStaff['final']=$status;
  5147. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5148. }
  5149. $vStaffString=json_encode($verifyStaff);
  5150. $receipt->nowStaff=$nowStaff;
  5151. $receipt->verifyStaff=$vStaffString;
  5152. }
  5153. //角色审批
  5154. if (isset($VS['ROLE'])){
  5155. //找出角色人 当前审批角色组
  5156. $verifyJSStaff=array();$nowStaffList2=array();
  5157. foreach ($verifyDetail as $key=>$value){
  5158. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5159. $verifyJSStaff=json_decode($value[3]);
  5160. foreach ($verifyJSStaff as $m){
  5161. $staffK=explode("_", $m);
  5162. array_push($nowStaffList2, $staffK[0]);
  5163. }
  5164. // print_r($nowStaffList2);
  5165. }
  5166. }
  5167. $RoleVerifyStaff=array();
  5168. foreach ($verifyStaff as $key=>$value){
  5169. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5170. foreach ($nowStaffList2 as $m) {
  5171. if ($key==$m."_R")
  5172. $RoleVerifyStaff[$key]=$value;
  5173. }
  5174. }
  5175. }
  5176. // print_r($verifyStaff);
  5177. // print_r($nowStaffList2);
  5178. // print_r($RoleVerifyStaff);
  5179. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5180. //print_r($verifyJSStaff);
  5181. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5182. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5183. //下一个审批人ID
  5184. $nextStaff=0;$falg=false;
  5185. foreach ($verifyDetail as $key=>$value){
  5186. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5187. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5188. $falg=true;
  5189. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5190. foreach ($vStaffString as $v){
  5191. $staffK=explode("_", $v);
  5192. array_push($nowStaffList, $staffK[0]);
  5193. }
  5194. $nowStaff=implode(',', $nowStaffList);
  5195. $nextStaff=$verifyDetail[$key+1][0];
  5196. }elseif(isset($verifyDetail[$key+1])){
  5197. $nextStaff=$verifyDetail[$key+1][0];
  5198. $nowStaff=$nextStaff;
  5199. }else
  5200. $nowStaff='';
  5201. break;
  5202. }
  5203. }
  5204. if ($falg)
  5205. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5206. else
  5207. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5208. // print_r($verifyStaff);
  5209. // echo $nowStaff;die;
  5210. }else{ //进入下一个角色或者审批人
  5211. /*
  5212. */
  5213. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5214. //
  5215. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5216. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5217. // print_r($verifyStaff);
  5218. // die;
  5219. }
  5220. if($status==3){
  5221. $verifyStaff['final']=$status;
  5222. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5223. }
  5224. $vStaffString=json_encode($verifyStaff);
  5225. $receipt->verifyStaff=$vStaffString;
  5226. $receipt->nowStaff=$nowStaff;
  5227. //die;
  5228. //}
  5229. // print_r($verifyStaff);
  5230. // die;
  5231. }
  5232. //print_r($verifyStaff);die;
  5233. }
  5234. //print_r($verifyDetail);
  5235. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5236. foreach ($verifyDetail as $k=>$v){
  5237. if ($v[1]=='ROLE'){
  5238. $roleId=$v[0];
  5239. $roleVerify=json_decode($v[3],true);
  5240. $roleKey=$k;$roleArray=array();
  5241. foreach ($roleVerify as $o=>$p){
  5242. $staffID=explode ('_',$p);
  5243. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5244. array_push($roleArray, $exp);
  5245. }
  5246. $verifyDetailCopy[$v[0]]=$roleArray;
  5247. }
  5248. }
  5249. //print_r($verifyDetail);
  5250. foreach ($verifyDetailCopy as $k=>$v){
  5251. foreach ($verifyDetail as $m=>$n){
  5252. if ($n[0]==$k){
  5253. array_splice($verifyDetail,$m,1,$v);
  5254. }
  5255. }
  5256. }
  5257. // die;
  5258. // if (!empty($roleArray))
  5259. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5260. // echo $roleId;
  5261. // print_r($verifyStaff);
  5262. // print_r($verifyDetail);
  5263. // die;
  5264. Doo::loadModel("receiptLog");
  5265. $receiptLog=new receiptLog();
  5266. //审批日志
  5267. if (!isset($verifyStaff['final'])){
  5268. if (!empty($roleId)){
  5269. Doo::loadModel("role");
  5270. $role=new role();
  5271. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5272. $receiptLog->rolename=$roleInfo['name'];
  5273. }
  5274. $receiptLog->username=$this->staff[0]['username'];
  5275. $receiptLog->uid=$this->staff[0]['sid'];
  5276. $receiptLog->date=date("Y-m-d");
  5277. $receiptLog->opinion=$opinion;
  5278. $receiptLog->img=$this->staff[0]['avatar'];
  5279. $receiptLog->status=1;
  5280. $receiptLog->rid=$rid;
  5281. $receiptLog->insert();
  5282. }
  5283. if (isset($verifyStaff['final'])){//rDetail
  5284. $receipt->verifyBreakup=$verifyString;
  5285. $receipt->status=3;
  5286. $receiptDetailObj->status=3;
  5287. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5288. if (!empty($roleId)){
  5289. Doo::loadModel("role");
  5290. $role=new role();
  5291. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5292. $receiptLog->rolename=$roleInfo['name'];
  5293. }
  5294. $receiptLog->username=$this->staff[0]['username'];
  5295. $receiptLog->uid=$this->staff[0]['sid'];
  5296. $receiptLog->date=date("Y-m-d");
  5297. $receiptLog->opinion=$opinion;
  5298. $receiptLog->img=$this->staff[0]['avatar'];
  5299. $receiptLog->status=3;
  5300. $receiptLog->rid=$rid;
  5301. $receiptLog->insert();
  5302. //微信企业号通知
  5303. $this->setWXMsg($rid,3);
  5304. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5305. $receipt->status=1;$reviseSum=0;
  5306. $receipt->verifyBreakup=$verifyString;
  5307. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5308. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5309. foreach ($reviseDetail as $key=>$value){
  5310. $receiptDetailObj=new receiptDetail();
  5311. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5312. $receiptDetailObj->item=$value['description'];
  5313. $receiptDetailObj->itemCategory="报销金额调整";
  5314. $receiptDetailObj->price=$value['price'];
  5315. $receiptDetailObj->date=$receiptDetail['date'];
  5316. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5317. $receiptDetailObj->rid=$rid;
  5318. $receiptDetailObj->status=1;
  5319. $receiptDetailObj->insert();
  5320. $reviseSum+=$value['price'];
  5321. }
  5322. $itemStatistics=new itemStatistics();
  5323. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5324. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5325. $itemStatistics->price=$reviseSum;
  5326. $itemStatistics->itemCategory="报销金额调整";
  5327. $itemStatistics->date=$receiptDetail['date'];
  5328. $itemStatistics->insert();
  5329. }
  5330. $receiptDetailObj=new receiptDetail();
  5331. $receiptDetailObj->status=1;
  5332. $receiptDetailObj->pastDate=date("Y-m-d");
  5333. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5334. $dateArray=explode("-", $receiptDetail['date']);
  5335. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5336. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5337. if(empty($stat)){
  5338. $statistics->date=$receiptDetail['date'];
  5339. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5340. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5341. $statistics->agPrice=$receiptDetail['sum'];
  5342. $statistics->rePrice=$reviseSum;
  5343. $statistics->insert();
  5344. }else{
  5345. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5346. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5347. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5348. }
  5349. $dateArray=explode("-", $receiptDetail['date']);
  5350. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5351. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5352. foreach ($accountItem['cSum'] as $key=>$value){
  5353. if($key=="agencySum"){
  5354. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5355. if(empty($iStatistics)){
  5356. $itemStatistics->cid=$receiptDetail['cid'];;
  5357. $itemStatistics->staff=$receiptDetail['staff'];
  5358. $itemStatistics->price=$value;
  5359. $itemStatistics->itemCategory=$this->AGENCY;
  5360. $itemStatistics->date=$receiptDetail['date'];
  5361. $itemStatistics->insert();
  5362. }else{
  5363. if (!empty($value)){
  5364. $itemStatistics->price=$value+$iStatistics['price'];
  5365. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5366. }
  5367. }
  5368. }elseif($key=="travelSum"){
  5369. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5370. if(empty($iStatistics)){
  5371. $itemStatistics->cid=$receiptDetail['cid'];
  5372. $itemStatistics->staff=$receiptDetail['staff'];
  5373. $itemStatistics->price=$value;
  5374. $itemStatistics->itemCategory=$this->TRAVEL;
  5375. $itemStatistics->date=$receiptDetail['date'];
  5376. $itemStatistics->insert();
  5377. }else{
  5378. if (!empty($value)){
  5379. $itemStatistics->price=$value+$iStatistics['price'];
  5380. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5381. }
  5382. }
  5383. }elseif($key=="trainSum"){
  5384. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5385. if(empty($iStatistics)){
  5386. $itemStatistics->cid=$receiptDetail['cid'];
  5387. $itemStatistics->staff=$receiptDetail['staff'];
  5388. $itemStatistics->price=$value;
  5389. $itemStatistics->itemCategory=$this->TRAIN;
  5390. $itemStatistics->date=$receiptDetail['date'];
  5391. $itemStatistics->insert();
  5392. }else{
  5393. if (!empty($value)){
  5394. $itemStatistics->price=$value+$iStatistics['price'];
  5395. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5396. }
  5397. }
  5398. }elseif($key=="otherSum"){
  5399. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5400. if(empty($iStatistics)){
  5401. $itemStatistics->cid=$receiptDetail['cid'];
  5402. $itemStatistics->staff=$receiptDetail['staff'];
  5403. $itemStatistics->price=$value;
  5404. $itemStatistics->itemCategory=$this->OTHER;
  5405. $itemStatistics->date=$receiptDetail['date'];
  5406. $itemStatistics->insert();
  5407. }else{
  5408. if (!empty($value)){
  5409. $itemStatistics->price=$value+$iStatistics['price'];
  5410. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5411. }
  5412. }
  5413. }
  5414. }
  5415. $receipt->pastDate=date("Y-m-d");
  5416. //微信企业号通知
  5417. $this->setWXMsg($rid,1);
  5418. }
  5419. $receipt->update(array('where'=>' rid = '.$rid));
  5420. return "/approvalExpenses/2";
  5421. }
  5422. }
  5423. function expensesRetreats(){
  5424. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5425. if (!empty($rid)){
  5426. //操作记录
  5427. Doo::loadModel("receipt");
  5428. $receipt=new receipt();
  5429. Doo::loadModel("receiptLog");
  5430. $receiptLog=new receiptLog();
  5431. Doo::loadModel("verify");
  5432. $verify=new verify();
  5433. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5434. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5435. $jd=json_decode($vr['staff']);$roleId=0;
  5436. foreach ($jd as $key=>$value){
  5437. if ($value[1]=='ROLE'){
  5438. $pos = strpos($value[3], $this->staff[0]['sid']);
  5439. if ($pos !== false) {
  5440. $roleId=$value[0];
  5441. }
  5442. }
  5443. }
  5444. //审批日志
  5445. //echo $roleId;die;
  5446. if (!empty($roleId)){
  5447. Doo::loadModel("role");
  5448. $role=new role();
  5449. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5450. $receiptLog->rolename=$roleInfo['name'];
  5451. }
  5452. $receiptLog->username=$this->staff[0]['username'];
  5453. $receiptLog->uid=$this->staff[0]['sid'];
  5454. $receiptLog->date=date("Y-m-d");
  5455. $receiptLog->opinion='撤回';
  5456. $receiptLog->img=$this->staff[0]['avatar'];
  5457. $receiptLog->status=4;
  5458. $receiptLog->rid=$rid;
  5459. $receiptLog->insert();
  5460. $receipt->status=4;
  5461. $receipt->update(array('where'=>'rid='.$rid));
  5462. //微信企业号通知
  5463. $this->setWXMsg($rid,2);
  5464. }
  5465. //echo "ddd";
  5466. return '/approvalExpenses';
  5467. }
  5468. function updateCheReceipt(){
  5469. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5470. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5471. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5472. if (!empty($rid)){
  5473. //操作记录
  5474. Doo::loadModel("receipt");
  5475. $receipt=new receipt();
  5476. Doo::loadModel("receiptLog");
  5477. $receiptLog=new receiptLog();
  5478. Doo::loadModel("verify");
  5479. $verify=new verify();
  5480. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5481. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5482. $jd=json_decode($vr['staff']);$roleId=0;
  5483. foreach ($jd as $key=>$value){
  5484. if ($value[1]=='ROLE'){
  5485. $pos = strpos($value[3], $this->staff[0]['sid']);
  5486. if ($pos !== false) {
  5487. $roleId=$value[0];
  5488. }
  5489. }
  5490. }
  5491. //审批日志
  5492. //echo $roleId;die;
  5493. if (!empty($roleId)){
  5494. Doo::loadModel("role");
  5495. $role=new role();
  5496. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5497. $receiptLog->rolename=$roleInfo['name'];
  5498. }
  5499. $receiptLog->username=$this->staff[0]['username'];
  5500. $receiptLog->uid=$this->staff[0]['sid'];
  5501. $receiptLog->date=date("Y-m-d");
  5502. $receiptLog->opinion=$opinion;
  5503. $receiptLog->img=$this->staff[0]['avatar'];
  5504. $receiptLog->status=4;
  5505. $receiptLog->rid=$rid;
  5506. $receiptLog->insert();
  5507. $receipt->status=4;
  5508. $receipt->update(array('where'=>'rid='.$rid));
  5509. //微信企业号通知
  5510. $this->setWXMsg($rid,2);
  5511. echo json_encode ( array (
  5512. 'status' => 1
  5513. ) );die;
  5514. }
  5515. echo json_encode ( array (
  5516. 'status' => 2
  5517. ) );die;
  5518. //echo "ddd";
  5519. //return '/saeaBorad';
  5520. }
  5521. function revisePrice(){
  5522. $description=$this->get_args('description')?$this->get_args('description'):"";
  5523. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5524. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5525. //echo $price;die;
  5526. if (!empty($rid)){
  5527. Doo::loadModel("receipt");
  5528. $receipt=new receipt();
  5529. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5530. if (empty($receiptDetail))
  5531. return "/approval";
  5532. $reviseDetail=array();
  5533. if (empty($receiptDetail['reviseDetail'])){
  5534. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5535. $reviseDetailString=json_encode($reviseDetail);
  5536. $receipt->reviseDetail=$reviseDetailString;
  5537. $receipt->revisePrice=$price;
  5538. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5539. }else{
  5540. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5541. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5542. $reviseDetailString=json_encode($reviseDetail);
  5543. $receipt->reviseDetail=$reviseDetailString;
  5544. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5545. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5546. }
  5547. $receipt->update(array('where'=>'rid='.$rid));
  5548. }
  5549. return '/approvalEdi/'.$rid;
  5550. }
  5551. function personalCollect(){
  5552. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5553. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5554. $this->showCache($path);
  5555. Doo::loadModel("receiptDetail");
  5556. Doo::loadModel("itemStatistics");
  5557. Doo::loadModel('statistics');
  5558. $statistics=new statistics();
  5559. $itemStatistics=new itemStatistics();
  5560. $receiptDetail=new receiptDetail();
  5561. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5562. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5563. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5564. //create collect html
  5565. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5566. $adjustment=array();
  5567. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5568. array_push($collectArray['日常相关费用'], $collectHtml);
  5569. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5570. array_push($collectArray['差旅相关费用'], $collectHtml);
  5571. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5572. array_push($collectArray['培训班费用'], $collectHtml);
  5573. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5574. array_push($collectArray['其他'], $collectHtml);
  5575. $data['collectArray']=$collectArray;
  5576. //statistics html
  5577. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5578. if(empty($stList))
  5579. $stList=array('rePrice'=>0,'agPrice'=>0);
  5580. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5581. //Adjustment price html
  5582. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5583. array_push($adjustment, $collectHtml);
  5584. $data['adjustment']=$adjustment;
  5585. //total price html
  5586. $collectHtml="";$total=0;
  5587. for ($i=1;$i<=12;$i++){
  5588. $sumPrice=0;
  5589. foreach ($receiptCollectList as $key=>$value){
  5590. if($value['month']==$i){
  5591. $sumPrice+=$value['price'];
  5592. }
  5593. }
  5594. if ($sumPrice==0)
  5595. $collectHtml.='<td class="taR">-</td>';
  5596. else
  5597. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5598. $total+=$sumPrice;
  5599. }
  5600. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5601. $data['totalPrice']=$collectHtml;
  5602. $data['year']=$year;
  5603. $data['totalYear']=$total;
  5604. $data['memu']="receipt";
  5605. $data['staff']=$this->staff;
  5606. $data['receiptMemu']='personalCollect';
  5607. $data['verifyId']=$this->verifyId;
  5608. $data['executeId']=$this->executeId;
  5609. //year staff status 2,4
  5610. if($year<date("Y")){
  5611. Doo::loadModel('receipt');
  5612. $receipt=new receipt();
  5613. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5614. if(empty($receiptList)){
  5615. ob_start();
  5616. $this->render ( "/admin/saea_slist_collect", $data );
  5617. $this->cacheFile($path);die;
  5618. }
  5619. }
  5620. $this->render ( "/admin/saea_slist_collect", $data );
  5621. }
  5622. function personalCollectDetail(){
  5623. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5624. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5625. $this->showCache($path);
  5626. Doo::loadModel("receiptDetail");
  5627. Doo::loadModel("itemStatistics");
  5628. Doo::loadModel('statistics');
  5629. Doo::loadModel('accountItem');
  5630. $accountItem=new accountItem();
  5631. $statistics=new statistics();
  5632. $itemStatistics=new itemStatistics();
  5633. $receiptDetail=new receiptDetail();
  5634. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5635. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5636. $accountList=$accountItem->find(array('asArray'=>true));
  5637. //create CollectDetail HTML
  5638. $collectHtml=array();
  5639. foreach ($accountList as $key=>$value){
  5640. $html="";$asum=0;
  5641. for ($i=1;$i<=12;$i++){
  5642. $falg=true;
  5643. foreach ($receiptCollectList as $v) {
  5644. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5645. $asum+=$v['price'];
  5646. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5647. }
  5648. }
  5649. if($falg)
  5650. $html.='<td class="taR">-</td>';
  5651. }
  5652. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5653. $collectHtml[$value['category']][$value['name']]=$html;
  5654. }
  5655. $data['collectHtml']=$collectHtml;
  5656. //create Adjustment price html
  5657. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5658. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5659. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5660. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5661. array_push($collectArray['日常相关费用'], $collectHtml);
  5662. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5663. array_push($collectArray['差旅相关费用'], $collectHtml);
  5664. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5665. array_push($collectArray['培训班费用'], $collectHtml);
  5666. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5667. array_push($collectArray['其他'], $collectHtml);
  5668. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5669. array_push($adjustment, $collectHtml);
  5670. //total price html
  5671. $collectHtml="";$total=0;
  5672. for ($i=1;$i<=12;$i++){
  5673. $sumPrice=0;
  5674. foreach ($receiptCollectList as $key=>$value){
  5675. if($value['month']==$i){
  5676. $sumPrice+=$value['price'];
  5677. }
  5678. }
  5679. if ($sumPrice==0)
  5680. $collectHtml.='<td class="taR">-</td>';
  5681. else
  5682. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5683. $total+=$sumPrice;
  5684. }
  5685. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5686. //statistics html
  5687. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5688. if(empty($stList))
  5689. $stList=array('rePrice'=>0,'agPrice'=>0);
  5690. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5691. $data['collectArray']=$collectArray;
  5692. $data['adjustment']=$adjustment;
  5693. $data['totalPrice']=$collectHtml;
  5694. $data['totalYear']=$total;
  5695. $data['year']=$year;
  5696. $data['memu']="receipt";
  5697. $data['staff']=$this->staff;
  5698. $data['receiptMemu']='personalCollect';
  5699. $data['verifyId']=$this->verifyId;
  5700. $data['executeId']=$this->executeId;
  5701. //year staff status 2,4
  5702. if($year<date("Y")){
  5703. Doo::loadModel('receipt');
  5704. $receipt=new receipt();
  5705. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5706. if(empty($receiptList)){
  5707. ob_start();
  5708. $this->render ( "/admin/saeaCollectArticles", $data );
  5709. $this->cacheFile($path);die;
  5710. }
  5711. }
  5712. $this->render ( "/admin/saeaCollectArticles", $data );
  5713. }
  5714. function companyCategoryCollect(){
  5715. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5716. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5717. $this->showCache($path);
  5718. Doo::loadModel('L_category');
  5719. Doo::loadModel('itemStatistics');
  5720. Doo::loadModel('statistics');
  5721. $statistics=new statistics();
  5722. $Lcategory=new L_category();
  5723. $itemStatistics=new itemStatistics();
  5724. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5725. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5726. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5727. //ceatre companyCollectHtml
  5728. foreach ($LcategoryList as $value){
  5729. $html="";$asum=0;
  5730. for ($i=1;$i<=12;$i++){
  5731. $falg=true;
  5732. foreach ($itemStatisticsList as $v){
  5733. if($value['cid']==$v['cid']&&$i==$v['month']){
  5734. $asum+=$v['price'];
  5735. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5736. }
  5737. }
  5738. if($falg)
  5739. $html.='<td class="taR">-</td>';
  5740. }
  5741. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5742. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5743. }
  5744. $data['companyHtml']=$collectHtml;
  5745. //total price html
  5746. $collectHtml="";$total=0;
  5747. for ($i=1;$i<=12;$i++){
  5748. $sumPrice=0;
  5749. foreach ($itemStatisticsList as $key=>$value){
  5750. if($value['month']==$i){
  5751. $sumPrice+=$value['price'];
  5752. }
  5753. }
  5754. if ($sumPrice==0)
  5755. $collectHtml.='<td class="taR">-</td>';
  5756. else
  5757. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5758. $total+=$sumPrice;
  5759. }
  5760. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5761. $data['companyTotalHtml']=$collectHtml;
  5762. $data['total']=$total;
  5763. //statistics html
  5764. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5765. if(empty($stList))
  5766. $stList=array('rePrice'=>0,'agPrice'=>0);
  5767. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5768. $data['year']=$year;
  5769. $data['memu']="receipt";
  5770. $data['staff']=$this->staff;
  5771. $data['receiptMemu']='companyCategoryCollect';
  5772. $data['verifyId']=$this->verifyId;
  5773. $data['executeId']=$this->executeId;
  5774. //year staff status 2,4
  5775. if($year<date("Y")){
  5776. Doo::loadModel('receipt');
  5777. $receipt=new receipt();
  5778. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5779. if(empty($receiptList)){
  5780. ob_start();
  5781. $this->render ( "/admin/saeaCompanyCollect", $data );
  5782. $this->cacheFile($path);die;
  5783. }
  5784. }
  5785. $this->render ( "/admin/saeaCompanyCollect", $data );
  5786. }
  5787. function categoryCollectDetail(){
  5788. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5789. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5790. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5791. $this->showCache($path);
  5792. Doo::loadModel('statistics');
  5793. $statistics=new statistics();
  5794. Doo::loadModel("receiptDetail");
  5795. $receiptDetail=new receiptDetail();
  5796. Doo::loadModel('L_category');
  5797. $Lcategory=new L_category();
  5798. Doo::loadModel('accountItem');
  5799. $accountItem=new accountItem();
  5800. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5801. if ($cid==0){
  5802. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5803. if ($cid==0)
  5804. $cid=$LcategoryList[0]['cid'];
  5805. }
  5806. $data['LcategoryList']=$LcategoryList;
  5807. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5808. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5809. $accountList=$accountItem->find(array('asArray'=>true));
  5810. //create CollectDetail HTML
  5811. $collectHtml=array();
  5812. foreach ($accountList as $key=>$value){
  5813. $html="";$asum=0;
  5814. for ($i=1;$i<=12;$i++){
  5815. $falg=true;
  5816. foreach ($receiptCollectList as $v) {
  5817. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5818. $asum+=$v['price'];
  5819. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5820. }
  5821. }
  5822. if($falg)
  5823. $html.='<td class="taR">-</td>';
  5824. }
  5825. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5826. $collectHtml[$value['category']][$value['name']]=$html;
  5827. }
  5828. $data['collectHtml']=$collectHtml;
  5829. //create Adjustment price html
  5830. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5831. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5832. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5833. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5834. array_push($collectArray['日常相关费用'], $collectHtml);
  5835. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5836. array_push($collectArray['差旅相关费用'], $collectHtml);
  5837. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5838. array_push($collectArray['培训班费用'], $collectHtml);
  5839. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5840. array_push($collectArray['其他'], $collectHtml);
  5841. $data['collectArray']=$collectArray;
  5842. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5843. array_push($adjustment, $collectHtml);
  5844. $data['adjustment']=$adjustment;
  5845. //total price html
  5846. $collectHtml="";$total=0;
  5847. for ($i=1;$i<=12;$i++){
  5848. $sumPrice=0;
  5849. foreach ($receiptCollectList as $key=>$value){
  5850. if($value['month']==$i){
  5851. $sumPrice+=$value['price'];
  5852. }
  5853. }
  5854. if ($sumPrice==0)
  5855. $collectHtml.='<td class="taR">-</td>';
  5856. else
  5857. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5858. $total+=$sumPrice;
  5859. }
  5860. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5861. //statistics html
  5862. $stList=$statistics->statisticsByCid($year,$cid);
  5863. if(empty($stList))
  5864. $stList=array('rePrice'=>0,'agPrice'=>0);
  5865. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5866. $data['totalYear']=$total;
  5867. $data['year']=$year;
  5868. $data['cid']=$cid;
  5869. $data['memu']="receipt";
  5870. $data['staff']=$this->staff;
  5871. $data['receiptMemu']='companyCategoryCollect';
  5872. $data['verifyId']=$this->verifyId;
  5873. $data['executeId']=$this->executeId;
  5874. //year staff status 2,4
  5875. if($year<date("Y")){
  5876. Doo::loadModel('receipt');
  5877. $receipt=new receipt();
  5878. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5879. if(empty($receiptList)){
  5880. ob_start();
  5881. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5882. $this->cacheFile($path);die;
  5883. }
  5884. }
  5885. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5886. }
  5887. function staffCollect(){
  5888. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5889. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5890. //$this->showCache($path);
  5891. Doo::loadModel('statistics');
  5892. $statistics=new statistics();
  5893. Doo::loadModel("receiptDetail");
  5894. $receiptDetail=new receiptDetail();
  5895. Doo::loadModel('L_category');
  5896. $Lcategory=new L_category();
  5897. Doo::loadModel('accountItem');
  5898. $accountItem=new accountItem();
  5899. Doo::loadModel('staff');
  5900. $staff=new staff();
  5901. Doo::loadModel('itemStatistics');
  5902. $itemStatistics=new itemStatistics();
  5903. /*
  5904. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5905. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5906. if(empty($stList))
  5907. $stList=array('rePrice'=>0,'agPrice'=>0);
  5908. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5909. */
  5910. //statistics html
  5911. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5912. if(empty($stList))
  5913. $stList=array('rePrice'=>0,'agPrice'=>0);
  5914. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5915. //---
  5916. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5917. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5918. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5919. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5920. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5921. //print_r($itemStatisticsList);die;
  5922. //ceatre companyCollectHtml
  5923. foreach ($categoryList as $vlu){
  5924. $count=$vlu['count']+1;
  5925. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5926. $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;
  5927. foreach ($staffList as $value){
  5928. if ($vlu['cid']==$value['cid']){
  5929. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5930. $asum=0;
  5931. for ($i=1;$i<=12;$i++){
  5932. $falg=true;
  5933. foreach ($itemStatisticsList as $v){
  5934. if($value['sid']==$v['staff']&&$i==$v['month']){
  5935. if ($v['month']==1)
  5936. $m1+=$v['price'];
  5937. if ($v['month']==2)
  5938. $m2+=$v['price'];
  5939. if ($v['month']==3)
  5940. $m3+=$v['price'];
  5941. if ($v['month']==4)
  5942. $m4+=$v['price'];
  5943. if ($v['month']==5)
  5944. $m5+=$v['price'];
  5945. if ($v['month']==6)
  5946. $m6+=$v['price'];
  5947. if ($v['month']==7)
  5948. $m7+=$v['price'];
  5949. if ($v['month']==8)
  5950. $m8+=$v['price'];
  5951. if ($v['month']==9)
  5952. $m9+=$v['price'];
  5953. if ($v['month']==10)
  5954. $m10+=$v['price'];
  5955. if ($v['month']==11)
  5956. $m11+=$v['price'];
  5957. if ($v['month']==12)
  5958. $m12+=$v['price'];
  5959. $asum+=$v['price'];
  5960. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5961. }
  5962. }
  5963. if($falg)
  5964. $html.='<td class="taR">-</td>';
  5965. }
  5966. $m13+=$asum;
  5967. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5968. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5969. $html="";
  5970. }
  5971. }
  5972. $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>
  5973. <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>
  5974. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5975. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5976. }
  5977. $data['companyHtml']=$collectHtml;
  5978. //total price html
  5979. $collectHtml="";$total=0;
  5980. for ($i=1;$i<=12;$i++){
  5981. $sumPrice=0;
  5982. foreach ($itemStatisticsList as $key=>$value){
  5983. if($value['month']==$i){
  5984. $sumPrice+=$value['price'];
  5985. }
  5986. }
  5987. if ($sumPrice==0)
  5988. $collectHtml.='<td class="taR">-</td>';
  5989. else
  5990. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5991. $total+=$sumPrice;
  5992. }
  5993. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5994. $data['companyTotalHtml']=$collectHtml;
  5995. $data['total']=$total;
  5996. $data['year']=$year;
  5997. $data['memu']="receipt";
  5998. $data['staff']=$this->staff;
  5999. $data['receiptMemu']='companyCategoryCollect';
  6000. $data['verifyId']=$this->verifyId;
  6001. $data['executeId']=$this->executeId;
  6002. if ($year<=date("Y")){
  6003. Doo::loadModel('receipt');
  6004. $receipt=new receipt();
  6005. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  6006. if(empty($receiptList)){ //generated files
  6007. ob_start();
  6008. $this->render ( "/admin/saeaStaffCollectB", $data );
  6009. $this->cacheFile($path);die;
  6010. }
  6011. }
  6012. $this->render ( "/admin/saeaStaffCollectB", $data );
  6013. }
  6014. function staffCollectBak(){
  6015. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6016. $month=$this->get_args('month')?$this->get_args('month'):1;
  6017. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  6018. $this->showCache($path);
  6019. Doo::loadModel('statistics');
  6020. $statistics=new statistics();
  6021. Doo::loadModel("receiptDetail");
  6022. $receiptDetail=new receiptDetail();
  6023. Doo::loadModel('L_category');
  6024. $Lcategory=new L_category();
  6025. Doo::loadModel('accountItem');
  6026. $accountItem=new accountItem();
  6027. Doo::loadModel('staff');
  6028. $staff=new staff();
  6029. Doo::loadModel('itemStatistics');
  6030. $itemStatistics=new itemStatistics();
  6031. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6032. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6033. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6034. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6035. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6036. $staffList=$staff->find(array('asArray'=>true));
  6037. $htmlArray=array();
  6038. foreach ($LcategoryList as $value){
  6039. $htmlArray[$value['title']]=array();
  6040. foreach ($staffList as $v){
  6041. if($value['cid']==$v['cid']){
  6042. $html="";$falg=true;$staffSumPrice=0;
  6043. foreach ($itemStatisticsList as $a){
  6044. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6045. if(empty($a['price'])){
  6046. $html.='<td class="taR">-</td>';$falg=false;break;
  6047. }else{
  6048. $staffSumPrice+=$a['price'];
  6049. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6050. }
  6051. }
  6052. }
  6053. if ($falg){
  6054. $html.='<td class="taR">-</td>';$falg=true;
  6055. }
  6056. $falg=true;
  6057. foreach ($itemStatisticsList as $a){
  6058. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6059. if(empty($a['price'])){
  6060. $html.='<td class="taR">-</td>';$falg=false;break;
  6061. }else{
  6062. $staffSumPrice+=$a['price'];
  6063. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6064. }
  6065. }
  6066. }
  6067. if ($falg){
  6068. $html.='<td class="taR">-</td>';$falg=true;
  6069. }
  6070. $falg=true;
  6071. foreach ($itemStatisticsList as $a){
  6072. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6073. if(empty($a['price'])){
  6074. $html.='<td class="taR">-</td>';$falg=false;break;
  6075. }else{
  6076. $staffSumPrice+=$a['price'];
  6077. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6078. }
  6079. }
  6080. }
  6081. if ($falg){
  6082. $html.='<td class="taR">-</td>';$falg=true;
  6083. }
  6084. $falg=true;
  6085. foreach ($itemStatisticsList as $a){
  6086. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6087. if(!empty($a['price'])){
  6088. $staffSumPrice+=$a['price'];
  6089. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6090. }else{
  6091. $html.='<td class="taR">-</td>';$falg=false;break;
  6092. }
  6093. }
  6094. }
  6095. if ($falg){
  6096. $html.='<td class="taR">-</td>';$falg=true;
  6097. }
  6098. $falg=true;
  6099. foreach ($itemStatisticsList as $a){
  6100. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6101. if(!empty($a['price'])){
  6102. $staffSumPrice+=$a['price'];
  6103. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6104. }else{
  6105. $html.='<td class="taR">-</td>';$falg=false;break;
  6106. }
  6107. }
  6108. }
  6109. if ($falg){
  6110. $html.='<td class="taR">-</td>';$falg=true;
  6111. }
  6112. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6113. $htmlArray[$value['title']][$v['username']]=$html;
  6114. }
  6115. }
  6116. /*-- ---*/
  6117. //合计费用
  6118. $cateHtml="";$catePrice=0;$cateFalg=true;
  6119. foreach ($itemCategoryList as $l){
  6120. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6121. if(empty($l['price'])){
  6122. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6123. }else{
  6124. $catePrice+=$l['price'];
  6125. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6126. }
  6127. }
  6128. }
  6129. if ($cateFalg){
  6130. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6131. }
  6132. $cateFalg=true;
  6133. foreach ($itemCategoryList as $l){
  6134. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6135. if(empty($l['price'])){
  6136. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6137. }else{
  6138. $catePrice+=$l['price'];
  6139. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6140. }
  6141. }
  6142. }
  6143. if ($cateFalg){
  6144. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6145. }
  6146. $cateFalg=true;
  6147. foreach ($itemCategoryList as $l){
  6148. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6149. if(empty($l['price'])){
  6150. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6151. }else{
  6152. $catePrice+=$l['price'];
  6153. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6154. }
  6155. }
  6156. }
  6157. if ($cateFalg){
  6158. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6159. }
  6160. $cateFalg=true;
  6161. foreach ($itemCategoryList as $l){
  6162. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6163. if(empty($l['price'])){
  6164. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6165. }else{
  6166. $catePrice+=$l['price'];
  6167. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6168. }
  6169. }
  6170. }
  6171. if ($cateFalg){
  6172. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6173. }
  6174. $cateFalg=true;
  6175. foreach ($itemCategoryList as $l){
  6176. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6177. if(empty($l['price'])){
  6178. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6179. }else{
  6180. $catePrice+=$l['price'];
  6181. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6182. }
  6183. }
  6184. }
  6185. if ($cateFalg){
  6186. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6187. }
  6188. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6189. $htmlArray[$value['title']]['合计']=$cateHtml;
  6190. /*-- ---*/
  6191. }
  6192. //print_r($htmlArray);die;
  6193. $data['htmlArray']=$htmlArray;
  6194. //statistics html
  6195. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6196. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6197. if(empty($stList))
  6198. $stList=array('rePrice'=>0,'agPrice'=>0);
  6199. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6200. $monthHtml="";
  6201. for ($i=1;$i<=12;$i++){
  6202. if ($i==$month)
  6203. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6204. else
  6205. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6206. }
  6207. $data['monthHtml']=$monthHtml;
  6208. $data['year']=$year;
  6209. $data['month']=$month;
  6210. $data['memu']="receipt";
  6211. $data['staff']=$this->staff;
  6212. $data['receiptMemu']='companyCategoryCollect';
  6213. $data['verifyId']=$this->verifyId;
  6214. $data['executeId']=$this->executeId;
  6215. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6216. Doo::loadModel('receipt');
  6217. $receipt=new receipt();
  6218. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6219. if(empty($receiptList)){ //generated files
  6220. ob_start();
  6221. $this->render ( "/admin/saeaStaffCollect", $data );
  6222. $this->cacheFile($path);die;
  6223. }
  6224. }
  6225. $this->render ( "/admin/saeaStaffCollect", $data );
  6226. }
  6227. function lyt(){
  6228. Doo::loadModel("receiptDetail");
  6229. $receiptDetail=new receiptDetail();
  6230. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6231. foreach ($receiptCollectList as $key=>$value){
  6232. $receiptDetail=new receiptDetail();
  6233. $receiptDetail->pastDate=$value['date'];
  6234. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6235. }
  6236. }
  6237. function staffCollectMonthDetail(){
  6238. $year=$this->get_args('year')?$this->get_args('year'):"";
  6239. $month=$this->get_args('month')?$this->get_args('month'):"";
  6240. if(!$year)
  6241. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6242. if(!$month)
  6243. $month=isset($this->params['month'])?$this->params['month']:1;
  6244. Doo::loadModel('staff');
  6245. $staff=new staff();
  6246. Doo::loadModel("receiptDetail");
  6247. $receiptDetail=new receiptDetail();
  6248. Doo::loadModel('accountItem');
  6249. $accountItem=new accountItem();
  6250. Doo::loadModel('statistics');
  6251. $statistics=new statistics();
  6252. Doo::loadModel('L_category');
  6253. $lCategory=new L_category();
  6254. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6255. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6256. $list=array();
  6257. foreach ($categoryList as $vlu){
  6258. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6259. $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;
  6260. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6261. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6262. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6263. $s1=0;
  6264. $m1=0;
  6265. foreach ($staffList as $value){
  6266. if ($vlu['cid']==$value['cid']){
  6267. //pastDate
  6268. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6269. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6270. // if ($value['sid']==42){
  6271. // print_r($receiptCollectList);die;
  6272. // }
  6273. if(!empty($receiptCollectList)){
  6274. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6275. $html="";
  6276. $psum=0;
  6277. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6278. foreach ($item as $va){
  6279. $falg=true;
  6280. foreach ($receiptCollectList as $v){
  6281. if($v['itemCategory']=='日常相关费用'){
  6282. if($v['item']==$va){
  6283. if ($va=='市内交通费')
  6284. $r1+=$v['price'];
  6285. if ($va=='市内出租费')
  6286. $r2+=$v['price'];
  6287. if ($va=='办事处房租')
  6288. $r3+=$v['price'];
  6289. if ($va=='电话费')
  6290. $r4+=$v['price'];
  6291. if ($va=='水费')
  6292. $r5+=$v['price'];
  6293. if ($va=='电费')
  6294. $r6+=$v['price'];
  6295. if ($va=='办公费用')
  6296. $r7+=$v['price'];
  6297. if ($va=='邮寄费')
  6298. $r8+=$v['price'];
  6299. if ($va=='其他费用')
  6300. $r9+=$v['price'];
  6301. if ($va=='车辆费用')
  6302. $r10+=$v['price'];
  6303. if ($va=='广告费')
  6304. $r11+=$v['price'];
  6305. if ($va=='团队建设费')
  6306. $r13+=$v['price'];
  6307. if ($va=='物业管理费')
  6308. $r14+=$v['price'];
  6309. if ($va=='宽带费')
  6310. $r15+=$v['price'];
  6311. $psum+=$v['price'];
  6312. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6313. }
  6314. }
  6315. }
  6316. if($falg)
  6317. $html.='<td class="taR">-</td>';
  6318. }
  6319. $r12+=$psum;
  6320. if(!empty($psum))
  6321. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6322. else
  6323. $psum='<td class="colGreen taR">-</td>';
  6324. $receiptL['日常相关费用']=$psum.$html;
  6325. /*-----------------------------------*/
  6326. $html="";
  6327. $psum=0;
  6328. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6329. foreach ($item as $va){
  6330. $falg=true;
  6331. foreach ($receiptCollectList as $v){
  6332. if($v['itemCategory']=='差旅相关费用'){
  6333. if($v['item']==$va){
  6334. if ($va=='往来交通费')
  6335. $c1+=$v['price'];
  6336. if ($va=='市内交通费')
  6337. $c2+=$v['price'];
  6338. if ($va=='出差住宿费')
  6339. $c3+=$v['price'];
  6340. if ($va=='出差补助')
  6341. $c4+=$v['price'];
  6342. if ($va=='其他费用')
  6343. $c5+=$v['price'];
  6344. $psum+=$v['price'];
  6345. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6346. }
  6347. }
  6348. }
  6349. if($falg)
  6350. $html.='<td class="taR">-</td>';
  6351. }
  6352. $c6+=$psum;
  6353. if(!empty($psum))
  6354. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6355. else
  6356. $psum='<td class="colGreen taR">-</td>';
  6357. $receiptL['差旅相关费用']=$psum.$html;
  6358. /*-------------------------------------*/
  6359. $html="";
  6360. $psum=0;
  6361. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6362. foreach ($item as $va){
  6363. $falg=true;
  6364. foreach ($receiptCollectList as $v){
  6365. if($v['itemCategory']=='培训班费用'){
  6366. if($v['item']==$va){
  6367. if ($va=='场租费')
  6368. $p1+=$v['price'];
  6369. if ($va=='薪酬')
  6370. $p2+=$v['price'];
  6371. if ($va=='住宿费')
  6372. $p3+=$v['price'];
  6373. if ($va=='交通费')
  6374. $p4+=$v['price'];
  6375. if ($va=='餐饮费')
  6376. $p5+=$v['price'];
  6377. if ($va=='办公费')
  6378. $p6+=$v['price'];
  6379. if ($va=='公关费')
  6380. $p7+=$v['price'];
  6381. if ($va=='其他')
  6382. $p8+=$v['price'];
  6383. $psum+=$v['price'];
  6384. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6385. }
  6386. }
  6387. }
  6388. if($falg)
  6389. $html.='<td class="taR">-</td>';
  6390. }
  6391. $p9+=$psum;
  6392. if(!empty($psum))
  6393. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6394. else
  6395. $psum='<td class="colGreen taR">-</td>';
  6396. $receiptL['培训班费用']=$psum.$html;
  6397. /*-------------------------------------*/
  6398. $html="";
  6399. $psum=0;
  6400. $item=array('公关费','广告费','借款','可自加费用');
  6401. foreach ($item as $va){
  6402. $falg=true;
  6403. foreach ($receiptCollectList as $v){
  6404. if($v['itemCategory']=='其他'){
  6405. // if ($value['sid']==42){
  6406. //
  6407. // echo var_dump($v['item']);
  6408. // echo var_dump($va);
  6409. // echo var_dump($v['item']==" ".$va);
  6410. // echo $v['item']."==".$va."/<br/>";
  6411. // //print_r( $receiptCollectList);//echo $va;
  6412. // }
  6413. if(trim($v['item'])==$va){
  6414. if ($va=='公关费')
  6415. $t1+=$v['price'];
  6416. if ($va=='广告费'){
  6417. $t2+=$v['price'];
  6418. }
  6419. if ($va=='借款')
  6420. $t3+=$v['price'];
  6421. if ($va=='可自加费用')
  6422. $t4+=$v['price'];
  6423. $psum+=$v['price'];
  6424. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6425. }
  6426. }
  6427. }
  6428. if($falg)
  6429. $html.='<td class="taR">-</td>';
  6430. }
  6431. $t5+=$psum;
  6432. if(!empty($psum))
  6433. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6434. else
  6435. $psum='<td class="colGreen taR">-</td>';
  6436. $receiptL['其他']=$psum.$html;
  6437. /*-------------------------------------*/
  6438. $html="";
  6439. $psum=0;
  6440. foreach ($receiptCollectList as $v){
  6441. if($v['itemCategory']=='报销金额调整'){
  6442. if (!empty($v['price'])){
  6443. $psum+=$v['price'];
  6444. }
  6445. }
  6446. }
  6447. $s1+=$psum;
  6448. if(!empty($psum))
  6449. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6450. else
  6451. $psum='<td class="taR colOrange">-</td>';
  6452. $receiptL['报销金额调整']=$psum.$html;
  6453. }else{
  6454. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6455. <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>
  6456. <td class="taR">-</td><td class="taR">-</td>';
  6457. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6458. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6459. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6460. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6461. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6462. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6463. }
  6464. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6465. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6466. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6467. if(!empty($monthStaffPrice[0]['price'])){
  6468. $m1+=$monthStaffPrice[0]['price'];
  6469. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6470. }else
  6471. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6472. $list[$value['username']]=$receiptL;
  6473. }
  6474. }
  6475. $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>
  6476. <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>
  6477. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6478. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6479. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6480. $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>
  6481. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6482. $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>';
  6483. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6484. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6485. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6486. }
  6487. $data['list']=$list;
  6488. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6489. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6490. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6491. //statistics html
  6492. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6493. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6494. if(empty($stList))
  6495. $stList=array('rePrice'=>0,'agPrice'=>0);
  6496. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6497. $monthHtml="";
  6498. for ($i=1;$i<=12;$i++){
  6499. if ($i==$month)
  6500. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6501. else
  6502. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6503. }
  6504. $data['monthHtml']=$monthHtml;
  6505. $data['year']=$year;
  6506. $data['month']=$month;
  6507. $data['memu']="receipt";
  6508. $data['staff']=$this->staff;
  6509. $data['receiptMemu']='companyCategoryCollect';
  6510. $data['verifyId']=$this->verifyId;
  6511. $data['executeId']=$this->executeId;
  6512. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6513. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6514. }
  6515. function staffCollectMonthDetail2(){
  6516. $year=$this->get_args('year')?$this->get_args('year'):"";
  6517. $month=$this->get_args('month')?$this->get_args('month'):"";
  6518. if(!$year)
  6519. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6520. if(!$month)
  6521. $month=isset($this->params['month'])?$this->params['month']:1;
  6522. Doo::loadModel('staff');
  6523. $staff=new staff();
  6524. Doo::loadModel("receiptDetail");
  6525. $receiptDetail=new receiptDetail();
  6526. Doo::loadModel('accountItem');
  6527. $accountItem=new accountItem();
  6528. Doo::loadModel('statistics');
  6529. $statistics=new statistics();
  6530. Doo::loadModel('L_category');
  6531. $lCategory=new L_category();
  6532. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6533. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6534. $list=array();
  6535. foreach ($categoryList as $vlu){
  6536. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6537. $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;
  6538. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6539. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6540. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6541. $s1=0;
  6542. $m1=0;
  6543. foreach ($staffList as $value){
  6544. if ($vlu['cid']==$value['cid']){
  6545. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6546. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6547. if(!empty($receiptCollectList)){
  6548. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6549. $html="";
  6550. $psum=0;
  6551. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6552. foreach ($item as $va){
  6553. $falg=true;
  6554. foreach ($receiptCollectList as $v){
  6555. if($v['itemCategory']=='日常相关费用'){
  6556. if($v['item']==$va){
  6557. if ($va=='市内交通费')
  6558. $r1+=$v['price'];
  6559. if ($va=='市内出租费')
  6560. $r2+=$v['price'];
  6561. if ($va=='办事处房租')
  6562. $r3+=$v['price'];
  6563. if ($va=='电话费')
  6564. $r4+=$v['price'];
  6565. if ($va=='水费')
  6566. $r5+=$v['price'];
  6567. if ($va=='电费')
  6568. $r6+=$v['price'];
  6569. if ($va=='办公费用')
  6570. $r7+=$v['price'];
  6571. if ($va=='邮寄费')
  6572. $r8+=$v['price'];
  6573. if ($va=='其他费用')
  6574. $r9+=$v['price'];
  6575. if ($va=='车辆费用')
  6576. $r10+=$v['price'];
  6577. if ($va=='广告费')
  6578. $r11+=$v['price'];
  6579. if ($va=='团队建设费')
  6580. $r13+=$v['price'];
  6581. if ($va=='物业管理费')
  6582. $r14+=$v['price'];
  6583. if ($va=='宽带费')
  6584. $r15+=$v['price'];
  6585. $psum+=$v['price'];
  6586. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6587. }
  6588. }
  6589. }
  6590. if($falg)
  6591. $html.='<td class="taR">-</td>';
  6592. }
  6593. $r12+=$psum;
  6594. if(!empty($psum))
  6595. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6596. else
  6597. $psum='<td class="colGreen taR">-</td>';
  6598. $receiptL['日常相关费用']=$psum.$html;
  6599. /*-----------------------------------*/
  6600. $html="";
  6601. $psum=0;
  6602. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6603. foreach ($item as $va){
  6604. $falg=true;
  6605. foreach ($receiptCollectList as $v){
  6606. if($v['itemCategory']=='差旅相关费用'){
  6607. if($v['item']==$va){
  6608. if ($va=='往来交通费')
  6609. $c1+=$v['price'];
  6610. if ($va=='市内交通费')
  6611. $c2+=$v['price'];
  6612. if ($va=='出差住宿费')
  6613. $c3+=$v['price'];
  6614. if ($va=='出差补助')
  6615. $c4+=$v['price'];
  6616. if ($va=='其他费用')
  6617. $c5+=$v['price'];
  6618. $psum+=$v['price'];
  6619. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6620. }
  6621. }
  6622. }
  6623. if($falg)
  6624. $html.='<td class="taR">-</td>';
  6625. }
  6626. $c6+=$psum;
  6627. if(!empty($psum))
  6628. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6629. else
  6630. $psum='<td class="colGreen taR">-</td>';
  6631. $receiptL['差旅相关费用']=$psum.$html;
  6632. /*-------------------------------------*/
  6633. $html="";
  6634. $psum=0;
  6635. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6636. foreach ($item as $va){
  6637. $falg=true;
  6638. foreach ($receiptCollectList as $v){
  6639. if($v['itemCategory']=='培训班费用'){
  6640. if($v['item']==$va){
  6641. if ($va=='场租费')
  6642. $p1+=$v['price'];
  6643. if ($va=='薪酬')
  6644. $p2+=$v['price'];
  6645. if ($va=='住宿费')
  6646. $p3+=$v['price'];
  6647. if ($va=='交通费')
  6648. $p4+=$v['price'];
  6649. if ($va=='餐饮费')
  6650. $p5+=$v['price'];
  6651. if ($va=='办公费')
  6652. $p6+=$v['price'];
  6653. if ($va=='公关费')
  6654. $p7+=$v['price'];
  6655. if ($va=='其他')
  6656. $p8+=$v['price'];
  6657. $psum+=$v['price'];
  6658. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6659. }
  6660. }
  6661. }
  6662. if($falg)
  6663. $html.='<td class="taR">-</td>';
  6664. }
  6665. $p9+=$psum;
  6666. if(!empty($psum))
  6667. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6668. else
  6669. $psum='<td class="colGreen taR">-</td>';
  6670. $receiptL['培训班费用']=$psum.$html;
  6671. /*-------------------------------------*/
  6672. $html="";
  6673. $psum=0;
  6674. $item=array('公关费','广告费','借款','可自加费用');
  6675. foreach ($item as $va){
  6676. $falg=true;
  6677. foreach ($receiptCollectList as $v){
  6678. if($v['itemCategory']=='其他'){
  6679. if($v['item']==$va){
  6680. if ($va=='公关费')
  6681. $t1+=$v['price'];
  6682. if ($va=='广告费')
  6683. $t2+=$v['price'];
  6684. if ($va=='借款')
  6685. $t3+=$v['price'];
  6686. if ($va=='可自加费用')
  6687. $t4+=$v['price'];
  6688. $psum+=$v['price'];
  6689. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6690. }
  6691. }
  6692. }
  6693. if($falg)
  6694. $html.='<td class="taR">-</td>';
  6695. }
  6696. $t5+=$psum;
  6697. if(!empty($psum))
  6698. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6699. else
  6700. $psum='<td class="colGreen taR">-</td>';
  6701. $receiptL['其他']=$psum.$html;
  6702. /*-------------------------------------*/
  6703. $html="";
  6704. $psum=0;
  6705. foreach ($receiptCollectList as $v){
  6706. if($v['itemCategory']=='报销金额调整'){
  6707. if (!empty($v['price'])){
  6708. $psum+=$v['price'];
  6709. }
  6710. }
  6711. }
  6712. $s1+=$psum;
  6713. if(!empty($psum))
  6714. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6715. else
  6716. $psum='<td class="taR colOrange">-</td>';
  6717. $receiptL['报销金额调整']=$psum.$html;
  6718. }else{
  6719. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6720. <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>';
  6721. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6722. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6723. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6724. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6725. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6726. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6727. }
  6728. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6729. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6730. if(!empty($monthStaffPrice[0]['price'])){
  6731. $m1+=$monthStaffPrice[0]['price'];
  6732. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6733. }else
  6734. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6735. $list[$value['username']]=$receiptL;
  6736. }
  6737. }
  6738. $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>
  6739. <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>
  6740. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6741. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6742. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6743. $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>
  6744. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6745. $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>';
  6746. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6747. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6748. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6749. }
  6750. $data['list']=$list;
  6751. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6752. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6753. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6754. //statistics html
  6755. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6756. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6757. if(empty($stList))
  6758. $stList=array('rePrice'=>0,'agPrice'=>0);
  6759. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6760. $monthHtml="";
  6761. for ($i=1;$i<=12;$i++){
  6762. if ($i==$month)
  6763. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6764. else
  6765. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6766. }
  6767. $data['monthHtml']=$monthHtml;
  6768. $data['year']=$year;
  6769. $data['month']=$month;
  6770. $data['memu']="receipt";
  6771. $data['staff']=$this->staff;
  6772. $data['receiptMemu']='companyCategoryCollect';
  6773. $data['verifyId']=$this->verifyId;
  6774. $data['executeId']=$this->executeId;
  6775. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6776. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6777. }
  6778. function companyMonthCollectDetail(){
  6779. $year=$this->get_args('year')?$this->get_args('year'):"";
  6780. $month=$this->get_args('month')?$this->get_args('month'):"";
  6781. if(!$year)
  6782. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6783. if(!$month)
  6784. $month=isset($this->params['month'])?$this->params['month']:1;
  6785. Doo::loadModel('staff');
  6786. $staff=new staff();
  6787. Doo::loadModel("receiptDetail");
  6788. $receiptDetail=new receiptDetail();
  6789. Doo::loadModel('accountItem');
  6790. $accountItem=new accountItem();
  6791. Doo::loadModel('statistics');
  6792. $statistics=new statistics();
  6793. Doo::loadModel('L_category');
  6794. $lCategory=new L_category();
  6795. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6796. $categoryList=$lCategory->find(array('asArray'=>true));
  6797. $list=array();
  6798. foreach ($categoryList as $value){
  6799. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6800. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6801. if(!empty($receiptCollectList)){
  6802. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6803. $html="";
  6804. $psum=0;
  6805. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6806. foreach ($item as $va){
  6807. $falg=true;
  6808. foreach ($receiptCollectList as $v){
  6809. if($v['itemCategory']=='日常相关费用'){
  6810. if($v['item']==$va){
  6811. $psum+=$v['price'];
  6812. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6813. }
  6814. }
  6815. }
  6816. if($falg)
  6817. $html.='<td class="taR">-</td>';
  6818. }
  6819. if(!empty($psum))
  6820. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6821. else
  6822. $psum='<td class="colGreen taR">-</td>';
  6823. $receiptL['日常相关费用']=$psum.$html;
  6824. /*-----------------------------------*/
  6825. $html="";
  6826. $psum=0;
  6827. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6828. foreach ($item as $va){
  6829. $falg=true;
  6830. foreach ($receiptCollectList as $v){
  6831. if($v['itemCategory']=='差旅相关费用'){
  6832. if($v['item']==$va){
  6833. $psum+=$v['price'];
  6834. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6835. }
  6836. }
  6837. }
  6838. if($falg)
  6839. $html.='<td class="taR">-</td>';
  6840. }
  6841. if(!empty($psum))
  6842. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6843. else
  6844. $psum='<td class="colGreen taR">-</td>';
  6845. $receiptL['差旅相关费用']=$psum.$html;
  6846. /*-------------------------------------*/
  6847. $html="";
  6848. $psum=0;
  6849. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6850. foreach ($item as $va){
  6851. $falg=true;
  6852. foreach ($receiptCollectList as $v){
  6853. if($v['itemCategory']=='培训班费用'){
  6854. if($v['item']==$va){
  6855. $psum+=$v['price'];
  6856. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6857. }
  6858. }
  6859. }
  6860. if($falg)
  6861. $html.='<td class="taR">-</td>';
  6862. }
  6863. if(!empty($psum))
  6864. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6865. else
  6866. $psum='<td class="colGreen taR">-</td>';
  6867. $receiptL['培训班费用']=$psum.$html;
  6868. /*-------------------------------------*/
  6869. $html="";
  6870. $psum=0;
  6871. $item=array('公关费','广告费','借款','可自加费用');
  6872. foreach ($item as $va){
  6873. $falg=true;
  6874. foreach ($receiptCollectList as $v){
  6875. if($v['itemCategory']=='其他'){
  6876. if($v['item']==$va){
  6877. $psum+=$v['price'];
  6878. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6879. }
  6880. }
  6881. }
  6882. if($falg)
  6883. $html.='<td class="taR">-</td>';
  6884. }
  6885. if(!empty($psum))
  6886. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6887. else
  6888. $psum='<td class="colGreen taR">-</td>';
  6889. $receiptL['其他']=$psum.$html;
  6890. /*-------------------------------------*/
  6891. $html="";
  6892. $psum=0;
  6893. foreach ($receiptCollectList as $v){
  6894. if($v['itemCategory']=='报销金额调整'){
  6895. if (!empty($v['price']))
  6896. $psum+=$v['price'];
  6897. }
  6898. }
  6899. if(!empty($psum))
  6900. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6901. else
  6902. $psum='<td class="taR colOrange">-</td>';
  6903. $receiptL['报销金额调整']=$psum.$html;
  6904. }else{
  6905. $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>
  6906. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6907. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6908. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6909. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6910. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6911. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6912. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6913. }
  6914. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6915. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6916. if(!empty($monthStaffPrice[0]['price']))
  6917. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6918. else
  6919. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6920. $list[$value['title']]=$receiptL;
  6921. }
  6922. $data['list']=$list;
  6923. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6924. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6925. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6926. //print_r($data['monthPriceHtml']);
  6927. // foreach ($data['monthPriceHtml'] as $value){
  6928. // echo $value;
  6929. // }
  6930. // die;
  6931. //statistics html
  6932. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6933. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6934. if(empty($stList))
  6935. $stList=array('rePrice'=>0,'agPrice'=>0);
  6936. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6937. $monthHtml="";
  6938. for ($i=1;$i<=12;$i++){
  6939. if ($i==$month)
  6940. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6941. else
  6942. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6943. }
  6944. $data['monthHtml']=$monthHtml;
  6945. $data['year']=$year;
  6946. $data['month']=$month;
  6947. $data['memu']="receipt";
  6948. $data['staff']=$this->staff;
  6949. $data['receiptMemu']='companyCategoryCollect';
  6950. $data['verifyId']=$this->verifyId;
  6951. $data['executeId']=$this->executeId;
  6952. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6953. }
  6954. function staffCollectDetail(){
  6955. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6956. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6957. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6958. if(!$staffname){
  6959. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6960. $staffname= urldecode($staffname);
  6961. }
  6962. Doo::loadModel('staff');
  6963. $staff=new staff();
  6964. Doo::loadModel("receiptDetail");
  6965. $receiptDetail=new receiptDetail();
  6966. Doo::loadModel('accountItem');
  6967. $accountItem=new accountItem();
  6968. Doo::loadModel('statistics');
  6969. $statistics=new statistics();
  6970. Doo::loadModel('L_category');
  6971. $lCategory=new L_category();
  6972. $staffList=$staff->find(array('asArray'=>true));
  6973. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6974. foreach ($staffList as $value){
  6975. if ($value['username']==$staffname&&$value['username']!='admin'){
  6976. $stTitle=$value['category'].'-'.$value['username'];
  6977. $staffId=$value['sid'];
  6978. $cid=$value['cid'];
  6979. $ocid=$value['cid'];
  6980. if (!empty($value['othercid']))
  6981. $cid=$value['cid'].','.$value['othercid'];
  6982. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6983. }elseif ($value['username']!='admin')
  6984. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6985. }
  6986. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6987. if(empty($pcid))
  6988. $pcid=$ocid;
  6989. $data['ocid']=$pcid;
  6990. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6991. $this->showCache($path);
  6992. //
  6993. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6994. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6995. $accountList=$accountItem->find(array('asArray'=>true));
  6996. //create CollectDetail HTML
  6997. $collectHtml=array();
  6998. foreach ($accountList as $key=>$value){
  6999. $html="";$asum=0;
  7000. for ($i=1;$i<=12;$i++){
  7001. $falg=true;
  7002. foreach ($receiptCollectList as $v) {
  7003. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  7004. $asum+=$v['price'];
  7005. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  7006. }
  7007. }
  7008. if($falg)
  7009. $html.='<td class="taR">-</td>';
  7010. }
  7011. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  7012. $collectHtml[$value['category']][$value['name']]=$html;
  7013. }
  7014. $data['collectHtml']=$collectHtml;
  7015. //create Adjustment price html
  7016. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7017. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  7018. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7019. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  7020. array_push($collectArray['日常相关费用'], $collectHtml);
  7021. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  7022. array_push($collectArray['差旅相关费用'], $collectHtml);
  7023. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7024. array_push($collectArray['培训班费用'], $collectHtml);
  7025. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7026. array_push($collectArray['其他'], $collectHtml);
  7027. $data['collectArray']=$collectArray;
  7028. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7029. array_push($adjustment, $collectHtml);
  7030. $data['adjustment']=$adjustment;
  7031. //total price html
  7032. $collectHtml="";$total=0;
  7033. for ($i=1;$i<=12;$i++){
  7034. $sumPrice=0;
  7035. foreach ($receiptCollectList as $key=>$value){
  7036. if($value['month']==$i){
  7037. $sumPrice+=$value['price'];
  7038. }
  7039. }
  7040. if ($sumPrice==0)
  7041. $collectHtml.='<td class="taR">-</td>';
  7042. else
  7043. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7044. $total+=$sumPrice;
  7045. }
  7046. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7047. //statistics html
  7048. $stList=$statistics->statisticsByYear($year,$staffId);
  7049. if(empty($stList))
  7050. $stList=array('rePrice'=>0,'agPrice'=>0);
  7051. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7052. $data['totalPrice']=$collectHtml;
  7053. $data['totalYear']=$total;
  7054. $data['stHtml']=$stHtml;
  7055. $data['year']=$year;
  7056. $data['stTitle']=$stTitle;
  7057. $data['memu']="receipt";
  7058. $data['staff']=$this->staff;
  7059. $data['receiptMemu']='companyCategoryCollect';
  7060. $data['verifyId']=$this->verifyId;
  7061. $data['executeId']=$this->executeId;
  7062. if ($year<date("Y")){
  7063. Doo::loadModel('receipt');
  7064. $receipt=new receipt();
  7065. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7066. if(empty($receiptList)){ //generated files
  7067. ob_start();
  7068. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7069. $this->cacheFile($path);die;
  7070. }
  7071. }
  7072. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7073. }
  7074. function BUGFLAG(){
  7075. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7076. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7077. $month=$this->get_args('month')?$this->get_args('month'):"";
  7078. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7079. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7080. if (empty($status))
  7081. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7082. $page_size=12;
  7083. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7084. $vidList=array();
  7085. $button=0;
  7086. Doo::loadModel('verify');
  7087. $verify=new verify();
  7088. Doo::loadModel('receipt');
  7089. $receipt=new receipt();
  7090. Doo::loadModel('staff');
  7091. $staff=new staff();
  7092. Doo::loadModel('L_category');
  7093. $Lcategory=new L_category();
  7094. $dateCondition=" and Year(date) =".$year;
  7095. if(!empty($month))
  7096. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7097. $categoryList=$Lcategory->find(array('asArray'=>true));
  7098. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7099. $cateCondition="";$staffCondition="";$approvalCondition="";
  7100. if (!empty($cid))
  7101. $cateCondition=' and cid='.$cid;
  7102. if(!empty($sid)){
  7103. $staffCondition=' and staff='.$sid;
  7104. $cateCondition="";
  7105. }
  7106. $approvalCondition=" and status=".$status;
  7107. if($status==2){
  7108. //查找角色审批人
  7109. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7110. }
  7111. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7112. $approvalCondition=' and status=2 ';
  7113. }
  7114. if($status==1){
  7115. $approvalCondition=' and (status='.$status.' or status=6) ';
  7116. }
  7117. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7118. $pageinfo['page']=array('previous'=>'');
  7119. if ($status==0){
  7120. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7121. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7122. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7123. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7124. }else
  7125. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7126. ,'desc'=>'rid','asArray'=>true));
  7127. $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
  7128. ,'desc'=>'rid','asArray'=>true));
  7129. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7130. //print_r($pageinfo);
  7131. $Locate=0;
  7132. foreach ($receiptList as $key=>$value){
  7133. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7134. $receiptList[$key]['reviseDetail']=array();
  7135. if (!empty($value['reviseDetail']))
  7136. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7137. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7138. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7139. $receiptList[$key]['category']=$categoryDetil['title'];
  7140. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7141. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7142. $verifyStaff=json_decode($value['verifyStaff'],true);
  7143. foreach ($verifyList as $k=>$v){
  7144. //init verifyStaff
  7145. $verifyList[$k]['date']="";
  7146. $verifyList[$k]['opinion']="";
  7147. $verifyList[$k]['status']="";
  7148. if (empty($verifyStaff)){
  7149. $verifyList[$k]['date']="";
  7150. $verifyList[$k]['opinion']="";
  7151. if ($v[0]==$this->staff[0]['sid']){
  7152. $verifyList[$k]['status']=4;
  7153. $button=4;
  7154. }
  7155. }else{
  7156. $flag=true;
  7157. foreach ($verifyStaff as $m=>$u){
  7158. if ($v[0]==$m){
  7159. $verifyList[$k]['date']=$u['date'];
  7160. $verifyList[$k]['opinion']=$u['opinion'];
  7161. $verifyList[$k]['status']=$u['status'];
  7162. $flag=false;
  7163. break;
  7164. }
  7165. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7166. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7167. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7168. }
  7169. if($flag){//检测可编辑
  7170. if($v[0]==$this->staff[0]['sid']){
  7171. $verifyList[$k]['status']=4;$button=4;
  7172. }
  7173. }
  7174. }
  7175. }
  7176. $receiptList[$key]['verifyList']=$verifyList;
  7177. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7178. $receiptList[$key]['button']=$button;
  7179. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7180. }
  7181. //print_r($receiptList);die;
  7182. //$data['verifyDetail']=$verifyDetail;
  7183. $mothHtml="";
  7184. for($i=1;$i<=12;$i++){
  7185. if($month==$i)
  7186. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7187. else
  7188. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7189. }
  7190. $data['mothHtml']=$mothHtml;
  7191. $data['page']=$pageinfo;
  7192. $data['receiptList']=$receiptList;
  7193. $data['receiptApprovalCount']=count($rLRes);
  7194. $data['status']=$status;
  7195. $data['year']=$year;
  7196. $data['categoryList']=$categoryList;
  7197. $data['staffList']=$staffList;
  7198. $data['cid']=$cid;
  7199. $data['sid']=$sid;
  7200. //print_r($receiptList);
  7201. $data['memu']="receipt";
  7202. $data['staff']=$this->staff;
  7203. $data['receiptMemu']='approvalExpenses';
  7204. $data['verifyId']=$this->verifyId;
  7205. $data['executeId']=$this->executeId;
  7206. $this->render ( "/admin/FALG", $data );
  7207. }
  7208. function ajaxGetReceiptOrder(){
  7209. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7210. if (!empty($receiptOrder)){
  7211. Doo::loadModel('receipt');
  7212. $receipt=new receipt();
  7213. Doo::loadModel ( 'staff' );
  7214. $staff = new staff ();
  7215. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7216. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7217. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7218. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7219. </tbody></table><table class="table table table-bordered"><tbody>';
  7220. foreach ($verifyStaff as $key=>$value){
  7221. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7222. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7223. }
  7224. $html.='</tbody></table></div></div>';
  7225. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7226. }
  7227. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7228. }
  7229. function _getMonthCollectDetail($receiptCollectList){
  7230. if(!empty($receiptCollectList)){
  7231. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7232. $html="";
  7233. $psum=0;
  7234. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7235. foreach ($item as $value){
  7236. $falg=true;
  7237. foreach ($receiptCollectList as $v){
  7238. if($v['itemCategory']=='日常相关费用'){
  7239. if($v['item']==$value){
  7240. $psum+=$v['price'];
  7241. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7242. }
  7243. }
  7244. }
  7245. if($falg)
  7246. $html.='<td class="taR">-</td>';
  7247. }
  7248. if(!empty($psum))
  7249. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7250. else
  7251. $psum='<td class="colGreen taR">-</td>';
  7252. $receiptL['日常相关费用']=$psum.$html;
  7253. /*-----------------------------------*/
  7254. $html="";
  7255. $psum=0;
  7256. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7257. foreach ($item as $value){
  7258. $falg=true;
  7259. foreach ($receiptCollectList as $v){
  7260. if($v['itemCategory']=='差旅相关费用'){
  7261. if($v['item']==$value){
  7262. $psum+=$v['price'];
  7263. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7264. }
  7265. }
  7266. }
  7267. if($falg)
  7268. $html.='<td class="taR">-</td>';
  7269. }
  7270. if(!empty($psum))
  7271. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7272. else
  7273. $psum='<td class="colGreen taR">-</td>';
  7274. $receiptL['差旅相关费用']=$psum.$html;
  7275. /*-------------------------------------*/
  7276. $html="";
  7277. $psum=0;
  7278. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7279. foreach ($item as $value){
  7280. $falg=true;
  7281. foreach ($receiptCollectList as $v){
  7282. if($v['itemCategory']=='培训班费用'){
  7283. if($v['item']==$value){
  7284. $psum+=$v['price'];
  7285. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7286. }
  7287. }
  7288. }
  7289. if($falg)
  7290. $html.='<td class="taR">-</td>';
  7291. }
  7292. if(!empty($psum))
  7293. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7294. else
  7295. $psum='<td class="colGreen taR">-</td>';
  7296. $receiptL['培训班费用']=$psum.$html;
  7297. /*-------------------------------------*/
  7298. $html="";
  7299. $psum=0;
  7300. $item=array('公关费','广告费','借款','可自加费用');
  7301. foreach ($item as $value){
  7302. $falg=true;
  7303. foreach ($receiptCollectList as $v){
  7304. if($v['itemCategory']=='其他'){
  7305. if($v['item']==$value){
  7306. $psum+=$v['price'];
  7307. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7308. }
  7309. }
  7310. }
  7311. if($falg)
  7312. $html.='<td class="taR">-</td>';
  7313. }
  7314. if(!empty($psum))
  7315. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7316. else
  7317. $psum='<td class="colGreen taR">-</td>';
  7318. $receiptL['其他']=$psum.$html;
  7319. /*-------------------------------------*/
  7320. $html="";
  7321. $psum=0;
  7322. foreach ($receiptCollectList as $v){
  7323. if($v['itemCategory']=='报销金额调整'){
  7324. if (!empty($v['price']))
  7325. $psum+=$v['price'];
  7326. }
  7327. }
  7328. if(!empty($psum))
  7329. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7330. else
  7331. $psum='<td class="taR colOrange">-</td>';
  7332. $receiptL['报销金额调整']=$psum.$html;
  7333. }else{
  7334. $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>
  7335. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7336. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7337. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7338. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7339. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7340. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7341. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7342. }
  7343. return $receiptL;
  7344. }
  7345. function eMail(){
  7346. Doo::loadModel('staff');
  7347. $staff=new staff();
  7348. Doo::loadModel('receipt');
  7349. $receipt=new receipt();
  7350. Doo::loadModel('L_category');
  7351. $Lcategory=new L_category();
  7352. Doo::loadModel("verify");
  7353. $verify=new verify();
  7354. $staffList=$staff->find(array('asArray'=>true));
  7355. foreach ($staffList as $key=>$value){
  7356. if($value['username']!='admin'){
  7357. //提交人
  7358. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7359. if(!empty($receiptList)){
  7360. $html='<br><div><style></style>
  7361. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7362. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7363. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7364. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7365. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7366. <tbody><tr>
  7367. <td style="padding: 0 40px;" align="left">
  7368. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7369. </td></tr><tr>
  7370. <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>
  7371. </tr>
  7372. </tbody> </table></td> </tr> <tr><td>
  7373. <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">
  7374. <tbody> <tr><td>
  7375. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7376. 以下报销单完成了审批,等着收款吧:</p>
  7377. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7378. foreach ($receiptList as $k=>$v){
  7379. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7380. $html.='
  7381. <tr>
  7382. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7383. <td align="left">
  7384. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7385. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7386. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7387. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7388. </tr>';
  7389. }
  7390. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7391. <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>
  7392. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7393. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7394. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7395. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7396. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7397. $receipt=new receipt();
  7398. $receipt->notice=1;
  7399. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7400. }
  7401. }
  7402. //审批人
  7403. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7404. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7405. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7406. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7407. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7408. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7409. <tbody><tr><td style="padding: 0 40px;" align="left">
  7410. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7411. </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>
  7412. </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">
  7413. <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>
  7414. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7415. foreach ($verifyList as $k=>$v){
  7416. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7417. foreach ($receiptList as $r=>$l){
  7418. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7419. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7420. $html.='
  7421. <tr>
  7422. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7423. <td align="left">
  7424. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7425. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7426. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7427. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7428. </tr>';
  7429. }
  7430. }
  7431. $html.='
  7432. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7433. <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>
  7434. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7435. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7436. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7437. // $receipt=new receipt();
  7438. // $receipt->notice=1;
  7439. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7440. }
  7441. }
  7442. }
  7443. }
  7444. function setWXMsg($rid,$type){
  7445. Doo::loadModel("receipt");
  7446. $receipt=new receipt();
  7447. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  7448. if(!empty($receiptDetail)){
  7449. Doo::loadModel('staff');
  7450. $staff = new staff();
  7451. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  7452. if(!empty($staffmsg['wxid'])){
  7453. require_once (SITE_PATH . '/protected/class/client.php');
  7454. $client = new client ('http://m.cld.smartcost.com.cn/');
  7455. $user = $staffmsg['wxid'];
  7456. $receiptName = '';
  7457. $msg = '';
  7458. switch($receiptDetail['Rtype']){
  7459. case 0:$receiptName = '报销';break;
  7460. case 1:$receiptName = '借款';break;
  7461. case 2:$receiptName = '对公汇款';break;
  7462. }
  7463. switch($type){
  7464. case 1:$msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';break;
  7465. case 2:$msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';break;
  7466. case 3:$msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被终止。';break;
  7467. }
  7468. $result = $client->SendMsg($user,$msg,'text');
  7469. }
  7470. }
  7471. }
  7472. // Email发送函数
  7473. function SMail($toemail, $subject, $contents) {
  7474. Doo::loadClass('class.phpmailer');
  7475. $mail = new PHPMailer();
  7476. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7477. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7478. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7479. $mail->Password = "cDO1GjtY1seH"; //密码
  7480. $mail->CharSet = "UTF8";
  7481. $mail->SMTPAuth = true;
  7482. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7483. $mail->Mailer = "smtp";
  7484. $mail->Port = 25;
  7485. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7486. $mail->MsgHTML($contents);
  7487. $mail->AddAddress($toemail);
  7488. $mail->CharSet = "UTF-8";
  7489. return $mail->Send();
  7490. }
  7491. function swfupload(){
  7492. $POST_MAX_SIZE = ini_get('post_max_size');
  7493. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7494. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7495. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7496. header("HTTP/1.1 500 Internal Server Error");
  7497. echo "POST exceeded maximum allowed size.";
  7498. exit(0);
  7499. }
  7500. // Settings
  7501. $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)
  7502. $upload_name = "Filedata";
  7503. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7504. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7505. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7506. // Other variables
  7507. $MAX_FILENAME_LENGTH = 260;
  7508. $file_name = "";
  7509. $file_extension = "";
  7510. $uploadErrors = array(
  7511. 0=>"文件上传成功",
  7512. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7513. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7514. 3=>"上传的文件仅为部分文件",
  7515. 4=>"没有文件上传",
  7516. 6=>"缺少临时文件夹"
  7517. );
  7518. $nk= time();
  7519. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7520. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7521. echo "文件无法保存.";
  7522. exit(0);
  7523. }
  7524. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7525. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7526. exit(0);
  7527. }
  7528. function _GetFileEXT($filename) {
  7529. $pics = explode ( '.', $filename );
  7530. $num = count ( $pics );
  7531. return $pics [$num - 1];
  7532. }
  7533. /**
  7534. * 获取get或者POST值
  7535. * @param string $name 属性名称
  7536. * @return fixed 值
  7537. */
  7538. function get_args($name) {
  7539. if (isset ( $_GET [$name] )) {
  7540. if (is_array ( $_GET [$name] ))
  7541. return $_GET [$name];
  7542. else
  7543. return addslashes ( $_GET [$name] );
  7544. } elseif (isset ( $_POST [$name] )) {
  7545. if (is_array ( $_POST [$name] ))
  7546. return $_POST [$name];
  7547. else
  7548. return addslashes ( $_POST [$name] );
  7549. } else
  7550. return false;
  7551. }
  7552. function num_to_rmb($num){
  7553. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7554. $c2 = "分角元拾佰仟万拾佰仟亿";
  7555. //精确到分后面就不要了,所以只留两个小数位
  7556. $num = round($num, 2);
  7557. //将数字转化为整数
  7558. $num = $num * 100;
  7559. if (strlen($num) > 10) {
  7560. return "金额太大,请检查";
  7561. }
  7562. $i = 0;
  7563. $c = "";
  7564. while (1) {
  7565. if ($i == 0) {
  7566. //获取最后一位数字
  7567. $n = substr($num, strlen($num)-1, 1);
  7568. } else {
  7569. $n = $num % 10;
  7570. }
  7571. //每次将最后一位数字转化为中文
  7572. $p1 = substr($c1, 3 * $n, 3);
  7573. $p2 = substr($c2, 3 * $i, 3);
  7574. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7575. $c = $p1 . $p2 . $c;
  7576. } else {
  7577. $c = $p1 . $c;
  7578. }
  7579. $i = $i + 1;
  7580. //去掉数字最后一位了
  7581. $num = $num / 10;
  7582. $num = (int)$num;
  7583. //结束循环
  7584. if ($num == 0) {
  7585. break;
  7586. }
  7587. }
  7588. $j = 0;
  7589. $slen = strlen($c);
  7590. while ($j < $slen) {
  7591. //utf8一个汉字相当3个字符
  7592. $m = substr($c, $j, 6);
  7593. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7594. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7595. $left = substr($c, 0, $j);
  7596. $right = substr($c, $j + 3);
  7597. $c = $left . $right;
  7598. $j = $j-3;
  7599. $slen = $slen-3;
  7600. }
  7601. $j = $j + 3;
  7602. }
  7603. //这个是为了去掉类似23.0中最后一个“零”字
  7604. if (substr($c, strlen($c)-3, 3) == '零') {
  7605. $c = substr($c, 0, strlen($c)-3);
  7606. }
  7607. //将处理的汉字加上“整”
  7608. if (empty($c)) {
  7609. return "零元整";
  7610. }else{
  7611. return $c . "整";
  7612. }
  7613. }
  7614. /**
  7615. * 获得分页数据
  7616. * @param unknown_type $table
  7617. * @param unknown_type $condition
  7618. * @param unknown_type $on_page
  7619. * @param unknown_type $page_size
  7620. */
  7621. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7622. $page_c = "";
  7623. $page ['previous'] = $this->get_previous ( $on_page );
  7624. $page ['on_page'] = $on_page;
  7625. $total_count = $this->get_table_count ( $table, $condition );
  7626. $total = intval ( $total_count / $page_size );
  7627. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7628. $page ['total_data'] = $total_count;
  7629. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7630. $i = 1;
  7631. $page_max = 1;
  7632. $page_width=3;
  7633. if ($on_page >= $page_width) {
  7634. $page_max = intval ( $on_page / $page_width ) + 1;
  7635. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7636. }
  7637. for(; $i <= $page ['total_page']; $i ++) {
  7638. if ($i == $on_page)
  7639. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7640. else
  7641. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7642. if ($i == ($page_width * $page_max))
  7643. break;
  7644. }
  7645. $page ['page'] = $page_c;
  7646. $page ['lower'] = (-- $on_page) * $page_size;
  7647. return $page;
  7648. }
  7649. /**
  7650. * 获取总页数
  7651. * @param unknown_type $table
  7652. * @param unknown_type $condition
  7653. */
  7654. public function get_table_count($table = "", $condition = "") {
  7655. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7656. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7657. //echo $sql;die;
  7658. $query = Doo::db ()->query ( $sql );
  7659. $result = $query->fetch ();
  7660. return $result ['count'];
  7661. }
  7662. /**
  7663. * 获取上一页
  7664. * @param unknown_type $on_page
  7665. */
  7666. function get_previous($on_page = 1) {
  7667. return $on_page != 0 ? $on_page - 1 : $on_page;
  7668. }
  7669. }
  7670. ?>