ReceiptController.php 305 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. //public static $NEW2 = 0;
  10. public $AGENCY="日常相关费用";
  11. public $TRAVEL="差旅相关费用";
  12. public $TRAIN="培训班费用";
  13. public $OTHER="其他";
  14. private $MYREVEIPTCACHEPATH="protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH="protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH="protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH="protected/cache/staffCollect/";
  18. private function showCache($path){
  19. if(file_exists($path)){
  20. echo "<!DOCTYPE html>";
  21. include $path;die;
  22. }
  23. }
  24. private function cacheFile($path){
  25. $content = ob_get_contents();
  26. $fp = fopen($path, "w");
  27. fwrite($fp, $content);
  28. fclose($fp);
  29. }
  30. // private function getExeCount(){
  31. // Doo::loadModel('receipt');
  32. // $receipt=new receipt();
  33. // $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  34. // return count($receiptList);
  35. // }
  36. // private function getReceiptCount(){
  37. // $status=2;
  38. // $year=date('Y');
  39. // Doo::loadModel('receipt');
  40. // $receipt=new receipt();
  41. // $dateCondition=" and Year(date) =".$year;
  42. // $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  43. // $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  44. // return count($receiptList);
  45. // }
  46. private function collectHtml($receiptCollectList=array(),$itemCategory="日常相关费用",$classType="b"){
  47. $collectHtml="";$sumPrice=0.00;
  48. for ($i=1;$i<=12;$i++){
  49. $falg=true;
  50. foreach ($receiptCollectList as $key=>$value){
  51. if($value['itemCategory']==$itemCategory&&$value['month']==$i){
  52. $sumPrice+=$value['price'];
  53. if ($classType=="b"){
  54. $collectHtml.='<td class="colGreen taR">¥'.$value['price'].'</td>';$falg=false;break;
  55. }else{
  56. $collectHtml.='<td class="taR">¥'.$value['price'].'</td>';$falg=false;break;
  57. }
  58. }
  59. }
  60. if ($falg)
  61. $collectHtml.='<td class="taR">-</td>';
  62. }
  63. $collectHtml.='<td class="taR colGreen">¥'.$sumPrice.'</td>';
  64. return $collectHtml;
  65. }
  66. function __construct() {
  67. if(isset($_COOKIE["staff"])){
  68. if(!empty($_COOKIE["staff"])){
  69. Doo::loadModel ( 'staff' );
  70. Doo::loadModel('verify');
  71. $verify=new verify();
  72. $staff = new staff ();
  73. Doo::loadModel("execute");
  74. $execute=new execute();
  75. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  76. $list=array();
  77. //判断角色的审批权限
  78. foreach ($verifyList as $key=>$value){
  79. $ver=json_decode($value['staff']);
  80. foreach ($ver as $k=>$v){
  81. if ($v[1]=='ROLE'){
  82. $roleList=json_decode($v[3]);
  83. foreach ($roleList as $t=>$g){
  84. $gList=explode("_", $g);
  85. array_push($list, $gList[0]);
  86. //print_r($list);
  87. }
  88. }else
  89. array_push($list, $v[0]);
  90. }
  91. }
  92. //判断执行人的审批权限
  93. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  94. $list2=array();
  95. foreach ($executeList as $key=>$value){
  96. $ver=json_decode($value['staff']);
  97. foreach ($ver as $k=>$v){
  98. array_push($list2, $v[0]);
  99. }
  100. }
  101. $eidList=file_get_contents("protected/config/execute/execute.ini");
  102. $eidList=array_filter(explode(",", $eidList));
  103. $this->executeId= array_merge($list2,$eidList);
  104. $this->verifyId=$list;
  105. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  106. return "/";
  107. }
  108. }
  109. Doo::loadCore ( 'uri/DooUriRouter' );
  110. $router = new DooUriRouter ();
  111. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  112. if($routeRs['1']!="login"){
  113. header ( 'Content-Type:text/html;charset=utf-8' );
  114. @header ( "Location: /login" );
  115. }
  116. }
  117. function saeaBorad(){
  118. Doo::loadModel('receipt');
  119. Doo::loadModel('verify');
  120. $verify=new verify();
  121. $receipt=new receipt();
  122. Doo::loadModel('L_category');
  123. $lCategory=new L_category();
  124. Doo::loadModel("role");
  125. $role=new role();
  126. Doo::loadModel("receiptLog");
  127. $receiptLog=new receiptLog();
  128. $receiptLogList=$receiptLog->getReceiptLogByUid($this->staff[0]['sid']);
  129. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)','desc'=>'rid','asArray'=>true));
  130. foreach ($receiptDetail as $key=>$value){
  131. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  132. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  133. $v=json_decode($veList['staff']);
  134. array_push($v[0], $veList['description']);
  135. foreach ($v as $n=>$m){
  136. if ($m['1']=='ROLE'){
  137. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  138. $v[$n][1]=$roleInfo['name'];
  139. }
  140. }
  141. $receiptDetail[$key]['staff']=$v;
  142. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  143. $receiptDetail[$key]['category']=$category['title'];
  144. }
  145. //print_r($receiptLogList);
  146. $data['receiptLogList']=$receiptLogList;
  147. $data['receiptDetail']=$receiptDetail;
  148. $data['memu']="receipt";
  149. $data['staff']=$this->staff;
  150. $data['receiptMemu']='saeaBorad';
  151. $data['verifyId']=$this->verifyId;
  152. $data['executeId']=$this->executeId;
  153. $this->render ( "/admin/saeaBorad", $data );
  154. }
  155. function remitAdd(){
  156. Doo::loadModel('accountItem');
  157. Doo::loadModel('verify');
  158. Doo::loadModel('receipt');
  159. Doo::loadModel('L_category');
  160. $lCategory=new L_category();
  161. $receipt=new receipt();
  162. $verify=new verify();
  163. $accountItem=new accountItem();
  164. Doo::loadModel("role");
  165. $role=new role();
  166. $acItem=$accountItem->find(array('asArray'=>true));
  167. $veList=$verify->find(array('asArray'=>true));
  168. foreach ($veList as $key=>$value){
  169. $v=json_decode($value['staff']);
  170. $list=array();
  171. foreach ($v as $n=>$m){
  172. if ($m['1']=='ROLE'){
  173. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  174. $v[$n][1]=$roleInfo['name'];
  175. array_push($list, $roleInfo['name']);
  176. }else{
  177. array_push($list, $v[$n][1]);
  178. }
  179. }
  180. $veList[$key]['staff']=implode('>', $list);
  181. }
  182. $data['category']=$lCategory->find(array('asArray'=>true));
  183. $data['veList']=$veList;
  184. $data['acItem']=$acItem;
  185. $data['memu']="receipt";
  186. $data['staff']=$this->staff;
  187. $data['receiptMemu']='saeaBorad';
  188. $data['verifyId']=$this->verifyId;
  189. $data['executeId']=$this->executeId;
  190. $this->render ( "/admin/remitAdd", $data );
  191. }
  192. function remitAddDo(){
  193. $agency=$this->get_args('agency');
  194. $travel=$this->get_args('travel');
  195. $train=$this->get_args('train');
  196. $other=$this->get_args('other');
  197. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  198. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  199. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  200. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  201. //print_r($agency);die;
  202. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  203. Doo::loadModel('receipt');
  204. Doo::loadModel('receiptDetail');
  205. Doo::loadModel('accountItem');
  206. $accountItem=new accountItem();
  207. $receipt=new receipt();
  208. Doo::loadModel('enclosur');
  209. Doo::loadModel('execute');
  210. $execute=new execute();
  211. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  212. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  213. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  214. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  215. $ag=$tr=$ta=$ot=0;
  216. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  217. foreach ($aItem as $key=>$value){
  218. if ($value['category']==$this->AGENCY){
  219. if (isset($agency[$ag])){
  220. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  221. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  222. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  223. }
  224. }
  225. $ag++;
  226. }
  227. }
  228. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  229. //报销单
  230. $receipt->accountItem=json_encode($accountJson);
  231. $receipt->staff=$this->staff[0]['sid'];
  232. $receipt->sum=number_format($sum, 2, '.', '');
  233. $receipt->date=date("Y-m-d");
  234. $receipt->cid=$cid;
  235. $receipt->status=5;
  236. $receipt->Rtype=2;
  237. //修改审批流程加入角色
  238. $receipt->verify=$verify;
  239. $receipt->executeCopy=$executeDetail['staff'];
  240. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  241. $receipt->explanation=$explanation;
  242. $rid=$receipt->insert();
  243. //附件
  244. if (!empty($enclosurName)){
  245. $enclosurArray=explode('-', $enclosurName);
  246. foreach ($enclosurArray as $value){
  247. $enclosur=new enclosur();
  248. $enclosur->name=$value;
  249. $enclosur->rid=$rid;
  250. $enclosur->insert();
  251. }
  252. //print_r($enclosurArray);die;
  253. }
  254. //报销详情
  255. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  256. $receiptDetail=new receiptDetail();
  257. $receiptDetail->staff=$this->staff[0]['sid'];
  258. $receiptDetail->item=$value['name'];
  259. $receiptDetail->itemCategory=$this->AGENCY;
  260. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  261. $receiptDetail->date=date("Y-m-d");
  262. $receiptDetail->cid=$cid;
  263. $receiptDetail->rid=$rid;
  264. $receiptDetail->status=4;
  265. $receiptDetail->insert();
  266. }
  267. }
  268. return "/saeaBorad";
  269. }
  270. function remitEdit(){
  271. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  272. //echo $rid;
  273. Doo::loadModel('accountItem');
  274. Doo::loadModel('verify');
  275. Doo::loadModel('receipt');
  276. $receipt=new receipt();
  277. $verify=new verify();
  278. $accountItem=new accountItem();
  279. Doo::loadModel('L_category');
  280. $lCategory=new L_category();
  281. Doo::loadModel("role");
  282. $role=new role();
  283. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  284. if(empty($receiptDetail))
  285. return "/saeaCreate";
  286. $acItem=$accountItem->find(array('asArray'=>true));
  287. $veList=$verify->find(array('asArray'=>true));
  288. foreach ($veList as $key=>$value){
  289. $v=json_decode($value['staff']);
  290. $list=array();
  291. foreach ($v as $n=>$m){
  292. if ($m['1']=='ROLE'){
  293. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  294. $v[$n][1]=$roleInfo['name'];
  295. array_push($list, $roleInfo['name']);
  296. }else{
  297. array_push($list, $v[$n][1]);
  298. }
  299. }
  300. $veList[$key]['staff']=implode('>', $list);
  301. }
  302. //配置编辑信息
  303. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  304. foreach ($acItem as $key=>$value){
  305. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  306. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  307. $acItem[$key]['price']=$v['price'];
  308. }
  309. }
  310. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  311. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  312. $acItem[$key]['price']=$v['price'];
  313. }
  314. }
  315. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  316. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  317. $acItem[$key]['price']=$v['price'];
  318. }
  319. }
  320. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  321. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  322. $acItem[$key]['price']=$v['price'];
  323. }
  324. }
  325. }
  326. $data['category']=$lCategory->find(array('asArray'=>true));
  327. $data['cSum']=$accountItemList['cSum'];
  328. $data['sum']=$receiptDetail['sum'];
  329. $data['receiptDetail']=$receiptDetail;
  330. $data['veList']=$veList;
  331. $data['acItem']=$acItem;
  332. $data['memu']="receipt";
  333. $data['staff']=$this->staff;
  334. $data['receiptMemu']='saeaBorad';
  335. $data['verify']=$receiptDetail['verify'];
  336. $data['verifyId']=$this->verifyId;
  337. $data['executeId']=$this->executeId;
  338. $data['rid']=$rid;
  339. $this->render ( "/admin/remitEdit", $data );
  340. }
  341. function remitEdiDo(){
  342. $agency=$this->get_args('agency');
  343. $travel=$this->get_args('travel');
  344. $train=$this->get_args('train');
  345. $other=$this->get_args('other');
  346. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  347. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  348. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  349. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  350. if(!empty($explanation)){
  351. Doo::loadModel('receipt');
  352. Doo::loadModel('receiptDetail');
  353. Doo::loadModel('accountItem');
  354. $accountItem=new accountItem();
  355. $receipt=new receipt();
  356. Doo::loadModel('execute');
  357. $execute=new execute();
  358. $executeDetail=$execute->getOne(array('where'=>'mold="对公汇款执行人"','asArray'=>true));
  359. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  360. if(empty($receiptDetail))
  361. return "/saeaBorad";
  362. $aItem=$accountItem->find(array('where'=>'name like "办公费用" or name like "其他费用"','asArray'=>true));
  363. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  364. $ag=$tr=$ta=$ot=0;
  365. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  366. foreach ($aItem as $key=>$value){
  367. if ($value['category']==$this->AGENCY){
  368. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  369. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  370. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  371. }
  372. $ag++;
  373. }
  374. }
  375. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  376. //报销单
  377. $rid=$receipt->rid=$receiptDetail['rid'];
  378. $receipt->accountItem=json_encode($accountJson);
  379. $receipt->staff=$this->staff[0]['sid'];
  380. $receipt->sum=number_format($sum, 2, '.', '');
  381. $receipt->date=date("Y-m-d");
  382. $receipt->cid=$cid;
  383. if ($receiptDetail['Rtype']==1)
  384. $receipt->status=7;
  385. else
  386. $receipt->status=5;
  387. if ($receiptDetail['status']!=4&&!empty($verify))
  388. $receipt->verify=$verify;
  389. $receipt->executeCopy=$executeDetail['staff'];
  390. $receipt->explanation=$explanation;
  391. $receipt->update();
  392. $receiptDetail=new receiptDetail();
  393. $receiptDetail->delete(array('where'=>'rid='.$rid));
  394. //报销详情
  395. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  396. $receiptDetail=new receiptDetail();
  397. $receiptDetail->staff=$this->staff[0]['sid'];
  398. $receiptDetail->item=$value['name'];
  399. $receiptDetail->itemCategory=$this->AGENCY;
  400. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  401. $receiptDetail->date=date("Y-m-d");
  402. $receiptDetail->cid=$cid;
  403. $receiptDetail->rid=$rid;
  404. $receiptDetail->status=4;
  405. $receiptDetail->insert();
  406. }
  407. //return "/referReceipt/".$rid;
  408. }
  409. return "/saeaBorad";
  410. }
  411. function remitApproval(){
  412. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  413. $status=isset($this->params['status'])?$this->params['status']:'';
  414. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  415. $month=$this->get_args('month')?$this->get_args('month'):"";
  416. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  417. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  418. if (empty($status))
  419. $status=$this->get_args('status')?$this->get_args('status'):2;
  420. $vidList=array();
  421. $button=0;
  422. Doo::loadModel('verify');
  423. Doo::loadModel('receipt');
  424. Doo::loadModel('staff');
  425. $staff=new staff();
  426. $receipt=new receipt();
  427. $verify=new verify();
  428. Doo::loadModel('L_category');
  429. $Lcategory=new L_category();
  430. Doo::loadModel('enclosur');
  431. $enclosur=new enclosur();
  432. //user verify ID
  433. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  434. foreach ($verifyDetail as $key=>$value){
  435. array_push($vidList, $value['vid']);
  436. }
  437. $vid=implode(",", $vidList);
  438. if(empty($verifyDetail))
  439. $vid=0;
  440. $categoryList=$Lcategory->find(array('asArray'=>true));
  441. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  442. $ap="";
  443. if($status==4){
  444. $ap=4;$status=2;
  445. }
  446. //get Receipt By verifyID status 2
  447. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  448. $Locate=0;$roleId=0;
  449. if($ap==4)
  450. $status=4;
  451. foreach ($receiptList as $key=>$value){
  452. $receiptList[$key]['Locate']=$Locate;$Locate++;
  453. $receiptList[$key]['reviseDetail']=array();
  454. if (!empty($value['reviseDetail']))
  455. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  456. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  457. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  458. $receiptList[$key]['category']=$categoryDetil['title'];
  459. //检测编辑状态
  460. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  461. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  462. $verifyStaff=json_decode($value['verifyStaff'],true);
  463. Doo::loadModel('role');
  464. $role=new role();
  465. //print_r($verifyList);
  466. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  467. foreach ($verifyList as $k=>$v){
  468. //init verifyStaff
  469. if ($v[1]=='ROLE'){
  470. if (!empty($verifyStaff)){
  471. $endStaffArray=end($verifyStaff);
  472. if ($v[0]==$endStaffArray['nextStaff']){
  473. $roleId=$v[0];
  474. }
  475. }
  476. $roleVerify=json_decode($v[3],true);
  477. $roleKey=$k;$roleArray=array();
  478. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  479. foreach ($roleVerify as $o=>$p){
  480. $staffID=explode ('_',$p);
  481. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  482. //print_r($staffID);
  483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  484. array_push($roleArray, $exp);
  485. }
  486. $roleArrayCopy[$v[0]]=$roleArray;
  487. //$verifyList[$k]['roleArray']=$roleArray;
  488. }
  489. //print_r($roleArray);
  490. $verifyList[$k]['date']="";
  491. $verifyList[$k]['opinion']="";
  492. $verifyList[$k]['status']="";
  493. if (empty($verifyStaff)){
  494. $verifyList[$k]['date']="";
  495. $verifyList[$k]['opinion']="";
  496. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  497. $verifyList[$k]['status']=4;
  498. $button=4;$flag=false;
  499. }
  500. }else{
  501. foreach ($verifyStaff as $m=>$u){
  502. if ($v[0]==$m){
  503. $verifyList[$k]['date']=$u['date'];
  504. $verifyList[$k]['opinion']=$u['opinion'];
  505. $verifyList[$k]['status']=$u['status'];
  506. $flag=false;
  507. break;
  508. }
  509. }
  510. $endStaffArray=end($verifyStaff);
  511. if (isset($endStaffArray['ROLE'])){
  512. }else{
  513. $endKey=key($verifyStaff);
  514. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  515. $button=4;
  516. $verifyList[$k]['status']=4;
  517. }
  518. }
  519. }
  520. }
  521. $rolename['name']='';
  522. if (!empty($roleId)){
  523. Doo::loadModel('role');
  524. $role=new role();
  525. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  526. }
  527. if (!empty($verifyStaff))
  528. $endStaffArray=end($verifyStaff);
  529. $KOP=false;
  530. foreach ($roleArrayCopy as $P=>$A){
  531. foreach ( $A as $MKI=>$AVL){
  532. if (!empty($verifyStaff)){
  533. //&&$rolename['rid']==$endStaffArray['nextStaff']
  534. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  535. $button=4;
  536. $roleArrayCopy[$P][$MKI]['status']=4;
  537. }
  538. foreach ($verifyStaff as $m=>$u){
  539. $AVLFK=$AVL[0].'_R';
  540. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  541. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  542. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  543. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  544. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  545. break;
  546. }
  547. }
  548. }else{
  549. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  550. $button=4;
  551. $roleArrayCopy[$P][$MKI]['status']=4;
  552. }
  553. }
  554. //$roleArray[$MKI]['rolename']=$rolename['name'];
  555. $KOP=true;
  556. }
  557. }
  558. foreach ($roleArrayCopy as $k=>$v){
  559. foreach ($verifyList as $m=>$n){
  560. if ($n[0]==$k){
  561. array_splice($verifyList,$m,1,$v);
  562. }
  563. }
  564. }
  565. $receiptList[$key]['verifyList']= $verifyList;
  566. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  567. $receiptList[$key]['button']=$button;
  568. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  569. }
  570. $mothHtml="";
  571. for($i=1;$i<=12;$i++){
  572. if($month==$i)
  573. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  574. else
  575. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  576. }
  577. //获取审批日志
  578. Doo::loadModel('receiptLog');
  579. $receiptLog=new receiptLog();
  580. $rlList=array();
  581. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  582. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  583. if (!empty($rlInfo)){
  584. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  585. }
  586. $receiptList[0]['rlList']=$rlList;
  587. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  588. $enclosurHtml='';
  589. foreach ($enclosurList as $value){
  590. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  591. }
  592. //print_r($receiptList);
  593. $data['enclosurHtml']=$enclosurHtml;
  594. $data['rolename']=$rolename['name'];
  595. $data['datetij']=$tijdate['date'];
  596. $data['mothHtml']=$mothHtml;
  597. $data['rid']=$rid;
  598. $data['receiptList']=$receiptList;
  599. $data['receiptApprovalCount']=count($receiptList);
  600. $data['status']=$status;
  601. $data['year']=$year;
  602. $data['categoryList']=$categoryList;
  603. $data['staffList']=$staffList;
  604. $data['cid']=$cid;
  605. $data['sid']=$sid;
  606. $data['ap']=$ap;
  607. $data['memu']="receipt";
  608. $data['staff']=$this->staff;
  609. $data['receiptMemu']='approvalExpenses';
  610. $data['verifyId']=$this->verifyId;
  611. $data['executeId']=$this->executeId;
  612. $this->render ( "/admin/remitApproval", $data );
  613. }
  614. function saeaLoanAdd(){
  615. Doo::loadModel('verify');
  616. $verify=new verify();
  617. Doo::loadModel("role");
  618. $role=new role();
  619. Doo::loadModel('L_category');
  620. $lCategory=new L_category();
  621. $veList=$verify->find(array('asArray'=>true));
  622. foreach ($veList as $key=>$value){
  623. $v=json_decode($value['staff']);
  624. $list=array();
  625. foreach ($v as $n=>$m){
  626. if ($m['1']=='ROLE'){
  627. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  628. $v[$n][1]=$roleInfo['name'];
  629. array_push($list, $roleInfo['name']);
  630. }else{
  631. array_push($list, $v[$n][1]);
  632. }
  633. }
  634. $veList[$key]['staff']=implode('>', $list);
  635. }
  636. $data['category']=$lCategory->find(array('asArray'=>true));
  637. $data['veList']=$veList;
  638. $data['memu']="receipt";
  639. $data['staff']=$this->staff;
  640. $data['receiptMemu']='saeaBorad';
  641. $data['verifyId']=$this->verifyId;
  642. $data['executeId']=$this->executeId;
  643. $this->render ( "/admin/saeaLoanAdd", $data );
  644. }
  645. function saeaLoanAddDo(){
  646. $agency=$this->get_args('agency');
  647. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  648. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  649. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  650. //die;
  651. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  652. Doo::loadModel('receipt');
  653. Doo::loadModel('receiptDetail');
  654. Doo::loadModel('accountItem');
  655. $accountItem=new accountItem();
  656. $receipt=new receipt();
  657. Doo::loadModel('loanReceipt');
  658. $loanReceipt=new loanReceipt();
  659. Doo::loadModel('execute');
  660. $execute=new execute();
  661. Doo::loadModel('enclosur');
  662. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  663. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  664. // if(!empty($receiptDetail))
  665. // return "/referReceipt/".$receiptDetail['rid'];
  666. $aItem=$accountItem->find(array('asArray'=>true));
  667. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  668. $ag=$tr=$ta=$ot=0;
  669. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  670. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  671. $sum+=$agency;$agencySum+=$agency;
  672. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  673. //借款数据备份
  674. $loanReceipt->loanItem=json_encode($accountJson);
  675. $loanReceipt->staff=$this->staff[0]['sid'];
  676. $loanReceipt->sum=number_format($sum, 2, '.', '');
  677. $loanReceipt->date=date("Y-m-d");
  678. $loanReceipt->cid=$cid;
  679. $loanReceipt->receiptOrder="#J".date("Ymd").mt_rand(1000,9999);
  680. $loanReceipt->status=5;
  681. $loanReceipt->Rtype=1;
  682. $loanReceipt->verify=$verify;
  683. $receipt->receiptOrder=$receipt->receiptOrder;
  684. $loanReceipt->explanation=$explanation;
  685. $loanRid=$loanReceipt->insert();
  686. //报销单
  687. $receipt->loanItem=json_encode($accountJson);
  688. $receipt->staff=$this->staff[0]['sid'];
  689. $receipt->sum=number_format($sum, 2, '.', '');
  690. $receipt->date=date("Y-m-d");
  691. $receipt->cid=$cid;
  692. //特殊状态
  693. $receipt->status=5;
  694. $receipt->Rtype=1;
  695. $receipt->loanRid=$loanRid;
  696. //修改审批流程加入角色
  697. $receipt->verify=$verify;
  698. $receipt->executeCopy=$executeDetail['staff'];
  699. $receipt->receiptOrder=$loanReceipt->receiptOrder;
  700. $receipt->explanation=$explanation;
  701. $rid=$receipt->insert();
  702. //执行数据备份
  703. // $executeCopy->rid=$rid;
  704. // $executeCopy->staff=$executeDetail['staff'];
  705. // $executeCopy->eid=$executeDetail['eid'];
  706. // $ecid=$executeCopy->insert();
  707. }
  708. return "/saeaBorad";
  709. }
  710. function saeaLoanEdi(){
  711. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  712. Doo::loadModel('verify');
  713. $verify=new verify();
  714. Doo::loadModel("role");
  715. $role=new role();
  716. Doo::loadModel('L_category');
  717. $lCategory=new L_category();
  718. Doo::loadModel('receipt');
  719. $receipt=new receipt();
  720. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  721. $veList=$verify->find(array('asArray'=>true));
  722. foreach ($veList as $key=>$value){
  723. $v=json_decode($value['staff']);
  724. $list=array();
  725. foreach ($v as $n=>$m){
  726. if ($m['1']=='ROLE'){
  727. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  728. $v[$n][1]=$roleInfo['name'];
  729. array_push($list, $roleInfo['name']);
  730. }else{
  731. array_push($list, $v[$n][1]);
  732. }
  733. }
  734. $veList[$key]['staff']=implode('>', $list);
  735. }
  736. $receiptInfo['loanItem']=json_decode($receiptInfo['loanItem'],true);
  737. $data['receiptInfo']=$receiptInfo;
  738. $data['category']=$lCategory->find(array('asArray'=>true));
  739. $data['veList']=$veList;
  740. $data['memu']="receipt";
  741. $data['staff']=$this->staff;
  742. $data['receiptMemu']='saeaBorad';
  743. $data['verifyId']=$this->verifyId;
  744. $data['executeId']=$this->executeId;
  745. $this->render ( "/admin/saeaLoanEdi", $data );
  746. }
  747. function saeaLoanEdiDo(){
  748. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  749. $agency=$this->get_args('agency');
  750. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  751. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  752. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  753. //die;
  754. if(!empty($cid)&&!empty($explanation)&&!empty($rid)){
  755. Doo::loadModel('receipt');
  756. Doo::loadModel('receiptDetail');
  757. Doo::loadModel('accountItem');
  758. $accountItem=new accountItem();
  759. $receipt=new receipt();
  760. Doo::loadModel('loanReceipt');
  761. $loanReceipt=new loanReceipt();
  762. Doo::loadModel('enclosur');
  763. Doo::loadModel('execute');
  764. $execute=new execute();
  765. $executeDetail=$execute->getOne(array('where'=>'mold="借款执行人"','asArray'=>true));
  766. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=5 or status=4) and rid='.$rid,'asArray'=>true));
  767. if(empty($receiptDetail))
  768. die('参数错误');
  769. $aItem=$accountItem->find(array('asArray'=>true));
  770. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=$accountJson['借款费用']=array();
  771. $ag=$tr=$ta=$ot=0;
  772. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  773. array_push($accountJson['借款费用'], array('aid'=>0,'name'=>'申请金额','price'=>number_format($agency, 2, '.', '')));
  774. $sum+=$agency;$agencySum+=$agency;
  775. $accountJson['cSum']=array('loanSum'=>number_format($agencySum, 2, '.', ''),'agencySum'=>number_format(0, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  776. //报销单
  777. $receipt->loanItem=json_encode($accountJson);
  778. $receipt->sum=number_format($sum, 2, '.', '');
  779. $receipt->cid=$cid;
  780. //特殊状态
  781. //修改审批流程加入角色
  782. if ($receiptDetail['status']!=4)
  783. $receipt->verify=$verify;
  784. $receipt->explanation=$explanation;
  785. $receipt->update(array('where'=>'rid='.$rid));
  786. //借款数据更新
  787. $loanReceipt->loanItem=json_encode($accountJson);
  788. $loanReceipt->sum=number_format($sum, 2, '.', '');
  789. $loanReceipt->cid=$cid;
  790. if ($receiptDetail['status']!=4)
  791. $loanReceipt->verify=$verify;
  792. $loanReceipt->explanation=$explanation;
  793. $receipt->executeCopy=$executeDetail['staff'];
  794. $loanReceipt->update(array('where'=>'rid='.$receiptDetail['loanRid']));
  795. }
  796. return "/saeaBorad";
  797. }
  798. function saeaLoanReceiptAdd(){
  799. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  800. Doo::loadModel('receipt');
  801. $receipt=new receipt();
  802. Doo::loadModel('loanReceipt');
  803. $loanReceipt=new loanReceipt();
  804. Doo::loadModel('L_category');
  805. $Lcategory=new L_category();
  806. Doo::loadModel('verify');
  807. Doo::loadModel('statistics');
  808. $statistics=new statistics();
  809. $verify=new verify();
  810. Doo::loadModel('staff');
  811. $staff=new staff();
  812. $receiptDe=$receipt->getOne(array('where'=>'rid='.$rid,'desc'=>'rid','asArray'=>true));
  813. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDe['loanRid'],'desc'=>'rid','asArray'=>true));
  814. $Locate=0;$roleId=0;$button=0;
  815. foreach ($receiptList as $key=>$value){
  816. $receiptList[$key]['Locate']=$Locate;$Locate++;
  817. $receiptList[$key]['reviseDetail']=array();
  818. if (!empty($value['reviseDetail']))
  819. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  820. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  821. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  822. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  823. $receiptList[$key]['category']=$categoryDetil['title'];
  824. //检测编辑状态
  825. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  826. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  827. $verifyStaff=json_decode($value['verifyStaff'],true);
  828. Doo::loadModel('role');
  829. $role=new role();
  830. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  831. foreach ($verifyList as $k=>$v){
  832. //init verifyStaff
  833. if ($v[1]=='ROLE'){
  834. if (!empty($verifyStaff)){
  835. $endStaffArray=end($verifyStaff);
  836. // if ($v[0]==$endStaffArray['nextStaff']){
  837. // $roleId=$v[0];
  838. // }
  839. }
  840. $roleVerify=json_decode($v[3],true);
  841. $roleKey=$k;$roleArray=array();
  842. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  843. foreach ($roleVerify as $o=>$p){
  844. $staffID=explode ('_',$p);
  845. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  846. //print_r($staffID);
  847. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  848. array_push($roleArray, $exp);
  849. }
  850. $roleArrayCopy[$v[0]]=$roleArray;
  851. //$verifyList[$k]['roleArray']=$roleArray;
  852. }
  853. $verifyList[$k]['date']="";
  854. $verifyList[$k]['opinion']="";
  855. $verifyList[$k]['status']="";
  856. if (empty($verifyStaff)){
  857. $verifyList[$k]['date']="";
  858. $verifyList[$k]['opinion']="";
  859. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  860. $verifyList[$k]['status']=4;
  861. $flag=false;
  862. }
  863. }else{
  864. foreach ($verifyStaff as $m=>$u){
  865. if ($v[0]==$m){
  866. $verifyList[$k]['date']=$u['date'];
  867. $verifyList[$k]['opinion']=$u['opinion'];
  868. $verifyList[$k]['status']=$u['status'];
  869. $flag=false;
  870. break;
  871. }
  872. }
  873. $endStaffArray=end($verifyStaff);
  874. if (isset($endStaffArray['ROLE'])){
  875. }else{
  876. // $endKey=key($verifyStaff);
  877. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  878. // $button=4;
  879. // $verifyList[$k]['status']=4;
  880. // }
  881. }
  882. }
  883. }
  884. $rolename['name']='';
  885. if (!empty($roleId)){
  886. Doo::loadModel('role');
  887. $role=new role();
  888. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  889. }
  890. if (!empty($verifyStaff))
  891. $endStaffArray=end($verifyStaff);
  892. $KOP=false;
  893. foreach ($roleArrayCopy as $P=>$A){
  894. foreach ( $A as $MKI=>$AVL){
  895. if (!empty($verifyStaff)){
  896. //&&$rolename['rid']==$endStaffArray['nextStaff']
  897. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  898. $button=4;
  899. $roleArrayCopy[$P][$MKI]['status']=4;
  900. }
  901. foreach ($verifyStaff as $m=>$u){
  902. $AVLFK=$AVL[0].'_R';
  903. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  904. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  905. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  906. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  907. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  908. break;
  909. }
  910. }
  911. }else{
  912. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  913. $button=4;
  914. $roleArrayCopy[$P][$MKI]['status']=4;
  915. }
  916. }
  917. //$roleArray[$MKI]['rolename']=$rolename['name'];
  918. $KOP=true;
  919. }
  920. }
  921. foreach ($roleArrayCopy as $k=>$v){
  922. foreach ($verifyList as $m=>$n){
  923. if ($n[0]==$k){
  924. array_splice($verifyList,$m,1,$v);
  925. }
  926. }
  927. }
  928. $receiptList[$key]['verifyList']=$verifyList;
  929. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  930. $receiptList[$key]['button']=$button;
  931. //
  932. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  933. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  934. }
  935. $data['receiptList']=$receiptList;
  936. Doo::loadModel('L_category');
  937. $lCategory=new L_category();
  938. Doo::loadModel('accountItem');
  939. $accountItem=new accountItem();
  940. $acItem=$accountItem->find(array('asArray'=>true));
  941. $veList=$verify->find(array('asArray'=>true));
  942. foreach ($veList as $key=>$value){
  943. $v=json_decode($value['staff']);
  944. $list=array();
  945. foreach ($v as $n=>$m){
  946. if ($m['1']=='ROLE'){
  947. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  948. $v[$n][1]=$roleInfo['name'];
  949. array_push($list, $roleInfo['name']);
  950. }else{
  951. array_push($list, $v[$n][1]);
  952. }
  953. }
  954. $veList[$key]['staff']=implode('>', $list);
  955. }
  956. $data['rid']=$rid;
  957. $data['category']=$lCategory->find(array('asArray'=>true));
  958. $data['veList']=$veList;
  959. $data['acItem']=$acItem;
  960. $data['memu']="receipt";
  961. $data['staff']=$this->staff;
  962. $data['receiptMemu']='saeaBorad';
  963. $data['verifyId']=$this->verifyId;
  964. $data['executeId']=$this->executeId;
  965. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  966. }
  967. function saeaLoanReceiptAddDo(){
  968. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  969. $agency=$this->get_args('agency');
  970. $travel=$this->get_args('travel');
  971. $train=$this->get_args('train');
  972. $other=$this->get_args('other');
  973. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  974. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  975. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  976. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  977. if(!empty($verify)&&!empty($cid)&&!empty($explanation)&&!empty($rid)){
  978. Doo::loadModel('receipt');
  979. Doo::loadModel('receiptDetail');
  980. Doo::loadModel('accountItem');
  981. $accountItem=new accountItem();
  982. $receipt=new receipt();
  983. Doo::loadModel('enclosur');
  984. Doo::loadModel('execute');
  985. $execute=new execute();
  986. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  987. $receiptDet=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  988. // if(!empty($receiptDetail))
  989. // return "/referReceipt/".$receiptDetail['rid'];
  990. $aItem=$accountItem->find(array('asArray'=>true));
  991. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  992. $ag=$tr=$ta=$ot=0;
  993. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  994. foreach ($aItem as $key=>$value){
  995. if ($value['category']==$this->AGENCY){
  996. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  997. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  998. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  999. }
  1000. $ag++;
  1001. }
  1002. if($value['category']==$this->TRAVEL){
  1003. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  1004. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  1005. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  1006. }
  1007. $tr++;
  1008. }
  1009. if($value['category']==$this->TRAIN){
  1010. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  1011. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  1012. $sum+=$train[$ta];$trainSum+=$train[$ta];
  1013. }
  1014. $ta++;
  1015. }
  1016. if($value['category']==$this->OTHER){
  1017. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  1018. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  1019. $sum+=$other[$ot];$otherSum+=$other[$ot];
  1020. }
  1021. $ot++;
  1022. }
  1023. }
  1024. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  1025. //报销单
  1026. $receipt->accountItem=json_encode($accountJson);
  1027. $receipt->staff=$this->staff[0]['sid'];
  1028. $receipt->loanSum=$receiptDet['sum'];
  1029. $receipt->sum=number_format($sum, 2, '.', '');
  1030. $receipt->date=date("Y-m-d");
  1031. $receipt->pastDate='';
  1032. $receipt->cid=$cid;
  1033. $receipt->status=7;
  1034. //修改审批流程加入角色
  1035. $receipt->verify=$verify;
  1036. $receipt->verifyStaff='';
  1037. $receipt->executeStaff='';
  1038. $receipt->executeCopy=$executeDetail['staff'];
  1039. //$receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1040. $receipt->explanation=$explanation;
  1041. $receipt->update(array('where'=>'rid='.$rid));
  1042. //附件
  1043. if (!empty($enclosurName)){
  1044. $enclosurArray=explode('-', $enclosurName);
  1045. foreach ($enclosurArray as $value){
  1046. $enclosur=new enclosur();
  1047. $enclosur->name=$value;
  1048. $enclosur->rid=$rid;
  1049. $enclosur->insert();
  1050. }
  1051. //print_r($enclosurArray);die;
  1052. }
  1053. //报销详情
  1054. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  1055. $receiptDetail=new receiptDetail();
  1056. $receiptDetail->staff=$this->staff[0]['sid'];
  1057. $receiptDetail->item=$value['name'];
  1058. $receiptDetail->itemCategory=$this->AGENCY;
  1059. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1060. $receiptDetail->date=date("Y-m-d");
  1061. $receiptDetail->cid=$cid;
  1062. $receiptDetail->rid=$rid;
  1063. $receiptDetail->status=4;
  1064. $receiptDetail->insert();
  1065. }
  1066. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  1067. $receiptDetail=new receiptDetail();
  1068. $receiptDetail->staff=$this->staff[0]['sid'];
  1069. $receiptDetail->item=$value['name'];
  1070. $receiptDetail->itemCategory=$this->TRAVEL;
  1071. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1072. $receiptDetail->date=date("Y-m-d");
  1073. $receiptDetail->cid=$cid;
  1074. $receiptDetail->rid=$rid;
  1075. $receiptDetail->status=4;
  1076. $receiptDetail->insert();
  1077. }
  1078. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  1079. $receiptDetail=new receiptDetail();
  1080. $receiptDetail->staff=$this->staff[0]['sid'];
  1081. $receiptDetail->item=$value['name'];
  1082. $receiptDetail->itemCategory=$this->TRAIN;
  1083. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1084. $receiptDetail->date=date("Y-m-d");
  1085. $receiptDetail->cid=$cid;
  1086. $receiptDetail->rid=$rid;
  1087. $receiptDetail->status=4;
  1088. $receiptDetail->insert();
  1089. }
  1090. foreach ($accountJson[$this->OTHER] as $key=>$value){
  1091. $receiptDetail=new receiptDetail();
  1092. $receiptDetail->staff=$this->staff[0]['sid'];
  1093. $receiptDetail->item=$value['name'];
  1094. $receiptDetail->itemCategory=$this->OTHER;
  1095. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  1096. $receiptDetail->date=date("Y-m-d");
  1097. $receiptDetail->cid=$cid;
  1098. $receiptDetail->rid=$rid;
  1099. $receiptDetail->status=4;
  1100. $receiptDetail->insert();
  1101. }
  1102. return "/saeaBorad";
  1103. }
  1104. return "/saeaLoanReceiptAdd/".$rid;
  1105. }
  1106. function saeaLoanReceiptEdi(){
  1107. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  1108. //echo $rid;
  1109. Doo::loadModel('accountItem');
  1110. Doo::loadModel('verify');
  1111. Doo::loadModel('receipt');
  1112. $receipt=new receipt();
  1113. $verify=new verify();
  1114. $accountItem=new accountItem();
  1115. Doo::loadModel('L_category');
  1116. $Lcategory=new L_category();
  1117. Doo::loadModel("role");
  1118. $role=new role();
  1119. Doo::loadModel('loanReceipt');
  1120. $loanReceipt=new loanReceipt();
  1121. Doo::loadModel('staff');
  1122. $staff=new staff();
  1123. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=7) and rid='.$rid,'asArray'=>true));
  1124. if(empty($receiptDetail))
  1125. return "/saeaBorad";
  1126. $receiptList=$loanReceipt->find(array('where'=>'rid='.$receiptDetail['loanRid'],'desc'=>'rid','asArray'=>true));
  1127. $Locate=0;$roleId=0;$button=0;
  1128. foreach ($receiptList as $key=>$value){
  1129. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1130. $receiptList[$key]['reviseDetail']=array();
  1131. if (!empty($value['reviseDetail']))
  1132. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1133. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1134. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1135. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1136. $receiptList[$key]['category']=$categoryDetil['title'];
  1137. //检测编辑状态
  1138. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1139. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1140. $verifyStaff=json_decode($value['verifyStaff'],true);
  1141. Doo::loadModel('role');
  1142. $role=new role();
  1143. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1144. foreach ($verifyList as $k=>$v){
  1145. //init verifyStaff
  1146. if ($v[1]=='ROLE'){
  1147. if (!empty($verifyStaff)){
  1148. $endStaffArray=end($verifyStaff);
  1149. // if ($v[0]==$endStaffArray['nextStaff']){
  1150. // $roleId=$v[0];
  1151. // }
  1152. }
  1153. $roleVerify=json_decode($v[3],true);
  1154. $roleKey=$k;$roleArray=array();
  1155. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1156. foreach ($roleVerify as $o=>$p){
  1157. $staffID=explode ('_',$p);
  1158. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1159. //print_r($staffID);
  1160. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1161. array_push($roleArray, $exp);
  1162. }
  1163. $roleArrayCopy[$v[0]]=$roleArray;
  1164. //$verifyList[$k]['roleArray']=$roleArray;
  1165. }
  1166. $verifyList[$k]['date']="";
  1167. $verifyList[$k]['opinion']="";
  1168. $verifyList[$k]['status']="";
  1169. if (empty($verifyStaff)){
  1170. $verifyList[$k]['date']="";
  1171. $verifyList[$k]['opinion']="";
  1172. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1173. $verifyList[$k]['status']=4;
  1174. $flag=false;
  1175. }
  1176. }else{
  1177. foreach ($verifyStaff as $m=>$u){
  1178. if ($v[0]==$m){
  1179. $verifyList[$k]['date']=$u['date'];
  1180. $verifyList[$k]['opinion']=$u['opinion'];
  1181. $verifyList[$k]['status']=$u['status'];
  1182. $flag=false;
  1183. break;
  1184. }
  1185. }
  1186. $endStaffArray=end($verifyStaff);
  1187. if (isset($endStaffArray['ROLE'])){
  1188. }else{
  1189. // $endKey=key($verifyStaff);
  1190. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1191. // $button=4;
  1192. // $verifyList[$k]['status']=4;
  1193. // }
  1194. }
  1195. }
  1196. }
  1197. $rolename['name']='';
  1198. if (!empty($roleId)){
  1199. Doo::loadModel('role');
  1200. $role=new role();
  1201. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1202. }
  1203. if (!empty($verifyStaff))
  1204. $endStaffArray=end($verifyStaff);
  1205. $KOP=false;
  1206. foreach ($roleArrayCopy as $P=>$A){
  1207. foreach ( $A as $MKI=>$AVL){
  1208. if (!empty($verifyStaff)){
  1209. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1210. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1211. $button=4;
  1212. $roleArrayCopy[$P][$MKI]['status']=4;
  1213. }
  1214. foreach ($verifyStaff as $m=>$u){
  1215. $AVLFK=$AVL[0].'_R';
  1216. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1217. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1218. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1219. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1220. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1221. break;
  1222. }
  1223. }
  1224. }else{
  1225. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1226. $button=4;
  1227. $roleArrayCopy[$P][$MKI]['status']=4;
  1228. }
  1229. }
  1230. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1231. $KOP=true;
  1232. }
  1233. }
  1234. foreach ($roleArrayCopy as $k=>$v){
  1235. foreach ($verifyList as $m=>$n){
  1236. if ($n[0]==$k){
  1237. array_splice($verifyList,$m,1,$v);
  1238. }
  1239. }
  1240. }
  1241. $receiptList[$key]['verifyList']=$verifyList;
  1242. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1243. $receiptList[$key]['button']=$button;
  1244. //
  1245. //$receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1246. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  1247. }
  1248. $data['receiptList']=$receiptList;
  1249. $acItem=$accountItem->find(array('asArray'=>true));
  1250. $veList=$verify->find(array('asArray'=>true));
  1251. foreach ($veList as $key=>$value){
  1252. $v=json_decode($value['staff']);
  1253. $list=array();
  1254. foreach ($v as $n=>$m){
  1255. if ($m['1']=='ROLE'){
  1256. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  1257. $v[$n][1]=$roleInfo['name'];
  1258. array_push($list, $roleInfo['name']);
  1259. }else{
  1260. array_push($list, $v[$n][1]);
  1261. }
  1262. }
  1263. $veList[$key]['staff']=implode('>', $list);
  1264. }
  1265. //配置编辑信息
  1266. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  1267. foreach ($acItem as $key=>$value){
  1268. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  1269. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  1270. $acItem[$key]['price']=$v['price'];
  1271. }
  1272. }
  1273. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  1274. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  1275. $acItem[$key]['price']=$v['price'];
  1276. }
  1277. }
  1278. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  1279. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  1280. $acItem[$key]['price']=$v['price'];
  1281. }
  1282. }
  1283. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  1284. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  1285. $acItem[$key]['price']=$v['price'];
  1286. }
  1287. }
  1288. }
  1289. $data['category']=$Lcategory->find(array('asArray'=>true));
  1290. $data['cSum']=$accountItemList['cSum'];
  1291. $data['sum']=$receiptDetail['sum'];
  1292. $data['receiptDetail']=$receiptDetail;
  1293. $data['veList']=$veList;
  1294. $data['acItem']=$acItem;
  1295. $data['memu']="receipt";
  1296. $data['staff']=$this->staff;
  1297. $data['receiptMemu']='saeaBorad';
  1298. $data['verify']=$receiptDetail['verify'];
  1299. $data['verifyId']=$this->verifyId;
  1300. $data['executeId']=$this->executeId;
  1301. $data['rid']=$rid;
  1302. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1303. }
  1304. function confirmation(){
  1305. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1306. Doo::loadModel('receipt');
  1307. Doo::loadModel('receiptDetail');
  1308. $receipt=new receipt();
  1309. $receiptDetail=new receiptDetail();
  1310. Doo::loadModel('statistics');
  1311. Doo::loadModel('itemStatistics');
  1312. $statistics=new statistics();
  1313. $itemStatistics=new itemStatistics();
  1314. Doo::loadModel("verify");
  1315. $verify=new verify();
  1316. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=4 or status=5) and Rtype=1 and rid='.$rid,'asArray'=>true));
  1317. if(empty($receiptDetailList))
  1318. return "/saeaBorad";
  1319. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  1320. $verifyDetail=json_decode($verifyDetail['staff'],true);
  1321. if (empty($receiptDetailList['nowStaff'])){
  1322. $nowStaff="";$nowStaffList=array();
  1323. if ($verifyDetail[0][1]=='ROLE'){
  1324. $vStaffString=json_decode($verifyDetail[0][3]);
  1325. foreach ($vStaffString as $key=>$value){
  1326. $staffK=explode("_", $value);
  1327. array_push($nowStaffList, $staffK[0]);
  1328. }
  1329. $nowStaff=implode(',', $nowStaffList);
  1330. }else{
  1331. $nowStaff=$verifyDetail[0][0];
  1332. }
  1333. $receipt->nowStaff=$nowStaff;
  1334. }
  1335. // echo $nowStaff;
  1336. // print_r($verifyDetail);die;
  1337. $receipt->rid=$receiptDetailList['rid'];
  1338. $receipt->status=2;
  1339. $receipt->update();
  1340. //操作日志
  1341. Doo::loadModel("receiptLog");
  1342. $receiptLog=new receiptLog();
  1343. $verify=new verify();
  1344. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  1345. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  1346. $jd=json_decode($vr['staff']);$roleId=0;
  1347. foreach ($jd as $key=>$value){
  1348. if ($value[1]=='ROLE'){
  1349. $pos = strpos($value[3], $this->staff[0]['sid']);
  1350. if ($pos !== false) {
  1351. $roleId=$value[0];
  1352. }
  1353. }
  1354. }
  1355. //审批日志
  1356. //echo $roleId;die;
  1357. if (!empty($roleId)){
  1358. Doo::loadModel("role");
  1359. $role=new role();
  1360. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1361. $receiptLog->rolename=$roleInfo['name'];
  1362. }
  1363. $receiptLog->username=$this->staff[0]['username'];
  1364. $receiptLog->uid=$this->staff[0]['sid'];
  1365. $receiptLog->date=date("Y-m-d");
  1366. $receiptLog->opinion='提交审批';
  1367. $receiptLog->img=$this->staff[0]['avatar'];
  1368. $receiptLog->status=2;
  1369. $receiptLog->rid=$rid;
  1370. $receiptLog->insert();
  1371. return "/expenses";
  1372. }
  1373. function expenses(){
  1374. $item=isset($this->params['item'])?$this->params['item']:"";
  1375. if(empty($item))
  1376. $item=$this->get_args('item')?$this->get_args('item'):"";
  1377. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  1378. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  1379. Doo::loadModel('receipt');
  1380. $receipt=new receipt();
  1381. Doo::loadModel('L_category');
  1382. $Lcategory=new L_category();
  1383. Doo::loadModel('verify');
  1384. Doo::loadModel('statistics');
  1385. $statistics=new statistics();
  1386. $verify=new verify();
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $condition="";
  1390. if($item=="expenses")
  1391. $condition=" and Rtype=1 ";
  1392. elseif ($item=="receipts")
  1393. $condition=" and Rtype=0 ";
  1394. elseif ($item=="remits")
  1395. $condition=" and Rtype=2 ";
  1396. $dateCondition=" and Year(date) =".$year;
  1397. if(!empty($moth)){
  1398. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  1399. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  1400. }else
  1401. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  1402. if(empty($stList))
  1403. $stList=array('rePrice'=>0,'agPrice'=>0);
  1404. $noPassSum=$receipt->receiptByYear($dateCondition,$this->staff[0]['sid']);
  1405. if(!isset($noPassSum['sum']))
  1406. $noPassSum['sum']=0;
  1407. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($noPassSum['sum']));
  1408. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  1409. $Locate=0;$roleId=0;$button=0;
  1410. foreach ($receiptList as $key=>$value){
  1411. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1412. $receiptList[$key]['reviseDetail']=array();
  1413. if (!empty($value['reviseDetail']))
  1414. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1415. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1416. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1417. $receiptList[$key]['category']=$categoryDetil['title'];
  1418. //检测编辑状态
  1419. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1420. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1421. $verifyStaff=json_decode($value['verifyStaff'],true);
  1422. Doo::loadModel('role');
  1423. $role=new role();
  1424. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1425. foreach ($verifyList as $k=>$v){
  1426. //init verifyStaff
  1427. if ($v[1]=='ROLE'){
  1428. if (!empty($verifyStaff)){
  1429. $endStaffArray=end($verifyStaff);
  1430. // if ($v[0]==$endStaffArray['nextStaff']){
  1431. // $roleId=$v[0];
  1432. // }
  1433. }
  1434. $roleVerify=json_decode($v[3],true);
  1435. $roleKey=$k;$roleArray=array();
  1436. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1437. foreach ($roleVerify as $o=>$p){
  1438. $staffID=explode ('_',$p);
  1439. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1440. //print_r($staffID);
  1441. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1442. array_push($roleArray, $exp);
  1443. }
  1444. $roleArrayCopy[$v[0]]=$roleArray;
  1445. //$verifyList[$k]['roleArray']=$roleArray;
  1446. }
  1447. $verifyList[$k]['date']="";
  1448. $verifyList[$k]['opinion']="";
  1449. $verifyList[$k]['status']="";
  1450. if (empty($verifyStaff)){
  1451. $verifyList[$k]['date']="";
  1452. $verifyList[$k]['opinion']="";
  1453. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1454. $verifyList[$k]['status']=4;
  1455. $flag=false;
  1456. }
  1457. }else{
  1458. foreach ($verifyStaff as $m=>$u){
  1459. if ($v[0]==$m){
  1460. $verifyList[$k]['date']=$u['date'];
  1461. $verifyList[$k]['opinion']=$u['opinion'];
  1462. $verifyList[$k]['status']=$u['status'];
  1463. $flag=false;
  1464. break;
  1465. }
  1466. }
  1467. $endStaffArray=end($verifyStaff);
  1468. if (isset($endStaffArray['ROLE'])){
  1469. }else{
  1470. // $endKey=key($verifyStaff);
  1471. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1472. // $button=4;
  1473. // $verifyList[$k]['status']=4;
  1474. // }
  1475. }
  1476. }
  1477. }
  1478. $rolename['name']='';
  1479. if (!empty($roleId)){
  1480. Doo::loadModel('role');
  1481. $role=new role();
  1482. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1483. }
  1484. if (!empty($verifyStaff))
  1485. $endStaffArray=end($verifyStaff);
  1486. $KOP=false;
  1487. foreach ($roleArrayCopy as $P=>$A){
  1488. foreach ( $A as $MKI=>$AVL){
  1489. if (!empty($verifyStaff)){
  1490. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1491. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1492. $button=4;
  1493. $roleArrayCopy[$P][$MKI]['status']=4;
  1494. }
  1495. foreach ($verifyStaff as $m=>$u){
  1496. $AVLFK=$AVL[0].'_R';
  1497. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1498. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1499. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1500. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1501. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1502. break;
  1503. }
  1504. }
  1505. }else{
  1506. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1507. $button=4;
  1508. $roleArrayCopy[$P][$MKI]['status']=4;
  1509. }
  1510. }
  1511. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1512. $KOP=true;
  1513. }
  1514. }
  1515. foreach ($roleArrayCopy as $k=>$v){
  1516. foreach ($verifyList as $m=>$n){
  1517. if ($n[0]==$k){
  1518. array_splice($verifyList,$m,1,$v);
  1519. }
  1520. }
  1521. }
  1522. $receiptList[$key]['verifyList']=$verifyList;
  1523. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1524. $receiptList[$key]['button']=$button;
  1525. }
  1526. //print_r($receiptList);die;
  1527. $mothHtml="";
  1528. for($i=1;$i<=12;$i++){
  1529. if($moth==$i)
  1530. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1531. else
  1532. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1533. }
  1534. $data['mothHtml']=$mothHtml;
  1535. $data['receiptList']=$receiptList;
  1536. $data['memu']="receipt";
  1537. $data['staff']=$this->staff;
  1538. $data['receiptMemu']='expenses';
  1539. $data['verifyId']=$this->verifyId;
  1540. $data['executeId']=$this->executeId;
  1541. $data['item']=$item;
  1542. $data['year']=$year;
  1543. $this->render ( "/admin/expenses", $data );
  1544. }
  1545. function expensesCollect(){
  1546. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1547. Doo::loadModel('receipt');
  1548. $receipt=new receipt();
  1549. Doo::loadModel('L_category');
  1550. $Lcategory=new L_category();
  1551. Doo::loadModel('verify');
  1552. Doo::loadModel('statistics');
  1553. $statistics=new statistics();
  1554. $verify=new verify();
  1555. Doo::loadModel('staff');
  1556. $staff=new staff();
  1557. Doo::loadModel('loanReceipt');
  1558. $loanReceipt=new loanReceipt();
  1559. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid,'desc'=>'rid','asArray'=>true));
  1560. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  1561. $Locate=0;$roleId=0;$button=0;
  1562. foreach ($loanList as $key=>$value){
  1563. $loanList[$key]['Locate']=$Locate;$Locate++;
  1564. $loanList[$key]['reviseDetail']=array();
  1565. if (!empty($value['reviseDetail']))
  1566. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1567. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1568. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1569. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1570. $loanList[$key]['category']=$categoryDetil['title'];
  1571. //检测编辑状态
  1572. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  1573. $verifyList['staff']=$value['verifyBreakup'];
  1574. else
  1575. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1576. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1577. $verifyStaff=json_decode($value['verifyStaff'],true);
  1578. Doo::loadModel('role');
  1579. $role=new role();
  1580. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1581. foreach ($verifyList as $k=>$v){
  1582. //init verifyStaff
  1583. if ($v[1]=='ROLE'){
  1584. if (!empty($verifyStaff)){
  1585. $endStaffArray=end($verifyStaff);
  1586. // if ($v[0]==$endStaffArray['nextStaff']){
  1587. // $roleId=$v[0];
  1588. // }
  1589. }
  1590. $roleVerify=json_decode($v[3],true);
  1591. $roleKey=$k;$roleArray=array();
  1592. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1593. foreach ($roleVerify as $o=>$p){
  1594. $staffID=explode ('_',$p);
  1595. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1596. //print_r($staffID);
  1597. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1598. array_push($roleArray, $exp);
  1599. }
  1600. $roleArrayCopy[$v[0]]=$roleArray;
  1601. //$verifyList[$k]['roleArray']=$roleArray;
  1602. }
  1603. $verifyList[$k]['date']="";
  1604. $verifyList[$k]['opinion']="";
  1605. $verifyList[$k]['status']="";
  1606. if (empty($verifyStaff)){
  1607. $verifyList[$k]['date']="";
  1608. $verifyList[$k]['opinion']="";
  1609. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1610. $verifyList[$k]['status']=4;
  1611. $flag=false;
  1612. }
  1613. }else{
  1614. foreach ($verifyStaff as $m=>$u){
  1615. if ($v[0]==$m){
  1616. $verifyList[$k]['date']=$u['date'];
  1617. $verifyList[$k]['opinion']=$u['opinion'];
  1618. $verifyList[$k]['status']=$u['status'];
  1619. $flag=false;
  1620. break;
  1621. }
  1622. }
  1623. $endStaffArray=end($verifyStaff);
  1624. if (isset($endStaffArray['ROLE'])){
  1625. }else{
  1626. // $endKey=key($verifyStaff);
  1627. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1628. // $button=4;
  1629. // $verifyList[$k]['status']=4;
  1630. // }
  1631. }
  1632. }
  1633. }
  1634. $rolename['name']='';
  1635. if (!empty($roleId)){
  1636. Doo::loadModel('role');
  1637. $role=new role();
  1638. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1639. }
  1640. if (!empty($verifyStaff))
  1641. $endStaffArray=end($verifyStaff);
  1642. $KOP=false;
  1643. foreach ($roleArrayCopy as $P=>$A){
  1644. foreach ( $A as $MKI=>$AVL){
  1645. if (!empty($verifyStaff)){
  1646. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1647. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1648. $button=4;
  1649. $roleArrayCopy[$P][$MKI]['status']=4;
  1650. }
  1651. foreach ($verifyStaff as $m=>$u){
  1652. $AVLFK=$AVL[0].'_R';
  1653. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1654. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1655. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1656. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1657. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1658. break;
  1659. }
  1660. }
  1661. }else{
  1662. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1663. $button=4;
  1664. $roleArrayCopy[$P][$MKI]['status']=4;
  1665. }
  1666. }
  1667. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1668. $KOP=true;
  1669. }
  1670. }
  1671. foreach ($roleArrayCopy as $k=>$v){
  1672. foreach ($verifyList as $m=>$n){
  1673. if ($n[0]==$k){
  1674. array_splice($verifyList,$m,1,$v);
  1675. }
  1676. }
  1677. }
  1678. $loanList[$key]['verifyList']=$verifyList;
  1679. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1680. $loanList[$key]['button']=$button;
  1681. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  1682. }
  1683. $data['loanList']=$loanList;
  1684. $Locate=0;$roleId=0;$button=0;
  1685. foreach ($receiptList as $key=>$value){
  1686. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1687. $receiptList[$key]['reviseDetail']=array();
  1688. if (!empty($value['reviseDetail']))
  1689. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1690. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1691. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  1692. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1693. $receiptList[$key]['category']=$categoryDetil['title'];
  1694. //检测编辑状态
  1695. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9){
  1696. if($value['status']==8&&$value['Rtype']==1)
  1697. $verifyList['staff']=$loanList[0]['verifyBreakup'];
  1698. else
  1699. $verifyList['staff']=$value['verifyBreakup'];
  1700. }else
  1701. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1702. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1703. $verifyStaff=json_decode($value['verifyStaff'],true);
  1704. Doo::loadModel('role');
  1705. $role=new role();
  1706. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  1707. foreach ($verifyList as $k=>$v){
  1708. //init verifyStaff
  1709. if ($v[1]=='ROLE'){
  1710. if (!empty($verifyStaff)){
  1711. $endStaffArray=end($verifyStaff);
  1712. // if ($v[0]==$endStaffArray['nextStaff']){
  1713. // $roleId=$v[0];
  1714. // }
  1715. }
  1716. $roleVerify=json_decode($v[3],true);
  1717. $roleKey=$k;$roleArray=array();
  1718. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  1719. foreach ($roleVerify as $o=>$p){
  1720. $staffID=explode ('_',$p);
  1721. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  1722. //print_r($staffID);
  1723. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  1724. array_push($roleArray, $exp);
  1725. }
  1726. $roleArrayCopy[$v[0]]=$roleArray;
  1727. //$verifyList[$k]['roleArray']=$roleArray;
  1728. }
  1729. $verifyList[$k]['date']="";
  1730. $verifyList[$k]['opinion']="";
  1731. $verifyList[$k]['status']="";
  1732. if (empty($verifyStaff)){
  1733. $verifyList[$k]['date']="";
  1734. $verifyList[$k]['opinion']="";
  1735. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  1736. $verifyList[$k]['status']=4;
  1737. $flag=false;
  1738. }
  1739. }else{
  1740. foreach ($verifyStaff as $m=>$u){
  1741. if ($v[0]==$m){
  1742. $verifyList[$k]['date']=$u['date'];
  1743. $verifyList[$k]['opinion']=$u['opinion'];
  1744. $verifyList[$k]['status']=$u['status'];
  1745. $flag=false;
  1746. break;
  1747. }
  1748. }
  1749. $endStaffArray=end($verifyStaff);
  1750. if (isset($endStaffArray['ROLE'])){
  1751. }else{
  1752. // $endKey=key($verifyStaff);
  1753. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1754. // $button=4;
  1755. // $verifyList[$k]['status']=4;
  1756. // }
  1757. }
  1758. }
  1759. }
  1760. $rolename['name']='';
  1761. if (!empty($roleId)){
  1762. Doo::loadModel('role');
  1763. $role=new role();
  1764. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  1765. }
  1766. if (!empty($verifyStaff))
  1767. $endStaffArray=end($verifyStaff);
  1768. $KOP=false;
  1769. foreach ($roleArrayCopy as $P=>$A){
  1770. foreach ( $A as $MKI=>$AVL){
  1771. if (!empty($verifyStaff)){
  1772. //&&$rolename['rid']==$endStaffArray['nextStaff']
  1773. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  1774. $button=4;
  1775. $roleArrayCopy[$P][$MKI]['status']=4;
  1776. }
  1777. foreach ($verifyStaff as $m=>$u){
  1778. $AVLFK=$AVL[0].'_R';
  1779. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1780. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  1781. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  1782. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  1783. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  1784. break;
  1785. }
  1786. }
  1787. }else{
  1788. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  1789. $button=4;
  1790. $roleArrayCopy[$P][$MKI]['status']=4;
  1791. }
  1792. }
  1793. //$roleArray[$MKI]['rolename']=$rolename['name'];
  1794. $KOP=true;
  1795. }
  1796. }
  1797. foreach ($roleArrayCopy as $k=>$v){
  1798. foreach ($verifyList as $m=>$n){
  1799. if ($n[0]==$k){
  1800. array_splice($verifyList,$m,1,$v);
  1801. }
  1802. }
  1803. }
  1804. //费用执行人相关数据
  1805. $executeCopy=json_decode($value['executeCopy'],true);
  1806. $executeStaff=json_decode($value['executeStaff'],true);
  1807. foreach ($executeCopy as $k=>$v){
  1808. $executeCopy[$k]['date']='';
  1809. $executeCopy[$k]['opinion']='';
  1810. $executeCopy[$k]['status']='';
  1811. if (!empty($executeStaff))
  1812. foreach ($executeStaff as $m=>$u){
  1813. if ($v[0]==$m){
  1814. $executeCopy[$k]['date']=$u['date'];
  1815. $executeCopy[$k]['opinion']=$u['opinion'];
  1816. $executeCopy[$k]['status']=$u['status'];
  1817. break;
  1818. }
  1819. }
  1820. }
  1821. $receiptList[$key]['executeCopy']=$executeCopy;
  1822. $receiptList[$key]['verifyList']=$verifyList;
  1823. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1824. $receiptList[$key]['button']=$button;
  1825. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  1826. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  1827. $relust=$value['sum']-$value['loanSum'];
  1828. $receiptList[$key]['relust']=$relust;
  1829. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  1830. }
  1831. $data['receiptList']=$receiptList;
  1832. $data['memu']="receipt";
  1833. $data['staff']=$this->staff;
  1834. $data['receiptMemu']='expenses';
  1835. $data['verifyId']=$this->verifyId;
  1836. $data['executeId']=$this->executeId;
  1837. $this->render ( "/admin/expensesCollect", $data );
  1838. }
  1839. function approvalExpenses(){
  1840. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  1841. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  1842. $month=$this->get_args('month')?$this->get_args('month'):"";
  1843. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  1844. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  1845. if (empty($status))
  1846. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  1847. $page_size=12;
  1848. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1849. $vidList=array();
  1850. $button=0;
  1851. Doo::loadModel('verify');
  1852. $verify=new verify();
  1853. Doo::loadModel('receipt');
  1854. $receipt=new receipt();
  1855. Doo::loadModel('staff');
  1856. $staff=new staff();
  1857. Doo::loadModel('L_category');
  1858. $Lcategory=new L_category();
  1859. //user verify ID
  1860. $verifyDetail=$verify->find(array('where'=>' (staff not like "%\"'.$this->staff[0]['sid'].'\",\"ROLE%") and (staff like "%[\"'.$this->staff[0]['sid'].'\",%" or staff like "%\"'.$this->staff[0]['sid'].'\_%" )','asArray'=>true));
  1861. foreach ($verifyDetail as $key=>$value){
  1862. array_push($vidList, $value['vid']);
  1863. }
  1864. $vid=implode(",", $vidList);
  1865. if(empty($verifyDetail))
  1866. $vid=0;
  1867. // if ($status==0)
  1868. // $dateCondition="";
  1869. // else
  1870. $dateCondition=" and Year(date) =".$year;
  1871. if(!empty($month))
  1872. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  1873. $categoryList=$Lcategory->find(array('asArray'=>true));
  1874. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  1875. $cateCondition="";$staffCondition="";$approvalCondition="";
  1876. if (!empty($cid))
  1877. $cateCondition=' and cid='.$cid;
  1878. if(!empty($sid)){
  1879. $staffCondition=' and staff='.$sid;
  1880. $cateCondition="";
  1881. }
  1882. $approvalCondition=" and status=".$status;
  1883. if($status==2){
  1884. //查找角色审批人
  1885. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  1886. }
  1887. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  1888. $approvalCondition=' and status=2 ';
  1889. }
  1890. if($status==1){
  1891. $approvalCondition=' and (status='.$status.' or status=6) ';
  1892. }
  1893. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  1894. $pageinfo['page']=array('previous'=>'');
  1895. if ($status==0){
  1896. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.') and status!=5', $page, $page_size, "approvalExpenses","","");
  1897. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')'
  1898. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  1899. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1900. }else
  1901. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition.' and verify in ('.$vid.')'
  1902. ,'desc'=>'rid','asArray'=>true));
  1903. $rLRes=$receipt->find(array('where'=>'status=2 and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )'.$cateCondition.$staffCondition
  1904. ,'desc'=>'rid','asArray'=>true));
  1905. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  1906. //print_r($pageinfo);
  1907. $Locate=0;
  1908. foreach ($receiptList as $key=>$value){
  1909. $receiptList[$key]['Locate']=$Locate;$Locate++;
  1910. $receiptList[$key]['reviseDetail']=array();
  1911. if (!empty($value['reviseDetail']))
  1912. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  1913. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  1914. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  1915. $receiptList[$key]['category']=$categoryDetil['title'];
  1916. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  1917. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  1918. $verifyStaff=json_decode($value['verifyStaff'],true);
  1919. foreach ($verifyList as $k=>$v){
  1920. //init verifyStaff
  1921. $verifyList[$k]['date']="";
  1922. $verifyList[$k]['opinion']="";
  1923. $verifyList[$k]['status']="";
  1924. if (empty($verifyStaff)){
  1925. $verifyList[$k]['date']="";
  1926. $verifyList[$k]['opinion']="";
  1927. if ($v[0]==$this->staff[0]['sid']){
  1928. $verifyList[$k]['status']=4;
  1929. $button=4;
  1930. }
  1931. }else{
  1932. $flag=true;
  1933. foreach ($verifyStaff as $m=>$u){
  1934. if ($v[0]==$m){
  1935. $verifyList[$k]['date']=$u['date'];
  1936. $verifyList[$k]['opinion']=$u['opinion'];
  1937. $verifyList[$k]['status']=$u['status'];
  1938. $flag=false;
  1939. break;
  1940. }
  1941. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  1942. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  1943. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  1944. }
  1945. if($flag){//检测可编辑
  1946. if($v[0]==$this->staff[0]['sid']){
  1947. $verifyList[$k]['status']=4;$button=4;
  1948. }
  1949. }
  1950. }
  1951. }
  1952. $receiptList[$key]['verifyList']=$verifyList;
  1953. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  1954. $receiptList[$key]['button']=$button;
  1955. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  1956. }
  1957. //print_r($receiptList);die;
  1958. //$data['verifyDetail']=$verifyDetail;
  1959. $mothHtml="";
  1960. for($i=1;$i<=12;$i++){
  1961. if($month==$i)
  1962. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  1963. else
  1964. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  1965. }
  1966. $data['mothHtml']=$mothHtml;
  1967. $data['page']=$pageinfo;
  1968. $data['receiptList']=$receiptList;
  1969. $data['receiptApprovalCount']=count($rLRes);
  1970. $data['status']=$status;
  1971. $data['year']=$year;
  1972. $data['categoryList']=$categoryList;
  1973. $data['staffList']=$staffList;
  1974. $data['cid']=$cid;
  1975. $data['sid']=$sid;
  1976. //print_r($receiptList);
  1977. $data['memu']="receipt";
  1978. $data['staff']=$this->staff;
  1979. $data['receiptMemu']='approvalExpenses';
  1980. $data['verifyId']=$this->verifyId;
  1981. $data['executeId']=$this->executeId;
  1982. $this->render ( "/admin/approvalExpenses", $data );
  1983. }
  1984. function expensesDoc(){
  1985. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  1986. Doo::loadModel('receipt');
  1987. $receipt=new receipt();
  1988. Doo::loadModel('L_category');
  1989. $Lcategory=new L_category();
  1990. Doo::loadModel('verify');
  1991. Doo::loadModel('statistics');
  1992. $statistics=new statistics();
  1993. $verify=new verify();
  1994. Doo::loadModel('staff');
  1995. $staff=new staff();
  1996. Doo::loadModel('loanReceipt');
  1997. $loanReceipt=new loanReceipt();
  1998. $receiptList=$receipt->find(array('where'=>' rid='.$rid,'desc'=>'rid','asArray'=>true));
  1999. $loanList=array();
  2000. if (!empty($receiptList))
  2001. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2002. $Locate=0;$roleId=0;$button=0;
  2003. foreach ($loanList as $key=>$value){
  2004. $loanList[$key]['Locate']=$Locate;$Locate++;
  2005. $loanList[$key]['reviseDetail']=array();
  2006. if (!empty($value['reviseDetail']))
  2007. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2008. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2009. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2010. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2011. $loanList[$key]['category']=$categoryDetil['title'];
  2012. //检测编辑状态
  2013. if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9)
  2014. $verifyList['staff']=$value['verifyBreakup'];
  2015. else
  2016. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2017. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2018. $verifyStaff=json_decode($value['verifyStaff'],true);
  2019. Doo::loadModel('role');
  2020. $role=new role();
  2021. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2022. foreach ($verifyList as $k=>$v){
  2023. //init verifyStaff
  2024. if ($v[1]=='ROLE'){
  2025. if (!empty($verifyStaff)){
  2026. $endStaffArray=end($verifyStaff);
  2027. // if ($v[0]==$endStaffArray['nextStaff']){
  2028. // $roleId=$v[0];
  2029. // }
  2030. }
  2031. $roleVerify=json_decode($v[3],true);
  2032. $roleKey=$k;$roleArray=array();
  2033. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2034. foreach ($roleVerify as $o=>$p){
  2035. $staffID=explode ('_',$p);
  2036. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2037. //print_r($staffID);
  2038. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2039. array_push($roleArray, $exp);
  2040. }
  2041. $roleArrayCopy[$v[0]]=$roleArray;
  2042. //$verifyList[$k]['roleArray']=$roleArray;
  2043. }
  2044. $verifyList[$k]['date']="";
  2045. $verifyList[$k]['opinion']="";
  2046. $verifyList[$k]['status']="";
  2047. if (empty($verifyStaff)){
  2048. $verifyList[$k]['date']="";
  2049. $verifyList[$k]['opinion']="";
  2050. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2051. $verifyList[$k]['status']=4;
  2052. $flag=false;
  2053. }
  2054. }else{
  2055. foreach ($verifyStaff as $m=>$u){
  2056. if ($v[0]==$m){
  2057. $verifyList[$k]['date']=$u['date'];
  2058. $verifyList[$k]['opinion']=$u['opinion'];
  2059. $verifyList[$k]['status']=$u['status'];
  2060. $flag=false;
  2061. break;
  2062. }
  2063. }
  2064. $endStaffArray=end($verifyStaff);
  2065. if (isset($endStaffArray['ROLE'])){
  2066. }else{
  2067. // $endKey=key($verifyStaff);
  2068. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2069. // $button=4;
  2070. // $verifyList[$k]['status']=4;
  2071. // }
  2072. }
  2073. }
  2074. }
  2075. $rolename['name']='';
  2076. if (!empty($roleId)){
  2077. Doo::loadModel('role');
  2078. $role=new role();
  2079. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2080. }
  2081. if (!empty($verifyStaff))
  2082. $endStaffArray=end($verifyStaff);
  2083. $KOP=false;
  2084. foreach ($roleArrayCopy as $P=>$A){
  2085. foreach ( $A as $MKI=>$AVL){
  2086. if (!empty($verifyStaff)){
  2087. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2088. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2089. $button=4;
  2090. $roleArrayCopy[$P][$MKI]['status']=4;
  2091. }
  2092. foreach ($verifyStaff as $m=>$u){
  2093. $AVLFK=$AVL[0].'_R';
  2094. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2095. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2096. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2097. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2098. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2099. break;
  2100. }
  2101. }
  2102. }else{
  2103. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2104. $button=4;
  2105. $roleArrayCopy[$P][$MKI]['status']=4;
  2106. }
  2107. }
  2108. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2109. $KOP=true;
  2110. }
  2111. }
  2112. foreach ($roleArrayCopy as $k=>$v){
  2113. foreach ($verifyList as $m=>$n){
  2114. if ($n[0]==$k){
  2115. array_splice($verifyList,$m,1,$v);
  2116. }
  2117. }
  2118. }
  2119. $loanList[$key]['verifyList']=$verifyList;
  2120. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2121. $loanList[$key]['button']=$button;
  2122. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  2123. }
  2124. $data['loanList']=$loanList;
  2125. //print_r($loanList);
  2126. $Locate=0;$roleId=0;$button=0;
  2127. foreach ($receiptList as $key=>$value){
  2128. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2129. $receiptList[$key]['reviseDetail']=array();
  2130. if (!empty($value['reviseDetail']))
  2131. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2132. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2133. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2134. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2135. $receiptList[$key]['category']=$categoryDetil['title'];
  2136. //检测编辑状态
  2137. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2138. $verifyList['staff']=$value['verifyBreakup'];
  2139. }else
  2140. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2141. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2142. $verifyStaff=json_decode($value['verifyStaff'],true);
  2143. Doo::loadModel('role');
  2144. $role=new role();
  2145. if ($verifyList==NULL)
  2146. $verifyList=array();
  2147. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2148. foreach ($verifyList as $k=>$v){
  2149. //init verifyStaff
  2150. if ($v[1]=='ROLE'){
  2151. if (!empty($verifyStaff)){
  2152. $endStaffArray=end($verifyStaff);
  2153. // if ($v[0]==$endStaffArray['nextStaff']){
  2154. // $roleId=$v[0];
  2155. // }
  2156. }
  2157. $roleVerify=json_decode($v[3],true);
  2158. $roleKey=$k;$roleArray=array();
  2159. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2160. foreach ($roleVerify as $o=>$p){
  2161. $staffID=explode ('_',$p);
  2162. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2163. //print_r($staffID);
  2164. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2165. array_push($roleArray, $exp);
  2166. }
  2167. $roleArrayCopy[$v[0]]=$roleArray;
  2168. //$verifyList[$k]['roleArray']=$roleArray;
  2169. }
  2170. $verifyList[$k]['date']="";
  2171. $verifyList[$k]['opinion']="";
  2172. $verifyList[$k]['status']="";
  2173. if (empty($verifyStaff)){
  2174. $verifyList[$k]['date']="";
  2175. $verifyList[$k]['opinion']="";
  2176. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2177. $verifyList[$k]['status']=4;
  2178. $flag=false;
  2179. }
  2180. }else{
  2181. foreach ($verifyStaff as $m=>$u){
  2182. if ($v[0]==$m){
  2183. $verifyList[$k]['date']=$u['date'];
  2184. $verifyList[$k]['opinion']=$u['opinion'];
  2185. $verifyList[$k]['status']=$u['status'];
  2186. $flag=false;
  2187. break;
  2188. }
  2189. }
  2190. $endStaffArray=end($verifyStaff);
  2191. if (isset($endStaffArray['ROLE'])){
  2192. }else{
  2193. // $endKey=key($verifyStaff);
  2194. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2195. // $button=4;
  2196. // $verifyList[$k]['status']=4;
  2197. // }
  2198. }
  2199. }
  2200. }
  2201. $rolename['name']='';
  2202. if (!empty($roleId)){
  2203. Doo::loadModel('role');
  2204. $role=new role();
  2205. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2206. }
  2207. if (!empty($verifyStaff))
  2208. $endStaffArray=end($verifyStaff);
  2209. $KOP=false;
  2210. foreach ($roleArrayCopy as $P=>$A){
  2211. foreach ( $A as $MKI=>$AVL){
  2212. if (!empty($verifyStaff)){
  2213. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2214. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2215. $button=4;
  2216. $roleArrayCopy[$P][$MKI]['status']=4;
  2217. }
  2218. foreach ($verifyStaff as $m=>$u){
  2219. $AVLFK=$AVL[0].'_R';
  2220. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2221. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2222. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2223. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2224. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2225. break;
  2226. }
  2227. }
  2228. }else{
  2229. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2230. $button=4;
  2231. $roleArrayCopy[$P][$MKI]['status']=4;
  2232. }
  2233. }
  2234. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2235. $KOP=true;
  2236. }
  2237. }
  2238. foreach ($roleArrayCopy as $k=>$v){
  2239. foreach ($verifyList as $m=>$n){
  2240. if ($n[0]==$k){
  2241. array_splice($verifyList,$m,1,$v);
  2242. }
  2243. }
  2244. }
  2245. //费用执行人相关数据
  2246. $executeCopy=json_decode($value['executeCopy'],true);
  2247. $executeStaff=json_decode($value['executeStaff'],true);
  2248. foreach ($executeCopy as $k=>$v){
  2249. $executeCopy[$k]['date']='';
  2250. $executeCopy[$k]['opinion']='';
  2251. $executeCopy[$k]['status']='';
  2252. if (!empty($executeStaff))
  2253. foreach ($executeStaff as $m=>$u){
  2254. if ($v[0]==$m){
  2255. $executeCopy[$k]['date']=$u['date'];
  2256. $executeCopy[$k]['opinion']=$u['opinion'];
  2257. $executeCopy[$k]['status']=$u['status'];
  2258. break;
  2259. }
  2260. }
  2261. }
  2262. $receiptList[$key]['executeCopy']=$executeCopy;
  2263. $receiptList[$key]['verifyList']=$verifyList;
  2264. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2265. $receiptList[$key]['button']=$button;
  2266. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  2267. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  2268. }
  2269. //print_r($receiptList);
  2270. //获取审批日志
  2271. Doo::loadModel('receiptLog');
  2272. $receiptLog=new receiptLog();
  2273. $rlList=array();
  2274. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2275. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2276. if (!empty($rlInfo)){
  2277. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2278. }
  2279. $receiptList[0]['rlList']=$rlList;
  2280. $data['receiptList']=$receiptList;
  2281. $data['memu']="receipt";
  2282. $data['staff']=$this->staff;
  2283. $data['receiptMemu']='approvalExpenses';
  2284. $data['verifyId']=$this->verifyId;
  2285. $data['executeId']=$this->executeId;
  2286. $this->render ( "/admin/expensesDoc", $data );
  2287. }
  2288. function expensesEdi(){
  2289. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  2290. $status=isset($this->params['status'])?$this->params['status']:'';
  2291. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  2292. $month=$this->get_args('month')?$this->get_args('month'):"";
  2293. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  2294. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  2295. if (empty($status))
  2296. $status=$this->get_args('status')?$this->get_args('status'):2;
  2297. $vidList=array();
  2298. $button=0;
  2299. Doo::loadModel('verify');
  2300. Doo::loadModel('receipt');
  2301. Doo::loadModel('staff');
  2302. $staff=new staff();
  2303. $receipt=new receipt();
  2304. $verify=new verify();
  2305. Doo::loadModel('L_category');
  2306. $Lcategory=new L_category();
  2307. Doo::loadModel('enclosur');
  2308. $enclosur=new enclosur();
  2309. //user verify ID
  2310. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  2311. foreach ($verifyDetail as $key=>$value){
  2312. array_push($vidList, $value['vid']);
  2313. }
  2314. $vid=implode(",", $vidList);
  2315. if(empty($verifyDetail))
  2316. $vid=0;
  2317. $categoryList=$Lcategory->find(array('asArray'=>true));
  2318. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  2319. $ap="";
  2320. if($status==4){
  2321. $ap=4;$status=2;
  2322. }
  2323. //get Receipt By verifyID status 2
  2324. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  2325. $Locate=0;$roleId=0;
  2326. if($ap==4)
  2327. $status=4;
  2328. foreach ($receiptList as $key=>$value){
  2329. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2330. $receiptList[$key]['reviseDetail']=array();
  2331. if (!empty($value['reviseDetail']))
  2332. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2333. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2334. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2335. $receiptList[$key]['category']=$categoryDetil['title'];
  2336. //检测编辑状态
  2337. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2338. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2339. $verifyStaff=json_decode($value['verifyStaff'],true);
  2340. Doo::loadModel('role');
  2341. $role=new role();
  2342. //print_r($verifyList);
  2343. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2344. foreach ($verifyList as $k=>$v){
  2345. //init verifyStaff
  2346. if ($v[1]=='ROLE'){
  2347. if (!empty($verifyStaff)){
  2348. $endStaffArray=end($verifyStaff);
  2349. if ($v[0]==$endStaffArray['nextStaff']){
  2350. $roleId=$v[0];
  2351. }
  2352. }
  2353. $roleVerify=json_decode($v[3],true);
  2354. $roleKey=$k;$roleArray=array();
  2355. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2356. foreach ($roleVerify as $o=>$p){
  2357. $staffID=explode ('_',$p);
  2358. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2359. //print_r($staffID);
  2360. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2361. array_push($roleArray, $exp);
  2362. }
  2363. $roleArrayCopy[$v[0]]=$roleArray;
  2364. //$verifyList[$k]['roleArray']=$roleArray;
  2365. }
  2366. //print_r($roleArray);
  2367. $verifyList[$k]['date']="";
  2368. $verifyList[$k]['opinion']="";
  2369. $verifyList[$k]['status']="";
  2370. if (empty($verifyStaff)){
  2371. $verifyList[$k]['date']="";
  2372. $verifyList[$k]['opinion']="";
  2373. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2374. $verifyList[$k]['status']=4;
  2375. $button=4;$flag=false;
  2376. }
  2377. }else{
  2378. foreach ($verifyStaff as $m=>$u){
  2379. if ($v[0]==$m){
  2380. $verifyList[$k]['date']=$u['date'];
  2381. $verifyList[$k]['opinion']=$u['opinion'];
  2382. $verifyList[$k]['status']=$u['status'];
  2383. $flag=false;
  2384. break;
  2385. }
  2386. }
  2387. $endStaffArray=end($verifyStaff);
  2388. if (isset($endStaffArray['ROLE'])){
  2389. }else{
  2390. $endKey=key($verifyStaff);
  2391. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2392. $button=4;
  2393. $verifyList[$k]['status']=4;
  2394. }
  2395. }
  2396. }
  2397. }
  2398. $rolename['name']='';
  2399. if (!empty($roleId)){
  2400. Doo::loadModel('role');
  2401. $role=new role();
  2402. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2403. }
  2404. if (!empty($verifyStaff))
  2405. $endStaffArray=end($verifyStaff);
  2406. $KOP=false;
  2407. foreach ($roleArrayCopy as $P=>$A){
  2408. foreach ( $A as $MKI=>$AVL){
  2409. if (!empty($verifyStaff)){
  2410. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2411. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2412. $button=4;
  2413. $roleArrayCopy[$P][$MKI]['status']=4;
  2414. }
  2415. foreach ($verifyStaff as $m=>$u){
  2416. $AVLFK=$AVL[0].'_R';
  2417. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2418. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2419. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2420. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2421. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2422. break;
  2423. }
  2424. }
  2425. }else{
  2426. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2427. $button=4;
  2428. $roleArrayCopy[$P][$MKI]['status']=4;
  2429. }
  2430. }
  2431. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2432. $KOP=true;
  2433. }
  2434. }
  2435. // print_r($roleArrayCopy);
  2436. // echo $roleKey;
  2437. foreach ($roleArrayCopy as $k=>$v){
  2438. foreach ($verifyList as $m=>$n){
  2439. if ($n[0]==$k){
  2440. array_splice($verifyList,$m,1,$v);
  2441. }
  2442. }
  2443. }
  2444. $receiptList[$key]['verifyList']=$verifyList;
  2445. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2446. $receiptList[$key]['button']=$button;
  2447. $receiptList[$key]['BIGsum']=$this->num_to_rmb($value['sum']);
  2448. }
  2449. //$data['verifyDetail']=$verifyDetail;
  2450. $mothHtml="";
  2451. for($i=1;$i<=12;$i++){
  2452. if($month==$i)
  2453. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  2454. else
  2455. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  2456. }
  2457. //获取审批日志
  2458. Doo::loadModel('receiptLog');
  2459. $receiptLog=new receiptLog();
  2460. $rlList=array();
  2461. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  2462. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  2463. if (!empty($rlInfo)){
  2464. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  2465. }
  2466. $receiptList[0]['rlList']=$rlList;
  2467. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  2468. $enclosurHtml='';
  2469. foreach ($enclosurList as $value){
  2470. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  2471. }
  2472. //print_r($receiptList);
  2473. $data['rid']=$rid;
  2474. $data['enclosurHtml']=$enclosurHtml;
  2475. $data['rolename']=$rolename['name'];
  2476. $data['datetij']=$tijdate['date'];
  2477. $data['mothHtml']=$mothHtml;
  2478. $data['receiptList']=$receiptList;
  2479. $data['receiptApprovalCount']=count($receiptList);
  2480. $data['status']=$status;
  2481. $data['year']=$year;
  2482. $data['categoryList']=$categoryList;
  2483. $data['staffList']=$staffList;
  2484. $data['cid']=$cid;
  2485. $data['sid']=$sid;
  2486. $data['ap']=$ap;
  2487. $data['memu']="receipt";
  2488. $data['staff']=$this->staff;
  2489. $data['receiptMemu']='approvalExpenses';
  2490. $data['verifyId']=$this->verifyId;
  2491. $data['executeId']=$this->executeId;
  2492. $this->render ( "/admin/expensesEdi", $data );
  2493. }
  2494. function expensesDefray(){
  2495. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  2496. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  2497. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  2498. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  2499. if(!empty($rid)){
  2500. Doo::loadModel("verify");
  2501. $verify=new verify();
  2502. Doo::loadModel("receiptDetail");
  2503. $receiptDetailObj=new receiptDetail();
  2504. Doo::loadModel("itemStatistics");
  2505. Doo::loadModel("statistics");
  2506. $statistics=new statistics();
  2507. $itemStatistics=new itemStatistics();
  2508. Doo::loadModel("receipt");
  2509. $receipt=new receipt();
  2510. Doo::loadModel("loanReceipt");
  2511. $loanReceipt=new loanReceipt();
  2512. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  2513. if (empty($receiptDetail))
  2514. return "/approval";
  2515. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  2516. $verifyString=$verifyDetail['staff'];
  2517. $verifyDetail=json_decode($verifyDetail['staff'],true);
  2518. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  2519. if(empty($opinion)){
  2520. if ($status==3)
  2521. $opinion="终止";
  2522. else
  2523. $opinion="同意支付";
  2524. }
  2525. $nowStaff=0;$nowStaffList=array();
  2526. if(empty($verifyStaff)){
  2527. //还需加入是否已经进入角色审批
  2528. if ($verifyDetail[0][1]=='ROLE'){
  2529. //print_r($verifyDetail);echo "ddd";
  2530. $vStaffString=json_decode($verifyDetail[0][3]);
  2531. foreach ($vStaffString as $key=>$value){
  2532. $staffK=explode("_", $value);
  2533. if ($staffK[0]!=$this->staff[0]['sid'])
  2534. array_push($nowStaffList, $staffK[0]);
  2535. }
  2536. //print_r($verifyDetail);
  2537. //die;
  2538. $nowStaff=implode(',', $nowStaffList);
  2539. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  2540. }else{
  2541. if ($verifyDetail[1][1]=='ROLE'){
  2542. $vStaffString=json_decode($verifyDetail[1][3]);
  2543. //echo "dd";
  2544. foreach ($vStaffString as $key=>$value){
  2545. $staffK=explode("_", $value);
  2546. array_push($nowStaffList, $staffK[0]);
  2547. }
  2548. $nowStaff=implode(',', $nowStaffList);
  2549. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  2550. }else{
  2551. $nowStaff=$verifyDetail[1][0];
  2552. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  2553. }
  2554. }
  2555. if($status==3)
  2556. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  2557. $vStaffString=json_encode($verifyStaff);
  2558. $receipt->nowStaff=$nowStaff;
  2559. $receipt->verifyStaff=$vStaffString;
  2560. $loanReceipt->nowStaff=$nowStaff;
  2561. $loanReceipt->verifyStaff=$vStaffString;
  2562. }else{
  2563. $VS=end($verifyStaff);
  2564. //非角色审批
  2565. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  2566. $nextStaff=0;$roleSTF=false;
  2567. foreach ($verifyDetail as $key=>$value){
  2568. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  2569. if (isset($verifyDetail[$key+1])){
  2570. $nextStaff=$verifyDetail[$key+1][0];
  2571. if ($verifyDetail[$key+1][1]=='ROLE')
  2572. $roleSTF=true;
  2573. }
  2574. break;
  2575. }
  2576. }
  2577. if (!$roleSTF){
  2578. $nowStaff=$nextStaff;
  2579. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2580. }else{
  2581. //获取角色下的所有用户ID
  2582. $nowStaffList=array();
  2583. foreach ($verifyDetail as $vfk){
  2584. if ($vfk[1]=='ROLE'){
  2585. $vStaffString=json_decode($vfk[3]);
  2586. foreach ($vStaffString as $key=>$value){
  2587. $staffK=explode("_", $value);
  2588. array_push($nowStaffList, $staffK[0]);
  2589. }
  2590. }
  2591. }
  2592. $nowStaff=implode(',', $nowStaffList);
  2593. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  2594. }
  2595. if($status==3){
  2596. $verifyStaff['final']=$status;
  2597. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2598. }
  2599. $vStaffString=json_encode($verifyStaff);
  2600. $receipt->nowStaff=$nowStaff;
  2601. $receipt->verifyStaff=$vStaffString;
  2602. $loanReceipt->nowStaff=$nowStaff;
  2603. $loanReceipt->verifyStaff=$vStaffString;
  2604. }
  2605. //角色审批
  2606. if (isset($VS['ROLE'])){
  2607. //找出角色人 当前审批角色组
  2608. $verifyJSStaff=array();$nowStaffList2=array();
  2609. foreach ($verifyDetail as $key=>$value){
  2610. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  2611. $verifyJSStaff=json_decode($value[3]);
  2612. foreach ($verifyJSStaff as $m){
  2613. $staffK=explode("_", $m);
  2614. array_push($nowStaffList2, $staffK[0]);
  2615. }
  2616. // print_r($nowStaffList2);
  2617. }
  2618. }
  2619. $RoleVerifyStaff=array();
  2620. foreach ($verifyStaff as $key=>$value){
  2621. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  2622. foreach ($nowStaffList2 as $m) {
  2623. if ($key==$m."_R")
  2624. $RoleVerifyStaff[$key]=$value;
  2625. }
  2626. }
  2627. }
  2628. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  2629. if ($jsCount==count($RoleVerifyStaff)){ //或者
  2630. //下一个审批人ID
  2631. $nextStaff=0;$falg=false;
  2632. foreach ($verifyDetail as $key=>$value){
  2633. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  2634. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  2635. $falg=true;
  2636. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  2637. foreach ($vStaffString as $v){
  2638. $staffK=explode("_", $v);
  2639. array_push($nowStaffList, $staffK[0]);
  2640. }
  2641. $nowStaff=implode(',', $nowStaffList);
  2642. $nextStaff=$verifyDetail[$key+1][0];
  2643. }elseif(isset($verifyDetail[$key+1])){
  2644. $nextStaff=$verifyDetail[$key+1][0];
  2645. $nowStaff=$nextStaff;
  2646. }else
  2647. $nowStaff='';
  2648. break;
  2649. }
  2650. }
  2651. if ($falg)
  2652. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  2653. else
  2654. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  2655. // print_r($verifyStaff);
  2656. // echo $nowStaff;die;
  2657. }else{ //进入下一个角色或者审批人
  2658. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2659. //
  2660. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  2661. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  2662. // print_r($verifyStaff);
  2663. // die;
  2664. }
  2665. if($status==3){
  2666. $verifyStaff['final']=$status;
  2667. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  2668. }
  2669. $vStaffString=json_encode($verifyStaff);
  2670. $receipt->verifyStaff=$vStaffString;
  2671. $receipt->nowStaff=$nowStaff;
  2672. $loanReceipt->nowStaff=$nowStaff;
  2673. $loanReceipt->verifyStaff=$vStaffString;
  2674. //die;
  2675. //}
  2676. // print_r($verifyStaff);
  2677. // die;
  2678. }
  2679. //print_r($verifyStaff);die;
  2680. }
  2681. //print_r($verifyDetail);
  2682. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  2683. foreach ($verifyDetail as $k=>$v){
  2684. if ($v[1]=='ROLE'){
  2685. $roleId=$v[0];
  2686. $roleVerify=json_decode($v[3],true);
  2687. $roleKey=$k;$roleArray=array();
  2688. foreach ($roleVerify as $o=>$p){
  2689. $staffID=explode ('_',$p);
  2690. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  2691. array_push($roleArray, $exp);
  2692. }
  2693. $verifyDetailCopy[$v[0]]=$roleArray;
  2694. }
  2695. }
  2696. //print_r($verifyDetail);
  2697. foreach ($verifyDetailCopy as $k=>$v){
  2698. foreach ($verifyDetail as $m=>$n){
  2699. if ($n[0]==$k){
  2700. array_splice($verifyDetail,$m,1,$v);
  2701. }
  2702. }
  2703. }
  2704. //审批日志
  2705. if (!isset($verifyStaff['final'])){
  2706. Doo::loadModel("receiptLog");
  2707. $receiptLog=new receiptLog();
  2708. if (!empty($roleId)){
  2709. Doo::loadModel("role");
  2710. $role=new role();
  2711. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2712. $receiptLog->rolename=$roleInfo['name'];
  2713. }
  2714. $receiptLog->username=$this->staff[0]['username'];
  2715. $receiptLog->uid=$this->staff[0]['sid'];
  2716. $receiptLog->date=date("Y-m-d");
  2717. $receiptLog->opinion=$opinion;
  2718. $receiptLog->img=$this->staff[0]['avatar'];
  2719. $receiptLog->status=1;
  2720. $receiptLog->rid=$rid;
  2721. $receiptLog->insert();
  2722. }
  2723. if (isset($verifyStaff['final'])){//rDetail
  2724. $receipt->status=3;
  2725. $receipt->verifyBreakup=$verifyString;
  2726. $receiptDetailObj->status=3;
  2727. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  2728. //微信企业号通知
  2729. $this->setWXMsg($rid,3);
  2730. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  2731. $receipt->status=6;
  2732. $receipt->pastDate=date("Y-m-d");
  2733. $receipt->isBK=1;
  2734. $loanReceipt->verifyBreakup=$verifyString;
  2735. $loanReceipt->status=1;
  2736. $loanReceipt->pastDate=date("Y-m-d");
  2737. $loanReceipt->update(array('where'=>' rid = '.$receiptDetail['loanRid']));
  2738. //微信企业号通知
  2739. $this->setWXMsg($rid,1);
  2740. }
  2741. $receipt->update(array('where'=>' rid = '.$rid));
  2742. return "/approvalExpenses/2";
  2743. }
  2744. }
  2745. function implement(){
  2746. Doo::loadModel('receipt');
  2747. $receipt=new receipt();
  2748. Doo::loadModel('L_category');
  2749. $Lcategory=new L_category();
  2750. Doo::loadModel('verify');
  2751. $verify=new verify();
  2752. Doo::loadModel('staff');
  2753. $staff=new staff();
  2754. Doo::loadModel("execute");
  2755. $execute=new execute();
  2756. $receiptList=$receipt->find(array('where'=>'executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  2757. Doo::loadModel('loanReceipt');
  2758. $loanReceipt=new loanReceipt();
  2759. //print_r($receiptList);
  2760. $loanList=array();
  2761. if (!isset($receiptList))
  2762. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  2763. $Locate=0;$roleId=0;$button=0;
  2764. foreach ($loanList as $key=>$value){
  2765. $loanList[$key]['Locate']=$Locate;$Locate++;
  2766. $loanList[$key]['reviseDetail']=array();
  2767. if (!empty($value['reviseDetail']))
  2768. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2769. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2770. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2771. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2772. $loanList[$key]['category']=$categoryDetil['title'];
  2773. //检测编辑状态
  2774. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2775. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2776. $verifyStaff=json_decode($value['verifyStaff'],true);
  2777. Doo::loadModel('role');
  2778. $role=new role();
  2779. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2780. foreach ($verifyList as $k=>$v){
  2781. //init verifyStaff
  2782. if ($v[1]=='ROLE'){
  2783. if (!empty($verifyStaff)){
  2784. $endStaffArray=end($verifyStaff);
  2785. // if ($v[0]==$endStaffArray['nextStaff']){
  2786. // $roleId=$v[0];
  2787. // }
  2788. }
  2789. $roleVerify=json_decode($v[3],true);
  2790. $roleKey=$k;$roleArray=array();
  2791. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2792. foreach ($roleVerify as $o=>$p){
  2793. $staffID=explode ('_',$p);
  2794. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2795. //print_r($staffID);
  2796. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2797. array_push($roleArray, $exp);
  2798. }
  2799. $roleArrayCopy[$v[0]]=$roleArray;
  2800. //$verifyList[$k]['roleArray']=$roleArray;
  2801. }
  2802. $verifyList[$k]['date']="";
  2803. $verifyList[$k]['opinion']="";
  2804. $verifyList[$k]['status']="";
  2805. if (empty($verifyStaff)){
  2806. $verifyList[$k]['date']="";
  2807. $verifyList[$k]['opinion']="";
  2808. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2809. $verifyList[$k]['status']=4;
  2810. $flag=false;
  2811. }
  2812. }else{
  2813. foreach ($verifyStaff as $m=>$u){
  2814. if ($v[0]==$m){
  2815. $verifyList[$k]['date']=$u['date'];
  2816. $verifyList[$k]['opinion']=$u['opinion'];
  2817. $verifyList[$k]['status']=$u['status'];
  2818. $flag=false;
  2819. break;
  2820. }
  2821. }
  2822. $endStaffArray=end($verifyStaff);
  2823. if (isset($endStaffArray['ROLE'])){
  2824. }else{
  2825. // $endKey=key($verifyStaff);
  2826. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2827. // $button=4;
  2828. // $verifyList[$k]['status']=4;
  2829. // }
  2830. }
  2831. }
  2832. }
  2833. $rolename['name']='';
  2834. if (!empty($roleId)){
  2835. Doo::loadModel('role');
  2836. $role=new role();
  2837. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2838. }
  2839. if (!empty($verifyStaff))
  2840. $endStaffArray=end($verifyStaff);
  2841. $KOP=false;
  2842. foreach ($roleArrayCopy as $P=>$A){
  2843. foreach ( $A as $MKI=>$AVL){
  2844. if (!empty($verifyStaff)){
  2845. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2846. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2847. $button=4;
  2848. $roleArrayCopy[$P][$MKI]['status']=4;
  2849. }
  2850. foreach ($verifyStaff as $m=>$u){
  2851. $AVLFK=$AVL[0].'_R';
  2852. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2853. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  2854. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  2855. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  2856. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  2857. break;
  2858. }
  2859. }
  2860. }else{
  2861. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  2862. $button=4;
  2863. $roleArrayCopy[$P][$MKI]['status']=4;
  2864. }
  2865. }
  2866. //$roleArray[$MKI]['rolename']=$rolename['name'];
  2867. $KOP=true;
  2868. }
  2869. }
  2870. foreach ($roleArrayCopy as $k=>$v){
  2871. foreach ($verifyList as $m=>$n){
  2872. if ($n[0]==$k){
  2873. array_splice($verifyList,$m,1,$v);
  2874. }
  2875. }
  2876. }
  2877. $loanList[$key]['verifyList']=$verifyList;
  2878. $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  2879. }
  2880. $data['loanList']=$loanList;
  2881. $Locate=0;$roleId=0;$button=0;
  2882. foreach ($receiptList as $key=>$value){
  2883. $button2=0;
  2884. $receiptList[$key]['Locate']=$Locate;$Locate++;
  2885. $receiptList[$key]['reviseDetail']=array();
  2886. if (!empty($value['reviseDetail']))
  2887. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  2888. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  2889. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  2890. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  2891. $receiptList[$key]['category']=$categoryDetil['title'];
  2892. $executeList=json_decode($value['executeCopy'],true);
  2893. $executeStaff=array();
  2894. if (!empty($value['executeStaff'] ))
  2895. $executeStaff=json_decode($value['executeStaff'],true);
  2896. if (isset($executeList)){
  2897. foreach ($executeList as $op=>$lo){
  2898. $executeList[$op]['date']="";
  2899. $executeList[$op]['opinion']="";
  2900. $executeList[$op]['status']="";
  2901. foreach ($executeStaff as $m=>$u){
  2902. if ($lo[0]==$m){
  2903. $executeList[$op]['date']=$u['date'];
  2904. $executeList[$op]['opinion']=$u['opinion'];
  2905. $executeList[$op]['status']=$u['status'];
  2906. break;
  2907. }
  2908. }
  2909. if ($this->staff[0]['sid']==$lo[0]&&empty($executeList[$op]['status'])){
  2910. $button2=1;
  2911. $executeList[$op]['status']=4;
  2912. }
  2913. }
  2914. }
  2915. //检测编辑状态
  2916. if ($value['status']==3||$value['status']==1||$value['status']==9){
  2917. $verifyList['staff']=$value['verifyBreakup'];
  2918. }else
  2919. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  2920. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  2921. $verifyStaff=json_decode($value['verifyStaff'],true);
  2922. Doo::loadModel('role');
  2923. $role=new role();
  2924. if ($verifyList==NULL)
  2925. $verifyList=array();
  2926. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  2927. foreach ($verifyList as $k=>$v){
  2928. //init verifyStaff
  2929. if ($v[1]=='ROLE'){
  2930. if (!empty($verifyStaff)){
  2931. $endStaffArray=end($verifyStaff);
  2932. // if ($v[0]==$endStaffArray['nextStaff']){
  2933. // $roleId=$v[0];
  2934. // }
  2935. }
  2936. $roleVerify=json_decode($v[3],true);
  2937. $roleKey=$k;$roleArray=array();
  2938. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  2939. foreach ($roleVerify as $o=>$p){
  2940. $staffID=explode ('_',$p);
  2941. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  2942. //print_r($staffID);
  2943. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  2944. array_push($roleArray, $exp);
  2945. }
  2946. $roleArrayCopy[$v[0]]=$roleArray;
  2947. //$verifyList[$k]['roleArray']=$roleArray;
  2948. }
  2949. $verifyList[$k]['date']="";
  2950. $verifyList[$k]['opinion']="";
  2951. $verifyList[$k]['status']="";
  2952. if (empty($verifyStaff)){
  2953. $verifyList[$k]['date']="";
  2954. $verifyList[$k]['opinion']="";
  2955. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  2956. $verifyList[$k]['status']=4;
  2957. $flag=false;
  2958. }
  2959. }else{
  2960. foreach ($verifyStaff as $m=>$u){
  2961. if ($v[0]==$m){
  2962. $verifyList[$k]['date']=$u['date'];
  2963. $verifyList[$k]['opinion']=$u['opinion'];
  2964. $verifyList[$k]['status']=$u['status'];
  2965. $flag=false;
  2966. break;
  2967. }
  2968. }
  2969. $endStaffArray=end($verifyStaff);
  2970. if (isset($endStaffArray['ROLE'])){
  2971. }else{
  2972. // $endKey=key($verifyStaff);
  2973. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2974. // $button=4;
  2975. // $verifyList[$k]['status']=4;
  2976. // }
  2977. }
  2978. }
  2979. }
  2980. $rolename['name']='';
  2981. if (!empty($roleId)){
  2982. Doo::loadModel('role');
  2983. $role=new role();
  2984. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  2985. }
  2986. if (!empty($verifyStaff))
  2987. $endStaffArray=end($verifyStaff);
  2988. $KOP=false;
  2989. foreach ($roleArrayCopy as $P=>$A){
  2990. foreach ( $A as $MKI=>$AVL){
  2991. if (!empty($verifyStaff)){
  2992. //&&$rolename['rid']==$endStaffArray['nextStaff']
  2993. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  2994. $button=4;
  2995. $roleArrayCopy[$P][$MKI]['status']=4;
  2996. }
  2997. foreach ($verifyStaff as $m=>$u){
  2998. $AVLFK=$AVL[0].'_R';
  2999. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3000. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3001. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3002. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3003. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3004. break;
  3005. }
  3006. }
  3007. }else{
  3008. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3009. $button=4;
  3010. $roleArrayCopy[$P][$MKI]['status']=4;
  3011. }
  3012. }
  3013. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3014. $KOP=true;
  3015. }
  3016. }
  3017. foreach ($roleArrayCopy as $k=>$v){
  3018. foreach ($verifyList as $m=>$n){
  3019. if ($n[0]==$k){
  3020. array_splice($verifyList,$m,1,$v);
  3021. }
  3022. }
  3023. }
  3024. $receiptList[$key]['verifyList']=$verifyList;
  3025. $receiptList[$key]['executeList']=$executeList;
  3026. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3027. $receiptList[$key]['button2']=$button2;
  3028. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3029. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3030. $relust=$value['sum']-$value['loanSum'];
  3031. $receiptList[$key]['relust']=$relust;
  3032. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3033. }
  3034. //print_r($receiptList[$key]['executeList']);
  3035. $data['receiptList']=$receiptList;
  3036. $data['memu']="receipt";
  3037. $data['staff']=$this->staff;
  3038. $data['receiptMemu']='implement';
  3039. $data['verifyId']=$this->verifyId;
  3040. $data['executeId']=$this->executeId;
  3041. $this->render ( "/admin/implement", $data );
  3042. }
  3043. function implementDo(){
  3044. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3045. $implementOpinions=$this->get_args('opinion')?$this->get_args('opinion'):"";
  3046. if (!empty($rid)){
  3047. Doo::loadModel('receipt');
  3048. $receipt=new receipt();
  3049. $rinfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  3050. $executeCopy=json_decode($rinfo['executeCopy'],true);
  3051. $executeStaff=json_decode($rinfo['executeStaff'],true);
  3052. if(empty($executeStaff)){
  3053. $executeStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1));
  3054. }else{
  3055. $executeStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$implementOpinions,'status'=>1);
  3056. }
  3057. if (count($executeStaff)==count($executeCopy)){
  3058. $receipt->executeStaff=json_encode($executeStaff);
  3059. $receipt->status=8;
  3060. if ($rinfo['Rtype']==1&&$rinfo['isBK']==1&&$rinfo['status']==1)
  3061. $receipt->status=9;
  3062. $receipt->executeDate= date("Y-m-d");
  3063. }else{
  3064. $receipt->executeStaff=json_encode($executeStaff);
  3065. }
  3066. $receipt->update(array('where'=>'rid='.$rid));
  3067. }
  3068. return "/implement";
  3069. }
  3070. function receiptburEdi(){
  3071. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  3072. $status=isset($this->params['status'])?$this->params['status']:'';
  3073. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  3074. $month=$this->get_args('month')?$this->get_args('month'):"";
  3075. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  3076. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  3077. if (empty($status))
  3078. $status=$this->get_args('status')?$this->get_args('status'):2;
  3079. $vidList=array();
  3080. $button=0;
  3081. Doo::loadModel('verify');
  3082. Doo::loadModel('receipt');
  3083. Doo::loadModel('staff');
  3084. $staff=new staff();
  3085. $receipt=new receipt();
  3086. $verify=new verify();
  3087. Doo::loadModel('L_category');
  3088. $Lcategory=new L_category();
  3089. Doo::loadModel('enclosur');
  3090. $enclosur=new enclosur();
  3091. Doo::loadModel('loanReceipt');
  3092. $loanReceipt=new loanReceipt();
  3093. //user verify ID
  3094. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  3095. foreach ($verifyDetail as $key=>$value){
  3096. array_push($vidList, $value['vid']);
  3097. }
  3098. $vid=implode(",", $vidList);
  3099. if(empty($verifyDetail))
  3100. $vid=0;
  3101. $categoryList=$Lcategory->find(array('asArray'=>true));
  3102. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  3103. $ap="";
  3104. if($status==4){
  3105. $ap=4;$status=2;
  3106. }
  3107. //get Receipt By verifyID status 2
  3108. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  3109. $loanList=$loanReceipt->find(array('where'=>'rid='.$receiptList[0]['loanRid'],'desc'=>'rid','asArray'=>true));
  3110. $Locate=0;$roleId=0;$button=0;
  3111. foreach ($loanList as $key=>$value){
  3112. $loanList[$key]['Locate']=$Locate;$Locate++;
  3113. $loanList[$key]['reviseDetail']=array();
  3114. if (!empty($value['reviseDetail']))
  3115. $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3116. $loanList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3117. $loanList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3118. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3119. $loanList[$key]['category']=$categoryDetil['title'];
  3120. //检测编辑状态
  3121. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3122. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3123. $verifyStaff=json_decode($value['verifyStaff'],true);
  3124. Doo::loadModel('role');
  3125. $role=new role();
  3126. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3127. foreach ($verifyList as $k=>$v){
  3128. //init verifyStaff
  3129. if ($v[1]=='ROLE'){
  3130. if (!empty($verifyStaff)){
  3131. $endStaffArray=end($verifyStaff);
  3132. }
  3133. $roleVerify=json_decode($v[3],true);
  3134. $roleKey=$k;$roleArray=array();
  3135. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3136. foreach ($roleVerify as $o=>$p){
  3137. $staffID=explode ('_',$p);
  3138. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3139. //print_r($staffID);
  3140. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3141. array_push($roleArray, $exp);
  3142. }
  3143. $roleArrayCopy[$v[0]]=$roleArray;
  3144. //$verifyList[$k]['roleArray']=$roleArray;
  3145. }
  3146. $verifyList[$k]['date']="";
  3147. $verifyList[$k]['opinion']="";
  3148. $verifyList[$k]['status']="";
  3149. if (empty($verifyStaff)){
  3150. $verifyList[$k]['date']="";
  3151. $verifyList[$k]['opinion']="";
  3152. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3153. $verifyList[$k]['status']=4;
  3154. $flag=false;
  3155. }
  3156. }else{
  3157. foreach ($verifyStaff as $m=>$u){
  3158. if ($v[0]==$m){
  3159. $verifyList[$k]['date']=$u['date'];
  3160. $verifyList[$k]['opinion']=$u['opinion'];
  3161. $verifyList[$k]['status']=$u['status'];
  3162. $flag=false;
  3163. break;
  3164. }
  3165. }
  3166. $endStaffArray=end($verifyStaff);
  3167. if (isset($endStaffArray['ROLE'])){
  3168. }else{
  3169. }
  3170. }
  3171. }
  3172. $rolename['name']='';
  3173. if (!empty($roleId)){
  3174. Doo::loadModel('role');
  3175. $role=new role();
  3176. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3177. }
  3178. if (!empty($verifyStaff))
  3179. $endStaffArray=end($verifyStaff);
  3180. $KOP=false;
  3181. foreach ($roleArrayCopy as $P=>$A){
  3182. foreach ( $A as $MKI=>$AVL){
  3183. if (!empty($verifyStaff)){
  3184. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3185. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3186. $button=4;
  3187. $roleArrayCopy[$P][$MKI]['status']=4;
  3188. }
  3189. foreach ($verifyStaff as $m=>$u){
  3190. $AVLFK=$AVL[0].'_R';
  3191. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3192. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3193. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3194. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3195. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3196. break;
  3197. }
  3198. }
  3199. }else{
  3200. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3201. $button=4;
  3202. $roleArrayCopy[$P][$MKI]['status']=4;
  3203. }
  3204. }
  3205. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3206. $KOP=true;
  3207. }
  3208. }
  3209. foreach ($roleArrayCopy as $k=>$v){
  3210. foreach ($verifyList as $m=>$n){
  3211. if ($n[0]==$k){
  3212. array_splice($verifyList,$m,1,$v);
  3213. }
  3214. }
  3215. }
  3216. $loanList[$key]['verifyList']=$verifyList;
  3217. }
  3218. $htmlLoan='';
  3219. if (isset($loanList[0])){
  3220. foreach ($loanList[0]['verifyList'] as $key=>$value){
  3221. if ($value['status']==1)
  3222. $htmlLoan.='<li class="done" >';
  3223. elseif ($value['status']==3)
  3224. $htmlLoan.='<li class="undone" >';
  3225. $htmlLoan.='<div class="avtra"><img src="'.$value[2].'_2.jpg"></div>';
  3226. $htmlLoan.='<div class="comment"><p class="colGray">'.$value['1'].'<span class="fR">'.$value['date'].'</span>';
  3227. if (isset($value['rolename']))
  3228. $htmlLoan.=$value['rolename'];
  3229. $htmlLoan.='</p><p>'.$value['opinion'].'</p></div></li>';
  3230. }
  3231. $data['loanDate']=$loanList[0]['date'];
  3232. }
  3233. $data['htmlLoan']=$htmlLoan;
  3234. //print_r($loanList);
  3235. $Locate=0;$roleId=0;$button=0;
  3236. if($ap==4)
  3237. $status=4;
  3238. foreach ($receiptList as $key=>$value){
  3239. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3240. $receiptList[$key]['reviseDetail']=array();
  3241. if (!empty($value['reviseDetail']))
  3242. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3243. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3244. $receiptList[$key]['loanItem']=json_decode($value['loanItem'],true);
  3245. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3246. $receiptList[$key]['category']=$categoryDetil['title'];
  3247. //检测编辑状态
  3248. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3249. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3250. $verifyStaff=json_decode($value['verifyStaff'],true);
  3251. Doo::loadModel('role');
  3252. $role=new role();
  3253. //print_r($verifyList);
  3254. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3255. foreach ($verifyList as $k=>$v){
  3256. //init verifyStaff
  3257. if ($v[1]=='ROLE'){
  3258. if (!empty($verifyStaff)){
  3259. $endStaffArray=end($verifyStaff);
  3260. if ($v[0]==$endStaffArray['nextStaff']){
  3261. $roleId=$v[0];
  3262. }
  3263. }
  3264. $roleVerify=json_decode($v[3],true);
  3265. $roleKey=$k;$roleArray=array();
  3266. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3267. foreach ($roleVerify as $o=>$p){
  3268. $staffID=explode ('_',$p);
  3269. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3270. //print_r($staffID);
  3271. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3272. array_push($roleArray, $exp);
  3273. }
  3274. $roleArrayCopy[$v[0]]=$roleArray;
  3275. //$verifyList[$k]['roleArray']=$roleArray;
  3276. }
  3277. //print_r($roleArray);
  3278. $verifyList[$k]['date']="";
  3279. $verifyList[$k]['opinion']="";
  3280. $verifyList[$k]['status']="";
  3281. if (empty($verifyStaff)){
  3282. $verifyList[$k]['date']="";
  3283. $verifyList[$k]['opinion']="";
  3284. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3285. $verifyList[$k]['status']=4;
  3286. $button=4;$flag=false;
  3287. }
  3288. }else{
  3289. foreach ($verifyStaff as $m=>$u){
  3290. if ($v[0]==$m){
  3291. $verifyList[$k]['date']=$u['date'];
  3292. $verifyList[$k]['opinion']=$u['opinion'];
  3293. $verifyList[$k]['status']=$u['status'];
  3294. $flag=false;
  3295. break;
  3296. }
  3297. }
  3298. $endStaffArray=end($verifyStaff);
  3299. if (isset($endStaffArray['ROLE'])){
  3300. }else{
  3301. $endKey=key($verifyStaff);
  3302. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3303. $button=4;
  3304. $verifyList[$k]['status']=4;
  3305. }
  3306. }
  3307. }
  3308. }
  3309. $rolename['name']='';
  3310. if (!empty($roleId)){
  3311. Doo::loadModel('role');
  3312. $role=new role();
  3313. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3314. }
  3315. if (!empty($verifyStaff))
  3316. $endStaffArray=end($verifyStaff);
  3317. $KOP=false;
  3318. foreach ($roleArrayCopy as $P=>$A){
  3319. foreach ( $A as $MKI=>$AVL){
  3320. if (!empty($verifyStaff)){
  3321. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3322. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3323. $button=4;
  3324. $roleArrayCopy[$P][$MKI]['status']=4;
  3325. }
  3326. foreach ($verifyStaff as $m=>$u){
  3327. $AVLFK=$AVL[0].'_R';
  3328. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3329. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3330. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3331. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3332. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3333. break;
  3334. }
  3335. }
  3336. }else{
  3337. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3338. $button=4;
  3339. $roleArrayCopy[$P][$MKI]['status']=4;
  3340. }
  3341. }
  3342. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3343. $KOP=true;
  3344. }
  3345. }
  3346. foreach ($roleArrayCopy as $k=>$v){
  3347. foreach ($verifyList as $m=>$n){
  3348. if ($n[0]==$k){
  3349. array_splice($verifyList,$m,1,$v);
  3350. }
  3351. }
  3352. }
  3353. //print_r($verifyList);
  3354. $receiptList[$key]['verifyList']=$verifyList;
  3355. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3356. $receiptList[$key]['button']=$button;
  3357. $receiptList[$key]['loanSumCN']=$this->num_to_rmb($value['loanSum']);
  3358. $receiptList[$key]['sumCN']=$this->num_to_rmb($value['sum']);
  3359. $relust=$value['sum']-$value['loanSum'];
  3360. $receiptList[$key]['relust']=$relust;
  3361. $receiptList[$key]['relustCN']=$this->num_to_rmb($relust);
  3362. }
  3363. //print_r($receiptList);die;
  3364. //$data['verifyDetail']=$verifyDetail;
  3365. $mothHtml="";
  3366. for($i=1;$i<=12;$i++){
  3367. if($month==$i)
  3368. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3369. else
  3370. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3371. }
  3372. //获取审批日志
  3373. Doo::loadModel('receiptLog');
  3374. $receiptLog=new receiptLog();
  3375. $rlList=array();
  3376. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  3377. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  3378. if (!empty($rlInfo)){
  3379. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  3380. }
  3381. //echo $rid;
  3382. //print_r($receiptList);
  3383. $receiptList[0]['rlList']=$rlList;
  3384. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  3385. $enclosurHtml='';
  3386. foreach ($enclosurList as $value){
  3387. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  3388. }
  3389. $data['enclosurHtml']=$enclosurHtml;
  3390. $data['rolename']=$rolename['name'];
  3391. // $data['datetij']=$tijdate['date'];
  3392. $data['mothHtml']=$mothHtml;
  3393. //print_r($receiptList);
  3394. $data['rid']=$rid;
  3395. $data['tijdate']=$tijdate['date'];
  3396. $data['receiptList']=$receiptList;
  3397. $data['receiptApprovalCount']=count($receiptList);
  3398. $data['status']=$status;
  3399. $data['year']=$year;
  3400. $data['categoryList']=$categoryList;
  3401. $data['staffList']=$staffList;
  3402. $data['cid']=$cid;
  3403. $data['sid']=$sid;
  3404. $data['ap']=$ap;
  3405. $data['memu']="receipt";
  3406. $data['staff']=$this->staff;
  3407. $data['receiptMemu']='approvalExpenses';
  3408. $data['verifyId']=$this->verifyId;
  3409. $data['executeId']=$this->executeId;
  3410. $this->render ( "/admin/receiptburEdi", $data );
  3411. }
  3412. function hisImplement(){
  3413. $item=isset($this->params['item'])?$this->params['item']:"";
  3414. if(empty($item))
  3415. $item=$this->get_args('item')?$this->get_args('item'):"";
  3416. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3417. $moth=$this->get_args('moth')?$this->get_args('moth'):date("m");
  3418. $day=$this->get_args('day')?$this->get_args('day'):date("d");
  3419. $sop=$this->get_args('sop')?$this->get_args('sop'):'SOP';
  3420. Doo::loadModel('receipt');
  3421. $receipt=new receipt();
  3422. Doo::loadModel('L_category');
  3423. $Lcategory=new L_category();
  3424. Doo::loadModel('verify');
  3425. Doo::loadModel('statistics');
  3426. $statistics=new statistics();
  3427. $verify=new verify();
  3428. Doo::loadModel('staff');
  3429. $staff=new staff();
  3430. $condition="";
  3431. if($item=="expenses")
  3432. $condition=" and Rtype=1 ";
  3433. elseif ($item=="receipts")
  3434. $condition=" and Rtype=0 ";
  3435. elseif ($item=="remits")
  3436. $condition=" and Rtype=2 ";
  3437. $sopString="";
  3438. $dateCondition=" and Year(executeDate) =".$year;
  3439. if($moth!='MONTH'){
  3440. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth;
  3441. }
  3442. if($day!='DAY')
  3443. $dateCondition=" and Year(executeDate) =".$year." and Month(executeDate) = ".$moth." and day(executeDate)=".$day;
  3444. if ($sop!='SOP')
  3445. $sopString=" and staff=".$sop;
  3446. //$noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3447. $receiptList=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition.$sopString,'desc'=>'rid','asArray'=>true));
  3448. //员工筛选
  3449. $receiptList2=$receipt->find(array('where'=>' (status=8 or status=9 )'.$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3450. $sopStaff=array();
  3451. foreach ($receiptList2 as $key=>$value){
  3452. $staffDetail=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3453. $sopStaff[$value['staff']]=$staffDetail['username'];
  3454. }
  3455. $Locate=0;$roleId=0;$button=0;
  3456. foreach ($receiptList as $key=>$value){
  3457. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3458. $receiptList[$key]['reviseDetail']=array();
  3459. if (!empty($value['reviseDetail']))
  3460. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3461. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3462. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3463. $receiptList[$key]['category']=$categoryDetil['title'];
  3464. //检测编辑状态
  3465. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3466. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3467. $verifyStaff=json_decode($value['verifyStaff'],true);
  3468. Doo::loadModel('role');
  3469. $role=new role();
  3470. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3471. foreach ($verifyList as $k=>$v){
  3472. //init verifyStaff
  3473. if ($v[1]=='ROLE'){
  3474. if (!empty($verifyStaff)){
  3475. $endStaffArray=end($verifyStaff);
  3476. }
  3477. $roleVerify=json_decode($v[3],true);
  3478. $roleKey=$k;$roleArray=array();
  3479. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3480. foreach ($roleVerify as $o=>$p){
  3481. $staffID=explode ('_',$p);
  3482. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3483. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3484. array_push($roleArray, $exp);
  3485. }
  3486. $roleArrayCopy[$v[0]]=$roleArray;
  3487. }
  3488. $verifyList[$k]['date']="";
  3489. $verifyList[$k]['opinion']="";
  3490. $verifyList[$k]['status']="";
  3491. if (empty($verifyStaff)){
  3492. $verifyList[$k]['date']="";
  3493. $verifyList[$k]['opinion']="";
  3494. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3495. $verifyList[$k]['status']=4;
  3496. $flag=false;
  3497. }
  3498. }else{
  3499. foreach ($verifyStaff as $m=>$u){
  3500. if ($v[0]==$m){
  3501. $verifyList[$k]['date']=$u['date'];
  3502. $verifyList[$k]['opinion']=$u['opinion'];
  3503. $verifyList[$k]['status']=$u['status'];
  3504. $flag=false;
  3505. break;
  3506. }
  3507. }
  3508. $endStaffArray=end($verifyStaff);
  3509. }
  3510. }
  3511. $rolename['name']='';
  3512. if (!empty($roleId)){
  3513. Doo::loadModel('role');
  3514. $role=new role();
  3515. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3516. }
  3517. if (!empty($verifyStaff))
  3518. $endStaffArray=end($verifyStaff);
  3519. $KOP=false;
  3520. foreach ($roleArrayCopy as $P=>$A){
  3521. foreach ( $A as $MKI=>$AVL){
  3522. if (!empty($verifyStaff)){
  3523. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3524. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3525. $button=4;
  3526. $roleArrayCopy[$P][$MKI]['status']=4;
  3527. }
  3528. foreach ($verifyStaff as $m=>$u){
  3529. $AVLFK=$AVL[0].'_R';
  3530. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3531. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3532. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3533. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3534. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3535. break;
  3536. }
  3537. }
  3538. }else{
  3539. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3540. $button=4;
  3541. $roleArrayCopy[$P][$MKI]['status']=4;
  3542. }
  3543. }
  3544. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3545. $KOP=true;
  3546. }
  3547. }
  3548. foreach ($roleArrayCopy as $k=>$v){
  3549. foreach ($verifyList as $m=>$n){
  3550. if ($n[0]==$k){
  3551. array_splice($verifyList,$m,1,$v);
  3552. }
  3553. }
  3554. }
  3555. $receiptList[$key]['verifyList']=$verifyList;
  3556. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3557. $receiptList[$key]['button']=$button;
  3558. }
  3559. //print_r($sopStaff);
  3560. $mothHtml="";
  3561. for($i=1;$i<=12;$i++){
  3562. if($moth==$i)
  3563. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3564. else
  3565. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3566. }
  3567. $dayHtml="";
  3568. if ($day!="DAY"||$moth!="MONTH"){
  3569. for($i = 1; $i <= 31; $i ++) {
  3570. if($day==$i)
  3571. $dayHtml.='<option value="'.$i.'" selected >'.$i.'日</option>';
  3572. else
  3573. $dayHtml.='<option value="'.$i.'" >'.$i.'日</option>';
  3574. }
  3575. }
  3576. $sopHtml="";
  3577. foreach ($sopStaff as $key=>$value){
  3578. if($sop==$key)
  3579. $sopHtml.='<option value="'.$key.'" selected >'.$value.'</option>';
  3580. else
  3581. $sopHtml.='<option value="'.$key.'" >'.$value.'</option>';
  3582. }
  3583. $data['sopHtml']=$sopHtml;
  3584. $data['dayHtml']=$dayHtml;
  3585. $data['mothHtml']=$mothHtml;
  3586. $data['receiptList']=$receiptList;
  3587. $data['memu']="receipt";
  3588. $data['staff']=$this->staff;
  3589. $data['receiptMemu']='implement';
  3590. $data['verifyId']=$this->verifyId;
  3591. $data['executeId']=$this->executeId;
  3592. $data['item']=$item;
  3593. $data['year']=$year;
  3594. $data['moth']=$moth;
  3595. $data['day']=$day;
  3596. $data['sop']=$sop;
  3597. $this->render ( "/admin/hisImplement", $data );
  3598. }
  3599. function ajaxExamine(){
  3600. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  3601. Doo::loadModel('receipt');
  3602. $receipt=new receipt();
  3603. if (!empty($rid)){
  3604. $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
  3605. ,'asArray'=>true));
  3606. echo json_encode(array('status'=>1,'receipt'=>$rLRes[0]));die;
  3607. }
  3608. echo json_encode(array('status'=>0,'receipt'=>array()));die;
  3609. }
  3610. /*
  3611. * 废弃
  3612. */
  3613. function myReceipt(){
  3614. //all approval past withdraw
  3615. $item=isset($this->params['item'])?$this->params['item']:"";
  3616. if(empty($item))
  3617. $item=$this->get_args('item')?$this->get_args('item'):"";
  3618. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  3619. $moth=$this->get_args('moth')?$this->get_args('moth'):"";
  3620. Doo::loadModel('receipt');
  3621. $receipt=new receipt();
  3622. //pre-loaded
  3623. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3624. //have cache
  3625. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year.".htmls";
  3626. if(!empty($moth))//yearPage
  3627. $path=SITE_PATH.$this->MYREVEIPTCACHEPATH.$item."_".$year."_".$moth.".htmls";
  3628. $this->showCache($path);
  3629. }
  3630. Doo::loadModel('L_category');
  3631. $Lcategory=new L_category();
  3632. Doo::loadModel('verify');
  3633. Doo::loadModel('statistics');
  3634. $statistics=new statistics();
  3635. $verify=new verify();
  3636. Doo::loadModel('staff');
  3637. $staff=new staff();
  3638. $condition=" and status!=0 ";
  3639. if($item=="approval")
  3640. $condition=" and status=2 ";
  3641. elseif ($item=="withdraw")
  3642. $condition=" and status=3 ";
  3643. elseif ($item=="past")
  3644. $condition=" and status=1 ";
  3645. elseif ($item=="whdw")
  3646. $condition=" and status=4 ";
  3647. $dateCondition=" and Year(date) =".$year;
  3648. if(!empty($moth)){
  3649. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$moth;
  3650. $stList=$statistics->getOne(array('select'=>'rePrice ,agPrice','where'=>' staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  3651. }else
  3652. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  3653. if(empty($stList))
  3654. $stList=array('rePrice'=>0,'agPrice'=>0);
  3655. $noPassSum=$receipt->receiptByYear($year,$this->staff[0]['sid']);
  3656. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']-$noPassSum['sum']));
  3657. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].$condition.$dateCondition,'desc'=>'rid','asArray'=>true));
  3658. $Locate=0;$roleId=0;$button=0;
  3659. foreach ($receiptList as $key=>$value){
  3660. $receiptList[$key]['Locate']=$Locate;$Locate++;
  3661. $receiptList[$key]['reviseDetail']=array();
  3662. if (!empty($value['reviseDetail']))
  3663. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  3664. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  3665. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  3666. $receiptList[$key]['category']=$categoryDetil['title'];
  3667. //检测编辑状态
  3668. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  3669. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  3670. $verifyStaff=json_decode($value['verifyStaff'],true);
  3671. Doo::loadModel('role');
  3672. $role=new role();
  3673. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  3674. foreach ($verifyList as $k=>$v){
  3675. //init verifyStaff
  3676. if ($v[1]=='ROLE'){
  3677. if (!empty($verifyStaff)){
  3678. $endStaffArray=end($verifyStaff);
  3679. // if ($v[0]==$endStaffArray['nextStaff']){
  3680. // $roleId=$v[0];
  3681. // }
  3682. }
  3683. $roleVerify=json_decode($v[3],true);
  3684. $roleKey=$k;$roleArray=array();
  3685. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  3686. foreach ($roleVerify as $o=>$p){
  3687. $staffID=explode ('_',$p);
  3688. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  3689. //print_r($staffID);
  3690. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  3691. array_push($roleArray, $exp);
  3692. }
  3693. $roleArrayCopy[$v[0]]=$roleArray;
  3694. //$verifyList[$k]['roleArray']=$roleArray;
  3695. }
  3696. $verifyList[$k]['date']="";
  3697. $verifyList[$k]['opinion']="";
  3698. $verifyList[$k]['status']="";
  3699. if (empty($verifyStaff)){
  3700. $verifyList[$k]['date']="";
  3701. $verifyList[$k]['opinion']="";
  3702. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  3703. $verifyList[$k]['status']=4;
  3704. $flag=false;
  3705. }
  3706. }else{
  3707. foreach ($verifyStaff as $m=>$u){
  3708. if ($v[0]==$m){
  3709. $verifyList[$k]['date']=$u['date'];
  3710. $verifyList[$k]['opinion']=$u['opinion'];
  3711. $verifyList[$k]['status']=$u['status'];
  3712. $flag=false;
  3713. break;
  3714. }
  3715. }
  3716. $endStaffArray=end($verifyStaff);
  3717. if (isset($endStaffArray['ROLE'])){
  3718. }else{
  3719. // $endKey=key($verifyStaff);
  3720. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3721. // $button=4;
  3722. // $verifyList[$k]['status']=4;
  3723. // }
  3724. }
  3725. }
  3726. }
  3727. $rolename['name']='';
  3728. if (!empty($roleId)){
  3729. Doo::loadModel('role');
  3730. $role=new role();
  3731. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  3732. }
  3733. if (!empty($verifyStaff))
  3734. $endStaffArray=end($verifyStaff);
  3735. $KOP=false;
  3736. foreach ($roleArrayCopy as $P=>$A){
  3737. foreach ( $A as $MKI=>$AVL){
  3738. if (!empty($verifyStaff)){
  3739. //&&$rolename['rid']==$endStaffArray['nextStaff']
  3740. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  3741. $button=4;
  3742. $roleArrayCopy[$P][$MKI]['status']=4;
  3743. }
  3744. foreach ($verifyStaff as $m=>$u){
  3745. $AVLFK=$AVL[0].'_R';
  3746. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3747. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  3748. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  3749. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  3750. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  3751. break;
  3752. }
  3753. }
  3754. }else{
  3755. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  3756. $button=4;
  3757. $roleArrayCopy[$P][$MKI]['status']=4;
  3758. }
  3759. }
  3760. //$roleArray[$MKI]['rolename']=$rolename['name'];
  3761. $KOP=true;
  3762. }
  3763. }
  3764. foreach ($roleArrayCopy as $k=>$v){
  3765. foreach ($verifyList as $m=>$n){
  3766. if ($n[0]==$k){
  3767. array_splice($verifyList,$m,1,$v);
  3768. }
  3769. }
  3770. }
  3771. $receiptList[$key]['verifyList']=$verifyList;
  3772. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  3773. $receiptList[$key]['button']=$button;
  3774. }
  3775. //print_r($receiptList);die;
  3776. $mothHtml="";
  3777. for($i=1;$i<=12;$i++){
  3778. if($moth==$i)
  3779. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  3780. else
  3781. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  3782. }
  3783. $data['mothHtml']=$mothHtml;
  3784. $data['receiptList']=$receiptList;
  3785. $data['memu']="receipt";
  3786. $data['staff']=$this->staff;
  3787. $data['receiptMemu']='receipt';
  3788. $data['verifyId']=$this->verifyId;
  3789. $data['executeId']=$this->executeId;
  3790. $data['item']=$item;
  3791. $data['year']=$year;
  3792. if(!empty($item)&&($item=="past"||$item=="withdraw")){
  3793. //sufficient condition to generate cache
  3794. if(empty($moth)&&($year<date("Y"))){
  3795. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  3796. if(empty($receiptList)){ //generated files
  3797. ob_start();
  3798. $this->render ( "/admin/saea_myList", $data );
  3799. $this->cacheFile($path);die;
  3800. // $content = ob_get_contents();
  3801. // $fp = fopen($path, "w");
  3802. // fwrite($fp, $content);
  3803. // fclose($fp);
  3804. }
  3805. }elseif (!empty($moth)&&($year<=date("Y"))&&($moth<date("m"))){
  3806. $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));
  3807. if(empty($receiptList)){ //generated files
  3808. ob_start();
  3809. $this->render ( "/admin/saea_myList", $data );
  3810. $this->cacheFile($path);die;
  3811. }
  3812. }
  3813. }
  3814. $this->render ( "/admin/saea_myList", $data );
  3815. }
  3816. function saeaCreate(){
  3817. Doo::loadModel('accountItem');
  3818. Doo::loadModel('verify');
  3819. Doo::loadModel('receipt');
  3820. Doo::loadModel('L_category');
  3821. $lCategory=new L_category();
  3822. $receipt=new receipt();
  3823. $verify=new verify();
  3824. $accountItem=new accountItem();
  3825. Doo::loadModel("role");
  3826. $role=new role();
  3827. $acItem=$accountItem->find(array('asArray'=>true));
  3828. $veList=$verify->find(array('asArray'=>true));
  3829. foreach ($veList as $key=>$value){
  3830. $v=json_decode($value['staff']);
  3831. $list=array();
  3832. foreach ($v as $n=>$m){
  3833. if ($m['1']=='ROLE'){
  3834. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  3835. $v[$n][1]=$roleInfo['name'];
  3836. array_push($list, $roleInfo['name']);
  3837. }else{
  3838. array_push($list, $v[$n][1]);
  3839. }
  3840. }
  3841. $veList[$key]['staff']=implode('>', $list);
  3842. }
  3843. $data['category']=$lCategory->find(array('asArray'=>true));
  3844. $data['veList']=$veList;
  3845. $data['acItem']=$acItem;
  3846. $data['memu']="receipt";
  3847. $data['staff']=$this->staff;
  3848. $data['receiptMemu']='saeaBorad';
  3849. $data['verifyId']=$this->verifyId;
  3850. $data['executeId']=$this->executeId;
  3851. $this->render ( "/admin/saea_create", $data );
  3852. }
  3853. function addReceipt(){
  3854. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3855. $agency=$this->get_args('agency');
  3856. $travel=$this->get_args('travel');
  3857. $train=$this->get_args('train');
  3858. $other=$this->get_args('other');
  3859. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  3860. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  3861. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  3862. $enclosurName=$this->get_args('enclosurName')?$this->get_args('enclosurName'):"";
  3863. if(!empty($verify)&&!empty($cid)&&!empty($explanation)){
  3864. Doo::loadModel('receipt');
  3865. Doo::loadModel('receiptDetail');
  3866. Doo::loadModel('accountItem');
  3867. $accountItem=new accountItem();
  3868. $receipt=new receipt();
  3869. Doo::loadModel('enclosur');
  3870. Doo::loadModel('execute');
  3871. $execute=new execute();
  3872. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  3873. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  3874. // if(!empty($receiptDetail))
  3875. // return "/referReceipt/".$receiptDetail['rid'];
  3876. $aItem=$accountItem->find(array('asArray'=>true));
  3877. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  3878. $ag=$tr=$ta=$ot=0;
  3879. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  3880. foreach ($aItem as $key=>$value){
  3881. if ($value['category']==$this->AGENCY){
  3882. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  3883. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  3884. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  3885. }
  3886. $ag++;
  3887. }
  3888. if($value['category']==$this->TRAVEL){
  3889. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  3890. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  3891. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  3892. }
  3893. $tr++;
  3894. }
  3895. if($value['category']==$this->TRAIN){
  3896. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  3897. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  3898. $sum+=$train[$ta];$trainSum+=$train[$ta];
  3899. }
  3900. $ta++;
  3901. }
  3902. if($value['category']==$this->OTHER){
  3903. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  3904. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  3905. $sum+=$other[$ot];$otherSum+=$other[$ot];
  3906. }
  3907. $ot++;
  3908. }
  3909. }
  3910. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  3911. //报销单
  3912. $receipt->accountItem=json_encode($accountJson);
  3913. $receipt->staff=$this->staff[0]['sid'];
  3914. $receipt->sum=number_format($sum, 2, '.', '');
  3915. $receipt->date=date("Y-m-d");
  3916. $receipt->cid=$cid;
  3917. $receipt->status=5;
  3918. //修改审批流程加入角色
  3919. $receipt->verify=$verify;
  3920. $receipt->executeCopy=$executeDetail['staff'];
  3921. $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  3922. $receipt->explanation=$explanation;
  3923. $rid=$receipt->insert();
  3924. //附件
  3925. if (!empty($enclosurName)){
  3926. $enclosurArray=explode('-', $enclosurName);
  3927. foreach ($enclosurArray as $value){
  3928. $enclosur=new enclosur();
  3929. $enclosur->name=$value;
  3930. $enclosur->rid=$rid;
  3931. $enclosur->insert();
  3932. }
  3933. //print_r($enclosurArray);die;
  3934. }
  3935. //报销详情
  3936. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  3937. $receiptDetail=new receiptDetail();
  3938. $receiptDetail->staff=$this->staff[0]['sid'];
  3939. $receiptDetail->item=$value['name'];
  3940. $receiptDetail->itemCategory=$this->AGENCY;
  3941. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3942. $receiptDetail->date=date("Y-m-d");
  3943. $receiptDetail->cid=$cid;
  3944. $receiptDetail->rid=$rid;
  3945. $receiptDetail->status=4;
  3946. $receiptDetail->insert();
  3947. }
  3948. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  3949. $receiptDetail=new receiptDetail();
  3950. $receiptDetail->staff=$this->staff[0]['sid'];
  3951. $receiptDetail->item=$value['name'];
  3952. $receiptDetail->itemCategory=$this->TRAVEL;
  3953. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3954. $receiptDetail->date=date("Y-m-d");
  3955. $receiptDetail->cid=$cid;
  3956. $receiptDetail->rid=$rid;
  3957. $receiptDetail->status=4;
  3958. $receiptDetail->insert();
  3959. }
  3960. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  3961. $receiptDetail=new receiptDetail();
  3962. $receiptDetail->staff=$this->staff[0]['sid'];
  3963. $receiptDetail->item=$value['name'];
  3964. $receiptDetail->itemCategory=$this->TRAIN;
  3965. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3966. $receiptDetail->date=date("Y-m-d");
  3967. $receiptDetail->cid=$cid;
  3968. $receiptDetail->rid=$rid;
  3969. $receiptDetail->status=4;
  3970. $receiptDetail->insert();
  3971. }
  3972. foreach ($accountJson[$this->OTHER] as $key=>$value){
  3973. $receiptDetail=new receiptDetail();
  3974. $receiptDetail->staff=$this->staff[0]['sid'];
  3975. $receiptDetail->item=$value['name'];
  3976. $receiptDetail->itemCategory=$this->OTHER;
  3977. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  3978. $receiptDetail->date=date("Y-m-d");
  3979. $receiptDetail->cid=$cid;
  3980. $receiptDetail->rid=$rid;
  3981. $receiptDetail->status=4;
  3982. $receiptDetail->insert();
  3983. }
  3984. //return "/referReceipt/".$rid;
  3985. }
  3986. return "/saeaBorad";
  3987. }
  3988. function referReceipt(){
  3989. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  3990. Doo::loadModel('receipt');
  3991. Doo::loadModel('verify');
  3992. $verify=new verify();
  3993. $receipt=new receipt();
  3994. Doo::loadModel('L_category');
  3995. $lCategory=new L_category();
  3996. Doo::loadModel("role");
  3997. $role=new role();
  3998. $receiptDetail=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and status=5 ','asArray'=>true));
  3999. if(empty($receiptDetail))
  4000. return "/addReceipt";
  4001. foreach ($receiptDetail as $key=>$value){
  4002. $receiptDetail[$key]['accountItem']=json_decode($value['accountItem'],true);
  4003. $veList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4004. $v=json_decode($veList['staff']);
  4005. array_push($v[0], $veList['description']);
  4006. foreach ($v as $n=>$m){
  4007. if ($m['1']=='ROLE'){
  4008. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4009. $v[$n][1]=$roleInfo['name'];
  4010. }
  4011. }
  4012. $receiptDetail[$key]['staff']=$v;
  4013. $category=$lCategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4014. $receiptDetail[$key]['category']=$category['title'];
  4015. }
  4016. //print_r($receiptDetail);
  4017. $data['receiptDetail']=$receiptDetail;
  4018. $data['memu']="receipt";
  4019. $data['staff']=$this->staff;
  4020. $data['receiptMemu']='saeaCreate';
  4021. $data['verifyId']=$this->verifyId;
  4022. $data['executeId']=$this->executeId;
  4023. $this->render ( "/admin/saea_confirm", $data );
  4024. }
  4025. function editReceipt(){
  4026. //edit status 4
  4027. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4028. //echo $rid;
  4029. Doo::loadModel('accountItem');
  4030. Doo::loadModel('verify');
  4031. Doo::loadModel('receipt');
  4032. $receipt=new receipt();
  4033. $verify=new verify();
  4034. $accountItem=new accountItem();
  4035. Doo::loadModel('L_category');
  4036. $lCategory=new L_category();
  4037. Doo::loadModel("role");
  4038. $role=new role();
  4039. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=4)','asArray'=>true));
  4040. if(empty($receiptDetail))
  4041. return "/saeaCreate";
  4042. $acItem=$accountItem->find(array('asArray'=>true));
  4043. $veList=$verify->find(array('asArray'=>true));
  4044. foreach ($veList as $key=>$value){
  4045. $v=json_decode($value['staff']);
  4046. $list=array();
  4047. foreach ($v as $n=>$m){
  4048. if ($m['1']=='ROLE'){
  4049. $roleInfo=$role->getOne(array('where'=>'rid='.$m[0],'asArray'=>true));
  4050. $v[$n][1]=$roleInfo['name'];
  4051. array_push($list, $roleInfo['name']);
  4052. }else{
  4053. array_push($list, $v[$n][1]);
  4054. }
  4055. }
  4056. $veList[$key]['staff']=implode('>', $list);
  4057. }
  4058. //配置编辑信息
  4059. $accountItemList=json_decode($receiptDetail['accountItem'],true);
  4060. foreach ($acItem as $key=>$value){
  4061. foreach ($accountItemList[$this->AGENCY] as $k=>$v){
  4062. if($acItem[$key]['category']==$this->AGENCY&&$acItem[$key]['name']==$v['name']){
  4063. $acItem[$key]['price']=$v['price'];
  4064. }
  4065. }
  4066. foreach ($accountItemList[$this->TRAIN] as $k=>$v){
  4067. if($acItem[$key]['category']==$this->TRAIN&&$acItem[$key]['name']==$v['name']){
  4068. $acItem[$key]['price']=$v['price'];
  4069. }
  4070. }
  4071. foreach ($accountItemList[$this->TRAVEL] as $k=>$v){
  4072. if($acItem[$key]['category']==$this->TRAVEL&&$acItem[$key]['name']==$v['name']){
  4073. $acItem[$key]['price']=$v['price'];
  4074. }
  4075. }
  4076. foreach ($accountItemList[$this->OTHER] as $k=>$v){
  4077. if($acItem[$key]['category']==$this->OTHER&&$acItem[$key]['name']==$v['name']){
  4078. $acItem[$key]['price']=$v['price'];
  4079. }
  4080. }
  4081. }
  4082. $data['category']=$lCategory->find(array('asArray'=>true));
  4083. $data['cSum']=$accountItemList['cSum'];
  4084. $data['sum']=$receiptDetail['sum'];
  4085. $data['receiptDetail']=$receiptDetail;
  4086. $data['veList']=$veList;
  4087. $data['acItem']=$acItem;
  4088. $data['memu']="receipt";
  4089. $data['staff']=$this->staff;
  4090. $data['receiptMemu']='saeaBorad';
  4091. $data['verify']=$receiptDetail['verify'];
  4092. $data['verifyId']=$this->verifyId;
  4093. $data['executeId']=$this->executeId;
  4094. $data['rid']=$rid;
  4095. $this->render ( "/admin/saea_edit", $data );
  4096. }
  4097. function updateReceipt(){
  4098. $agency=$this->get_args('agency');
  4099. $travel=$this->get_args('travel');
  4100. $train=$this->get_args('train');
  4101. $other=$this->get_args('other');
  4102. $verify=$this->get_args('verify')&&is_numeric($this->get_args('verify'))?$this->get_args('verify'):0;
  4103. $explanation=$this->get_args('explanation')?$this->get_args('explanation'):"";
  4104. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  4105. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  4106. if(!empty($explanation)){
  4107. Doo::loadModel('receipt');
  4108. Doo::loadModel('receiptDetail');
  4109. Doo::loadModel('accountItem');
  4110. $accountItem=new accountItem();
  4111. $receipt=new receipt();
  4112. Doo::loadModel('execute');
  4113. $execute=new execute();
  4114. $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=5 or status=7 or status=4)','asArray'=>true));
  4115. if(empty($receiptDetail))
  4116. return "/saeaBorad";
  4117. if ($receiptDetail['Rtype']==1)
  4118. $executeDetail=$execute->getOne(array('where'=>'mold="借款费用执行人"','asArray'=>true));
  4119. else
  4120. $executeDetail=$execute->getOne(array('where'=>'mold="报销单执行人"','asArray'=>true));
  4121. $aItem=$accountItem->find(array('asArray'=>true));
  4122. $accountJson[$this->AGENCY]=$accountJson[$this->TRAVEL]=$accountJson[$this->TRAIN]=$accountJson[$this->OTHER]=array();
  4123. $ag=$tr=$ta=$ot=0;
  4124. $sum=$agencySum=$travelSum=$trainSum=$otherSum=0;
  4125. foreach ($aItem as $key=>$value){
  4126. if ($value['category']==$this->AGENCY){
  4127. if (is_numeric($agency[$ag])&&$agency[$ag]!=0){
  4128. array_push($accountJson[$this->AGENCY], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($agency[$ag], 2, '.', '')));
  4129. $sum+=$agency[$ag];$agencySum+=$agency[$ag];
  4130. }
  4131. $ag++;
  4132. }
  4133. if($value['category']==$this->TRAVEL){
  4134. if (is_numeric($travel[$tr])&&$travel[$tr]!=0){
  4135. array_push($accountJson[$this->TRAVEL], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($travel[$tr], 2, '.', '')));
  4136. $sum+=$travel[$tr];$travelSum+=$travel[$tr];
  4137. }
  4138. $tr++;
  4139. }
  4140. if($value['category']==$this->TRAIN){
  4141. if (is_numeric($train[$ta])&&$train[$ta]!=0){
  4142. array_push($accountJson[$this->TRAIN], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($train[$ta], 2, '.', '')));
  4143. $sum+=$train[$ta];$trainSum+=$train[$ta];
  4144. }
  4145. $ta++;
  4146. }
  4147. if($value['category']==$this->OTHER){
  4148. if (is_numeric($other[$ot])&&$other[$ot]!=0){
  4149. array_push($accountJson[$this->OTHER], array('aid'=>$value['aid'],'name'=>$value['name'],'price'=>number_format($other[$ot], 2, '.', '')));
  4150. $sum+=$other[$ot];$otherSum+=$other[$ot];
  4151. }
  4152. $ot++;
  4153. }
  4154. }
  4155. $accountJson['cSum']=array('agencySum'=>number_format($agencySum, 2, '.', ''),'travelSum'=>number_format($travelSum, 2, '.', ''),'trainSum'=>number_format($trainSum, 2, '.', ''),'otherSum'=>number_format($otherSum, 2, '.', ''));
  4156. //报销单
  4157. $rid=$receipt->rid=$receiptDetail['rid'];
  4158. $receipt->accountItem=json_encode($accountJson);
  4159. $receipt->staff=$this->staff[0]['sid'];
  4160. $receipt->sum=number_format($sum, 2, '.', '');
  4161. $receipt->date=date("Y-m-d");
  4162. $receipt->cid=$cid;
  4163. if (($receiptDetail['status']!=4)){
  4164. if ($receiptDetail['Rtype']==1)
  4165. $receipt->status=7;
  4166. else
  4167. $receipt->status=5;
  4168. }
  4169. if ($receiptDetail!=4&&!empty($verify))
  4170. $receipt->verify=$verify;
  4171. $receipt->executeCopy=$executeDetail['staff'];
  4172. $receipt->explanation=$explanation;
  4173. $receipt->update();
  4174. $receiptDetail=new receiptDetail();
  4175. $receiptDetail->delete(array('where'=>'rid='.$rid));
  4176. //报销详情
  4177. foreach ($accountJson[$this->AGENCY] as $key=>$value){
  4178. $receiptDetail=new receiptDetail();
  4179. $receiptDetail->staff=$this->staff[0]['sid'];
  4180. $receiptDetail->item=$value['name'];
  4181. $receiptDetail->itemCategory=$this->AGENCY;
  4182. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4183. $receiptDetail->date=date("Y-m-d");
  4184. $receiptDetail->cid=$cid;
  4185. $receiptDetail->rid=$rid;
  4186. $receiptDetail->status=4;
  4187. $receiptDetail->insert();
  4188. }
  4189. foreach ($accountJson[$this->TRAVEL] as $key=>$value){
  4190. $receiptDetail=new receiptDetail();
  4191. $receiptDetail->staff=$this->staff[0]['sid'];
  4192. $receiptDetail->item=$value['name'];
  4193. $receiptDetail->itemCategory=$this->TRAVEL;
  4194. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4195. $receiptDetail->date=date("Y-m-d");
  4196. $receiptDetail->cid=$cid;
  4197. $receiptDetail->rid=$rid;
  4198. $receiptDetail->status=4;
  4199. $receiptDetail->insert();
  4200. }
  4201. foreach ($accountJson[$this->TRAIN] as $key=>$value){
  4202. $receiptDetail=new receiptDetail();
  4203. $receiptDetail->staff=$this->staff[0]['sid'];
  4204. $receiptDetail->item=$value['name'];
  4205. $receiptDetail->itemCategory=$this->TRAIN;
  4206. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4207. $receiptDetail->date=date("Y-m-d");
  4208. $receiptDetail->cid=$cid;
  4209. $receiptDetail->rid=$rid;
  4210. $receiptDetail->status=4;
  4211. $receiptDetail->insert();
  4212. }
  4213. foreach ($accountJson[$this->OTHER] as $key=>$value){
  4214. $receiptDetail=new receiptDetail();
  4215. $receiptDetail->staff=$this->staff[0]['sid'];
  4216. $receiptDetail->item=$value['name'];
  4217. $receiptDetail->itemCategory=$this->OTHER;
  4218. $receiptDetail->price=number_format($value['price'], 2, '.', '');
  4219. $receiptDetail->date=date("Y-m-d");
  4220. $receiptDetail->cid=$cid;
  4221. $receiptDetail->rid=$rid;
  4222. $receiptDetail->status=4;
  4223. $receiptDetail->insert();
  4224. }
  4225. //return "/referReceipt/".$rid;
  4226. }
  4227. return "/saeaBorad";
  4228. }
  4229. function approvedReceipt(){
  4230. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  4231. Doo::loadModel('receipt');
  4232. Doo::loadModel('receiptDetail');
  4233. $receipt=new receipt();
  4234. $receiptDetail=new receiptDetail();
  4235. Doo::loadModel('statistics');
  4236. Doo::loadModel('itemStatistics');
  4237. $statistics=new statistics();
  4238. $itemStatistics=new itemStatistics();
  4239. Doo::loadModel("verify");
  4240. $verify=new verify();
  4241. //审批状态的判定
  4242. $receiptDetailList=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and rid='.$rid.' and (status=4 or status=5 or status=7)','asArray'=>true));
  4243. if(empty($receiptDetailList))
  4244. return "/saeaBorad";
  4245. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetailList['verify'],'asArray'=>true));
  4246. $verifyDetail=json_decode($verifyDetail['staff'],true);
  4247. if (empty($receiptDetailList['nowStaff'])){
  4248. $nowStaff="";$nowStaffList=array();
  4249. if ($verifyDetail[0][1]=='ROLE'){
  4250. $vStaffString=json_decode($verifyDetail[0][3]);
  4251. foreach ($vStaffString as $key=>$value){
  4252. $staffK=explode("_", $value);
  4253. array_push($nowStaffList, $staffK[0]);
  4254. }
  4255. $nowStaff=implode(',', $nowStaffList);
  4256. }else{
  4257. $nowStaff=$verifyDetail[0][0];
  4258. }
  4259. $receipt->nowStaff=$nowStaff;
  4260. }
  4261. // echo $nowStaff;
  4262. // print_r($verifyDetail);die;
  4263. $receipt->rid=$receiptDetailList['rid'];
  4264. $receipt->date=date("Y-m-d");
  4265. $receipt->status=2;
  4266. $receipt->update();
  4267. $receiptDetail->status=2;
  4268. $receiptDetail->update(array('where'=>'rid='.$receiptDetailList['rid']));
  4269. Doo::loadModel("receiptLog");
  4270. $receiptLog=new receiptLog();
  4271. Doo::loadModel("verify");
  4272. $verify=new verify();
  4273. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  4274. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  4275. $jd=json_decode($vr['staff']);$roleId=0;
  4276. foreach ($jd as $key=>$value){
  4277. if ($value[1]=='ROLE'){
  4278. $pos = strpos($value[3], $this->staff[0]['sid']);
  4279. if ($pos !== false) {
  4280. $roleId=$value[0];
  4281. }
  4282. }
  4283. }
  4284. //审批日志
  4285. //echo $roleId;die;
  4286. if (!empty($roleId)){
  4287. Doo::loadModel("role");
  4288. $role=new role();
  4289. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4290. $receiptLog->rolename=$roleInfo['name'];
  4291. }
  4292. $receiptLog->username=$this->staff[0]['username'];
  4293. $receiptLog->uid=$this->staff[0]['sid'];
  4294. $receiptLog->date=date("Y-m-d");
  4295. $receiptLog->opinion='提交审批';
  4296. $receiptLog->img=$this->staff[0]['avatar'];
  4297. $receiptLog->status=2;
  4298. $receiptLog->rid=$rid;
  4299. $receiptLog->insert();
  4300. //statistics item
  4301. $dateArray=explode("-", $receiptDetailList['date']);
  4302. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  4303. $accountItem=json_decode($receiptDetailList['accountItem'],true);
  4304. //print_r($accountItem['cSum']['agencySum']);die;
  4305. // foreach ($accountItem['cSum'] as $key=>$value){
  4306. // if($key=="agencySum"){
  4307. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  4308. // if(empty($iStatistics)){
  4309. // $itemStatistics->cid=$this->staff[0]['cid'];
  4310. // $itemStatistics->staff=$this->staff[0]['sid'];
  4311. // $itemStatistics->price=$value;
  4312. // $itemStatistics->itemCategory=$this->AGENCY;
  4313. // $itemStatistics->date=date("Y-m-d");
  4314. // $itemStatistics->insert();
  4315. // }else{
  4316. // if (!empty($value)){
  4317. // $itemStatistics->price=$value+$iStatistics['price'];
  4318. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4319. // }
  4320. // }
  4321. // }elseif($key=="travelSum"){
  4322. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  4323. // if(empty($iStatistics)){
  4324. // $itemStatistics->cid=$this->staff[0]['cid'];
  4325. // $itemStatistics->staff=$this->staff[0]['sid'];
  4326. // $itemStatistics->price=$value;
  4327. // $itemStatistics->itemCategory=$this->TRAVEL;
  4328. // $itemStatistics->date=date("Y-m-d");
  4329. // $itemStatistics->insert();
  4330. // }else{
  4331. // if (!empty($value)){
  4332. // $itemStatistics->price=$value+$iStatistics['price'];
  4333. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4334. // }
  4335. // }
  4336. // }elseif($key=="trainSum"){
  4337. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  4338. // if(empty($iStatistics)){
  4339. // $itemStatistics->cid=$this->staff[0]['cid'];
  4340. // $itemStatistics->staff=$this->staff[0]['sid'];
  4341. // $itemStatistics->price=$value;
  4342. // $itemStatistics->itemCategory=$this->TRAIN;
  4343. // $itemStatistics->date=date("Y-m-d");
  4344. // $itemStatistics->insert();
  4345. // }else{
  4346. // if (!empty($value)){
  4347. // $itemStatistics->price=$value+$iStatistics['price'];
  4348. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4349. // }
  4350. // }
  4351. // }elseif($key=="otherSum"){
  4352. // $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  4353. // if(empty($iStatistics)){
  4354. // $itemStatistics->cid=$this->staff[0]['cid'];
  4355. // $itemStatistics->staff=$this->staff[0]['sid'];
  4356. // $itemStatistics->price=$value;
  4357. // $itemStatistics->itemCategory=$this->OTHER;
  4358. // $itemStatistics->date=date("Y-m-d");
  4359. // $itemStatistics->insert();
  4360. // }else{
  4361. // if (!empty($value)){
  4362. // $itemStatistics->price=$value+$iStatistics['price'];
  4363. // $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  4364. // }
  4365. // }
  4366. // }
  4367. // }
  4368. $stat=$statistics->getOne(array('where'=>'staff='.$this->staff[0]['sid'].$dateCondition,'asArray'=>true));
  4369. if(empty($stat)){
  4370. $statistics->date=date("Y-m-d");
  4371. $statistics->cid=$this->staff[0]['cid'];
  4372. $statistics->staff=$this->staff[0]['sid'];
  4373. $statistics->agPrice=0;
  4374. $statistics->rePrice=$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4375. $statistics->insert();
  4376. }else{
  4377. $statistics->rePrice=$stat['rePrice']+$accountItem['cSum']['agencySum']+$accountItem['cSum']['travelSum']+$accountItem['cSum']['trainSum']+$accountItem['cSum']['otherSum'];
  4378. $statistics->update(array('where'=>'sid='.$stat['sid']));
  4379. }
  4380. return "/expenses";
  4381. }
  4382. function approval(){
  4383. $status=isset($this->params['status'])?$this->params['status']:'';
  4384. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4385. $month=$this->get_args('month')?$this->get_args('month'):"";
  4386. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4387. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4388. if (empty($status))
  4389. $status=$this->get_args('status')?$this->get_args('status'):2;
  4390. $vidList=array();
  4391. $button=0;
  4392. Doo::loadModel('verify');
  4393. $verify=new verify();
  4394. Doo::loadModel('receipt');
  4395. $receipt=new receipt();
  4396. Doo::loadModel('staff');
  4397. $staff=new staff();
  4398. Doo::loadModel('L_category');
  4399. $Lcategory=new L_category();
  4400. //user verify ID
  4401. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4402. foreach ($verifyDetail as $key=>$value){
  4403. array_push($vidList, $value['vid']);
  4404. }
  4405. $vid=implode(",", $vidList);
  4406. if(empty($verifyDetail))
  4407. $vid=0;
  4408. /*
  4409. */
  4410. $dateCondition=" and Year(date) =".$year;
  4411. if(!empty($month))
  4412. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  4413. $categoryList=$Lcategory->find(array('asArray'=>true));
  4414. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4415. $cateCondition="";$staffCondition="";$approvalCondition="";
  4416. if (!empty($cid))
  4417. $cateCondition=' and cid='.$cid;
  4418. if(!empty($sid)){
  4419. $staffCondition=' and staff='.$sid;
  4420. $cateCondition="";
  4421. }
  4422. // elseif($status==1){
  4423. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  4424. // }
  4425. if($status==2){
  4426. //查找角色审批人
  4427. $approvalCondition=' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' ) ';
  4428. }
  4429. $ap="";
  4430. if($status==4){
  4431. $ap=4;$status=2;
  4432. $approvalCondition=' and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  4433. }
  4434. if($status==5){
  4435. $status=4;$ap=5;
  4436. }
  4437. //echo $vid;
  4438. //get Receipt By verifyID status 2 .$approvalCondition
  4439. //$receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  4440. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  4441. ,'desc'=>'rid','asArray'=>true));
  4442. //echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  4443. $Locate=0;
  4444. if($ap==4)
  4445. $status=4;
  4446. elseif ($ap==5)
  4447. $status=5;
  4448. foreach ($receiptList as $key=>$value){
  4449. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4450. $receiptList[$key]['reviseDetail']=array();
  4451. if (!empty($value['reviseDetail']))
  4452. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4453. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4454. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4455. $receiptList[$key]['category']=$categoryDetil['title'];
  4456. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4457. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4458. $verifyStaff=json_decode($value['verifyStaff'],true);
  4459. foreach ($verifyList as $k=>$v){
  4460. //init verifyStaff
  4461. $verifyList[$k]['date']="";
  4462. $verifyList[$k]['opinion']="";
  4463. $verifyList[$k]['status']="";
  4464. if (empty($verifyStaff)){
  4465. $verifyList[$k]['date']="";
  4466. $verifyList[$k]['opinion']="";
  4467. if ($v[0]==$this->staff[0]['sid']){
  4468. $verifyList[$k]['status']=4;
  4469. $button=4;
  4470. }
  4471. }else{
  4472. $flag=true;
  4473. foreach ($verifyStaff as $m=>$u){
  4474. if ($v[0]==$m){
  4475. $verifyList[$k]['date']=$u['date'];
  4476. $verifyList[$k]['opinion']=$u['opinion'];
  4477. $verifyList[$k]['status']=$u['status'];
  4478. $flag=false;
  4479. break;
  4480. }
  4481. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4482. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4483. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4484. }
  4485. if($flag){//检测可编辑
  4486. if($v[0]==$this->staff[0]['sid']){
  4487. $verifyList[$k]['status']=4;$button=4;
  4488. }
  4489. }
  4490. }
  4491. }
  4492. $receiptList[$key]['verifyList']=$verifyList;
  4493. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4494. $receiptList[$key]['button']=$button;
  4495. }
  4496. //print_r($receiptList);die;
  4497. //$data['verifyDetail']=$verifyDetail;
  4498. $mothHtml="";
  4499. for($i=1;$i<=12;$i++){
  4500. if($month==$i)
  4501. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4502. else
  4503. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4504. }
  4505. $data['mothHtml']=$mothHtml;
  4506. $data['receiptList']=$receiptList;
  4507. $data['receiptApprovalCount']=count($receiptList);
  4508. $data['status']=$status;
  4509. $data['year']=$year;
  4510. $data['categoryList']=$categoryList;
  4511. $data['staffList']=$staffList;
  4512. $data['cid']=$cid;
  4513. $data['sid']=$sid;
  4514. $data['ap']=$ap;
  4515. $data['memu']="receipt";
  4516. $data['staff']=$this->staff;
  4517. $data['receiptMemu']='approval';
  4518. $data['verifyId']=$this->verifyId;
  4519. $data['executeId']=$this->executeId;
  4520. $this->render ( "/admin/saea_reportList", $data );
  4521. }
  4522. function approvalDetails(){
  4523. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4524. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4525. $month=$this->get_args('month')?$this->get_args('month'):"";
  4526. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4527. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4528. Doo::loadModel('verify');
  4529. $verify=new verify();
  4530. Doo::loadModel('receipt');
  4531. $receipt=new receipt();
  4532. Doo::loadModel('staff');
  4533. $staff=new staff();
  4534. Doo::loadModel('L_category');
  4535. $Lcategory=new L_category();
  4536. Doo::loadModel('enclosur');
  4537. $enclosur=new enclosur();
  4538. $vidList=array();
  4539. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4540. foreach ($verifyDetail as $key=>$value){
  4541. array_push($vidList, $value['vid']);
  4542. }
  4543. $vid=implode(",", $vidList);
  4544. if(empty($verifyDetail))
  4545. $vid=0;
  4546. $categoryList=$Lcategory->find(array('asArray'=>true));
  4547. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4548. $ap=0;
  4549. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4550. $Locate=0;$roleId=0;$button=0;
  4551. foreach ($receiptList as $key=>$value){
  4552. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4553. $receiptList[$key]['reviseDetail']=array();
  4554. if (!empty($value['reviseDetail']))
  4555. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4556. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4557. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4558. $receiptList[$key]['category']=$categoryDetil['title'];
  4559. //检测编辑状态
  4560. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4561. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4562. $verifyStaff=json_decode($value['verifyStaff'],true);
  4563. Doo::loadModel('role');
  4564. $role=new role();
  4565. //print_r($verifyList);
  4566. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4567. foreach ($verifyList as $k=>$v){
  4568. //init verifyStaff
  4569. if ($v[1]=='ROLE'){
  4570. if (!empty($verifyStaff)){
  4571. $endStaffArray=end($verifyStaff);
  4572. if ($v[0]==$endStaffArray['nextStaff']){
  4573. $roleId=$v[0];
  4574. }
  4575. }
  4576. $roleVerify=json_decode($v[3],true);
  4577. $roleKey=$k;$roleArray=array();
  4578. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4579. foreach ($roleVerify as $o=>$p){
  4580. $staffID=explode ('_',$p);
  4581. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4582. //print_r($staffID);
  4583. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4584. array_push($roleArray, $exp);
  4585. }
  4586. $roleArrayCopy[$v[0]]=$roleArray;
  4587. //$verifyList[$k]['roleArray']=$roleArray;
  4588. }
  4589. //print_r($roleArray);
  4590. $verifyList[$k]['date']="";
  4591. $verifyList[$k]['opinion']="";
  4592. $verifyList[$k]['status']="";
  4593. if (empty($verifyStaff)){
  4594. $verifyList[$k]['date']="";
  4595. $verifyList[$k]['opinion']="";
  4596. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4597. $verifyList[$k]['status']=4;
  4598. $button=4;$flag=false;
  4599. }
  4600. }else{
  4601. foreach ($verifyStaff as $m=>$u){
  4602. if ($v[0]==$m){
  4603. $verifyList[$k]['date']=$u['date'];
  4604. $verifyList[$k]['opinion']=$u['opinion'];
  4605. $verifyList[$k]['status']=$u['status'];
  4606. $flag=false;
  4607. break;
  4608. }
  4609. }
  4610. $endStaffArray=end($verifyStaff);
  4611. if (isset($endStaffArray['ROLE'])){
  4612. }else{
  4613. $endKey=key($verifyStaff);
  4614. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4615. $button=4;
  4616. $verifyList[$k]['status']=4;
  4617. }
  4618. }
  4619. }
  4620. }
  4621. $rolename['name']='';
  4622. if (!empty($roleId)){
  4623. Doo::loadModel('role');
  4624. $role=new role();
  4625. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4626. }
  4627. if (!empty($verifyStaff))
  4628. $endStaffArray=end($verifyStaff);
  4629. $KOP=false;
  4630. foreach ($roleArrayCopy as $P=>$A){
  4631. foreach ( $A as $MKI=>$AVL){
  4632. if (!empty($verifyStaff)){
  4633. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4634. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4635. $button=4;
  4636. $roleArrayCopy[$P][$MKI]['status']=4;
  4637. }
  4638. foreach ($verifyStaff as $m=>$u){
  4639. $AVLFK=$AVL[0].'_R';
  4640. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4641. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4642. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4643. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4644. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4645. break;
  4646. }
  4647. }
  4648. }else{
  4649. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4650. $button=4;
  4651. $roleArrayCopy[$P][$MKI]['status']=4;
  4652. }
  4653. }
  4654. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4655. $KOP=true;
  4656. }
  4657. }
  4658. foreach ($roleArrayCopy as $k=>$v){
  4659. foreach ($verifyList as $m=>$n){
  4660. if ($n[0]==$k){
  4661. array_splice($verifyList,$m,1,$v);
  4662. }
  4663. }
  4664. }
  4665. $receiptList[$key]['verifyList']=$verifyList;
  4666. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4667. $receiptList[$key]['button']=$button;
  4668. }
  4669. $mothHtml="";
  4670. for($i=1;$i<=12;$i++){
  4671. if($month==$i)
  4672. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4673. else
  4674. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4675. }
  4676. //获取审批日志
  4677. Doo::loadModel('receiptLog');
  4678. $receiptLog=new receiptLog();
  4679. $rlList=array();
  4680. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4681. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4682. if (!empty($rlInfo)){
  4683. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4684. }
  4685. $receiptList[0]['rlList']=$rlList;
  4686. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4687. $enclosurHtml='';
  4688. foreach ($enclosurList as $value){
  4689. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4690. }
  4691. $data['enclosurHtml']=$enclosurHtml;
  4692. $data['rolename']=$rolename['name'];
  4693. $data['datetij']=$tijdate['date'];
  4694. $data['mothHtml']=$mothHtml;
  4695. $data['receiptList']=$receiptList;
  4696. $data['receiptApprovalCount']=count($receiptList);
  4697. $data['year']=$year;
  4698. $data['categoryList']=$categoryList;
  4699. $data['staffList']=$staffList;
  4700. $data['cid']=$cid;
  4701. $data['sid']=$sid;
  4702. $data['status']=0;
  4703. if ($receiptList[0]['status']!=1&&$receiptList[0]['status']!=3){
  4704. $ap=4;
  4705. }else
  4706. $data['status']=$receiptList[0]['status'];
  4707. if ($receiptList[0]['status']==4){
  4708. $data['status']=5;
  4709. $ap=0;
  4710. }
  4711. $data['ap']=$ap;
  4712. $data['memu']="receipt";
  4713. $data['staff']=$this->staff;
  4714. $data['receiptMemu']='approval';
  4715. $data['verifyId']=$this->verifyId;
  4716. $data['executeId']=$this->executeId;
  4717. $this->render ( "/admin/saeaReportListReport", $data );
  4718. }
  4719. function approvalEdi(){
  4720. $rid=isset($this->params['rid'])?$this->params['rid']:0;
  4721. $status=isset($this->params['status'])?$this->params['status']:'';
  4722. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4723. $month=$this->get_args('month')?$this->get_args('month'):"";
  4724. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  4725. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  4726. if (empty($status))
  4727. $status=$this->get_args('status')?$this->get_args('status'):2;
  4728. $vidList=array();
  4729. $button=0;
  4730. Doo::loadModel('verify');
  4731. Doo::loadModel('receipt');
  4732. Doo::loadModel('staff');
  4733. $staff=new staff();
  4734. $receipt=new receipt();
  4735. $verify=new verify();
  4736. Doo::loadModel('L_category');
  4737. $Lcategory=new L_category();
  4738. Doo::loadModel('enclosur');
  4739. $enclosur=new enclosur();
  4740. //user verify ID
  4741. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'%"','asArray'=>true));
  4742. foreach ($verifyDetail as $key=>$value){
  4743. array_push($vidList, $value['vid']);
  4744. }
  4745. $vid=implode(",", $vidList);
  4746. if(empty($verifyDetail))
  4747. $vid=0;
  4748. $categoryList=$Lcategory->find(array('asArray'=>true));
  4749. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  4750. $ap="";
  4751. if($status==4){
  4752. $ap=4;$status=2;
  4753. }
  4754. //get Receipt By verifyID status 2
  4755. $receiptList=$receipt->find(array('where'=>'rid ='.$rid,'desc'=>'rid','asArray'=>true));
  4756. $Locate=0;$roleId=0;
  4757. if($ap==4)
  4758. $status=4;
  4759. foreach ($receiptList as $key=>$value){
  4760. $receiptList[$key]['Locate']=$Locate;$Locate++;
  4761. $receiptList[$key]['reviseDetail']=array();
  4762. if (!empty($value['reviseDetail']))
  4763. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  4764. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  4765. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  4766. $receiptList[$key]['category']=$categoryDetil['title'];
  4767. //检测编辑状态
  4768. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  4769. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  4770. $verifyStaff=json_decode($value['verifyStaff'],true);
  4771. // print_r($verifyList);
  4772. //
  4773. // if (empty($verifyStaff)){
  4774. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4775. // $verifyList[0]['status']=4;$button=4;
  4776. // }
  4777. //
  4778. // }else{
  4779. //
  4780. // }
  4781. // die;
  4782. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  4783. // echo array_search("green",$a);
  4784. //
  4785. Doo::loadModel('role');
  4786. $role=new role();
  4787. //print_r($verifyList);
  4788. $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array();
  4789. foreach ($verifyList as $k=>$v){
  4790. //init verifyStaff
  4791. if ($v[1]=='ROLE'){
  4792. if (!empty($verifyStaff)){
  4793. $endStaffArray=end($verifyStaff);
  4794. if ($v[0]==$endStaffArray['nextStaff']){
  4795. $roleId=$v[0];
  4796. }
  4797. }
  4798. $roleVerify=json_decode($v[3],true);
  4799. $roleKey=$k;$roleArray=array();
  4800. $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true));
  4801. foreach ($roleVerify as $o=>$p){
  4802. $staffID=explode ('_',$p);
  4803. $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true));
  4804. //print_r($staffID);
  4805. $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']);
  4806. array_push($roleArray, $exp);
  4807. }
  4808. $roleArrayCopy[$v[0]]=$roleArray;
  4809. //$verifyList[$k]['roleArray']=$roleArray;
  4810. }
  4811. //print_r($roleArray);
  4812. $verifyList[$k]['date']="";
  4813. $verifyList[$k]['opinion']="";
  4814. $verifyList[$k]['status']="";
  4815. if (empty($verifyStaff)){
  4816. $verifyList[$k]['date']="";
  4817. $verifyList[$k]['opinion']="";
  4818. if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){
  4819. $verifyList[$k]['status']=4;
  4820. $button=4;$flag=false;
  4821. }
  4822. }else{
  4823. foreach ($verifyStaff as $m=>$u){
  4824. if ($v[0]==$m){
  4825. $verifyList[$k]['date']=$u['date'];
  4826. $verifyList[$k]['opinion']=$u['opinion'];
  4827. $verifyList[$k]['status']=$u['status'];
  4828. $flag=false;
  4829. break;
  4830. }
  4831. }
  4832. $endStaffArray=end($verifyStaff);
  4833. if (isset($endStaffArray['ROLE'])){
  4834. }else{
  4835. $endKey=key($verifyStaff);
  4836. if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4837. $button=4;
  4838. $verifyList[$k]['status']=4;
  4839. }
  4840. }
  4841. //print_r($endStaffArray);die;
  4842. // if (empty($verifyStaff)){
  4843. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  4844. // $verifyList[$k]['status']=4;$button=4;
  4845. // }
  4846. //
  4847. // }else{
  4848. //
  4849. // }
  4850. // if($flag){//检测可编辑
  4851. // if($v[0]==$this->staff[0]['sid']){
  4852. // $verifyList[$k]['status']=4;$button=4;
  4853. // }
  4854. // }
  4855. }
  4856. }
  4857. $rolename['name']='';
  4858. if (!empty($roleId)){
  4859. Doo::loadModel('role');
  4860. $role=new role();
  4861. $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  4862. }
  4863. if (!empty($verifyStaff))
  4864. $endStaffArray=end($verifyStaff);
  4865. $KOP=false;
  4866. foreach ($roleArrayCopy as $P=>$A){
  4867. foreach ( $A as $MKI=>$AVL){
  4868. if (!empty($verifyStaff)){
  4869. //&&$rolename['rid']==$endStaffArray['nextStaff']
  4870. if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){
  4871. $button=4;
  4872. $roleArrayCopy[$P][$MKI]['status']=4;
  4873. }
  4874. foreach ($verifyStaff as $m=>$u){
  4875. $AVLFK=$AVL[0].'_R';
  4876. //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4877. if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1
  4878. $roleArrayCopy[$P][$MKI]['date']=$u['date'];
  4879. $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion'];
  4880. $roleArrayCopy[$P][$MKI]['status']=$u['status'];
  4881. break;
  4882. }
  4883. }
  4884. }else{
  4885. if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){
  4886. $button=4;
  4887. $roleArrayCopy[$P][$MKI]['status']=4;
  4888. }
  4889. }
  4890. //$roleArray[$MKI]['rolename']=$rolename['name'];
  4891. $KOP=true;
  4892. }
  4893. }
  4894. // print_r($roleArrayCopy);
  4895. // echo $roleKey;
  4896. foreach ($roleArrayCopy as $k=>$v){
  4897. foreach ($verifyList as $m=>$n){
  4898. if ($n[0]==$k){
  4899. array_splice($verifyList,$m,1,$v);
  4900. }
  4901. }
  4902. }
  4903. // if ($KOP)
  4904. // array_splice($verifyList,$roleKey,1,$roleArray);
  4905. //print_r($verifyList);
  4906. $receiptList[$key]['verifyList']=$verifyList;
  4907. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  4908. $receiptList[$key]['button']=$button;
  4909. }
  4910. //$data['verifyDetail']=$verifyDetail;
  4911. $mothHtml="";
  4912. for($i=1;$i<=12;$i++){
  4913. if($month==$i)
  4914. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4915. else
  4916. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4917. }
  4918. //获取审批日志
  4919. Doo::loadModel('receiptLog');
  4920. $receiptLog=new receiptLog();
  4921. $rlList=array();
  4922. $rlInfo=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=4','asArray'=>true));
  4923. $tijdate=$receiptLog->getOne(array('where'=>'rid='.$rid.' and status=2','asc'=>'rlid','asArray'=>true));
  4924. if (!empty($rlInfo)){
  4925. $rlList=$receiptLog->find(array('where'=>'rid='.$rid,'asc'=>'rlid','asArray'=>true));
  4926. }
  4927. $receiptList[0]['rlList']=$rlList;
  4928. $enclosurList=$enclosur->find(array('where'=>'rid='.$rid,'asArray'=>true));
  4929. $enclosurHtml='';
  4930. foreach ($enclosurList as $value){
  4931. $enclosurHtml.='<a href="/upload/swfupload/'.$value['name'].'" class="sFile" target="_blank">'.$value['name'].'</a>';
  4932. }
  4933. $data['enclosurHtml']=$enclosurHtml;
  4934. $data['rolename']=$rolename['name'];
  4935. $data['datetij']=$tijdate['date'];
  4936. $data['mothHtml']=$mothHtml;
  4937. $data['receiptList']=$receiptList;
  4938. $data['receiptApprovalCount']=count($receiptList);
  4939. $data['status']=$status;
  4940. $data['year']=$year;
  4941. $data['categoryList']=$categoryList;
  4942. $data['staffList']=$staffList;
  4943. $data['cid']=$cid;
  4944. $data['sid']=$sid;
  4945. $data['ap']=$ap;
  4946. $data['memu']="receipt";
  4947. $data['staff']=$this->staff;
  4948. $data['receiptMemu']='approval';
  4949. $data['verifyId']=$this->verifyId;
  4950. $data['executeId']=$this->executeId;
  4951. $this->render ( "/admin/saeaReportListReport", $data );
  4952. }
  4953. function remittance(){
  4954. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  4955. $month=$this->get_args('month')?$this->get_args('month'):"";
  4956. Doo::loadModel('receipt');
  4957. $receipt=new receipt();
  4958. Doo::loadModel('staff');
  4959. $staff=new staff();
  4960. $dateCondition=" and Year(pastDate) =".$year;
  4961. if(!empty($month))
  4962. $dateCondition=" and Year(pastDate) =".$year." and Month(pastDate) = ".$month;
  4963. //get Receipt By verifyID status 1
  4964. $receiptList=$receipt->find(array('select'=>'sum(sum) as sum,staff,pastDate','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'staff,pastDate','asArray'=>true));
  4965. $dateList=$receipt->find(array('select'=>'pastDate,verifyStaff','where'=>' status=1'.$dateCondition,'desc'=>'pastDate','groupby'=>'pastDate','asArray'=>true));
  4966. $dataList=array();
  4967. foreach ($dateList as $d=>$a){
  4968. $dataList[$a['pastDate']]=array();$daySum=0;
  4969. foreach ($receiptList as $key=>$value){
  4970. if($a['pastDate']==$value['pastDate']){
  4971. $oderList=$receipt->find(array('select'=>'receiptOrder','where'=>' status=1 and staff='.$value['staff'].' and pastDate=\''.$a['pastDate'].'\'','asArray'=>true));
  4972. $list=array();$html="";
  4973. foreach ($oderList as $v){
  4974. array_push($list, $v['receiptOrder']);
  4975. $html.='<a class="fL" href="#comment" onclick=showOpinion("'.$v['receiptOrder'].'") data="" data-toggle="modal">&nbsp;'.$v['receiptOrder'].'、</a>';
  4976. }
  4977. $receiptList[$key]['receiptOrder']=$html;
  4978. //$receiptList[$key]['receiptOrder']=implode(",", $list);
  4979. $sinfo=$staff->getOne(array('select'=>'username ','where'=>' sid='.$value['staff'],'asArray'=>true));
  4980. $receiptList[$key]['username']=$sinfo['username'];
  4981. $daySum+=$value['sum'];
  4982. array_push($dataList[$a['pastDate']], $receiptList[$key]);
  4983. }
  4984. $dataList[$a['pastDate']]['9999999']=number_format($daySum,2);
  4985. //$dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  4986. }
  4987. }
  4988. //print_r($dataList);
  4989. $data['dataList']=$dataList;
  4990. $mothHtml="";
  4991. for($i=1;$i<=12;$i++){
  4992. if($month==$i)
  4993. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  4994. else
  4995. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  4996. }
  4997. $data['year']=$year;
  4998. $data['mothHtml']=$mothHtml;
  4999. $data['memu']="receipt";
  5000. $data['staff']=$this->staff;
  5001. $data['receiptMemu']='approval';
  5002. $data['verifyId']=$this->verifyId;
  5003. $data['executeId']=$this->executeId;
  5004. $this->render ( "/admin/saeaReportListPay", $data );
  5005. }
  5006. function revocationAdjustment(){
  5007. $sid=isset($this->params['sid'])&&is_numeric($this->params['sid'])?$this->params['sid']:0;
  5008. $price=isset($this->params['price'])&&is_numeric($this->params['price'])?$this->params['price']:-99999;
  5009. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5010. //echo $price;die;
  5011. if ((!empty($sid))&&($price!=-99999)&&(!empty($rid))){
  5012. Doo::loadModel('receipt');
  5013. $receipt=new receipt();
  5014. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5015. if (empty($receiptDetail['reviseDetail']))
  5016. return "/approval";
  5017. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5018. $RD=array();
  5019. foreach ($reviseDetail as $key=>$value){
  5020. if ($value['price']==$price&&$value['sid']==$sid)
  5021. continue;
  5022. array_push($RD, $value);
  5023. }
  5024. $reviseDetailString=json_encode($RD);
  5025. $receipt->reviseDetail=$reviseDetailString;
  5026. $receipt->sum=$receiptDetail['sum']-$price;
  5027. $receipt->revisePrice=$receiptDetail['revisePrice']-$price;
  5028. $receipt->update(array('where'=>'rid='.$rid));
  5029. }
  5030. //approvalEdi/37
  5031. return "/approvalEdi/".$rid;
  5032. }
  5033. function updateApprovalReceipt(){
  5034. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5035. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  5036. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5037. $Locate=$this->get_args('Locate')&&is_numeric($this->get_args('Locate'))?$this->get_args('Locate'):0;
  5038. if(!empty($rid)){
  5039. Doo::loadModel("verify");
  5040. $verify=new verify();
  5041. Doo::loadModel("receiptDetail");
  5042. $receiptDetailObj=new receiptDetail();
  5043. Doo::loadModel("itemStatistics");
  5044. Doo::loadModel("statistics");
  5045. $statistics=new statistics();
  5046. $itemStatistics=new itemStatistics();
  5047. Doo::loadModel("receipt");
  5048. $receipt=new receipt();
  5049. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5050. if (empty($receiptDetail))
  5051. return "/approval";
  5052. $verifyDetail=$verify->getOne(array('where'=>' vid ='.$receiptDetail['verify'],'asArray'=>true));
  5053. $verifyString=$verifyDetail['staff'];
  5054. $verifyDetail=json_decode($verifyDetail['staff'],true);
  5055. $verifyStaff=json_decode($receiptDetail['verifyStaff'],true);
  5056. if(empty($opinion)){
  5057. if ($status==3)
  5058. $opinion="终止";
  5059. else
  5060. $opinion="同意支付";
  5061. }
  5062. $nowStaff=0;$nowStaffList=array();
  5063. if(empty($verifyStaff)){
  5064. //还需加入是否已经进入角色审批
  5065. if ($verifyDetail[0][1]=='ROLE'){
  5066. $vStaffString=json_decode($verifyDetail[0][3]);
  5067. foreach ($vStaffString as $key=>$value){
  5068. $staffK=explode("_", $value);
  5069. if ($staffK[0]!=$this->staff[0]['sid'])
  5070. array_push($nowStaffList, $staffK[0]);
  5071. }
  5072. //print_r($verifyDetail);
  5073. //die;
  5074. if (!empty($nowStaffList)){
  5075. $nowStaff=implode(',', $nowStaffList);
  5076. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[0][0],'ROLE'=>1));
  5077. }else{
  5078. $nowStaff=$verifyDetail[1][0];
  5079. $verifyStaff=array($this->staff[0]['sid']."_R"=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5080. }
  5081. }else{
  5082. if ($verifyDetail[1][1]=='ROLE'){
  5083. $vStaffString=json_decode($verifyDetail[1][3]);
  5084. //echo "dd";
  5085. foreach ($vStaffString as $key=>$value){
  5086. $staffK=explode("_", $value);
  5087. array_push($nowStaffList, $staffK[0]);
  5088. }
  5089. $nowStaff=implode(',', $nowStaffList);
  5090. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0],'ROLE'=>1));
  5091. }else{
  5092. $nowStaff=$verifyDetail[1][0];
  5093. $verifyStaff=array($this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$verifyDetail[1][0]));
  5094. }
  5095. }
  5096. if($status==3)
  5097. $verifyStaff=array('final'=>$status,$this->staff[0]['sid']=>array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status));
  5098. $vStaffString=json_encode($verifyStaff);
  5099. $receipt->nowStaff=$nowStaff;
  5100. $receipt->verifyStaff=$vStaffString;
  5101. }else{
  5102. $VS=end($verifyStaff);
  5103. //非角色审批
  5104. if (!array_key_exists($this->staff[0]['sid'],$verifyStaff)&&!isset($VS['ROLE'])){
  5105. $nextStaff=0;$roleSTF=false;
  5106. foreach ($verifyDetail as $key=>$value){
  5107. if ($value[0]==$this->staff[0]['sid']&&$value[1]!='ROLE'){
  5108. if (isset($verifyDetail[$key+1])){
  5109. $nextStaff=$verifyDetail[$key+1][0];
  5110. if ($verifyDetail[$key+1][1]=='ROLE')
  5111. $roleSTF=true;
  5112. }
  5113. break;
  5114. }
  5115. }
  5116. if (!$roleSTF){
  5117. $nowStaff=$nextStaff;
  5118. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5119. }else{
  5120. //获取角色下的所有用户ID
  5121. $nowStaffList=array();
  5122. foreach ($verifyDetail as $vfk){
  5123. if ($vfk[1]=='ROLE'){
  5124. $vStaffString=json_decode($vfk[3]);
  5125. foreach ($vStaffString as $key=>$value){
  5126. $staffK=explode("_", $value);
  5127. array_push($nowStaffList, $staffK[0]);
  5128. }
  5129. }
  5130. }
  5131. $nowStaff=implode(',', $nowStaffList);
  5132. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>0);
  5133. }
  5134. if($status==3){
  5135. $verifyStaff['final']=$status;
  5136. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5137. }
  5138. $vStaffString=json_encode($verifyStaff);
  5139. $receipt->nowStaff=$nowStaff;
  5140. $receipt->verifyStaff=$vStaffString;
  5141. }
  5142. //角色审批
  5143. if (isset($VS['ROLE'])){
  5144. //找出角色人 当前审批角色组
  5145. $verifyJSStaff=array();$nowStaffList2=array();
  5146. foreach ($verifyDetail as $key=>$value){
  5147. if($value[1]=='ROLE'&&$value[0]==$VS['nextStaff']){
  5148. $verifyJSStaff=json_decode($value[3]);
  5149. foreach ($verifyJSStaff as $m){
  5150. $staffK=explode("_", $m);
  5151. array_push($nowStaffList2, $staffK[0]);
  5152. }
  5153. // print_r($nowStaffList2);
  5154. }
  5155. }
  5156. $RoleVerifyStaff=array();
  5157. foreach ($verifyStaff as $key=>$value){
  5158. if (isset($value['ROLE'])&&$value['ROLE']==1&&$VS['nextStaff']==$value['nextStaff']){
  5159. foreach ($nowStaffList2 as $m) {
  5160. if ($key==$m."_R")
  5161. $RoleVerifyStaff[$key]=$value;
  5162. }
  5163. }
  5164. }
  5165. // print_r($verifyStaff);
  5166. // print_r($nowStaffList2);
  5167. // print_r($RoleVerifyStaff);
  5168. //if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  5169. //print_r($verifyJSStaff);
  5170. $jsCount=count($verifyJSStaff)-1;//echo $jsCount;die;
  5171. if ($jsCount==count($RoleVerifyStaff)){ //或者
  5172. //下一个审批人ID
  5173. $nextStaff=0;$falg=false;
  5174. foreach ($verifyDetail as $key=>$value){
  5175. if ($value[0]==$VS['nextStaff']&&$value[1]=='ROLE'){
  5176. if (isset($verifyDetail[$key+1])&&$verifyDetail[$key+1][1]=='ROLE'){
  5177. $falg=true;
  5178. $vStaffString=json_decode($verifyDetail[$key+1][3]);$nowStaffList=array();
  5179. foreach ($vStaffString as $v){
  5180. $staffK=explode("_", $v);
  5181. array_push($nowStaffList, $staffK[0]);
  5182. }
  5183. $nowStaff=implode(',', $nowStaffList);
  5184. $nextStaff=$verifyDetail[$key+1][0];
  5185. }elseif(isset($verifyDetail[$key+1])){
  5186. $nextStaff=$verifyDetail[$key+1][0];
  5187. $nowStaff=$nextStaff;
  5188. }else
  5189. $nowStaff='';
  5190. break;
  5191. }
  5192. }
  5193. if ($falg)
  5194. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff,'ROLE'=>1);
  5195. else
  5196. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$nextStaff);
  5197. // print_r($verifyStaff);
  5198. // echo $nowStaff;die;
  5199. }else{ //进入下一个角色或者审批人
  5200. /*
  5201. */
  5202. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5203. //
  5204. $nowStaff=str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  5205. $verifyStaff[$this->staff[0]['sid'].'_R']=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status,'nextStaff'=>$VS['nextStaff'],'ROLE'=>1);
  5206. // print_r($verifyStaff);
  5207. // die;
  5208. }
  5209. if($status==3){
  5210. $verifyStaff['final']=$status;
  5211. $verifyStaff[$this->staff[0]['sid']]=array('date'=>date('Y-m-d'),'opinion'=>$opinion,'status'=>$status);
  5212. }
  5213. $vStaffString=json_encode($verifyStaff);
  5214. $receipt->verifyStaff=$vStaffString;
  5215. $receipt->nowStaff=$nowStaff;
  5216. //die;
  5217. //}
  5218. // print_r($verifyStaff);
  5219. // die;
  5220. }
  5221. //print_r($verifyStaff);die;
  5222. }
  5223. //print_r($verifyDetail);
  5224. $roleKey=0;$roleId=0;$verifyDetailCopy=array();
  5225. foreach ($verifyDetail as $k=>$v){
  5226. if ($v[1]=='ROLE'){
  5227. $roleId=$v[0];
  5228. $roleVerify=json_decode($v[3],true);
  5229. $roleKey=$k;$roleArray=array();
  5230. foreach ($roleVerify as $o=>$p){
  5231. $staffID=explode ('_',$p);
  5232. $exp=array(0=>$staffID[0],1=>$staffID[1]);
  5233. array_push($roleArray, $exp);
  5234. }
  5235. $verifyDetailCopy[$v[0]]=$roleArray;
  5236. }
  5237. }
  5238. //print_r($verifyDetail);
  5239. foreach ($verifyDetailCopy as $k=>$v){
  5240. foreach ($verifyDetail as $m=>$n){
  5241. if ($n[0]==$k){
  5242. array_splice($verifyDetail,$m,1,$v);
  5243. }
  5244. }
  5245. }
  5246. // die;
  5247. // if (!empty($roleArray))
  5248. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  5249. // echo $roleId;
  5250. // print_r($verifyStaff);
  5251. // print_r($verifyDetail);
  5252. // die;
  5253. Doo::loadModel("receiptLog");
  5254. $receiptLog=new receiptLog();
  5255. //审批日志
  5256. if (!isset($verifyStaff['final'])){
  5257. if (!empty($roleId)){
  5258. Doo::loadModel("role");
  5259. $role=new role();
  5260. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5261. $receiptLog->rolename=$roleInfo['name'];
  5262. }
  5263. $receiptLog->username=$this->staff[0]['username'];
  5264. $receiptLog->uid=$this->staff[0]['sid'];
  5265. $receiptLog->date=date("Y-m-d");
  5266. $receiptLog->opinion=$opinion;
  5267. $receiptLog->img=$this->staff[0]['avatar'];
  5268. $receiptLog->status=1;
  5269. $receiptLog->rid=$rid;
  5270. $receiptLog->insert();
  5271. }
  5272. if (isset($verifyStaff['final'])){//rDetail
  5273. $receipt->verifyBreakup=$verifyString;
  5274. $receipt->status=3;
  5275. $receiptDetailObj->status=3;
  5276. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5277. if (!empty($roleId)){
  5278. Doo::loadModel("role");
  5279. $role=new role();
  5280. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5281. $receiptLog->rolename=$roleInfo['name'];
  5282. }
  5283. $receiptLog->username=$this->staff[0]['username'];
  5284. $receiptLog->uid=$this->staff[0]['sid'];
  5285. $receiptLog->date=date("Y-m-d");
  5286. $receiptLog->opinion=$opinion;
  5287. $receiptLog->img=$this->staff[0]['avatar'];
  5288. $receiptLog->status=3;
  5289. $receiptLog->rid=$rid;
  5290. $receiptLog->insert();
  5291. //微信企业号通知
  5292. $this->setWXMsg($rid,3);
  5293. }elseif(count($verifyStaff)==count($verifyDetail)){//要修改 角色的数量
  5294. $receipt->status=1;$reviseSum=0;
  5295. $receipt->verifyBreakup=$verifyString;
  5296. if(!empty($receiptDetail['reviseDetail'])){//statistics item rDetail
  5297. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5298. foreach ($reviseDetail as $key=>$value){
  5299. $receiptDetailObj=new receiptDetail();
  5300. $receiptDetailObj->staff=$receiptDetail['staff'];// $this->staff[0]['sid'];
  5301. $receiptDetailObj->item=$value['description'];
  5302. $receiptDetailObj->itemCategory="报销金额调整";
  5303. $receiptDetailObj->price=$value['price'];
  5304. $receiptDetailObj->date=$receiptDetail['date'];
  5305. $receiptDetailObj->cid=$this->staff[0]['cid'];
  5306. $receiptDetailObj->rid=$rid;
  5307. $receiptDetailObj->status=1;
  5308. $receiptDetailObj->insert();
  5309. $reviseSum+=$value['price'];
  5310. }
  5311. $itemStatistics=new itemStatistics();
  5312. $itemStatistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5313. $itemStatistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5314. $itemStatistics->price=$reviseSum;
  5315. $itemStatistics->itemCategory="报销金额调整";
  5316. $itemStatistics->date=$receiptDetail['date'];
  5317. $itemStatistics->insert();
  5318. }
  5319. $receiptDetailObj=new receiptDetail();
  5320. $receiptDetailObj->status=1;
  5321. $receiptDetailObj->pastDate=date("Y-m-d");
  5322. $receiptDetailObj->update(array('where'=>'rid='.$rid));
  5323. $dateArray=explode("-", $receiptDetail['date']);
  5324. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5325. $stat=$statistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].$dateCondition,'asArray'=>true));
  5326. if(empty($stat)){
  5327. $statistics->date=$receiptDetail['date'];
  5328. $statistics->cid=$receiptDetail['cid'];//$this->staff[0]['cid'];
  5329. $statistics->staff=$receiptDetail['staff'];//$this->staff[0]['sid'];
  5330. $statistics->agPrice=$receiptDetail['sum'];
  5331. $statistics->rePrice=$reviseSum;
  5332. $statistics->insert();
  5333. }else{
  5334. $statistics->agPrice=$stat['agPrice']+$receiptDetail['sum'];
  5335. $statistics->rePrice=$stat['rePrice']+$reviseSum;
  5336. $statistics->update(array('where'=>'sid='.$stat['sid']));
  5337. }
  5338. $dateArray=explode("-", $receiptDetail['date']);
  5339. $dateCondition=" and Year(date) =".$dateArray[0]." and Month(date) = ".$dateArray[1];
  5340. $accountItem=json_decode($receiptDetail['accountItem'],true);
  5341. foreach ($accountItem['cSum'] as $key=>$value){
  5342. if($key=="agencySum"){
  5343. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->AGENCY.'"'.$dateCondition,'asArray'=>true));
  5344. if(empty($iStatistics)){
  5345. $itemStatistics->cid=$receiptDetail['cid'];;
  5346. $itemStatistics->staff=$receiptDetail['staff'];
  5347. $itemStatistics->price=$value;
  5348. $itemStatistics->itemCategory=$this->AGENCY;
  5349. $itemStatistics->date=$receiptDetail['date'];
  5350. $itemStatistics->insert();
  5351. }else{
  5352. if (!empty($value)){
  5353. $itemStatistics->price=$value+$iStatistics['price'];
  5354. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5355. }
  5356. }
  5357. }elseif($key=="travelSum"){
  5358. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAVEL.'"'.$dateCondition,'asArray'=>true));
  5359. if(empty($iStatistics)){
  5360. $itemStatistics->cid=$receiptDetail['cid'];
  5361. $itemStatistics->staff=$receiptDetail['staff'];
  5362. $itemStatistics->price=$value;
  5363. $itemStatistics->itemCategory=$this->TRAVEL;
  5364. $itemStatistics->date=$receiptDetail['date'];
  5365. $itemStatistics->insert();
  5366. }else{
  5367. if (!empty($value)){
  5368. $itemStatistics->price=$value+$iStatistics['price'];
  5369. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5370. }
  5371. }
  5372. }elseif($key=="trainSum"){
  5373. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->TRAIN.'"'.$dateCondition,'asArray'=>true));
  5374. if(empty($iStatistics)){
  5375. $itemStatistics->cid=$receiptDetail['cid'];
  5376. $itemStatistics->staff=$receiptDetail['staff'];
  5377. $itemStatistics->price=$value;
  5378. $itemStatistics->itemCategory=$this->TRAIN;
  5379. $itemStatistics->date=$receiptDetail['date'];
  5380. $itemStatistics->insert();
  5381. }else{
  5382. if (!empty($value)){
  5383. $itemStatistics->price=$value+$iStatistics['price'];
  5384. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5385. }
  5386. }
  5387. }elseif($key=="otherSum"){
  5388. $iStatistics=$itemStatistics->getOne(array('where'=>'staff='.$receiptDetail['staff'].' and itemCategory="'.$this->OTHER.'"'.$dateCondition,'asArray'=>true));
  5389. if(empty($iStatistics)){
  5390. $itemStatistics->cid=$receiptDetail['cid'];
  5391. $itemStatistics->staff=$receiptDetail['staff'];
  5392. $itemStatistics->price=$value;
  5393. $itemStatistics->itemCategory=$this->OTHER;
  5394. $itemStatistics->date=$receiptDetail['date'];
  5395. $itemStatistics->insert();
  5396. }else{
  5397. if (!empty($value)){
  5398. $itemStatistics->price=$value+$iStatistics['price'];
  5399. $itemStatistics->update(array('where'=>'sid='.$iStatistics['sid']));
  5400. }
  5401. }
  5402. }
  5403. }
  5404. $receipt->pastDate=date("Y-m-d");
  5405. //微信企业号通知
  5406. $this->setWXMsg($rid,1);
  5407. }
  5408. $receipt->update(array('where'=>' rid = '.$rid));
  5409. return "/approvalExpenses/2";
  5410. }
  5411. }
  5412. function expensesRetreats(){
  5413. $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5414. if (!empty($rid)){
  5415. //操作记录
  5416. Doo::loadModel("receipt");
  5417. $receipt=new receipt();
  5418. Doo::loadModel("receiptLog");
  5419. $receiptLog=new receiptLog();
  5420. Doo::loadModel("verify");
  5421. $verify=new verify();
  5422. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5423. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5424. $jd=json_decode($vr['staff']);$roleId=0;
  5425. foreach ($jd as $key=>$value){
  5426. if ($value[1]=='ROLE'){
  5427. $pos = strpos($value[3], $this->staff[0]['sid']);
  5428. if ($pos !== false) {
  5429. $roleId=$value[0];
  5430. }
  5431. }
  5432. }
  5433. //审批日志
  5434. //echo $roleId;die;
  5435. if (!empty($roleId)){
  5436. Doo::loadModel("role");
  5437. $role=new role();
  5438. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5439. $receiptLog->rolename=$roleInfo['name'];
  5440. }
  5441. $receiptLog->username=$this->staff[0]['username'];
  5442. $receiptLog->uid=$this->staff[0]['sid'];
  5443. $receiptLog->date=date("Y-m-d");
  5444. $receiptLog->opinion='撤回';
  5445. $receiptLog->img=$this->staff[0]['avatar'];
  5446. $receiptLog->status=4;
  5447. $receiptLog->rid=$rid;
  5448. $receiptLog->insert();
  5449. $receipt->status=4;
  5450. $receipt->update(array('where'=>'rid='.$rid));
  5451. //微信企业号通知
  5452. $this->setWXMsg($rid,2);
  5453. }
  5454. //echo "ddd";
  5455. return '/approvalExpenses';
  5456. }
  5457. function updateCheReceipt(){
  5458. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5459. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  5460. //$rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  5461. if (!empty($rid)){
  5462. //操作记录
  5463. Doo::loadModel("receipt");
  5464. $receipt=new receipt();
  5465. Doo::loadModel("receiptLog");
  5466. $receiptLog=new receiptLog();
  5467. Doo::loadModel("verify");
  5468. $verify=new verify();
  5469. $receiptInfo=$receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  5470. $vr=$verify->getOne(array('where'=>'vid='.$receiptInfo['verify'],'asArray'=>true));
  5471. $jd=json_decode($vr['staff']);$roleId=0;
  5472. foreach ($jd as $key=>$value){
  5473. if ($value[1]=='ROLE'){
  5474. $pos = strpos($value[3], $this->staff[0]['sid']);
  5475. if ($pos !== false) {
  5476. $roleId=$value[0];
  5477. }
  5478. }
  5479. }
  5480. //审批日志
  5481. //echo $roleId;die;
  5482. if (!empty($roleId)){
  5483. Doo::loadModel("role");
  5484. $role=new role();
  5485. $roleInfo=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true));
  5486. $receiptLog->rolename=$roleInfo['name'];
  5487. }
  5488. $receiptLog->username=$this->staff[0]['username'];
  5489. $receiptLog->uid=$this->staff[0]['sid'];
  5490. $receiptLog->date=date("Y-m-d");
  5491. $receiptLog->opinion=$opinion;
  5492. $receiptLog->img=$this->staff[0]['avatar'];
  5493. $receiptLog->status=4;
  5494. $receiptLog->rid=$rid;
  5495. $receiptLog->insert();
  5496. $receipt->status=4;
  5497. $receipt->update(array('where'=>'rid='.$rid));
  5498. //微信企业号通知
  5499. $this->setWXMsg($rid,2);
  5500. echo json_encode ( array (
  5501. 'status' => 1
  5502. ) );die;
  5503. }
  5504. echo json_encode ( array (
  5505. 'status' => 2
  5506. ) );die;
  5507. //echo "ddd";
  5508. //return '/saeaBorad';
  5509. }
  5510. function revisePrice(){
  5511. $description=$this->get_args('description')?$this->get_args('description'):"";
  5512. $price=$this->get_args('price')&&is_numeric($this->get_args('price'))?$this->get_args('price'):0;
  5513. $rid=$this->get_args('rid')&&is_numeric($this->get_args('rid'))?$this->get_args('rid'):0;
  5514. //echo $price;die;
  5515. if (!empty($rid)){
  5516. Doo::loadModel("receipt");
  5517. $receipt=new receipt();
  5518. $receiptDetail=$receipt->getOne(array('where'=>'rid='.$rid.' and status=2 ','asArray'=>true));
  5519. if (empty($receiptDetail))
  5520. return "/approval";
  5521. $reviseDetail=array();
  5522. if (empty($receiptDetail['reviseDetail'])){
  5523. array_push($reviseDetail, array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5524. $reviseDetailString=json_encode($reviseDetail);
  5525. $receipt->reviseDetail=$reviseDetailString;
  5526. $receipt->revisePrice=$price;
  5527. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5528. }else{
  5529. $reviseDetail=json_decode($receiptDetail['reviseDetail'],true);
  5530. array_push($reviseDetail,array('sid'=>$this->staff[0]['sid'],'name'=>$this->staff[0]['username'],'description'=>$description,'price'=>$price));
  5531. $reviseDetailString=json_encode($reviseDetail);
  5532. $receipt->reviseDetail=$reviseDetailString;
  5533. $receipt->revisePrice=round($price,2)+round($receiptDetail['revisePrice'],2);
  5534. $receipt->sum=bcadd($receiptDetail['sum'],$price,2);
  5535. }
  5536. $receipt->update(array('where'=>'rid='.$rid));
  5537. }
  5538. return '/approvalEdi/'.$rid;
  5539. }
  5540. function personalCollect(){
  5541. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5542. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollect_".$year.".htmls";
  5543. $this->showCache($path);
  5544. Doo::loadModel("receiptDetail");
  5545. Doo::loadModel("itemStatistics");
  5546. Doo::loadModel('statistics');
  5547. $statistics=new statistics();
  5548. $itemStatistics=new itemStatistics();
  5549. $receiptDetail=new receiptDetail();
  5550. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5551. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5552. $data['itemStatisticsList']=$itemStatistics->find(array('where'=>'staff='.$this->staff[0]['sid'],'asArray'=>true));
  5553. //create collect html
  5554. $collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5555. $adjustment=array();
  5556. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用');
  5557. array_push($collectArray['日常相关费用'], $collectHtml);
  5558. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用');
  5559. array_push($collectArray['差旅相关费用'], $collectHtml);
  5560. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用');
  5561. array_push($collectArray['培训班费用'], $collectHtml);
  5562. $collectHtml=$this->collectHtml($receiptCollectList,'其他');
  5563. array_push($collectArray['其他'], $collectHtml);
  5564. $data['collectArray']=$collectArray;
  5565. //statistics html
  5566. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5567. if(empty($stList))
  5568. $stList=array('rePrice'=>0,'agPrice'=>0);
  5569. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5570. //Adjustment price html
  5571. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5572. array_push($adjustment, $collectHtml);
  5573. $data['adjustment']=$adjustment;
  5574. //total price html
  5575. $collectHtml="";$total=0;
  5576. for ($i=1;$i<=12;$i++){
  5577. $sumPrice=0;
  5578. foreach ($receiptCollectList as $key=>$value){
  5579. if($value['month']==$i){
  5580. $sumPrice+=$value['price'];
  5581. }
  5582. }
  5583. if ($sumPrice==0)
  5584. $collectHtml.='<td class="taR">-</td>';
  5585. else
  5586. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5587. $total+=$sumPrice;
  5588. }
  5589. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5590. $data['totalPrice']=$collectHtml;
  5591. $data['year']=$year;
  5592. $data['totalYear']=$total;
  5593. $data['memu']="receipt";
  5594. $data['staff']=$this->staff;
  5595. $data['receiptMemu']='personalCollect';
  5596. $data['verifyId']=$this->verifyId;
  5597. $data['executeId']=$this->executeId;
  5598. //year staff status 2,4
  5599. if($year<date("Y")){
  5600. Doo::loadModel('receipt');
  5601. $receipt=new receipt();
  5602. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5603. if(empty($receiptList)){
  5604. ob_start();
  5605. $this->render ( "/admin/saea_slist_collect", $data );
  5606. $this->cacheFile($path);die;
  5607. }
  5608. }
  5609. $this->render ( "/admin/saea_slist_collect", $data );
  5610. }
  5611. function personalCollectDetail(){
  5612. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5613. $path=SITE_PATH.$this->PERSONALCOLLECTCACHEPATH."personalCollectDetail_".$year.".htmls";
  5614. $this->showCache($path);
  5615. Doo::loadModel("receiptDetail");
  5616. Doo::loadModel("itemStatistics");
  5617. Doo::loadModel('statistics');
  5618. Doo::loadModel('accountItem');
  5619. $accountItem=new accountItem();
  5620. $statistics=new statistics();
  5621. $itemStatistics=new itemStatistics();
  5622. $receiptDetail=new receiptDetail();
  5623. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  5624. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'item,Month(date)','asArray'=>true));
  5625. $accountList=$accountItem->find(array('asArray'=>true));
  5626. //create CollectDetail HTML
  5627. $collectHtml=array();
  5628. foreach ($accountList as $key=>$value){
  5629. $html="";$asum=0;
  5630. for ($i=1;$i<=12;$i++){
  5631. $falg=true;
  5632. foreach ($receiptCollectList as $v) {
  5633. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5634. $asum+=$v['price'];
  5635. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5636. }
  5637. }
  5638. if($falg)
  5639. $html.='<td class="taR">-</td>';
  5640. }
  5641. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5642. $collectHtml[$value['category']][$value['name']]=$html;
  5643. }
  5644. $data['collectHtml']=$collectHtml;
  5645. //create Adjustment price html
  5646. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(date) as month',
  5647. 'where'=>'staff='.$this->staff[0]['sid']." and status=1 and Year(date)=".$year,'groupby'=>'itemCategory,Month(date)','asArray'=>true));
  5648. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5649. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5650. array_push($collectArray['日常相关费用'], $collectHtml);
  5651. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5652. array_push($collectArray['差旅相关费用'], $collectHtml);
  5653. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5654. array_push($collectArray['培训班费用'], $collectHtml);
  5655. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5656. array_push($collectArray['其他'], $collectHtml);
  5657. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5658. array_push($adjustment, $collectHtml);
  5659. //total price html
  5660. $collectHtml="";$total=0;
  5661. for ($i=1;$i<=12;$i++){
  5662. $sumPrice=0;
  5663. foreach ($receiptCollectList as $key=>$value){
  5664. if($value['month']==$i){
  5665. $sumPrice+=$value['price'];
  5666. }
  5667. }
  5668. if ($sumPrice==0)
  5669. $collectHtml.='<td class="taR">-</td>';
  5670. else
  5671. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5672. $total+=$sumPrice;
  5673. }
  5674. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5675. //statistics html
  5676. $stList=$statistics->statisticsByYear($year,$this->staff[0]['sid']);
  5677. if(empty($stList))
  5678. $stList=array('rePrice'=>0,'agPrice'=>0);
  5679. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5680. $data['collectArray']=$collectArray;
  5681. $data['adjustment']=$adjustment;
  5682. $data['totalPrice']=$collectHtml;
  5683. $data['totalYear']=$total;
  5684. $data['year']=$year;
  5685. $data['memu']="receipt";
  5686. $data['staff']=$this->staff;
  5687. $data['receiptMemu']='personalCollect';
  5688. $data['verifyId']=$this->verifyId;
  5689. $data['executeId']=$this->executeId;
  5690. //year staff status 2,4
  5691. if($year<date("Y")){
  5692. Doo::loadModel('receipt');
  5693. $receipt=new receipt();
  5694. $receiptList=$receipt->find(array('where'=>'staff='.$this->staff[0]['sid'].' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5695. if(empty($receiptList)){
  5696. ob_start();
  5697. $this->render ( "/admin/saeaCollectArticles", $data );
  5698. $this->cacheFile($path);die;
  5699. }
  5700. }
  5701. $this->render ( "/admin/saeaCollectArticles", $data );
  5702. }
  5703. function companyCategoryCollect(){
  5704. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5705. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollect_".$year.".htmls";
  5706. $this->showCache($path);
  5707. Doo::loadModel('L_category');
  5708. Doo::loadModel('itemStatistics');
  5709. Doo::loadModel('statistics');
  5710. $statistics=new statistics();
  5711. $Lcategory=new L_category();
  5712. $itemStatistics=new itemStatistics();
  5713. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5714. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5715. 'where'=>" Year(date)=".$year,'groupby'=>'cid,Month(date)','asArray'=>true));
  5716. //ceatre companyCollectHtml
  5717. foreach ($LcategoryList as $value){
  5718. $html="";$asum=0;
  5719. for ($i=1;$i<=12;$i++){
  5720. $falg=true;
  5721. foreach ($itemStatisticsList as $v){
  5722. if($value['cid']==$v['cid']&&$i==$v['month']){
  5723. $asum+=$v['price'];
  5724. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5725. }
  5726. }
  5727. if($falg)
  5728. $html.='<td class="taR">-</td>';
  5729. }
  5730. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5731. $collectHtml[$value['title']]=array('html'=>$html,'cid'=>$value['cid']);
  5732. }
  5733. $data['companyHtml']=$collectHtml;
  5734. //total price html
  5735. $collectHtml="";$total=0;
  5736. for ($i=1;$i<=12;$i++){
  5737. $sumPrice=0;
  5738. foreach ($itemStatisticsList as $key=>$value){
  5739. if($value['month']==$i){
  5740. $sumPrice+=$value['price'];
  5741. }
  5742. }
  5743. if ($sumPrice==0)
  5744. $collectHtml.='<td class="taR">-</td>';
  5745. else
  5746. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5747. $total+=$sumPrice;
  5748. }
  5749. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5750. $data['companyTotalHtml']=$collectHtml;
  5751. $data['total']=$total;
  5752. //statistics html
  5753. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5754. if(empty($stList))
  5755. $stList=array('rePrice'=>0,'agPrice'=>0);
  5756. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5757. $data['year']=$year;
  5758. $data['memu']="receipt";
  5759. $data['staff']=$this->staff;
  5760. $data['receiptMemu']='companyCategoryCollect';
  5761. $data['verifyId']=$this->verifyId;
  5762. $data['executeId']=$this->executeId;
  5763. //year staff status 2,4
  5764. if($year<date("Y")){
  5765. Doo::loadModel('receipt');
  5766. $receipt=new receipt();
  5767. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and (status=2 or status=4)','asArray'=>true));
  5768. if(empty($receiptList)){
  5769. ob_start();
  5770. $this->render ( "/admin/saeaCompanyCollect", $data );
  5771. $this->cacheFile($path);die;
  5772. }
  5773. }
  5774. $this->render ( "/admin/saeaCompanyCollect", $data );
  5775. }
  5776. function categoryCollectDetail(){
  5777. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5778. $cid=isset($this->params['cid'])&&is_numeric($this->params['cid'])?$this->params['cid']:0;
  5779. $path=SITE_PATH.$this->CATEGORYCOLLECTPATH."categoryCollectDetail_".$year."_".$cid.".htmls";
  5780. $this->showCache($path);
  5781. Doo::loadModel('statistics');
  5782. $statistics=new statistics();
  5783. Doo::loadModel("receiptDetail");
  5784. $receiptDetail=new receiptDetail();
  5785. Doo::loadModel('L_category');
  5786. $Lcategory=new L_category();
  5787. Doo::loadModel('accountItem');
  5788. $accountItem=new accountItem();
  5789. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  5790. if ($cid==0){
  5791. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  5792. if ($cid==0)
  5793. $cid=$LcategoryList[0]['cid'];
  5794. }
  5795. $data['LcategoryList']=$LcategoryList;
  5796. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  5797. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate)','asArray'=>true));
  5798. $accountList=$accountItem->find(array('asArray'=>true));
  5799. //create CollectDetail HTML
  5800. $collectHtml=array();
  5801. foreach ($accountList as $key=>$value){
  5802. $html="";$asum=0;
  5803. for ($i=1;$i<=12;$i++){
  5804. $falg=true;
  5805. foreach ($receiptCollectList as $v) {
  5806. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  5807. $asum+=$v['price'];
  5808. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5809. }
  5810. }
  5811. if($falg)
  5812. $html.='<td class="taR">-</td>';
  5813. }
  5814. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5815. $collectHtml[$value['category']][$value['name']]=$html;
  5816. }
  5817. $data['collectHtml']=$collectHtml;
  5818. //create Adjustment price html
  5819. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  5820. 'where'=>'cid='.$cid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  5821. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  5822. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  5823. array_push($collectArray['日常相关费用'], $collectHtml);
  5824. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  5825. array_push($collectArray['差旅相关费用'], $collectHtml);
  5826. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  5827. array_push($collectArray['培训班费用'], $collectHtml);
  5828. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  5829. array_push($collectArray['其他'], $collectHtml);
  5830. $data['collectArray']=$collectArray;
  5831. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  5832. array_push($adjustment, $collectHtml);
  5833. $data['adjustment']=$adjustment;
  5834. //total price html
  5835. $collectHtml="";$total=0;
  5836. for ($i=1;$i<=12;$i++){
  5837. $sumPrice=0;
  5838. foreach ($receiptCollectList as $key=>$value){
  5839. if($value['month']==$i){
  5840. $sumPrice+=$value['price'];
  5841. }
  5842. }
  5843. if ($sumPrice==0)
  5844. $collectHtml.='<td class="taR">-</td>';
  5845. else
  5846. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5847. $total+=$sumPrice;
  5848. }
  5849. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5850. //statistics html
  5851. $stList=$statistics->statisticsByCid($year,$cid);
  5852. if(empty($stList))
  5853. $stList=array('rePrice'=>0,'agPrice'=>0);
  5854. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5855. $data['totalYear']=$total;
  5856. $data['year']=$year;
  5857. $data['cid']=$cid;
  5858. $data['memu']="receipt";
  5859. $data['staff']=$this->staff;
  5860. $data['receiptMemu']='companyCategoryCollect';
  5861. $data['verifyId']=$this->verifyId;
  5862. $data['executeId']=$this->executeId;
  5863. //year staff status 2,4
  5864. if($year<date("Y")){
  5865. Doo::loadModel('receipt');
  5866. $receipt=new receipt();
  5867. $receiptList=$receipt->find(array('where'=>'Year(date) ='.$year.' and cid ='.$cid.' and (status=2 or status=4)','asArray'=>true));
  5868. if(empty($receiptList)){
  5869. ob_start();
  5870. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5871. $this->cacheFile($path);die;
  5872. }
  5873. }
  5874. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  5875. }
  5876. function staffCollect(){
  5877. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  5878. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_.htmls";
  5879. //$this->showCache($path);
  5880. Doo::loadModel('statistics');
  5881. $statistics=new statistics();
  5882. Doo::loadModel("receiptDetail");
  5883. $receiptDetail=new receiptDetail();
  5884. Doo::loadModel('L_category');
  5885. $Lcategory=new L_category();
  5886. Doo::loadModel('accountItem');
  5887. $accountItem=new accountItem();
  5888. Doo::loadModel('staff');
  5889. $staff=new staff();
  5890. Doo::loadModel('itemStatistics');
  5891. $itemStatistics=new itemStatistics();
  5892. /*
  5893. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  5894. 'where'=>" Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  5895. if(empty($stList))
  5896. $stList=array('rePrice'=>0,'agPrice'=>0);
  5897. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5898. */
  5899. //statistics html
  5900. $stList=$statistics->statisticsByComPanyYear($year,$this->staff[0]['sid']);
  5901. if(empty($stList))
  5902. $stList=array('rePrice'=>0,'agPrice'=>0);
  5903. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  5904. //---
  5905. $staffList=$staff->find(array('where'=>'username !="admin"','asArray'=>true));
  5906. $LcategoryList=$Lcategory->find(array('asArray'=>true));//'staff='.$this->staff[0]['sid']." and
  5907. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  5908. 'where'=>" Year(date)=".$year,'groupby'=>'staff,Month(date)','asArray'=>true));
  5909. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  5910. //print_r($itemStatisticsList);die;
  5911. //ceatre companyCollectHtml
  5912. foreach ($categoryList as $vlu){
  5913. $count=$vlu['count']+1;
  5914. $html='<th rowspan="'.$count.'">'.$vlu['category'].'</th>';
  5915. $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;
  5916. foreach ($staffList as $value){
  5917. if ($vlu['cid']==$value['cid']){
  5918. $html.='<td><a href="/staffCollectDetail/'.$value['username'].'">'.$value['username'].'</a></td>';
  5919. $asum=0;
  5920. for ($i=1;$i<=12;$i++){
  5921. $falg=true;
  5922. foreach ($itemStatisticsList as $v){
  5923. if($value['sid']==$v['staff']&&$i==$v['month']){
  5924. if ($v['month']==1)
  5925. $m1+=$v['price'];
  5926. if ($v['month']==2)
  5927. $m2+=$v['price'];
  5928. if ($v['month']==3)
  5929. $m3+=$v['price'];
  5930. if ($v['month']==4)
  5931. $m4+=$v['price'];
  5932. if ($v['month']==5)
  5933. $m5+=$v['price'];
  5934. if ($v['month']==6)
  5935. $m6+=$v['price'];
  5936. if ($v['month']==7)
  5937. $m7+=$v['price'];
  5938. if ($v['month']==8)
  5939. $m8+=$v['price'];
  5940. if ($v['month']==9)
  5941. $m9+=$v['price'];
  5942. if ($v['month']==10)
  5943. $m10+=$v['price'];
  5944. if ($v['month']==11)
  5945. $m11+=$v['price'];
  5946. if ($v['month']==12)
  5947. $m12+=$v['price'];
  5948. $asum+=$v['price'];
  5949. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  5950. }
  5951. }
  5952. if($falg)
  5953. $html.='<td class="taR">-</td>';
  5954. }
  5955. $m13+=$asum;
  5956. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  5957. $collectHtml[$value['username']]=array('html'=>$html,'sid'=>$value['sid']);
  5958. $html="";
  5959. }
  5960. }
  5961. $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>
  5962. <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>
  5963. <td class="taR">¥'.$m12.'</td><td class="taR">¥'.$m13.'</td>';
  5964. $collectHtml[$vlu['cid']]=array('html'=>$hl,'sid'=>'');
  5965. }
  5966. $data['companyHtml']=$collectHtml;
  5967. //total price html
  5968. $collectHtml="";$total=0;
  5969. for ($i=1;$i<=12;$i++){
  5970. $sumPrice=0;
  5971. foreach ($itemStatisticsList as $key=>$value){
  5972. if($value['month']==$i){
  5973. $sumPrice+=$value['price'];
  5974. }
  5975. }
  5976. if ($sumPrice==0)
  5977. $collectHtml.='<td class="taR">-</td>';
  5978. else
  5979. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  5980. $total+=$sumPrice;
  5981. }
  5982. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  5983. $data['companyTotalHtml']=$collectHtml;
  5984. $data['total']=$total;
  5985. $data['year']=$year;
  5986. $data['memu']="receipt";
  5987. $data['staff']=$this->staff;
  5988. $data['receiptMemu']='companyCategoryCollect';
  5989. $data['verifyId']=$this->verifyId;
  5990. $data['executeId']=$this->executeId;
  5991. if ($year<=date("Y")){
  5992. Doo::loadModel('receipt');
  5993. $receipt=new receipt();
  5994. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  5995. if(empty($receiptList)){ //generated files
  5996. ob_start();
  5997. $this->render ( "/admin/saeaStaffCollectB", $data );
  5998. $this->cacheFile($path);die;
  5999. }
  6000. }
  6001. $this->render ( "/admin/saeaStaffCollectB", $data );
  6002. }
  6003. function staffCollectBak(){
  6004. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6005. $month=$this->get_args('month')?$this->get_args('month'):1;
  6006. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollect_".$year."_".$month.".htmls";
  6007. $this->showCache($path);
  6008. Doo::loadModel('statistics');
  6009. $statistics=new statistics();
  6010. Doo::loadModel("receiptDetail");
  6011. $receiptDetail=new receiptDetail();
  6012. Doo::loadModel('L_category');
  6013. $Lcategory=new L_category();
  6014. Doo::loadModel('accountItem');
  6015. $accountItem=new accountItem();
  6016. Doo::loadModel('staff');
  6017. $staff=new staff();
  6018. Doo::loadModel('itemStatistics');
  6019. $itemStatistics=new itemStatistics();
  6020. $itemStatisticsList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6021. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'staff,itemCategory,Month(date)','asArray'=>true));
  6022. $itemCategoryList=$itemStatistics->find(array('select'=>'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  6023. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'cid,itemCategory,Month(date)','asArray'=>true));
  6024. $LcategoryList=$Lcategory->find(array('asArray'=>true));
  6025. $staffList=$staff->find(array('asArray'=>true));
  6026. $htmlArray=array();
  6027. foreach ($LcategoryList as $value){
  6028. $htmlArray[$value['title']]=array();
  6029. foreach ($staffList as $v){
  6030. if($value['cid']==$v['cid']){
  6031. $html="";$falg=true;$staffSumPrice=0;
  6032. foreach ($itemStatisticsList as $a){
  6033. if($v['sid']==$a['staff']&&$a['itemCategory']=="日常相关费用"){
  6034. if(empty($a['price'])){
  6035. $html.='<td class="taR">-</td>';$falg=false;break;
  6036. }else{
  6037. $staffSumPrice+=$a['price'];
  6038. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6039. }
  6040. }
  6041. }
  6042. if ($falg){
  6043. $html.='<td class="taR">-</td>';$falg=true;
  6044. }
  6045. $falg=true;
  6046. foreach ($itemStatisticsList as $a){
  6047. if($v['sid']==$a['staff']&&$a['itemCategory']=="差旅相关费用"){
  6048. if(empty($a['price'])){
  6049. $html.='<td class="taR">-</td>';$falg=false;break;
  6050. }else{
  6051. $staffSumPrice+=$a['price'];
  6052. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6053. }
  6054. }
  6055. }
  6056. if ($falg){
  6057. $html.='<td class="taR">-</td>';$falg=true;
  6058. }
  6059. $falg=true;
  6060. foreach ($itemStatisticsList as $a){
  6061. if($v['sid']==$a['staff']&&$a['itemCategory']=="培训班费用"){
  6062. if(empty($a['price'])){
  6063. $html.='<td class="taR">-</td>';$falg=false;break;
  6064. }else{
  6065. $staffSumPrice+=$a['price'];
  6066. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6067. }
  6068. }
  6069. }
  6070. if ($falg){
  6071. $html.='<td class="taR">-</td>';$falg=true;
  6072. }
  6073. $falg=true;
  6074. foreach ($itemStatisticsList as $a){
  6075. if($v['sid']==$a['staff']&&$a['itemCategory']=="其他"){
  6076. if(!empty($a['price'])){
  6077. $staffSumPrice+=$a['price'];
  6078. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6079. }else{
  6080. $html.='<td class="taR">-</td>';$falg=false;break;
  6081. }
  6082. }
  6083. }
  6084. if ($falg){
  6085. $html.='<td class="taR">-</td>';$falg=true;
  6086. }
  6087. $falg=true;
  6088. foreach ($itemStatisticsList as $a){
  6089. if($v['sid']==$a['staff']&&$a['itemCategory']=="报销金额调整"){
  6090. if(!empty($a['price'])){
  6091. $staffSumPrice+=$a['price'];
  6092. $html.='<td class="taR">¥'.$a['price'].'</td>';$falg=false;break;
  6093. }else{
  6094. $html.='<td class="taR">-</td>';$falg=false;break;
  6095. }
  6096. }
  6097. }
  6098. if ($falg){
  6099. $html.='<td class="taR">-</td>';$falg=true;
  6100. }
  6101. $html.='<td class="colGreen taR">¥'.$staffSumPrice.'</td>';
  6102. $htmlArray[$value['title']][$v['username']]=$html;
  6103. }
  6104. }
  6105. /*-- ---*/
  6106. //合计费用
  6107. $cateHtml="";$catePrice=0;$cateFalg=true;
  6108. foreach ($itemCategoryList as $l){
  6109. if($value['cid']==$l['cid']&&$l['itemCategory']=="日常相关费用"){
  6110. if(empty($l['price'])){
  6111. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6112. }else{
  6113. $catePrice+=$l['price'];
  6114. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6115. }
  6116. }
  6117. }
  6118. if ($cateFalg){
  6119. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6120. }
  6121. $cateFalg=true;
  6122. foreach ($itemCategoryList as $l){
  6123. if($value['cid']==$l['cid']&&$l['itemCategory']=="差旅相关费用"){
  6124. if(empty($l['price'])){
  6125. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6126. }else{
  6127. $catePrice+=$l['price'];
  6128. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6129. }
  6130. }
  6131. }
  6132. if ($cateFalg){
  6133. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6134. }
  6135. $cateFalg=true;
  6136. foreach ($itemCategoryList as $l){
  6137. if($value['cid']==$l['cid']&&$l['itemCategory']=="培训班费用"){
  6138. if(empty($l['price'])){
  6139. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6140. }else{
  6141. $catePrice+=$l['price'];
  6142. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6143. }
  6144. }
  6145. }
  6146. if ($cateFalg){
  6147. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6148. }
  6149. $cateFalg=true;
  6150. foreach ($itemCategoryList as $l){
  6151. if($value['cid']==$l['cid']&&$l['itemCategory']=="其他"){
  6152. if(empty($l['price'])){
  6153. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6154. }else{
  6155. $catePrice+=$l['price'];
  6156. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6157. }
  6158. }
  6159. }
  6160. if ($cateFalg){
  6161. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6162. }
  6163. $cateFalg=true;
  6164. foreach ($itemCategoryList as $l){
  6165. if($value['cid']==$l['cid']&&$l['itemCategory']=="报销金额调整"){
  6166. if(empty($l['price'])){
  6167. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=false;break;
  6168. }else{
  6169. $catePrice+=$l['price'];
  6170. $cateHtml.='<td class="colGreen taR">¥'.$l['price'].'</td>';$cateFalg=false;break;
  6171. }
  6172. }
  6173. }
  6174. if ($cateFalg){
  6175. $cateHtml.='<td class="colGreen taR">-</td>';$cateFalg=true;
  6176. }
  6177. $cateHtml.='<td class="colGreen taR">¥'.$catePrice.'</td>';
  6178. $htmlArray[$value['title']]['合计']=$cateHtml;
  6179. /*-- ---*/
  6180. }
  6181. //print_r($htmlArray);die;
  6182. $data['htmlArray']=$htmlArray;
  6183. //statistics html
  6184. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6185. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6186. if(empty($stList))
  6187. $stList=array('rePrice'=>0,'agPrice'=>0);
  6188. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6189. $monthHtml="";
  6190. for ($i=1;$i<=12;$i++){
  6191. if ($i==$month)
  6192. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6193. else
  6194. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6195. }
  6196. $data['monthHtml']=$monthHtml;
  6197. $data['year']=$year;
  6198. $data['month']=$month;
  6199. $data['memu']="receipt";
  6200. $data['staff']=$this->staff;
  6201. $data['receiptMemu']='companyCategoryCollect';
  6202. $data['verifyId']=$this->verifyId;
  6203. $data['executeId']=$this->executeId;
  6204. if (!empty($month)&&($year<=date("Y"))&&($month<date("m"))){
  6205. Doo::loadModel('receipt');
  6206. $receipt=new receipt();
  6207. $receiptList=$receipt->find(array('where'=>'(status=2 or status=4) and Year(date) ='.$year.' and Month(date) ='.$month,'asArray'=>true));
  6208. if(empty($receiptList)){ //generated files
  6209. ob_start();
  6210. $this->render ( "/admin/saeaStaffCollect", $data );
  6211. $this->cacheFile($path);die;
  6212. }
  6213. }
  6214. $this->render ( "/admin/saeaStaffCollect", $data );
  6215. }
  6216. function lyt(){
  6217. Doo::loadModel("receiptDetail");
  6218. $receiptDetail=new receiptDetail();
  6219. $receiptCollectList=$receiptDetail->find(array('where'=>'status=1 ','asArray'=>true));
  6220. foreach ($receiptCollectList as $key=>$value){
  6221. $receiptDetail=new receiptDetail();
  6222. $receiptDetail->pastDate=$value['date'];
  6223. $receiptDetail->update(array('where' => "rdid= '".$value['rdid']."'"));
  6224. }
  6225. }
  6226. function staffCollectMonthDetail(){
  6227. $year=$this->get_args('year')?$this->get_args('year'):"";
  6228. $month=$this->get_args('month')?$this->get_args('month'):"";
  6229. if(!$year)
  6230. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6231. if(!$month)
  6232. $month=isset($this->params['month'])?$this->params['month']:1;
  6233. Doo::loadModel('staff');
  6234. $staff=new staff();
  6235. Doo::loadModel("receiptDetail");
  6236. $receiptDetail=new receiptDetail();
  6237. Doo::loadModel('accountItem');
  6238. $accountItem=new accountItem();
  6239. Doo::loadModel('statistics');
  6240. $statistics=new statistics();
  6241. Doo::loadModel('L_category');
  6242. $lCategory=new L_category();
  6243. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6244. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6245. $list=array();
  6246. foreach ($categoryList as $vlu){
  6247. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6248. $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;
  6249. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6250. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6251. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6252. $s1=0;
  6253. $m1=0;
  6254. foreach ($staffList as $value){
  6255. if ($vlu['cid']==$value['cid']){
  6256. //pastDate
  6257. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6258. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6259. // if ($value['sid']==42){
  6260. // print_r($receiptCollectList);die;
  6261. // }
  6262. if(!empty($receiptCollectList)){
  6263. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6264. $html="";
  6265. $psum=0;
  6266. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6267. foreach ($item as $va){
  6268. $falg=true;
  6269. foreach ($receiptCollectList as $v){
  6270. if($v['itemCategory']=='日常相关费用'){
  6271. if($v['item']==$va){
  6272. if ($va=='市内交通费')
  6273. $r1+=$v['price'];
  6274. if ($va=='市内出租费')
  6275. $r2+=$v['price'];
  6276. if ($va=='办事处房租')
  6277. $r3+=$v['price'];
  6278. if ($va=='电话费')
  6279. $r4+=$v['price'];
  6280. if ($va=='水费')
  6281. $r5+=$v['price'];
  6282. if ($va=='电费')
  6283. $r6+=$v['price'];
  6284. if ($va=='办公费用')
  6285. $r7+=$v['price'];
  6286. if ($va=='邮寄费')
  6287. $r8+=$v['price'];
  6288. if ($va=='其他费用')
  6289. $r9+=$v['price'];
  6290. if ($va=='车辆费用')
  6291. $r10+=$v['price'];
  6292. if ($va=='广告费')
  6293. $r11+=$v['price'];
  6294. if ($va=='团队建设费')
  6295. $r13+=$v['price'];
  6296. if ($va=='物业管理费')
  6297. $r14+=$v['price'];
  6298. if ($va=='宽带费')
  6299. $r15+=$v['price'];
  6300. $psum+=$v['price'];
  6301. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6302. }
  6303. }
  6304. }
  6305. if($falg)
  6306. $html.='<td class="taR">-</td>';
  6307. }
  6308. $r12+=$psum;
  6309. if(!empty($psum))
  6310. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6311. else
  6312. $psum='<td class="colGreen taR">-</td>';
  6313. $receiptL['日常相关费用']=$psum.$html;
  6314. /*-----------------------------------*/
  6315. $html="";
  6316. $psum=0;
  6317. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6318. foreach ($item as $va){
  6319. $falg=true;
  6320. foreach ($receiptCollectList as $v){
  6321. if($v['itemCategory']=='差旅相关费用'){
  6322. if($v['item']==$va){
  6323. if ($va=='往来交通费')
  6324. $c1+=$v['price'];
  6325. if ($va=='市内交通费')
  6326. $c2+=$v['price'];
  6327. if ($va=='出差住宿费')
  6328. $c3+=$v['price'];
  6329. if ($va=='出差补助')
  6330. $c4+=$v['price'];
  6331. if ($va=='其他费用')
  6332. $c5+=$v['price'];
  6333. $psum+=$v['price'];
  6334. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6335. }
  6336. }
  6337. }
  6338. if($falg)
  6339. $html.='<td class="taR">-</td>';
  6340. }
  6341. $c6+=$psum;
  6342. if(!empty($psum))
  6343. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6344. else
  6345. $psum='<td class="colGreen taR">-</td>';
  6346. $receiptL['差旅相关费用']=$psum.$html;
  6347. /*-------------------------------------*/
  6348. $html="";
  6349. $psum=0;
  6350. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6351. foreach ($item as $va){
  6352. $falg=true;
  6353. foreach ($receiptCollectList as $v){
  6354. if($v['itemCategory']=='培训班费用'){
  6355. if($v['item']==$va){
  6356. if ($va=='场租费')
  6357. $p1+=$v['price'];
  6358. if ($va=='薪酬')
  6359. $p2+=$v['price'];
  6360. if ($va=='住宿费')
  6361. $p3+=$v['price'];
  6362. if ($va=='交通费')
  6363. $p4+=$v['price'];
  6364. if ($va=='餐饮费')
  6365. $p5+=$v['price'];
  6366. if ($va=='办公费')
  6367. $p6+=$v['price'];
  6368. if ($va=='公关费')
  6369. $p7+=$v['price'];
  6370. if ($va=='其他')
  6371. $p8+=$v['price'];
  6372. $psum+=$v['price'];
  6373. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6374. }
  6375. }
  6376. }
  6377. if($falg)
  6378. $html.='<td class="taR">-</td>';
  6379. }
  6380. $p9+=$psum;
  6381. if(!empty($psum))
  6382. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6383. else
  6384. $psum='<td class="colGreen taR">-</td>';
  6385. $receiptL['培训班费用']=$psum.$html;
  6386. /*-------------------------------------*/
  6387. $html="";
  6388. $psum=0;
  6389. $item=array('公关费','广告费','借款','可自加费用');
  6390. foreach ($item as $va){
  6391. $falg=true;
  6392. foreach ($receiptCollectList as $v){
  6393. if($v['itemCategory']=='其他'){
  6394. // if ($value['sid']==42){
  6395. //
  6396. // echo var_dump($v['item']);
  6397. // echo var_dump($va);
  6398. // echo var_dump($v['item']==" ".$va);
  6399. // echo $v['item']."==".$va."/<br/>";
  6400. // //print_r( $receiptCollectList);//echo $va;
  6401. // }
  6402. if(trim($v['item'])==$va){
  6403. if ($va=='公关费')
  6404. $t1+=$v['price'];
  6405. if ($va=='广告费'){
  6406. $t2+=$v['price'];
  6407. }
  6408. if ($va=='借款')
  6409. $t3+=$v['price'];
  6410. if ($va=='可自加费用')
  6411. $t4+=$v['price'];
  6412. $psum+=$v['price'];
  6413. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6414. }
  6415. }
  6416. }
  6417. if($falg)
  6418. $html.='<td class="taR">-</td>';
  6419. }
  6420. $t5+=$psum;
  6421. if(!empty($psum))
  6422. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6423. else
  6424. $psum='<td class="colGreen taR">-</td>';
  6425. $receiptL['其他']=$psum.$html;
  6426. /*-------------------------------------*/
  6427. $html="";
  6428. $psum=0;
  6429. foreach ($receiptCollectList as $v){
  6430. if($v['itemCategory']=='报销金额调整'){
  6431. if (!empty($v['price'])){
  6432. $psum+=$v['price'];
  6433. }
  6434. }
  6435. }
  6436. $s1+=$psum;
  6437. if(!empty($psum))
  6438. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6439. else
  6440. $psum='<td class="taR colOrange">-</td>';
  6441. $receiptL['报销金额调整']=$psum.$html;
  6442. }else{
  6443. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6444. <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>
  6445. <td class="taR">-</td><td class="taR">-</td>';
  6446. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6447. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6448. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6449. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6450. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6451. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6452. }
  6453. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6454. 'where'=>'staff='.$value['sid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'Month(pastDate)','asArray'=>true));
  6455. //echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  6456. if(!empty($monthStaffPrice[0]['price'])){
  6457. $m1+=$monthStaffPrice[0]['price'];
  6458. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6459. }else
  6460. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6461. $list[$value['username']]=$receiptL;
  6462. }
  6463. }
  6464. $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>
  6465. <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>
  6466. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6467. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6468. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6469. $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>
  6470. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6471. $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>';
  6472. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6473. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6474. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6475. }
  6476. $data['list']=$list;
  6477. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6478. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6479. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6480. //statistics html
  6481. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6482. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6483. if(empty($stList))
  6484. $stList=array('rePrice'=>0,'agPrice'=>0);
  6485. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6486. $monthHtml="";
  6487. for ($i=1;$i<=12;$i++){
  6488. if ($i==$month)
  6489. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6490. else
  6491. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6492. }
  6493. $data['monthHtml']=$monthHtml;
  6494. $data['year']=$year;
  6495. $data['month']=$month;
  6496. $data['memu']="receipt";
  6497. $data['staff']=$this->staff;
  6498. $data['receiptMemu']='companyCategoryCollect';
  6499. $data['verifyId']=$this->verifyId;
  6500. $data['executeId']=$this->executeId;
  6501. $this->render ( "/admin/staffCollectMonthDetail", $data );
  6502. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6503. }
  6504. function staffCollectMonthDetail2(){
  6505. $year=$this->get_args('year')?$this->get_args('year'):"";
  6506. $month=$this->get_args('month')?$this->get_args('month'):"";
  6507. if(!$year)
  6508. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6509. if(!$month)
  6510. $month=isset($this->params['month'])?$this->params['month']:1;
  6511. Doo::loadModel('staff');
  6512. $staff=new staff();
  6513. Doo::loadModel("receiptDetail");
  6514. $receiptDetail=new receiptDetail();
  6515. Doo::loadModel('accountItem');
  6516. $accountItem=new accountItem();
  6517. Doo::loadModel('statistics');
  6518. $statistics=new statistics();
  6519. Doo::loadModel('L_category');
  6520. $lCategory=new L_category();
  6521. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6522. $categoryList=$staff->find(array('select'=>'COUNT(*) as count,cid,category','where'=>'username !="admin"','groupby'=>'cid','asArray'=>true));
  6523. $list=array();
  6524. foreach ($categoryList as $vlu){
  6525. //$html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  6526. $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;
  6527. $c1=0;$c2=0;$c3=0;$c4=0;$c5=0;$c6=0;
  6528. $p1=0;$p2=0;$p3=0;$p4=0;$p5=0;$p6=0;$p7=0;$p8=0;$p9=0;
  6529. $t1=0;$t2=0;$t3=0;$t4=0;$t5=0;
  6530. $s1=0;
  6531. $m1=0;
  6532. foreach ($staffList as $value){
  6533. if ($vlu['cid']==$value['cid']){
  6534. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6535. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6536. if(!empty($receiptCollectList)){
  6537. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6538. $html="";
  6539. $psum=0;
  6540. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  6541. foreach ($item as $va){
  6542. $falg=true;
  6543. foreach ($receiptCollectList as $v){
  6544. if($v['itemCategory']=='日常相关费用'){
  6545. if($v['item']==$va){
  6546. if ($va=='市内交通费')
  6547. $r1+=$v['price'];
  6548. if ($va=='市内出租费')
  6549. $r2+=$v['price'];
  6550. if ($va=='办事处房租')
  6551. $r3+=$v['price'];
  6552. if ($va=='电话费')
  6553. $r4+=$v['price'];
  6554. if ($va=='水费')
  6555. $r5+=$v['price'];
  6556. if ($va=='电费')
  6557. $r6+=$v['price'];
  6558. if ($va=='办公费用')
  6559. $r7+=$v['price'];
  6560. if ($va=='邮寄费')
  6561. $r8+=$v['price'];
  6562. if ($va=='其他费用')
  6563. $r9+=$v['price'];
  6564. if ($va=='车辆费用')
  6565. $r10+=$v['price'];
  6566. if ($va=='广告费')
  6567. $r11+=$v['price'];
  6568. if ($va=='团队建设费')
  6569. $r13+=$v['price'];
  6570. if ($va=='物业管理费')
  6571. $r14+=$v['price'];
  6572. if ($va=='宽带费')
  6573. $r15+=$v['price'];
  6574. $psum+=$v['price'];
  6575. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6576. }
  6577. }
  6578. }
  6579. if($falg)
  6580. $html.='<td class="taR">-</td>';
  6581. }
  6582. $r12+=$psum;
  6583. if(!empty($psum))
  6584. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6585. else
  6586. $psum='<td class="colGreen taR">-</td>';
  6587. $receiptL['日常相关费用']=$psum.$html;
  6588. /*-----------------------------------*/
  6589. $html="";
  6590. $psum=0;
  6591. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6592. foreach ($item as $va){
  6593. $falg=true;
  6594. foreach ($receiptCollectList as $v){
  6595. if($v['itemCategory']=='差旅相关费用'){
  6596. if($v['item']==$va){
  6597. if ($va=='往来交通费')
  6598. $c1+=$v['price'];
  6599. if ($va=='市内交通费')
  6600. $c2+=$v['price'];
  6601. if ($va=='出差住宿费')
  6602. $c3+=$v['price'];
  6603. if ($va=='出差补助')
  6604. $c4+=$v['price'];
  6605. if ($va=='其他费用')
  6606. $c5+=$v['price'];
  6607. $psum+=$v['price'];
  6608. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6609. }
  6610. }
  6611. }
  6612. if($falg)
  6613. $html.='<td class="taR">-</td>';
  6614. }
  6615. $c6+=$psum;
  6616. if(!empty($psum))
  6617. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6618. else
  6619. $psum='<td class="colGreen taR">-</td>';
  6620. $receiptL['差旅相关费用']=$psum.$html;
  6621. /*-------------------------------------*/
  6622. $html="";
  6623. $psum=0;
  6624. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6625. foreach ($item as $va){
  6626. $falg=true;
  6627. foreach ($receiptCollectList as $v){
  6628. if($v['itemCategory']=='培训班费用'){
  6629. if($v['item']==$va){
  6630. if ($va=='场租费')
  6631. $p1+=$v['price'];
  6632. if ($va=='薪酬')
  6633. $p2+=$v['price'];
  6634. if ($va=='住宿费')
  6635. $p3+=$v['price'];
  6636. if ($va=='交通费')
  6637. $p4+=$v['price'];
  6638. if ($va=='餐饮费')
  6639. $p5+=$v['price'];
  6640. if ($va=='办公费')
  6641. $p6+=$v['price'];
  6642. if ($va=='公关费')
  6643. $p7+=$v['price'];
  6644. if ($va=='其他')
  6645. $p8+=$v['price'];
  6646. $psum+=$v['price'];
  6647. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6648. }
  6649. }
  6650. }
  6651. if($falg)
  6652. $html.='<td class="taR">-</td>';
  6653. }
  6654. $p9+=$psum;
  6655. if(!empty($psum))
  6656. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6657. else
  6658. $psum='<td class="colGreen taR">-</td>';
  6659. $receiptL['培训班费用']=$psum.$html;
  6660. /*-------------------------------------*/
  6661. $html="";
  6662. $psum=0;
  6663. $item=array('公关费','广告费','借款','可自加费用');
  6664. foreach ($item as $va){
  6665. $falg=true;
  6666. foreach ($receiptCollectList as $v){
  6667. if($v['itemCategory']=='其他'){
  6668. if($v['item']==$va){
  6669. if ($va=='公关费')
  6670. $t1+=$v['price'];
  6671. if ($va=='广告费')
  6672. $t2+=$v['price'];
  6673. if ($va=='借款')
  6674. $t3+=$v['price'];
  6675. if ($va=='可自加费用')
  6676. $t4+=$v['price'];
  6677. $psum+=$v['price'];
  6678. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6679. }
  6680. }
  6681. }
  6682. if($falg)
  6683. $html.='<td class="taR">-</td>';
  6684. }
  6685. $t5+=$psum;
  6686. if(!empty($psum))
  6687. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6688. else
  6689. $psum='<td class="colGreen taR">-</td>';
  6690. $receiptL['其他']=$psum.$html;
  6691. /*-------------------------------------*/
  6692. $html="";
  6693. $psum=0;
  6694. foreach ($receiptCollectList as $v){
  6695. if($v['itemCategory']=='报销金额调整'){
  6696. if (!empty($v['price'])){
  6697. $psum+=$v['price'];
  6698. }
  6699. }
  6700. }
  6701. $s1+=$psum;
  6702. if(!empty($psum))
  6703. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6704. else
  6705. $psum='<td class="taR colOrange">-</td>';
  6706. $receiptL['报销金额调整']=$psum.$html;
  6707. }else{
  6708. $receiptL['日常相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6709. <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>';
  6710. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6711. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6712. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6713. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6714. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6715. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6716. }
  6717. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6718. 'where'=>'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month,'asArray'=>true));
  6719. if(!empty($monthStaffPrice[0]['price'])){
  6720. $m1+=$monthStaffPrice[0]['price'];
  6721. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6722. }else
  6723. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6724. $list[$value['username']]=$receiptL;
  6725. }
  6726. }
  6727. $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>
  6728. <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>
  6729. <td class="taR">'.$r14.'</td><td class="taR">'.$r15.'</td>';
  6730. $receiptL['差旅相关费用']='<td class="colGreen taR">'.$c6.'</td><td class="taR">'.$c1.'</td>
  6731. <td class="taR">'.$c2.'</td><td class="taR">'.$c3.'</td><td class="taR">'.$c4.'</td><td class="taR">'.$c5.'</td>';
  6732. $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>
  6733. <td class="taR">'.$p5.'</td><td class="taR">'.$p6.'</td><td class="taR">'.$p7.'</td><td class="taR">'.$p8.'</td>';
  6734. $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>';
  6735. $receiptL['报销金额调整']='<td class="taR colOrange">'.$s1.'</td>';
  6736. $receiptL['monthStaffPrice']='<td><b>¥'.$m1.'</b></td>';
  6737. $list['<span class=colRed >'.$vlu['category'].'小计</span>']=$receiptL;
  6738. }
  6739. $data['list']=$list;
  6740. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  6741. 'where'=>" status=1 and Year(date)=".$year.' and Month(date)='.$month,'groupby'=>'item,Month(date),itemCategory','asArray'=>true));
  6742. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6743. //statistics html
  6744. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6745. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6746. if(empty($stList))
  6747. $stList=array('rePrice'=>0,'agPrice'=>0);
  6748. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6749. $monthHtml="";
  6750. for ($i=1;$i<=12;$i++){
  6751. if ($i==$month)
  6752. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6753. else
  6754. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6755. }
  6756. $data['monthHtml']=$monthHtml;
  6757. $data['year']=$year;
  6758. $data['month']=$month;
  6759. $data['memu']="receipt";
  6760. $data['staff']=$this->staff;
  6761. $data['receiptMemu']='companyCategoryCollect';
  6762. $data['verifyId']=$this->verifyId;
  6763. $data['executeId']=$this->executeId;
  6764. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  6765. //$this->render ( "/admin/saeaStaffCollectDetail", $data );
  6766. }
  6767. function companyMonthCollectDetail(){
  6768. $year=$this->get_args('year')?$this->get_args('year'):"";
  6769. $month=$this->get_args('month')?$this->get_args('month'):"";
  6770. if(!$year)
  6771. $year=isset($this->params['year'])?$this->params['year']:date("Y");
  6772. if(!$month)
  6773. $month=isset($this->params['month'])?$this->params['month']:1;
  6774. Doo::loadModel('staff');
  6775. $staff=new staff();
  6776. Doo::loadModel("receiptDetail");
  6777. $receiptDetail=new receiptDetail();
  6778. Doo::loadModel('accountItem');
  6779. $accountItem=new accountItem();
  6780. Doo::loadModel('statistics');
  6781. $statistics=new statistics();
  6782. Doo::loadModel('L_category');
  6783. $lCategory=new L_category();
  6784. $staffList=$staff->find(array('where'=>'username!="admin"','asArray'=>true));
  6785. $categoryList=$lCategory->find(array('asArray'=>true));
  6786. $list=array();
  6787. foreach ($categoryList as $value){
  6788. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6789. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6790. if(!empty($receiptCollectList)){
  6791. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  6792. $html="";
  6793. $psum=0;
  6794. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费');
  6795. foreach ($item as $va){
  6796. $falg=true;
  6797. foreach ($receiptCollectList as $v){
  6798. if($v['itemCategory']=='日常相关费用'){
  6799. if($v['item']==$va){
  6800. $psum+=$v['price'];
  6801. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6802. }
  6803. }
  6804. }
  6805. if($falg)
  6806. $html.='<td class="taR">-</td>';
  6807. }
  6808. if(!empty($psum))
  6809. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6810. else
  6811. $psum='<td class="colGreen taR">-</td>';
  6812. $receiptL['日常相关费用']=$psum.$html;
  6813. /*-----------------------------------*/
  6814. $html="";
  6815. $psum=0;
  6816. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  6817. foreach ($item as $va){
  6818. $falg=true;
  6819. foreach ($receiptCollectList as $v){
  6820. if($v['itemCategory']=='差旅相关费用'){
  6821. if($v['item']==$va){
  6822. $psum+=$v['price'];
  6823. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6824. }
  6825. }
  6826. }
  6827. if($falg)
  6828. $html.='<td class="taR">-</td>';
  6829. }
  6830. if(!empty($psum))
  6831. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6832. else
  6833. $psum='<td class="colGreen taR">-</td>';
  6834. $receiptL['差旅相关费用']=$psum.$html;
  6835. /*-------------------------------------*/
  6836. $html="";
  6837. $psum=0;
  6838. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  6839. foreach ($item as $va){
  6840. $falg=true;
  6841. foreach ($receiptCollectList as $v){
  6842. if($v['itemCategory']=='培训班费用'){
  6843. if($v['item']==$va){
  6844. $psum+=$v['price'];
  6845. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6846. }
  6847. }
  6848. }
  6849. if($falg)
  6850. $html.='<td class="taR">-</td>';
  6851. }
  6852. if(!empty($psum))
  6853. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6854. else
  6855. $psum='<td class="colGreen taR">-</td>';
  6856. $receiptL['培训班费用']=$psum.$html;
  6857. /*-------------------------------------*/
  6858. $html="";
  6859. $psum=0;
  6860. $item=array('公关费','广告费','借款','可自加费用');
  6861. foreach ($item as $va){
  6862. $falg=true;
  6863. foreach ($receiptCollectList as $v){
  6864. if($v['itemCategory']=='其他'){
  6865. if($v['item']==$va){
  6866. $psum+=$v['price'];
  6867. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  6868. }
  6869. }
  6870. }
  6871. if($falg)
  6872. $html.='<td class="taR">-</td>';
  6873. }
  6874. if(!empty($psum))
  6875. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  6876. else
  6877. $psum='<td class="colGreen taR">-</td>';
  6878. $receiptL['其他']=$psum.$html;
  6879. /*-------------------------------------*/
  6880. $html="";
  6881. $psum=0;
  6882. foreach ($receiptCollectList as $v){
  6883. if($v['itemCategory']=='报销金额调整'){
  6884. if (!empty($v['price']))
  6885. $psum+=$v['price'];
  6886. }
  6887. }
  6888. if(!empty($psum))
  6889. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  6890. else
  6891. $psum='<td class="taR colOrange">-</td>';
  6892. $receiptL['报销金额调整']=$psum.$html;
  6893. }else{
  6894. $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>
  6895. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6896. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  6897. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6898. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  6899. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6900. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  6901. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  6902. }
  6903. $monthStaffPrice=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6904. 'where'=>'cid='.$value['cid']." and status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'asArray'=>true));
  6905. if(!empty($monthStaffPrice[0]['price']))
  6906. $receiptL['monthStaffPrice']='<td><b>¥'.$monthStaffPrice[0]['price'].'</b></td>';
  6907. else
  6908. $receiptL['monthStaffPrice']='<td><b>-</b></td>';
  6909. $list[$value['title']]=$receiptL;
  6910. }
  6911. $data['list']=$list;
  6912. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6913. 'where'=>" status=1 and Year(pastDate)=".$year.' and Month(pastDate)='.$month,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6914. $data['monthPriceHtml']=$this->_getMonthCollectDetail($receiptCollectList);
  6915. //print_r($data['monthPriceHtml']);
  6916. // foreach ($data['monthPriceHtml'] as $value){
  6917. // echo $value;
  6918. // }
  6919. // die;
  6920. //statistics html
  6921. $stList=$statistics->getOne(array('select'=>'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  6922. 'where'=>'Month(date)='.$month." and Year(date)=".$year,'groupby'=>'Month(date)','asArray'=>true));
  6923. if(empty($stList))
  6924. $stList=array('rePrice'=>0,'agPrice'=>0);
  6925. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  6926. $monthHtml="";
  6927. for ($i=1;$i<=12;$i++){
  6928. if ($i==$month)
  6929. $monthHtml.='<option selected value="'.$i.'">'.$i.'</option>';
  6930. else
  6931. $monthHtml.='<option value="'.$i.'">'.$i.'</option>';
  6932. }
  6933. $data['monthHtml']=$monthHtml;
  6934. $data['year']=$year;
  6935. $data['month']=$month;
  6936. $data['memu']="receipt";
  6937. $data['staff']=$this->staff;
  6938. $data['receiptMemu']='companyCategoryCollect';
  6939. $data['verifyId']=$this->verifyId;
  6940. $data['executeId']=$this->executeId;
  6941. $this->render ( "/admin/companyMonthCollectDetail", $data );
  6942. }
  6943. function staffCollectDetail(){
  6944. $year=$this->get_args('year')?$this->get_args('year'):date("Y");
  6945. $staffname=$this->get_args('username')?$this->get_args('username'):"";
  6946. $pcid=$this->get_args('category')?$this->get_args('category'):"";
  6947. if(!$staffname){
  6948. $staffname=isset($this->params['staffname'])?$this->params['staffname']:"";
  6949. $staffname= urldecode($staffname);
  6950. }
  6951. Doo::loadModel('staff');
  6952. $staff=new staff();
  6953. Doo::loadModel("receiptDetail");
  6954. $receiptDetail=new receiptDetail();
  6955. Doo::loadModel('accountItem');
  6956. $accountItem=new accountItem();
  6957. Doo::loadModel('statistics');
  6958. $statistics=new statistics();
  6959. Doo::loadModel('L_category');
  6960. $lCategory=new L_category();
  6961. $staffList=$staff->find(array('asArray'=>true));
  6962. $stHtml='';$stTitle="";$staffId=0;$cid=0;$ocid=0;
  6963. foreach ($staffList as $value){
  6964. if ($value['username']==$staffname&&$value['username']!='admin'){
  6965. $stTitle=$value['category'].'-'.$value['username'];
  6966. $staffId=$value['sid'];
  6967. $cid=$value['cid'];
  6968. $ocid=$value['cid'];
  6969. if (!empty($value['othercid']))
  6970. $cid=$value['cid'].','.$value['othercid'];
  6971. $stHtml.='<option selected value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6972. }elseif ($value['username']!='admin')
  6973. $stHtml.='<option value="'.$value['username'].'">'.$value['category'].'-'.$value['username'].'</option>';
  6974. }
  6975. $data['lCategoryHtml']=$lCategory->find(array('where'=>'cid in('.$cid.')','asArray'=>true));
  6976. if(empty($pcid))
  6977. $pcid=$ocid;
  6978. $data['ocid']=$pcid;
  6979. $path=SITE_PATH.$this->STAFFCOLLECTPATH."staffCollectDetail_".$year."_".$staffId.".htmls";
  6980. $this->showCache($path);
  6981. //
  6982. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  6983. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'item,Month(pastDate),itemCategory','asArray'=>true));
  6984. $accountList=$accountItem->find(array('asArray'=>true));
  6985. //create CollectDetail HTML
  6986. $collectHtml=array();
  6987. foreach ($accountList as $key=>$value){
  6988. $html="";$asum=0;
  6989. for ($i=1;$i<=12;$i++){
  6990. $falg=true;
  6991. foreach ($receiptCollectList as $v) {
  6992. if($value['category']==$v['itemCategory']&&$v['item']==$value['name']&&$i==$v['month']){
  6993. $asum+=$v['price'];
  6994. $html.='<td class="taR">¥'.$v['price'].'</td>';$falg=false;break;
  6995. }
  6996. }
  6997. if($falg)
  6998. $html.='<td class="taR">-</td>';
  6999. }
  7000. $html.='<td class="taR colGreen"><b>¥'.$asum.'</b></td>';
  7001. $collectHtml[$value['category']][$value['name']]=$html;
  7002. }
  7003. $data['collectHtml']=$collectHtml;
  7004. //create Adjustment price html
  7005. $receiptCollectList=$receiptDetail->find(array('select'=>'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  7006. 'where'=>'staff='.$staffId." and cid=".$pcid." and status=1 and Year(pastDate)=".$year,'groupby'=>'itemCategory,Month(pastDate)','asArray'=>true));
  7007. $adjustment=array();$collectArray=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7008. $collectHtml=$this->collectHtml($receiptCollectList,'日常相关费用','b');
  7009. array_push($collectArray['日常相关费用'], $collectHtml);
  7010. $collectHtml=$this->collectHtml($receiptCollectList,'差旅相关费用','b');
  7011. array_push($collectArray['差旅相关费用'], $collectHtml);
  7012. $collectHtml=$this->collectHtml($receiptCollectList,'培训班费用','b');
  7013. array_push($collectArray['培训班费用'], $collectHtml);
  7014. $collectHtml=$this->collectHtml($receiptCollectList,'其他','b');
  7015. array_push($collectArray['其他'], $collectHtml);
  7016. $data['collectArray']=$collectArray;
  7017. $collectHtml=$this->collectHtml($receiptCollectList,'报销金额调整');
  7018. array_push($adjustment, $collectHtml);
  7019. $data['adjustment']=$adjustment;
  7020. //total price html
  7021. $collectHtml="";$total=0;
  7022. for ($i=1;$i<=12;$i++){
  7023. $sumPrice=0;
  7024. foreach ($receiptCollectList as $key=>$value){
  7025. if($value['month']==$i){
  7026. $sumPrice+=$value['price'];
  7027. }
  7028. }
  7029. if ($sumPrice==0)
  7030. $collectHtml.='<td class="taR">-</td>';
  7031. else
  7032. $collectHtml.='<td class="taR">¥'.$sumPrice.'</td>';
  7033. $total+=$sumPrice;
  7034. }
  7035. $collectHtml.='<td class="taR colGreen">¥'.$total.'</td>';
  7036. //statistics html
  7037. $stList=$statistics->statisticsByYear($year,$staffId);
  7038. if(empty($stList))
  7039. $stList=array('rePrice'=>0,'agPrice'=>0);
  7040. $data['stList']=array('rePrice'=>$stList['rePrice'],'agPrice'=>$stList['agPrice'],'skPrice'=>($stList['rePrice']-$stList['agPrice']));
  7041. $data['totalPrice']=$collectHtml;
  7042. $data['totalYear']=$total;
  7043. $data['stHtml']=$stHtml;
  7044. $data['year']=$year;
  7045. $data['stTitle']=$stTitle;
  7046. $data['memu']="receipt";
  7047. $data['staff']=$this->staff;
  7048. $data['receiptMemu']='companyCategoryCollect';
  7049. $data['verifyId']=$this->verifyId;
  7050. $data['executeId']=$this->executeId;
  7051. if ($year<date("Y")){
  7052. Doo::loadModel('receipt');
  7053. $receipt=new receipt();
  7054. $receiptList=$receipt->find(array('where'=>'staff='.$staffId.' and (status=2 or status=4) and Year(date) ='.$year,'asArray'=>true));
  7055. if(empty($receiptList)){ //generated files
  7056. ob_start();
  7057. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7058. $this->cacheFile($path);die;
  7059. }
  7060. }
  7061. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  7062. }
  7063. function BUGFLAG(){
  7064. $status=isset($this->params['status'])&&is_numeric($this->params['status'])?$this->params['status']:0;
  7065. $year=$this->get_args('year')?$this->get_args('year'):date('Y');
  7066. $month=$this->get_args('month')?$this->get_args('month'):"";
  7067. $cid=$this->get_args('cid')?$this->get_args('cid'):0;
  7068. $sid=$this->get_args('sid')?$this->get_args('sid'):0;
  7069. if (empty($status))
  7070. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  7071. $page_size=12;
  7072. $page = isset($this->params ['page'])&&is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7073. $vidList=array();
  7074. $button=0;
  7075. Doo::loadModel('verify');
  7076. $verify=new verify();
  7077. Doo::loadModel('receipt');
  7078. $receipt=new receipt();
  7079. Doo::loadModel('staff');
  7080. $staff=new staff();
  7081. Doo::loadModel('L_category');
  7082. $Lcategory=new L_category();
  7083. $dateCondition=" and Year(date) =".$year;
  7084. if(!empty($month))
  7085. $dateCondition=" and Year(date) =".$year." and Month(date) = ".$month;
  7086. $categoryList=$Lcategory->find(array('asArray'=>true));
  7087. $staffList=$staff->find(array('where'=>'cid='.$cid,'asArray'=>true));
  7088. $cateCondition="";$staffCondition="";$approvalCondition="";
  7089. if (!empty($cid))
  7090. $cateCondition=' and cid='.$cid;
  7091. if(!empty($sid)){
  7092. $staffCondition=' and staff='.$sid;
  7093. $cateCondition="";
  7094. }
  7095. $approvalCondition=" and status=".$status;
  7096. if($status==2){
  7097. //查找角色审批人
  7098. $approvalCondition=' and status='.$status.' and (nowStaff like "%,'.$this->staff[0]['sid'].'%" or nowStaff like "%'.$this->staff[0]['sid'].',%" or nowStaff='.$this->staff[0]['sid'].' )';
  7099. }
  7100. if($status==5){//and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  7101. $approvalCondition=' and status=2 ';
  7102. }
  7103. if($status==1){
  7104. $approvalCondition=' and (status='.$status.' or status=6) ';
  7105. }
  7106. //nowStaff like "%'.$this->staff[0]['sid'].'%"
  7107. $pageinfo['page']=array('previous'=>'');
  7108. if ($status==0){
  7109. $pageinfo=$this->get_page("CLD_receipt", $dateCondition.$cateCondition.$staffCondition.' and status!=5', $page, $page_size, "approvalExpenses","","");
  7110. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition
  7111. ,'limit'=>$pageinfo ['lower'].','.$page_size,'desc'=>'rid','asArray'=>true));
  7112. //echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7113. }else
  7114. $receiptList=$receipt->find(array('where'=>'status!=5 '.$dateCondition.$cateCondition.$staffCondition.$approvalCondition
  7115. ,'desc'=>'rid','asArray'=>true));
  7116. $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
  7117. ,'desc'=>'rid','asArray'=>true));
  7118. //echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  7119. //print_r($pageinfo);
  7120. $Locate=0;
  7121. foreach ($receiptList as $key=>$value){
  7122. $receiptList[$key]['Locate']=$Locate;$Locate++;
  7123. $receiptList[$key]['reviseDetail']=array();
  7124. if (!empty($value['reviseDetail']))
  7125. $receiptList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true);
  7126. $receiptList[$key]['accountItem']=json_decode($value['accountItem'],true);
  7127. $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true));
  7128. $receiptList[$key]['category']=$categoryDetil['title'];
  7129. $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true));
  7130. $verifyList=json_decode($verifyList['staff'],true);//status opinion
  7131. $verifyStaff=json_decode($value['verifyStaff'],true);
  7132. foreach ($verifyList as $k=>$v){
  7133. //init verifyStaff
  7134. $verifyList[$k]['date']="";
  7135. $verifyList[$k]['opinion']="";
  7136. $verifyList[$k]['status']="";
  7137. if (empty($verifyStaff)){
  7138. $verifyList[$k]['date']="";
  7139. $verifyList[$k]['opinion']="";
  7140. if ($v[0]==$this->staff[0]['sid']){
  7141. $verifyList[$k]['status']=4;
  7142. $button=4;
  7143. }
  7144. }else{
  7145. $flag=true;
  7146. foreach ($verifyStaff as $m=>$u){
  7147. if ($v[0]==$m){
  7148. $verifyList[$k]['date']=$u['date'];
  7149. $verifyList[$k]['opinion']=$u['opinion'];
  7150. $verifyList[$k]['status']=$u['status'];
  7151. $flag=false;
  7152. break;
  7153. }
  7154. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7155. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7156. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7157. }
  7158. if($flag){//检测可编辑
  7159. if($v[0]==$this->staff[0]['sid']){
  7160. $verifyList[$k]['status']=4;$button=4;
  7161. }
  7162. }
  7163. }
  7164. }
  7165. $receiptList[$key]['verifyList']=$verifyList;
  7166. $receiptList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true));
  7167. $receiptList[$key]['button']=$button;
  7168. $receiptList[$key]['nowStaffArray']=explode(',',$value['nowStaff']);
  7169. }
  7170. //print_r($receiptList);die;
  7171. //$data['verifyDetail']=$verifyDetail;
  7172. $mothHtml="";
  7173. for($i=1;$i<=12;$i++){
  7174. if($month==$i)
  7175. $mothHtml.='<option selected value="'.$i.'">'.$i.'月</option>';
  7176. else
  7177. $mothHtml.='<option value="'.$i.'">'.$i.'月</option>';
  7178. }
  7179. $data['mothHtml']=$mothHtml;
  7180. $data['page']=$pageinfo;
  7181. $data['receiptList']=$receiptList;
  7182. $data['receiptApprovalCount']=count($rLRes);
  7183. $data['status']=$status;
  7184. $data['year']=$year;
  7185. $data['categoryList']=$categoryList;
  7186. $data['staffList']=$staffList;
  7187. $data['cid']=$cid;
  7188. $data['sid']=$sid;
  7189. //print_r($receiptList);
  7190. $data['memu']="receipt";
  7191. $data['staff']=$this->staff;
  7192. $data['receiptMemu']='approvalExpenses';
  7193. $data['verifyId']=$this->verifyId;
  7194. $data['executeId']=$this->executeId;
  7195. $this->render ( "/admin/FALG", $data );
  7196. }
  7197. function ajaxGetReceiptOrder(){
  7198. $receiptOrder=$this->get_args('receiptOrder')?$this->get_args('receiptOrder'):"";
  7199. if (!empty($receiptOrder)){
  7200. Doo::loadModel('receipt');
  7201. $receipt=new receipt();
  7202. Doo::loadModel ( 'staff' );
  7203. $staff = new staff ();
  7204. $receiptInfo=$receipt->getOne(array('where'=>' receiptOrder="'.$receiptOrder.'"','asArray'=>true));
  7205. $verifyStaff=json_decode($receiptInfo['verifyStaff'],true);
  7206. $html='<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  7207. <tr><td>单号:<b>'.$receiptOrder.'</b></td><td>金额:<b class="colOrange">¥'.$receiptInfo['sum'].'</b></td></tr>
  7208. </tbody></table><table class="table table table-bordered"><tbody>';
  7209. foreach ($verifyStaff as $key=>$value){
  7210. $staffInfo=$staff->getOne(array('select'=>'username','where'=>' sid="'.$key.'"','asArray'=>true));
  7211. $html.='<tr><th width="70">'.$staffInfo['username'].'</th><td>'.$value['opinion'].'</td></tr>';
  7212. }
  7213. $html.='</tbody></table></div></div>';
  7214. echo json_encode(array('status'=>1,'receiptHtml'=>$html));die;
  7215. }
  7216. echo json_encode(array('status'=>2,'receiptHtml'=>''));die;
  7217. }
  7218. function _getMonthCollectDetail($receiptCollectList){
  7219. if(!empty($receiptCollectList)){
  7220. $receiptL=array('日常相关费用'=>array(),'差旅相关费用'=>array(),'培训班费用'=>array(),'其他'=>array());
  7221. $html="";
  7222. $psum=0;
  7223. $item=array('市内交通费','市内出租费','办事处房租','电话费','水费','电费','办公费用','邮寄费','其他费用','车辆费用','广告费','团队建设费','物业管理费','宽带费');
  7224. foreach ($item as $value){
  7225. $falg=true;
  7226. foreach ($receiptCollectList as $v){
  7227. if($v['itemCategory']=='日常相关费用'){
  7228. if($v['item']==$value){
  7229. $psum+=$v['price'];
  7230. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7231. }
  7232. }
  7233. }
  7234. if($falg)
  7235. $html.='<td class="taR">-</td>';
  7236. }
  7237. if(!empty($psum))
  7238. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7239. else
  7240. $psum='<td class="colGreen taR">-</td>';
  7241. $receiptL['日常相关费用']=$psum.$html;
  7242. /*-----------------------------------*/
  7243. $html="";
  7244. $psum=0;
  7245. $item=array('往来交通费','市内交通费','出差住宿费','出差补助','其他费用');
  7246. foreach ($item as $value){
  7247. $falg=true;
  7248. foreach ($receiptCollectList as $v){
  7249. if($v['itemCategory']=='差旅相关费用'){
  7250. if($v['item']==$value){
  7251. $psum+=$v['price'];
  7252. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7253. }
  7254. }
  7255. }
  7256. if($falg)
  7257. $html.='<td class="taR">-</td>';
  7258. }
  7259. if(!empty($psum))
  7260. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7261. else
  7262. $psum='<td class="colGreen taR">-</td>';
  7263. $receiptL['差旅相关费用']=$psum.$html;
  7264. /*-------------------------------------*/
  7265. $html="";
  7266. $psum=0;
  7267. $item=array('场租费','薪酬','住宿费','交通费','餐饮费','办公费','公关费','其他');
  7268. foreach ($item as $value){
  7269. $falg=true;
  7270. foreach ($receiptCollectList as $v){
  7271. if($v['itemCategory']=='培训班费用'){
  7272. if($v['item']==$value){
  7273. $psum+=$v['price'];
  7274. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7275. }
  7276. }
  7277. }
  7278. if($falg)
  7279. $html.='<td class="taR">-</td>';
  7280. }
  7281. if(!empty($psum))
  7282. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7283. else
  7284. $psum='<td class="colGreen taR">-</td>';
  7285. $receiptL['培训班费用']=$psum.$html;
  7286. /*-------------------------------------*/
  7287. $html="";
  7288. $psum=0;
  7289. $item=array('公关费','广告费','借款','可自加费用');
  7290. foreach ($item as $value){
  7291. $falg=true;
  7292. foreach ($receiptCollectList as $v){
  7293. if($v['itemCategory']=='其他'){
  7294. if($v['item']==$value){
  7295. $psum+=$v['price'];
  7296. $html.='<td class="taR">'.$v['price'].'</td>';$falg=false;break;
  7297. }
  7298. }
  7299. }
  7300. if($falg)
  7301. $html.='<td class="taR">-</td>';
  7302. }
  7303. if(!empty($psum))
  7304. $psum='<td class="colGreen taR">¥'.$psum.'</td>';
  7305. else
  7306. $psum='<td class="colGreen taR">-</td>';
  7307. $receiptL['其他']=$psum.$html;
  7308. /*-------------------------------------*/
  7309. $html="";
  7310. $psum=0;
  7311. foreach ($receiptCollectList as $v){
  7312. if($v['itemCategory']=='报销金额调整'){
  7313. if (!empty($v['price']))
  7314. $psum+=$v['price'];
  7315. }
  7316. }
  7317. if(!empty($psum))
  7318. $psum='<td class="taR colOrange">¥'.$psum.'</td>';
  7319. else
  7320. $psum='<td class="taR colOrange">-</td>';
  7321. $receiptL['报销金额调整']=$psum.$html;
  7322. }else{
  7323. $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>
  7324. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7325. $receiptL['差旅相关费用']='<td class="colGreen taR">-</td><td class="taR">-</td>
  7326. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7327. $receiptL['培训班费用']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  7328. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7329. $receiptL['其他']='<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  7330. $receiptL['报销金额调整']='<td class="taR colOrange">-</td>';
  7331. }
  7332. return $receiptL;
  7333. }
  7334. function eMail(){
  7335. Doo::loadModel('staff');
  7336. $staff=new staff();
  7337. Doo::loadModel('receipt');
  7338. $receipt=new receipt();
  7339. Doo::loadModel('L_category');
  7340. $Lcategory=new L_category();
  7341. Doo::loadModel("verify");
  7342. $verify=new verify();
  7343. $staffList=$staff->find(array('asArray'=>true));
  7344. foreach ($staffList as $key=>$value){
  7345. if($value['username']!='admin'){
  7346. //提交人
  7347. $receiptList=$receipt->find(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0','asArray'=>true));
  7348. if(!empty($receiptList)){
  7349. $html='<br><div><style></style>
  7350. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  7351. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  7352. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7353. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  7354. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7355. <tbody><tr>
  7356. <td style="padding: 0 40px;" align="left">
  7357. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7358. </td></tr><tr>
  7359. <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>
  7360. </tr>
  7361. </tbody> </table></td> </tr> <tr><td>
  7362. <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">
  7363. <tbody> <tr><td>
  7364. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  7365. 以下报销单完成了审批,等着收款吧:</p>
  7366. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  7367. foreach ($receiptList as $k=>$v){
  7368. $category=$Lcategory->getOne(array('where'=>'cid='.$v['cid'],'asArray'=>true));
  7369. $html.='
  7370. <tr>
  7371. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7372. <td align="left">
  7373. <p style="font-size:16px;line-height:22px;margin:0">'.$v['receiptOrder'].'</p></td>
  7374. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'</p></td>
  7375. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$v['sum'].'元</p></td>
  7376. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$v['date'].'</span></td>
  7377. </tr>';
  7378. }
  7379. $html.=' </tbody></table></td></tr></tbody></table></td></tr>
  7380. <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>
  7381. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  7382. if(filter_var($value['email'], FILTER_VALIDATE_EMAIL)){
  7383. $this->SMail($value['email'], "CLD提醒您,您的报销单已同意支付", $html);
  7384. $this->SMail('1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7385. $this->SMail('cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html);
  7386. $receipt=new receipt();
  7387. $receipt->notice=1;
  7388. $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7389. }
  7390. }
  7391. //审批人
  7392. $verifyList=$verify->find(array('where'=>" staff like '%[\"".$value['sid']."\",%'",'asArray'=>true));
  7393. $html='<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  7394. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  7395. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  7396. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  7397. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  7398. <tbody><tr><td style="padding: 0 40px;" align="left">
  7399. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,'.$value['username'].'</p>
  7400. </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>
  7401. </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">
  7402. <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>
  7403. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  7404. foreach ($verifyList as $k=>$v){
  7405. $receiptList=$receipt->find(array('where'=>"verify=".$v['vid']." and status=2 and verifyStaff not like '%{\"".$value['sid']."\":%'",'asArray'=>true));
  7406. foreach ($receiptList as $r=>$l){
  7407. $category=$Lcategory->getOne(array('where'=>'cid='.$l['cid'],'asArray'=>true));
  7408. $staffDetile=$staff->getOne(array('where'=>'sid='.$l['staff'],'asArray'=>true));
  7409. $html.='
  7410. <tr>
  7411. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  7412. <td align="left">
  7413. <p style="font-size:16px;line-height:22px;margin:0">'.$l['receiptOrder'].'</p></td>
  7414. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">'.$category['title'].'-'.$staffDetile['username'].'</p></td>
  7415. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥'.$l['sum'].'元</p></td>
  7416. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">'.$l['date'].'</span></td>
  7417. </tr>';
  7418. }
  7419. }
  7420. $html.='
  7421. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  7422. <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>
  7423. </tr></tbody></table></td></tr></tbody></table></div><br>';
  7424. if((filter_var($value['email'], FILTER_VALIDATE_EMAIL))&&(!empty($verifyList))&&(!empty($receiptList))){
  7425. $this->SMail($value['email'], "CLD提醒您,有需要你审批的报销单", $html);
  7426. // $receipt=new receipt();
  7427. // $receipt->notice=1;
  7428. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  7429. }
  7430. }
  7431. }
  7432. }
  7433. function setWXMsg($rid,$type){
  7434. Doo::loadModel("receipt");
  7435. $receipt=new receipt();
  7436. $receiptDetail = $receipt->getOne(array('where'=>'rid='.$rid,'asArray'=>true));
  7437. if(!empty($receiptDetail)){
  7438. Doo::loadModel('staff');
  7439. $staff = new staff();
  7440. $staffmsg = $staff->getStaffBySid($receiptDetail['staff']);
  7441. if(!empty($staffmsg['wxid'])){
  7442. require_once (SITE_PATH . '/protected/class/client.php');
  7443. $client = new client ('http://m.cld.smartcost.com.cn/');
  7444. $user = $staffmsg['wxid'];
  7445. $receiptName = '';
  7446. $msg = '';
  7447. switch($receiptDetail['Rtype']){
  7448. case 0:$receiptName = '报销';break;
  7449. case 1:$receiptName = '借款';break;
  7450. case 2:$receiptName = '对公汇款';break;
  7451. }
  7452. switch($type){
  7453. case 1:$msg = '太好了,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已同意支付。';break;
  7454. case 2:$msg = '注意,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被撤回,请及时处理。';break;
  7455. case 3:$msg = '很遗憾,您的'.$receiptName.' '.$receiptDetail['receiptOrder'].',¥'.$receiptDetail['sum'].',已被终止。';break;
  7456. }
  7457. $result = $client->SendMsg($user,$msg,'text');
  7458. }
  7459. }
  7460. }
  7461. // Email发送函数
  7462. function SMail($toemail, $subject, $contents) {
  7463. Doo::loadClass('class.phpmailer');
  7464. $mail = new PHPMailer();
  7465. $mail->From = "postmaster@support.zhzdwk.com"; //发送邮箱全名
  7466. $mail->FromName = "=?UTF-8?B?" . base64_encode("CLD") . "?="; //发送人昵称
  7467. $mail->Username = "postmaster@websupport.sendcloud.org"; //用户名
  7468. $mail->Password = "cDO1GjtY1seH"; //密码
  7469. $mail->CharSet = "UTF8";
  7470. $mail->SMTPAuth = true;
  7471. $mail->Host = "smtpcloud.sohu.com"; //邮件主机的smtp地址
  7472. $mail->Mailer = "smtp";
  7473. $mail->Port = 25;
  7474. $mail->Subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";
  7475. $mail->MsgHTML($contents);
  7476. $mail->AddAddress($toemail);
  7477. $mail->CharSet = "UTF-8";
  7478. return $mail->Send();
  7479. }
  7480. function swfupload(){
  7481. $POST_MAX_SIZE = ini_get('post_max_size');
  7482. $unit = strtoupper(substr($POST_MAX_SIZE, -1));
  7483. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  7484. if ((int)$_SERVER['CONTENT_LENGTH'] > $multiplier*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) {
  7485. header("HTTP/1.1 500 Internal Server Error");
  7486. echo "POST exceeded maximum allowed size.";
  7487. exit(0);
  7488. }
  7489. // Settings
  7490. $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)
  7491. $upload_name = "Filedata";
  7492. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  7493. $extension_whitelist = array("doc", "txt", "jpg", "gif", "png"); // Allowed file extensions
  7494. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  7495. // Other variables
  7496. $MAX_FILENAME_LENGTH = 260;
  7497. $file_name = "";
  7498. $file_extension = "";
  7499. $uploadErrors = array(
  7500. 0=>"文件上传成功",
  7501. 1=>"上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  7502. 2=>"上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  7503. 3=>"上传的文件仅为部分文件",
  7504. 4=>"没有文件上传",
  7505. 6=>"缺少临时文件夹"
  7506. );
  7507. $nk= time();
  7508. $file_name = $nk.'.'.$this->_GetFileEXT($_FILES[$upload_name]['name']); //preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  7509. if (!@move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
  7510. echo "文件无法保存.";
  7511. exit(0);
  7512. }
  7513. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  7514. echo json_encode(array('filename'=>$file_name,'id'=>$nk));
  7515. exit(0);
  7516. }
  7517. function _GetFileEXT($filename) {
  7518. $pics = explode ( '.', $filename );
  7519. $num = count ( $pics );
  7520. return $pics [$num - 1];
  7521. }
  7522. /**
  7523. * 获取get或者POST值
  7524. * @param string $name 属性名称
  7525. * @return fixed 值
  7526. */
  7527. function get_args($name) {
  7528. if (isset ( $_GET [$name] )) {
  7529. if (is_array ( $_GET [$name] ))
  7530. return $_GET [$name];
  7531. else
  7532. return addslashes ( $_GET [$name] );
  7533. } elseif (isset ( $_POST [$name] )) {
  7534. if (is_array ( $_POST [$name] ))
  7535. return $_POST [$name];
  7536. else
  7537. return addslashes ( $_POST [$name] );
  7538. } else
  7539. return false;
  7540. }
  7541. function num_to_rmb($num){
  7542. $c1 = "零壹贰叁肆伍陆柒捌玖";
  7543. $c2 = "分角元拾佰仟万拾佰仟亿";
  7544. //精确到分后面就不要了,所以只留两个小数位
  7545. $num = round($num, 2);
  7546. //将数字转化为整数
  7547. $num = $num * 100;
  7548. if (strlen($num) > 10) {
  7549. return "金额太大,请检查";
  7550. }
  7551. $i = 0;
  7552. $c = "";
  7553. while (1) {
  7554. if ($i == 0) {
  7555. //获取最后一位数字
  7556. $n = substr($num, strlen($num)-1, 1);
  7557. } else {
  7558. $n = $num % 10;
  7559. }
  7560. //每次将最后一位数字转化为中文
  7561. $p1 = substr($c1, 3 * $n, 3);
  7562. $p2 = substr($c2, 3 * $i, 3);
  7563. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  7564. $c = $p1 . $p2 . $c;
  7565. } else {
  7566. $c = $p1 . $c;
  7567. }
  7568. $i = $i + 1;
  7569. //去掉数字最后一位了
  7570. $num = $num / 10;
  7571. $num = (int)$num;
  7572. //结束循环
  7573. if ($num == 0) {
  7574. break;
  7575. }
  7576. }
  7577. $j = 0;
  7578. $slen = strlen($c);
  7579. while ($j < $slen) {
  7580. //utf8一个汉字相当3个字符
  7581. $m = substr($c, $j, 6);
  7582. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  7583. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  7584. $left = substr($c, 0, $j);
  7585. $right = substr($c, $j + 3);
  7586. $c = $left . $right;
  7587. $j = $j-3;
  7588. $slen = $slen-3;
  7589. }
  7590. $j = $j + 3;
  7591. }
  7592. //这个是为了去掉类似23.0中最后一个“零”字
  7593. if (substr($c, strlen($c)-3, 3) == '零') {
  7594. $c = substr($c, 0, strlen($c)-3);
  7595. }
  7596. //将处理的汉字加上“整”
  7597. if (empty($c)) {
  7598. return "零元整";
  7599. }else{
  7600. return $c . "整";
  7601. }
  7602. }
  7603. /**
  7604. * 获得分页数据
  7605. * @param unknown_type $table
  7606. * @param unknown_type $condition
  7607. * @param unknown_type $on_page
  7608. * @param unknown_type $page_size
  7609. */
  7610. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7611. $page_c = "";
  7612. $page ['previous'] = $this->get_previous ( $on_page );
  7613. $page ['on_page'] = $on_page;
  7614. $total_count = $this->get_table_count ( $table, $condition );
  7615. $total = intval ( $total_count / $page_size );
  7616. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7617. $page ['total_data'] = $total_count;
  7618. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7619. $i = 1;
  7620. $page_max = 1;
  7621. $page_width=3;
  7622. if ($on_page >= $page_width) {
  7623. $page_max = intval ( $on_page / $page_width ) + 1;
  7624. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7625. }
  7626. for(; $i <= $page ['total_page']; $i ++) {
  7627. if ($i == $on_page)
  7628. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7629. else
  7630. $page_c .= '<li><a href="/' . $action .'/0/'. $i . $get . '">' . $i . '</a></li>';
  7631. if ($i == ($page_width * $page_max))
  7632. break;
  7633. }
  7634. $page ['page'] = $page_c;
  7635. $page ['lower'] = (-- $on_page) * $page_size;
  7636. return $page;
  7637. }
  7638. /**
  7639. * 获取总页数
  7640. * @param unknown_type $table
  7641. * @param unknown_type $condition
  7642. */
  7643. public function get_table_count($table = "", $condition = "") {
  7644. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7645. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7646. //echo $sql;die;
  7647. $query = Doo::db ()->query ( $sql );
  7648. $result = $query->fetch ();
  7649. return $result ['count'];
  7650. }
  7651. /**
  7652. * 获取上一页
  7653. * @param unknown_type $on_page
  7654. */
  7655. function get_previous($on_page = 1) {
  7656. return $on_page != 0 ? $on_page - 1 : $on_page;
  7657. }
  7658. }
  7659. ?>