ReceiptController.php 534 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300
  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. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. public function beforeRun($resource, $action) {
  58. Doo::loadClass ( 'XDeode' );
  59. $XDeode = new XDeode ( 5 );
  60. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  61. // 单独判断公司汇总的访问权限
  62. if ($action == 'companyCategoryCollect') {
  63. Doo::loadModel ( "receiptAuthorityManage" );
  64. $invoiceCompanyManage = new receiptAuthorityManage ();
  65. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  66. if (empty ( $icm ))
  67. die ( 'illegal request' );
  68. }
  69. Doo::loadModel ( 'staff' );
  70. $staff = new staff ();
  71. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  72. $accessModular = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'where'=>'mold !="日常收支"',
  121. 'select' => 'staff',
  122. 'asArray' => true
  123. ) );
  124. $list2 = array ();
  125. foreach ( $executeList as $key => $value ) {
  126. $ver = json_decode ( $value ['staff'] );
  127. foreach ( $ver as $k => $v ) {
  128. array_push ( $list2, $v [0] );
  129. }
  130. }
  131. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  132. $eidList = array_filter ( explode ( ",", $eidList ) );
  133. $this->executeId = array_merge ( $list2, $eidList );
  134. $this->verifyId = $list;
  135. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  136. // 检测用户信息完成
  137. $this->data ['isStaffCompleteMsg'] = false;
  138. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  139. if (! empty ( $detail ))
  140. $this->data ['isStaffCompleteMsg'] = true;
  141. return "/";
  142. }
  143. }
  144. Doo::loadCore ( 'uri/DooUriRouter' );
  145. $router = new DooUriRouter ();
  146. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  147. if ($routeRs ['1'] != "login") {
  148. header ( 'Content-Type:text/html;charset=utf-8' );
  149. @header ( "Location: /login" );
  150. }
  151. }
  152. function saeaBorad() {
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'verify' );
  156. $verify = new verify ();
  157. Doo::loadModel ( 'L_category' );
  158. $lCategory = new L_category ();
  159. Doo::loadModel ( "role" );
  160. $role = new role ();
  161. Doo::loadModel ( "receiptLog" );
  162. $receiptLog = new receiptLog ();
  163. Doo::loadClass ( 'XDeode' );
  164. $XDeode = new XDeode ( 7 );
  165. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  166. $receiptDetail = $receipt->find ( array (
  167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  168. 'desc' => 'rid',
  169. 'asArray' => true
  170. ) );
  171. foreach ( $receiptDetail as $key => $value ) {
  172. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  173. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  174. $veList = $verify->getOne ( array (
  175. 'where' => 'vid=' . $value ['verify'],
  176. 'asArray' => true
  177. ) );
  178. $v = json_decode ( $veList ['staff'] );
  179. array_push ( $v [0], $veList ['description'] );
  180. foreach ( $v as $n => $m ) {
  181. if ($m ['1'] == 'ROLE') {
  182. $roleInfo = $role->getOne ( array (
  183. 'where' => 'rid=' . $m [0],
  184. 'asArray' => true
  185. ) );
  186. $v [$n] [1] = $roleInfo ['name'];
  187. }
  188. }
  189. $receiptDetail [$key] ['staff'] = $v;
  190. $category = $lCategory->getOne ( array (
  191. 'where' => 'cid=' . $value ['cid'],
  192. 'asArray' => true
  193. ) );
  194. $receiptDetail [$key] ['category'] = $category ['title'];
  195. }
  196. // print_r($receiptLogList);
  197. Doo::loadModel ( 'RAssist' );
  198. $RAssist = new RAssist ();
  199. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  200. $data ['receiptExtendList'] = $receiptExtendList;
  201. $data ['receiptLogList'] = $receiptLogList;
  202. $data ['receiptDetail'] = $receiptDetail;
  203. $data ['memu'] = "receipt";
  204. $data ['staff'] = $this->staff;
  205. $data ['receiptMemu'] = 'saeaBorad';
  206. $data ['verifyId'] = $this->verifyId;
  207. $data ['executeId'] = $this->executeId;
  208. $this->render ( "/admin/saeaBorad", $data );
  209. }
  210. function remitAdd() {
  211. Doo::loadModel ( 'accountItem' );
  212. Doo::loadModel ( 'verify' );
  213. Doo::loadModel ( 'receipt' );
  214. Doo::loadModel ( 'L_category' );
  215. $lCategory = new L_category ();
  216. $receipt = new receipt ();
  217. $verify = new verify ();
  218. $accountItem = new accountItem ();
  219. Doo::loadModel ( "role" );
  220. $role = new role ();
  221. $acItem = $accountItem->find ( array (
  222. 'asArray' => true
  223. ) );
  224. $veList = $verify->getVerifyBySubordinate('REMIT');
  225. $data ['category'] = $lCategory->find ( array (
  226. 'asArray' => true
  227. ) );
  228. $data ['veList'] = $veList;
  229. $data ['acItem'] = $acItem;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/admin/remitAdd", $data );
  236. }
  237. function remitAddDo() {
  238. $agency = $this->get_args ( 'agency' );
  239. $travel = $this->get_args ( 'travel' );
  240. $train = $this->get_args ( 'train' );
  241. $other = $this->get_args ( 'other' );
  242. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  243. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  244. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  245. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  246. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  247. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  248. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  249. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  250. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  251. // print_r($agency);die;
  252. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  253. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  254. header ( 'Content-Type:text/html;charset=utf-8' );
  255. die ( '请填写联行号' );
  256. }
  257. Doo::loadModel ( 'receipt' );
  258. Doo::loadModel ( 'receiptDetail' );
  259. Doo::loadModel ( 'accountItem' );
  260. $accountItem = new accountItem ();
  261. $receipt = new receipt ();
  262. Doo::loadModel ( 'enclosur' );
  263. Doo::loadModel ( 'execute' );
  264. $execute = new execute ();
  265. $executeDetail = $execute->getOne ( array (
  266. 'where' => 'mold="对公汇款执行人"',
  267. 'asArray' => true
  268. ) );
  269. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  270. $aItem = $accountItem->find ( array (
  271. 'where' => 'name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保"',
  272. 'asArray' => true
  273. ) );
  274. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  275. $ag = $tr = $ta = $ot = 0;
  276. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  277. foreach ( $aItem as $key => $value ) {
  278. if ($value ['category'] == $this->AGENCY) {
  279. if (isset ( $agency [$ag] )) {
  280. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  281. array_push ( $accountJson [$this->AGENCY], array (
  282. 'aid' => $value ['aid'],
  283. 'name' => $value ['name'],
  284. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  285. ) );
  286. $sum += $agency [$ag];
  287. $agencySum += $agency [$ag];
  288. }
  289. }
  290. $ag ++;
  291. }
  292. }
  293. $accountJson ['cSum'] = array (
  294. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  295. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  296. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  297. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  298. );
  299. // 报销单
  300. $receipt->accountItem = json_encode ( $accountJson );
  301. $receipt->staff = $this->staff [0] ['sid'];
  302. $receipt->sum = number_format ( $sum, 2, '.', '' );
  303. $receipt->date = date ( "Y-m-d" );
  304. $receipt->cid = $cid;
  305. $receipt->status = 5;
  306. $receipt->Rtype = 2;
  307. // 修改审批流程加入角色
  308. $receipt->verify = $verify;
  309. $receipt->executeCopy = $executeDetail ['staff'];
  310. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  311. $order = array (
  312. "\r\n",
  313. "\n",
  314. "\r"
  315. );
  316. $replace = '<br/>';
  317. $explanation = str_replace ( $order, $replace, $explanation );
  318. $receipt->explanation = $explanation;
  319. $receipt->remittanceName = $remittanceName;
  320. $receipt->bankName = $bankName;
  321. $receipt->bankNumber = $bankNumber;
  322. $receipt->remittanceBankType = $remittanceBankType;
  323. if ($remittanceBankType == 1)
  324. $receipt->coupletNumber = $coupletNumber;
  325. $rid = $receipt->insert ();
  326. // 附件
  327. if (! empty ( $enclosurName )) {
  328. $enclosurArray = explode ( '-', $enclosurName );
  329. foreach ( $enclosurArray as $value ) {
  330. $enclosur = new enclosur ();
  331. $enclosur->name = $value;
  332. $enclosur->rid = $rid;
  333. $enclosur->insert ();
  334. }
  335. // print_r($enclosurArray);die;
  336. }
  337. // 报销详情
  338. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  339. $receiptDetail = new receiptDetail ();
  340. $receiptDetail->staff = $this->staff [0] ['sid'];
  341. $receiptDetail->item = $value ['name'];
  342. $receiptDetail->itemCategory = $this->AGENCY;
  343. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  344. $receiptDetail->date = date ( "Y-m-d" );
  345. $receiptDetail->cid = $cid;
  346. $receiptDetail->rid = $rid;
  347. $receiptDetail->status = 4;
  348. $receiptDetail->insert ();
  349. }
  350. return "/saeaBorad";
  351. } else
  352. die ( 'illegal request' );
  353. }
  354. function remitEdit() {
  355. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  356. Doo::loadClass ( 'XDeode' );
  357. $XDeode = new XDeode ( 7 );
  358. $rid = $XDeode->decode ( $ridKey );
  359. if (! is_numeric ( $rid ))
  360. die ( 'illegal request' );
  361. Doo::loadModel ( 'accountItem' );
  362. Doo::loadModel ( 'verify' );
  363. Doo::loadModel ( 'receipt' );
  364. $receipt = new receipt ();
  365. $verify = new verify ();
  366. $accountItem = new accountItem ();
  367. Doo::loadModel ( 'L_category' );
  368. $lCategory = new L_category ();
  369. Doo::loadModel ( "role" );
  370. $role = new role ();
  371. Doo::loadModel ( 'enclosur' );
  372. $enclosur = new enclosur ();
  373. $receiptDetail = $receipt->getOne ( array (
  374. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  375. 'asArray' => true
  376. ) );
  377. if (empty ( $receiptDetail ))
  378. return "/saeaCreate";
  379. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  380. $acItem = $accountItem->find ( array (
  381. 'asArray' => true
  382. ) );
  383. $veList = $verify->getVerifyBySubordinate('REMIT');
  384. // 配置编辑信息
  385. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  386. foreach ( $acItem as $key => $value ) {
  387. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  388. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  389. $acItem [$key] ['price'] = $v ['price'];
  390. }
  391. }
  392. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  393. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  394. $acItem [$key] ['price'] = $v ['price'];
  395. }
  396. }
  397. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  398. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  399. $acItem [$key] ['price'] = $v ['price'];
  400. }
  401. }
  402. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  403. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  404. $acItem [$key] ['price'] = $v ['price'];
  405. }
  406. }
  407. }
  408. $data ['category'] = $lCategory->find ( array (
  409. 'asArray' => true
  410. ) );
  411. $data ['enclosurList'] = $enclosurList;
  412. $data ['cSum'] = $accountItemList ['cSum'];
  413. $data ['sum'] = $receiptDetail ['sum'];
  414. $data ['receiptDetail'] = $receiptDetail;
  415. $data ['veList'] = $veList;
  416. $data ['acItem'] = $acItem;
  417. $data ['memu'] = "receipt";
  418. $data ['staff'] = $this->staff;
  419. $data ['receiptMemu'] = 'saeaBorad';
  420. $data ['verify'] = $receiptDetail ['verify'];
  421. $data ['verifyId'] = $this->verifyId;
  422. $data ['executeId'] = $this->executeId;
  423. $data ['rid'] = $rid;
  424. $data ['ridKey'] = $ridKey;
  425. $this->render ( "/admin/remitEdit", $data );
  426. }
  427. function remitEdiDo() {
  428. $agency = $this->get_args ( 'agency' );
  429. $travel = $this->get_args ( 'travel' );
  430. $train = $this->get_args ( 'train' );
  431. $other = $this->get_args ( 'other' );
  432. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  433. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  434. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  435. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  436. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  437. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  438. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  439. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  440. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  441. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  442. Doo::loadClass ( 'XDeode' );
  443. $XDeode = new XDeode ( 7 );
  444. $rid = $XDeode->decode ( $ridKey );
  445. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  446. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  447. header ( 'Content-Type:text/html;charset=utf-8' );
  448. die ( '请填写联行号' );
  449. }
  450. Doo::loadModel ( 'receipt' );
  451. Doo::loadModel ( 'receiptDetail' );
  452. Doo::loadModel ( 'accountItem' );
  453. $accountItem = new accountItem ();
  454. $receipt = new receipt ();
  455. Doo::loadModel ( 'enclosur' );
  456. $enclosur = new enclosur ();
  457. Doo::loadModel ( 'execute' );
  458. $execute = new execute ();
  459. $executeDetail = $execute->getOne ( array (
  460. 'where' => 'mold="对公汇款执行人"',
  461. 'asArray' => true
  462. ) );
  463. $receiptDetail = $receipt->getOne ( array (
  464. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  465. 'asArray' => true
  466. ) );
  467. if (empty ( $receiptDetail ))
  468. return "/saeaBorad";
  469. $aItem = $accountItem->find ( array (
  470. 'where' => 'name like "办公费用" or name like "其他费用" or name like "公积金" or name like "社保"',
  471. 'asArray' => true
  472. ) );
  473. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  474. $ag = $tr = $ta = $ot = 0;
  475. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  476. foreach ( $aItem as $key => $value ) {
  477. if ($value ['category'] == $this->AGENCY) {
  478. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  479. array_push ( $accountJson [$this->AGENCY], array (
  480. 'aid' => $value ['aid'],
  481. 'name' => $value ['name'],
  482. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  483. ) );
  484. $sum += $agency [$ag];
  485. $agencySum += $agency [$ag];
  486. }
  487. $ag ++;
  488. }
  489. }
  490. $accountJson ['cSum'] = array (
  491. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  492. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  493. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  494. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  495. );
  496. // 报销单
  497. $rid = $receipt->rid = $receiptDetail ['rid'];
  498. $receipt->accountItem = json_encode ( $accountJson );
  499. $receipt->staff = $this->staff [0] ['sid'];
  500. $receipt->sum = number_format ( $sum, 2, '.', '' );
  501. $receipt->date = date ( "Y-m-d" );
  502. $receipt->cid = $cid;
  503. if ($receiptDetail ['Rtype'] == 1)
  504. $receipt->status = 7;
  505. else
  506. $receipt->status = 5;
  507. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  508. $receipt->verify = $verify;
  509. $receipt->executeCopy = $executeDetail ['staff'];
  510. $order = array (
  511. "\r\n",
  512. "\n",
  513. "\r"
  514. );
  515. $replace = '<br/>';
  516. $explanation = str_replace ( $order, $replace, $explanation );
  517. $receipt->explanation = $explanation;
  518. $receipt->remittanceName = $remittanceName;
  519. $receipt->bankName = $bankName;
  520. $receipt->bankNumber = $bankNumber;
  521. $receipt->remittanceBankType = $remittanceBankType;
  522. if ($remittanceBankType == 1)
  523. $receipt->coupletNumber = $coupletNumber;
  524. $receipt->update ();
  525. $receiptDetail = new receiptDetail ();
  526. $receiptDetail->delete ( array (
  527. 'where' => 'rid=' . $rid
  528. ) );
  529. // 报销详情
  530. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  531. $receiptDetail = new receiptDetail ();
  532. $receiptDetail->staff = $this->staff [0] ['sid'];
  533. $receiptDetail->item = $value ['name'];
  534. $receiptDetail->itemCategory = $this->AGENCY;
  535. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  536. $receiptDetail->date = date ( "Y-m-d" );
  537. $receiptDetail->cid = $cid;
  538. $receiptDetail->rid = $rid;
  539. $receiptDetail->status = 4;
  540. $receiptDetail->insert ();
  541. }
  542. // 附件
  543. if (! empty ( $enclosurName )) {
  544. $enclosurArray = explode ( '-', $enclosurName );
  545. foreach ( $enclosurArray as $value ) {
  546. $enclosur = new enclosur ();
  547. $enclosur->name = $value;
  548. $enclosur->rid = $rid;
  549. $enclosur->insert ();
  550. }
  551. }
  552. }
  553. return "/saeaBorad";
  554. }
  555. function remitApproval() {
  556. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  557. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  558. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  559. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  560. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  561. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  562. if (empty ( $status ))
  563. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  564. $vidList = array ();
  565. $button = 0;
  566. Doo::loadModel ( 'verify' );
  567. Doo::loadModel ( 'receipt' );
  568. Doo::loadModel ( 'staff' );
  569. $staff = new staff ();
  570. $receipt = new receipt ();
  571. $verify = new verify ();
  572. Doo::loadModel ( 'L_category' );
  573. $Lcategory = new L_category ();
  574. Doo::loadModel ( 'enclosur' );
  575. $enclosur = new enclosur ();
  576. // user verify ID
  577. $verifyDetail = $verify->find ( array (
  578. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  579. 'asArray' => true
  580. ) );
  581. foreach ( $verifyDetail as $key => $value ) {
  582. array_push ( $vidList, $value ['vid'] );
  583. }
  584. $vid = implode ( ",", $vidList );
  585. if (empty ( $verifyDetail ))
  586. $vid = 0;
  587. $categoryList = $Lcategory->find ( array (
  588. 'asArray' => true
  589. ) );
  590. $staffList = $staff->find ( array (
  591. 'where' => 'cid=' . $cid,
  592. 'asArray' => true
  593. ) );
  594. $ap = "";
  595. if ($status == 4) {
  596. $ap = 4;
  597. $status = 2;
  598. }
  599. // get Receipt By verifyID status 2
  600. $receiptList = $receipt->find ( array (
  601. 'where' => 'rid =' . $rid . ' and status=2',
  602. 'desc' => 'rid',
  603. 'asArray' => true
  604. ) );
  605. if (empty ( $receiptList )) {
  606. die ( 'illegal request' );
  607. }
  608. $Locate = 0;
  609. $roleId = 0;
  610. if ($ap == 4)
  611. $status = 4;
  612. foreach ( $receiptList as $key => $value ) {
  613. $receiptList [$key] ['Locate'] = $Locate;
  614. $Locate ++;
  615. $receiptList [$key] ['reviseDetail'] = array ();
  616. if (! empty ( $value ['reviseDetail'] ))
  617. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  618. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  619. $categoryDetil = $Lcategory->getOne ( array (
  620. 'where' => 'cid=' . $value ['cid'],
  621. 'asArray' => true
  622. ) );
  623. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  624. // 检测编辑状态
  625. $verifyList = $verify->getOne ( array (
  626. 'where' => 'vid=' . $value ['verify'],
  627. 'asArray' => true
  628. ) );
  629. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  630. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  631. Doo::loadModel ( 'role' );
  632. $role = new role ();
  633. // print_r($verifyList);
  634. $flag = true;
  635. $roleKey = 0;
  636. $endStaffArray = array ();
  637. $roleArrayCopy = array ();
  638. foreach ( $verifyList as $k => $v ) {
  639. // init verifyStaff
  640. if ($v [1] == 'ROLE') {
  641. if (! empty ( $verifyStaff )) {
  642. $endStaffArray = end ( $verifyStaff );
  643. if ($v [0] == $endStaffArray ['nextStaff']) {
  644. $roleId = $v [0];
  645. }
  646. }
  647. $roleVerify = json_decode ( $v [3], true );
  648. $roleKey = $k;
  649. $roleArray = array ();
  650. $rolename = $role->getOne ( array (
  651. 'where' => 'rid=' . $v [0],
  652. 'asArray' => true
  653. ) );
  654. foreach ( $roleVerify as $o => $p ) {
  655. $staffID = explode ( '_', $p );
  656. $staffInfo = $staff->getOne ( array (
  657. 'where' => 'sid=' . $staffID [0],
  658. 'asArray' => true
  659. ) );
  660. // print_r($staffID);
  661. $exp = array (
  662. 0 => $staffInfo ['sid'],
  663. 1 => $staffID [1],
  664. 2 => $staffInfo ['avatar'],
  665. 'date' => '',
  666. 'date' => '',
  667. 'opinion' => '',
  668. 'status' => '',
  669. 'rolename' => $rolename ['name']
  670. );
  671. array_push ( $roleArray, $exp );
  672. }
  673. $roleArrayCopy [$v [0]] = $roleArray;
  674. // $verifyList[$k]['roleArray']=$roleArray;
  675. }
  676. // print_r($roleArray);
  677. $verifyList [$k] ['date'] = "";
  678. $verifyList [$k] ['opinion'] = "";
  679. $verifyList [$k] ['status'] = "";
  680. if (empty ( $verifyStaff )) {
  681. $verifyList [$k] ['date'] = "";
  682. $verifyList [$k] ['opinion'] = "";
  683. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  684. $verifyList [$k] ['status'] = 4;
  685. $button = 4;
  686. $flag = false;
  687. }
  688. } else {
  689. foreach ( $verifyStaff as $m => $u ) {
  690. if ($v [0] == $m) {
  691. $verifyList [$k] ['date'] = $u ['date'];
  692. $verifyList [$k] ['opinion'] = $u ['opinion'];
  693. $verifyList [$k] ['status'] = $u ['status'];
  694. $flag = false;
  695. break;
  696. }
  697. }
  698. $endStaffArray = end ( $verifyStaff );
  699. if (isset ( $endStaffArray ['ROLE'] )) {
  700. } else {
  701. $endKey = key ( $verifyStaff );
  702. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  703. $button = 4;
  704. $verifyList [$k] ['status'] = 4;
  705. }
  706. }
  707. }
  708. }
  709. $rolename ['name'] = '';
  710. if (! empty ( $roleId )) {
  711. Doo::loadModel ( 'role' );
  712. $role = new role ();
  713. $rolename = $role->getOne ( array (
  714. 'where' => 'rid=' . $roleId,
  715. 'asArray' => true
  716. ) );
  717. }
  718. if (! empty ( $verifyStaff ))
  719. $endStaffArray = end ( $verifyStaff );
  720. $KOP = false;
  721. foreach ( $roleArrayCopy as $P => $A ) {
  722. foreach ( $A as $MKI => $AVL ) {
  723. if (! empty ( $verifyStaff )) {
  724. // &&$rolename['rid']==$endStaffArray['nextStaff']
  725. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  726. $button = 4;
  727. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  728. }
  729. foreach ( $verifyStaff as $m => $u ) {
  730. $AVLFK = $AVL [0] . '_R';
  731. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  732. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  733. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  734. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  735. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  736. break;
  737. }
  738. }
  739. } else {
  740. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  741. $button = 4;
  742. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  743. }
  744. }
  745. // $roleArray[$MKI]['rolename']=$rolename['name'];
  746. $KOP = true;
  747. }
  748. }
  749. foreach ( $roleArrayCopy as $k => $v ) {
  750. foreach ( $verifyList as $m => $n ) {
  751. if ($n [0] == $k) {
  752. array_splice ( $verifyList, $m, 1, $v );
  753. }
  754. }
  755. }
  756. $receiptList [$key] ['verifyList'] = $verifyList;
  757. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  758. 'where' => 'sid=' . $value ['staff'],
  759. 'asArray' => true
  760. ) );
  761. $receiptList [$key] ['button'] = $button;
  762. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  763. }
  764. $mothHtml = "";
  765. for($i = 1; $i <= 12; $i ++) {
  766. if ($month == $i)
  767. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  768. else
  769. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  770. }
  771. // 获取审批日志
  772. Doo::loadModel ( 'receiptLog' );
  773. $receiptLog = new receiptLog ();
  774. $rlList = array ();
  775. $rlInfo = $receiptLog->getOne ( array (
  776. 'where' => 'rid=' . $rid . ' and status=4',
  777. 'asArray' => true
  778. ) );
  779. $tijdate = $receiptLog->getOne ( array (
  780. 'where' => 'rid=' . $rid . ' and status=2',
  781. 'asc' => 'rlid',
  782. 'asArray' => true
  783. ) );
  784. if (! empty ( $rlInfo )) {
  785. $rlList = $receiptLog->find ( array (
  786. 'where' => 'rid=' . $rid,
  787. 'asc' => 'rlid',
  788. 'asArray' => true
  789. ) );
  790. }
  791. $receiptList [0] ['rlList'] = $rlList;
  792. $enclosurList = $enclosur->find ( array (
  793. 'where' => 'rid=' . $rid,
  794. 'asArray' => true
  795. ) );
  796. $enclosurHtml = '';
  797. foreach ( $enclosurList as $value ) {
  798. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  799. }
  800. // print_r($receiptList);
  801. $data ['enclosurHtml'] = $enclosurHtml;
  802. $data ['rolename'] = $rolename ['name'];
  803. $data ['datetij'] = $tijdate ['date'];
  804. $data ['mothHtml'] = $mothHtml;
  805. $data ['rid'] = $rid;
  806. $data ['receiptList'] = $receiptList;
  807. $data ['receiptApprovalCount'] = count ( $receiptList );
  808. $data ['status'] = $status;
  809. $data ['year'] = $year;
  810. $data ['categoryList'] = $categoryList;
  811. $data ['staffList'] = $staffList;
  812. $data ['cid'] = $cid;
  813. $data ['sid'] = $sid;
  814. $data ['ap'] = $ap;
  815. $data ['memu'] = "receipt";
  816. $data ['staff'] = $this->staff;
  817. $data ['receiptMemu'] = 'approvalExpenses';
  818. $data ['verifyId'] = $this->verifyId;
  819. $data ['executeId'] = $this->executeId;
  820. $this->render ( "/admin/remitApproval", $data );
  821. }
  822. function saeaLoanAdd() {
  823. Doo::loadModel ( 'verify' );
  824. $verify = new verify ();
  825. Doo::loadModel ( "role" );
  826. $role = new role ();
  827. Doo::loadModel ( 'L_category' );
  828. $lCategory = new L_category ();
  829. $veList = $verify->getVerifyBySubordinate('LOAN');
  830. $data ['category'] = $lCategory->find ( array (
  831. 'asArray' => true
  832. ) );
  833. $data ['veList'] = $veList;
  834. $data ['memu'] = "receipt";
  835. $data ['staff'] = $this->staff;
  836. $data ['receiptMemu'] = 'saeaBorad';
  837. $data ['verifyId'] = $this->verifyId;
  838. $data ['executeId'] = $this->executeId;
  839. $this->render ( "/admin/saeaLoanAdd", $data );
  840. }
  841. function saeaLoanAddDo() {
  842. $agency = $this->get_args ( 'agency' );
  843. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  844. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  845. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  846. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  847. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  848. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  849. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  850. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  851. // die;
  852. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  853. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  854. header ( 'Content-Type:text/html;charset=utf-8' );
  855. die ( '请填写联行号' );
  856. }
  857. Doo::loadModel ( 'receipt' );
  858. Doo::loadModel ( 'receiptDetail' );
  859. Doo::loadModel ( 'accountItem' );
  860. $accountItem = new accountItem ();
  861. $receipt = new receipt ();
  862. Doo::loadModel ( 'loanReceipt' );
  863. $loanReceipt = new loanReceipt ();
  864. Doo::loadModel ( 'execute' );
  865. $execute = new execute ();
  866. Doo::loadModel ( 'enclosur' );
  867. $executeDetail = $execute->getOne ( array (
  868. 'where' => 'mold="借款执行人"',
  869. 'asArray' => true
  870. ) );
  871. $aItem = $accountItem->find ( array (
  872. 'asArray' => true
  873. ) );
  874. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  875. $ag = $tr = $ta = $ot = 0;
  876. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  877. array_push ( $accountJson ['借款费用'], array (
  878. 'aid' => 0,
  879. 'name' => '申请金额',
  880. 'price' => number_format ( $agency, 2, '.', '' )
  881. ) );
  882. $sum += $agency;
  883. $agencySum += $agency;
  884. $accountJson ['cSum'] = array (
  885. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  886. 'agencySum' => number_format ( 0, 2, '.', '' ),
  887. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  888. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  889. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  890. );
  891. // 借款数据备份
  892. $loanReceipt->loanItem = json_encode ( $accountJson );
  893. $loanReceipt->staff = $this->staff [0] ['sid'];
  894. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  895. $loanReceipt->date = date ( "Y-m-d" );
  896. $loanReceipt->cid = $cid;
  897. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  898. $loanReceipt->status = 5;
  899. $loanReceipt->Rtype = 1;
  900. $loanReceipt->verify = $verify;
  901. $receipt->receiptOrder = $receipt->receiptOrder;
  902. // 添加HTML换行符
  903. // var_dump($explanation);
  904. $order = array (
  905. "\r\n",
  906. "\n",
  907. "\r"
  908. );
  909. $replace = '<br/>';
  910. $explanation = str_replace ( $order, $replace, $explanation );
  911. // $explanation=str_replace('\r',"<br/>",$explanation);
  912. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  913. $loanReceipt->explanation = $explanation;
  914. $loanRid = $loanReceipt->insert ();
  915. // 报销单
  916. $receipt->loanItem = json_encode ( $accountJson );
  917. $receipt->staff = $this->staff [0] ['sid'];
  918. $receipt->sum = number_format ( $sum, 2, '.', '' );
  919. $receipt->date = date ( "Y-m-d" );
  920. $receipt->cid = $cid;
  921. // 特殊状态
  922. $receipt->status = 5;
  923. $receipt->Rtype = 1;
  924. $receipt->loanRid = $loanRid;
  925. // 修改审批流程加入角色
  926. $receipt->verify = $verify;
  927. $receipt->executeCopy = $executeDetail ['staff'];
  928. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  929. $receipt->explanation = $explanation;
  930. $receipt->remittanceName = $remittanceName;
  931. $receipt->bankName = $bankName;
  932. $receipt->bankNumber = $bankNumber;
  933. $receipt->remittanceBankType = $remittanceBankType;
  934. if ($remittanceBankType == 1)
  935. $receipt->coupletNumber = $coupletNumber;
  936. $rid = $receipt->insert ();
  937. return "/saeaBorad";
  938. } else
  939. die ( 'illegal request' );
  940. }
  941. function saeaLoanEdi() {
  942. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  943. Doo::loadClass ( 'XDeode' );
  944. $XDeode = new XDeode ( 7 );
  945. $rid = $XDeode->decode ( $ridKey );
  946. if (! is_numeric ( $rid ))
  947. die ( 'illegal request' );
  948. Doo::loadModel ( 'verify' );
  949. $verify = new verify ();
  950. Doo::loadModel ( "role" );
  951. $role = new role ();
  952. Doo::loadModel ( 'L_category' );
  953. $lCategory = new L_category ();
  954. Doo::loadModel ( 'receipt' );
  955. $receipt = new receipt ();
  956. $receiptInfo = $receipt->getOne ( array (
  957. 'where' => 'rid=' . $rid,
  958. 'asArray' => true
  959. ) );
  960. $veList = $verify->find ( array (
  961. 'where'=>'subordinate like "%LOAN%"',
  962. 'asArray' => true
  963. ) );
  964. foreach ( $veList as $key => $value ) {
  965. $v = json_decode ( $value ['staff'] );
  966. $list = array ();
  967. foreach ( $v as $n => $m ) {
  968. if ($m ['1'] == 'ROLE') {
  969. $roleInfo = $role->getOne ( array (
  970. 'where' => 'rid=' . $m [0],
  971. 'asArray' => true
  972. ) );
  973. $v [$n] [1] = $roleInfo ['name'];
  974. array_push ( $list, $roleInfo ['name'] );
  975. } else {
  976. array_push ( $list, $v [$n] [1] );
  977. }
  978. }
  979. $veList [$key] ['staff'] = implode ( '>', $list );
  980. }
  981. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  982. // print_r($receiptInfo);
  983. $data ['receiptInfo'] = $receiptInfo;
  984. $data ['category'] = $lCategory->find ( array (
  985. 'asArray' => true
  986. ) );
  987. $data ['veList'] = $veList;
  988. $data ['ridKey'] = $ridKey;
  989. $data ['memu'] = "receipt";
  990. $data ['staff'] = $this->staff;
  991. $data ['receiptMemu'] = 'saeaBorad';
  992. $data ['verifyId'] = $this->verifyId;
  993. $data ['executeId'] = $this->executeId;
  994. $this->render ( "/admin/saeaLoanEdi", $data );
  995. }
  996. function saeaLoanEdiDo() {
  997. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  998. $agency = $this->get_args ( 'agency' );
  999. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1000. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1001. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1002. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1003. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1004. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1005. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1006. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1007. // die;
  1008. Doo::loadClass ( 'XDeode' );
  1009. $XDeode = new XDeode ( 7 );
  1010. $rid = $XDeode->decode ( $ridKey );
  1011. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1012. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1013. header ( 'Content-Type:text/html;charset=utf-8' );
  1014. die ( '请填写联行号' );
  1015. }
  1016. Doo::loadModel ( 'receipt' );
  1017. Doo::loadModel ( 'receiptDetail' );
  1018. Doo::loadModel ( 'accountItem' );
  1019. $accountItem = new accountItem ();
  1020. $receipt = new receipt ();
  1021. Doo::loadModel ( 'loanReceipt' );
  1022. $loanReceipt = new loanReceipt ();
  1023. Doo::loadModel ( 'enclosur' );
  1024. Doo::loadModel ( 'execute' );
  1025. $execute = new execute ();
  1026. $executeDetail = $execute->getOne ( array (
  1027. 'where' => 'mold="借款执行人"',
  1028. 'asArray' => true
  1029. ) );
  1030. $receiptDetail = $receipt->getOne ( array (
  1031. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1032. 'asArray' => true
  1033. ) );
  1034. if (empty ( $receiptDetail ))
  1035. die ( '参数错误' );
  1036. $aItem = $accountItem->find ( array (
  1037. 'asArray' => true
  1038. ) );
  1039. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1040. $ag = $tr = $ta = $ot = 0;
  1041. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1042. array_push ( $accountJson ['借款费用'], array (
  1043. 'aid' => 0,
  1044. 'name' => '申请金额',
  1045. 'price' => number_format ( $agency, 2, '.', '' )
  1046. ) );
  1047. $sum += $agency;
  1048. $agencySum += $agency;
  1049. $accountJson ['cSum'] = array (
  1050. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1051. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1052. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1053. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1054. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1055. );
  1056. // 报销单
  1057. $receipt->loanItem = json_encode ( $accountJson );
  1058. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1059. $receipt->cid = $cid;
  1060. // 特殊状态
  1061. // 修改审批流程加入角色
  1062. if ($receiptDetail ['status'] != 4)
  1063. $receipt->verify = $verify;
  1064. $order = array (
  1065. "\r\n",
  1066. "\n",
  1067. "\r"
  1068. );
  1069. $replace = '<br/>';
  1070. $explanation = str_replace ( $order, $replace, $explanation );
  1071. $receipt->explanation = $explanation;
  1072. $receipt->remittanceName = $remittanceName;
  1073. $receipt->bankName = $bankName;
  1074. $receipt->bankNumber = $bankNumber;
  1075. $receipt->remittanceBankType = $remittanceBankType;
  1076. if ($remittanceBankType == 1)
  1077. $receipt->coupletNumber = $coupletNumber;
  1078. $receipt->update ( array (
  1079. 'where' => 'rid=' . $rid
  1080. ) );
  1081. // 借款数据更新
  1082. $loanReceipt->loanItem = json_encode ( $accountJson );
  1083. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1084. $loanReceipt->cid = $cid;
  1085. if ($receiptDetail ['status'] != 4)
  1086. $loanReceipt->verify = $verify;
  1087. $loanReceipt->explanation = $explanation;
  1088. $receipt->executeCopy = $executeDetail ['staff'];
  1089. $loanReceipt->update ( array (
  1090. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1091. ) );
  1092. }
  1093. return "/saeaBorad";
  1094. }
  1095. function saeaLoanReceiptAdd() {
  1096. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1097. Doo::loadModel ( 'receipt' );
  1098. $receipt = new receipt ();
  1099. Doo::loadModel ( 'loanReceipt' );
  1100. $loanReceipt = new loanReceipt ();
  1101. Doo::loadModel ( 'L_category' );
  1102. $Lcategory = new L_category ();
  1103. Doo::loadModel ( 'verify' );
  1104. Doo::loadModel ( 'statistics' );
  1105. $statistics = new statistics ();
  1106. $verify = new verify ();
  1107. Doo::loadModel ( 'staff' );
  1108. $staff = new staff ();
  1109. $receiptDetail = $receipt->getOne ( array (
  1110. 'where' => 'rid=' . $rid,
  1111. 'desc' => 'rid',
  1112. 'asArray' => true
  1113. ) );
  1114. $receiptList = $loanReceipt->find ( array (
  1115. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1116. 'desc' => 'rid',
  1117. 'asArray' => true
  1118. ) );
  1119. $Locate = 0;
  1120. $roleId = 0;
  1121. $button = 0;
  1122. foreach ( $receiptList as $key => $value ) {
  1123. $receiptList [$key] ['Locate'] = $Locate;
  1124. $Locate ++;
  1125. $receiptList [$key] ['reviseDetail'] = array ();
  1126. if (! empty ( $value ['reviseDetail'] ))
  1127. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1128. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1129. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1130. $categoryDetil = $Lcategory->getOne ( array (
  1131. 'where' => 'cid=' . $value ['cid'],
  1132. 'asArray' => true
  1133. ) );
  1134. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1135. // 检测编辑状态
  1136. $verifyList = $verify->getOne ( array (
  1137. 'where' => 'vid=' . $value ['verify'],
  1138. 'asArray' => true
  1139. ) );
  1140. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1141. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1142. Doo::loadModel ( 'role' );
  1143. $role = new role ();
  1144. $flag = true;
  1145. $roleKey = 0;
  1146. $endStaffArray = array ();
  1147. $roleArrayCopy = array ();
  1148. foreach ( $verifyList as $k => $v ) {
  1149. // init verifyStaff
  1150. if ($v [1] == 'ROLE') {
  1151. if (! empty ( $verifyStaff )) {
  1152. $endStaffArray = end ( $verifyStaff );
  1153. // if ($v[0]==$endStaffArray['nextStaff']){
  1154. // $roleId=$v[0];
  1155. // }
  1156. }
  1157. $roleVerify = json_decode ( $v [3], true );
  1158. $roleKey = $k;
  1159. $roleArray = array ();
  1160. $rolename = $role->getOne ( array (
  1161. 'where' => 'rid=' . $v [0],
  1162. 'asArray' => true
  1163. ) );
  1164. foreach ( $roleVerify as $o => $p ) {
  1165. $staffID = explode ( '_', $p );
  1166. $staffInfo = $staff->getOne ( array (
  1167. 'where' => 'sid=' . $staffID [0],
  1168. 'asArray' => true
  1169. ) );
  1170. // print_r($staffID);
  1171. $exp = array (
  1172. 0 => $staffInfo ['sid'],
  1173. 1 => $staffID [1],
  1174. 2 => $staffInfo ['avatar'],
  1175. 'date' => '',
  1176. 'date' => '',
  1177. 'opinion' => '',
  1178. 'status' => '',
  1179. 'rolename' => $rolename ['name']
  1180. );
  1181. array_push ( $roleArray, $exp );
  1182. }
  1183. $roleArrayCopy [$v [0]] = $roleArray;
  1184. // $verifyList[$k]['roleArray']=$roleArray;
  1185. }
  1186. $verifyList [$k] ['date'] = "";
  1187. $verifyList [$k] ['opinion'] = "";
  1188. $verifyList [$k] ['status'] = "";
  1189. if (empty ( $verifyStaff )) {
  1190. $verifyList [$k] ['date'] = "";
  1191. $verifyList [$k] ['opinion'] = "";
  1192. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1193. $verifyList [$k] ['status'] = 4;
  1194. $flag = false;
  1195. }
  1196. } else {
  1197. foreach ( $verifyStaff as $m => $u ) {
  1198. if ($v [0] == $m) {
  1199. $verifyList [$k] ['date'] = $u ['date'];
  1200. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1201. $verifyList [$k] ['status'] = $u ['status'];
  1202. $flag = false;
  1203. break;
  1204. }
  1205. }
  1206. $endStaffArray = end ( $verifyStaff );
  1207. if (isset ( $endStaffArray ['ROLE'] )) {
  1208. } else {
  1209. // $endKey=key($verifyStaff);
  1210. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1211. // $button=4;
  1212. // $verifyList[$k]['status']=4;
  1213. // }
  1214. }
  1215. }
  1216. }
  1217. $rolename ['name'] = '';
  1218. if (! empty ( $roleId )) {
  1219. Doo::loadModel ( 'role' );
  1220. $role = new role ();
  1221. $rolename = $role->getOne ( array (
  1222. 'where' => 'rid=' . $roleId,
  1223. 'asArray' => true
  1224. ) );
  1225. }
  1226. if (! empty ( $verifyStaff ))
  1227. $endStaffArray = end ( $verifyStaff );
  1228. $KOP = false;
  1229. foreach ( $roleArrayCopy as $P => $A ) {
  1230. foreach ( $A as $MKI => $AVL ) {
  1231. if (! empty ( $verifyStaff )) {
  1232. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1233. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1234. $button = 4;
  1235. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1236. }
  1237. foreach ( $verifyStaff as $m => $u ) {
  1238. $AVLFK = $AVL [0] . '_R';
  1239. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1240. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1241. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1242. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1243. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1244. break;
  1245. }
  1246. }
  1247. } else {
  1248. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1249. $button = 4;
  1250. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1251. }
  1252. }
  1253. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1254. $KOP = true;
  1255. }
  1256. }
  1257. foreach ( $roleArrayCopy as $k => $v ) {
  1258. foreach ( $verifyList as $m => $n ) {
  1259. if ($n [0] == $k) {
  1260. array_splice ( $verifyList, $m, 1, $v );
  1261. }
  1262. }
  1263. }
  1264. $receiptList [$key] ['verifyList'] = $verifyList;
  1265. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1266. 'where' => 'sid=' . $value ['staff'],
  1267. 'asArray' => true
  1268. ) );
  1269. $receiptList [$key] ['button'] = $button;
  1270. //
  1271. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1272. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1273. }
  1274. $data ['receiptList'] = $receiptList;
  1275. $data ['receiptDetail'] = $receiptDetail;
  1276. Doo::loadModel ( 'L_category' );
  1277. $lCategory = new L_category ();
  1278. Doo::loadModel ( 'accountItem' );
  1279. $accountItem = new accountItem ();
  1280. $acItem = $accountItem->find ( array (
  1281. 'asArray' => true
  1282. ) );
  1283. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1284. $data ['rid'] = $rid;
  1285. $data ['category'] = $lCategory->find ( array (
  1286. 'asArray' => true
  1287. ) );
  1288. $data ['veList'] = $veList;
  1289. $data ['acItem'] = $acItem;
  1290. $data ['memu'] = "receipt";
  1291. $data ['staff'] = $this->staff;
  1292. $data ['receiptMemu'] = 'saeaBorad';
  1293. $data ['verifyId'] = $this->verifyId;
  1294. $data ['executeId'] = $this->executeId;
  1295. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1296. }
  1297. function saeaLoanReceiptAddDo() {
  1298. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1299. $agency = $this->get_args ( 'agency' );
  1300. $travel = $this->get_args ( 'travel' );
  1301. $train = $this->get_args ( 'train' );
  1302. $other = $this->get_args ( 'other' );
  1303. $inttrain = $this->get_args ( 'inttrain' );
  1304. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1305. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1306. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1307. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1308. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1309. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1310. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1311. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1312. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1313. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1314. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1315. header ( 'Content-Type:text/html;charset=utf-8' );
  1316. die ( '请填写联行号' );
  1317. }
  1318. Doo::loadModel ( 'receipt' );
  1319. Doo::loadModel ( 'receiptDetail' );
  1320. Doo::loadModel ( 'accountItem' );
  1321. $accountItem = new accountItem ();
  1322. $receipt = new receipt ();
  1323. Doo::loadModel ( 'enclosur' );
  1324. Doo::loadModel ( 'execute' );
  1325. $execute = new execute ();
  1326. $executeDetail = $execute->getOne ( array (
  1327. 'where' => 'mold="借款费用执行人"',
  1328. 'asArray' => true
  1329. ) );
  1330. $receiptDet = $receipt->getOne ( array (
  1331. 'where' => 'rid=' . $rid,
  1332. 'asArray' => true
  1333. ) );
  1334. // if(!empty($receiptDetail))
  1335. // return "/referReceipt/".$receiptDetail['rid'];
  1336. $aItem = $accountItem->find ( array (
  1337. 'asArray' => true
  1338. ) );
  1339. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1340. $ag = $tr = $ta = $ot =$it = 0;
  1341. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1342. foreach ( $aItem as $key => $value ) {
  1343. if ($value ['category'] == $this->AGENCY) {
  1344. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1345. array_push ( $accountJson [$this->AGENCY], array (
  1346. 'aid' => $value ['aid'],
  1347. 'name' => $value ['name'],
  1348. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1349. ) );
  1350. $sum += $agency [$ag];
  1351. $agencySum += $agency [$ag];
  1352. }
  1353. $ag ++;
  1354. }
  1355. if ($value ['category'] == $this->TRAVEL) {
  1356. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1357. array_push ( $accountJson [$this->TRAVEL], array (
  1358. 'aid' => $value ['aid'],
  1359. 'name' => $value ['name'],
  1360. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1361. ) );
  1362. $sum += $travel [$tr];
  1363. $travelSum += $travel [$tr];
  1364. }
  1365. $tr ++;
  1366. }
  1367. if ($value ['category'] == $this->INTTRAIN) {
  1368. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1369. array_push ( $accountJson [$this->INTTRAIN], array (
  1370. 'aid' => $value ['aid'],
  1371. 'name' => $value ['name'],
  1372. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1373. ) );
  1374. $sum += $inttrain [$it];
  1375. $inttrainSum += $inttrain [$it];
  1376. }
  1377. $it ++;
  1378. }
  1379. if ($value ['category'] == $this->TRAIN) {
  1380. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1381. array_push ( $accountJson [$this->TRAIN], array (
  1382. 'aid' => $value ['aid'],
  1383. 'name' => $value ['name'],
  1384. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1385. ) );
  1386. $sum += $train [$ta];
  1387. $trainSum += $train [$ta];
  1388. }
  1389. $ta ++;
  1390. }
  1391. if ($value ['category'] == $this->OTHER) {
  1392. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1393. array_push ( $accountJson [$this->OTHER], array (
  1394. 'aid' => $value ['aid'],
  1395. 'name' => $value ['name'],
  1396. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1397. ) );
  1398. $sum += $other [$ot];
  1399. $otherSum += $other [$ot];
  1400. }
  1401. $ot ++;
  1402. }
  1403. }
  1404. $accountJson ['cSum'] = array (
  1405. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1406. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1407. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1408. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1409. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1410. );
  1411. // 报销单
  1412. $receipt->accountItem = json_encode ( $accountJson );
  1413. $receipt->staff = $this->staff [0] ['sid'];
  1414. $receipt->loanSum = $receiptDet ['sum'];
  1415. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1416. $receipt->date = date ( "Y-m-d" );
  1417. $receipt->pastDate = '';
  1418. $receipt->cid = $cid;
  1419. $receipt->status = 7;
  1420. // 修改审批流程加入角色
  1421. $receipt->verify = $verify;
  1422. $receipt->verifyStaff = '';
  1423. $receipt->executeStaff = '';
  1424. $receipt->executeCopy = $executeDetail ['staff'];
  1425. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1426. $receipt->explanation = $explanation;
  1427. $receipt->remittanceName = $remittanceName;
  1428. $receipt->bankName = $bankName;
  1429. $receipt->bankNumber = $bankNumber;
  1430. $receipt->remittanceBankType = $remittanceBankType;
  1431. if ($remittanceBankType == 1)
  1432. $receipt->coupletNumber = $coupletNumber;
  1433. $receipt->update ( array (
  1434. 'where' => 'rid=' . $rid
  1435. ) );
  1436. // 附件
  1437. if (! empty ( $enclosurName )) {
  1438. $enclosurArray = explode ( '-', $enclosurName );
  1439. foreach ( $enclosurArray as $value ) {
  1440. $enclosur = new enclosur ();
  1441. $enclosur->name = $value;
  1442. $enclosur->rid = $rid;
  1443. $enclosur->insert ();
  1444. }
  1445. // print_r($enclosurArray);die;
  1446. }
  1447. // 报销详情
  1448. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1449. $receiptDetail = new receiptDetail ();
  1450. $receiptDetail->staff = $this->staff [0] ['sid'];
  1451. $receiptDetail->item = $value ['name'];
  1452. $receiptDetail->itemCategory = $this->AGENCY;
  1453. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1454. $receiptDetail->date = date ( "Y-m-d" );
  1455. $receiptDetail->cid = $cid;
  1456. $receiptDetail->rid = $rid;
  1457. $receiptDetail->status = 4;
  1458. $receiptDetail->insert ();
  1459. }
  1460. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1461. $receiptDetail = new receiptDetail ();
  1462. $receiptDetail->staff = $this->staff [0] ['sid'];
  1463. $receiptDetail->item = $value ['name'];
  1464. $receiptDetail->itemCategory = $this->TRAVEL;
  1465. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1466. $receiptDetail->date = date ( "Y-m-d" );
  1467. $receiptDetail->cid = $cid;
  1468. $receiptDetail->rid = $rid;
  1469. $receiptDetail->status = 4;
  1470. $receiptDetail->insert ();
  1471. }
  1472. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1473. $receiptDetail = new receiptDetail ();
  1474. $receiptDetail->staff = $this->staff [0] ['sid'];
  1475. $receiptDetail->item = $value ['name'];
  1476. $receiptDetail->itemCategory = $this->TRAIN;
  1477. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1478. $receiptDetail->date = date ( "Y-m-d" );
  1479. $receiptDetail->cid = $cid;
  1480. $receiptDetail->rid = $rid;
  1481. $receiptDetail->status = 4;
  1482. $receiptDetail->insert ();
  1483. }
  1484. //内训
  1485. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1486. $receiptDetail = new receiptDetail ();
  1487. $receiptDetail->staff = $this->staff [0] ['sid'];
  1488. $receiptDetail->item = $value ['name'];
  1489. $receiptDetail->itemCategory = $this->INTTRAIN;
  1490. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1491. $receiptDetail->date = date ( "Y-m-d" );
  1492. $receiptDetail->cid = $cid;
  1493. $receiptDetail->rid = $rid;
  1494. $receiptDetail->status = 4;
  1495. $receiptDetail->insert ();
  1496. }
  1497. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1498. $receiptDetail = new receiptDetail ();
  1499. $receiptDetail->staff = $this->staff [0] ['sid'];
  1500. $receiptDetail->item = $value ['name'];
  1501. $receiptDetail->itemCategory = $this->OTHER;
  1502. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1503. $receiptDetail->date = date ( "Y-m-d" );
  1504. $receiptDetail->cid = $cid;
  1505. $receiptDetail->rid = $rid;
  1506. $receiptDetail->status = 4;
  1507. $receiptDetail->insert ();
  1508. }
  1509. return "/saeaBorad";
  1510. }
  1511. return "/saeaLoanReceiptAdd/" . $rid;
  1512. }
  1513. function saeaLoanReceiptEdi() {
  1514. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1515. Doo::loadClass ( 'XDeode' );
  1516. $XDeode = new XDeode ( 7 );
  1517. $rid = $XDeode->decode ( $ridKey );
  1518. if (! is_numeric ( $rid ))
  1519. die ( 'illegal request' );
  1520. Doo::loadModel ( 'accountItem' );
  1521. Doo::loadModel ( 'verify' );
  1522. Doo::loadModel ( 'receipt' );
  1523. $receipt = new receipt ();
  1524. $verify = new verify ();
  1525. $accountItem = new accountItem ();
  1526. Doo::loadModel ( 'L_category' );
  1527. $Lcategory = new L_category ();
  1528. Doo::loadModel ( "role" );
  1529. $role = new role ();
  1530. Doo::loadModel ( 'loanReceipt' );
  1531. $loanReceipt = new loanReceipt ();
  1532. Doo::loadModel ( 'staff' );
  1533. $staff = new staff ();
  1534. $receiptDetail = $receipt->getOne ( array (
  1535. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1536. 'asArray' => true
  1537. ) );
  1538. if (empty ( $receiptDetail ))
  1539. return "/saeaBorad";
  1540. $receiptList = $loanReceipt->find ( array (
  1541. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1542. 'desc' => 'rid',
  1543. 'asArray' => true
  1544. ) );
  1545. $Locate = 0;
  1546. $roleId = 0;
  1547. $button = 0;
  1548. foreach ( $receiptList as $key => $value ) {
  1549. $receiptList [$key] ['Locate'] = $Locate;
  1550. $Locate ++;
  1551. $receiptList [$key] ['reviseDetail'] = array ();
  1552. if (! empty ( $value ['reviseDetail'] ))
  1553. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1554. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1555. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1556. $categoryDetil = $Lcategory->getOne ( array (
  1557. 'where' => 'cid=' . $value ['cid'],
  1558. 'asArray' => true
  1559. ) );
  1560. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1561. // 检测编辑状态
  1562. $verifyList = $verify->getOne ( array (
  1563. 'where' => 'vid=' . $value ['verify'],
  1564. 'asArray' => true
  1565. ) );
  1566. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1567. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1568. Doo::loadModel ( 'role' );
  1569. $role = new role ();
  1570. $flag = true;
  1571. $roleKey = 0;
  1572. $endStaffArray = array ();
  1573. $roleArrayCopy = array ();
  1574. foreach ( $verifyList as $k => $v ) {
  1575. // init verifyStaff
  1576. if ($v [1] == 'ROLE') {
  1577. if (! empty ( $verifyStaff )) {
  1578. $endStaffArray = end ( $verifyStaff );
  1579. // if ($v[0]==$endStaffArray['nextStaff']){
  1580. // $roleId=$v[0];
  1581. // }
  1582. }
  1583. $roleVerify = json_decode ( $v [3], true );
  1584. $roleKey = $k;
  1585. $roleArray = array ();
  1586. $rolename = $role->getOne ( array (
  1587. 'where' => 'rid=' . $v [0],
  1588. 'asArray' => true
  1589. ) );
  1590. foreach ( $roleVerify as $o => $p ) {
  1591. $staffID = explode ( '_', $p );
  1592. $staffInfo = $staff->getOne ( array (
  1593. 'where' => 'sid=' . $staffID [0],
  1594. 'asArray' => true
  1595. ) );
  1596. // print_r($staffID);
  1597. $exp = array (
  1598. 0 => $staffInfo ['sid'],
  1599. 1 => $staffID [1],
  1600. 2 => $staffInfo ['avatar'],
  1601. 'date' => '',
  1602. 'date' => '',
  1603. 'opinion' => '',
  1604. 'status' => '',
  1605. 'rolename' => $rolename ['name']
  1606. );
  1607. array_push ( $roleArray, $exp );
  1608. }
  1609. $roleArrayCopy [$v [0]] = $roleArray;
  1610. // $verifyList[$k]['roleArray']=$roleArray;
  1611. }
  1612. $verifyList [$k] ['date'] = "";
  1613. $verifyList [$k] ['opinion'] = "";
  1614. $verifyList [$k] ['status'] = "";
  1615. if (empty ( $verifyStaff )) {
  1616. $verifyList [$k] ['date'] = "";
  1617. $verifyList [$k] ['opinion'] = "";
  1618. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1619. $verifyList [$k] ['status'] = 4;
  1620. $flag = false;
  1621. }
  1622. } else {
  1623. foreach ( $verifyStaff as $m => $u ) {
  1624. if ($v [0] == $m) {
  1625. $verifyList [$k] ['date'] = $u ['date'];
  1626. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1627. $verifyList [$k] ['status'] = $u ['status'];
  1628. $flag = false;
  1629. break;
  1630. }
  1631. }
  1632. $endStaffArray = end ( $verifyStaff );
  1633. if (isset ( $endStaffArray ['ROLE'] )) {
  1634. } else {
  1635. // $endKey=key($verifyStaff);
  1636. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1637. // $button=4;
  1638. // $verifyList[$k]['status']=4;
  1639. // }
  1640. }
  1641. }
  1642. }
  1643. $rolename ['name'] = '';
  1644. if (! empty ( $roleId )) {
  1645. Doo::loadModel ( 'role' );
  1646. $role = new role ();
  1647. $rolename = $role->getOne ( array (
  1648. 'where' => 'rid=' . $roleId,
  1649. 'asArray' => true
  1650. ) );
  1651. }
  1652. if (! empty ( $verifyStaff ))
  1653. $endStaffArray = end ( $verifyStaff );
  1654. $KOP = false;
  1655. foreach ( $roleArrayCopy as $P => $A ) {
  1656. foreach ( $A as $MKI => $AVL ) {
  1657. if (! empty ( $verifyStaff )) {
  1658. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1659. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1660. $button = 4;
  1661. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1662. }
  1663. foreach ( $verifyStaff as $m => $u ) {
  1664. $AVLFK = $AVL [0] . '_R';
  1665. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1666. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1667. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1668. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1669. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1670. break;
  1671. }
  1672. }
  1673. } else {
  1674. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1675. $button = 4;
  1676. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1677. }
  1678. }
  1679. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1680. $KOP = true;
  1681. }
  1682. }
  1683. foreach ( $roleArrayCopy as $k => $v ) {
  1684. foreach ( $verifyList as $m => $n ) {
  1685. if ($n [0] == $k) {
  1686. array_splice ( $verifyList, $m, 1, $v );
  1687. }
  1688. }
  1689. }
  1690. $receiptList [$key] ['verifyList'] = $verifyList;
  1691. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1692. 'where' => 'sid=' . $value ['staff'],
  1693. 'asArray' => true
  1694. ) );
  1695. $receiptList [$key] ['button'] = $button;
  1696. //
  1697. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1698. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1699. }
  1700. $data ['receiptList'] = $receiptList;
  1701. $acItem = $accountItem->find ( array (
  1702. 'asArray' => true
  1703. ) );
  1704. $veList = $verify->find ( array (
  1705. 'asArray' => true
  1706. ) );
  1707. foreach ( $veList as $key => $value ) {
  1708. $v = json_decode ( $value ['staff'] );
  1709. $list = array ();
  1710. foreach ( $v as $n => $m ) {
  1711. if ($m ['1'] == 'ROLE') {
  1712. $roleInfo = $role->getOne ( array (
  1713. 'where' => 'rid=' . $m [0],
  1714. 'asArray' => true
  1715. ) );
  1716. $v [$n] [1] = $roleInfo ['name'];
  1717. array_push ( $list, $roleInfo ['name'] );
  1718. } else {
  1719. array_push ( $list, $v [$n] [1] );
  1720. }
  1721. }
  1722. $veList [$key] ['staff'] = implode ( '>', $list );
  1723. }
  1724. // 配置编辑信息
  1725. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1726. foreach ( $acItem as $key => $value ) {
  1727. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1728. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1729. $acItem [$key] ['price'] = $v ['price'];
  1730. }
  1731. }
  1732. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1733. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1734. $acItem [$key] ['price'] = $v ['price'];
  1735. }
  1736. }
  1737. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1738. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1739. $acItem [$key] ['price'] = $v ['price'];
  1740. }
  1741. }
  1742. //内训
  1743. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1744. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1745. $acItem [$key] ['price'] = $v ['price'];
  1746. }
  1747. }
  1748. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1749. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1750. $acItem [$key] ['price'] = $v ['price'];
  1751. }
  1752. }
  1753. }
  1754. $data ['category'] = $Lcategory->find ( array (
  1755. 'asArray' => true
  1756. ) );
  1757. $data ['ridKey'] = $ridKey;
  1758. $data ['cSum'] = $accountItemList ['cSum'];
  1759. $data ['sum'] = $receiptDetail ['sum'];
  1760. $data ['receiptDetail'] = $receiptDetail;
  1761. $data ['veList'] = $veList;
  1762. $data ['acItem'] = $acItem;
  1763. $data ['memu'] = "receipt";
  1764. $data ['staff'] = $this->staff;
  1765. $data ['receiptMemu'] = 'saeaBorad';
  1766. $data ['verify'] = $receiptDetail ['verify'];
  1767. $data ['verifyId'] = $this->verifyId;
  1768. $data ['executeId'] = $this->executeId;
  1769. $data ['rid'] = $rid;
  1770. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1771. }
  1772. /**
  1773. * 培训班结算
  1774. */
  1775. function receiptTrainAdd() {
  1776. Doo::loadModel ( 'accountItem' );
  1777. $accountItem = new accountItem ();
  1778. $acItem = $accountItem->find ( array (
  1779. 'asArray' => true
  1780. ) );
  1781. // 审批组
  1782. Doo::loadModel ( 'verify' );
  1783. $verify = new verify ();
  1784. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1785. // 办事处
  1786. Doo::loadModel ( 'L_category' );
  1787. $lCategory = new L_category ();
  1788. $data ['category'] = $lCategory->getCategory ();
  1789. $data ['veList'] = $veList;
  1790. $data ['memu'] = "receipt";
  1791. $data ['staff'] = $this->staff;
  1792. $data ['acItem'] = $acItem;
  1793. $data ['receiptMemu'] = 'saeaBorad';
  1794. $data ['verifyId'] = $this->verifyId;
  1795. $data ['executeId'] = $this->executeId;
  1796. $this->render ( "/receipt/receiptTrainAdd", $data );
  1797. }
  1798. /**
  1799. * 添加培训班结算
  1800. */
  1801. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1802. // 培训班信息
  1803. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1804. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1805. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1806. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1807. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1808. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1809. // 发票信息
  1810. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1811. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1812. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1813. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1814. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1815. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1816. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1817. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1818. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1819. header ( 'Content-Type:text/html;charset=utf-8' );
  1820. die ( '请填写联行号' );
  1821. }
  1822. Doo::loadModel ( 'execute' );
  1823. $execute = new execute ();
  1824. $executeDetail = $execute->getOne ( array (
  1825. 'where' => 'mold="培训班结算"',
  1826. 'asArray' => true
  1827. ) );
  1828. if (empty ( $executeDetail )) {
  1829. header ( 'Content-Type:text/html;charset=utf-8' );
  1830. die ( '未设置执行人' );
  1831. }
  1832. Doo::loadClass ( 'XDeode' );
  1833. $XDeode = new XDeode ( 5 );
  1834. $cid = $XDeode->decode ( $cid );
  1835. Doo::loadModel ( 'receipt' );
  1836. $receipt = new receipt ();
  1837. Doo::loadModel ( 'receiptTraining' );
  1838. $receiptTraining = new receiptTraining ();
  1839. // 创建费用培训班
  1840. $item = array (
  1841. 'cid' => $this->staff [0] ['cid'],
  1842. 'categoryName' => $this->staff [0] ['category'],
  1843. 'trainName' => $trainName,
  1844. 'trainStartDate' => $trainStartDate,
  1845. 'trainEndDate' => $trainEndDate,
  1846. 'participants' => $participants,
  1847. 'trainAddress' => $trainAddress,
  1848. 'trainRemarks' => $trainRemarks,
  1849. 'creator' => $this->staff [0] ['sid'],
  1850. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1851. );
  1852. $irid = $receiptTraining->addReceiptTraining ( $item );
  1853. // 报销单
  1854. $receipt->status = 5;
  1855. $receipt->trainId = $irid;
  1856. $receipt->Rtype = 3;
  1857. $receipt->staff = $this->staff [0] ['sid'];
  1858. $receipt->cid = $cid;
  1859. $receipt->verify = $verify;
  1860. $receipt->date = date ( "Y-m-d" );
  1861. $receipt->executeCopy = $executeDetail ['staff'];
  1862. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1863. $receipt->remittanceName = $remittanceName;
  1864. $receipt->bankName = $bankName;
  1865. $receipt->bankNumber = $bankNumber;
  1866. $receipt->remittanceBankType = $remittanceBankType;
  1867. if ($remittanceBankType == 1)
  1868. $receipt->coupletNumber = $coupletNumber;
  1869. $rid = $receipt->insert ();
  1870. $XDeode = new XDeode ( 7 );
  1871. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1872. } else
  1873. die ( 'illegal request' );
  1874. }
  1875. /**
  1876. * 培训班编辑
  1877. */
  1878. function receiptTrainEdi() {
  1879. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1880. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1881. Doo::loadClass ( 'XDeode' );
  1882. $XDeode = new XDeode ( 7 );
  1883. $rid = $XDeode->decode ( $ridKey );
  1884. if (! is_numeric ( $rid ))
  1885. die ( 'illegal request' );
  1886. Doo::loadModel ( 'receipt' );
  1887. $receipt = new receipt ();
  1888. Doo::loadModel ( 'receiptTraining' );
  1889. $receiptTraining = new receiptTraining ();
  1890. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1891. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1892. die ('illegal request--status');
  1893. }
  1894. //如有已入账已收款的发票,自动取消办事处已收款
  1895. // Doo::loadModel ( 'RIExtend' );
  1896. // $RIExtend = new RIExtend ();
  1897. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1898. // if (!empty($RIExtendList)){
  1899. // foreach ($RIExtendList as $key=>$value){
  1900. // $RIExtend = new RIExtend ();
  1901. // $RIExtend->delete(array (
  1902. // 'where' => 'iid=' . $value['iid'],
  1903. // 'limit' => 1
  1904. // ));
  1905. // }
  1906. // }
  1907. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1908. // 汇总表合计
  1909. // 收入合计--加入开票合计
  1910. Doo::loadModel ( 'invoiceTraining' );
  1911. $invoiceTraining = new invoiceTraining ();
  1912. $invoiceTrainingDetail = array (
  1913. 'invoiceArriveAmount' => 0,
  1914. 'RIAmount' => 0,
  1915. 'invoiceTotalAmount' => 0,
  1916. 'invoiceCompanyAmount'=>0
  1917. );
  1918. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1919. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1920. }
  1921. // print_r($invoiceTrainingDetail);
  1922. $invoiceArriveAmount = $RIAmount = 0;
  1923. if (! empty ( $invoiceTrainingDetail )) {
  1924. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1925. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1926. }
  1927. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1928. //print_r($invoiceTrainingDetail);
  1929. // 支出项目
  1930. Doo::loadModel ( 'accountItem' );
  1931. $accountItem = new accountItem ();
  1932. // 项目金额合计
  1933. Doo::loadModel ( 'RItem' );
  1934. $RItem = new RItem ();
  1935. // 讲师获得
  1936. Doo::loadModel ( 'RILecturer' );
  1937. $RILecturer = new RILecturer ();
  1938. $RItemList = $RItem->getRItemByRid ( $rid );
  1939. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1940. // 支出项金额详情
  1941. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1942. // print_r($aiData);
  1943. // 利润
  1944. $profit=$invoiceArriveAmount - $aiData ['total'];
  1945. $companyProfit=$profit * 0.6;
  1946. $categoryProfit=$profit * 0.4;
  1947. $data ['profit'] = sprintf("%.2f",$profit);
  1948. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1949. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1950. //发票利润
  1951. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1952. //发票公司利润
  1953. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1954. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1955. //办事处利润
  1956. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1957. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1958. // print_r($aiData['dataList']);
  1959. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1960. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1961. // 备用金
  1962. $sum = 0;
  1963. $data ['receiptLoanDetail'] = array (
  1964. 'sum' => '0.00'
  1965. );
  1966. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1967. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1968. $sum = $data ['receiptLoanDetail'] ['sum'];
  1969. }
  1970. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1971. $data ['payment'] = sprintf("%.2f",$payment);
  1972. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1973. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1974. $data ['aiList'] = $aiData ['dataList'];
  1975. // 占比计算
  1976. if ($invoiceArriveAmount != 0) {
  1977. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1978. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1979. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1980. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1981. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1982. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1983. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1984. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1985. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1986. } else {
  1987. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1988. }
  1989. //发票金额占比计算
  1990. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1991. //支出
  1992. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1993. //利润
  1994. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1995. //公司利润
  1996. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //办事处利润
  1998. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //公司收款
  2000. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //备用金
  2002. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //办事处收款
  2004. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //办事处实际支出
  2006. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //付总部款
  2008. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. }else{
  2010. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2011. }
  2012. //讲师人数
  2013. Doo::loadModel ( 'RILecturer' );
  2014. $RILecturer = new RILecturer ();
  2015. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2016. $data['lectureCount']=count($RILecturerList);
  2017. // 审批组
  2018. Doo::loadModel ( 'verify' );
  2019. $verify = new verify ();
  2020. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2021. // 办事处
  2022. Doo::loadModel ( 'L_category' );
  2023. $lCategory = new L_category ();
  2024. $data ['category'] = $lCategory->getCategory ();
  2025. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2026. $data ['receiptDetail'] = $receiptDetail;
  2027. $data ['veList'] = $veList;
  2028. $data ['trainEdiType'] = $trainEdiType;
  2029. $data ['ridKey'] = $ridKey;
  2030. $data ['memu'] = "receipt";
  2031. $data ['staff'] = $this->staff;
  2032. $data ['receiptMemu'] = 'saeaBorad';
  2033. $data ['verifyId'] = $this->verifyId;
  2034. $data ['executeId'] = $this->executeId;
  2035. $this->render ( "/receipt/receiptTrainEdi", $data );
  2036. }
  2037. /**
  2038. * 培训班借款编辑
  2039. */
  2040. function receiptTrainLoanEdi() {
  2041. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2042. Doo::loadClass ( 'XDeode' );
  2043. $XDeode = new XDeode ( 7 );
  2044. $rid = $XDeode->decode ( $ridKey );
  2045. if (! is_numeric ( $rid ))
  2046. die ( 'illegal request' );
  2047. Doo::loadModel ( 'receipt' );
  2048. $receipt = new receipt ();
  2049. Doo::loadModel ( 'receiptTraining' );
  2050. $receiptTraining = new receiptTraining ();
  2051. Doo::loadModel ( 'verify' );
  2052. $verify = new verify ();
  2053. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2054. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2055. die ();
  2056. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2057. // 借款详情HTML
  2058. // 获得借款信息
  2059. $receiptLoanHtml = '';
  2060. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2061. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2062. // 获得某费用单审批信息
  2063. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2064. Doo::loadClass ( 'receipt.func' );
  2065. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2066. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2067. }
  2068. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2069. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2070. $data ['receiptDetail'] = $receiptDetail;
  2071. $data ['trainEdiType'] = "LOAN";
  2072. $data ['ridKey'] = $ridKey;
  2073. $data ['memu'] = "receipt";
  2074. $data ['staff'] = $this->staff;
  2075. $data ['receiptMemu'] = 'saeaBorad';
  2076. $data ['verifyId'] = $this->verifyId;
  2077. $data ['executeId'] = $this->executeId;
  2078. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2079. }
  2080. /**
  2081. * 更新培训班结算基本信息
  2082. */
  2083. function receiptTrainInfoEdiDo() {
  2084. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2085. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2086. // 培训班信息
  2087. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2088. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2089. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2090. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2091. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2092. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2093. // 发票信息
  2094. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2095. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2096. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2097. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2098. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2099. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2100. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2101. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2102. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2103. header ( 'Content-Type:text/html;charset=utf-8' );
  2104. die ( '请填写联行号' );
  2105. }
  2106. Doo::loadClass ( 'XDeode' );
  2107. $XDeode = new XDeode ( 5 );
  2108. $cid = $XDeode->decode ( $cid );
  2109. $rtid = $XDeode->decode ( $rtid );
  2110. $rid = $XDeode->decode ( $rid );
  2111. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2112. die ( 'illegal request-IdError' );
  2113. }
  2114. Doo::loadModel ( 'receipt' );
  2115. $receipt = new receipt ();
  2116. Doo::loadModel ( 'receiptTraining' );
  2117. $receiptTraining = new receiptTraining ();
  2118. // 更新费用培训班
  2119. $item = array (
  2120. 'rtid' => $rtid,
  2121. 'trainName' => $trainName,
  2122. 'trainStartDate' => $trainStartDate,
  2123. 'trainEndDate' => $trainEndDate,
  2124. 'participants' => $participants,
  2125. 'trainAddress' => $trainAddress,
  2126. 'trainRemarks' => $trainRemarks
  2127. );
  2128. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2129. // 报销单
  2130. $receipt->rid = $rid;
  2131. $receipt->cid = $cid;
  2132. $receipt->verify = $verify;
  2133. $receipt->remittanceName = $remittanceName;
  2134. $receipt->bankName = $bankName;
  2135. $receipt->bankNumber = $bankNumber;
  2136. $receipt->remittanceBankType = $remittanceBankType;
  2137. if ($remittanceBankType == 1)
  2138. $receipt->coupletNumber = $coupletNumber;
  2139. $receipt->update ();
  2140. $XDeode = new XDeode ( 7 );
  2141. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2142. } else
  2143. die ( 'illegal request' );
  2144. }
  2145. /**
  2146. * 编辑培训班结算---更新借款
  2147. */
  2148. function receiptTrainLoanEdiDo() {
  2149. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2150. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2151. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2152. Doo::loadModel ( 'receipt' );
  2153. $receipt = new receipt ();
  2154. Doo::loadClass ( 'XDeode' );
  2155. $XDeode = new XDeode ( 5 );
  2156. $rid = $XDeode->decode ( $ridKey );
  2157. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2158. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2159. die ( 'illegal request-ridError' );
  2160. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2161. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2162. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2163. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2164. die ( 'illegal request-receiptError' );
  2165. }
  2166. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2167. die ( 'illegal request-receipLoantError' );
  2168. }
  2169. // 培训班结算挂钩借款
  2170. $receipt = new receipt ();
  2171. $item = array (
  2172. 'rid' => $rid,
  2173. 'trainLoanRid' => $ridLoan
  2174. );
  2175. $receipt->setReceiptByCondition ( $item );
  2176. // 更新借款状态变成已挂钩
  2177. $receipt = new receipt ();
  2178. $item = array (
  2179. 'rid' => $ridLoan,
  2180. 'status' => 10,
  2181. 'statusTrain' => 1
  2182. );
  2183. $receipt->setReceiptByCondition ( $item );
  2184. $XDeode = new XDeode ( 7 );
  2185. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2186. } else
  2187. die ( 'illegal request' );
  2188. }
  2189. /**
  2190. * 编辑培训班结算--移除借款
  2191. */
  2192. function receiptTrainLoanRemoveDo() {
  2193. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2194. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2195. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2196. Doo::loadModel ( 'receipt' );
  2197. $receipt = new receipt ();
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $rid = $XDeode->decode ( $ridKey );
  2201. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2202. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2203. die ( 'illegal request-ridError' );
  2204. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2205. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2206. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2207. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2208. die ( 'illegal request-receiptError' );
  2209. }
  2210. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2211. die ( 'illegal request-receipLoantError' );
  2212. }
  2213. // 培训班结算挂钩借款
  2214. $receipt = new receipt ();
  2215. $item = array (
  2216. 'rid' => $rid,
  2217. 'trainLoanRid' => 0
  2218. );
  2219. $receipt->setReceiptByCondition ( $item );
  2220. // 更新借款状态变成已挂钩
  2221. $receipt = new receipt ();
  2222. $item = array (
  2223. 'rid' => $ridLoan,
  2224. 'status' => 8,
  2225. 'statusTrain' => 0
  2226. );
  2227. $receipt->setReceiptByCondition ( $item );
  2228. $XDeode = new XDeode ( 7 );
  2229. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2230. } else
  2231. die ( 'illegal request' );
  2232. }
  2233. /**
  2234. * 编辑培训班结算 ---开票
  2235. */
  2236. function receiptTrainInvoiceEdi() {
  2237. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2238. Doo::loadClass ( 'XDeode' );
  2239. $XDeode = new XDeode ( 7 );
  2240. $rid = $XDeode->decode ( $ridKey );
  2241. if (! is_numeric ( $rid ))
  2242. die ( 'illegal request' );
  2243. Doo::loadModel ( 'receipt' );
  2244. $receipt = new receipt ();
  2245. Doo::loadModel ( 'receiptTraining' );
  2246. $receiptTraining = new receiptTraining ();
  2247. Doo::loadModel ( 'invoice' );
  2248. $invoice = new invoice ();
  2249. Doo::loadModel ( 'invoiceTraining' );
  2250. $invoiceTraining = new invoiceTraining ();
  2251. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2252. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2253. die ();
  2254. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2255. $invoiceList = $invoiceTrainingDetail = array ();
  2256. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2257. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2258. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2259. }
  2260. //print_r($invoiceList);
  2261. $data ['invoiceList'] = $invoiceList;
  2262. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2263. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2264. $data ['receiptDetail'] = $receiptDetail;
  2265. $data ['trainEdiType'] = "INVOICE";
  2266. $data ['ridKey'] = $ridKey;
  2267. $data ['memu'] = "receipt";
  2268. $data ['staff'] = $this->staff;
  2269. $data ['receiptMemu'] = 'saeaBorad';
  2270. $data ['verifyId'] = $this->verifyId;
  2271. $data ['executeId'] = $this->executeId;
  2272. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2273. }
  2274. /**
  2275. * 编辑培训班结算---更新开票
  2276. */
  2277. function receiptTrainInvoiceEdiDo() {
  2278. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2279. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2280. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2281. Doo::loadModel ( 'receipt' );
  2282. $receipt = new receipt ();
  2283. Doo::loadModel ( 'invoiceTraining' );
  2284. $invoiceTraining = new invoiceTraining ();
  2285. Doo::loadClass ( 'XDeode' );
  2286. $XDeode = new XDeode ( 5 );
  2287. $rid = $XDeode->decode ( $ridKey );
  2288. $itid = $XDeode->decode ( $itidKey );
  2289. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2290. die ( 'illegal request-idError' );
  2291. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2292. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2293. // 不合法的数据
  2294. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2295. die ( 'illegal request-receiptError' );
  2296. }
  2297. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2298. die ( 'illegal request-receipLoantError' );
  2299. }
  2300. // 培训班结算挂钩借款
  2301. $receipt = new receipt ();
  2302. $item = array (
  2303. 'rid' => $rid,
  2304. 'invoiceTrainId' => $itid
  2305. );
  2306. $receipt->setReceiptByCondition ( $item );
  2307. $invoiceTraining = new invoiceTraining ();
  2308. $item = array (
  2309. 'bindReceipt' => 1,
  2310. 'itid' => $itid
  2311. );
  2312. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2313. $XDeode = new XDeode ( 7 );
  2314. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2315. } else
  2316. die ( 'illegal request' );
  2317. }
  2318. /**
  2319. * 更新培训班结算 收款和取消收款
  2320. */
  2321. function receiptTrainReceivables() {
  2322. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2323. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2324. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2325. Doo::loadClass ( 'XDeode' );
  2326. $XDeode = new XDeode ( 5 );
  2327. $rid = $XDeode->decode ( $ridKey );
  2328. $iid = $XDeode->decode ( $iidKey );
  2329. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2330. die ( 'illegal request-iid' );
  2331. Doo::loadModel ( 'RIExtend' );
  2332. $RIExtend = new RIExtend ();
  2333. if ($doType == 'CONFIRM') {
  2334. $RIExtend->rid = $rid;
  2335. $RIExtend->iid = $iid;
  2336. $RIExtend->RIstatus = 1;
  2337. $RIExtend->insert ();
  2338. echo json_encode ( array (
  2339. 'status' => 1,
  2340. ) );
  2341. die ( );
  2342. } elseif ($doType == 'CANCEL') {
  2343. $RIExtend->delete ( array (
  2344. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2345. 'limit' => 1
  2346. ) );
  2347. echo json_encode ( array (
  2348. 'status' => 1,
  2349. ) );
  2350. die ( );
  2351. } else {
  2352. echo json_encode ( array (
  2353. 'status' => 2,
  2354. ) );
  2355. die ( );
  2356. }
  2357. }
  2358. /**
  2359. * 移除挂钩的培训班发票
  2360. */
  2361. function receiptTrainReceivablesDelDo() {
  2362. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2363. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2364. Doo::loadModel ( 'receipt' );
  2365. $receipt = new receipt ();
  2366. Doo::loadModel ( 'RIExtend' );
  2367. $RIExtend = new RIExtend ();
  2368. Doo::loadClass ( 'XDeode' );
  2369. $XDeode = new XDeode ( 5 );
  2370. $rid = $XDeode->decode ( $ridKey );
  2371. $itid = $XDeode->decode ( $itidKey );
  2372. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2373. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2374. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2375. die ( 'illegal request-status' );
  2376. }
  2377. $receipt = new receipt ();
  2378. $receipt->rid = $rid;
  2379. $receipt->invoiceTrainId = 0;
  2380. $receipt->update ();
  2381. Doo::loadModel ( 'invoiceTraining' );
  2382. $invoiceTraining = new invoiceTraining ();
  2383. $item = array (
  2384. 'bindReceipt' => 0,
  2385. 'itid' => $itid
  2386. );
  2387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2388. $RIExtend->delete ( array (
  2389. 'where' => 'rid=' . $rid
  2390. ) );
  2391. $XDeode = new XDeode ( 7 );
  2392. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2393. } else
  2394. die ( 'illegal request-iid' );
  2395. }
  2396. /**
  2397. * 编辑培训班结算
  2398. */
  2399. function receiptTrainItemEdi() {
  2400. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2401. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2402. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2403. Doo::loadClass ( 'XDeode' );
  2404. $XDeode = new XDeode ( 7 );
  2405. $rid = $XDeode->decode ( $ridKey );
  2406. if (! is_numeric ( $rid ))
  2407. die ( 'illegal request' );
  2408. Doo::loadModel ( 'receipt' );
  2409. $receipt = new receipt ();
  2410. Doo::loadModel ( 'receiptTraining' );
  2411. $receiptTraining = new receiptTraining ();
  2412. Doo::loadModel ( 'RItem' );
  2413. $RItem = new RItem ();
  2414. Doo::loadModel ( 'accountItem' );
  2415. $accountItem = new accountItem ();
  2416. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2417. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2418. die ();
  2419. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2420. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2421. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2422. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2423. // if($value['name']=='税款'){
  2424. // unset($aiList[$key]);break;
  2425. // }
  2426. // }
  2427. //print_r($RItemList);
  2428. $data ['name'] = $name;
  2429. $data ['RItemList'] = $RItemList;
  2430. $data ['aiList'] = $aiList;
  2431. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2432. $data ['receiptDetail'] = $receiptDetail;
  2433. $data ['trainEdiType'] = "ITEM";
  2434. $data ['ridKey'] = $ridKey;
  2435. $data ['memu'] = "receipt";
  2436. $data ['staff'] = $this->staff;
  2437. $data ['receiptMemu'] = 'saeaBorad';
  2438. $data ['verifyId'] = $this->verifyId;
  2439. $data ['executeId'] = $this->executeId;
  2440. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2441. }
  2442. /**
  2443. * 添加支出项 需要修改 费用金额合计
  2444. */
  2445. function receiptTrainItemAddDo() {
  2446. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2447. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2448. // 支出项信息
  2449. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2450. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2451. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2452. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2453. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2454. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2455. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2456. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2457. Doo::loadClass ( 'XDeode' );
  2458. $XDeode = new XDeode ( 5 );
  2459. Doo::loadModel ( 'RItem' );
  2460. $RItem = new RItem ();
  2461. $rid = $XDeode->decode ( $ridKey );
  2462. $rtid= $XDeode->decode ( $rtidKey );
  2463. if (! is_numeric ( $rid )){
  2464. die ( 'illegal request' );
  2465. }
  2466. Doo::loadModel ( 'receiptDetail' );
  2467. $receiptDetail = new receiptDetail ();
  2468. Doo::loadModel ( 'receipt' );
  2469. $receipt = new receipt ();
  2470. Doo::loadModel ( 'receiptTraining' );
  2471. $receiptTraining = new receiptTraining ();
  2472. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2473. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2474. $order = array (
  2475. "\r\n",
  2476. "\n",
  2477. "\r"
  2478. );
  2479. $replace = '<br/>';
  2480. $describe = str_replace ( $order, $replace, $describe );
  2481. $itemData = array (
  2482. 'rid' => $rid,
  2483. 'item' => $item,
  2484. 'price' => $price,
  2485. 'date' => $date,
  2486. 'inputer' => $inputer,
  2487. 'describe' => $describe,
  2488. 'creater' => $this->staff['0']['username'],
  2489. 'createrId' => $this->staff['0']['sid'],
  2490. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2491. 'identifying'=>$identifyingTotal
  2492. );
  2493. if($payType=='company'){
  2494. $itemData += array (
  2495. 'payType' => 1
  2496. );
  2497. }
  2498. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2499. //更新支出项标识总数
  2500. $itemData = array (
  2501. 'rtid'=>$rtid,
  2502. 'identifyingTotal'=>$identifyingTotal
  2503. );
  2504. $receiptTraining->setReceiptTrainByCondition($itemData);
  2505. $XDeode = new XDeode ( 7 );
  2506. if($payType=='company'){
  2507. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2508. }else{
  2509. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2510. }
  2511. } else
  2512. die ( 'illegal request-dataError' );
  2513. }
  2514. /**
  2515. * 培训班结算-讲师
  2516. */
  2517. function receiptTrainLecturerEdi() {
  2518. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2519. Doo::loadClass ( 'XDeode' );
  2520. $XDeode = new XDeode ( 7 );
  2521. $rid = $XDeode->decode ( $ridKey );
  2522. if (! is_numeric ( $rid ))
  2523. die ( 'illegal request' );
  2524. Doo::loadModel ( 'receipt' );
  2525. $receipt = new receipt ();
  2526. Doo::loadModel ( 'receiptTraining' );
  2527. $receiptTraining = new receiptTraining ();
  2528. Doo::loadModel ( 'RILecturer' );
  2529. $RILecturer = new RILecturer ();
  2530. Doo::loadModel ( 'lecturer' );
  2531. $lecturer = new lecturer ();
  2532. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2533. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2534. die ();
  2535. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2536. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2537. $lecturerList = $lecturer->getLecturerAll ();
  2538. $INSIDEhtml = $OUTSIDEhtml = '';
  2539. foreach ( $lecturerList as $key => $value ) {
  2540. if ($value ['ltype'] == 'INSIDE') {
  2541. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2542. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2543. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2544. }
  2545. }
  2546. $data ['INSIDEhtml'] = $INSIDEhtml;
  2547. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2548. // print_r($RItemList);
  2549. $data ['RILecturerList'] = $RILecturerList;
  2550. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2551. $data ['receiptDetail'] = $receiptDetail;
  2552. $data ['trainEdiType'] = "LECTURER";
  2553. $data ['ridKey'] = $ridKey;
  2554. $data ['memu'] = "receipt";
  2555. $data ['staff'] = $this->staff;
  2556. $data ['receiptMemu'] = 'saeaBorad';
  2557. $data ['verifyId'] = $this->verifyId;
  2558. $data ['executeId'] = $this->executeId;
  2559. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2560. }
  2561. /**
  2562. * 添加讲师
  2563. */
  2564. function receiptTrainLecturerAddDo() {
  2565. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2566. // 支出项信息
  2567. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2568. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2569. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2570. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2571. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2572. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2573. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2574. Doo::loadClass ( 'XDeode' );
  2575. $XDeode = new XDeode ( 5 );
  2576. Doo::loadModel ( 'RILecturer' );
  2577. $RILecturer = new RILecturer ();
  2578. $rid = $XDeode->decode ( $ridKey );
  2579. if (! is_numeric ( $rid ))
  2580. die ( 'illegal request' );
  2581. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2582. die ( 'illegal request-taxationError' );
  2583. $RILecturer->rid = $rid;
  2584. $RILecturer->ltype = $ltype;
  2585. if ($ltype == 'OUTSIDE') {
  2586. if ($taxation == 'TAXATION') {
  2587. $RILecturer->taxation = 1;
  2588. } elseif ($taxation == 'NOTAXATION') {
  2589. $RILecturer->taxation = 0;
  2590. }
  2591. }
  2592. $RILecturer->lecturerName = $lecturerName;
  2593. $RILecturer->schoolDay = $schoolDay;
  2594. $RILecturer->price = $price;
  2595. $RILecturer->fees=$fees;
  2596. $RILecturer->insert ();
  2597. // 添加公司汇总
  2598. // 报销详情
  2599. Doo::loadModel ( 'receiptDetail' );
  2600. $receiptDetail = new receiptDetail ();
  2601. Doo::loadModel ( 'receipt' );
  2602. $receipt = new receipt ();
  2603. // 金额总计
  2604. $price = $price * $schoolDay;
  2605. $rInfo = $receipt->getReceiptByRid ( $rid );
  2606. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2607. if (empty ( $rdInfo )) {
  2608. $receiptDetail = new receiptDetail ();
  2609. $receiptDetail->staff = $rInfo ['staff'];
  2610. $receiptDetail->item = '讲课费';
  2611. $receiptDetail->itemCategory = '培训班费用';
  2612. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2613. $receiptDetail->date = date ( "Y-m-d" );
  2614. $receiptDetail->cid = $rInfo ['cid'];
  2615. $receiptDetail->rid = $rid;
  2616. $receiptDetail->status = 4;
  2617. $receiptDetail->insert ();
  2618. } else {
  2619. $receiptDetail = new receiptDetail ();
  2620. $rdInfo ['price'] += $fees;
  2621. $receiptDetail->price = $rdInfo ['price'];
  2622. $receiptDetail->update ( array (
  2623. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2624. ) );
  2625. }
  2626. $receipt = new receipt ();
  2627. $receipt->sum=$rInfo['sum']+$fees;
  2628. $receipt->update ( array (
  2629. 'where' => 'rid=' . $rid
  2630. ) );
  2631. $XDeode = new XDeode ( 7 );
  2632. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2633. } else
  2634. die ( 'illegal request' );
  2635. }
  2636. /**
  2637. * 移除讲师
  2638. */
  2639. function receiptTrainLecturerDelDo() {
  2640. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2641. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2642. Doo::loadModel ( 'receipt' );
  2643. $receipt = new receipt ();
  2644. Doo::loadModel ( 'RILecturer' );
  2645. $RILecturer = new RILecturer ();
  2646. Doo::loadClass ( 'XDeode' );
  2647. $XDeode = new XDeode ( 5 );
  2648. $rid = $XDeode->decode ( $ridKey );
  2649. $rlid = $XDeode->decode ( $rlidKey );
  2650. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2651. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2652. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2653. die ( 'illegal request-status' );
  2654. }
  2655. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2656. if (empty($detail)){
  2657. die ( 'illegal request-data' );
  2658. }
  2659. $RILecturer->delete ( array (
  2660. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2661. ) );
  2662. //更新费用合计金额
  2663. $rInfo = $receipt->getReceiptByRid ( $rid );
  2664. $receipt = new receipt ();
  2665. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2666. $receipt->update ( array (
  2667. 'where' => 'rid=' . $rid
  2668. ) );
  2669. Doo::loadModel ( 'receiptDetail' );
  2670. $receiptDetail = new receiptDetail ();
  2671. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2672. $receiptDetail = new receiptDetail ();
  2673. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2674. $receiptDetail->price = $rdInfo ['price'];
  2675. $receiptDetail->update ( array (
  2676. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2677. ) );
  2678. $XDeode = new XDeode ( 7 );
  2679. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2680. } else
  2681. die ( 'illegal request-iid' );
  2682. }
  2683. /**
  2684. * 培训班提交审批
  2685. */
  2686. function receiptTrainDo() {
  2687. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2688. Doo::loadClass ( 'XDeode' );
  2689. $XDeode = new XDeode ( 7 );
  2690. $rid = $XDeode->decode ( $ridKey );
  2691. Doo::loadModel ( 'receipt' );
  2692. $receipt = new receipt ();
  2693. Doo::loadModel ( 'receiptDetail' );
  2694. $receiptDetail = new receiptDetail ();
  2695. Doo::loadModel ( 'statistics' );
  2696. $statistics = new statistics ();
  2697. Doo::loadModel ( "verify" );
  2698. $verify = new verify ();
  2699. // 审批状态的判定
  2700. $receiptDetailList = $receipt->getOne ( array (
  2701. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2702. 'asArray' => true
  2703. ) );
  2704. if (empty ( $receiptDetailList ))
  2705. return "/saeaBorad";
  2706. $verifyDetail = $verify->getOne ( array (
  2707. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2708. 'asArray' => true
  2709. ) );
  2710. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2711. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2712. $nowStaff = "";
  2713. $nowStaffList = array ();
  2714. if ($verifyDetail [0] [1] == 'ROLE') {
  2715. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2716. foreach ( $vStaffString as $key => $value ) {
  2717. $staffK = explode ( "_", $value );
  2718. array_push ( $nowStaffList, $staffK [0] );
  2719. }
  2720. $nowStaff = implode ( ',', $nowStaffList );
  2721. } else {
  2722. $nowStaff = $verifyDetail [0] [0];
  2723. }
  2724. $receipt->nowStaff = $nowStaff;
  2725. }
  2726. // echo $nowStaff;
  2727. // print_r($verifyDetail);die;
  2728. $receipt->rid = $receiptDetailList ['rid'];
  2729. $receipt->date = date ( "Y-m-d" );
  2730. $receipt->status = 2;
  2731. $receipt->update ();
  2732. $receiptDetail->status = 2;
  2733. $receiptDetail->update ( array (
  2734. 'where' => 'rid=' . $receiptDetailList ['rid']
  2735. ) );
  2736. Doo::loadModel ( "receiptLog" );
  2737. $receiptLog = new receiptLog ();
  2738. Doo::loadModel ( "verify" );
  2739. $verify = new verify ();
  2740. $vr = $verify->getOne ( array (
  2741. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2742. 'asArray' => true
  2743. ) );
  2744. $jd = json_decode ( $vr ['staff'] );
  2745. $roleId = 0;
  2746. foreach ( $jd as $key => $value ) {
  2747. if ($value [1] == 'ROLE') {
  2748. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2749. if ($pos !== false) {
  2750. $roleId = $value [0];
  2751. }
  2752. }
  2753. }
  2754. // 审批日志
  2755. // echo $roleId;die;
  2756. if (! empty ( $roleId )) {
  2757. Doo::loadModel ( "role" );
  2758. $role = new role ();
  2759. $roleInfo = $role->getOne ( array (
  2760. 'where' => 'rid=' . $roleId,
  2761. 'asArray' => true
  2762. ) );
  2763. // $receiptLog->rolename = $roleInfo ['name'];
  2764. }
  2765. $receiptLog->username = $this->staff [0] ['username'];
  2766. $receiptLog->uid = $this->staff [0] ['sid'];
  2767. $receiptLog->date = date ( "Y-m-d" );
  2768. $receiptLog->opinion = '提交审批';
  2769. $receiptLog->img = $this->staff [0] ['avatar'];
  2770. $receiptLog->status = 2;
  2771. $receiptLog->rid = $rid;
  2772. $receiptLog->insert ();
  2773. // 写入列表项
  2774. Doo::loadModel ( 'accountItem' );
  2775. $accountItem = new accountItem ();
  2776. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2777. // 项目金额合计
  2778. Doo::loadModel ( 'RItem' );
  2779. $RItem = new RItem ();
  2780. // 讲师获得
  2781. Doo::loadModel ( 'RILecturer' );
  2782. $RILecturer = new RILecturer ();
  2783. $RItemList = $RItem->getRItemByRid ( $rid );
  2784. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2785. // 支出项金额详情
  2786. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2787. // print_r($aItem);
  2788. // print_r($aiData);
  2789. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2790. $ag = $tr = $ta = $ot = 0;
  2791. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2792. foreach ( $aItem as $key => $value ) {
  2793. if ($value ['category'] == $this->TRAIN) {
  2794. foreach ( $aiData ['dataList'] as $k => $v ) {
  2795. if ($value ['name'] == $v ['name']) {
  2796. array_push ( $accountJson [$this->TRAIN], array (
  2797. 'aid' => $value ['aid'],
  2798. 'name' => $value ['name'],
  2799. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2800. ) );
  2801. $sum += $v ['price'];
  2802. $trainSum += $v ['price'];
  2803. unset ( $aiData ['dataList'] [$k] );
  2804. break;
  2805. }
  2806. }
  2807. }
  2808. }
  2809. $accountJson ['cSum'] = array (
  2810. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2811. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2812. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2813. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2814. );
  2815. // 报销单
  2816. $receipt = new receipt ();
  2817. $receipt->accountItem = json_encode ( $accountJson );
  2818. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2819. $receipt->update ( array (
  2820. 'where' => 'rid=' . $rid
  2821. ) );
  2822. // print_r($accountJson);
  2823. // statistics item 统计写入
  2824. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2825. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2826. $accountItem = $accountJson;
  2827. $stat = $statistics->getOne ( array (
  2828. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2829. 'asArray' => true
  2830. ) );
  2831. if (empty ( $stat )) {
  2832. $statistics->date = date ( "Y-m-d" );
  2833. $statistics->cid = $this->staff [0] ['cid'];
  2834. $statistics->staff = $this->staff [0] ['sid'];
  2835. $statistics->agPrice = 0;
  2836. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2837. $statistics->insert ();
  2838. } else {
  2839. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2840. $statistics->update ( array (
  2841. 'where' => 'sid=' . $stat ['sid']
  2842. ) );
  2843. }
  2844. return "/saeaBorad";
  2845. }
  2846. function confirmation() {
  2847. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2848. Doo::loadModel ( 'receipt' );
  2849. Doo::loadModel ( 'receiptDetail' );
  2850. $receipt = new receipt ();
  2851. $receiptDetail = new receiptDetail ();
  2852. Doo::loadModel ( 'statistics' );
  2853. Doo::loadModel ( 'itemStatistics' );
  2854. $statistics = new statistics ();
  2855. $itemStatistics = new itemStatistics ();
  2856. Doo::loadModel ( "verify" );
  2857. $verify = new verify ();
  2858. $receiptDetailList = $receipt->getOne ( array (
  2859. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2860. 'asArray' => true
  2861. ) );
  2862. if (empty ( $receiptDetailList ))
  2863. return "/saeaBorad";
  2864. $verifyDetail = $verify->getOne ( array (
  2865. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2866. 'asArray' => true
  2867. ) );
  2868. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2869. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2870. $nowStaff = "";
  2871. $nowStaffList = array ();
  2872. if ($verifyDetail [0] [1] == 'ROLE') {
  2873. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2874. foreach ( $vStaffString as $key => $value ) {
  2875. $staffK = explode ( "_", $value );
  2876. array_push ( $nowStaffList, $staffK [0] );
  2877. }
  2878. $nowStaff = implode ( ',', $nowStaffList );
  2879. } else {
  2880. $nowStaff = $verifyDetail [0] [0];
  2881. }
  2882. $receipt->nowStaff = $nowStaff;
  2883. }
  2884. // echo $nowStaff;
  2885. // print_r($verifyDetail);die;
  2886. $receipt->rid = $receiptDetailList ['rid'];
  2887. $receipt->status = 2;
  2888. $receipt->update ();
  2889. // 操作日志
  2890. Doo::loadModel ( "receiptLog" );
  2891. $receiptLog = new receiptLog ();
  2892. $verify = new verify ();
  2893. $receiptInfo = $receipt->getOne ( array (
  2894. 'where' => 'rid=' . $rid,
  2895. 'asArray' => true
  2896. ) );
  2897. $vr = $verify->getOne ( array (
  2898. 'where' => 'vid=' . $receiptInfo ['verify'],
  2899. 'asArray' => true
  2900. ) );
  2901. $jd = json_decode ( $vr ['staff'] );
  2902. $roleId = 0;
  2903. foreach ( $jd as $key => $value ) {
  2904. if ($value [1] == 'ROLE') {
  2905. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2906. if ($pos !== false) {
  2907. $roleId = $value [0];
  2908. }
  2909. }
  2910. }
  2911. // 审批日志
  2912. // echo $roleId;die;
  2913. if (! empty ( $roleId )) {
  2914. Doo::loadModel ( "role" );
  2915. $role = new role ();
  2916. $roleInfo = $role->getOne ( array (
  2917. 'where' => 'rid=' . $roleId,
  2918. 'asArray' => true
  2919. ) );
  2920. // $receiptLog->rolename = $roleInfo ['name'];
  2921. }
  2922. $receiptLog->username = $this->staff [0] ['username'];
  2923. $receiptLog->uid = $this->staff [0] ['sid'];
  2924. $receiptLog->date = date ( "Y-m-d" );
  2925. $receiptLog->opinion = '提交审批';
  2926. $receiptLog->img = $this->staff [0] ['avatar'];
  2927. $receiptLog->status = 2;
  2928. $receiptLog->rid = $rid;
  2929. $receiptLog->insert ();
  2930. return "/expenses";
  2931. }
  2932. function expenses() {
  2933. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2934. if (empty ( $item ))
  2935. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2936. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2937. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2938. Doo::loadClass ( 'XDeode' );
  2939. $XDeode = new XDeode ( 7 );
  2940. Doo::loadModel ( 'receipt' );
  2941. $receipt = new receipt ();
  2942. Doo::loadModel ( 'L_category' );
  2943. $Lcategory = new L_category ();
  2944. Doo::loadModel ( 'verify' );
  2945. Doo::loadModel ( 'statistics' );
  2946. $statistics = new statistics ();
  2947. $verify = new verify ();
  2948. Doo::loadModel ( 'staff' );
  2949. $staff = new staff ();
  2950. $condition = "";
  2951. if ($item == "expenses")
  2952. $condition = " and Rtype=1 ";
  2953. elseif ($item == "receipts")
  2954. $condition = " and Rtype=0 ";
  2955. elseif ($item == "remits")
  2956. $condition = " and Rtype=2 ";
  2957. elseif ($item == "train")
  2958. $condition = " and Rtype=3 ";
  2959. $dateCondition = " and Year(date) =" . $year;
  2960. if (! empty ( $moth )) {
  2961. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2962. $stList = $statistics->getOne ( array (
  2963. 'select' => 'rePrice ,agPrice',
  2964. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2965. 'asArray' => true
  2966. ) );
  2967. } else
  2968. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2969. if (empty ( $stList ))
  2970. $stList = array (
  2971. 'rePrice' => 0,
  2972. 'agPrice' => 0
  2973. );
  2974. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2975. if (! isset ( $noPassSum ['sum'] ))
  2976. $noPassSum ['sum'] = 0;
  2977. $data ['stList'] = array (
  2978. 'rePrice' => $stList ['rePrice'],
  2979. 'agPrice' => $stList ['agPrice'],
  2980. 'skPrice' => ($noPassSum ['sum'])
  2981. );
  2982. $receiptList = $receipt->find ( array (
  2983. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2984. 'desc' => 'rid',
  2985. 'asArray' => true
  2986. ) );
  2987. $Locate = 0;
  2988. $roleId = 0;
  2989. $button = 0;
  2990. foreach ( $receiptList as $key => $value ) {
  2991. $receiptList [$key] ['Locate'] = $Locate;
  2992. $Locate ++;
  2993. $receiptList [$key] ['reviseDetail'] = array ();
  2994. if (! empty ( $value ['reviseDetail'] ))
  2995. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2996. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2997. $categoryDetil = $Lcategory->getOne ( array (
  2998. 'where' => 'cid=' . $value ['cid'],
  2999. 'asArray' => true
  3000. ) );
  3001. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3002. // 检测编辑状态
  3003. $verifyList = $verify->getOne ( array (
  3004. 'where' => 'vid=' . $value ['verify'],
  3005. 'asArray' => true
  3006. ) );
  3007. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3008. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3009. Doo::loadModel ( 'role' );
  3010. $role = new role ();
  3011. $flag = true;
  3012. $roleKey = 0;
  3013. $endStaffArray = array ();
  3014. $roleArrayCopy = array ();
  3015. foreach ( $verifyList as $k => $v ) {
  3016. // init verifyStaff
  3017. if ($v [1] == 'ROLE') {
  3018. if (! empty ( $verifyStaff )) {
  3019. $endStaffArray = end ( $verifyStaff );
  3020. // if ($v[0]==$endStaffArray['nextStaff']){
  3021. // $roleId=$v[0];
  3022. // }
  3023. }
  3024. $roleVerify = json_decode ( $v [3], true );
  3025. $roleKey = $k;
  3026. $roleArray = array ();
  3027. $rolename = $role->getOne ( array (
  3028. 'where' => 'rid=' . $v [0],
  3029. 'asArray' => true
  3030. ) );
  3031. foreach ( $roleVerify as $o => $p ) {
  3032. $staffID = explode ( '_', $p );
  3033. $staffInfo = $staff->getOne ( array (
  3034. 'where' => 'sid=' . $staffID [0],
  3035. 'asArray' => true
  3036. ) );
  3037. // print_r($staffID);
  3038. $exp = array (
  3039. 0 => $staffInfo ['sid'],
  3040. 1 => $staffID [1],
  3041. 2 => $staffInfo ['avatar'],
  3042. 'date' => '',
  3043. 'date' => '',
  3044. 'opinion' => '',
  3045. 'status' => '',
  3046. 'rolename' => $rolename ['name']
  3047. );
  3048. array_push ( $roleArray, $exp );
  3049. }
  3050. $roleArrayCopy [$v [0]] = $roleArray;
  3051. // $verifyList[$k]['roleArray']=$roleArray;
  3052. }
  3053. $verifyList [$k] ['date'] = "";
  3054. $verifyList [$k] ['opinion'] = "";
  3055. $verifyList [$k] ['status'] = "";
  3056. if (empty ( $verifyStaff )) {
  3057. $verifyList [$k] ['date'] = "";
  3058. $verifyList [$k] ['opinion'] = "";
  3059. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3060. $verifyList [$k] ['status'] = 4;
  3061. $flag = false;
  3062. }
  3063. } else {
  3064. foreach ( $verifyStaff as $m => $u ) {
  3065. if ($v [0] == $m) {
  3066. $verifyList [$k] ['date'] = $u ['date'];
  3067. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3068. $verifyList [$k] ['status'] = $u ['status'];
  3069. $flag = false;
  3070. break;
  3071. }
  3072. }
  3073. $endStaffArray = end ( $verifyStaff );
  3074. if (isset ( $endStaffArray ['ROLE'] )) {
  3075. } else {
  3076. // $endKey=key($verifyStaff);
  3077. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3078. // $button=4;
  3079. // $verifyList[$k]['status']=4;
  3080. // }
  3081. }
  3082. }
  3083. }
  3084. $rolename ['name'] = '';
  3085. if (! empty ( $roleId )) {
  3086. Doo::loadModel ( 'role' );
  3087. $role = new role ();
  3088. $rolename = $role->getOne ( array (
  3089. 'where' => 'rid=' . $roleId,
  3090. 'asArray' => true
  3091. ) );
  3092. }
  3093. if (! empty ( $verifyStaff ))
  3094. $endStaffArray = end ( $verifyStaff );
  3095. $KOP = false;
  3096. foreach ( $roleArrayCopy as $P => $A ) {
  3097. foreach ( $A as $MKI => $AVL ) {
  3098. if (! empty ( $verifyStaff )) {
  3099. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3100. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3101. $button = 4;
  3102. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3103. }
  3104. foreach ( $verifyStaff as $m => $u ) {
  3105. $AVLFK = $AVL [0] . '_R';
  3106. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3107. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3108. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3109. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3110. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3111. break;
  3112. }
  3113. }
  3114. } else {
  3115. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3116. $button = 4;
  3117. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3118. }
  3119. }
  3120. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3121. $KOP = true;
  3122. }
  3123. }
  3124. foreach ( $roleArrayCopy as $k => $v ) {
  3125. foreach ( $verifyList as $m => $n ) {
  3126. if ($n [0] == $k) {
  3127. array_splice ( $verifyList, $m, 1, $v );
  3128. }
  3129. }
  3130. }
  3131. $receiptList [$key] ['verifyList'] = $verifyList;
  3132. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3133. 'where' => 'sid=' . $value ['staff'],
  3134. 'asArray' => true
  3135. ) );
  3136. $receiptList [$key] ['button'] = $button;
  3137. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3138. }
  3139. // print_r($receiptList);die;
  3140. $mothHtml = "";
  3141. for($i = 1; $i <= 12; $i ++) {
  3142. if ($moth == $i)
  3143. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3144. else
  3145. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3146. }
  3147. $dateHtml = "";
  3148. $now = date ( "Y" );
  3149. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3150. if ($YEARD <= $now) {
  3151. $dateHtml .= '<option ';
  3152. if ($year == $YEARD) {
  3153. $dateHtml .= 'selected ';
  3154. }
  3155. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3156. }
  3157. }
  3158. $data ['dateHtml'] = $dateHtml;
  3159. $data ['mothHtml'] = $mothHtml;
  3160. $data ['receiptList'] = $receiptList;
  3161. $data ['memu'] = "receipt";
  3162. $data ['staff'] = $this->staff;
  3163. $data ['receiptMemu'] = 'expenses';
  3164. $data ['verifyId'] = $this->verifyId;
  3165. $data ['executeId'] = $this->executeId;
  3166. $data ['item'] = $item;
  3167. $data ['year'] = $year;
  3168. $this->render ( "/admin/expenses", $data );
  3169. }
  3170. function expensesCollect() {
  3171. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3172. Doo::loadModel ( 'receipt' );
  3173. $receipt = new receipt ();
  3174. Doo::loadModel ( 'L_category' );
  3175. $Lcategory = new L_category ();
  3176. Doo::loadModel ( 'verify' );
  3177. Doo::loadModel ( 'statistics' );
  3178. $statistics = new statistics ();
  3179. $verify = new verify ();
  3180. Doo::loadModel ( 'staff' );
  3181. $staff = new staff ();
  3182. Doo::loadModel ( 'loanReceipt' );
  3183. $loanReceipt = new loanReceipt ();
  3184. $receiptList = $receipt->find ( array (//去掉
  3185. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3186. 'desc' => 'rid',
  3187. 'asArray' => true
  3188. ) );
  3189. $loanList = $loanReceipt->find ( array (
  3190. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3191. 'desc' => 'rid',
  3192. 'asArray' => true
  3193. ) );
  3194. /*
  3195. * $Locate=0;$roleId=0;$button=0; foreach ($loanList as $key=>$value){ $loanList[$key]['Locate']=$Locate;$Locate++; $loanList[$key]['reviseDetail']=array(); if (!empty($value['reviseDetail'])) $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true); $loanList[$key]['accountItem']=json_decode($value['accountItem'],true); $loanList[$key]['loanItem']=json_decode($value['loanItem'],true); $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true)); $loanList[$key]['category']=$categoryDetil['title']; //检测编辑状态 if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9) $verifyList['staff']=$value['verifyBreakup']; else $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true)); $verifyList=json_decode($verifyList['staff'],true);//status opinion $verifyStaff=json_decode($value['verifyStaff'],true); Doo::loadModel('role'); $role=new role(); $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array(); foreach ($verifyList as $k=>$v){ //init verifyStaff if ($v[1]=='ROLE'){ if (!empty($verifyStaff)){ $endStaffArray=end($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']){ // $roleId=$v[0]; // } } $roleVerify=json_decode($v[3],true); $roleKey=$k;$roleArray=array(); $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true)); foreach ($roleVerify as $o=>$p){ $staffID=explode ('_',$p); $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true)); //print_r($staffID); $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']); array_push($roleArray, $exp); } $roleArrayCopy[$v[0]]=$roleArray; //$verifyList[$k]['roleArray']=$roleArray; } $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; $verifyList[$k]['status']=""; if (empty($verifyStaff)){ $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){ $verifyList[$k]['status']=4; $flag=false; } }else{ foreach ($verifyStaff as $m=>$u){ if ($v[0]==$m){ $verifyList[$k]['date']=$u['date']; $verifyList[$k]['opinion']=$u['opinion']; $verifyList[$k]['status']=$u['status']; $flag=false; break; } } $endStaffArray=end($verifyStaff); if (isset($endStaffArray['ROLE'])){ }else{ // $endKey=key($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){ // $button=4; // $verifyList[$k]['status']=4; // } } } } $rolename['name']=''; if (!empty($roleId)){ Doo::loadModel('role'); $role=new role(); $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true)); } if (!empty($verifyStaff)) $endStaffArray=end($verifyStaff); $KOP=false; foreach ($roleArrayCopy as $P=>$A){ foreach ( $A as $MKI=>$AVL){ if (!empty($verifyStaff)){ //&&$rolename['rid']==$endStaffArray['nextStaff'] if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } foreach ($verifyStaff as $m=>$u){ $AVLFK=$AVL[0].'_R'; //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>'; if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1 $roleArrayCopy[$P][$MKI]['date']=$u['date']; $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion']; $roleArrayCopy[$P][$MKI]['status']=$u['status']; break; } } }else{ if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } } //$roleArray[$MKI]['rolename']=$rolename['name']; $KOP=true; } } foreach ($roleArrayCopy as $k=>$v){ foreach ($verifyList as $m=>$n){ if ($n[0]==$k){ array_splice($verifyList,$m,1,$v); } } } $loanList[$key]['verifyList']=$verifyList; $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true)); $loanList[$key]['button']=$button; //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']); } $data['loanList']=$loanList;
  3196. */
  3197. $data ['explanation'] = '';
  3198. if (! empty ( $loanList ))
  3199. $data ['explanation'] = $loanList [0] ['explanation'];
  3200. $Locate = 0;
  3201. $roleId = 0;
  3202. $button = 0;
  3203. foreach ( $receiptList as $key => $value ) {
  3204. $receiptList [$key] ['Locate'] = $Locate;
  3205. $Locate ++;
  3206. $receiptList [$key] ['reviseDetail'] = array ();
  3207. if (! empty ( $value ['reviseDetail'] ))
  3208. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3209. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3210. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3211. $categoryDetil = $Lcategory->getOne ( array (
  3212. 'where' => 'cid=' . $value ['cid'],
  3213. 'asArray' => true
  3214. ) );
  3215. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3216. // 检测编辑状态
  3217. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3218. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3219. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3220. else
  3221. $verifyList ['staff'] = $value ['verifyBreakup'];
  3222. } else
  3223. $verifyList = $verify->getOne ( array (
  3224. 'where' => 'vid=' . $value ['verify'],
  3225. 'asArray' => true
  3226. ) );
  3227. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3228. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3229. Doo::loadModel ( 'role' );
  3230. $role = new role ();
  3231. $flag = true;
  3232. $roleKey = 0;
  3233. $endStaffArray = array ();
  3234. $roleArrayCopy = array ();
  3235. foreach ( $verifyList as $k => $v ) {
  3236. // init verifyStaff
  3237. if ($v [1] == 'ROLE') {
  3238. if (! empty ( $verifyStaff )) {
  3239. $endStaffArray = end ( $verifyStaff );
  3240. // if ($v[0]==$endStaffArray['nextStaff']){
  3241. // $roleId=$v[0];
  3242. // }
  3243. }
  3244. $roleVerify = json_decode ( $v [3], true );
  3245. $roleKey = $k;
  3246. $roleArray = array ();
  3247. $rolename = $role->getOne ( array (
  3248. 'where' => 'rid=' . $v [0],
  3249. 'asArray' => true
  3250. ) );
  3251. foreach ( $roleVerify as $o => $p ) {
  3252. $staffID = explode ( '_', $p );
  3253. $staffInfo = $staff->getOne ( array (
  3254. 'where' => 'sid=' . $staffID [0],
  3255. 'asArray' => true
  3256. ) );
  3257. // print_r($staffID);
  3258. $exp = array (
  3259. 0 => $staffInfo ['sid'],
  3260. 1 => $staffID [1],
  3261. 2 => $staffInfo ['avatar'],
  3262. 'date' => '',
  3263. 'date' => '',
  3264. 'opinion' => '',
  3265. 'status' => '',
  3266. 'rolename' => $rolename ['name']
  3267. );
  3268. array_push ( $roleArray, $exp );
  3269. }
  3270. $roleArrayCopy [$v [0]] = $roleArray;
  3271. // $verifyList[$k]['roleArray']=$roleArray;
  3272. }
  3273. $verifyList [$k] ['date'] = "";
  3274. $verifyList [$k] ['opinion'] = "";
  3275. $verifyList [$k] ['status'] = "";
  3276. if (empty ( $verifyStaff )) {
  3277. $verifyList [$k] ['date'] = "";
  3278. $verifyList [$k] ['opinion'] = "";
  3279. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3280. $verifyList [$k] ['status'] = 4;
  3281. $flag = false;
  3282. }
  3283. } else {
  3284. foreach ( $verifyStaff as $m => $u ) {
  3285. if ($v [0] == $m) {
  3286. $verifyList [$k] ['date'] = $u ['date'];
  3287. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3288. $verifyList [$k] ['status'] = $u ['status'];
  3289. $flag = false;
  3290. break;
  3291. }
  3292. }
  3293. $endStaffArray = end ( $verifyStaff );
  3294. if (isset ( $endStaffArray ['ROLE'] )) {
  3295. } else {
  3296. // $endKey=key($verifyStaff);
  3297. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3298. // $button=4;
  3299. // $verifyList[$k]['status']=4;
  3300. // }
  3301. }
  3302. }
  3303. }
  3304. $rolename ['name'] = '';
  3305. if (! empty ( $roleId )) {
  3306. Doo::loadModel ( 'role' );
  3307. $role = new role ();
  3308. $rolename = $role->getOne ( array (
  3309. 'where' => 'rid=' . $roleId,
  3310. 'asArray' => true
  3311. ) );
  3312. }
  3313. if (! empty ( $verifyStaff ))
  3314. $endStaffArray = end ( $verifyStaff );
  3315. $KOP = false;
  3316. foreach ( $roleArrayCopy as $P => $A ) {
  3317. foreach ( $A as $MKI => $AVL ) {
  3318. if (! empty ( $verifyStaff )) {
  3319. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3320. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3321. $button = 4;
  3322. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3323. }
  3324. foreach ( $verifyStaff as $m => $u ) {
  3325. $AVLFK = $AVL [0] . '_R';
  3326. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3327. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3328. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3329. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3330. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3331. break;
  3332. }
  3333. }
  3334. } else {
  3335. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3336. $button = 4;
  3337. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3338. }
  3339. }
  3340. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3341. $KOP = true;
  3342. }
  3343. }
  3344. foreach ( $roleArrayCopy as $k => $v ) {
  3345. foreach ( $verifyList as $m => $n ) {
  3346. if ($n [0] == $k) {
  3347. array_splice ( $verifyList, $m, 1, $v );
  3348. }
  3349. }
  3350. }
  3351. // 费用执行人相关数据
  3352. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3353. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3354. foreach ( $executeCopy as $k => $v ) {
  3355. $executeCopy [$k] ['date'] = '';
  3356. $executeCopy [$k] ['opinion'] = '';
  3357. $executeCopy [$k] ['status'] = '';
  3358. if (! empty ( $executeStaff ))
  3359. foreach ( $executeStaff as $m => $u ) {
  3360. if ($v [0] == $m) {
  3361. $executeCopy [$k] ['date'] = $u ['date'];
  3362. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3363. $executeCopy [$k] ['status'] = $u ['status'];
  3364. break;
  3365. }
  3366. }
  3367. }
  3368. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3369. $receiptList [$key] ['verifyList'] = $verifyList;
  3370. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3371. 'where' => 'sid=' . $value ['staff'],
  3372. 'asArray' => true
  3373. ) );
  3374. $receiptList [$key] ['button'] = $button;
  3375. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3376. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3377. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3378. $receiptList [$key] ['relust'] = $relust;
  3379. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3380. }
  3381. Doo::loadModel ( 'enclosur' );
  3382. $enclosur = new enclosur ();
  3383. $enclosurList = $enclosur->find ( array (
  3384. 'where' => 'rid=' . $rid,
  3385. 'asArray' => true
  3386. ) );
  3387. $enclosurHtml = '';
  3388. foreach ( $enclosurList as $value ) {
  3389. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3390. }
  3391. $data ['enclosurHtml'] = $enclosurHtml;
  3392. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3393. $data ['receiptList'] = $receiptList;
  3394. $data ['memu'] = "receipt";
  3395. $data ['staff'] = $this->staff;
  3396. $data ['receiptMemu'] = 'expenses';
  3397. $data ['verifyId'] = $this->verifyId;
  3398. $data ['executeId'] = $this->executeId;
  3399. $this->render ( "/admin/expensesCollect", $data );
  3400. }
  3401. function approvalExpenses() {
  3402. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3403. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3404. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3405. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3406. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3407. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3408. // echo $rdate;
  3409. if (empty ( $status ))
  3410. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3411. $page_size = 8;
  3412. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3413. $vidList = array ();
  3414. $button = 0;
  3415. Doo::loadModel ( 'verify' );
  3416. $verify = new verify ();
  3417. Doo::loadModel ( 'receipt' );
  3418. $receipt = new receipt ();
  3419. Doo::loadModel ( 'staff' );
  3420. $staff = new staff ();
  3421. Doo::loadModel ( 'L_category' );
  3422. $Lcategory = new L_category ();
  3423. // user verify ID
  3424. $verifyDetail = $verify->find ( array (
  3425. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3426. 'asArray' => true
  3427. ) );
  3428. foreach ( $verifyDetail as $key => $value ) {
  3429. array_push ( $vidList, $value ['vid'] );
  3430. }
  3431. $vid = implode ( ",", $vidList );
  3432. if (empty ( $verifyDetail ))
  3433. $vid = 0;
  3434. // if ($status==0)
  3435. // $dateCondition="";
  3436. // else
  3437. $dateCondition = " ";
  3438. // if (! empty ( $month ))
  3439. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3440. if ($status == 'done' || $status == 'termination') {
  3441. if (! empty ( $year )) {
  3442. $dateCondition = " and Year(pastDate) =" . $year;
  3443. if (! empty ( $month ))
  3444. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3445. }
  3446. } elseif ($status == 'finish') {
  3447. if (! empty ( $year )) {
  3448. $dateCondition = " and Year(pastDate) =" . $year;
  3449. if (! empty ( $month ))
  3450. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3451. }
  3452. }
  3453. // date ( 'Y-m' )
  3454. // if (! empty ( $rdate ) && $status == 'done')
  3455. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3456. // elseif (! empty ( $rdate ))
  3457. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3458. $categoryList = $Lcategory->find ( array (
  3459. 'asArray' => true
  3460. ) );
  3461. $staffList = $staff->find ( array (
  3462. 'where' => 'cid=' . $cid,
  3463. 'asArray' => true
  3464. ) );
  3465. $cateCondition = "";
  3466. $staffCondition = "";
  3467. $approvalCondition = "";
  3468. if (! empty ( $cid )) {
  3469. $cateCondition = ' and cid=' . $cid;
  3470. }
  3471. if (! empty ( $sid )) {
  3472. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3473. $cateCondition = "";
  3474. }
  3475. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3476. if ($status == 'pendApproval') {
  3477. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3478. }
  3479. if ($status == 'ongoing') {
  3480. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3481. }
  3482. if ($status == 'done') {
  3483. $approvalCondition = ' and (status=8 or status=9 ) ';
  3484. }
  3485. if ($status == 'termination') {
  3486. $approvalCondition = " and status=3";
  3487. }
  3488. if ($status == 'finish') {
  3489. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3490. }
  3491. $pageinfo ['page'] = array (
  3492. 'previous' => ''
  3493. );
  3494. if(!empty($receiptOrder)){
  3495. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3496. $receiptList = $receipt->find ( array ( // $dateCondition
  3497. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3498. 'desc' => 'rid',
  3499. 'asArray' => true
  3500. ) );
  3501. }else{
  3502. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3503. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3504. $receiptList = $receipt->find ( array ( // $dateCondition.
  3505. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3506. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3507. 'desc' => 'rid',
  3508. 'asArray' => true
  3509. ) );
  3510. } else {
  3511. $receiptList = $receipt->find ( array ( // $dateCondition
  3512. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3513. 'desc' => 'rid',
  3514. 'asArray' => true
  3515. ) );
  3516. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3517. }
  3518. }
  3519. $rLRes = $receipt->find ( array (
  3520. '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 . ' and verify in (' . $vid . ')',
  3521. 'desc' => 'rid',
  3522. 'asArray' => true
  3523. ) );
  3524. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3525. // print_r($receiptList);
  3526. Doo::loadClass ( 'XDeode' );
  3527. $XDeode = new XDeode ( 7 );
  3528. $Locate = 0;
  3529. $reportList = $reportCateList = array ();
  3530. foreach ( $receiptList as $key => $value ) {
  3531. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3532. $receiptList [$key] ['Locate'] = $Locate;
  3533. $Locate ++;
  3534. $receiptList [$key] ['reviseDetail'] = array ();
  3535. if (! empty ( $value ['reviseDetail'] ))
  3536. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3537. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3538. $categoryDetil = $Lcategory->getOne ( array (
  3539. 'where' => 'cid=' . $value ['cid'],
  3540. 'asArray' => true
  3541. ) );
  3542. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3543. $verifyList = $verify->getOne ( array (
  3544. 'where' => 'vid=' . $value ['verify'],
  3545. 'asArray' => true
  3546. ) );
  3547. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3548. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3549. foreach ( $verifyList as $k => $v ) {
  3550. // init verifyStaff
  3551. $verifyList [$k] ['date'] = "";
  3552. $verifyList [$k] ['opinion'] = "";
  3553. $verifyList [$k] ['status'] = "";
  3554. if (empty ( $verifyStaff )) {
  3555. $verifyList [$k] ['date'] = "";
  3556. $verifyList [$k] ['opinion'] = "";
  3557. if ($v [0] == $this->staff [0] ['sid']) {
  3558. $verifyList [$k] ['status'] = 4;
  3559. $button = 4;
  3560. }
  3561. } else {
  3562. $flag = true;
  3563. foreach ( $verifyStaff as $m => $u ) {
  3564. if ($v [0] == $m) {
  3565. $verifyList [$k] ['date'] = $u ['date'];
  3566. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3567. $verifyList [$k] ['status'] = $u ['status'];
  3568. $flag = false;
  3569. break;
  3570. }
  3571. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3572. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3573. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3574. }
  3575. if ($flag) { // 检测可编辑
  3576. if ($v [0] == $this->staff [0] ['sid']) {
  3577. $verifyList [$k] ['status'] = 4;
  3578. $button = 4;
  3579. }
  3580. }
  3581. }
  3582. }
  3583. $receiptList [$key] ['verifyList'] = $verifyList;
  3584. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3585. 'where' => 'sid=' . $value ['staff'],
  3586. 'asArray' => true
  3587. ) );
  3588. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3589. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3590. $receiptList [$key] ['button'] = $button;
  3591. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3592. }
  3593. $reportList = array_unique ( $reportList );
  3594. $reportHtml = '';
  3595. foreach ( $reportList as $key => $value ) {
  3596. $v = explode ( "-", $value );
  3597. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3598. }
  3599. // print_r($reportList)
  3600. $data ['reportHtml'] = $reportHtml;
  3601. $reportCateList = array_unique ( $reportCateList );
  3602. $reportCateHtml = '';
  3603. foreach ( $reportCateList as $key => $value ) {
  3604. $v = explode ( "-", $value );
  3605. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3606. }
  3607. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3608. $data ['reportCateHtml'] = $reportCateHtml;
  3609. // print_r($receiptList);die;
  3610. // $data['verifyDetail']=$verifyDetail;
  3611. $mothHtml = "";
  3612. for($i = 1; $i <= 12; $i ++) {
  3613. if ($month == $i)
  3614. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3615. else
  3616. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3617. }
  3618. $data ['mothHtml'] = $mothHtml;
  3619. $dateHtml = "";
  3620. $now = date ( "Y" );
  3621. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3622. if ($YEARD <= $now) {
  3623. $dateHtml .= '<option ';
  3624. if ($year == $YEARD) {
  3625. $dateHtml .= 'selected ';
  3626. }
  3627. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3628. }
  3629. }
  3630. $data ['dateHtml'] = $dateHtml;
  3631. $data ['page'] = $pageinfo;
  3632. $data ['receiptList'] = $receiptList;
  3633. $data ['receiptApprovalCount'] = count ( $rLRes );
  3634. $data ['status'] = $status;
  3635. $data ['year'] = $year;
  3636. $data ['month'] = $month;
  3637. $data ['categoryList'] = $categoryList;
  3638. $data ['staffList'] = $staffList;
  3639. $data ['cid'] = $cid;
  3640. $data ['sid'] = $sid;
  3641. // print_r($receiptList);
  3642. $data['receiptOrder']=$receiptOrder;
  3643. $data ['memu'] = "receipt";
  3644. $data ['staff'] = $this->staff;
  3645. $data ['receiptMemu'] = 'approvalExpenses';
  3646. $data ['verifyId'] = $this->verifyId;
  3647. $data ['executeId'] = $this->executeId;
  3648. $this->render ( "/admin/approvalExpenses", $data );
  3649. }
  3650. function expensesDoc() {
  3651. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3652. Doo::loadClass ( 'XDeode' );
  3653. $XDeode = new XDeode ( 5 );
  3654. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3655. $rid = $XDeode->decode ( $rid );
  3656. if (! is_numeric ( $rid ))
  3657. die ( 'illegal request' );
  3658. Doo::loadModel ( 'receipt' );
  3659. $receipt = new receipt ();
  3660. Doo::loadModel ( 'L_category' );
  3661. $Lcategory = new L_category ();
  3662. Doo::loadModel ( 'verify' );
  3663. Doo::loadModel ( 'statistics' );
  3664. $statistics = new statistics ();
  3665. $verify = new verify ();
  3666. Doo::loadModel ( 'staff' );
  3667. $staff = new staff ();
  3668. Doo::loadModel ( 'loanReceipt' );
  3669. $loanReceipt = new loanReceipt ();
  3670. $receiptList = $receipt->find ( array (
  3671. 'where' => ' rid=' . $rid,
  3672. 'desc' => 'rid',
  3673. 'asArray' => true
  3674. ) );
  3675. $loanList = array ();
  3676. if (! empty ( $receiptList ))
  3677. $loanList = $loanReceipt->find ( array (
  3678. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3679. 'desc' => 'rid',
  3680. 'asArray' => true
  3681. ) );
  3682. $Locate = 0;
  3683. $roleId = 0;
  3684. $button = 0;
  3685. foreach ( $loanList as $key => $value ) {
  3686. $loanList [$key] ['Locate'] = $Locate;
  3687. $Locate ++;
  3688. $loanList [$key] ['reviseDetail'] = array ();
  3689. if (! empty ( $value ['reviseDetail'] ))
  3690. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3691. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3692. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3693. $categoryDetil = $Lcategory->getOne ( array (
  3694. 'where' => 'cid=' . $value ['cid'],
  3695. 'asArray' => true
  3696. ) );
  3697. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3698. // 检测编辑状态
  3699. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3700. $verifyList ['staff'] = $value ['verifyBreakup'];
  3701. else
  3702. $verifyList = $verify->getOne ( array (
  3703. 'where' => 'vid=' . $value ['verify'],
  3704. 'asArray' => true
  3705. ) );
  3706. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3707. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3708. Doo::loadModel ( 'role' );
  3709. $role = new role ();
  3710. $flag = true;
  3711. $roleKey = 0;
  3712. $endStaffArray = array ();
  3713. $roleArrayCopy = array ();
  3714. foreach ( $verifyList as $k => $v ) {
  3715. // init verifyStaff
  3716. if ($v [1] == 'ROLE') {
  3717. if (! empty ( $verifyStaff )) {
  3718. $endStaffArray = end ( $verifyStaff );
  3719. // if ($v[0]==$endStaffArray['nextStaff']){
  3720. // $roleId=$v[0];
  3721. // }
  3722. }
  3723. $roleVerify = json_decode ( $v [3], true );
  3724. $roleKey = $k;
  3725. $roleArray = array ();
  3726. $rolename = $role->getOne ( array (
  3727. 'where' => 'rid=' . $v [0],
  3728. 'asArray' => true
  3729. ) );
  3730. foreach ( $roleVerify as $o => $p ) {
  3731. $staffID = explode ( '_', $p );
  3732. $staffInfo = $staff->getOne ( array (
  3733. 'where' => 'sid=' . $staffID [0],
  3734. 'asArray' => true
  3735. ) );
  3736. // print_r($staffID);
  3737. $exp = array (
  3738. 0 => $staffInfo ['sid'],
  3739. 1 => $staffID [1],
  3740. 2 => $staffInfo ['avatar'],
  3741. 'date' => '',
  3742. 'date' => '',
  3743. 'opinion' => '',
  3744. 'status' => '',
  3745. 'rolename' => $rolename ['name']
  3746. );
  3747. array_push ( $roleArray, $exp );
  3748. }
  3749. $roleArrayCopy [$v [0]] = $roleArray;
  3750. // $verifyList[$k]['roleArray']=$roleArray;
  3751. }
  3752. $verifyList [$k] ['date'] = "";
  3753. $verifyList [$k] ['opinion'] = "";
  3754. $verifyList [$k] ['status'] = "";
  3755. if (empty ( $verifyStaff )) {
  3756. $verifyList [$k] ['date'] = "";
  3757. $verifyList [$k] ['opinion'] = "";
  3758. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3759. $verifyList [$k] ['status'] = 4;
  3760. $flag = false;
  3761. }
  3762. } else {
  3763. foreach ( $verifyStaff as $m => $u ) {
  3764. if ($v [0] == $m) {
  3765. $verifyList [$k] ['date'] = $u ['date'];
  3766. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3767. $verifyList [$k] ['status'] = $u ['status'];
  3768. $flag = false;
  3769. break;
  3770. }
  3771. }
  3772. $endStaffArray = end ( $verifyStaff );
  3773. if (isset ( $endStaffArray ['ROLE'] )) {
  3774. } else {
  3775. // $endKey=key($verifyStaff);
  3776. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3777. // $button=4;
  3778. // $verifyList[$k]['status']=4;
  3779. // }
  3780. }
  3781. }
  3782. }
  3783. $rolename ['name'] = '';
  3784. if (! empty ( $roleId )) {
  3785. Doo::loadModel ( 'role' );
  3786. $role = new role ();
  3787. $rolename = $role->getOne ( array (
  3788. 'where' => 'rid=' . $roleId,
  3789. 'asArray' => true
  3790. ) );
  3791. }
  3792. if (! empty ( $verifyStaff ))
  3793. $endStaffArray = end ( $verifyStaff );
  3794. $KOP = false;
  3795. foreach ( $roleArrayCopy as $P => $A ) {
  3796. foreach ( $A as $MKI => $AVL ) {
  3797. if (! empty ( $verifyStaff )) {
  3798. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3799. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3800. $button = 4;
  3801. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3802. }
  3803. foreach ( $verifyStaff as $m => $u ) {
  3804. $AVLFK = $AVL [0] . '_R';
  3805. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3806. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3807. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3808. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3809. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3810. break;
  3811. }
  3812. }
  3813. } else {
  3814. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3815. $button = 4;
  3816. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3817. }
  3818. }
  3819. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3820. $KOP = true;
  3821. }
  3822. }
  3823. foreach ( $roleArrayCopy as $k => $v ) {
  3824. foreach ( $verifyList as $m => $n ) {
  3825. if ($n [0] == $k) {
  3826. array_splice ( $verifyList, $m, 1, $v );
  3827. }
  3828. }
  3829. }
  3830. $loanList [$key] ['verifyList'] = $verifyList;
  3831. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3832. 'where' => 'sid=' . $value ['staff'],
  3833. 'asArray' => true
  3834. ) );
  3835. $loanList [$key] ['button'] = $button;
  3836. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3837. }
  3838. $data ['loanList'] = $loanList;
  3839. //print_r($loanList);
  3840. $Locate = 0;
  3841. $roleId = 0;
  3842. $button = 0;
  3843. foreach ( $receiptList as $key => $value ) {
  3844. $receiptList [$key] ['Locate'] = $Locate;
  3845. $Locate ++;
  3846. $receiptList [$key] ['reviseDetail'] = array ();
  3847. if (! empty ( $value ['reviseDetail'] ))
  3848. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3849. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3850. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3851. $categoryDetil = $Lcategory->getOne ( array (
  3852. 'where' => 'cid=' . $value ['cid'],
  3853. 'asArray' => true
  3854. ) );
  3855. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3856. // 检测编辑状态
  3857. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3858. $verifyList ['staff'] = $value ['verifyBreakup'];
  3859. } else
  3860. $verifyList = $verify->getOne ( array (
  3861. 'where' => 'vid=' . $value ['verify'],
  3862. 'asArray' => true
  3863. ) );
  3864. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3865. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3866. Doo::loadModel ( 'role' );
  3867. $role = new role ();
  3868. if ($verifyList == NULL)
  3869. $verifyList = array ();
  3870. $flag = true;
  3871. $roleKey = 0;
  3872. $endStaffArray = array ();
  3873. $roleArrayCopy = array ();
  3874. foreach ( $verifyList as $k => $v ) {
  3875. // init verifyStaff
  3876. if ($v [1] == 'ROLE') {
  3877. if (! empty ( $verifyStaff )) {
  3878. $endStaffArray = end ( $verifyStaff );
  3879. // if ($v[0]==$endStaffArray['nextStaff']){
  3880. // $roleId=$v[0];
  3881. // }
  3882. }
  3883. $roleVerify = json_decode ( $v [3], true );
  3884. $roleKey = $k;
  3885. $roleArray = array ();
  3886. $rolename = $role->getOne ( array (
  3887. 'where' => 'rid=' . $v [0],
  3888. 'asArray' => true
  3889. ) );
  3890. foreach ( $roleVerify as $o => $p ) {
  3891. $staffID = explode ( '_', $p );
  3892. $staffInfo = $staff->getOne ( array (
  3893. 'where' => 'sid=' . $staffID [0],
  3894. 'asArray' => true
  3895. ) );
  3896. // print_r($staffID);
  3897. $exp = array (
  3898. 0 => $staffInfo ['sid'],
  3899. 1 => $staffID [1],
  3900. 2 => $staffInfo ['avatar'],
  3901. 'date' => '',
  3902. 'date' => '',
  3903. 'opinion' => '',
  3904. 'status' => '',
  3905. 'rolename' => $rolename ['name']
  3906. );
  3907. array_push ( $roleArray, $exp );
  3908. }
  3909. $roleArrayCopy [$v [0]] = $roleArray;
  3910. // $verifyList[$k]['roleArray']=$roleArray;
  3911. }
  3912. $verifyList [$k] ['date'] = "";
  3913. $verifyList [$k] ['opinion'] = "";
  3914. $verifyList [$k] ['status'] = "";
  3915. if (empty ( $verifyStaff )) {
  3916. $verifyList [$k] ['date'] = "";
  3917. $verifyList [$k] ['opinion'] = "";
  3918. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3919. $verifyList [$k] ['status'] = 4;
  3920. $flag = false;
  3921. }
  3922. } else {
  3923. foreach ( $verifyStaff as $m => $u ) {
  3924. if ($v [0] == $m) {
  3925. $verifyList [$k] ['date'] = $u ['date'];
  3926. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3927. $verifyList [$k] ['status'] = $u ['status'];
  3928. $flag = false;
  3929. break;
  3930. }
  3931. }
  3932. $endStaffArray = end ( $verifyStaff );
  3933. if (isset ( $endStaffArray ['ROLE'] )) {
  3934. } else {
  3935. // $endKey=key($verifyStaff);
  3936. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3937. // $button=4;
  3938. // $verifyList[$k]['status']=4;
  3939. // }
  3940. }
  3941. }
  3942. }
  3943. $FC = @$rolename ['name'];
  3944. $rolename ['name'] = '';
  3945. if (! empty ( $roleId )) {
  3946. Doo::loadModel ( 'role' );
  3947. $role = new role ();
  3948. $rolename = $role->getOne ( array (
  3949. 'where' => 'rid=' . $roleId,
  3950. 'asArray' => true
  3951. ) );
  3952. }
  3953. if (! empty ( $verifyStaff ))
  3954. $endStaffArray = end ( $verifyStaff );
  3955. $KOP = false;
  3956. foreach ( $roleArrayCopy as $P => $A ) {
  3957. foreach ( $A as $MKI => $AVL ) {
  3958. if (! empty ( $verifyStaff )) {
  3959. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3960. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3961. $button = 4;
  3962. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3963. }
  3964. foreach ( $verifyStaff as $m => $u ) {
  3965. $AVLFK = $AVL [0] . '_R';
  3966. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3967. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3968. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3969. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3970. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3971. break;
  3972. }
  3973. }
  3974. } else {
  3975. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3976. $button = 4;
  3977. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3978. }
  3979. }
  3980. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3981. $KOP = true;
  3982. }
  3983. }
  3984. foreach ( $roleArrayCopy as $k => $v ) {
  3985. foreach ( $verifyList as $m => $n ) {
  3986. if ($n [0] == $k) {
  3987. array_splice ( $verifyList, $m, 1, $v );
  3988. }
  3989. }
  3990. }
  3991. // 费用执行人相关数据
  3992. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3993. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3994. foreach ( $executeCopy as $k => $v ) {
  3995. $executeCopy [$k] ['date'] = '';
  3996. $executeCopy [$k] ['opinion'] = '';
  3997. $executeCopy [$k] ['status'] = '';
  3998. if (! empty ( $executeStaff ))
  3999. foreach ( $executeStaff as $m => $u ) {
  4000. if ($v [0] == $m) {
  4001. $executeCopy [$k] ['date'] = $u ['date'];
  4002. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4003. $executeCopy [$k] ['status'] = $u ['status'];
  4004. break;
  4005. }
  4006. }
  4007. }
  4008. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4009. // print_r($verifyList);
  4010. $receiptList [$key] ['verifyList'] = $verifyList;
  4011. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4012. 'where' => 'sid=' . $value ['staff'],
  4013. 'asArray' => true
  4014. ) );
  4015. $receiptList [$key] ['button'] = $button;
  4016. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4017. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4018. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4019. $receiptList [$key] ['relust'] = $relust;
  4020. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4021. }
  4022. // print_r($receiptList);
  4023. // 获取审批日志
  4024. Doo::loadModel ( 'receiptLog' );
  4025. $receiptLog = new receiptLog ();
  4026. $rlList = array ();
  4027. $rlInfo = $receiptLog->getOne ( array (
  4028. 'where' => 'rid=' . $rid . ' and status=4',
  4029. 'asArray' => true
  4030. ) );
  4031. // $tijdate = $receiptLog->getOne ( array (
  4032. // 'where' => 'rid=' . $rid . ' and status=2',
  4033. // 'asc' => 'rlid',
  4034. // 'asArray' => true
  4035. // ) );
  4036. if (! empty ( $rlInfo )) {
  4037. $rlList = $receiptLog->find ( array (
  4038. 'where' => 'rid=' . $rid,
  4039. 'asc' => 'rlid',
  4040. 'asArray' => true
  4041. ) );
  4042. }
  4043. $RN=array();
  4044. if (!empty( $rolename ['staff'])){
  4045. $RN = @json_decode ( $rolename ['staff'] );
  4046. }
  4047. //
  4048. foreach ( $rlList as $key => $value ) {
  4049. $rlList [$key] ['rolename'] = '';
  4050. foreach ( $RN as $k => $v ) {
  4051. $id = explode ( "_", $v );
  4052. if ($id [0] == $value ['uid']) {
  4053. $rlList [$key] ['rolename'] = $FC;
  4054. break;
  4055. }
  4056. }
  4057. }
  4058. Doo::loadModel ( 'enclosur' );
  4059. $enclosur = new enclosur ();
  4060. $enclosurList = $enclosur->find ( array (
  4061. 'where' => 'rid=' . $rid,
  4062. 'asArray' => true
  4063. ) );
  4064. $enclosurHtml = '';
  4065. foreach ( $enclosurList as $value ) {
  4066. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4067. }
  4068. $data ['enclosurHtml'] = $enclosurHtml;
  4069. $receiptList [0] ['rlList'] = $rlList;
  4070. $data ['receiptList'] = $receiptList;
  4071. // print_r($receiptList);
  4072. $data ['memu'] = "receipt";
  4073. $data ['staff'] = $this->staff;
  4074. $data ['receiptMemu'] = 'approvalExpenses';
  4075. $data ['verifyId'] = $this->verifyId;
  4076. $data ['executeId'] = $this->executeId;
  4077. $this->render ( "/admin/expensesDoc", $data );
  4078. }
  4079. function expensesEdi() {
  4080. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4081. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4082. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4083. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4084. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4085. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4086. if (empty ( $status ))
  4087. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4088. $vidList = array ();
  4089. $button = 0;
  4090. Doo::loadModel ( 'verify' );
  4091. Doo::loadModel ( 'receipt' );
  4092. Doo::loadModel ( 'staff' );
  4093. $staff = new staff ();
  4094. $receipt = new receipt ();
  4095. $verify = new verify ();
  4096. Doo::loadModel ( 'L_category' );
  4097. $Lcategory = new L_category ();
  4098. Doo::loadModel ( 'enclosur' );
  4099. $enclosur = new enclosur ();
  4100. // user verify ID
  4101. $verifyDetail = $verify->find ( array (
  4102. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4103. 'asArray' => true
  4104. ) );
  4105. foreach ( $verifyDetail as $key => $value ) {
  4106. array_push ( $vidList, $value ['vid'] );
  4107. }
  4108. $vid = implode ( ",", $vidList );
  4109. if (empty ( $verifyDetail ))
  4110. $vid = 0;
  4111. $categoryList = $Lcategory->find ( array (
  4112. 'asArray' => true
  4113. ) );
  4114. $staffList = $staff->find ( array (
  4115. 'where' => 'cid=' . $cid,
  4116. 'asArray' => true
  4117. ) );
  4118. $ap = "";
  4119. if ($status == 4) {
  4120. $ap = 4;
  4121. $status = 2;
  4122. }
  4123. // get Receipt By verifyID status 2
  4124. $receiptList = $receipt->find ( array (
  4125. 'where' => 'rid =' . $rid . ' and status=2',
  4126. 'desc' => 'rid',
  4127. 'asArray' => true
  4128. ) );
  4129. if (empty ( $receiptList )) {
  4130. die ( 'illegal request' );
  4131. }
  4132. $Locate = 0;
  4133. $roleId = 0;
  4134. if ($ap == 4)
  4135. $status = 4;
  4136. foreach ( $receiptList as $key => $value ) {
  4137. $receiptList [$key] ['Locate'] = $Locate;
  4138. $Locate ++;
  4139. $receiptList [$key] ['reviseDetail'] = array ();
  4140. if (! empty ( $value ['reviseDetail'] ))
  4141. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4142. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4143. $categoryDetil = $Lcategory->getOne ( array (
  4144. 'where' => 'cid=' . $value ['cid'],
  4145. 'asArray' => true
  4146. ) );
  4147. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4148. // 检测编辑状态
  4149. $verifyList = $verify->getOne ( array (
  4150. 'where' => 'vid=' . $value ['verify'],
  4151. 'asArray' => true
  4152. ) );
  4153. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4154. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4155. Doo::loadModel ( 'role' );
  4156. $role = new role ();
  4157. // print_r($verifyList);
  4158. $flag = true;
  4159. $roleKey = 0;
  4160. $endStaffArray = array ();
  4161. $roleArrayCopy = array ();
  4162. foreach ( $verifyList as $k => $v ) {
  4163. // init verifyStaff
  4164. if ($v [1] == 'ROLE') {
  4165. if (! empty ( $verifyStaff )) {
  4166. $endStaffArray = end ( $verifyStaff );
  4167. if ($v [0] == $endStaffArray ['nextStaff']) {
  4168. $roleId = $v [0];
  4169. }
  4170. }
  4171. $roleVerify = json_decode ( $v [3], true );
  4172. $roleKey = $k;
  4173. $roleArray = array ();
  4174. $rolename = $role->getOne ( array (
  4175. 'where' => 'rid=' . $v [0],
  4176. 'asArray' => true
  4177. ) );
  4178. foreach ( $roleVerify as $o => $p ) {
  4179. $staffID = explode ( '_', $p );
  4180. $staffInfo = $staff->getOne ( array (
  4181. 'where' => 'sid=' . $staffID [0],
  4182. 'asArray' => true
  4183. ) );
  4184. // print_r($staffID);
  4185. $exp = array (
  4186. 0 => $staffInfo ['sid'],
  4187. 1 => $staffID [1],
  4188. 2 => $staffInfo ['avatar'],
  4189. 'date' => '',
  4190. 'date' => '',
  4191. 'opinion' => '',
  4192. 'status' => '',
  4193. 'rolename' => $rolename ['name']
  4194. );
  4195. array_push ( $roleArray, $exp );
  4196. }
  4197. $roleArrayCopy [$v [0]] = $roleArray;
  4198. // $verifyList[$k]['roleArray']=$roleArray;
  4199. }
  4200. // print_r($roleArray);
  4201. $verifyList [$k] ['date'] = "";
  4202. $verifyList [$k] ['opinion'] = "";
  4203. $verifyList [$k] ['status'] = "";
  4204. if (empty ( $verifyStaff )) {
  4205. $verifyList [$k] ['date'] = "";
  4206. $verifyList [$k] ['opinion'] = "";
  4207. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4208. $verifyList [$k] ['status'] = 4;
  4209. $button = 4;
  4210. $flag = false;
  4211. }
  4212. } else {
  4213. foreach ( $verifyStaff as $m => $u ) {
  4214. if ($v [0] == $m) {
  4215. $verifyList [$k] ['date'] = $u ['date'];
  4216. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4217. $verifyList [$k] ['status'] = $u ['status'];
  4218. $flag = false;
  4219. break;
  4220. }
  4221. }
  4222. $endStaffArray = end ( $verifyStaff );
  4223. if (isset ( $endStaffArray ['ROLE'] )) {
  4224. } else {
  4225. $endKey = key ( $verifyStaff );
  4226. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4227. $button = 4;
  4228. $verifyList [$k] ['status'] = 4;
  4229. }
  4230. }
  4231. }
  4232. }
  4233. $rolename ['name'] = '';
  4234. if (! empty ( $roleId )) {
  4235. Doo::loadModel ( 'role' );
  4236. $role = new role ();
  4237. $rolename = $role->getOne ( array (
  4238. 'where' => 'rid=' . $roleId,
  4239. 'asArray' => true
  4240. ) );
  4241. }
  4242. if (! empty ( $verifyStaff ))
  4243. $endStaffArray = end ( $verifyStaff );
  4244. $KOP = false;
  4245. foreach ( $roleArrayCopy as $P => $A ) {
  4246. foreach ( $A as $MKI => $AVL ) {
  4247. if (! empty ( $verifyStaff )) {
  4248. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4249. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4250. $button = 4;
  4251. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4252. }
  4253. foreach ( $verifyStaff as $m => $u ) {
  4254. $AVLFK = $AVL [0] . '_R';
  4255. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4256. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4257. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4258. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4259. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4260. break;
  4261. }
  4262. }
  4263. } else {
  4264. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4265. $button = 4;
  4266. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4267. }
  4268. }
  4269. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4270. $KOP = true;
  4271. }
  4272. }
  4273. // print_r($roleArrayCopy);
  4274. // echo $roleKey;
  4275. foreach ( $roleArrayCopy as $k => $v ) {
  4276. foreach ( $verifyList as $m => $n ) {
  4277. if ($n [0] == $k) {
  4278. array_splice ( $verifyList, $m, 1, $v );
  4279. }
  4280. }
  4281. }
  4282. $receiptList [$key] ['verifyList'] = $verifyList;
  4283. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4284. 'where' => 'sid=' . $value ['staff'],
  4285. 'asArray' => true
  4286. ) );
  4287. $receiptList [$key] ['button'] = $button;
  4288. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4289. }
  4290. // $data['verifyDetail']=$verifyDetail;
  4291. $mothHtml = "";
  4292. for($i = 1; $i <= 12; $i ++) {
  4293. if ($month == $i)
  4294. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4295. else
  4296. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4297. }
  4298. // 获取审批日志
  4299. Doo::loadModel ( 'receiptLog' );
  4300. $receiptLog = new receiptLog ();
  4301. $rlList = array ();
  4302. $rlInfo = $receiptLog->getOne ( array (
  4303. 'where' => 'rid=' . $rid . ' and status=4',
  4304. 'asArray' => true
  4305. ) );
  4306. $tijdate = $receiptLog->getOne ( array (
  4307. 'where' => 'rid=' . $rid . ' and status=2',
  4308. 'asc' => 'rlid',
  4309. 'asArray' => true
  4310. ) );
  4311. if (! empty ( $rlInfo )) {
  4312. $rlList = $receiptLog->find ( array (
  4313. 'where' => 'rid=' . $rid,
  4314. 'asc' => 'rlid',
  4315. 'asArray' => true
  4316. ) );
  4317. }
  4318. $receiptList [0] ['rlList'] = $rlList;
  4319. $enclosurList = $enclosur->find ( array (
  4320. 'where' => 'rid=' . $rid,
  4321. 'asArray' => true
  4322. ) );
  4323. $enclosurHtml = '';
  4324. foreach ( $enclosurList as $value ) {
  4325. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4326. }
  4327. // print_r($receiptList);
  4328. $data ['rid'] = $rid;
  4329. $data ['enclosurHtml'] = $enclosurHtml;
  4330. $data ['rolename'] = $rolename ['name'];
  4331. $data ['datetij'] = $tijdate ['date'];
  4332. $data ['mothHtml'] = $mothHtml;
  4333. $data ['receiptList'] = $receiptList;
  4334. $data ['receiptApprovalCount'] = count ( $receiptList );
  4335. $data ['status'] = $status;
  4336. $data ['year'] = $year;
  4337. $data ['categoryList'] = $categoryList;
  4338. $data ['staffList'] = $staffList;
  4339. $data ['cid'] = $cid;
  4340. $data ['sid'] = $sid;
  4341. $data ['ap'] = $ap;
  4342. $data ['memu'] = "receipt";
  4343. $data ['staff'] = $this->staff;
  4344. $data ['receiptMemu'] = 'approvalExpenses';
  4345. $data ['verifyId'] = $this->verifyId;
  4346. $data ['executeId'] = $this->executeId;
  4347. $this->render ( "/admin/expensesEdi", $data );
  4348. }
  4349. function expensesDefray() {
  4350. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4351. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4352. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4353. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4354. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4355. if (! empty ( $rid )) {
  4356. Doo::loadModel ( "verify" );
  4357. $verify = new verify ();
  4358. Doo::loadModel ( "receiptDetail" );
  4359. $receiptDetailObj = new receiptDetail ();
  4360. Doo::loadModel ( "itemStatistics" );
  4361. Doo::loadModel ( "statistics" );
  4362. $statistics = new statistics ();
  4363. $itemStatistics = new itemStatistics ();
  4364. Doo::loadModel ( "receipt" );
  4365. $receipt = new receipt ();
  4366. Doo::loadModel ( "loanReceipt" );
  4367. $loanReceipt = new loanReceipt ();
  4368. $receiptDetail = $receipt->getOne ( array (
  4369. 'where' => 'rid=' . $rid . ' and status=2 ',
  4370. 'asArray' => true
  4371. ) );
  4372. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4373. $nsflag = true;
  4374. foreach ( $nslist as $value ) {
  4375. if ($value == $this->staff ['0'] ['sid']) {
  4376. $nsflag = false;
  4377. break;
  4378. }
  4379. }
  4380. // print_r($nslist);die;
  4381. if (empty ( $receiptDetail ) || $nsflag)
  4382. return "/approvalExpenses/pendApproval";
  4383. $verifyDetail = $verify->getOne ( array (
  4384. 'where' => ' vid =' . $receiptDetail ['verify'],
  4385. 'asArray' => true
  4386. ) );
  4387. $verifyString = $verifyDetail ['staff'];
  4388. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4389. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4390. if (empty ( $opinion )) {
  4391. if ($status == 3)
  4392. $opinion = "终止";
  4393. else
  4394. $opinion = "同意支付";
  4395. }
  4396. $nowStaff = 0;
  4397. $nowStaffList = array ();
  4398. if (empty ( $verifyStaff )) {
  4399. // 还需加入是否已经进入角色审批
  4400. if ($verifyDetail [0] [1] == 'ROLE') {
  4401. // print_r($verifyDetail);echo "ddd";
  4402. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4403. foreach ( $vStaffString as $key => $value ) {
  4404. $staffK = explode ( "_", $value );
  4405. if ($staffK [0] != $this->staff [0] ['sid'])
  4406. array_push ( $nowStaffList, $staffK [0] );
  4407. }
  4408. // print_r($verifyDetail);
  4409. // die;
  4410. if (! empty ( $nowStaffList )) {
  4411. $nowStaff = implode ( ',', $nowStaffList );
  4412. $verifyStaff = array (
  4413. $this->staff [0] ['sid'] . "_R" => array (
  4414. 'date' => date ( 'Y-m-d' ),
  4415. 'opinion' => $opinion,
  4416. 'status' => $status,
  4417. 'nextStaff' => $verifyDetail [0] [0],
  4418. 'ROLE' => 1
  4419. )
  4420. );
  4421. } else {
  4422. $nowStaff = $verifyDetail [1] [0];
  4423. $verifyStaff = array (
  4424. $this->staff [0] ['sid'] . "_R" => array (
  4425. 'date' => date ( 'Y-m-d' ),
  4426. 'opinion' => $opinion,
  4427. 'status' => $status,
  4428. 'nextStaff' => $verifyDetail [1] [0]
  4429. )
  4430. );
  4431. }
  4432. } else {
  4433. if ($verifyDetail [1] [1] == 'ROLE') {
  4434. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4435. // echo "dd";
  4436. foreach ( $vStaffString as $key => $value ) {
  4437. $staffK = explode ( "_", $value );
  4438. array_push ( $nowStaffList, $staffK [0] );
  4439. }
  4440. $nowStaff = implode ( ',', $nowStaffList );
  4441. $verifyStaff = array (
  4442. $this->staff [0] ['sid'] => array (
  4443. 'date' => date ( 'Y-m-d' ),
  4444. 'opinion' => $opinion,
  4445. 'status' => $status,
  4446. 'nextStaff' => $verifyDetail [1] [0],
  4447. 'ROLE' => 1
  4448. )
  4449. );
  4450. } else {
  4451. $nowStaff = $verifyDetail [1] [0];
  4452. $verifyStaff = array (
  4453. $this->staff [0] ['sid'] => array (
  4454. 'date' => date ( 'Y-m-d' ),
  4455. 'opinion' => $opinion,
  4456. 'status' => $status,
  4457. 'nextStaff' => $verifyDetail [1] [0]
  4458. )
  4459. );
  4460. }
  4461. }
  4462. if ($status == 3)
  4463. $verifyStaff = array (
  4464. 'final' => $status,
  4465. $this->staff [0] ['sid'] => array (
  4466. 'date' => date ( 'Y-m-d' ),
  4467. 'opinion' => $opinion,
  4468. 'status' => $status
  4469. )
  4470. );
  4471. $vStaffString = json_encode ( $verifyStaff );
  4472. $receipt->nowStaff = $nowStaff;
  4473. $receipt->verifyStaff = $vStaffString;
  4474. $loanReceipt->nowStaff = $nowStaff;
  4475. $loanReceipt->verifyStaff = $vStaffString;
  4476. } else {
  4477. $VS = end ( $verifyStaff );
  4478. // 非角色审批
  4479. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4480. $nextStaff = 0;
  4481. $roleSTF = false;
  4482. foreach ( $verifyDetail as $key => $value ) {
  4483. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4484. if (isset ( $verifyDetail [$key + 1] )) {
  4485. $nextStaff = $verifyDetail [$key + 1] [0];
  4486. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4487. $roleSTF = true;
  4488. }
  4489. break;
  4490. }
  4491. }
  4492. if (! $roleSTF) {
  4493. $nowStaff = $nextStaff;
  4494. $verifyStaff [$this->staff [0] ['sid']] = array (
  4495. 'date' => date ( 'Y-m-d' ),
  4496. 'opinion' => $opinion,
  4497. 'status' => $status,
  4498. 'nextStaff' => $nextStaff
  4499. );
  4500. } else {
  4501. // 获取角色下的所有用户ID
  4502. $nowStaffList = array ();
  4503. foreach ( $verifyDetail as $vfk ) {
  4504. if ($vfk [1] == 'ROLE') {
  4505. $vStaffString = json_decode ( $vfk [3] );
  4506. foreach ( $vStaffString as $key => $value ) {
  4507. $staffK = explode ( "_", $value );
  4508. array_push ( $nowStaffList, $staffK [0] );
  4509. }
  4510. }
  4511. }
  4512. $nowStaff = implode ( ',', $nowStaffList );
  4513. $verifyStaff [$this->staff [0] ['sid']] = array (
  4514. 'date' => date ( 'Y-m-d' ),
  4515. 'opinion' => $opinion,
  4516. 'status' => $status,
  4517. 'nextStaff' => $nextStaff,
  4518. 'ROLE' => 0
  4519. );
  4520. }
  4521. if ($status == 3) {
  4522. $verifyStaff ['final'] = $status;
  4523. $verifyStaff [$this->staff [0] ['sid']] = array (
  4524. 'date' => date ( 'Y-m-d' ),
  4525. 'opinion' => $opinion,
  4526. 'status' => $status
  4527. );
  4528. }
  4529. $vStaffString = json_encode ( $verifyStaff );
  4530. $receipt->nowStaff = $nowStaff;
  4531. $receipt->verifyStaff = $vStaffString;
  4532. $loanReceipt->nowStaff = $nowStaff;
  4533. $loanReceipt->verifyStaff = $vStaffString;
  4534. }
  4535. // 角色审批
  4536. if (isset ( $VS ['ROLE'] )) {
  4537. // 找出角色人 当前审批角色组
  4538. $verifyJSStaff = array ();
  4539. $nowStaffList2 = array ();
  4540. foreach ( $verifyDetail as $key => $value ) {
  4541. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4542. $verifyJSStaff = json_decode ( $value [3] );
  4543. foreach ( $verifyJSStaff as $m ) {
  4544. $staffK = explode ( "_", $m );
  4545. array_push ( $nowStaffList2, $staffK [0] );
  4546. }
  4547. // print_r($nowStaffList2);
  4548. }
  4549. }
  4550. $RoleVerifyStaff = array ();
  4551. foreach ( $verifyStaff as $key => $value ) {
  4552. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4553. foreach ( $nowStaffList2 as $m ) {
  4554. if ($key == $m . "_R")
  4555. $RoleVerifyStaff [$key] = $value;
  4556. }
  4557. }
  4558. }
  4559. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4560. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4561. // 下一个审批人ID
  4562. $nextStaff = 0;
  4563. $falg = false;
  4564. foreach ( $verifyDetail as $key => $value ) {
  4565. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4566. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4567. $falg = true;
  4568. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4569. $nowStaffList = array ();
  4570. foreach ( $vStaffString as $v ) {
  4571. $staffK = explode ( "_", $v );
  4572. array_push ( $nowStaffList, $staffK [0] );
  4573. }
  4574. $nowStaff = implode ( ',', $nowStaffList );
  4575. $nextStaff = $verifyDetail [$key + 1] [0];
  4576. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4577. $nextStaff = $verifyDetail [$key + 1] [0];
  4578. $nowStaff = $nextStaff;
  4579. } else
  4580. $nowStaff = '';
  4581. break;
  4582. }
  4583. }
  4584. if ($falg)
  4585. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4586. 'date' => date ( 'Y-m-d' ),
  4587. 'opinion' => $opinion,
  4588. 'status' => $status,
  4589. 'nextStaff' => $nextStaff,
  4590. 'ROLE' => 1
  4591. );
  4592. else
  4593. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4594. 'date' => date ( 'Y-m-d' ),
  4595. 'opinion' => $opinion,
  4596. 'status' => $status,
  4597. 'nextStaff' => $nextStaff
  4598. );
  4599. // print_r($verifyStaff);
  4600. // echo $nowStaff;die;
  4601. } else { // 进入下一个角色或者审批人
  4602. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  4603. //
  4604. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4605. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4606. 'date' => date ( 'Y-m-d' ),
  4607. 'opinion' => $opinion,
  4608. 'status' => $status,
  4609. 'nextStaff' => $VS ['nextStaff'],
  4610. 'ROLE' => 1
  4611. );
  4612. // print_r($verifyStaff);
  4613. // die;
  4614. }
  4615. if ($status == 3) {
  4616. $verifyStaff ['final'] = $status;
  4617. $verifyStaff [$this->staff [0] ['sid']] = array (
  4618. 'date' => date ( 'Y-m-d' ),
  4619. 'opinion' => $opinion,
  4620. 'status' => $status
  4621. );
  4622. }
  4623. $vStaffString = json_encode ( $verifyStaff );
  4624. $receipt->verifyStaff = $vStaffString;
  4625. $receipt->nowStaff = $nowStaff;
  4626. $loanReceipt->nowStaff = $nowStaff;
  4627. $loanReceipt->verifyStaff = $vStaffString;
  4628. // die;
  4629. // }
  4630. // print_r($verifyStaff);
  4631. // die;
  4632. }
  4633. // print_r($verifyStaff);die;
  4634. }
  4635. // print_r($verifyDetail);
  4636. $roleKey = 0;
  4637. $roleId = 0;
  4638. $verifyDetailCopy = array ();
  4639. foreach ( $verifyDetail as $k => $v ) {
  4640. if ($v [1] == 'ROLE') {
  4641. $roleId = $v [0];
  4642. $roleVerify = json_decode ( $v [3], true );
  4643. $roleKey = $k;
  4644. $roleArray = array ();
  4645. foreach ( $roleVerify as $o => $p ) {
  4646. $staffID = explode ( '_', $p );
  4647. $exp = array (
  4648. 0 => $staffID [0],
  4649. 1 => $staffID [1]
  4650. );
  4651. array_push ( $roleArray, $exp );
  4652. }
  4653. $verifyDetailCopy [$v [0]] = $roleArray;
  4654. }
  4655. }
  4656. // print_r($verifyDetail);
  4657. foreach ( $verifyDetailCopy as $k => $v ) {
  4658. foreach ( $verifyDetail as $m => $n ) {
  4659. if ($n [0] == $k) {
  4660. array_splice ( $verifyDetail, $m, 1, $v );
  4661. }
  4662. }
  4663. }
  4664. // 审批日志
  4665. if (! isset ( $verifyStaff ['final'] )) {
  4666. Doo::loadModel ( "receiptLog" );
  4667. $receiptLog = new receiptLog ();
  4668. if (! empty ( $roleId )) {
  4669. Doo::loadModel ( "role" );
  4670. $role = new role ();
  4671. $roleInfo = $role->getOne ( array (
  4672. 'where' => 'rid=' . $roleId,
  4673. 'asArray' => true
  4674. ) );
  4675. $receiptLog->rolename = $roleInfo ['name'];
  4676. }
  4677. $receiptLog->username = $this->staff [0] ['username'];
  4678. $receiptLog->uid = $this->staff [0] ['sid'];
  4679. $receiptLog->date = date ( "Y-m-d" );
  4680. $receiptLog->opinion = $opinion;
  4681. $receiptLog->img = $this->staff [0] ['avatar'];
  4682. $receiptLog->status = 1;
  4683. $receiptLog->rid = $rid;
  4684. $receiptLog->insert ();
  4685. }
  4686. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4687. $receipt->status = 3;
  4688. $receipt->verifyBreakup = $verifyString;
  4689. $receiptDetailObj->status = 3;
  4690. $receiptDetailObj->update ( array (
  4691. 'where' => 'rid=' . $rid
  4692. ) );
  4693. // 微信企业号通知
  4694. $this->setWXMsg ( $rid, 3 );
  4695. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4696. $receipt->status = 6;
  4697. $receipt->pastDate = date ( "Y-m-d" );
  4698. $receipt->isBK = 1;
  4699. $loanReceipt->verifyBreakup = $verifyString;
  4700. $loanReceipt->status = 1;
  4701. $loanReceipt->pastDate = date ( "Y-m-d" );
  4702. //生成流水后 不更新汇款金额
  4703. Doo::loadModel ( 'wasteBook' );
  4704. $wasteBook = new wasteBook ();
  4705. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4706. if (empty($wbDetail)){
  4707. $loanReceipt->amount = $receiptDetail ['amount'];
  4708. }
  4709. $loanReceipt->update ( array (
  4710. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4711. ) );
  4712. // 微信企业号通知
  4713. $this->setWXMsg ( $rid, 1 );
  4714. }
  4715. $receipt->amount = $amount;
  4716. $receipt->update ( array (
  4717. 'where' => ' rid = ' . $rid
  4718. ) );
  4719. // 进入下一条审批费用新加需求
  4720. $vidList = array ();
  4721. $verifyDetail = $verify->find ( array (
  4722. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4723. 'asArray' => true
  4724. ) );
  4725. foreach ( $verifyDetail as $key => $value ) {
  4726. array_push ( $vidList, $value ['vid'] );
  4727. }
  4728. $vid = implode ( ",", $vidList );
  4729. if (empty ( $verifyDetail ))
  4730. $vid = 0;
  4731. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4732. $receipt = new receipt ();
  4733. $rd = $receipt->getOne ( array (
  4734. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4735. 'asc' => 'rid',
  4736. 'asArray' => true
  4737. ) );
  4738. if (empty ( $rd )) {
  4739. return '/approvalExpenses/pendApproval';
  4740. }
  4741. if ($rd ['Rtype'] == 1) {
  4742. if ($rd ['isBK'] == 1) {
  4743. return '/receiptburEdi/' . $rd ['rid'];
  4744. } else {
  4745. return '/expensesEdi/' . $rd ['rid'];
  4746. }
  4747. } elseif ($rd ['Rtype'] == 2) {
  4748. return '/remitApproval/' . $rd ['rid'];
  4749. } else {
  4750. return '/receiptburEdi/' . $rd ['rid'];
  4751. }
  4752. // return "/approvalExpenses/pendApproval";
  4753. }
  4754. }
  4755. function ajaxExamineExe() {
  4756. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4757. Doo::loadModel ( 'receipt' );
  4758. $receipt = new receipt ();
  4759. Doo::loadClass ( 'XDeode' );
  4760. $XDeode = new XDeode ( 5 );
  4761. if (! empty ( $rid )) {
  4762. $rLRes = $receipt->find ( array (
  4763. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4764. 'asArray' => true
  4765. ) );
  4766. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4767. echo json_encode ( array (
  4768. 'status' => 1,
  4769. 'receipt' => $rLRes [0]
  4770. ) );
  4771. die ();
  4772. }
  4773. echo json_encode ( array (
  4774. 'status' => 0,
  4775. 'receipt' => array ()
  4776. ) );
  4777. die ();
  4778. }
  4779. function implement() {
  4780. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4781. Doo::loadClass ( 'XDeode' );
  4782. $XDeode = new XDeode ( 5 );
  4783. Doo::loadModel ( 'receipt' );
  4784. $receipt = new receipt ();
  4785. Doo::loadModel ( 'L_category' );
  4786. $Lcategory = new L_category ();
  4787. Doo::loadModel ( 'verify' );
  4788. $verify = new verify ();
  4789. Doo::loadModel ( 'staff' );
  4790. $staff = new staff ();
  4791. Doo::loadModel ( "execute" );
  4792. $execute = new execute ();
  4793. $rid = $XDeode->decode ( $rid );
  4794. $receiptList = $receipt->find ( array (
  4795. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4796. 'desc' => 'rid',
  4797. 'asArray' => true
  4798. ) );
  4799. Doo::loadModel ( 'loanReceipt' );
  4800. $loanReceipt = new loanReceipt ();
  4801. // print_r($receiptList);
  4802. $loanList = array ();
  4803. if (! isset ( $receiptList ))
  4804. $loanList = $loanReceipt->find ( array (
  4805. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4806. 'desc' => 'rid',
  4807. 'asArray' => true
  4808. ) );
  4809. $Locate = 0;
  4810. $roleId = 0;
  4811. $button = 0;
  4812. foreach ( $loanList as $key => $value ) {
  4813. $loanList [$key] ['Locate'] = $Locate;
  4814. $Locate ++;
  4815. $loanList [$key] ['reviseDetail'] = array ();
  4816. if (! empty ( $value ['reviseDetail'] ))
  4817. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4818. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4819. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4820. $categoryDetil = $Lcategory->getOne ( array (
  4821. 'where' => 'cid=' . $value ['cid'],
  4822. 'asArray' => true
  4823. ) );
  4824. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4825. // 检测编辑状态
  4826. $verifyList = $verify->getOne ( array (
  4827. 'where' => 'vid=' . $value ['verify'],
  4828. 'asArray' => true
  4829. ) );
  4830. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4831. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4832. Doo::loadModel ( 'role' );
  4833. $role = new role ();
  4834. $flag = true;
  4835. $roleKey = 0;
  4836. $endStaffArray = array ();
  4837. $roleArrayCopy = array ();
  4838. foreach ( $verifyList as $k => $v ) {
  4839. // init verifyStaff
  4840. if ($v [1] == 'ROLE') {
  4841. if (! empty ( $verifyStaff )) {
  4842. $endStaffArray = end ( $verifyStaff );
  4843. // if ($v[0]==$endStaffArray['nextStaff']){
  4844. // $roleId=$v[0];
  4845. // }
  4846. }
  4847. $roleVerify = json_decode ( $v [3], true );
  4848. $roleKey = $k;
  4849. $roleArray = array ();
  4850. $rolename = $role->getOne ( array (
  4851. 'where' => 'rid=' . $v [0],
  4852. 'asArray' => true
  4853. ) );
  4854. foreach ( $roleVerify as $o => $p ) {
  4855. $staffID = explode ( '_', $p );
  4856. $staffInfo = $staff->getOne ( array (
  4857. 'where' => 'sid=' . $staffID [0],
  4858. 'asArray' => true
  4859. ) );
  4860. // print_r($staffID);
  4861. $exp = array (
  4862. 0 => $staffInfo ['sid'],
  4863. 1 => $staffID [1],
  4864. 2 => $staffInfo ['avatar'],
  4865. 'date' => '',
  4866. 'date' => '',
  4867. 'opinion' => '',
  4868. 'status' => '',
  4869. 'rolename' => $rolename ['name']
  4870. );
  4871. array_push ( $roleArray, $exp );
  4872. }
  4873. $roleArrayCopy [$v [0]] = $roleArray;
  4874. // $verifyList[$k]['roleArray']=$roleArray;
  4875. }
  4876. $verifyList [$k] ['date'] = "";
  4877. $verifyList [$k] ['opinion'] = "";
  4878. $verifyList [$k] ['status'] = "";
  4879. if (empty ( $verifyStaff )) {
  4880. $verifyList [$k] ['date'] = "";
  4881. $verifyList [$k] ['opinion'] = "";
  4882. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4883. $verifyList [$k] ['status'] = 4;
  4884. $flag = false;
  4885. }
  4886. } else {
  4887. foreach ( $verifyStaff as $m => $u ) {
  4888. if ($v [0] == $m) {
  4889. $verifyList [$k] ['date'] = $u ['date'];
  4890. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4891. $verifyList [$k] ['status'] = $u ['status'];
  4892. $flag = false;
  4893. break;
  4894. }
  4895. }
  4896. $endStaffArray = end ( $verifyStaff );
  4897. if (isset ( $endStaffArray ['ROLE'] )) {
  4898. } else {
  4899. // $endKey=key($verifyStaff);
  4900. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4901. // $button=4;
  4902. // $verifyList[$k]['status']=4;
  4903. // }
  4904. }
  4905. }
  4906. }
  4907. $rolename ['name'] = '';
  4908. if (! empty ( $roleId )) {
  4909. Doo::loadModel ( 'role' );
  4910. $role = new role ();
  4911. $rolename = $role->getOne ( array (
  4912. 'where' => 'rid=' . $roleId,
  4913. 'asArray' => true
  4914. ) );
  4915. }
  4916. if (! empty ( $verifyStaff ))
  4917. $endStaffArray = end ( $verifyStaff );
  4918. $KOP = false;
  4919. foreach ( $roleArrayCopy as $P => $A ) {
  4920. foreach ( $A as $MKI => $AVL ) {
  4921. if (! empty ( $verifyStaff )) {
  4922. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4923. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4924. $button = 4;
  4925. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4926. }
  4927. foreach ( $verifyStaff as $m => $u ) {
  4928. $AVLFK = $AVL [0] . '_R';
  4929. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4930. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4931. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4932. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4933. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4934. break;
  4935. }
  4936. }
  4937. } else {
  4938. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4939. $button = 4;
  4940. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4941. }
  4942. }
  4943. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4944. $KOP = true;
  4945. }
  4946. }
  4947. foreach ( $roleArrayCopy as $k => $v ) {
  4948. foreach ( $verifyList as $m => $n ) {
  4949. if ($n [0] == $k) {
  4950. array_splice ( $verifyList, $m, 1, $v );
  4951. }
  4952. }
  4953. }
  4954. $loanList [$key] ['verifyList'] = $verifyList;
  4955. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4956. 'where' => 'sid=' . $value ['staff'],
  4957. 'asArray' => true
  4958. ) );
  4959. }
  4960. $data ['loanList'] = $loanList;
  4961. $Locate = 0;
  4962. $roleId = 0;
  4963. $button = 0;
  4964. Doo::loadClass ( 'XDeode' );
  4965. $XDeode = new XDeode ( 5 );
  4966. foreach ( $receiptList as $key => $value ) {
  4967. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4968. $button2 = 0;
  4969. $receiptList [$key] ['Locate'] = $Locate;
  4970. $Locate ++;
  4971. $receiptList [$key] ['reviseDetail'] = array ();
  4972. if (! empty ( $value ['reviseDetail'] ))
  4973. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4974. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4975. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4976. $categoryDetil = $Lcategory->getOne ( array (
  4977. 'where' => 'cid=' . $value ['cid'],
  4978. 'asArray' => true
  4979. ) );
  4980. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4981. $executeList = json_decode ( $value ['executeCopy'], true );
  4982. $executeStaff = array ();
  4983. if (! empty ( $value ['executeStaff'] ))
  4984. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4985. if (isset ( $executeList )) {
  4986. foreach ( $executeList as $op => $lo ) {
  4987. $executeList [$op] ['date'] = "";
  4988. $executeList [$op] ['opinion'] = "";
  4989. $executeList [$op] ['status'] = "";
  4990. foreach ( $executeStaff as $m => $u ) {
  4991. if ($lo [0] == $m) {
  4992. $executeList [$op] ['date'] = $u ['date'];
  4993. $executeList [$op] ['opinion'] = $u ['opinion'];
  4994. $executeList [$op] ['status'] = $u ['status'];
  4995. break;
  4996. }
  4997. }
  4998. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  4999. $button2 = 1;
  5000. $executeList [$op] ['status'] = 4;
  5001. }
  5002. }
  5003. }
  5004. // 检测编辑状态
  5005. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5006. $verifyList ['staff'] = $value ['verifyBreakup'];
  5007. } else
  5008. $verifyList = $verify->getOne ( array (
  5009. 'where' => 'vid=' . $value ['verify'],
  5010. 'asArray' => true
  5011. ) );
  5012. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5013. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5014. Doo::loadModel ( 'role' );
  5015. $role = new role ();
  5016. if ($verifyList == NULL)
  5017. $verifyList = array ();
  5018. $flag = true;
  5019. $roleKey = 0;
  5020. $endStaffArray = array ();
  5021. $roleArrayCopy = array ();
  5022. foreach ( $verifyList as $k => $v ) {
  5023. // init verifyStaff
  5024. if ($v [1] == 'ROLE') {
  5025. if (! empty ( $verifyStaff )) {
  5026. $endStaffArray = end ( $verifyStaff );
  5027. // if ($v[0]==$endStaffArray['nextStaff']){
  5028. // $roleId=$v[0];
  5029. // }
  5030. }
  5031. $roleVerify = json_decode ( $v [3], true );
  5032. $roleKey = $k;
  5033. $roleArray = array ();
  5034. $rolename = $role->getOne ( array (
  5035. 'where' => 'rid=' . $v [0],
  5036. 'asArray' => true
  5037. ) );
  5038. foreach ( $roleVerify as $o => $p ) {
  5039. $staffID = explode ( '_', $p );
  5040. $staffInfo = $staff->getOne ( array (
  5041. 'where' => 'sid=' . $staffID [0],
  5042. 'asArray' => true
  5043. ) );
  5044. // print_r($staffID);
  5045. $exp = array (
  5046. 0 => $staffInfo ['sid'],
  5047. 1 => $staffID [1],
  5048. 2 => $staffInfo ['avatar'],
  5049. 'date' => '',
  5050. 'date' => '',
  5051. 'opinion' => '',
  5052. 'status' => '',
  5053. 'rolename' => $rolename ['name']
  5054. );
  5055. array_push ( $roleArray, $exp );
  5056. }
  5057. $roleArrayCopy [$v [0]] = $roleArray;
  5058. // $verifyList[$k]['roleArray']=$roleArray;
  5059. }
  5060. $verifyList [$k] ['date'] = "";
  5061. $verifyList [$k] ['opinion'] = "";
  5062. $verifyList [$k] ['status'] = "";
  5063. if (empty ( $verifyStaff )) {
  5064. $verifyList [$k] ['date'] = "";
  5065. $verifyList [$k] ['opinion'] = "";
  5066. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5067. $verifyList [$k] ['status'] = 4;
  5068. $flag = false;
  5069. }
  5070. } else {
  5071. foreach ( $verifyStaff as $m => $u ) {
  5072. if ($v [0] == $m) {
  5073. $verifyList [$k] ['date'] = $u ['date'];
  5074. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5075. $verifyList [$k] ['status'] = $u ['status'];
  5076. $flag = false;
  5077. break;
  5078. }
  5079. }
  5080. $endStaffArray = end ( $verifyStaff );
  5081. if (isset ( $endStaffArray ['ROLE'] )) {
  5082. } else {
  5083. // $endKey=key($verifyStaff);
  5084. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5085. // $button=4;
  5086. // $verifyList[$k]['status']=4;
  5087. // }
  5088. }
  5089. }
  5090. }
  5091. $rolename ['name'] = '';
  5092. if (! empty ( $roleId )) {
  5093. Doo::loadModel ( 'role' );
  5094. $role = new role ();
  5095. $rolename = $role->getOne ( array (
  5096. 'where' => 'rid=' . $roleId,
  5097. 'asArray' => true
  5098. ) );
  5099. }
  5100. if (! empty ( $verifyStaff ))
  5101. $endStaffArray = end ( $verifyStaff );
  5102. $KOP = false;
  5103. foreach ( $roleArrayCopy as $P => $A ) {
  5104. foreach ( $A as $MKI => $AVL ) {
  5105. if (! empty ( $verifyStaff )) {
  5106. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5107. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5108. $button = 4;
  5109. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5110. }
  5111. foreach ( $verifyStaff as $m => $u ) {
  5112. $AVLFK = $AVL [0] . '_R';
  5113. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5114. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5115. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5116. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5117. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5118. break;
  5119. }
  5120. }
  5121. } else {
  5122. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5123. $button = 4;
  5124. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5125. }
  5126. }
  5127. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5128. $KOP = true;
  5129. }
  5130. }
  5131. foreach ( $roleArrayCopy as $k => $v ) {
  5132. foreach ( $verifyList as $m => $n ) {
  5133. if ($n [0] == $k) {
  5134. array_splice ( $verifyList, $m, 1, $v );
  5135. }
  5136. }
  5137. }
  5138. $receiptList [$key] ['verifyList'] = $verifyList;
  5139. $receiptList [$key] ['executeList'] = $executeList;
  5140. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5141. 'where' => 'sid=' . $value ['staff'],
  5142. 'asArray' => true
  5143. ) );
  5144. $receiptList [$key] ['button2'] = $button2;
  5145. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5146. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5147. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5148. $receiptList [$key] ['relust'] = $relust;
  5149. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5150. }
  5151. // 是否写入过流水
  5152. $accountType = 0;
  5153. if ($receiptList [0] ['Rtype'] == 0) {
  5154. $accountType = 3;
  5155. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5156. if (!empty($receiptList [0]['accountItem']) )
  5157. $accountType = 2;
  5158. else
  5159. $accountType = 1;
  5160. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5161. $accountType = 4;
  5162. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5163. $accountType = 12;
  5164. }
  5165. Doo::loadModel ( 'wasteBook' );
  5166. $wasteBook = new wasteBook ();
  5167. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5168. $data ['wbDetail'] = $wbDetail;
  5169. $wbDetailLoan=array();
  5170. if ($accountType==2){
  5171. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5172. }
  5173. $data ['wbDetailLoan'] = $wbDetailLoan;
  5174. //print_r($receiptList);
  5175. $data ['receiptList'] = $receiptList;
  5176. $data ['memu'] = "receipt";
  5177. $data ['staff'] = $this->staff;
  5178. $data ['receiptMemu'] = 'implement';
  5179. $data ['verifyId'] = $this->verifyId;
  5180. $data ['executeId'] = $this->executeId;
  5181. $this->render ( "/admin/implement", $data );
  5182. }
  5183. function implementDo() {
  5184. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5185. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5186. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5187. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5188. // $ab = '';
  5189. // if ($accountBank == 'CGBDeposit')
  5190. // $ab = '纵横广发';
  5191. // elseif ($accountBank == 'ICBCDeposit')
  5192. // $ab = '纵横工行';
  5193. // elseif ($accountBank == 'HUADeposit')
  5194. // $ab = '华润银行';
  5195. // elseif ($accountBank == 'PersonalDeposit')
  5196. // $ab = '个人广发';
  5197. // if (empty ( $ab ))
  5198. // die ( 'illegal request--22' );
  5199. if (! empty ( $rid )) {
  5200. Doo::loadModel ( 'receipt' );
  5201. $receipt = new receipt ();
  5202. // Doo::loadClass ( 'XDeode' );
  5203. // $XDeode = new XDeode ( 5 );
  5204. // $rinfo = $receipt->getOne ( array (
  5205. // 'where' => 'rid=' . $rid,
  5206. // 'asArray' => true
  5207. // ) );
  5208. $rinfo = $receipt->getReceiptByRid ( $rid );
  5209. // $accountType = '';
  5210. // if ($rinfo ['Rtype'] == 1) {
  5211. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5212. // $accountType = 2;
  5213. // else
  5214. // $accountType = 1;
  5215. // } elseif ($rinfo ['Rtype'] == 2) {
  5216. // $accountType = 4;
  5217. // } elseif ($rinfo ['Rtype'] == 0)
  5218. // $accountType = 3;
  5219. // if (empty ( $accountType ))
  5220. // die ( 'illegal request' );
  5221. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5222. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5223. if (empty ( $executeStaff )) {
  5224. $executeStaff = array (
  5225. $this->staff [0] ['sid'] => array (
  5226. 'date' => date ( 'Y-m-d' ),
  5227. 'opinion' => $implementOpinions,
  5228. 'status' => 1
  5229. )
  5230. );
  5231. } else {
  5232. $executeStaff [$this->staff [0] ['sid']] = array (
  5233. 'date' => date ( 'Y-m-d' ),
  5234. 'opinion' => $implementOpinions,
  5235. 'status' => 1
  5236. );
  5237. }
  5238. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5239. $receipt->executeStaff = json_encode ( $executeStaff );
  5240. $receipt->status = 8;
  5241. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5242. $receipt->status = 9;
  5243. if ($rinfo ['status'] == 6) {
  5244. $receipt->loanDate = date ( "Y-m-d" );
  5245. }
  5246. $receipt->executeDate = date ( "Y-m-d" );
  5247. } else {
  5248. $receipt->executeStaff = json_encode ( $executeStaff );
  5249. }
  5250. //$receipt->amount = $amount;
  5251. $receipt->update ( array (
  5252. 'where' => 'rid=' . $rid
  5253. ) );
  5254. // 公司流水记录
  5255. // Doo::loadModel ( 'wasteBook' );
  5256. // $wasteBook = new wasteBook ();
  5257. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5258. // // 银行
  5259. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5260. // $item = array (
  5261. // 'dataID' => $rid,
  5262. // 'expensesType' => 2,
  5263. // 'accountType' => $accountType,
  5264. // 'accountPriceShow' => $amount,
  5265. // 'accountPrice' => - $amount,
  5266. // 'accountBank' => $accountBank,
  5267. // 'category' => $rinfo ['category'] [0] ['title'],
  5268. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5269. // 'name' => $rinfo ['staffDetail'] ['username'],
  5270. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5271. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5272. // );
  5273. // $wasteBook->setAccountBookStatistics ( $item );
  5274. // }
  5275. }
  5276. //$ridKey = $XDeode->encode ( $rid );
  5277. return "/hisImplement";
  5278. // return "/implement/" . $ridKey . ".html";
  5279. }
  5280. function receiptburEdi() {
  5281. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5282. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5283. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5284. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5285. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5286. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5287. if (empty ( $status ))
  5288. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5289. $vidList = array ();
  5290. $button = 0;
  5291. Doo::loadModel ( 'verify' );
  5292. Doo::loadModel ( 'receipt' );
  5293. Doo::loadModel ( 'staff' );
  5294. $staff = new staff ();
  5295. $receipt = new receipt ();
  5296. $verify = new verify ();
  5297. Doo::loadModel ( 'L_category' );
  5298. $Lcategory = new L_category ();
  5299. Doo::loadModel ( 'enclosur' );
  5300. $enclosur = new enclosur ();
  5301. Doo::loadModel ( 'loanReceipt' );
  5302. $loanReceipt = new loanReceipt ();
  5303. // user verify ID
  5304. $verifyDetail = $verify->find ( array (
  5305. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5306. 'asArray' => true
  5307. ) );
  5308. foreach ( $verifyDetail as $key => $value ) {
  5309. array_push ( $vidList, $value ['vid'] );
  5310. }
  5311. $vid = implode ( ",", $vidList );
  5312. if (empty ( $verifyDetail ))
  5313. $vid = 0;
  5314. $categoryList = $Lcategory->find ( array (
  5315. 'asArray' => true
  5316. ) );
  5317. $staffList = $staff->find ( array (
  5318. 'where' => 'cid=' . $cid,
  5319. 'asArray' => true
  5320. ) );
  5321. $ap = "";
  5322. if ($status == 4) {
  5323. $ap = 4;
  5324. $status = 2;
  5325. }
  5326. // get Receipt By verifyID status 2
  5327. $receiptList = $receipt->find ( array (
  5328. 'where' => 'rid =' . $rid . ' and status=2',
  5329. 'desc' => 'rid',
  5330. 'asArray' => true
  5331. ) );
  5332. if (empty ( $receiptList )) {
  5333. die ( 'illegal request' );
  5334. }
  5335. $loanList = $loanReceipt->find ( array (
  5336. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5337. 'desc' => 'rid',
  5338. 'asArray' => true
  5339. ) );
  5340. $data ['explanation'] = '';
  5341. if (! empty ( $loanList ))
  5342. $data ['explanation'] = $loanList [0] ['explanation'];
  5343. $Locate = 0;
  5344. $roleId = 0;
  5345. $button = 0;
  5346. foreach ( $loanList as $key => $value ) {
  5347. $loanList [$key] ['Locate'] = $Locate;
  5348. $Locate ++;
  5349. $loanList [$key] ['reviseDetail'] = array ();
  5350. if (! empty ( $value ['reviseDetail'] ))
  5351. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5352. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5353. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5354. $categoryDetil = $Lcategory->getOne ( array (
  5355. 'where' => 'cid=' . $value ['cid'],
  5356. 'asArray' => true
  5357. ) );
  5358. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5359. // 检测编辑状态
  5360. $verifyList = $verify->getOne ( array (
  5361. 'where' => 'vid=' . $value ['verify'],
  5362. 'asArray' => true
  5363. ) );
  5364. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5365. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5366. Doo::loadModel ( 'role' );
  5367. $role = new role ();
  5368. $flag = true;
  5369. $roleKey = 0;
  5370. $endStaffArray = array ();
  5371. $roleArrayCopy = array ();
  5372. foreach ( $verifyList as $k => $v ) {
  5373. // init verifyStaff
  5374. if ($v [1] == 'ROLE') {
  5375. if (! empty ( $verifyStaff )) {
  5376. $endStaffArray = end ( $verifyStaff );
  5377. }
  5378. $roleVerify = json_decode ( $v [3], true );
  5379. $roleKey = $k;
  5380. $roleArray = array ();
  5381. $rolename = $role->getOne ( array (
  5382. 'where' => 'rid=' . $v [0],
  5383. 'asArray' => true
  5384. ) );
  5385. foreach ( $roleVerify as $o => $p ) {
  5386. $staffID = explode ( '_', $p );
  5387. $staffInfo = $staff->getOne ( array (
  5388. 'where' => 'sid=' . $staffID [0],
  5389. 'asArray' => true
  5390. ) );
  5391. // print_r($staffID);
  5392. $exp = array (
  5393. 0 => $staffInfo ['sid'],
  5394. 1 => $staffID [1],
  5395. 2 => $staffInfo ['avatar'],
  5396. 'date' => '',
  5397. 'date' => '',
  5398. 'opinion' => '',
  5399. 'status' => '',
  5400. 'rolename' => $rolename ['name']
  5401. );
  5402. array_push ( $roleArray, $exp );
  5403. }
  5404. $roleArrayCopy [$v [0]] = $roleArray;
  5405. // $verifyList[$k]['roleArray']=$roleArray;
  5406. }
  5407. $verifyList [$k] ['date'] = "";
  5408. $verifyList [$k] ['opinion'] = "";
  5409. $verifyList [$k] ['status'] = "";
  5410. if (empty ( $verifyStaff )) {
  5411. $verifyList [$k] ['date'] = "";
  5412. $verifyList [$k] ['opinion'] = "";
  5413. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5414. $verifyList [$k] ['status'] = 4;
  5415. $flag = false;
  5416. }
  5417. } else {
  5418. foreach ( $verifyStaff as $m => $u ) {
  5419. if ($v [0] == $m) {
  5420. $verifyList [$k] ['date'] = $u ['date'];
  5421. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5422. $verifyList [$k] ['status'] = $u ['status'];
  5423. $flag = false;
  5424. break;
  5425. }
  5426. }
  5427. $endStaffArray = end ( $verifyStaff );
  5428. if (isset ( $endStaffArray ['ROLE'] )) {
  5429. } else {
  5430. }
  5431. }
  5432. }
  5433. $rolename ['name'] = '';
  5434. if (! empty ( $roleId )) {
  5435. Doo::loadModel ( 'role' );
  5436. $role = new role ();
  5437. $rolename = $role->getOne ( array (
  5438. 'where' => 'rid=' . $roleId,
  5439. 'asArray' => true
  5440. ) );
  5441. }
  5442. if (! empty ( $verifyStaff ))
  5443. $endStaffArray = end ( $verifyStaff );
  5444. $KOP = false;
  5445. foreach ( $roleArrayCopy as $P => $A ) {
  5446. foreach ( $A as $MKI => $AVL ) {
  5447. if (! empty ( $verifyStaff )) {
  5448. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5449. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5450. $button = 4;
  5451. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5452. }
  5453. foreach ( $verifyStaff as $m => $u ) {
  5454. $AVLFK = $AVL [0] . '_R';
  5455. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5456. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5457. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5458. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5459. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5460. break;
  5461. }
  5462. }
  5463. } else {
  5464. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5465. $button = 4;
  5466. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5467. }
  5468. }
  5469. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5470. $KOP = true;
  5471. }
  5472. }
  5473. foreach ( $roleArrayCopy as $k => $v ) {
  5474. foreach ( $verifyList as $m => $n ) {
  5475. if ($n [0] == $k) {
  5476. array_splice ( $verifyList, $m, 1, $v );
  5477. }
  5478. }
  5479. }
  5480. $loanList [$key] ['verifyList'] = $verifyList;
  5481. }
  5482. $htmlLoan = '';
  5483. $data ['loanReceiptDate'] = '';
  5484. if (isset ( $loanList [0] )) {
  5485. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5486. if ($value ['status'] == 1)
  5487. $htmlLoan .= '<li class="done" >';
  5488. elseif ($value ['status'] == 3)
  5489. $htmlLoan .= '<li class="undone" >';
  5490. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5491. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5492. if (isset ( $value ['rolename'] ))
  5493. $htmlLoan .= $value ['rolename'];
  5494. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5495. }
  5496. $data ['loanDate'] = $loanList [0] ['date'];
  5497. } else {
  5498. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5499. }
  5500. $data ['htmlLoan'] = $htmlLoan;
  5501. // $data ['LoanReceipt']=$loanList[0];
  5502. // print_r($loanList);
  5503. $Locate = 0;
  5504. $roleId = 0;
  5505. $button = 0;
  5506. if ($ap == 4)
  5507. $status = 4;
  5508. Doo::loadClass ( 'XDeode' );
  5509. $XDeode = new XDeode ( 5 );
  5510. foreach ( $receiptList as $key => $value ) {
  5511. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5512. $receiptList [$key] ['Locate'] = $Locate;
  5513. $Locate ++;
  5514. $receiptList [$key] ['reviseDetail'] = array ();
  5515. // 调整金额 代码调整
  5516. if (! empty ( $value ['reviseDetail'] )) {
  5517. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5518. foreach ( $reviseDetail as $ry => $re ) {
  5519. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5520. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5521. }
  5522. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5523. // print_r($reviseDetail);
  5524. }
  5525. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5526. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5527. $categoryDetil = $Lcategory->getOne ( array (
  5528. 'where' => 'cid=' . $value ['cid'],
  5529. 'asArray' => true
  5530. ) );
  5531. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5532. // 检测编辑状态
  5533. $verifyList = $verify->getOne ( array (
  5534. 'where' => 'vid=' . $value ['verify'],
  5535. 'asArray' => true
  5536. ) );
  5537. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5538. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5539. Doo::loadModel ( 'role' );
  5540. $role = new role ();
  5541. // print_r($verifyList);
  5542. $flag = true;
  5543. $roleKey = 0;
  5544. $endStaffArray = array ();
  5545. $roleArrayCopy = array ();
  5546. foreach ( $verifyList as $k => $v ) {
  5547. // init verifyStaff
  5548. if ($v [1] == 'ROLE') {
  5549. if (! empty ( $verifyStaff )) {
  5550. $endStaffArray = end ( $verifyStaff );
  5551. if ($v [0] == $endStaffArray ['nextStaff']) {
  5552. $roleId = $v [0];
  5553. }
  5554. }
  5555. $roleVerify = json_decode ( $v [3], true );
  5556. $roleKey = $k;
  5557. $roleArray = array ();
  5558. $rolename = $role->getOne ( array (
  5559. 'where' => 'rid=' . $v [0],
  5560. 'asArray' => true
  5561. ) );
  5562. foreach ( $roleVerify as $o => $p ) {
  5563. $staffID = explode ( '_', $p );
  5564. $staffInfo = $staff->getOne ( array (
  5565. 'where' => 'sid=' . $staffID [0],
  5566. 'asArray' => true
  5567. ) );
  5568. // print_r($staffID);
  5569. $exp = array (
  5570. 0 => $staffInfo ['sid'],
  5571. 1 => $staffID [1],
  5572. 2 => $staffInfo ['avatar'],
  5573. 'date' => '',
  5574. 'date' => '',
  5575. 'opinion' => '',
  5576. 'status' => '',
  5577. 'rolename' => $rolename ['name']
  5578. );
  5579. array_push ( $roleArray, $exp );
  5580. }
  5581. $roleArrayCopy [$v [0]] = $roleArray;
  5582. // $verifyList[$k]['roleArray']=$roleArray;
  5583. }
  5584. // print_r($roleArray);
  5585. $verifyList [$k] ['date'] = "";
  5586. $verifyList [$k] ['opinion'] = "";
  5587. $verifyList [$k] ['status'] = "";
  5588. if (empty ( $verifyStaff )) {
  5589. $verifyList [$k] ['date'] = "";
  5590. $verifyList [$k] ['opinion'] = "";
  5591. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5592. $verifyList [$k] ['status'] = 4;
  5593. $button = 4;
  5594. $flag = false;
  5595. }
  5596. } else {
  5597. foreach ( $verifyStaff as $m => $u ) {
  5598. if ($v [0] == $m) {
  5599. $verifyList [$k] ['date'] = $u ['date'];
  5600. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5601. $verifyList [$k] ['status'] = $u ['status'];
  5602. $flag = false;
  5603. break;
  5604. }
  5605. }
  5606. $endStaffArray = end ( $verifyStaff );
  5607. if (isset ( $endStaffArray ['ROLE'] )) {
  5608. } else {
  5609. $endKey = key ( $verifyStaff );
  5610. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5611. $button = 4;
  5612. $verifyList [$k] ['status'] = 4;
  5613. }
  5614. }
  5615. }
  5616. }
  5617. $rolename ['name'] = '';
  5618. if (! empty ( $roleId )) {
  5619. Doo::loadModel ( 'role' );
  5620. $role = new role ();
  5621. $rolename = $role->getOne ( array (
  5622. 'where' => 'rid=' . $roleId,
  5623. 'asArray' => true
  5624. ) );
  5625. }
  5626. if (! empty ( $verifyStaff ))
  5627. $endStaffArray = end ( $verifyStaff );
  5628. $KOP = false;
  5629. foreach ( $roleArrayCopy as $P => $A ) {
  5630. foreach ( $A as $MKI => $AVL ) {
  5631. if (! empty ( $verifyStaff )) {
  5632. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5633. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5634. $button = 4;
  5635. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5636. }
  5637. foreach ( $verifyStaff as $m => $u ) {
  5638. $AVLFK = $AVL [0] . '_R';
  5639. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5640. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5641. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5642. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5643. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5644. break;
  5645. }
  5646. }
  5647. } else {
  5648. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5649. $button = 4;
  5650. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5651. }
  5652. }
  5653. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5654. $KOP = true;
  5655. }
  5656. }
  5657. foreach ( $roleArrayCopy as $k => $v ) {
  5658. foreach ( $verifyList as $m => $n ) {
  5659. if ($n [0] == $k) {
  5660. array_splice ( $verifyList, $m, 1, $v );
  5661. }
  5662. }
  5663. }
  5664. // print_r($verifyList);
  5665. $receiptList [$key] ['verifyList'] = $verifyList;
  5666. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5667. 'where' => 'sid=' . $value ['staff'],
  5668. 'asArray' => true
  5669. ) );
  5670. $receiptList [$key] ['button'] = $button;
  5671. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5672. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5673. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5674. $receiptList [$key] ['relust'] = $relust;
  5675. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5676. }
  5677. //print_r($receiptList);die;
  5678. // $data['verifyDetail']=$verifyDetail;
  5679. $mothHtml = "";
  5680. for($i = 1; $i <= 12; $i ++) {
  5681. if ($month == $i)
  5682. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5683. else
  5684. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5685. }
  5686. // 获取审批日志
  5687. Doo::loadModel ( 'receiptLog' );
  5688. $receiptLog = new receiptLog ();
  5689. $rlList = array ();
  5690. $rlInfo = $receiptLog->getOne ( array (
  5691. 'where' => 'rid=' . $rid . ' and status=4',
  5692. 'asArray' => true
  5693. ) );
  5694. $tijdate = $receiptLog->getOne ( array (
  5695. 'where' => 'rid=' . $rid . ' and status=2',
  5696. 'asc' => 'rlid',
  5697. 'asArray' => true
  5698. ) );
  5699. if (! empty ( $rlInfo )) {
  5700. $rlList = $receiptLog->find ( array (
  5701. 'where' => 'rid=' . $rid,
  5702. 'asc' => 'rlid',
  5703. 'asArray' => true
  5704. ) );
  5705. }
  5706. // echo $rid;
  5707. // print_r($receiptList);
  5708. $receiptList [0] ['rlList'] = $rlList;
  5709. // print_r($receiptList);
  5710. $enclosurList = $enclosur->find ( array (
  5711. 'where' => 'rid=' . $rid,
  5712. 'asArray' => true
  5713. ) );
  5714. $enclosurHtml = '';
  5715. foreach ( $enclosurList as $value ) {
  5716. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5717. }
  5718. $data ['enclosurHtml'] = $enclosurHtml;
  5719. $data ['rolename'] = $rolename ['name'];
  5720. $data ['mothHtml'] = $mothHtml;
  5721. // print_r($receiptList);
  5722. $data ['rid'] = $rid;
  5723. $data ['tijdate'] = $tijdate ['date'];
  5724. $data ['receiptList'] = $receiptList;
  5725. $data ['receiptApprovalCount'] = count ( $receiptList );
  5726. $data ['status'] = $status;
  5727. $data ['year'] = $year;
  5728. $data ['categoryList'] = $categoryList;
  5729. $data ['staffList'] = $staffList;
  5730. $data ['cid'] = $cid;
  5731. $data ['sid'] = $sid;
  5732. $data ['ap'] = $ap;
  5733. $data ['memu'] = "receipt";
  5734. $data ['staff'] = $this->staff;
  5735. $data ['receiptMemu'] = 'approvalExpenses';
  5736. $data ['verifyId'] = $this->verifyId;
  5737. $data ['executeId'] = $this->executeId;
  5738. $this->render ( "/admin/receiptburEdi", $data );
  5739. }
  5740. function hisImplement() {
  5741. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5742. if (empty ( $item ))
  5743. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5744. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5745. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5746. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5747. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5748. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5749. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5750. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5751. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5752. Doo::loadClass ( 'XDeode' );
  5753. $XDeode = new XDeode ( 5 );
  5754. Doo::loadModel ( 'receipt' );
  5755. $receipt = new receipt ();
  5756. Doo::loadModel ( 'L_category' );
  5757. $Lcategory = new L_category ();
  5758. Doo::loadModel ( 'verify' );
  5759. Doo::loadModel ( 'statistics' );
  5760. $statistics = new statistics ();
  5761. $verify = new verify ();
  5762. Doo::loadModel ( 'staff' );
  5763. $staff = new staff ();
  5764. Doo::loadClass ( 'XDeode' );
  5765. $XDeode = new XDeode ( 5 );
  5766. $XDeode7 = new XDeode ( 7 );
  5767. $cid = $XDeode->decode ( $cidKey );
  5768. $condition = "";
  5769. if ($item == "expenses")
  5770. $condition = " and Rtype=1 ";
  5771. elseif ($item == "receipts")
  5772. $condition = " and Rtype=0 ";
  5773. elseif ($item == "remits")
  5774. $condition = " and Rtype=2 ";
  5775. elseif($item == "train")
  5776. $condition = " and Rtype=3 ";
  5777. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5778. $sopString = $cidString = "";
  5779. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5780. if (empty ( $rdate ))
  5781. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5782. else
  5783. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5784. if ($status == 'pendImplement') {
  5785. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5786. } elseif ($status == 'alerpts') {
  5787. $statusCon = '(status=8 or status=9 )';
  5788. if (empty ( $rdate ))
  5789. $dateCondition .= " and Year(date) =" . $year;
  5790. else
  5791. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5792. }
  5793. if ($sop != 'SOP')
  5794. $sopString = " and staff=" . $sop;
  5795. if ($cidKey != 'ALL')
  5796. $cidString = " and cid=" . $cid;
  5797. if(!empty($receiptOrder)){
  5798. $receiptList = $receipt->find ( array (
  5799. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5800. 'desc' => 'rid',
  5801. 'asArray' => true
  5802. ) );
  5803. // 员工筛选
  5804. $receiptList2 = $receipt->find ( array (
  5805. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5806. 'desc' => 'rid',
  5807. 'asArray' => true
  5808. ) );
  5809. }else{
  5810. $receiptList = $receipt->find ( array (
  5811. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5812. 'desc' => 'rid',
  5813. 'asArray' => true
  5814. ) );
  5815. // 员工筛选
  5816. $receiptList2 = $receipt->find ( array (
  5817. 'where' => $statusCon . $condition . $dateCondition,
  5818. 'desc' => 'rid',
  5819. 'asArray' => true
  5820. ) );
  5821. }
  5822. $sopStaff = array ();
  5823. foreach ( $receiptList2 as $key => $value ) {
  5824. $staffDetail = $staff->getOne ( array (
  5825. 'select' => 'username',
  5826. 'where' => 'sid=' . $value ['staff'],
  5827. 'asArray' => true
  5828. ) );
  5829. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5830. }
  5831. // 办事处筛选
  5832. $categoryScreen = array ();
  5833. $categorList = $Lcategory->getCategory ();
  5834. foreach ( $receiptList2 as $key => $value ) {
  5835. foreach ( $categorList as $k => $v ) {
  5836. if ($value ['cid'] == $v ['cid']) {
  5837. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5838. break;
  5839. }
  5840. }
  5841. }
  5842. $categoryScreenHtml = "";
  5843. foreach ( $categoryScreen as $key => $value ) {
  5844. if ($cidKey == $key)
  5845. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5846. else
  5847. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5848. }
  5849. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5850. $data ['cidKey'] = $cidKey;
  5851. $Locate = 0;
  5852. $roleId = 0;
  5853. $button = 0;
  5854. $staffBatchNumber = 100001;
  5855. $remittanceList = array ();
  5856. foreach ( $receiptList as $key => $value ) {
  5857. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5858. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5859. $receiptList [$key] ['Texe'] = 'false';
  5860. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5861. $receiptList [$key] ['Texe'] = 'true';
  5862. }
  5863. $receiptList [$key] ['TRexe'] = 'true';
  5864. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5865. $receiptList [$key] ['TRexe'] = 'false';
  5866. }
  5867. $receiptList [$key] ['Locate'] = $Locate;
  5868. $Locate ++;
  5869. $receiptList [$key] ['reviseDetail'] = array ();
  5870. if (! empty ( $value ['reviseDetail'] ))
  5871. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5872. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5873. $categoryDetil = $Lcategory->getOne ( array (
  5874. 'where' => 'cid=' . $value ['cid'],
  5875. 'asArray' => true
  5876. ) );
  5877. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5878. // 检测编辑状态
  5879. $verifyList = $verify->getOne ( array (
  5880. 'where' => 'vid=' . $value ['verify'],
  5881. 'asArray' => true
  5882. ) );
  5883. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5884. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5885. Doo::loadModel ( 'role' );
  5886. $role = new role ();
  5887. $flag = true;
  5888. $roleKey = 0;
  5889. $endStaffArray = array ();
  5890. $roleArrayCopy = array ();
  5891. foreach ( $verifyList as $k => $v ) {
  5892. // init verifyStaff
  5893. if ($v [1] == 'ROLE') {
  5894. if (! empty ( $verifyStaff )) {
  5895. $endStaffArray = end ( $verifyStaff );
  5896. }
  5897. $roleVerify = json_decode ( $v [3], true );
  5898. $roleKey = $k;
  5899. $roleArray = array ();
  5900. $rolename = $role->getOne ( array (
  5901. 'where' => 'rid=' . $v [0],
  5902. 'asArray' => true
  5903. ) );
  5904. foreach ( $roleVerify as $o => $p ) {
  5905. $staffID = explode ( '_', $p );
  5906. $staffInfo = $staff->getOne ( array (
  5907. 'where' => 'sid=' . $staffID [0],
  5908. 'asArray' => true
  5909. ) );
  5910. $exp = array (
  5911. 0 => $staffInfo ['sid'],
  5912. 1 => $staffID [1],
  5913. 2 => $staffInfo ['avatar'],
  5914. 'date' => '',
  5915. 'date' => '',
  5916. 'opinion' => '',
  5917. 'status' => '',
  5918. 'rolename' => $rolename ['name']
  5919. );
  5920. array_push ( $roleArray, $exp );
  5921. }
  5922. $roleArrayCopy [$v [0]] = $roleArray;
  5923. }
  5924. $verifyList [$k] ['date'] = "";
  5925. $verifyList [$k] ['opinion'] = "";
  5926. $verifyList [$k] ['status'] = "";
  5927. if (empty ( $verifyStaff )) {
  5928. $verifyList [$k] ['date'] = "";
  5929. $verifyList [$k] ['opinion'] = "";
  5930. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5931. $verifyList [$k] ['status'] = 4;
  5932. $flag = false;
  5933. }
  5934. } else {
  5935. foreach ( $verifyStaff as $m => $u ) {
  5936. if ($v [0] == $m) {
  5937. $verifyList [$k] ['date'] = $u ['date'];
  5938. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5939. $verifyList [$k] ['status'] = $u ['status'];
  5940. $flag = false;
  5941. break;
  5942. }
  5943. }
  5944. $endStaffArray = end ( $verifyStaff );
  5945. }
  5946. }
  5947. $rolename ['name'] = '';
  5948. if (! empty ( $roleId )) {
  5949. Doo::loadModel ( 'role' );
  5950. $role = new role ();
  5951. $rolename = $role->getOne ( array (
  5952. 'where' => 'rid=' . $roleId,
  5953. 'asArray' => true
  5954. ) );
  5955. }
  5956. if (! empty ( $verifyStaff ))
  5957. $endStaffArray = end ( $verifyStaff );
  5958. $KOP = false;
  5959. foreach ( $roleArrayCopy as $P => $A ) {
  5960. foreach ( $A as $MKI => $AVL ) {
  5961. if (! empty ( $verifyStaff )) {
  5962. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5963. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5964. $button = 4;
  5965. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5966. }
  5967. foreach ( $verifyStaff as $m => $u ) {
  5968. $AVLFK = $AVL [0] . '_R';
  5969. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5970. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5971. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5972. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5973. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5974. break;
  5975. }
  5976. }
  5977. } else {
  5978. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5979. $button = 4;
  5980. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5981. }
  5982. }
  5983. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5984. $KOP = true;
  5985. }
  5986. }
  5987. foreach ( $roleArrayCopy as $k => $v ) {
  5988. foreach ( $verifyList as $m => $n ) {
  5989. if ($n [0] == $k) {
  5990. array_splice ( $verifyList, $m, 1, $v );
  5991. }
  5992. }
  5993. }
  5994. $receiptList [$key] ['verifyList'] = $verifyList;
  5995. $staffDetail = $staff->getOne ( array (
  5996. 'where' => 'sid=' . $value ['staff'],
  5997. 'asArray' => true
  5998. ) );
  5999. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6000. $receiptList [$key] ['button'] = $button;
  6001. // 设置导出汇款execl
  6002. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6003. $remittanceDetail = array (
  6004. $staffBatchNumber,
  6005. $value ['remittanceName'],
  6006. $value ['bankNumber'],
  6007. $value ['bankName'],
  6008. $value ['remittanceBankType'],
  6009. $value ['coupletNumber'],
  6010. $value ['sum']
  6011. );
  6012. array_push ( $remittanceList, $remittanceDetail );
  6013. $staffBatchNumber ++;
  6014. }
  6015. }
  6016. $data ['remittanceList'] = json_encode ( $remittanceList );
  6017. // print_r($receiptList);
  6018. $mothHtml = "";
  6019. for($i = 1; $i <= 12; $i ++) {
  6020. if ($moth == $i)
  6021. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6022. else
  6023. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6024. }
  6025. $dayHtml = "";
  6026. if ($day != "DAY" || $moth != "MONTH") {
  6027. for($i = 1; $i <= 31; $i ++) {
  6028. if ($day == $i)
  6029. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6030. else
  6031. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6032. }
  6033. }
  6034. $sopHtml = "";
  6035. foreach ( $sopStaff as $key => $value ) {
  6036. if ($sop == $key)
  6037. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6038. else
  6039. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6040. }
  6041. $data ['status'] = $status;
  6042. $data ['rdate'] = $rdate;
  6043. $data ['sopHtml'] = $sopHtml;
  6044. $data ['dayHtml'] = $dayHtml;
  6045. $data ['mothHtml'] = $mothHtml;
  6046. $data ['receiptList'] = $receiptList;
  6047. $data ['memu'] = "receipt";
  6048. $data ['staff'] = $this->staff;
  6049. $data ['receiptMemu'] = 'implement';
  6050. $data ['verifyId'] = $this->verifyId;
  6051. $data ['executeId'] = $this->executeId;
  6052. $data ['item'] = $item;
  6053. $data ['year'] = $year;
  6054. $data ['moth'] = $moth;
  6055. $data['receiptOrder']=$receiptOrder;
  6056. $data ['day'] = $day;
  6057. $data ['sop'] = $sop;
  6058. $this->render ( "/admin/hisImplement", $data );
  6059. }
  6060. /**
  6061. * 导出汇款信息的exelc
  6062. */
  6063. function exportRemittance() {
  6064. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6065. if (empty ( $remittanceInfo ))
  6066. die ( 'illegal request' );
  6067. $title = array (
  6068. '员工编号',
  6069. '姓名',
  6070. '员工账号',
  6071. '员工账户开户行',
  6072. '转账类型',
  6073. '联行号',
  6074. '金额'
  6075. );
  6076. $data = json_decode ( $remittanceInfo, true );
  6077. if (empty ( $data ))
  6078. die ( 'illegal request' );
  6079. Doo::loadClass ( 'receipt.func' );
  6080. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6081. header ( 'Content-Type:text/html;charset=utf-8' );
  6082. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6083. }
  6084. function ajaxExamine() {
  6085. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6086. Doo::loadModel ( 'receipt' );
  6087. $receipt = new receipt ();
  6088. if (! empty ( $rid )) {
  6089. $rLRes = $receipt->find ( array (
  6090. '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,
  6091. 'asArray' => true
  6092. ) );
  6093. echo json_encode ( array (
  6094. 'status' => 1,
  6095. 'receipt' => $rLRes [0]
  6096. ) );
  6097. die ();
  6098. }
  6099. echo json_encode ( array (
  6100. 'status' => 0,
  6101. 'receipt' => array ()
  6102. ) );
  6103. die ();
  6104. }
  6105. /*
  6106. * 废弃
  6107. */
  6108. function myReceipt() {
  6109. // all approval past withdraw
  6110. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6111. if (empty ( $item ))
  6112. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6113. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6114. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6115. Doo::loadModel ( 'receipt' );
  6116. $receipt = new receipt ();
  6117. // pre-loaded
  6118. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6119. // have cache
  6120. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6121. if (! empty ( $moth )) // yearPage
  6122. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6123. $this->showCache ( $path );
  6124. }
  6125. Doo::loadModel ( 'L_category' );
  6126. $Lcategory = new L_category ();
  6127. Doo::loadModel ( 'verify' );
  6128. Doo::loadModel ( 'statistics' );
  6129. $statistics = new statistics ();
  6130. $verify = new verify ();
  6131. Doo::loadModel ( 'staff' );
  6132. $staff = new staff ();
  6133. $condition = " and status!=0 ";
  6134. if ($item == "approval")
  6135. $condition = " and status=2 ";
  6136. elseif ($item == "withdraw")
  6137. $condition = " and status=3 ";
  6138. elseif ($item == "past")
  6139. $condition = " and status=1 ";
  6140. elseif ($item == "whdw")
  6141. $condition = " and status=4 ";
  6142. $dateCondition = " and Year(date) =" . $year;
  6143. if (! empty ( $moth )) {
  6144. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6145. $stList = $statistics->getOne ( array (
  6146. 'select' => 'rePrice ,agPrice',
  6147. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6148. 'asArray' => true
  6149. ) );
  6150. } else
  6151. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6152. if (empty ( $stList ))
  6153. $stList = array (
  6154. 'rePrice' => 0,
  6155. 'agPrice' => 0
  6156. );
  6157. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6158. $data ['stList'] = array (
  6159. 'rePrice' => $stList ['rePrice'],
  6160. 'agPrice' => $stList ['agPrice'],
  6161. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6162. );
  6163. $receiptList = $receipt->find ( array (
  6164. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6165. 'desc' => 'rid',
  6166. 'asArray' => true
  6167. ) );
  6168. $Locate = 0;
  6169. $roleId = 0;
  6170. $button = 0;
  6171. foreach ( $receiptList as $key => $value ) {
  6172. $receiptList [$key] ['Locate'] = $Locate;
  6173. $Locate ++;
  6174. $receiptList [$key] ['reviseDetail'] = array ();
  6175. if (! empty ( $value ['reviseDetail'] ))
  6176. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6177. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6178. $categoryDetil = $Lcategory->getOne ( array (
  6179. 'where' => 'cid=' . $value ['cid'],
  6180. 'asArray' => true
  6181. ) );
  6182. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6183. // 检测编辑状态
  6184. $verifyList = $verify->getOne ( array (
  6185. 'where' => 'vid=' . $value ['verify'],
  6186. 'asArray' => true
  6187. ) );
  6188. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6189. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6190. Doo::loadModel ( 'role' );
  6191. $role = new role ();
  6192. $flag = true;
  6193. $roleKey = 0;
  6194. $endStaffArray = array ();
  6195. $roleArrayCopy = array ();
  6196. foreach ( $verifyList as $k => $v ) {
  6197. // init verifyStaff
  6198. if ($v [1] == 'ROLE') {
  6199. if (! empty ( $verifyStaff )) {
  6200. $endStaffArray = end ( $verifyStaff );
  6201. // if ($v[0]==$endStaffArray['nextStaff']){
  6202. // $roleId=$v[0];
  6203. // }
  6204. }
  6205. $roleVerify = json_decode ( $v [3], true );
  6206. $roleKey = $k;
  6207. $roleArray = array ();
  6208. $rolename = $role->getOne ( array (
  6209. 'where' => 'rid=' . $v [0],
  6210. 'asArray' => true
  6211. ) );
  6212. foreach ( $roleVerify as $o => $p ) {
  6213. $staffID = explode ( '_', $p );
  6214. $staffInfo = $staff->getOne ( array (
  6215. 'where' => 'sid=' . $staffID [0],
  6216. 'asArray' => true
  6217. ) );
  6218. // print_r($staffID);
  6219. $exp = array (
  6220. 0 => $staffInfo ['sid'],
  6221. 1 => $staffID [1],
  6222. 2 => $staffInfo ['avatar'],
  6223. 'date' => '',
  6224. 'date' => '',
  6225. 'opinion' => '',
  6226. 'status' => '',
  6227. 'rolename' => $rolename ['name']
  6228. );
  6229. array_push ( $roleArray, $exp );
  6230. }
  6231. $roleArrayCopy [$v [0]] = $roleArray;
  6232. // $verifyList[$k]['roleArray']=$roleArray;
  6233. }
  6234. $verifyList [$k] ['date'] = "";
  6235. $verifyList [$k] ['opinion'] = "";
  6236. $verifyList [$k] ['status'] = "";
  6237. if (empty ( $verifyStaff )) {
  6238. $verifyList [$k] ['date'] = "";
  6239. $verifyList [$k] ['opinion'] = "";
  6240. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6241. $verifyList [$k] ['status'] = 4;
  6242. $flag = false;
  6243. }
  6244. } else {
  6245. foreach ( $verifyStaff as $m => $u ) {
  6246. if ($v [0] == $m) {
  6247. $verifyList [$k] ['date'] = $u ['date'];
  6248. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6249. $verifyList [$k] ['status'] = $u ['status'];
  6250. $flag = false;
  6251. break;
  6252. }
  6253. }
  6254. $endStaffArray = end ( $verifyStaff );
  6255. if (isset ( $endStaffArray ['ROLE'] )) {
  6256. } else {
  6257. // $endKey=key($verifyStaff);
  6258. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6259. // $button=4;
  6260. // $verifyList[$k]['status']=4;
  6261. // }
  6262. }
  6263. }
  6264. }
  6265. $rolename ['name'] = '';
  6266. if (! empty ( $roleId )) {
  6267. Doo::loadModel ( 'role' );
  6268. $role = new role ();
  6269. $rolename = $role->getOne ( array (
  6270. 'where' => 'rid=' . $roleId,
  6271. 'asArray' => true
  6272. ) );
  6273. }
  6274. if (! empty ( $verifyStaff ))
  6275. $endStaffArray = end ( $verifyStaff );
  6276. $KOP = false;
  6277. foreach ( $roleArrayCopy as $P => $A ) {
  6278. foreach ( $A as $MKI => $AVL ) {
  6279. if (! empty ( $verifyStaff )) {
  6280. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6281. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6282. $button = 4;
  6283. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6284. }
  6285. foreach ( $verifyStaff as $m => $u ) {
  6286. $AVLFK = $AVL [0] . '_R';
  6287. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6288. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6289. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6290. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6291. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6292. break;
  6293. }
  6294. }
  6295. } else {
  6296. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6297. $button = 4;
  6298. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6299. }
  6300. }
  6301. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6302. $KOP = true;
  6303. }
  6304. }
  6305. foreach ( $roleArrayCopy as $k => $v ) {
  6306. foreach ( $verifyList as $m => $n ) {
  6307. if ($n [0] == $k) {
  6308. array_splice ( $verifyList, $m, 1, $v );
  6309. }
  6310. }
  6311. }
  6312. $receiptList [$key] ['verifyList'] = $verifyList;
  6313. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6314. 'where' => 'sid=' . $value ['staff'],
  6315. 'asArray' => true
  6316. ) );
  6317. $receiptList [$key] ['button'] = $button;
  6318. }
  6319. // print_r($receiptList);die;
  6320. $mothHtml = "";
  6321. for($i = 1; $i <= 12; $i ++) {
  6322. if ($moth == $i)
  6323. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6324. else
  6325. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6326. }
  6327. $data ['mothHtml'] = $mothHtml;
  6328. $data ['receiptList'] = $receiptList;
  6329. $data ['memu'] = "receipt";
  6330. $data ['staff'] = $this->staff;
  6331. $data ['receiptMemu'] = 'receipt';
  6332. $data ['verifyId'] = $this->verifyId;
  6333. $data ['executeId'] = $this->executeId;
  6334. $data ['item'] = $item;
  6335. $data ['year'] = $year;
  6336. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6337. // sufficient condition to generate cache
  6338. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6339. $receiptList = $receipt->find ( array (
  6340. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6341. 'asArray' => true
  6342. ) );
  6343. if (empty ( $receiptList )) { // generated files
  6344. ob_start ();
  6345. $this->render ( "/admin/saea_myList", $data );
  6346. $this->cacheFile ( $path );
  6347. die ();
  6348. // $content = ob_get_contents();
  6349. // $fp = fopen($path, "w");
  6350. // fwrite($fp, $content);
  6351. // fclose($fp);
  6352. }
  6353. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6354. $receiptList = $receipt->find ( array (
  6355. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6356. 'asArray' => true
  6357. ) );
  6358. if (empty ( $receiptList )) { // generated files
  6359. ob_start ();
  6360. $this->render ( "/admin/saea_myList", $data );
  6361. $this->cacheFile ( $path );
  6362. die ();
  6363. }
  6364. }
  6365. }
  6366. $this->render ( "/admin/saea_myList", $data );
  6367. }
  6368. function saeaCreate() {
  6369. Doo::loadModel ( 'accountItem' );
  6370. Doo::loadModel ( 'verify' );
  6371. Doo::loadModel ( 'receipt' );
  6372. Doo::loadModel ( 'L_category' );
  6373. $lCategory = new L_category ();
  6374. $receipt = new receipt ();
  6375. $verify = new verify ();
  6376. $accountItem = new accountItem ();
  6377. Doo::loadModel ( "role" );
  6378. $role = new role ();
  6379. $acItem = $accountItem->find ( array (
  6380. 'asArray' => true
  6381. ) );
  6382. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6383. $data ['category'] = $lCategory->find ( array (
  6384. 'asArray' => true
  6385. ) );
  6386. $data ['veList'] = $veList;
  6387. $data ['acItem'] = $acItem;
  6388. $data ['memu'] = "receipt";
  6389. $data ['staff'] = $this->staff;
  6390. $data ['receiptMemu'] = 'saeaBorad';
  6391. $data ['verifyId'] = $this->verifyId;
  6392. $data ['executeId'] = $this->executeId;
  6393. $this->render ( "/admin/saea_create", $data );
  6394. }
  6395. function addReceipt() {
  6396. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6397. $agency = $this->get_args ( 'agency' );
  6398. $travel = $this->get_args ( 'travel' );
  6399. $train = $this->get_args ( 'train' );
  6400. $other = $this->get_args ( 'other' );
  6401. $inttrain = $this->get_args ( 'inttrain' );
  6402. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6403. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6404. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6405. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6406. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6407. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6408. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6409. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6410. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6411. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6412. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6413. header ( 'Content-Type:text/html;charset=utf-8' );
  6414. die ( '请填写联行号' );
  6415. }
  6416. Doo::loadModel ( 'receipt' );
  6417. Doo::loadModel ( 'receiptDetail' );
  6418. Doo::loadModel ( 'accountItem' );
  6419. $accountItem = new accountItem ();
  6420. $receipt = new receipt ();
  6421. Doo::loadModel ( 'enclosur' );
  6422. Doo::loadModel ( 'execute' );
  6423. $execute = new execute ();
  6424. $executeDetail = $execute->getOne ( array (
  6425. 'where' => 'mold="报销单执行人"',
  6426. 'asArray' => true
  6427. ) );
  6428. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6429. // if(!empty($receiptDetail))
  6430. // return "/referReceipt/".$receiptDetail['rid'];
  6431. $aItem = $accountItem->find ( array (
  6432. 'asArray' => true
  6433. ) );
  6434. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6435. $ag = $tr = $ta = $ot= $it = 0;
  6436. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6437. foreach ( $aItem as $key => $value ) {
  6438. if ($value ['category'] == $this->AGENCY) {
  6439. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6440. array_push ( $accountJson [$this->AGENCY], array (
  6441. 'aid' => $value ['aid'],
  6442. 'name' => $value ['name'],
  6443. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6444. ) );
  6445. $sum += $agency [$ag];
  6446. $agencySum += $agency [$ag];
  6447. }
  6448. $ag ++;
  6449. }
  6450. if ($value ['category'] == $this->TRAVEL) {
  6451. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6452. array_push ( $accountJson [$this->TRAVEL], array (
  6453. 'aid' => $value ['aid'],
  6454. 'name' => $value ['name'],
  6455. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6456. ) );
  6457. $sum += $travel [$tr];
  6458. $travelSum += $travel [$tr];
  6459. }
  6460. $tr ++;
  6461. }
  6462. if ($value ['category'] == $this->TRAIN) {
  6463. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6464. array_push ( $accountJson [$this->TRAIN], array (
  6465. 'aid' => $value ['aid'],
  6466. 'name' => $value ['name'],
  6467. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6468. ) );
  6469. $sum += $train [$ta];
  6470. $trainSum += $train [$ta];
  6471. }
  6472. $ta ++;
  6473. }
  6474. if ($value ['category'] == $this->INTTRAIN) {
  6475. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6476. array_push ( $accountJson [$this->INTTRAIN], array (
  6477. 'aid' => $value ['aid'],
  6478. 'name' => $value ['name'],
  6479. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6480. ) );
  6481. $sum += $inttrain [$it];
  6482. $inttrainSum += $inttrain [$it];
  6483. }
  6484. $it ++;
  6485. }
  6486. if ($value ['category'] == $this->OTHER) {
  6487. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6488. array_push ( $accountJson [$this->OTHER], array (
  6489. 'aid' => $value ['aid'],
  6490. 'name' => $value ['name'],
  6491. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6492. ) );
  6493. $sum += $other [$ot];
  6494. $otherSum += $other [$ot];
  6495. }
  6496. $ot ++;
  6497. }
  6498. }
  6499. $accountJson ['cSum'] = array (
  6500. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6501. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6502. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6503. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6504. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6505. );
  6506. // 报销单
  6507. $receipt->accountItem = json_encode ( $accountJson );
  6508. $receipt->staff = $this->staff [0] ['sid'];
  6509. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6510. $receipt->date = date ( "Y-m-d" );
  6511. $receipt->cid = $cid;
  6512. $receipt->status = 5;
  6513. // 修改审批流程加入角色
  6514. $receipt->verify = $verify;
  6515. $receipt->executeCopy = $executeDetail ['staff'];
  6516. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6517. $order = array (
  6518. "\r\n",
  6519. "\n",
  6520. "\r"
  6521. );
  6522. $replace = '<br/>';
  6523. $explanation = str_replace ( $order, $replace, $explanation );
  6524. $receipt->explanation = $explanation;
  6525. $receipt->remittanceName = $remittanceName;
  6526. $receipt->bankName = $bankName;
  6527. $receipt->bankNumber = $bankNumber;
  6528. $receipt->remittanceBankType = $remittanceBankType;
  6529. if ($remittanceBankType == 1)
  6530. $receipt->coupletNumber = $coupletNumber;
  6531. $rid = $receipt->insert ();
  6532. // 附件
  6533. if (! empty ( $enclosurName )) {
  6534. $enclosurArray = explode ( '-', $enclosurName );
  6535. foreach ( $enclosurArray as $value ) {
  6536. $enclosur = new enclosur ();
  6537. $enclosur->name = $value;
  6538. $enclosur->rid = $rid;
  6539. $enclosur->insert ();
  6540. }
  6541. // print_r($enclosurArray);die;
  6542. }
  6543. // 报销详情
  6544. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6545. $receiptDetail = new receiptDetail ();
  6546. $receiptDetail->staff = $this->staff [0] ['sid'];
  6547. $receiptDetail->item = $value ['name'];
  6548. $receiptDetail->itemCategory = $this->AGENCY;
  6549. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6550. $receiptDetail->date = date ( "Y-m-d" );
  6551. $receiptDetail->cid = $cid;
  6552. $receiptDetail->rid = $rid;
  6553. $receiptDetail->status = 4;
  6554. $receiptDetail->insert ();
  6555. }
  6556. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6557. $receiptDetail = new receiptDetail ();
  6558. $receiptDetail->staff = $this->staff [0] ['sid'];
  6559. $receiptDetail->item = $value ['name'];
  6560. $receiptDetail->itemCategory = $this->TRAVEL;
  6561. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6562. $receiptDetail->date = date ( "Y-m-d" );
  6563. $receiptDetail->cid = $cid;
  6564. $receiptDetail->rid = $rid;
  6565. $receiptDetail->status = 4;
  6566. $receiptDetail->insert ();
  6567. }
  6568. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6569. $receiptDetail = new receiptDetail ();
  6570. $receiptDetail->staff = $this->staff [0] ['sid'];
  6571. $receiptDetail->item = $value ['name'];
  6572. $receiptDetail->itemCategory = $this->TRAIN;
  6573. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6574. $receiptDetail->date = date ( "Y-m-d" );
  6575. $receiptDetail->cid = $cid;
  6576. $receiptDetail->rid = $rid;
  6577. $receiptDetail->status = 4;
  6578. $receiptDetail->insert ();
  6579. }
  6580. //内训
  6581. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6582. $receiptDetail = new receiptDetail ();
  6583. $receiptDetail->staff = $this->staff [0] ['sid'];
  6584. $receiptDetail->item = $value ['name'];
  6585. $receiptDetail->itemCategory = $this->INTTRAIN;
  6586. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6587. $receiptDetail->date = date ( "Y-m-d" );
  6588. $receiptDetail->cid = $cid;
  6589. $receiptDetail->rid = $rid;
  6590. $receiptDetail->status = 4;
  6591. $receiptDetail->insert ();
  6592. }
  6593. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6594. $receiptDetail = new receiptDetail ();
  6595. $receiptDetail->staff = $this->staff [0] ['sid'];
  6596. $receiptDetail->item = $value ['name'];
  6597. $receiptDetail->itemCategory = $this->OTHER;
  6598. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6599. $receiptDetail->date = date ( "Y-m-d" );
  6600. $receiptDetail->cid = $cid;
  6601. $receiptDetail->rid = $rid;
  6602. $receiptDetail->status = 4;
  6603. $receiptDetail->insert ();
  6604. }
  6605. return "/saeaBorad";
  6606. } else
  6607. die ( 'illegal request' );
  6608. }
  6609. function referReceipt() {
  6610. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6611. Doo::loadModel ( 'receipt' );
  6612. Doo::loadModel ( 'verify' );
  6613. $verify = new verify ();
  6614. $receipt = new receipt ();
  6615. Doo::loadModel ( 'L_category' );
  6616. $lCategory = new L_category ();
  6617. Doo::loadModel ( "role" );
  6618. $role = new role ();
  6619. $receiptDetail = $receipt->find ( array (
  6620. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6621. 'asArray' => true
  6622. ) );
  6623. if (empty ( $receiptDetail ))
  6624. return "/addReceipt";
  6625. foreach ( $receiptDetail as $key => $value ) {
  6626. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6627. $veList = $verify->getOne ( array (
  6628. 'where' => 'vid=' . $value ['verify'],
  6629. 'asArray' => true
  6630. ) );
  6631. $v = json_decode ( $veList ['staff'] );
  6632. array_push ( $v [0], $veList ['description'] );
  6633. foreach ( $v as $n => $m ) {
  6634. if ($m ['1'] == 'ROLE') {
  6635. $roleInfo = $role->getOne ( array (
  6636. 'where' => 'rid=' . $m [0],
  6637. 'asArray' => true
  6638. ) );
  6639. $v [$n] [1] = $roleInfo ['name'];
  6640. }
  6641. }
  6642. $receiptDetail [$key] ['staff'] = $v;
  6643. $category = $lCategory->getOne ( array (
  6644. 'where' => 'cid=' . $value ['cid'],
  6645. 'asArray' => true
  6646. ) );
  6647. $receiptDetail [$key] ['category'] = $category ['title'];
  6648. }
  6649. // print_r($receiptDetail);
  6650. $data ['receiptDetail'] = $receiptDetail;
  6651. $data ['memu'] = "receipt";
  6652. $data ['staff'] = $this->staff;
  6653. $data ['receiptMemu'] = 'saeaCreate';
  6654. $data ['verifyId'] = $this->verifyId;
  6655. $data ['executeId'] = $this->executeId;
  6656. $this->render ( "/admin/saea_confirm", $data );
  6657. }
  6658. function editReceipt() {
  6659. // edit status 4
  6660. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6661. Doo::loadClass ( 'XDeode' );
  6662. $XDeode = new XDeode ( 7 );
  6663. $rid = $XDeode->decode ( $ridKey );
  6664. if (empty ( $rid ))
  6665. die ( 'illegal request' );
  6666. // echo $rid.'sd';
  6667. Doo::loadModel ( 'accountItem' );
  6668. Doo::loadModel ( 'verify' );
  6669. Doo::loadModel ( 'receipt' );
  6670. $receipt = new receipt ();
  6671. $verify = new verify ();
  6672. $accountItem = new accountItem ();
  6673. Doo::loadModel ( 'L_category' );
  6674. $lCategory = new L_category ();
  6675. Doo::loadModel ( "role" );
  6676. $role = new role ();
  6677. Doo::loadModel ( 'enclosur' );
  6678. $enclosur = new enclosur ();
  6679. $receiptDetail = $receipt->getOne ( array (
  6680. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6681. 'asArray' => true
  6682. ) );
  6683. if (empty ( $receiptDetail ))
  6684. die ( 'illegal request' );
  6685. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6686. $acItem = $accountItem->find ( array (
  6687. 'asArray' => true
  6688. ) );
  6689. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6690. // 配置编辑信息
  6691. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6692. foreach ( $acItem as $key => $value ) {
  6693. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6694. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6695. $acItem [$key] ['price'] = $v ['price'];
  6696. }
  6697. }
  6698. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6699. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6700. $acItem [$key] ['price'] = $v ['price'];
  6701. }
  6702. }
  6703. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6704. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6705. $acItem [$key] ['price'] = $v ['price'];
  6706. }
  6707. }
  6708. //内训
  6709. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6710. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6711. $acItem [$key] ['price'] = $v ['price'];
  6712. }
  6713. }
  6714. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6715. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6716. $acItem [$key] ['price'] = $v ['price'];
  6717. }
  6718. }
  6719. }
  6720. $data ['category'] = $lCategory->find ( array (
  6721. 'asArray' => true
  6722. ) );
  6723. $data ['cSum'] = $accountItemList ['cSum'];
  6724. $data ['sum'] = $receiptDetail ['sum'];
  6725. $data ['enclosurList'] = $enclosurList;
  6726. $data ['receiptDetail'] = $receiptDetail;
  6727. $data ['veList'] = $veList;
  6728. $data ['acItem'] = $acItem;
  6729. $data ['memu'] = "receipt";
  6730. $data ['staff'] = $this->staff;
  6731. $data ['receiptMemu'] = 'saeaBorad';
  6732. $data ['verify'] = $receiptDetail ['verify'];
  6733. $data ['verifyId'] = $this->verifyId;
  6734. $data ['executeId'] = $this->executeId;
  6735. $data ['rid'] = $ridKey;
  6736. $this->render ( "/admin/saea_edit", $data );
  6737. }
  6738. function updateReceipt() {
  6739. $agency = $this->get_args ( 'agency' );
  6740. $travel = $this->get_args ( 'travel' );
  6741. $train = $this->get_args ( 'train' );
  6742. $other = $this->get_args ( 'other' );
  6743. $inttrain = $this->get_args ( 'inttrain' );
  6744. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6745. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6746. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6747. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6748. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6749. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6750. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6751. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6752. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6753. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6754. Doo::loadClass ( 'XDeode' );
  6755. $XDeode = new XDeode ( 7 );
  6756. $rid = $XDeode->decode ( $ridKey );
  6757. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6758. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6759. header ( 'Content-Type:text/html;charset=utf-8' );
  6760. die ( '请填写联行号' );
  6761. }
  6762. Doo::loadModel ( 'receipt' );
  6763. Doo::loadModel ( 'receiptDetail' );
  6764. Doo::loadModel ( 'accountItem' );
  6765. $accountItem = new accountItem ();
  6766. $receipt = new receipt ();
  6767. Doo::loadModel ( 'enclosur' );
  6768. Doo::loadModel ( 'execute' );
  6769. $execute = new execute ();
  6770. $receiptDetail = $receipt->getOne ( array (
  6771. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6772. 'asArray' => true
  6773. ) );
  6774. if (empty ( $receiptDetail ))
  6775. return "/saeaBorad";
  6776. if ($receiptDetail ['Rtype'] == 1)
  6777. $executeDetail = $execute->getOne ( array (
  6778. 'where' => 'mold="借款费用执行人"',
  6779. 'asArray' => true
  6780. ) );
  6781. else
  6782. $executeDetail = $execute->getOne ( array (
  6783. 'where' => 'mold="报销单执行人"',
  6784. 'asArray' => true
  6785. ) );
  6786. $aItem = $accountItem->find ( array (
  6787. 'asArray' => true
  6788. ) );
  6789. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6790. $ag = $tr = $ta = $ot = $it = 0 ;
  6791. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6792. foreach ( $aItem as $key => $value ) {
  6793. if ($value ['category'] == $this->AGENCY) {
  6794. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6795. array_push ( $accountJson [$this->AGENCY], array (
  6796. 'aid' => $value ['aid'],
  6797. 'name' => $value ['name'],
  6798. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6799. ) );
  6800. $sum += $agency [$ag];
  6801. $agencySum += $agency [$ag];
  6802. }
  6803. $ag ++;
  6804. }
  6805. if ($value ['category'] == $this->TRAVEL) {
  6806. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6807. array_push ( $accountJson [$this->TRAVEL], array (
  6808. 'aid' => $value ['aid'],
  6809. 'name' => $value ['name'],
  6810. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6811. ) );
  6812. $sum += $travel [$tr];
  6813. $travelSum += $travel [$tr];
  6814. }
  6815. $tr ++;
  6816. }
  6817. if ($value ['category'] == $this->TRAIN) {
  6818. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6819. array_push ( $accountJson [$this->TRAIN], array (
  6820. 'aid' => $value ['aid'],
  6821. 'name' => $value ['name'],
  6822. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6823. ) );
  6824. $sum += $train [$ta];
  6825. $trainSum += $train [$ta];
  6826. }
  6827. $ta ++;
  6828. }
  6829. if ($value ['category'] == $this->INTTRAIN) {
  6830. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6831. array_push ( $accountJson [$this->INTTRAIN], array (
  6832. 'aid' => $value ['aid'],
  6833. 'name' => $value ['name'],
  6834. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6835. ) );
  6836. $sum += $inttrain [$it];
  6837. $inttrainSum += $inttrain [$it];
  6838. }
  6839. $it ++;
  6840. }
  6841. if ($value ['category'] == $this->OTHER) {
  6842. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6843. array_push ( $accountJson [$this->OTHER], array (
  6844. 'aid' => $value ['aid'],
  6845. 'name' => $value ['name'],
  6846. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6847. ) );
  6848. $sum += $other [$ot];
  6849. $otherSum += $other [$ot];
  6850. }
  6851. $ot ++;
  6852. }
  6853. }
  6854. $accountJson ['cSum'] = array (
  6855. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6856. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6857. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6858. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6859. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6860. );
  6861. // 报销单
  6862. $rid = $receipt->rid = $receiptDetail ['rid'];
  6863. $receipt->accountItem = json_encode ( $accountJson );
  6864. $receipt->staff = $this->staff [0] ['sid'];
  6865. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6866. $receipt->date = date ( "Y-m-d" );
  6867. $receipt->cid = $cid;
  6868. if (($receiptDetail ['status'] != 4)) {
  6869. if ($receiptDetail ['Rtype'] == 1)
  6870. $receipt->status = 7;
  6871. else
  6872. $receipt->status = 5;
  6873. }
  6874. if ($receiptDetail != 4 && ! empty ( $verify ))
  6875. $receipt->verify = $verify;
  6876. $receipt->executeCopy = $executeDetail ['staff'];
  6877. $order = array (
  6878. "\r\n",
  6879. "\n",
  6880. "\r"
  6881. );
  6882. $replace = '<br/>';
  6883. $explanation = str_replace ( $order, $replace, $explanation );
  6884. $receipt->explanation = $explanation;
  6885. $receipt->remittanceName = $remittanceName;
  6886. $receipt->bankName = $bankName;
  6887. $receipt->bankNumber = $bankNumber;
  6888. $receipt->remittanceBankType = $remittanceBankType;
  6889. if ($remittanceBankType == 1)
  6890. $receipt->coupletNumber = $coupletNumber;
  6891. $receipt->update ();
  6892. $receiptDetail = new receiptDetail ();
  6893. $receiptDetail->delete ( array (
  6894. 'where' => 'rid=' . $rid
  6895. ) );
  6896. // 报销详情
  6897. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6898. $receiptDetail = new receiptDetail ();
  6899. $receiptDetail->staff = $this->staff [0] ['sid'];
  6900. $receiptDetail->item = $value ['name'];
  6901. $receiptDetail->itemCategory = $this->AGENCY;
  6902. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6903. $receiptDetail->date = date ( "Y-m-d" );
  6904. $receiptDetail->cid = $cid;
  6905. $receiptDetail->rid = $rid;
  6906. $receiptDetail->status = 4;
  6907. $receiptDetail->insert ();
  6908. }
  6909. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6910. $receiptDetail = new receiptDetail ();
  6911. $receiptDetail->staff = $this->staff [0] ['sid'];
  6912. $receiptDetail->item = $value ['name'];
  6913. $receiptDetail->itemCategory = $this->TRAVEL;
  6914. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6915. $receiptDetail->date = date ( "Y-m-d" );
  6916. $receiptDetail->cid = $cid;
  6917. $receiptDetail->rid = $rid;
  6918. $receiptDetail->status = 4;
  6919. $receiptDetail->insert ();
  6920. }
  6921. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6922. $receiptDetail = new receiptDetail ();
  6923. $receiptDetail->staff = $this->staff [0] ['sid'];
  6924. $receiptDetail->item = $value ['name'];
  6925. $receiptDetail->itemCategory = $this->TRAIN;
  6926. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6927. $receiptDetail->date = date ( "Y-m-d" );
  6928. $receiptDetail->cid = $cid;
  6929. $receiptDetail->rid = $rid;
  6930. $receiptDetail->status = 4;
  6931. $receiptDetail->insert ();
  6932. }
  6933. //内训
  6934. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6935. $receiptDetail = new receiptDetail ();
  6936. $receiptDetail->staff = $this->staff [0] ['sid'];
  6937. $receiptDetail->item = $value ['name'];
  6938. $receiptDetail->itemCategory = $this->INTTRAIN;
  6939. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6940. $receiptDetail->date = date ( "Y-m-d" );
  6941. $receiptDetail->cid = $cid;
  6942. $receiptDetail->rid = $rid;
  6943. $receiptDetail->status = 4;
  6944. $receiptDetail->insert ();
  6945. }
  6946. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6947. $receiptDetail = new receiptDetail ();
  6948. $receiptDetail->staff = $this->staff [0] ['sid'];
  6949. $receiptDetail->item = $value ['name'];
  6950. $receiptDetail->itemCategory = $this->OTHER;
  6951. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6952. $receiptDetail->date = date ( "Y-m-d" );
  6953. $receiptDetail->cid = $cid;
  6954. $receiptDetail->rid = $rid;
  6955. $receiptDetail->status = 4;
  6956. $receiptDetail->insert ();
  6957. }
  6958. // 附件
  6959. if (! empty ( $enclosurName )) {
  6960. $enclosurArray = explode ( '-', $enclosurName );
  6961. foreach ( $enclosurArray as $value ) {
  6962. $enclosur = new enclosur ();
  6963. $enclosur->name = $value;
  6964. $enclosur->rid = $rid;
  6965. $enclosur->insert ();
  6966. }
  6967. }
  6968. // return "/referReceipt/".$rid;
  6969. }
  6970. return "/saeaBorad";
  6971. }
  6972. function approvedReceipt() {
  6973. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6974. Doo::loadModel ( 'receipt' );
  6975. Doo::loadModel ( 'receiptDetail' );
  6976. $receipt = new receipt ();
  6977. $receiptDetail = new receiptDetail ();
  6978. Doo::loadModel ( 'statistics' );
  6979. Doo::loadModel ( 'itemStatistics' );
  6980. $statistics = new statistics ();
  6981. $itemStatistics = new itemStatistics ();
  6982. Doo::loadModel ( "verify" );
  6983. $verify = new verify ();
  6984. // 审批状态的判定
  6985. $receiptDetailList = $receipt->getOne ( array (
  6986. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  6987. 'asArray' => true
  6988. ) );
  6989. if (empty ( $receiptDetailList ))
  6990. return "/saeaBorad";
  6991. $verifyDetail = $verify->getOne ( array (
  6992. 'where' => ' vid =' . $receiptDetailList ['verify'],
  6993. 'asArray' => true
  6994. ) );
  6995. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  6996. if (empty ( $receiptDetailList ['nowStaff'] )) {
  6997. $nowStaff = "";
  6998. $nowStaffList = array ();
  6999. if ($verifyDetail [0] [1] == 'ROLE') {
  7000. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7001. foreach ( $vStaffString as $key => $value ) {
  7002. $staffK = explode ( "_", $value );
  7003. array_push ( $nowStaffList, $staffK [0] );
  7004. }
  7005. $nowStaff = implode ( ',', $nowStaffList );
  7006. } else {
  7007. $nowStaff = $verifyDetail [0] [0];
  7008. }
  7009. $receipt->nowStaff = $nowStaff;
  7010. }
  7011. // echo $nowStaff;
  7012. // print_r($verifyDetail);die;
  7013. $receipt->rid = $receiptDetailList ['rid'];
  7014. $receipt->date = date ( "Y-m-d" );
  7015. $receipt->status = 2;
  7016. $receipt->update ();
  7017. $receiptDetail->status = 2;
  7018. $receiptDetail->update ( array (
  7019. 'where' => 'rid=' . $receiptDetailList ['rid']
  7020. ) );
  7021. Doo::loadModel ( "receiptLog" );
  7022. $receiptLog = new receiptLog ();
  7023. Doo::loadModel ( "verify" );
  7024. $verify = new verify ();
  7025. $receiptInfo = $receipt->getOne ( array (
  7026. 'where' => 'rid=' . $rid,
  7027. 'asArray' => true
  7028. ) );
  7029. $vr = $verify->getOne ( array (
  7030. 'where' => 'vid=' . $receiptInfo ['verify'],
  7031. 'asArray' => true
  7032. ) );
  7033. $jd = json_decode ( $vr ['staff'] );
  7034. $roleId = 0;
  7035. foreach ( $jd as $key => $value ) {
  7036. if ($value [1] == 'ROLE') {
  7037. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7038. if ($pos !== false) {
  7039. $roleId = $value [0];
  7040. }
  7041. }
  7042. }
  7043. // 审批日志
  7044. // echo $roleId;die;
  7045. if (! empty ( $roleId )) {
  7046. Doo::loadModel ( "role" );
  7047. $role = new role ();
  7048. $roleInfo = $role->getOne ( array (
  7049. 'where' => 'rid=' . $roleId,
  7050. 'asArray' => true
  7051. ) );
  7052. // $receiptLog->rolename = $roleInfo ['name'];
  7053. }
  7054. $receiptLog->username = $this->staff [0] ['username'];
  7055. $receiptLog->uid = $this->staff [0] ['sid'];
  7056. $receiptLog->date = date ( "Y-m-d" );
  7057. $receiptLog->opinion = '提交审批';
  7058. $receiptLog->img = $this->staff [0] ['avatar'];
  7059. $receiptLog->status = 2;
  7060. $receiptLog->rid = $rid;
  7061. $receiptLog->insert ();
  7062. // statistics item
  7063. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7064. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7065. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7066. $stat = $statistics->getOne ( array (
  7067. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7068. 'asArray' => true
  7069. ) );
  7070. if (empty ( $stat )) {
  7071. $statistics->date = date ( "Y-m-d" );
  7072. $statistics->cid = $this->staff [0] ['cid'];
  7073. $statistics->staff = $this->staff [0] ['sid'];
  7074. $statistics->agPrice = 0;
  7075. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7076. $statistics->insert ();
  7077. } else {
  7078. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7079. $statistics->update ( array (
  7080. 'where' => 'sid=' . $stat ['sid']
  7081. ) );
  7082. }
  7083. return "/expenses";
  7084. }
  7085. function approval() {
  7086. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7087. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7088. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7089. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7090. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7091. if (empty ( $status ))
  7092. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7093. $vidList = array ();
  7094. $button = 0;
  7095. Doo::loadModel ( 'verify' );
  7096. $verify = new verify ();
  7097. Doo::loadModel ( 'receipt' );
  7098. $receipt = new receipt ();
  7099. Doo::loadModel ( 'staff' );
  7100. $staff = new staff ();
  7101. Doo::loadModel ( 'L_category' );
  7102. $Lcategory = new L_category ();
  7103. // user verify ID
  7104. $verifyDetail = $verify->find ( array (
  7105. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7106. 'asArray' => true
  7107. ) );
  7108. foreach ( $verifyDetail as $key => $value ) {
  7109. array_push ( $vidList, $value ['vid'] );
  7110. }
  7111. $vid = implode ( ",", $vidList );
  7112. if (empty ( $verifyDetail ))
  7113. $vid = 0;
  7114. /*
  7115. */
  7116. $dateCondition = " and Year(date) =" . $year;
  7117. if (! empty ( $month ))
  7118. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7119. $categoryList = $Lcategory->find ( array (
  7120. 'asArray' => true
  7121. ) );
  7122. $staffList = $staff->find ( array (
  7123. 'where' => 'cid=' . $cid,
  7124. 'asArray' => true
  7125. ) );
  7126. $cateCondition = "";
  7127. $staffCondition = "";
  7128. $approvalCondition = "";
  7129. if (! empty ( $cid ))
  7130. $cateCondition = ' and cid=' . $cid;
  7131. if (! empty ( $sid )) {
  7132. $staffCondition = ' and staff=' . $sid;
  7133. $cateCondition = "";
  7134. }
  7135. // elseif($status==1){
  7136. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7137. // }
  7138. if ($status == 2) {
  7139. // 查找角色审批人
  7140. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7141. }
  7142. $ap = "";
  7143. if ($status == 4) {
  7144. $ap = 4;
  7145. $status = 2;
  7146. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7147. }
  7148. if ($status == 5) {
  7149. $status = 4;
  7150. $ap = 5;
  7151. }
  7152. // echo $vid;
  7153. // get Receipt By verifyID status 2 .$approvalCondition
  7154. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7155. $receiptList = $receipt->find ( array (
  7156. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7157. 'desc' => 'rid',
  7158. 'asArray' => true
  7159. ) );
  7160. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7161. $Locate = 0;
  7162. if ($ap == 4)
  7163. $status = 4;
  7164. elseif ($ap == 5)
  7165. $status = 5;
  7166. foreach ( $receiptList as $key => $value ) {
  7167. $receiptList [$key] ['Locate'] = $Locate;
  7168. $Locate ++;
  7169. $receiptList [$key] ['reviseDetail'] = array ();
  7170. if (! empty ( $value ['reviseDetail'] ))
  7171. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7172. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7173. $categoryDetil = $Lcategory->getOne ( array (
  7174. 'where' => 'cid=' . $value ['cid'],
  7175. 'asArray' => true
  7176. ) );
  7177. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7178. $verifyList = $verify->getOne ( array (
  7179. 'where' => 'vid=' . $value ['verify'],
  7180. 'asArray' => true
  7181. ) );
  7182. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7183. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7184. foreach ( $verifyList as $k => $v ) {
  7185. // init verifyStaff
  7186. $verifyList [$k] ['date'] = "";
  7187. $verifyList [$k] ['opinion'] = "";
  7188. $verifyList [$k] ['status'] = "";
  7189. if (empty ( $verifyStaff )) {
  7190. $verifyList [$k] ['date'] = "";
  7191. $verifyList [$k] ['opinion'] = "";
  7192. if ($v [0] == $this->staff [0] ['sid']) {
  7193. $verifyList [$k] ['status'] = 4;
  7194. $button = 4;
  7195. }
  7196. } else {
  7197. $flag = true;
  7198. foreach ( $verifyStaff as $m => $u ) {
  7199. if ($v [0] == $m) {
  7200. $verifyList [$k] ['date'] = $u ['date'];
  7201. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7202. $verifyList [$k] ['status'] = $u ['status'];
  7203. $flag = false;
  7204. break;
  7205. }
  7206. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7207. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7208. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7209. }
  7210. if ($flag) { // 检测可编辑
  7211. if ($v [0] == $this->staff [0] ['sid']) {
  7212. $verifyList [$k] ['status'] = 4;
  7213. $button = 4;
  7214. }
  7215. }
  7216. }
  7217. }
  7218. $receiptList [$key] ['verifyList'] = $verifyList;
  7219. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7220. 'where' => 'sid=' . $value ['staff'],
  7221. 'asArray' => true
  7222. ) );
  7223. $receiptList [$key] ['button'] = $button;
  7224. }
  7225. // print_r($receiptList);die;
  7226. // $data['verifyDetail']=$verifyDetail;
  7227. $mothHtml = "";
  7228. for($i = 1; $i <= 12; $i ++) {
  7229. if ($month == $i)
  7230. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7231. else
  7232. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7233. }
  7234. $data ['mothHtml'] = $mothHtml;
  7235. $data ['receiptList'] = $receiptList;
  7236. $data ['receiptApprovalCount'] = count ( $receiptList );
  7237. $data ['status'] = $status;
  7238. $data ['year'] = $year;
  7239. $data ['categoryList'] = $categoryList;
  7240. $data ['staffList'] = $staffList;
  7241. $data ['cid'] = $cid;
  7242. $data ['sid'] = $sid;
  7243. $data ['ap'] = $ap;
  7244. $data ['memu'] = "receipt";
  7245. $data ['staff'] = $this->staff;
  7246. $data ['receiptMemu'] = 'approval';
  7247. $data ['verifyId'] = $this->verifyId;
  7248. $data ['executeId'] = $this->executeId;
  7249. $this->render ( "/admin/saea_reportList", $data );
  7250. }
  7251. function approvalDetails() {
  7252. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7253. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7254. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7255. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7256. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7257. Doo::loadModel ( 'verify' );
  7258. $verify = new verify ();
  7259. Doo::loadModel ( 'receipt' );
  7260. $receipt = new receipt ();
  7261. Doo::loadModel ( 'staff' );
  7262. $staff = new staff ();
  7263. Doo::loadModel ( 'L_category' );
  7264. $Lcategory = new L_category ();
  7265. Doo::loadModel ( 'enclosur' );
  7266. $enclosur = new enclosur ();
  7267. $vidList = array ();
  7268. $verifyDetail = $verify->find ( array (
  7269. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7270. 'asArray' => true
  7271. ) );
  7272. foreach ( $verifyDetail as $key => $value ) {
  7273. array_push ( $vidList, $value ['vid'] );
  7274. }
  7275. $vid = implode ( ",", $vidList );
  7276. if (empty ( $verifyDetail ))
  7277. $vid = 0;
  7278. $categoryList = $Lcategory->find ( array (
  7279. 'asArray' => true
  7280. ) );
  7281. $staffList = $staff->find ( array (
  7282. 'where' => 'cid=' . $cid,
  7283. 'asArray' => true
  7284. ) );
  7285. $ap = 0;
  7286. $receiptList = $receipt->find ( array (
  7287. 'where' => 'rid =' . $rid,
  7288. 'desc' => 'rid',
  7289. 'asArray' => true
  7290. ) );
  7291. $Locate = 0;
  7292. $roleId = 0;
  7293. $button = 0;
  7294. foreach ( $receiptList as $key => $value ) {
  7295. $receiptList [$key] ['Locate'] = $Locate;
  7296. $Locate ++;
  7297. $receiptList [$key] ['reviseDetail'] = array ();
  7298. if (! empty ( $value ['reviseDetail'] ))
  7299. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7300. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7301. $categoryDetil = $Lcategory->getOne ( array (
  7302. 'where' => 'cid=' . $value ['cid'],
  7303. 'asArray' => true
  7304. ) );
  7305. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7306. // 检测编辑状态
  7307. $verifyList = $verify->getOne ( array (
  7308. 'where' => 'vid=' . $value ['verify'],
  7309. 'asArray' => true
  7310. ) );
  7311. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7312. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7313. Doo::loadModel ( 'role' );
  7314. $role = new role ();
  7315. // print_r($verifyList);
  7316. $flag = true;
  7317. $roleKey = 0;
  7318. $endStaffArray = array ();
  7319. $roleArrayCopy = array ();
  7320. foreach ( $verifyList as $k => $v ) {
  7321. // init verifyStaff
  7322. if ($v [1] == 'ROLE') {
  7323. if (! empty ( $verifyStaff )) {
  7324. $endStaffArray = end ( $verifyStaff );
  7325. if ($v [0] == $endStaffArray ['nextStaff']) {
  7326. $roleId = $v [0];
  7327. }
  7328. }
  7329. $roleVerify = json_decode ( $v [3], true );
  7330. $roleKey = $k;
  7331. $roleArray = array ();
  7332. $rolename = $role->getOne ( array (
  7333. 'where' => 'rid=' . $v [0],
  7334. 'asArray' => true
  7335. ) );
  7336. foreach ( $roleVerify as $o => $p ) {
  7337. $staffID = explode ( '_', $p );
  7338. $staffInfo = $staff->getOne ( array (
  7339. 'where' => 'sid=' . $staffID [0],
  7340. 'asArray' => true
  7341. ) );
  7342. // print_r($staffID);
  7343. $exp = array (
  7344. 0 => $staffInfo ['sid'],
  7345. 1 => $staffID [1],
  7346. 2 => $staffInfo ['avatar'],
  7347. 'date' => '',
  7348. 'date' => '',
  7349. 'opinion' => '',
  7350. 'status' => '',
  7351. 'rolename' => $rolename ['name']
  7352. );
  7353. array_push ( $roleArray, $exp );
  7354. }
  7355. $roleArrayCopy [$v [0]] = $roleArray;
  7356. // $verifyList[$k]['roleArray']=$roleArray;
  7357. }
  7358. // print_r($roleArray);
  7359. $verifyList [$k] ['date'] = "";
  7360. $verifyList [$k] ['opinion'] = "";
  7361. $verifyList [$k] ['status'] = "";
  7362. if (empty ( $verifyStaff )) {
  7363. $verifyList [$k] ['date'] = "";
  7364. $verifyList [$k] ['opinion'] = "";
  7365. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7366. $verifyList [$k] ['status'] = 4;
  7367. $button = 4;
  7368. $flag = false;
  7369. }
  7370. } else {
  7371. foreach ( $verifyStaff as $m => $u ) {
  7372. if ($v [0] == $m) {
  7373. $verifyList [$k] ['date'] = $u ['date'];
  7374. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7375. $verifyList [$k] ['status'] = $u ['status'];
  7376. $flag = false;
  7377. break;
  7378. }
  7379. }
  7380. $endStaffArray = end ( $verifyStaff );
  7381. if (isset ( $endStaffArray ['ROLE'] )) {
  7382. } else {
  7383. $endKey = key ( $verifyStaff );
  7384. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7385. $button = 4;
  7386. $verifyList [$k] ['status'] = 4;
  7387. }
  7388. }
  7389. }
  7390. }
  7391. $rolename ['name'] = '';
  7392. if (! empty ( $roleId )) {
  7393. Doo::loadModel ( 'role' );
  7394. $role = new role ();
  7395. $rolename = $role->getOne ( array (
  7396. 'where' => 'rid=' . $roleId,
  7397. 'asArray' => true
  7398. ) );
  7399. }
  7400. if (! empty ( $verifyStaff ))
  7401. $endStaffArray = end ( $verifyStaff );
  7402. $KOP = false;
  7403. foreach ( $roleArrayCopy as $P => $A ) {
  7404. foreach ( $A as $MKI => $AVL ) {
  7405. if (! empty ( $verifyStaff )) {
  7406. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7407. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7408. $button = 4;
  7409. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7410. }
  7411. foreach ( $verifyStaff as $m => $u ) {
  7412. $AVLFK = $AVL [0] . '_R';
  7413. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7414. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7415. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7416. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7417. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7418. break;
  7419. }
  7420. }
  7421. } else {
  7422. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7423. $button = 4;
  7424. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7425. }
  7426. }
  7427. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7428. $KOP = true;
  7429. }
  7430. }
  7431. foreach ( $roleArrayCopy as $k => $v ) {
  7432. foreach ( $verifyList as $m => $n ) {
  7433. if ($n [0] == $k) {
  7434. array_splice ( $verifyList, $m, 1, $v );
  7435. }
  7436. }
  7437. }
  7438. $receiptList [$key] ['verifyList'] = $verifyList;
  7439. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7440. 'where' => 'sid=' . $value ['staff'],
  7441. 'asArray' => true
  7442. ) );
  7443. $receiptList [$key] ['button'] = $button;
  7444. }
  7445. $mothHtml = "";
  7446. for($i = 1; $i <= 12; $i ++) {
  7447. if ($month == $i)
  7448. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7449. else
  7450. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7451. }
  7452. // 获取审批日志
  7453. Doo::loadModel ( 'receiptLog' );
  7454. $receiptLog = new receiptLog ();
  7455. $rlList = array ();
  7456. $rlInfo = $receiptLog->getOne ( array (
  7457. 'where' => 'rid=' . $rid . ' and status=4',
  7458. 'asArray' => true
  7459. ) );
  7460. $tijdate = $receiptLog->getOne ( array (
  7461. 'where' => 'rid=' . $rid . ' and status=2',
  7462. 'asc' => 'rlid',
  7463. 'asArray' => true
  7464. ) );
  7465. if (! empty ( $rlInfo )) {
  7466. $rlList = $receiptLog->find ( array (
  7467. 'where' => 'rid=' . $rid,
  7468. 'asc' => 'rlid',
  7469. 'asArray' => true
  7470. ) );
  7471. }
  7472. $receiptList [0] ['rlList'] = $rlList;
  7473. $enclosurList = $enclosur->find ( array (
  7474. 'where' => 'rid=' . $rid,
  7475. 'asArray' => true
  7476. ) );
  7477. $enclosurHtml = '';
  7478. foreach ( $enclosurList as $value ) {
  7479. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7480. }
  7481. $data ['enclosurHtml'] = $enclosurHtml;
  7482. $data ['rolename'] = $rolename ['name'];
  7483. $data ['datetij'] = $tijdate ['date'];
  7484. $data ['mothHtml'] = $mothHtml;
  7485. $data ['receiptList'] = $receiptList;
  7486. $data ['receiptApprovalCount'] = count ( $receiptList );
  7487. $data ['year'] = $year;
  7488. $data ['categoryList'] = $categoryList;
  7489. $data ['staffList'] = $staffList;
  7490. $data ['cid'] = $cid;
  7491. $data ['sid'] = $sid;
  7492. $data ['status'] = 0;
  7493. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7494. $ap = 4;
  7495. } else
  7496. $data ['status'] = $receiptList [0] ['status'];
  7497. if ($receiptList [0] ['status'] == 4) {
  7498. $data ['status'] = 5;
  7499. $ap = 0;
  7500. }
  7501. $data ['ap'] = $ap;
  7502. $data ['memu'] = "receipt";
  7503. $data ['staff'] = $this->staff;
  7504. $data ['receiptMemu'] = 'approval';
  7505. $data ['verifyId'] = $this->verifyId;
  7506. $data ['executeId'] = $this->executeId;
  7507. $this->render ( "/admin/saeaReportListReport", $data );
  7508. }
  7509. function approvalEdi() {
  7510. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7511. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7512. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7513. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7514. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7515. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7516. if (empty ( $status ))
  7517. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7518. $vidList = array ();
  7519. $button = 0;
  7520. Doo::loadModel ( 'verify' );
  7521. Doo::loadModel ( 'receipt' );
  7522. Doo::loadModel ( 'staff' );
  7523. $staff = new staff ();
  7524. $receipt = new receipt ();
  7525. $verify = new verify ();
  7526. Doo::loadModel ( 'L_category' );
  7527. $Lcategory = new L_category ();
  7528. Doo::loadModel ( 'enclosur' );
  7529. $enclosur = new enclosur ();
  7530. // user verify ID
  7531. $verifyDetail = $verify->find ( array (
  7532. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7533. 'asArray' => true
  7534. ) );
  7535. foreach ( $verifyDetail as $key => $value ) {
  7536. array_push ( $vidList, $value ['vid'] );
  7537. }
  7538. $vid = implode ( ",", $vidList );
  7539. if (empty ( $verifyDetail ))
  7540. $vid = 0;
  7541. $categoryList = $Lcategory->find ( array (
  7542. 'asArray' => true
  7543. ) );
  7544. $staffList = $staff->find ( array (
  7545. 'where' => 'cid=' . $cid,
  7546. 'asArray' => true
  7547. ) );
  7548. $ap = "";
  7549. if ($status == 4) {
  7550. $ap = 4;
  7551. $status = 2;
  7552. }
  7553. // get Receipt By verifyID status 2
  7554. $receiptList = $receipt->find ( array (
  7555. 'where' => 'rid =' . $rid,
  7556. 'desc' => 'rid',
  7557. 'asArray' => true
  7558. ) );
  7559. $Locate = 0;
  7560. $roleId = 0;
  7561. if ($ap == 4)
  7562. $status = 4;
  7563. foreach ( $receiptList as $key => $value ) {
  7564. $receiptList [$key] ['Locate'] = $Locate;
  7565. $Locate ++;
  7566. $receiptList [$key] ['reviseDetail'] = array ();
  7567. if (! empty ( $value ['reviseDetail'] ))
  7568. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7569. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7570. $categoryDetil = $Lcategory->getOne ( array (
  7571. 'where' => 'cid=' . $value ['cid'],
  7572. 'asArray' => true
  7573. ) );
  7574. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7575. // 检测编辑状态
  7576. $verifyList = $verify->getOne ( array (
  7577. 'where' => 'vid=' . $value ['verify'],
  7578. 'asArray' => true
  7579. ) );
  7580. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7581. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7582. // print_r($verifyList);
  7583. //
  7584. // if (empty($verifyStaff)){
  7585. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7586. // $verifyList[0]['status']=4;$button=4;
  7587. // }
  7588. //
  7589. // }else{
  7590. //
  7591. // }
  7592. // die;
  7593. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7594. // echo array_search("green",$a);
  7595. //
  7596. Doo::loadModel ( 'role' );
  7597. $role = new role ();
  7598. // print_r($verifyList);
  7599. $flag = true;
  7600. $roleKey = 0;
  7601. $endStaffArray = array ();
  7602. $roleArrayCopy = array ();
  7603. foreach ( $verifyList as $k => $v ) {
  7604. // init verifyStaff
  7605. if ($v [1] == 'ROLE') {
  7606. if (! empty ( $verifyStaff )) {
  7607. $endStaffArray = end ( $verifyStaff );
  7608. if ($v [0] == $endStaffArray ['nextStaff']) {
  7609. $roleId = $v [0];
  7610. }
  7611. }
  7612. $roleVerify = json_decode ( $v [3], true );
  7613. $roleKey = $k;
  7614. $roleArray = array ();
  7615. $rolename = $role->getOne ( array (
  7616. 'where' => 'rid=' . $v [0],
  7617. 'asArray' => true
  7618. ) );
  7619. foreach ( $roleVerify as $o => $p ) {
  7620. $staffID = explode ( '_', $p );
  7621. $staffInfo = $staff->getOne ( array (
  7622. 'where' => 'sid=' . $staffID [0],
  7623. 'asArray' => true
  7624. ) );
  7625. // print_r($staffID);
  7626. $exp = array (
  7627. 0 => $staffInfo ['sid'],
  7628. 1 => $staffID [1],
  7629. 2 => $staffInfo ['avatar'],
  7630. 'date' => '',
  7631. 'date' => '',
  7632. 'opinion' => '',
  7633. 'status' => '',
  7634. 'rolename' => $rolename ['name']
  7635. );
  7636. array_push ( $roleArray, $exp );
  7637. }
  7638. $roleArrayCopy [$v [0]] = $roleArray;
  7639. // $verifyList[$k]['roleArray']=$roleArray;
  7640. }
  7641. // print_r($roleArray);
  7642. $verifyList [$k] ['date'] = "";
  7643. $verifyList [$k] ['opinion'] = "";
  7644. $verifyList [$k] ['status'] = "";
  7645. if (empty ( $verifyStaff )) {
  7646. $verifyList [$k] ['date'] = "";
  7647. $verifyList [$k] ['opinion'] = "";
  7648. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7649. $verifyList [$k] ['status'] = 4;
  7650. $button = 4;
  7651. $flag = false;
  7652. }
  7653. } else {
  7654. foreach ( $verifyStaff as $m => $u ) {
  7655. if ($v [0] == $m) {
  7656. $verifyList [$k] ['date'] = $u ['date'];
  7657. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7658. $verifyList [$k] ['status'] = $u ['status'];
  7659. $flag = false;
  7660. break;
  7661. }
  7662. }
  7663. $endStaffArray = end ( $verifyStaff );
  7664. if (isset ( $endStaffArray ['ROLE'] )) {
  7665. } else {
  7666. $endKey = key ( $verifyStaff );
  7667. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7668. $button = 4;
  7669. $verifyList [$k] ['status'] = 4;
  7670. }
  7671. }
  7672. // print_r($endStaffArray);die;
  7673. // if (empty($verifyStaff)){
  7674. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7675. // $verifyList[$k]['status']=4;$button=4;
  7676. // }
  7677. //
  7678. // }else{
  7679. //
  7680. // }
  7681. // if($flag){//检测可编辑
  7682. // if($v[0]==$this->staff[0]['sid']){
  7683. // $verifyList[$k]['status']=4;$button=4;
  7684. // }
  7685. // }
  7686. }
  7687. }
  7688. $rolename ['name'] = '';
  7689. if (! empty ( $roleId )) {
  7690. Doo::loadModel ( 'role' );
  7691. $role = new role ();
  7692. $rolename = $role->getOne ( array (
  7693. 'where' => 'rid=' . $roleId,
  7694. 'asArray' => true
  7695. ) );
  7696. }
  7697. if (! empty ( $verifyStaff ))
  7698. $endStaffArray = end ( $verifyStaff );
  7699. $KOP = false;
  7700. foreach ( $roleArrayCopy as $P => $A ) {
  7701. foreach ( $A as $MKI => $AVL ) {
  7702. if (! empty ( $verifyStaff )) {
  7703. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7704. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7705. $button = 4;
  7706. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7707. }
  7708. foreach ( $verifyStaff as $m => $u ) {
  7709. $AVLFK = $AVL [0] . '_R';
  7710. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7711. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7712. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7713. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7714. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7715. break;
  7716. }
  7717. }
  7718. } else {
  7719. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7720. $button = 4;
  7721. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7722. }
  7723. }
  7724. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7725. $KOP = true;
  7726. }
  7727. }
  7728. // print_r($roleArrayCopy);
  7729. // echo $roleKey;
  7730. foreach ( $roleArrayCopy as $k => $v ) {
  7731. foreach ( $verifyList as $m => $n ) {
  7732. if ($n [0] == $k) {
  7733. array_splice ( $verifyList, $m, 1, $v );
  7734. }
  7735. }
  7736. }
  7737. // if ($KOP)
  7738. // array_splice($verifyList,$roleKey,1,$roleArray);
  7739. // print_r($verifyList);
  7740. $receiptList [$key] ['verifyList'] = $verifyList;
  7741. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7742. 'where' => 'sid=' . $value ['staff'],
  7743. 'asArray' => true
  7744. ) );
  7745. $receiptList [$key] ['button'] = $button;
  7746. }
  7747. // $data['verifyDetail']=$verifyDetail;
  7748. $mothHtml = "";
  7749. for($i = 1; $i <= 12; $i ++) {
  7750. if ($month == $i)
  7751. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7752. else
  7753. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7754. }
  7755. // 获取审批日志
  7756. Doo::loadModel ( 'receiptLog' );
  7757. $receiptLog = new receiptLog ();
  7758. $rlList = array ();
  7759. $rlInfo = $receiptLog->getOne ( array (
  7760. 'where' => 'rid=' . $rid . ' and status=4',
  7761. 'asArray' => true
  7762. ) );
  7763. $tijdate = $receiptLog->getOne ( array (
  7764. 'where' => 'rid=' . $rid . ' and status=2',
  7765. 'asc' => 'rlid',
  7766. 'asArray' => true
  7767. ) );
  7768. if (! empty ( $rlInfo )) {
  7769. $rlList = $receiptLog->find ( array (
  7770. 'where' => 'rid=' . $rid,
  7771. 'asc' => 'rlid',
  7772. 'asArray' => true
  7773. ) );
  7774. }
  7775. $receiptList [0] ['rlList'] = $rlList;
  7776. $enclosurList = $enclosur->find ( array (
  7777. 'where' => 'rid=' . $rid,
  7778. 'asArray' => true
  7779. ) );
  7780. $enclosurHtml = '';
  7781. foreach ( $enclosurList as $value ) {
  7782. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7783. }
  7784. $data ['enclosurHtml'] = $enclosurHtml;
  7785. $data ['rolename'] = $rolename ['name'];
  7786. $data ['datetij'] = $tijdate ['date'];
  7787. $data ['mothHtml'] = $mothHtml;
  7788. $data ['receiptList'] = $receiptList;
  7789. $data ['receiptApprovalCount'] = count ( $receiptList );
  7790. $data ['status'] = $status;
  7791. $data ['year'] = $year;
  7792. $data ['categoryList'] = $categoryList;
  7793. $data ['staffList'] = $staffList;
  7794. $data ['cid'] = $cid;
  7795. $data ['sid'] = $sid;
  7796. $data ['ap'] = $ap;
  7797. $data ['memu'] = "receipt";
  7798. $data ['staff'] = $this->staff;
  7799. $data ['receiptMemu'] = 'approval';
  7800. $data ['verifyId'] = $this->verifyId;
  7801. $data ['executeId'] = $this->executeId;
  7802. $this->render ( "/admin/saeaReportListReport", $data );
  7803. }
  7804. function remittanceHky() {
  7805. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7806. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7807. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7808. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7809. $page_size = 15;
  7810. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7811. Doo::loadModel ( 'receipt' );
  7812. $receipt = new receipt ();
  7813. Doo::loadModel ( 'staff' );
  7814. $staff = new staff ();
  7815. $dateCondition = " and Year(executeDate) =" . $year;
  7816. if ($moth != 'MONTH')
  7817. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7818. if ($day != 'DAY' && $moth != 'MONTH')
  7819. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7820. $sql = ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition;
  7821. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7822. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7823. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7824. $dayList = $receipt->find ( array (
  7825. 'select' => 'executeDate,sum(amount) as amount',
  7826. 'where' => $sql,
  7827. 'desc' => 'executeDate',
  7828. 'groupby' => 'executeDate',
  7829. 'limit' => $limit,
  7830. 'asArray' => true
  7831. ) );
  7832. // print_r($dayList);
  7833. foreach ( $dayList as $key => $value ) {
  7834. $remitString = "";
  7835. $receiptList = $receipt->find ( array (
  7836. 'select' => 'rid,executeDate,amount,staff,cid',
  7837. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7838. 'desc' => 'executeDate',
  7839. 'asArray' => true
  7840. ) );
  7841. foreach ( $receiptList as $k => $v ) {
  7842. $sinfo = $staff->getOne ( array (
  7843. 'select' => 'username,category',
  7844. 'where' => ' sid=' . $v ['staff'],
  7845. 'asArray' => true
  7846. ) );
  7847. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7848. }
  7849. $dayList [$key] ['staff'] = $remitString;
  7850. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7851. }
  7852. // print_r($dayList);
  7853. $mothHtml = "";
  7854. for($i = 1; $i <= 12; $i ++) {
  7855. if ($moth == $i)
  7856. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7857. else
  7858. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7859. }
  7860. $dayHtml = "";
  7861. if ($day != "DAY" || $moth != "MONTH") {
  7862. for($i = 1; $i <= 31; $i ++) {
  7863. if ($day == $i)
  7864. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7865. else
  7866. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7867. }
  7868. }
  7869. $dateHtml = "";
  7870. $now = date ( "Y" );
  7871. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7872. if ($YEARD <= $now) {
  7873. $dateHtml .= '<option ';
  7874. if ($year == $YEARD) {
  7875. $dateHtml .= 'selected ';
  7876. }
  7877. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7878. }
  7879. }
  7880. $data ['dateHtml'] = $dateHtml;
  7881. $data ['page'] = $pageinfo;
  7882. $data ['year'] = $year;
  7883. $data ['moth'] = $moth;
  7884. $data ['day'] = $day;
  7885. $data ['get'] = $get;
  7886. $data ['dayHtml'] = $dayHtml;
  7887. $data ['mothHtml'] = $mothHtml;
  7888. $data ['receiptList'] = $dayList;
  7889. $data ['memu'] = "receipt";
  7890. $data ['staff'] = $this->staff;
  7891. $data ['receiptMemu'] = 'remittanceHky';
  7892. $data ['verifyId'] = $this->verifyId;
  7893. $data ['executeId'] = $this->executeId;
  7894. $this->render ( "/admin/remittanceHky", $data );
  7895. }
  7896. function remittancep() {
  7897. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7898. Doo::loadModel ( 'receipt' );
  7899. $receipt = new receipt ();
  7900. Doo::loadModel ( 'staff' );
  7901. $staff = new staff ();
  7902. Doo::loadClass ( 'XDeode' );
  7903. $XDeode = new XDeode ( 5 );
  7904. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7905. $rplist = $receipt->find ( array (
  7906. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7907. 'asArray' => true
  7908. ) );
  7909. $dayList = $receipt->find ( array (
  7910. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7911. 'desc' => 'executeDate',
  7912. 'groupby' => 'staff',
  7913. 'asArray' => true
  7914. ) );
  7915. $html = '';
  7916. foreach ( $dayList as $key => $value ) {
  7917. $sinfo = $staff->getOne ( array (
  7918. 'select' => 'username,category',
  7919. 'where' => ' sid=' . $value ['staff'],
  7920. 'asArray' => true
  7921. ) );
  7922. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  7923. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  7924. $au = 0;
  7925. foreach ( $rplist as $k => $v ) {
  7926. if ($value ['staff'] == $v ['staff']) {
  7927. $html .= '<tr><td><a href="#saea-detail" node-invoice="INFO" data-iskey="' . $XDeode->encode ( $v ['rid'] ) . '" data-toggle="modal">' . $v ['receiptOrder'] . '</a></td><td class="taR">¥' . $v ['amount'] . '</td></tr>';
  7928. $au += $v ['amount'];
  7929. }
  7930. }
  7931. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  7932. }
  7933. $data ['html'] = $html;
  7934. $data ['memu'] = "receipt";
  7935. $data ['staff'] = $this->staff;
  7936. $data ['receiptMemu'] = 'remittanceHky';
  7937. $data ['verifyId'] = $this->verifyId;
  7938. $data ['executeId'] = $this->executeId;
  7939. $this->render ( "/admin/remittancep", $data );
  7940. }
  7941. function ajaxGetReceiptDetails() {
  7942. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  7943. Doo::loadClass ( 'XDeode' );
  7944. $XDeode = new XDeode ( 5 );
  7945. $rid = $XDeode->decode ( $rid );
  7946. if (empty ( $rid )) {
  7947. echo json_encode ( array (
  7948. 'status' => 2,
  7949. 'msg' => 'illegal request'
  7950. ) );
  7951. die ();
  7952. }
  7953. Doo::loadModel ( 'receipt' );
  7954. $receipt = new receipt ();
  7955. Doo::loadModel ( 'staff' );
  7956. $staff = new staff ();
  7957. $rinfo = $receipt->getOne ( array (
  7958. 'where' => 'rid= ' . $rid,
  7959. 'asArray' => true
  7960. ) );
  7961. $sinfo = $staff->getOne ( array (
  7962. 'select' => 'username,category',
  7963. 'where' => ' sid=' . $rinfo ['staff'],
  7964. 'asArray' => true
  7965. ) );
  7966. $rinfo ['reviseDetail'] = array ();
  7967. if (! empty ( $rinfo ['reviseDetail'] ))
  7968. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  7969. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  7970. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  7971. $rinfo ['category'] = $sinfo ['category'];
  7972. $verifyStaff = array ();
  7973. if (! empty ( $rinfo ['verifyStaff'] ))
  7974. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  7975. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  7976. $rinfo ['relust'] = $relust;
  7977. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  7978. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  7979. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  7980. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  7981. // 费用执行人相关数据
  7982. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  7983. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  7984. foreach ( $executeCopy as $k => $v ) {
  7985. $executeCopy [$k] ['date'] = '';
  7986. $executeCopy [$k] ['opinion'] = '';
  7987. $executeCopy [$k] ['status'] = '';
  7988. if (! empty ( $executeStaff ))
  7989. foreach ( $executeStaff as $m => $u ) {
  7990. if ($v [0] == $m) {
  7991. $executeCopy [$k] ['date'] = $u ['date'];
  7992. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  7993. $executeCopy [$k] ['status'] = $u ['status'];
  7994. break;
  7995. }
  7996. }
  7997. }
  7998. $rinfo ['executeCopy'] = $executeCopy;
  7999. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8000. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8001. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8002. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8003. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8004. $html .= '<tr><th>' . $value ['name'] . '</th>
  8005. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8006. }
  8007. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8008. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8009. <tr><th class="taC" colspan="2">费用说明</th>
  8010. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8011. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8012. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8013. </tbody></table>';
  8014. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8015. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8016. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8017. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8018. $html .= '<tr><th>' . $value ['name'] . '</th>
  8019. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8020. }
  8021. $html .= '<tr><th class="taR">合计</th>
  8022. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8023. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8024. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8025. $html .= '<tr><th>' . $value ['name'] . '</th>
  8026. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8027. }
  8028. $html .= '<tr><th class="taR">合计</th>
  8029. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8030. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8031. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8032. $html .= '<tr><th>' . $value ['name'] . '</th>
  8033. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8034. }
  8035. $html .= '<tr><th class="taR">合计</th>
  8036. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8037. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8038. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8039. $html .= '<tr><th>' . $value ['name'] . '</th>
  8040. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8041. }
  8042. $html .= '<tr><th class="taR">合计</th>
  8043. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8044. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8045. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8046. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8047. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8048. }
  8049. $html .= '<tr><th class="taR">合计</th>
  8050. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8051. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8052. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8053. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8054. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8055. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8056. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8057. <tr';
  8058. if ($rinfo ['relust'] >= 0) {
  8059. $html .= 'class="success"';
  8060. } else {
  8061. $html .= 'class="error"';
  8062. }
  8063. $html .= '><td class="taR"><b>借款结余</b></td>
  8064. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8065. </tbody></table>
  8066. ';
  8067. }
  8068. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8069. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8070. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8071. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8072. $html .= '<tr><th>' . $value ['name'] . '</th>
  8073. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8074. }
  8075. $html .= '<tr><th class="taR">合计</th>
  8076. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8077. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8078. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8079. <tr><th class="taC" colspan="2">费用说明</th>
  8080. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8081. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8082. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8083. </tbody></table>';
  8084. } else {
  8085. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8086. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8087. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8088. $html .= '<tr><th>' . $value ['name'] . '</th>
  8089. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8090. }
  8091. $html .= '<tr><th class="taR">合计</th>
  8092. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8093. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8094. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8095. $html .= '<tr><th>' . $value ['name'] . '</th>
  8096. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8097. }
  8098. $html .= '<tr><th class="taR">合计</th>
  8099. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8100. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8101. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8102. $html .= '<tr><th>' . $value ['name'] . '</th>
  8103. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8104. }
  8105. $html .= '<tr><th class="taR">合计</th>
  8106. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8107. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8108. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8109. $html .= '<tr><th>' . $value ['name'] . '</th>
  8110. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8111. }
  8112. $html .= '<tr><th class="taR">合计</th>
  8113. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8114. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8115. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8116. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8117. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8118. }
  8119. $html .= '<tr><th class="taR">合计</th>
  8120. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8121. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8122. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8123. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8124. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8125. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8126. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8127. $html .= '</tbody></table>';
  8128. /*
  8129. * <table class="table table-bordered table-condensed table-hover"> <tbody> <tr><th colspan="2" class="taC">日常相关费用</th></tr> <!-- loop receiptList' value.accountItem.日常相关费用 --> <tr><th>{{receiptList' value' value.name}}</th><td width="140" class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptList' value.accountItem.cSum.agencySum}}</td></tr> <tr><th colspan="2" class="taC">差旅相关费用</th></tr> <!-- loop receiptDetail' value.accountItem.差旅相关费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.travelSum}}</td></tr> <tr><th colspan="2" class="taC">培训班费用</th></tr> <!-- loop receiptDetail' value.accountItem.培训班费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.trainSum}}</td></tr> <tr><th colspan="2" class="taC">其他</th></tr> <!-- loop receiptDetail' value.accountItem.其他 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.otherSum}}</td></tr> <tr><th colspan="2" class="taC">报销金额调整</th></tr> <!-- loop receiptList' value.reviseDetail --> <tr><th><span class="interval">|</span>{{receiptList' value' value.name}}:{{receiptList' value' value.description}}</th><td class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colOrange taR">¥{{receiptList' value.revisePrice}}</td></tr> <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr> <tr><th style="text-align:center" colspan="2">{{receiptDetail' value.category}}</th></tr> <tr><th class="taC" colspan="2">报销说明</th></tr> <tr><td colspan="2">{{receiptDetail' value.explanation}}</td></tr> <tr class="warning"><td class="taR"><b>({{receiptDetail' value.receiptOrder}})本次报销费用合计</b></td> <td class="colGreed taR"><b style="font-size:24px">¥{{receiptDetail' value.sum}}</b><br>{{receiptDetail' value.sumCN}}</td></tr> </tbody> </table>
  8130. */
  8131. }
  8132. // print_r($verifyStaff);die;
  8133. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8134. foreach ( $verifyStaff as $key => $value ) {
  8135. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8136. $sinfo = $staff->getOne ( array (
  8137. 'select' => 'username',
  8138. 'where' => ' sid=' . $key,
  8139. 'asArray' => true
  8140. ) );
  8141. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8142. }
  8143. $html .= '</tbody></table>';
  8144. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8145. foreach ( $rinfo ['executeCopy'] as $value ) {
  8146. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8147. }
  8148. $html .= '</tbody></table>';
  8149. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8150. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8151. </tr></table>';
  8152. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8153. echo json_encode ( array (
  8154. 'status' => 1,
  8155. 'html' => $html
  8156. ) );
  8157. die ();
  8158. }
  8159. /**
  8160. * 删除附件
  8161. */
  8162. function ajaxRemEnclousur() {
  8163. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8164. if (empty ( $key ))
  8165. echo json_encode ( array (
  8166. 'status' => 2
  8167. ) );
  8168. Doo::loadModel ( 'enclosur' );
  8169. $enclosur = new enclosur ();
  8170. $enclosur->delEnclosurByEid ( $key );
  8171. echo json_encode ( array (
  8172. 'status' => 1
  8173. ) );
  8174. }
  8175. function remittance() {
  8176. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8177. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8178. Doo::loadModel ( 'receipt' );
  8179. $receipt = new receipt ();
  8180. Doo::loadModel ( 'staff' );
  8181. $staff = new staff ();
  8182. $dateCondition = " and Year(pastDate) =" . $year;
  8183. if (! empty ( $month ))
  8184. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8185. // get Receipt By verifyID status 1
  8186. $receiptList = $receipt->find ( array (
  8187. 'select' => 'sum(sum) as sum,staff,pastDate',
  8188. 'where' => ' status=1' . $dateCondition,
  8189. 'desc' => 'pastDate',
  8190. 'groupby' => 'staff,pastDate',
  8191. 'asArray' => true
  8192. ) );
  8193. $dateList = $receipt->find ( array (
  8194. 'select' => 'pastDate,verifyStaff',
  8195. 'where' => ' status=1' . $dateCondition,
  8196. 'desc' => 'pastDate',
  8197. 'groupby' => 'pastDate',
  8198. 'asArray' => true
  8199. ) );
  8200. $dataList = array ();
  8201. foreach ( $dateList as $d => $a ) {
  8202. $dataList [$a ['pastDate']] = array ();
  8203. $daySum = 0;
  8204. foreach ( $receiptList as $key => $value ) {
  8205. if ($a ['pastDate'] == $value ['pastDate']) {
  8206. $oderList = $receipt->find ( array (
  8207. 'select' => 'receiptOrder',
  8208. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8209. 'asArray' => true
  8210. ) );
  8211. $list = array ();
  8212. $html = "";
  8213. foreach ( $oderList as $v ) {
  8214. array_push ( $list, $v ['receiptOrder'] );
  8215. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8216. }
  8217. $receiptList [$key] ['receiptOrder'] = $html;
  8218. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8219. $sinfo = $staff->getOne ( array (
  8220. 'select' => 'username ',
  8221. 'where' => ' sid=' . $value ['staff'],
  8222. 'asArray' => true
  8223. ) );
  8224. $receiptList [$key] ['username'] = $sinfo ['username'];
  8225. $daySum += $value ['sum'];
  8226. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8227. }
  8228. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8229. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8230. }
  8231. }
  8232. // print_r($dataList);
  8233. $data ['dataList'] = $dataList;
  8234. $mothHtml = "";
  8235. for($i = 1; $i <= 12; $i ++) {
  8236. if ($month == $i)
  8237. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8238. else
  8239. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8240. }
  8241. $data ['year'] = $year;
  8242. $data ['mothHtml'] = $mothHtml;
  8243. $data ['memu'] = "receipt";
  8244. $data ['staff'] = $this->staff;
  8245. $data ['receiptMemu'] = 'approval';
  8246. $data ['verifyId'] = $this->verifyId;
  8247. $data ['executeId'] = $this->executeId;
  8248. $this->render ( "/admin/saeaReportListPay", $data );
  8249. }
  8250. /**
  8251. * 金额调整,提高稳定性
  8252. * @return string
  8253. */
  8254. function revocationAdjustment() {
  8255. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8256. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8257. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8258. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8259. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8260. Doo::loadClass ( 'XDeode' );
  8261. $XDeode = new XDeode ( 5 );
  8262. Doo::loadModel ( 'receipt' );
  8263. $receipt = new receipt ();
  8264. $sid = $XDeode->decode ( $sidKey );
  8265. $rid = $XDeode->decode ( $ridKey );
  8266. $reviseKey = $XDeode->decode ( $reviseKey );
  8267. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8268. die ( 'illegal request' );
  8269. $receiptDetail = $receipt->getOne ( array (
  8270. 'where' => 'rid=' . $rid,
  8271. 'asArray' => true
  8272. ) );
  8273. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8274. die ( 'illegal request' );
  8275. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8276. if (! isset ( $reviseDetail [$reviseKey] ))
  8277. die ( 'illegal request' );
  8278. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8279. unset ( $reviseDetail [$reviseKey] );
  8280. $revisePrice = 0;
  8281. foreach ( $reviseDetail as $key => $value ) {
  8282. $revisePrice += $value ['price'];
  8283. }
  8284. $reviseDetailString = json_encode ( $reviseDetail );
  8285. $receipt->reviseDetail = $reviseDetailString;
  8286. $receipt->sum = $receiptDetail ['sum'] - $price;
  8287. $receipt->revisePrice = $revisePrice;
  8288. $receipt->update ( array (
  8289. 'where' => 'rid=' . $rid
  8290. ) );
  8291. return '/receiptburEdi/' . $rid;
  8292. } else
  8293. die ( 'illegal request2' );
  8294. }
  8295. function updateApprovalReceipt() {
  8296. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8297. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8298. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8299. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8300. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8301. if (! empty ( $rid )) {
  8302. Doo::loadModel ( "verify" );
  8303. $verify = new verify ();
  8304. Doo::loadModel ( "receiptDetail" );
  8305. $receiptDetailObj = new receiptDetail ();
  8306. Doo::loadModel ( "itemStatistics" );
  8307. Doo::loadModel ( "statistics" );
  8308. $statistics = new statistics ();
  8309. $itemStatistics = new itemStatistics ();
  8310. Doo::loadModel ( "receipt" );
  8311. $receipt = new receipt ();
  8312. $receiptDetail = $receipt->getOne ( array (
  8313. 'where' => 'rid=' . $rid . ' and status=2 ',
  8314. 'asArray' => true
  8315. ) );
  8316. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8317. $nsflag = true;
  8318. foreach ( $nslist as $value ) {
  8319. if ($value == $this->staff ['0'] ['sid']) {
  8320. $nsflag = false;
  8321. break;
  8322. }
  8323. }
  8324. if (empty ( $receiptDetail ) || $nsflag)
  8325. return "/approvalExpenses/pendApproval";
  8326. $verifyDetail = $verify->getOne ( array (
  8327. 'where' => ' vid =' . $receiptDetail ['verify'],
  8328. 'asArray' => true
  8329. ) );
  8330. $verifyString = $verifyDetail ['staff'];
  8331. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8332. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8333. if (empty ( $opinion )) {
  8334. if ($status == 3)
  8335. $opinion = "终止";
  8336. else
  8337. $opinion = "同意支付";
  8338. }
  8339. $nowStaff = 0;
  8340. $nowStaffList = array ();
  8341. if (empty ( $verifyStaff )) {
  8342. // 还需加入是否已经进入角色审批
  8343. if ($verifyDetail [0] [1] == 'ROLE') {
  8344. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8345. foreach ( $vStaffString as $key => $value ) {
  8346. $staffK = explode ( "_", $value );
  8347. if ($staffK [0] != $this->staff [0] ['sid'])
  8348. array_push ( $nowStaffList, $staffK [0] );
  8349. }
  8350. // print_r($verifyDetail);
  8351. // die;
  8352. if (! empty ( $nowStaffList )) {
  8353. $nowStaff = implode ( ',', $nowStaffList );
  8354. $verifyStaff = array (
  8355. $this->staff [0] ['sid'] . "_R" => array (
  8356. 'date' => date ( 'Y-m-d' ),
  8357. 'opinion' => $opinion,
  8358. 'status' => $status,
  8359. 'nextStaff' => $verifyDetail [0] [0],
  8360. 'ROLE' => 1
  8361. )
  8362. );
  8363. } else {
  8364. $nowStaff = $verifyDetail [1] [0];
  8365. $verifyStaff = array (
  8366. $this->staff [0] ['sid'] . "_R" => array (
  8367. 'date' => date ( 'Y-m-d' ),
  8368. 'opinion' => $opinion,
  8369. 'status' => $status,
  8370. 'nextStaff' => $verifyDetail [1] [0]
  8371. )
  8372. );
  8373. }
  8374. } else {
  8375. if ($verifyDetail [1] [1] == 'ROLE') {
  8376. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8377. // echo "dd";
  8378. foreach ( $vStaffString as $key => $value ) {
  8379. $staffK = explode ( "_", $value );
  8380. array_push ( $nowStaffList, $staffK [0] );
  8381. }
  8382. $nowStaff = implode ( ',', $nowStaffList );
  8383. $verifyStaff = array (
  8384. $this->staff [0] ['sid'] => array (
  8385. 'date' => date ( 'Y-m-d' ),
  8386. 'opinion' => $opinion,
  8387. 'status' => $status,
  8388. 'nextStaff' => $verifyDetail [1] [0],
  8389. 'ROLE' => 1
  8390. )
  8391. );
  8392. } else {
  8393. $nowStaff = $verifyDetail [1] [0];
  8394. $verifyStaff = array (
  8395. $this->staff [0] ['sid'] => array (
  8396. 'date' => date ( 'Y-m-d' ),
  8397. 'opinion' => $opinion,
  8398. 'status' => $status,
  8399. 'nextStaff' => $verifyDetail [1] [0]
  8400. )
  8401. );
  8402. }
  8403. }
  8404. if ($status == 3)
  8405. $verifyStaff = array (
  8406. 'final' => $status,
  8407. $this->staff [0] ['sid'] => array (
  8408. 'date' => date ( 'Y-m-d' ),
  8409. 'opinion' => $opinion,
  8410. 'status' => $status
  8411. )
  8412. );
  8413. $vStaffString = json_encode ( $verifyStaff );
  8414. $receipt->nowStaff = $nowStaff;
  8415. $receipt->verifyStaff = $vStaffString;
  8416. } else {
  8417. $VS = end ( $verifyStaff );
  8418. // 非角色审批
  8419. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8420. $nextStaff = 0;
  8421. $roleSTF = false;
  8422. foreach ( $verifyDetail as $key => $value ) {
  8423. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8424. if (isset ( $verifyDetail [$key + 1] )) {
  8425. $nextStaff = $verifyDetail [$key + 1] [0];
  8426. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8427. $roleSTF = true;
  8428. }
  8429. break;
  8430. }
  8431. }
  8432. if (! $roleSTF) {
  8433. $nowStaff = $nextStaff;
  8434. $verifyStaff [$this->staff [0] ['sid']] = array (
  8435. 'date' => date ( 'Y-m-d' ),
  8436. 'opinion' => $opinion,
  8437. 'status' => $status,
  8438. 'nextStaff' => $nextStaff
  8439. );
  8440. } else {
  8441. // 获取角色下的所有用户ID
  8442. $nowStaffList = array ();
  8443. foreach ( $verifyDetail as $vfk ) {
  8444. if ($vfk [1] == 'ROLE') {
  8445. $vStaffString = json_decode ( $vfk [3] );
  8446. foreach ( $vStaffString as $key => $value ) {
  8447. $staffK = explode ( "_", $value );
  8448. array_push ( $nowStaffList, $staffK [0] );
  8449. }
  8450. }
  8451. }
  8452. $nowStaff = implode ( ',', $nowStaffList );
  8453. $verifyStaff [$this->staff [0] ['sid']] = array (
  8454. 'date' => date ( 'Y-m-d' ),
  8455. 'opinion' => $opinion,
  8456. 'status' => $status,
  8457. 'nextStaff' => $nextStaff,
  8458. 'ROLE' => 0
  8459. );
  8460. }
  8461. if ($status == 3) {
  8462. $verifyStaff ['final'] = $status;
  8463. $verifyStaff [$this->staff [0] ['sid']] = array (
  8464. 'date' => date ( 'Y-m-d' ),
  8465. 'opinion' => $opinion,
  8466. 'status' => $status
  8467. );
  8468. }
  8469. $vStaffString = json_encode ( $verifyStaff );
  8470. $receipt->nowStaff = $nowStaff;
  8471. $receipt->verifyStaff = $vStaffString;
  8472. }
  8473. // 角色审批
  8474. if (isset ( $VS ['ROLE'] )) {
  8475. // 找出角色人 当前审批角色组
  8476. $verifyJSStaff = array ();
  8477. $nowStaffList2 = array ();
  8478. foreach ( $verifyDetail as $key => $value ) {
  8479. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8480. $verifyJSStaff = json_decode ( $value [3] );
  8481. foreach ( $verifyJSStaff as $m ) {
  8482. $staffK = explode ( "_", $m );
  8483. array_push ( $nowStaffList2, $staffK [0] );
  8484. }
  8485. // print_r($nowStaffList2);
  8486. }
  8487. }
  8488. $RoleVerifyStaff = array ();
  8489. foreach ( $verifyStaff as $key => $value ) {
  8490. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8491. foreach ( $nowStaffList2 as $m ) {
  8492. if ($key == $m . "_R")
  8493. $RoleVerifyStaff [$key] = $value;
  8494. }
  8495. }
  8496. }
  8497. // print_r($verifyStaff);
  8498. // print_r($nowStaffList2);
  8499. // print_r($RoleVerifyStaff);
  8500. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8501. // print_r($verifyJSStaff);
  8502. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8503. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8504. // 下一个审批人ID
  8505. $nextStaff = 0;
  8506. $falg = false;
  8507. foreach ( $verifyDetail as $key => $value ) {
  8508. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8509. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8510. $falg = true;
  8511. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8512. $nowStaffList = array ();
  8513. foreach ( $vStaffString as $v ) {
  8514. $staffK = explode ( "_", $v );
  8515. array_push ( $nowStaffList, $staffK [0] );
  8516. }
  8517. $nowStaff = implode ( ',', $nowStaffList );
  8518. $nextStaff = $verifyDetail [$key + 1] [0];
  8519. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8520. $nextStaff = $verifyDetail [$key + 1] [0];
  8521. $nowStaff = $nextStaff;
  8522. } else
  8523. $nowStaff = '';
  8524. break;
  8525. }
  8526. }
  8527. if ($falg)
  8528. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8529. 'date' => date ( 'Y-m-d' ),
  8530. 'opinion' => $opinion,
  8531. 'status' => $status,
  8532. 'nextStaff' => $nextStaff,
  8533. 'ROLE' => 1
  8534. );
  8535. else
  8536. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8537. 'date' => date ( 'Y-m-d' ),
  8538. 'opinion' => $opinion,
  8539. 'status' => $status,
  8540. 'nextStaff' => $nextStaff
  8541. );
  8542. // print_r($verifyStaff);
  8543. // echo $nowStaff;die;
  8544. } else { // 进入下一个角色或者审批人
  8545. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8546. //
  8547. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8548. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8549. 'date' => date ( 'Y-m-d' ),
  8550. 'opinion' => $opinion,
  8551. 'status' => $status,
  8552. 'nextStaff' => $VS ['nextStaff'],
  8553. 'ROLE' => 1
  8554. );
  8555. // print_r($verifyStaff);
  8556. // die;
  8557. }
  8558. if ($status == 3) {
  8559. $verifyStaff ['final'] = $status;
  8560. $verifyStaff [$this->staff [0] ['sid']] = array (
  8561. 'date' => date ( 'Y-m-d' ),
  8562. 'opinion' => $opinion,
  8563. 'status' => $status
  8564. );
  8565. }
  8566. $vStaffString = json_encode ( $verifyStaff );
  8567. $receipt->verifyStaff = $vStaffString;
  8568. $receipt->nowStaff = $nowStaff;
  8569. // die;
  8570. // }
  8571. // print_r($verifyStaff);
  8572. // die;
  8573. }
  8574. // print_r($verifyStaff);die;
  8575. }
  8576. // print_r($verifyDetail);
  8577. $roleKey = 0;
  8578. $roleId = 0;
  8579. $verifyDetailCopy = array ();
  8580. foreach ( $verifyDetail as $k => $v ) {
  8581. if ($v [1] == 'ROLE') {
  8582. $roleId = $v [0];
  8583. $roleVerify = json_decode ( $v [3], true );
  8584. $roleKey = $k;
  8585. $roleArray = array ();
  8586. foreach ( $roleVerify as $o => $p ) {
  8587. $staffID = explode ( '_', $p );
  8588. $exp = array (
  8589. 0 => $staffID [0],
  8590. 1 => $staffID [1]
  8591. );
  8592. array_push ( $roleArray, $exp );
  8593. }
  8594. $verifyDetailCopy [$v [0]] = $roleArray;
  8595. }
  8596. }
  8597. // print_r($verifyDetail);
  8598. foreach ( $verifyDetailCopy as $k => $v ) {
  8599. foreach ( $verifyDetail as $m => $n ) {
  8600. if ($n [0] == $k) {
  8601. array_splice ( $verifyDetail, $m, 1, $v );
  8602. }
  8603. }
  8604. }
  8605. // die;
  8606. // if (!empty($roleArray))
  8607. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8608. // echo $roleId;
  8609. // print_r($verifyStaff);
  8610. // print_r($verifyDetail);
  8611. // die;
  8612. Doo::loadModel ( "receiptLog" );
  8613. $receiptLog = new receiptLog ();
  8614. // 审批日志
  8615. if (! isset ( $verifyStaff ['final'] )) {
  8616. if (! empty ( $roleId )) {
  8617. Doo::loadModel ( "role" );
  8618. $role = new role ();
  8619. $roleInfo = $role->getOne ( array (
  8620. 'where' => 'rid=' . $roleId,
  8621. 'asArray' => true
  8622. ) );
  8623. $receiptLog->rolename = $roleInfo ['name'];
  8624. }
  8625. $receiptLog->username = $this->staff [0] ['username'];
  8626. $receiptLog->uid = $this->staff [0] ['sid'];
  8627. $receiptLog->date = date ( "Y-m-d" );
  8628. $receiptLog->opinion = $opinion;
  8629. $receiptLog->img = $this->staff [0] ['avatar'];
  8630. $receiptLog->status = 1;
  8631. $receiptLog->rid = $rid;
  8632. $receiptLog->insert ();
  8633. }
  8634. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8635. $receipt->verifyBreakup = $verifyString;
  8636. $receipt->status = 3;
  8637. $receiptDetailObj->status = 3;
  8638. $receiptDetailObj->update ( array (
  8639. 'where' => 'rid=' . $rid
  8640. ) );
  8641. if (! empty ( $roleId )) {
  8642. Doo::loadModel ( "role" );
  8643. $role = new role ();
  8644. $roleInfo = $role->getOne ( array (
  8645. 'where' => 'rid=' . $roleId,
  8646. 'asArray' => true
  8647. ) );
  8648. $receiptLog->rolename = $roleInfo ['name'];
  8649. }
  8650. $receiptLog->username = $this->staff [0] ['username'];
  8651. $receiptLog->uid = $this->staff [0] ['sid'];
  8652. $receiptLog->date = date ( "Y-m-d" );
  8653. $receiptLog->opinion = $opinion;
  8654. $receiptLog->img = $this->staff [0] ['avatar'];
  8655. $receiptLog->status = 3;
  8656. $receiptLog->rid = $rid;
  8657. $receiptLog->insert ();
  8658. // 微信企业号通知
  8659. $this->setWXMsg ( $rid, 3 );
  8660. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8661. $receipt->status = 1;
  8662. $reviseSum = 0;
  8663. $receipt->verifyBreakup = $verifyString;
  8664. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8665. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8666. foreach ( $reviseDetail as $key => $value ) {
  8667. $receiptDetailObj = new receiptDetail ();
  8668. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8669. $receiptDetailObj->item = $value ['description'];
  8670. $receiptDetailObj->itemCategory = "报销金额调整";
  8671. $receiptDetailObj->price = $value ['price'];
  8672. $receiptDetailObj->date = $receiptDetail ['date'];
  8673. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8674. $receiptDetailObj->rid = $rid;
  8675. $receiptDetailObj->status = 1;
  8676. $receiptDetailObj->insert ();
  8677. $reviseSum += $value ['price'];
  8678. }
  8679. $itemStatistics = new itemStatistics ();
  8680. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8681. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8682. $itemStatistics->price = $reviseSum;
  8683. $itemStatistics->itemCategory = "报销金额调整";
  8684. $itemStatistics->date = $receiptDetail ['date'];
  8685. $itemStatistics->insert ();
  8686. }
  8687. $receiptDetailObj = new receiptDetail ();
  8688. $receiptDetailObj->status = 1;
  8689. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8690. $receiptDetailObj->update ( array (
  8691. 'where' => 'rid=' . $rid
  8692. ) );
  8693. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8694. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8695. $stat = $statistics->getOne ( array (
  8696. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8697. 'asArray' => true
  8698. ) );
  8699. if (empty ( $stat )) {
  8700. $statistics->date = $receiptDetail ['date'];
  8701. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8702. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8703. $statistics->agPrice = $receiptDetail ['sum'];
  8704. $statistics->rePrice = $reviseSum;
  8705. $statistics->insert ();
  8706. } else {
  8707. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8708. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8709. $statistics->update ( array (
  8710. 'where' => 'sid=' . $stat ['sid']
  8711. ) );
  8712. }
  8713. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8714. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8715. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8716. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8717. if ($key == "agencySum") {
  8718. $iStatistics = $itemStatistics->getOne ( array (
  8719. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8720. 'asArray' => true
  8721. ) );
  8722. if (empty ( $iStatistics )) {
  8723. $itemStatistics->cid = $receiptDetail ['cid'];
  8724. ;
  8725. $itemStatistics->staff = $receiptDetail ['staff'];
  8726. $itemStatistics->price = $value;
  8727. $itemStatistics->itemCategory = $this->AGENCY;
  8728. $itemStatistics->date = $receiptDetail ['date'];
  8729. $itemStatistics->insert ();
  8730. } else {
  8731. if (! empty ( $value )) {
  8732. $itemStatistics->price = $value + $iStatistics ['price'];
  8733. $itemStatistics->update ( array (
  8734. 'where' => 'sid=' . $iStatistics ['sid']
  8735. ) );
  8736. }
  8737. }
  8738. } elseif ($key == "travelSum") {
  8739. $iStatistics = $itemStatistics->getOne ( array (
  8740. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8741. 'asArray' => true
  8742. ) );
  8743. if (empty ( $iStatistics )) {
  8744. $itemStatistics->cid = $receiptDetail ['cid'];
  8745. $itemStatistics->staff = $receiptDetail ['staff'];
  8746. $itemStatistics->price = $value;
  8747. $itemStatistics->itemCategory = $this->TRAVEL;
  8748. $itemStatistics->date = $receiptDetail ['date'];
  8749. $itemStatistics->insert ();
  8750. } else {
  8751. if (! empty ( $value )) {
  8752. $itemStatistics->price = $value + $iStatistics ['price'];
  8753. $itemStatistics->update ( array (
  8754. 'where' => 'sid=' . $iStatistics ['sid']
  8755. ) );
  8756. }
  8757. }
  8758. } elseif ($key == "trainSum") {
  8759. $iStatistics = $itemStatistics->getOne ( array (
  8760. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8761. 'asArray' => true
  8762. ) );
  8763. if (empty ( $iStatistics )) {
  8764. $itemStatistics->cid = $receiptDetail ['cid'];
  8765. $itemStatistics->staff = $receiptDetail ['staff'];
  8766. $itemStatistics->price = $value;
  8767. $itemStatistics->itemCategory = $this->TRAIN;
  8768. $itemStatistics->date = $receiptDetail ['date'];
  8769. $itemStatistics->insert ();
  8770. } else {
  8771. if (! empty ( $value )) {
  8772. $itemStatistics->price = $value + $iStatistics ['price'];
  8773. $itemStatistics->update ( array (
  8774. 'where' => 'sid=' . $iStatistics ['sid']
  8775. ) );
  8776. }
  8777. }
  8778. } elseif ($key == "otherSum") {
  8779. $iStatistics = $itemStatistics->getOne ( array (
  8780. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8781. 'asArray' => true
  8782. ) );
  8783. if (empty ( $iStatistics )) {
  8784. $itemStatistics->cid = $receiptDetail ['cid'];
  8785. $itemStatistics->staff = $receiptDetail ['staff'];
  8786. $itemStatistics->price = $value;
  8787. $itemStatistics->itemCategory = $this->OTHER;
  8788. $itemStatistics->date = $receiptDetail ['date'];
  8789. $itemStatistics->insert ();
  8790. } else {
  8791. if (! empty ( $value )) {
  8792. $itemStatistics->price = $value + $iStatistics ['price'];
  8793. $itemStatistics->update ( array (
  8794. 'where' => 'sid=' . $iStatistics ['sid']
  8795. ) );
  8796. }
  8797. }
  8798. }
  8799. }
  8800. $receipt->pastDate = date ( "Y-m-d" );
  8801. // 微信企业号通知
  8802. $this->setWXMsg ( $rid, 1 );
  8803. }
  8804. //是否有流水
  8805. Doo::loadModel ( 'wasteBook' );
  8806. $wasteBook = new wasteBook ();
  8807. $accountType=3;
  8808. if ($receiptDetail['Rtype']==1){
  8809. $accountType=2;
  8810. }elseif($receiptDetail['Rtype']==2){
  8811. $accountType=4;
  8812. }
  8813. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8814. if (empty($wbDetail)){
  8815. $receipt->amount = $amount;
  8816. }
  8817. $receipt->update ( array (
  8818. 'where' => ' rid = ' . $rid
  8819. ) );
  8820. // 进入下一条审批费用新加需求
  8821. $vidList = array ();
  8822. $verifyDetail = $verify->find ( array (
  8823. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8824. 'asArray' => true
  8825. ) );
  8826. foreach ( $verifyDetail as $key => $value ) {
  8827. array_push ( $vidList, $value ['vid'] );
  8828. }
  8829. $vid = implode ( ",", $vidList );
  8830. if (empty ( $verifyDetail ))
  8831. $vid = 0;
  8832. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8833. $receipt = new receipt ();
  8834. $rd = $receipt->getOne ( array (
  8835. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8836. 'asc' => 'rid',
  8837. 'asArray' => true
  8838. ) );
  8839. if (empty ( $rd )) {
  8840. return '/approvalExpenses/pendApproval';
  8841. }
  8842. if ($rd ['Rtype'] == 1) {
  8843. if ($rd ['isBK'] == 1) {
  8844. return '/receiptburEdi/' . $rd ['rid'];
  8845. } else {
  8846. return '/expensesEdi/' . $rd ['rid'];
  8847. }
  8848. } elseif ($rd ['Rtype'] == 2) {
  8849. return '/remitApproval/' . $rd ['rid'];
  8850. } else {
  8851. return '/receiptburEdi/' . $rd ['rid'];
  8852. }
  8853. // return "/approvalExpenses/pendApproval";
  8854. }
  8855. }
  8856. function expensesRetreats() {
  8857. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8858. if (! empty ( $rid )) {
  8859. // 操作记录
  8860. Doo::loadModel ( "receipt" );
  8861. $receipt = new receipt ();
  8862. Doo::loadModel ( "receiptLog" );
  8863. $receiptLog = new receiptLog ();
  8864. Doo::loadModel ( "verify" );
  8865. $verify = new verify ();
  8866. $receiptInfo = $receipt->getOne ( array (
  8867. 'where' => 'rid=' . $rid,
  8868. 'asArray' => true
  8869. ) );
  8870. $vr = $verify->getOne ( array (
  8871. 'where' => 'vid=' . $receiptInfo ['verify'],
  8872. 'asArray' => true
  8873. ) );
  8874. $jd = json_decode ( $vr ['staff'] );
  8875. $roleId = 0;
  8876. foreach ( $jd as $key => $value ) {
  8877. if ($value [1] == 'ROLE') {
  8878. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8879. if ($pos !== false) {
  8880. $roleId = $value [0];
  8881. }
  8882. }
  8883. }
  8884. // 审批日志
  8885. // echo $roleId;die;
  8886. if (! empty ( $roleId )) {
  8887. Doo::loadModel ( "role" );
  8888. $role = new role ();
  8889. $roleInfo = $role->getOne ( array (
  8890. 'where' => 'rid=' . $roleId,
  8891. 'asArray' => true
  8892. ) );
  8893. $receiptLog->rolename = $roleInfo ['name'];
  8894. }
  8895. $receiptLog->username = $this->staff [0] ['username'];
  8896. $receiptLog->uid = $this->staff [0] ['sid'];
  8897. $receiptLog->date = date ( "Y-m-d" );
  8898. $receiptLog->opinion = '撤回';
  8899. $receiptLog->img = $this->staff [0] ['avatar'];
  8900. $receiptLog->status = 4;
  8901. $receiptLog->rid = $rid;
  8902. $receiptLog->insert ();
  8903. $receipt->status = 4;
  8904. $receipt->update ( array (
  8905. 'where' => 'rid=' . $rid
  8906. ) );
  8907. // 微信企业号通知
  8908. $this->setWXMsg ( $rid, 2 );
  8909. }
  8910. // echo "ddd";
  8911. return '/approvalExpenses/pendApproval';
  8912. }
  8913. function updateCheReceipt() {
  8914. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8915. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8916. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8917. if (! empty ( $rid )) {
  8918. // 操作记录
  8919. Doo::loadModel ( "receipt" );
  8920. $receipt = new receipt ();
  8921. Doo::loadModel ( "receiptLog" );
  8922. $receiptLog = new receiptLog ();
  8923. Doo::loadModel ( "verify" );
  8924. $verify = new verify ();
  8925. $receiptInfo = $receipt->getOne ( array (
  8926. 'where' => 'rid=' . $rid . ' and status=2',
  8927. 'asArray' => true
  8928. ) );
  8929. if (empty ( $receiptInfo )) {
  8930. echo json_encode ( array (
  8931. 'status' => 2
  8932. ) );
  8933. die ();
  8934. }
  8935. $vr = $verify->getOne ( array (
  8936. 'where' => 'vid=' . $receiptInfo ['verify'],
  8937. 'asArray' => true
  8938. ) );
  8939. $jd = json_decode ( $vr ['staff'] );
  8940. $roleId = 0;
  8941. foreach ( $jd as $key => $value ) {
  8942. if ($value [1] == 'ROLE') {
  8943. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8944. if ($pos !== false) {
  8945. $roleId = $value [0];
  8946. }
  8947. }
  8948. }
  8949. // 审批日志
  8950. // echo $roleId;die;
  8951. if (! empty ( $roleId )) {
  8952. Doo::loadModel ( "role" );
  8953. $role = new role ();
  8954. $roleInfo = $role->getOne ( array (
  8955. 'where' => 'rid=' . $roleId,
  8956. 'asArray' => true
  8957. ) );
  8958. $receiptLog->rolename = $roleInfo ['name'];
  8959. }
  8960. $receiptLog->username = $this->staff [0] ['username'];
  8961. $receiptLog->uid = $this->staff [0] ['sid'];
  8962. $receiptLog->date = date ( "Y-m-d" );
  8963. $receiptLog->opinion = $opinion;
  8964. $receiptLog->img = $this->staff [0] ['avatar'];
  8965. $receiptLog->status = 4;
  8966. $receiptLog->rid = $rid;
  8967. $receiptLog->insert ();
  8968. $receipt->status = 4;
  8969. $receipt->update ( array (
  8970. 'where' => 'rid=' . $rid
  8971. ) );
  8972. // 微信企业号通知
  8973. $this->setWXMsg ( $rid, 2 );
  8974. echo json_encode ( array (
  8975. 'status' => 1
  8976. ) );
  8977. // Header("HTTP/1.1 303 See Other");
  8978. // Header("Location: /approvalExpenses/pendApproval");
  8979. die ();
  8980. }
  8981. echo json_encode ( array (
  8982. 'status' => 2
  8983. ) );
  8984. die ();
  8985. // echo "ddd";
  8986. // return '/saeaBorad';
  8987. }
  8988. function revisePrice() {
  8989. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  8990. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  8991. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8992. // echo $price;die;
  8993. if (! empty ( $rid )) {
  8994. Doo::loadModel ( "receipt" );
  8995. $receipt = new receipt ();
  8996. $receiptDetail = $receipt->getOne ( array (
  8997. 'where' => 'rid=' . $rid . ' and status=2 ',
  8998. 'asArray' => true
  8999. ) );
  9000. if (empty ( $receiptDetail ))
  9001. die ( 'illegal request' );
  9002. $reviseDetail = array ();
  9003. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9004. array_push ( $reviseDetail, array (
  9005. 'sid' => $this->staff [0] ['sid'],
  9006. 'name' => $this->staff [0] ['username'],
  9007. 'description' => $description,
  9008. 'price' => $price
  9009. ) );
  9010. $reviseDetailString = json_encode ( $reviseDetail );
  9011. $receipt->reviseDetail = $reviseDetailString;
  9012. $receipt->revisePrice = $price;
  9013. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9014. } else {
  9015. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9016. array_push ( $reviseDetail, array (
  9017. 'sid' => $this->staff [0] ['sid'],
  9018. 'name' => $this->staff [0] ['username'],
  9019. 'description' => $description,
  9020. 'price' => $price
  9021. ) );
  9022. $reviseDetailString = json_encode ( $reviseDetail );
  9023. $receipt->reviseDetail = $reviseDetailString;
  9024. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9025. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9026. }
  9027. $receipt->update ( array (
  9028. 'where' => 'rid=' . $rid
  9029. ) );
  9030. if ($receiptDetail ['Rtype'] == 1) {
  9031. if ($receiptDetail ['isBK'] == 1) {
  9032. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9033. }
  9034. } elseif ($receiptDetail ['Rtype'] == 2) {
  9035. } else {
  9036. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9037. }
  9038. }
  9039. die ( 'illegal request' );
  9040. }
  9041. function personalCollect() {
  9042. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9043. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9044. $this->showCache ( $path );
  9045. Doo::loadModel ( "receiptDetail" );
  9046. Doo::loadModel ( "itemStatistics" );
  9047. Doo::loadModel ( 'statistics' );
  9048. $statistics = new statistics ();
  9049. $itemStatistics = new itemStatistics ();
  9050. $receiptDetail = new receiptDetail ();
  9051. $receiptCollectList = $receiptDetail->find ( array (
  9052. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9053. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9054. 'groupby' => 'itemCategory,Month(date)',
  9055. 'asArray' => true
  9056. ) );
  9057. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9058. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9059. 'asArray' => true
  9060. ) );
  9061. // create collect html
  9062. $collectArray = array (
  9063. '日常相关费用' => array (),
  9064. '差旅相关费用' => array (),
  9065. '培训班费用' => array (),
  9066. '其他' => array ()
  9067. );
  9068. $adjustment = array ();
  9069. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9070. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9071. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9072. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9073. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9074. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9075. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9076. array_push ( $collectArray ['其他'], $collectHtml );
  9077. $data ['collectArray'] = $collectArray;
  9078. // statistics html
  9079. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9080. if (empty ( $stList ))
  9081. $stList = array (
  9082. 'rePrice' => 0,
  9083. 'agPrice' => 0
  9084. );
  9085. $data ['stList'] = array (
  9086. 'rePrice' => $stList ['rePrice'],
  9087. 'agPrice' => $stList ['agPrice'],
  9088. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9089. );
  9090. // Adjustment price html
  9091. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9092. array_push ( $adjustment, $collectHtml );
  9093. $data ['adjustment'] = $adjustment;
  9094. // total price html
  9095. $collectHtml = "";
  9096. $total = 0;
  9097. for($i = 1; $i <= 12; $i ++) {
  9098. $sumPrice = 0;
  9099. foreach ( $receiptCollectList as $key => $value ) {
  9100. if ($value ['month'] == $i) {
  9101. $sumPrice += $value ['price'];
  9102. }
  9103. }
  9104. if ($sumPrice == 0)
  9105. $collectHtml .= '<td class="taR">-</td>';
  9106. else
  9107. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9108. $total += $sumPrice;
  9109. }
  9110. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9111. $data ['totalPrice'] = $collectHtml;
  9112. $dateHtml = "";
  9113. $now = date ( "Y" );
  9114. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9115. if ($YEARD <= $now) {
  9116. $dateHtml .= '<option ';
  9117. if ($year == $YEARD) {
  9118. $dateHtml .= 'selected ';
  9119. }
  9120. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9121. }
  9122. }
  9123. $data ['dateHtml'] = $dateHtml;
  9124. $data ['year'] = $year;
  9125. $data ['totalYear'] = $total;
  9126. $data ['memu'] = "receipt";
  9127. $data ['staff'] = $this->staff;
  9128. $data ['receiptMemu'] = 'personalCollect';
  9129. $data ['verifyId'] = $this->verifyId;
  9130. $data ['executeId'] = $this->executeId;
  9131. // year staff status 2,4
  9132. if ($year < date ( "Y" )) {
  9133. Doo::loadModel ( 'receipt' );
  9134. $receipt = new receipt ();
  9135. $receiptList = $receipt->find ( array (
  9136. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9137. 'asArray' => true
  9138. ) );
  9139. if (empty ( $receiptList )) {
  9140. ob_start ();
  9141. $this->render ( "/admin/saea_slist_collect", $data );
  9142. $this->cacheFile ( $path );
  9143. die ();
  9144. }
  9145. }
  9146. $this->render ( "/admin/saea_slist_collect", $data );
  9147. }
  9148. function personalCollectDetail() {
  9149. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9150. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9151. $this->showCache ( $path );
  9152. Doo::loadModel ( "receiptDetail" );
  9153. Doo::loadModel ( "itemStatistics" );
  9154. Doo::loadModel ( 'statistics' );
  9155. Doo::loadModel ( 'accountItem' );
  9156. $accountItem = new accountItem ();
  9157. $statistics = new statistics ();
  9158. $itemStatistics = new itemStatistics ();
  9159. $receiptDetail = new receiptDetail ();
  9160. $receiptCollectList = $receiptDetail->find ( array (
  9161. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9162. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9163. 'groupby' => 'item,Month(date)',
  9164. 'asArray' => true
  9165. ) );
  9166. $accountList = $accountItem->find ( array (
  9167. 'asArray' => true
  9168. ) );
  9169. // create CollectDetail HTML
  9170. $collectHtml = array ();
  9171. foreach ( $accountList as $key => $value ) {
  9172. $html = "";
  9173. $asum = 0;
  9174. for($i = 1; $i <= 12; $i ++) {
  9175. $falg = true;
  9176. foreach ( $receiptCollectList as $v ) {
  9177. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9178. $asum += $v ['price'];
  9179. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9180. $falg = false;
  9181. break;
  9182. }
  9183. }
  9184. if ($falg)
  9185. $html .= '<td class="taR">-</td>';
  9186. }
  9187. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9188. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9189. }
  9190. $data ['collectHtml'] = $collectHtml;
  9191. // create Adjustment price html
  9192. $receiptCollectList = $receiptDetail->find ( array (
  9193. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9194. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9195. 'groupby' => 'itemCategory,Month(date)',
  9196. 'asArray' => true
  9197. ) );
  9198. $adjustment = array ();
  9199. $collectArray = array (
  9200. '日常相关费用' => array (),
  9201. '差旅相关费用' => array (),
  9202. '培训班费用' => array (),
  9203. '其他' => array ()
  9204. );
  9205. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9206. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9207. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9208. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9209. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9210. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9211. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9212. array_push ( $collectArray ['其他'], $collectHtml );
  9213. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9214. array_push ( $adjustment, $collectHtml );
  9215. // total price html
  9216. $collectHtml = "";
  9217. $total = 0;
  9218. for($i = 1; $i <= 12; $i ++) {
  9219. $sumPrice = 0;
  9220. foreach ( $receiptCollectList as $key => $value ) {
  9221. if ($value ['month'] == $i) {
  9222. $sumPrice += $value ['price'];
  9223. }
  9224. }
  9225. if ($sumPrice == 0)
  9226. $collectHtml .= '<td class="taR">-</td>';
  9227. else
  9228. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9229. $total += $sumPrice;
  9230. }
  9231. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9232. // statistics html
  9233. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9234. if (empty ( $stList ))
  9235. $stList = array (
  9236. 'rePrice' => 0,
  9237. 'agPrice' => 0
  9238. );
  9239. $data ['stList'] = array (
  9240. 'rePrice' => $stList ['rePrice'],
  9241. 'agPrice' => $stList ['agPrice'],
  9242. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9243. );
  9244. $data ['collectArray'] = $collectArray;
  9245. $data ['adjustment'] = $adjustment;
  9246. $data ['totalPrice'] = $collectHtml;
  9247. $data ['totalYear'] = $total;
  9248. $data ['year'] = $year;
  9249. $dateHtml = "";
  9250. $now = date ( "Y" );
  9251. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9252. if ($YEARD <= $now) {
  9253. $dateHtml .= '<option ';
  9254. if ($year == $YEARD) {
  9255. $dateHtml .= 'selected ';
  9256. }
  9257. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9258. }
  9259. }
  9260. $data ['dateHtml'] = $dateHtml;
  9261. $data ['memu'] = "receipt";
  9262. $data ['staff'] = $this->staff;
  9263. $data ['receiptMemu'] = 'personalCollect';
  9264. $data ['verifyId'] = $this->verifyId;
  9265. $data ['executeId'] = $this->executeId;
  9266. // year staff status 2,4
  9267. if ($year < date ( "Y" )) {
  9268. Doo::loadModel ( 'receipt' );
  9269. $receipt = new receipt ();
  9270. $receiptList = $receipt->find ( array (
  9271. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9272. 'asArray' => true
  9273. ) );
  9274. if (empty ( $receiptList )) {
  9275. ob_start ();
  9276. $this->render ( "/admin/saeaCollectArticles", $data );
  9277. $this->cacheFile ( $path );
  9278. die ();
  9279. }
  9280. }
  9281. $this->render ( "/admin/saeaCollectArticles", $data );
  9282. }
  9283. function companyCategoryCollect() {
  9284. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9285. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9286. $this->showCache ( $path );
  9287. Doo::loadModel ( 'L_category' );
  9288. Doo::loadModel ( 'itemStatistics' );
  9289. Doo::loadModel ( 'statistics' );
  9290. $statistics = new statistics ();
  9291. $Lcategory = new L_category ();
  9292. $itemStatistics = new itemStatistics ();
  9293. Doo::loadModel ( "receiptAuthorityManage" );
  9294. $receiptAuthorityManage = new receiptAuthorityManage ();
  9295. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9296. $cidList = array ();
  9297. foreach ( $imcStaff as $key => $value ) {
  9298. array_push ( $cidList, $value ['cid'] );
  9299. }
  9300. $cidString = implode ( ',', $cidList );
  9301. $LcategoryList = $Lcategory->find ( array (
  9302. 'where' => ' cid in (' . $cidString . ')',
  9303. 'asArray' => true
  9304. ) ); // 'staff='.$this->staff[0]['sid']." and
  9305. $itemStatisticsList = $itemStatistics->find ( array (
  9306. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9307. 'where' => " Year(date)=" . $year,
  9308. 'groupby' => 'cid,Month(date)',
  9309. 'asArray' => true
  9310. ) );
  9311. // ceatre companyCollectHtml
  9312. foreach ( $LcategoryList as $value ) {
  9313. $html = "";
  9314. $asum = 0;
  9315. for($i = 1; $i <= 12; $i ++) {
  9316. $falg = true;
  9317. foreach ( $itemStatisticsList as $v ) {
  9318. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9319. $asum += $v ['price'];
  9320. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9321. $falg = false;
  9322. break;
  9323. }
  9324. }
  9325. if ($falg)
  9326. $html .= '<td class="taR">-</td>';
  9327. }
  9328. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9329. $collectHtml [$value ['title']] = array (
  9330. 'html' => $html,
  9331. 'cid' => $value ['cid']
  9332. );
  9333. }
  9334. $data ['companyHtml'] = $collectHtml;
  9335. // total price html
  9336. $collectHtml = "";
  9337. $total = 0;
  9338. for($i = 1; $i <= 12; $i ++) {
  9339. $sumPrice = 0;
  9340. foreach ( $itemStatisticsList as $key => $value ) {
  9341. if ($value ['month'] == $i) {
  9342. $sumPrice += $value ['price'];
  9343. }
  9344. }
  9345. if ($sumPrice == 0)
  9346. $collectHtml .= '<td class="taR">-</td>';
  9347. else
  9348. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9349. $total += $sumPrice;
  9350. }
  9351. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9352. $data ['companyTotalHtml'] = $collectHtml;
  9353. $data ['total'] = $total;
  9354. // statistics html
  9355. // echo $cidString;
  9356. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9357. if (empty ( $stList ))
  9358. $stList = array (
  9359. 'rePrice' => 0,
  9360. 'agPrice' => 0
  9361. );
  9362. $data ['stList'] = array (
  9363. 'rePrice' => $stList ['rePrice'],
  9364. 'agPrice' => $stList ['agPrice'],
  9365. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9366. );
  9367. $data ['year'] = $year;
  9368. $data ['memu'] = "receipt";
  9369. $data ['staff'] = $this->staff;
  9370. $data ['receiptMemu'] = 'companyCategoryCollect';
  9371. $data ['verifyId'] = $this->verifyId;
  9372. $data ['executeId'] = $this->executeId;
  9373. $dateHtml = "";
  9374. $now = date ( "Y" );
  9375. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9376. if ($YEARD <= $now) {
  9377. $dateHtml .= '<option ';
  9378. if ($year == $YEARD) {
  9379. $dateHtml .= 'selected ';
  9380. }
  9381. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9382. }
  9383. }
  9384. $data ['dateHtml'] = $dateHtml;
  9385. // year staff status 2,4
  9386. if ($year < date ( "Y" )) {
  9387. Doo::loadModel ( 'receipt' );
  9388. $receipt = new receipt ();
  9389. $receiptList = $receipt->find ( array (
  9390. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9391. 'asArray' => true
  9392. ) );
  9393. if (empty ( $receiptList )) {
  9394. ob_start ();
  9395. $this->render ( "/admin/saeaCompanyCollect", $data );
  9396. $this->cacheFile ( $path );
  9397. die ();
  9398. }
  9399. }
  9400. $this->render ( "/admin/saeaCompanyCollect", $data );
  9401. }
  9402. function categoryCollectDetail() {
  9403. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9404. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9405. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9406. $this->showCache ( $path );
  9407. Doo::loadModel ( 'statistics' );
  9408. $statistics = new statistics ();
  9409. Doo::loadModel ( "receiptDetail" );
  9410. $receiptDetail = new receiptDetail ();
  9411. Doo::loadModel ( 'L_category' );
  9412. $Lcategory = new L_category ();
  9413. Doo::loadModel ( 'accountItem' );
  9414. $accountItem = new accountItem ();
  9415. Doo::loadModel ( "receiptAuthorityManage" );
  9416. $receiptAuthorityManage = new receiptAuthorityManage ();
  9417. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9418. $cidList = array ();
  9419. foreach ( $imcStaff as $key => $value ) {
  9420. array_push ( $cidList, $value ['cid'] );
  9421. }
  9422. $cidString = implode ( ',', $cidList );
  9423. $LcategoryList = $Lcategory->find ( array (
  9424. 'where' => 'cid in (' . $cidString . ')',
  9425. 'asArray' => true
  9426. ) );
  9427. if ($cid == 0) {
  9428. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9429. if ($cid == 0)
  9430. $cid = $LcategoryList [0] ['cid'];
  9431. }
  9432. $data ['LcategoryList'] = $LcategoryList;
  9433. $receiptCollectList = $receiptDetail->find ( array (
  9434. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9435. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9436. 'groupby' => 'item,Month(pastDate)',
  9437. 'asArray' => true
  9438. ) );
  9439. $accountList = $accountItem->find ( array (
  9440. 'asArray' => true
  9441. ) );
  9442. // create CollectDetail HTML
  9443. $collectHtml = array ();
  9444. foreach ( $accountList as $key => $value ) {
  9445. $html = "";
  9446. $asum = 0;
  9447. for($i = 1; $i <= 12; $i ++) {
  9448. $falg = true;
  9449. foreach ( $receiptCollectList as $v ) {
  9450. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9451. $asum += $v ['price'];
  9452. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9453. $falg = false;
  9454. break;
  9455. }
  9456. }
  9457. if ($falg)
  9458. $html .= '<td class="taR">-</td>';
  9459. }
  9460. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9461. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9462. }
  9463. $data ['collectHtml'] = $collectHtml;
  9464. // create Adjustment price html
  9465. $receiptCollectList = $receiptDetail->find ( array (
  9466. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9467. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9468. 'groupby' => 'itemCategory,Month(pastDate)',
  9469. 'asArray' => true
  9470. ) );
  9471. $adjustment = array ();
  9472. $collectArray = array (
  9473. '日常相关费用' => array (),
  9474. '差旅相关费用' => array (),
  9475. '培训班费用' => array (),
  9476. '内部培训费用'=>array(),
  9477. '其他' => array ()
  9478. );
  9479. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9480. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9481. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9482. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9483. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9484. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9485. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9486. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9487. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9488. array_push ( $collectArray ['其他'], $collectHtml );
  9489. $data ['collectArray'] = $collectArray;
  9490. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9491. array_push ( $adjustment, $collectHtml );
  9492. $data ['adjustment'] = $adjustment;
  9493. // total price html
  9494. $collectHtml = "";
  9495. $total = 0;
  9496. for($i = 1; $i <= 12; $i ++) {
  9497. $sumPrice = 0;
  9498. foreach ( $receiptCollectList as $key => $value ) {
  9499. if ($value ['month'] == $i) {
  9500. $sumPrice += $value ['price'];
  9501. }
  9502. }
  9503. if ($sumPrice == 0)
  9504. $collectHtml .= '<td class="taR">-</td>';
  9505. else
  9506. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9507. $total += $sumPrice;
  9508. }
  9509. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9510. // statistics html
  9511. $stList = $statistics->statisticsByCid ( $year, $cid );
  9512. if (empty ( $stList ))
  9513. $stList = array (
  9514. 'rePrice' => 0,
  9515. 'agPrice' => 0
  9516. );
  9517. $data ['stList'] = array (
  9518. 'rePrice' => $stList ['rePrice'],
  9519. 'agPrice' => $stList ['agPrice'],
  9520. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9521. );
  9522. $data ['totalYear'] = $total;
  9523. $data ['year'] = $year;
  9524. $data ['cid'] = $cid;
  9525. $data ['memu'] = "receipt";
  9526. $data ['staff'] = $this->staff;
  9527. $data ['receiptMemu'] = 'companyCategoryCollect';
  9528. $data ['verifyId'] = $this->verifyId;
  9529. $data ['executeId'] = $this->executeId;
  9530. // year staff status 2,4
  9531. if ($year < date ( "Y" )) {
  9532. Doo::loadModel ( 'receipt' );
  9533. $receipt = new receipt ();
  9534. $receiptList = $receipt->find ( array (
  9535. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9536. 'asArray' => true
  9537. ) );
  9538. if (empty ( $receiptList )) {
  9539. ob_start ();
  9540. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9541. $this->cacheFile ( $path );
  9542. die ();
  9543. }
  9544. }
  9545. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9546. }
  9547. function staffCollect() {
  9548. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9549. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9550. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9551. // $this->showCache($path);
  9552. Doo::loadModel ( 'statistics' );
  9553. $statistics = new statistics ();
  9554. Doo::loadModel ( "receiptDetail" );
  9555. $receiptDetail = new receiptDetail ();
  9556. Doo::loadModel ( 'L_category' );
  9557. $Lcategory = new L_category ();
  9558. Doo::loadModel ( 'accountItem' );
  9559. $accountItem = new accountItem ();
  9560. Doo::loadModel ( 'staff' );
  9561. $staff = new staff ();
  9562. Doo::loadModel ( 'itemStatistics' );
  9563. $itemStatistics = new itemStatistics ();
  9564. Doo::loadModel ( "receiptAuthorityManage" );
  9565. $receiptAuthorityManage = new receiptAuthorityManage ();
  9566. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9567. $cidList = array ();
  9568. foreach ( $imcStaff as $key => $value ) {
  9569. array_push ( $cidList, $value ['cid'] );
  9570. }
  9571. $cidString = implode ( ',', $cidList );
  9572. $naturecon='';
  9573. if ($nature=='ONJOB'){
  9574. $naturecon=' and (nature!=4 )';
  9575. }elseif($nature=='LEAVEJOB'){
  9576. $naturecon=' and (nature=4 )';
  9577. }else{
  9578. die ( 'illegal request--nature' );
  9579. }
  9580. // statistics html
  9581. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9582. if (empty ( $stList ))
  9583. $stList = array (
  9584. 'rePrice' => 0,
  9585. 'agPrice' => 0
  9586. );
  9587. $data ['stList'] = array (
  9588. 'rePrice' => $stList ['rePrice'],
  9589. 'agPrice' => $stList ['agPrice'],
  9590. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9591. );
  9592. // ---
  9593. $staffList = $staff->find ( array (
  9594. 'where' => 'username !="admin" '.$naturecon,
  9595. 'asArray' => true
  9596. ) );
  9597. $LcategoryList = $Lcategory->find ( array (
  9598. 'asArray' => true
  9599. ) ); // 'staff='.$this->staff[0]['sid']." and
  9600. $itemStatisticsList = $itemStatistics->find ( array (
  9601. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9602. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9603. 'groupby' => 'staff,Month(date)',
  9604. 'asArray' => true
  9605. ) );
  9606. $categoryList = $staff->find ( array (
  9607. 'select' => 'COUNT(*) as count,cid,category',
  9608. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9609. 'groupby' => 'cid',
  9610. 'asArray' => true
  9611. ) );
  9612. // print_r($itemStatisticsList);die;
  9613. // ceatre companyCollectHtml
  9614. foreach ( $categoryList as $vlu ) {
  9615. $count = $vlu ['count'] + 1;
  9616. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9617. $m1 = 0;
  9618. $m2 = 0;
  9619. $m3 = 0;
  9620. $m4 = 0;
  9621. $m5 = 0;
  9622. $m6 = 0;
  9623. $m7 = 0;
  9624. $m8 = 0;
  9625. $m9 = 0;
  9626. $m10 = 0;
  9627. $m11 = 0;
  9628. $m12 = 0;
  9629. $m13 = 0;
  9630. foreach ( $staffList as $value ) {
  9631. if ($vlu ['cid'] == $value ['cid']) {
  9632. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9633. $asum = 0;
  9634. for($i = 1; $i <= 12; $i ++) {
  9635. $falg = true;
  9636. foreach ( $itemStatisticsList as $v ) {
  9637. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9638. if ($v ['month'] == 1)
  9639. $m1 += $v ['price'];
  9640. if ($v ['month'] == 2)
  9641. $m2 += $v ['price'];
  9642. if ($v ['month'] == 3)
  9643. $m3 += $v ['price'];
  9644. if ($v ['month'] == 4)
  9645. $m4 += $v ['price'];
  9646. if ($v ['month'] == 5)
  9647. $m5 += $v ['price'];
  9648. if ($v ['month'] == 6)
  9649. $m6 += $v ['price'];
  9650. if ($v ['month'] == 7)
  9651. $m7 += $v ['price'];
  9652. if ($v ['month'] == 8)
  9653. $m8 += $v ['price'];
  9654. if ($v ['month'] == 9)
  9655. $m9 += $v ['price'];
  9656. if ($v ['month'] == 10)
  9657. $m10 += $v ['price'];
  9658. if ($v ['month'] == 11)
  9659. $m11 += $v ['price'];
  9660. if ($v ['month'] == 12)
  9661. $m12 += $v ['price'];
  9662. $asum += $v ['price'];
  9663. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9664. $falg = false;
  9665. break;
  9666. }
  9667. }
  9668. if ($falg)
  9669. $html .= '<td class="taR">-</td>';
  9670. }
  9671. $m13 += $asum;
  9672. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9673. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9674. 'html' => $html,
  9675. 'sid' => $value ['sid']
  9676. );
  9677. $html = "";
  9678. }
  9679. }
  9680. $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>
  9681. <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>
  9682. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9683. $collectHtml [$vlu ['cid']] = array (
  9684. 'html' => $hl,
  9685. 'sid' => ''
  9686. );
  9687. }
  9688. $data ['companyHtml'] = $collectHtml;
  9689. // total price html
  9690. $collectHtml = "";
  9691. $total = 0;
  9692. for($i = 1; $i <= 12; $i ++) {
  9693. $sumPrice = 0;
  9694. foreach ( $itemStatisticsList as $key => $value ) {
  9695. if ($value ['month'] == $i) {
  9696. $sumPrice += $value ['price'];
  9697. }
  9698. }
  9699. if ($sumPrice == 0)
  9700. $collectHtml .= '<td class="taR">-</td>';
  9701. else
  9702. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9703. $total += $sumPrice;
  9704. }
  9705. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9706. $data ['companyTotalHtml'] = $collectHtml;
  9707. $data ['total'] = $total;
  9708. $data ['nature'] =$nature;
  9709. $data ['year'] = $year;
  9710. $data ['memu'] = "receipt";
  9711. $data ['staff'] = $this->staff;
  9712. $data ['receiptMemu'] = 'companyCategoryCollect';
  9713. $data ['verifyId'] = $this->verifyId;
  9714. $data ['executeId'] = $this->executeId;
  9715. if ($year <= date ( "Y" )) {
  9716. Doo::loadModel ( 'receipt' );
  9717. $receipt = new receipt ();
  9718. $receiptList = $receipt->find ( array (
  9719. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9720. 'asArray' => true
  9721. ) );
  9722. if (empty ( $receiptList )) { // generated files
  9723. ob_start ();
  9724. $this->render ( "/admin/saeaStaffCollectB", $data );
  9725. $this->cacheFile ( $path );
  9726. die ();
  9727. }
  9728. }
  9729. $this->render ( "/admin/saeaStaffCollectB", $data );
  9730. }
  9731. function staffCollectBak() {
  9732. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9733. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9734. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9735. $this->showCache ( $path );
  9736. Doo::loadModel ( 'statistics' );
  9737. $statistics = new statistics ();
  9738. Doo::loadModel ( "receiptDetail" );
  9739. $receiptDetail = new receiptDetail ();
  9740. Doo::loadModel ( 'L_category' );
  9741. $Lcategory = new L_category ();
  9742. Doo::loadModel ( 'accountItem' );
  9743. $accountItem = new accountItem ();
  9744. Doo::loadModel ( 'staff' );
  9745. $staff = new staff ();
  9746. Doo::loadModel ( 'itemStatistics' );
  9747. $itemStatistics = new itemStatistics ();
  9748. $itemStatisticsList = $itemStatistics->find ( array (
  9749. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9750. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9751. 'groupby' => 'staff,itemCategory,Month(date)',
  9752. 'asArray' => true
  9753. ) );
  9754. $itemCategoryList = $itemStatistics->find ( array (
  9755. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9756. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9757. 'groupby' => 'cid,itemCategory,Month(date)',
  9758. 'asArray' => true
  9759. ) );
  9760. $LcategoryList = $Lcategory->find ( array (
  9761. 'asArray' => true
  9762. ) );
  9763. $staffList = $staff->find ( array (
  9764. 'asArray' => true
  9765. ) );
  9766. $htmlArray = array ();
  9767. foreach ( $LcategoryList as $value ) {
  9768. $htmlArray [$value ['title']] = array ();
  9769. foreach ( $staffList as $v ) {
  9770. if ($value ['cid'] == $v ['cid']) {
  9771. $html = "";
  9772. $falg = true;
  9773. $staffSumPrice = 0;
  9774. foreach ( $itemStatisticsList as $a ) {
  9775. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9776. if (empty ( $a ['price'] )) {
  9777. $html .= '<td class="taR">-</td>';
  9778. $falg = false;
  9779. break;
  9780. } else {
  9781. $staffSumPrice += $a ['price'];
  9782. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9783. $falg = false;
  9784. break;
  9785. }
  9786. }
  9787. }
  9788. if ($falg) {
  9789. $html .= '<td class="taR">-</td>';
  9790. $falg = true;
  9791. }
  9792. $falg = true;
  9793. foreach ( $itemStatisticsList as $a ) {
  9794. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9795. if (empty ( $a ['price'] )) {
  9796. $html .= '<td class="taR">-</td>';
  9797. $falg = false;
  9798. break;
  9799. } else {
  9800. $staffSumPrice += $a ['price'];
  9801. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9802. $falg = false;
  9803. break;
  9804. }
  9805. }
  9806. }
  9807. if ($falg) {
  9808. $html .= '<td class="taR">-</td>';
  9809. $falg = true;
  9810. }
  9811. $falg = true;
  9812. foreach ( $itemStatisticsList as $a ) {
  9813. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9814. if (empty ( $a ['price'] )) {
  9815. $html .= '<td class="taR">-</td>';
  9816. $falg = false;
  9817. break;
  9818. } else {
  9819. $staffSumPrice += $a ['price'];
  9820. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9821. $falg = false;
  9822. break;
  9823. }
  9824. }
  9825. }
  9826. if ($falg) {
  9827. $html .= '<td class="taR">-</td>';
  9828. $falg = true;
  9829. }
  9830. $falg = true;
  9831. foreach ( $itemStatisticsList as $a ) {
  9832. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9833. if (! empty ( $a ['price'] )) {
  9834. $staffSumPrice += $a ['price'];
  9835. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9836. $falg = false;
  9837. break;
  9838. } else {
  9839. $html .= '<td class="taR">-</td>';
  9840. $falg = false;
  9841. break;
  9842. }
  9843. }
  9844. }
  9845. if ($falg) {
  9846. $html .= '<td class="taR">-</td>';
  9847. $falg = true;
  9848. }
  9849. $falg = true;
  9850. foreach ( $itemStatisticsList as $a ) {
  9851. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9852. if (! empty ( $a ['price'] )) {
  9853. $staffSumPrice += $a ['price'];
  9854. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9855. $falg = false;
  9856. break;
  9857. } else {
  9858. $html .= '<td class="taR">-</td>';
  9859. $falg = false;
  9860. break;
  9861. }
  9862. }
  9863. }
  9864. if ($falg) {
  9865. $html .= '<td class="taR">-</td>';
  9866. $falg = true;
  9867. }
  9868. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9869. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9870. }
  9871. }
  9872. /* -- --- */
  9873. // 合计费用
  9874. $cateHtml = "";
  9875. $catePrice = 0;
  9876. $cateFalg = true;
  9877. foreach ( $itemCategoryList as $l ) {
  9878. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9879. if (empty ( $l ['price'] )) {
  9880. $cateHtml .= '<td class="colGreen taR">-</td>';
  9881. $cateFalg = false;
  9882. break;
  9883. } else {
  9884. $catePrice += $l ['price'];
  9885. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9886. $cateFalg = false;
  9887. break;
  9888. }
  9889. }
  9890. }
  9891. if ($cateFalg) {
  9892. $cateHtml .= '<td class="colGreen taR">-</td>';
  9893. $cateFalg = true;
  9894. }
  9895. $cateFalg = true;
  9896. foreach ( $itemCategoryList as $l ) {
  9897. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9898. if (empty ( $l ['price'] )) {
  9899. $cateHtml .= '<td class="colGreen taR">-</td>';
  9900. $cateFalg = false;
  9901. break;
  9902. } else {
  9903. $catePrice += $l ['price'];
  9904. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9905. $cateFalg = false;
  9906. break;
  9907. }
  9908. }
  9909. }
  9910. if ($cateFalg) {
  9911. $cateHtml .= '<td class="colGreen taR">-</td>';
  9912. $cateFalg = true;
  9913. }
  9914. $cateFalg = true;
  9915. foreach ( $itemCategoryList as $l ) {
  9916. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9917. if (empty ( $l ['price'] )) {
  9918. $cateHtml .= '<td class="colGreen taR">-</td>';
  9919. $cateFalg = false;
  9920. break;
  9921. } else {
  9922. $catePrice += $l ['price'];
  9923. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9924. $cateFalg = false;
  9925. break;
  9926. }
  9927. }
  9928. }
  9929. if ($cateFalg) {
  9930. $cateHtml .= '<td class="colGreen taR">-</td>';
  9931. $cateFalg = true;
  9932. }
  9933. $cateFalg = true;
  9934. foreach ( $itemCategoryList as $l ) {
  9935. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  9936. if (empty ( $l ['price'] )) {
  9937. $cateHtml .= '<td class="colGreen taR">-</td>';
  9938. $cateFalg = false;
  9939. break;
  9940. } else {
  9941. $catePrice += $l ['price'];
  9942. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9943. $cateFalg = false;
  9944. break;
  9945. }
  9946. }
  9947. }
  9948. if ($cateFalg) {
  9949. $cateHtml .= '<td class="colGreen taR">-</td>';
  9950. $cateFalg = true;
  9951. }
  9952. $cateFalg = true;
  9953. foreach ( $itemCategoryList as $l ) {
  9954. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  9955. if (empty ( $l ['price'] )) {
  9956. $cateHtml .= '<td class="colGreen taR">-</td>';
  9957. $cateFalg = false;
  9958. break;
  9959. } else {
  9960. $catePrice += $l ['price'];
  9961. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9962. $cateFalg = false;
  9963. break;
  9964. }
  9965. }
  9966. }
  9967. if ($cateFalg) {
  9968. $cateHtml .= '<td class="colGreen taR">-</td>';
  9969. $cateFalg = true;
  9970. }
  9971. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  9972. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  9973. /* -- --- */
  9974. }
  9975. // print_r($htmlArray);die;
  9976. $data ['htmlArray'] = $htmlArray;
  9977. // statistics html
  9978. $stList = $statistics->getOne ( array (
  9979. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  9980. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9981. 'groupby' => 'Month(date)',
  9982. 'asArray' => true
  9983. ) );
  9984. if (empty ( $stList ))
  9985. $stList = array (
  9986. 'rePrice' => 0,
  9987. 'agPrice' => 0
  9988. );
  9989. $data ['stList'] = array (
  9990. 'rePrice' => $stList ['rePrice'],
  9991. 'agPrice' => $stList ['agPrice'],
  9992. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9993. );
  9994. $monthHtml = "";
  9995. for($i = 1; $i <= 12; $i ++) {
  9996. if ($i == $month)
  9997. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  9998. else
  9999. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10000. }
  10001. $data ['monthHtml'] = $monthHtml;
  10002. $data ['year'] = $year;
  10003. $data ['month'] = $month;
  10004. $data ['memu'] = "receipt";
  10005. $data ['staff'] = $this->staff;
  10006. $data ['receiptMemu'] = 'companyCategoryCollect';
  10007. $data ['verifyId'] = $this->verifyId;
  10008. $data ['executeId'] = $this->executeId;
  10009. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10010. Doo::loadModel ( 'receipt' );
  10011. $receipt = new receipt ();
  10012. $receiptList = $receipt->find ( array (
  10013. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10014. 'asArray' => true
  10015. ) );
  10016. if (empty ( $receiptList )) { // generated files
  10017. ob_start ();
  10018. $this->render ( "/admin/saeaStaffCollect", $data );
  10019. $this->cacheFile ( $path );
  10020. die ();
  10021. }
  10022. }
  10023. $this->render ( "/admin/saeaStaffCollect", $data );
  10024. }
  10025. /**
  10026. * 日常收支
  10027. */
  10028. function payments() {
  10029. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10030. Doo::loadModel ( "execute" );
  10031. $execute = new execute ();
  10032. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10033. die ( 'illegal request' );
  10034. }
  10035. Doo::loadModel ( "accountBook" );
  10036. $accountBook = new accountBook ();
  10037. Doo::loadModel ( "accountBookStatistics" );
  10038. $accountBookStatistics = new accountBookStatistics ();
  10039. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10040. $list = $accountBook->getAccountBookByLimit ( 10 );
  10041. $data ['date'] = date ( "Y-m-d" );
  10042. $data ['statisticsList'] = $statisticsList;
  10043. $data ['list'] = $list;
  10044. $data ['memu'] = "receipt";
  10045. $data ['staff'] = $this->staff;
  10046. $data ['receiptMemu'] = 'payments';
  10047. $data ['verifyId'] = $this->verifyId;
  10048. $data ['executeId'] = $this->executeId;
  10049. $this->render ( "/expenses/payments", $data );
  10050. }
  10051. function paymentsIncomeDo() {
  10052. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10053. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10054. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10055. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10056. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10057. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10058. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10059. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10060. Doo::loadClass ( 'XDeode' );
  10061. $XDeode = new XDeode ( 5 );
  10062. Doo::loadModel ( "accountBook" );
  10063. Doo::loadModel ( "accountBookStatistics" );
  10064. Doo::loadModel ( 'wasteBook' );
  10065. // 记录流水时银行的转换
  10066. $accountBank = '';
  10067. if ($receivedBank == '纵横广发') {
  10068. $accountBank = 'CGBDeposit';
  10069. } elseif ($receivedBank == '纵横工行') {
  10070. $accountBank = 'ICBCDeposit';
  10071. } elseif ($receivedBank == '华润银行') {
  10072. $accountBank = 'HUADeposit';
  10073. } elseif ($receivedBank == '个人广发') {
  10074. $accountBank = 'PersonalDeposit';
  10075. }
  10076. if (empty ( $accountBank ))
  10077. die ( 'illegal request' );
  10078. // 收入为理财时特殊处理
  10079. if ($accountType == 7 || $accountType == 9) {
  10080. if ($receivedBank == '个人广发') {
  10081. die ( '个人广发 illegal request' );
  10082. }
  10083. // 添加一条收入
  10084. $accountBook = new accountBook ();
  10085. $accountBook->accountType = 10;
  10086. $accountBook->accountMsg = $accountMsg;
  10087. $accountBook->receivedPrice = $receivedPrice;
  10088. $accountBook->receivedMsg = $receivedMsg;
  10089. $accountBook->receivedBank = $receivedBank;
  10090. $accountBook->receivedDate = $receivedDate;
  10091. $accountBook->remarks = $remarks;
  10092. $accountBook->expensesType = 1;
  10093. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10094. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10095. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10096. $inComeId = $accountBook->insert ();
  10097. // 收支汇总-添加一条收入日常汇总
  10098. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10099. $accountBookStatistics = new accountBookStatistics ();
  10100. $item = array (
  10101. 'date' => date ( "Y-m-d" ),
  10102. 'accountType' => $abDetail ['accountType'],
  10103. 'accountMsg' => $abDetail ['accountMsg'],
  10104. 'aid' => $abDetail ['aid'],
  10105. 'inComePrice' => $abDetail ['receivedPrice'],
  10106. 'expensesType' => $abDetail ['expensesType']
  10107. );
  10108. $accountBookStatistics->setAccountBookStatistics ( $item );
  10109. // 添加收入流水
  10110. $wasteBook = new wasteBook ();
  10111. $itemWaste = array (
  10112. 'accountPriceShow' => $receivedPrice,
  10113. 'accountPrice' => $receivedPrice,
  10114. 'expensesType' => 1,
  10115. 'accountType' => 6, // 流水类型
  10116. 'dataID' => $inComeId,
  10117. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10118. 'accountBank' => $accountBank,
  10119. 'category' => $this->staff [0] ['category'],
  10120. 'cid' => $this->staff [0] ['cid'],
  10121. 'name' => $this->staff [0] ['username'],
  10122. 'sid' => $this->staff [0] ['sid'],
  10123. 'inputDate' => date ( "Y-m-d H:i:s" )
  10124. );
  10125. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10126. // 添加一条理财支出
  10127. $accountBank = 'CGBDeposit';
  10128. $expenditureBank = '纵横广发';
  10129. $dailyExpenditureType = 4;
  10130. if ($accountType == 9) {
  10131. $accountBank = 'ICBCDeposit';
  10132. $expenditureBank = '纵横工行';
  10133. $dailyExpenditureType = 6;
  10134. }
  10135. $accountBook = new accountBook ();
  10136. $accountBook->expensesType = 2;
  10137. $accountBook->expenditureType = $dailyExpenditureType;
  10138. $accountBook->expenditureMsg = $accountMsg;
  10139. $accountBook->expenditurePrice = $receivedPrice;
  10140. $accountBook->expenditureBank = $expenditureBank;
  10141. $accountBook->expenditureDate = $receivedDate;
  10142. $accountBook->remarks = $remarks;
  10143. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10144. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10145. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10146. $id = $accountBook->insert ();
  10147. // 收支汇总-添加一条理财支出汇总
  10148. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10149. $accountBookStatistics = new accountBookStatistics ();
  10150. $item = array (
  10151. 'date' => date ( "Y-m-d" ),
  10152. 'accountType' => $abDetail ['accountType'],
  10153. 'accountMsg' => $abDetail ['accountMsg'],
  10154. 'aid' => $abDetail ['aid'],
  10155. 'financingPrice' => - $receivedPrice,
  10156. 'expensesType' => 3
  10157. );
  10158. $accountBookStatistics->setAccountBookStatistics ( $item );
  10159. // 添加一条支出理财流水
  10160. $accountTypeWaste = 5;
  10161. if ($accountMsg == '公司固定') {
  10162. $accountTypeWaste = 9;
  10163. } elseif ($accountMsg == '公司活期') {
  10164. $accountTypeWaste = 10;
  10165. } elseif ($accountMsg == '个人(GR)') {
  10166. $accountBank = 'PersonalDeposit';
  10167. }
  10168. $itemWaste = array (
  10169. 'expensesType' => 2,
  10170. 'accountType' => $accountTypeWaste,
  10171. 'accountPriceShow' => $receivedPrice,
  10172. 'accountPrice' => - $receivedPrice,
  10173. 'dataID' => $id,
  10174. 'dailyExpenditureType' => $dailyExpenditureType,
  10175. 'accountBank' => $accountBank,
  10176. 'category' => $this->staff [0] ['category'],
  10177. 'cid' => $this->staff [0] ['cid'],
  10178. 'name' => $this->staff [0] ['username'],
  10179. 'sid' => $this->staff [0] ['sid'],
  10180. 'inputDate' => date ( "Y-m-d H:i:s" )
  10181. );
  10182. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10183. } elseif ($accountType == 1) {
  10184. if ($receivedBank == '个人广发')
  10185. die ( 'illegal request' );
  10186. // 添加一条收入
  10187. $accountBook = new accountBook ();
  10188. $accountBook->accountType = $accountType;
  10189. $accountBook->accountMsg = $accountMsg;
  10190. $accountBook->receivedPrice = $receivedPrice;
  10191. $accountBook->receivedMsg = $receivedMsg;
  10192. $accountBook->receivedBank = $receivedBank;
  10193. $accountBook->receivedDate = $receivedDate;
  10194. $accountBook->remarks = $remarks;
  10195. $accountBook->expensesType = 1;
  10196. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10197. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10198. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10199. $id = $accountBook->insert ();
  10200. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10201. // 收支汇总-添加一条收入日常汇总
  10202. $accountBookStatistics = new accountBookStatistics ();
  10203. $item = array (
  10204. 'date' => date ( "Y-m-d" ),
  10205. 'accountType' => $abDetail ['accountType'],
  10206. 'accountMsg' => $abDetail ['accountMsg'],
  10207. 'aid' => $abDetail ['aid'],
  10208. 'expensesType' => $abDetail ['expensesType']
  10209. );
  10210. if ($abDetail ['accountType'] == 8) {
  10211. $item += array (
  10212. 'inComePrice' => $abDetail ['receivedPrice']
  10213. );
  10214. } else {
  10215. $item += array (
  10216. 'inComePrice' => $abDetail ['receivedPrice']
  10217. );
  10218. }
  10219. $accountBookStatistics->setAccountBookStatistics ( $item );
  10220. // 流水存储方向
  10221. $itemWaste = array (
  10222. 'accountType' => 6
  10223. ); // 流水类型
  10224. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10225. // }else
  10226. if ($accountMsg == '活期理财收益') {
  10227. $itemWaste = array (
  10228. 'accountType' => 10
  10229. ); // 流水类型
  10230. }
  10231. // 添加收入流水
  10232. $wasteBook = new wasteBook ();
  10233. $itemWaste += array (
  10234. 'accountPrice' => $receivedPrice,
  10235. 'accountPriceShow' => $receivedPrice,
  10236. 'expensesType' => 1,
  10237. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10238. 'dataID' => $id,
  10239. 'accountBank' => $accountBank,
  10240. 'category' => $this->staff [0] ['category'],
  10241. 'cid' => $this->staff [0] ['cid'],
  10242. 'name' => $this->staff [0] ['username'],
  10243. 'sid' => $this->staff [0] ['sid'],
  10244. 'inputDate' => date ( "Y-m-d H:i:s" )
  10245. );
  10246. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10247. } else { // 普通日常收入处理
  10248. // 添加一条收入
  10249. $accountBook = new accountBook ();
  10250. $accountBook->accountType = $accountType;
  10251. $accountBook->accountMsg = $accountMsg;
  10252. $accountBook->receivedPrice = $receivedPrice;
  10253. $accountBook->receivedMsg = $receivedMsg;
  10254. $accountBook->receivedBank = $receivedBank;
  10255. $accountBook->receivedDate = $receivedDate;
  10256. $accountBook->remarks = $remarks;
  10257. $accountBook->expensesType = 1;
  10258. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10259. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10260. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10261. $id = $accountBook->insert ();
  10262. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10263. // 收支汇总-添加一条收入日常汇总
  10264. $accountBookStatistics = new accountBookStatistics ();
  10265. $item = array (
  10266. 'date' => date ( "Y-m-d" ),
  10267. 'accountType' => $abDetail ['accountType'],
  10268. 'accountMsg' => $abDetail ['accountMsg'],
  10269. 'aid' => $abDetail ['aid'],
  10270. 'expensesType' => $abDetail ['expensesType']
  10271. );
  10272. if ($abDetail ['accountType'] == 8) {
  10273. $item += array (
  10274. 'inComePrice' => $abDetail ['receivedPrice']
  10275. );
  10276. } else {
  10277. $item += array (
  10278. 'inComePrice' => $abDetail ['receivedPrice']
  10279. );
  10280. }
  10281. $accountBookStatistics->setAccountBookStatistics ( $item );
  10282. // 添加收入流水
  10283. $itemWaste = array (
  10284. 'accountPrice' => $receivedPrice
  10285. );
  10286. if ($receivedBank == '个人广发') {
  10287. $itemWaste = array (
  10288. 'accountPrice' => - $receivedPrice
  10289. );
  10290. }
  10291. $wasteBook = new wasteBook ();
  10292. $itemWaste += array (
  10293. 'accountPriceShow' => $receivedPrice,
  10294. 'expensesType' => 1,
  10295. 'accountType' => 6, // 流水类型
  10296. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10297. 'dataID' => $id,
  10298. 'accountBank' => $accountBank,
  10299. 'category' => $this->staff [0] ['category'],
  10300. 'cid' => $this->staff [0] ['cid'],
  10301. 'name' => $this->staff [0] ['username'],
  10302. 'sid' => $this->staff [0] ['sid'],
  10303. 'inputDate' => date ( "Y-m-d H:i:s" )
  10304. );
  10305. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10306. }
  10307. }
  10308. return '/payments';
  10309. }
  10310. /**
  10311. * 添加收入
  10312. * @return string
  10313. */
  10314. function paymentsIncomeDo_() {
  10315. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10316. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10317. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10318. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10319. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10320. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10321. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10322. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10323. Doo::loadClass ( 'XDeode' );
  10324. $XDeode = new XDeode ( 5 );
  10325. Doo::loadModel ( "accountBook" );
  10326. $accountBook = new accountBook ();
  10327. $accountBank = '';
  10328. $accountTypeWaste = 6;
  10329. if ($receivedBank == '纵横广发') {
  10330. $accountBank = 'CGBDeposit';
  10331. } elseif ($receivedBank == '纵横工行') {
  10332. $accountBank = 'ICBCDeposit';
  10333. } elseif ($receivedBank == '华润银行') {
  10334. $accountBank = 'HUADeposit';
  10335. } elseif ($receivedBank == '个人广发') {
  10336. $accountBank = 'PersonalDeposit';
  10337. }
  10338. if (empty ( $accountBank ))
  10339. die ( 'illegal request' );
  10340. $dailyIncomeType = '';
  10341. $itemWaste = array (
  10342. 'accountPrice' => $receivedPrice,
  10343. 'expensesType' => 1
  10344. );
  10345. if ($receivedBank == '个人广发') {
  10346. $itemWaste = array (
  10347. 'accountPrice' => - $receivedPrice,
  10348. 'expensesType' => 1
  10349. );
  10350. }
  10351. if ($accountType == 4) {
  10352. $dailyIncomeType = 4;
  10353. } elseif ($accountType == 1) {
  10354. $dailyIncomeType = 1;
  10355. } elseif ($accountType == 2) {
  10356. $dailyIncomeType = 2;
  10357. } elseif ($accountType == 3) {
  10358. $dailyIncomeType = 3;
  10359. } elseif ($accountType == 5) {
  10360. $dailyIncomeType = 5;
  10361. } elseif ($accountType == 6) {
  10362. $dailyIncomeType = 6;
  10363. } elseif ($accountType == 7 || $accountType == 9) {
  10364. $dailyIncomeType = 7;
  10365. if ($accountMsg == '公司固定') {
  10366. $accountTypeWaste = 9;
  10367. } elseif ($accountMsg == '公司活期') {
  10368. $accountTypeWaste = 10;
  10369. } elseif ($accountMsg == '个人(GR)') {
  10370. $accountBank = 'PersonalDeposit';
  10371. }
  10372. $itemWaste = array (
  10373. 'accountPrice' => - $receivedPrice,
  10374. 'expensesType' => 2
  10375. );
  10376. } elseif ($accountType == 8) {
  10377. $dailyIncomeType = 8;
  10378. }
  10379. if (empty ( $dailyIncomeType ))
  10380. die ( 'illegal request' );
  10381. $accountBook->accountType = $accountType;
  10382. $accountBook->accountMsg = $accountMsg;
  10383. $accountBook->receivedPrice = $receivedPrice;
  10384. $accountBook->receivedMsg = $receivedMsg;
  10385. $accountBook->receivedBank = $receivedBank;
  10386. $accountBook->receivedDate = $receivedDate;
  10387. $accountBook->remarks = $remarks;
  10388. $accountBook->expensesType = 1;
  10389. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10390. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10391. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10392. $id = $accountBook->insert ();
  10393. //
  10394. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10395. // 收支汇总
  10396. Doo::loadModel ( "accountBookStatistics" );
  10397. $accountBookStatistics = new accountBookStatistics ();
  10398. $item = array (
  10399. 'date' => date ( "Y-m-d" ),
  10400. 'accountType' => $abDetail ['accountType'],
  10401. 'accountMsg' => $abDetail ['accountMsg'],
  10402. 'aid' => $abDetail ['aid']
  10403. );
  10404. if ($abDetail ['expensesType'] == 1) {
  10405. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10406. $item += array (
  10407. 'financingPrice' => - $receivedPrice,
  10408. 'expensesType' => 3
  10409. );
  10410. } else if ($abDetail ['accountType'] == 8) {
  10411. $item += array (
  10412. 'inComePrice' => - $abDetail ['receivedPrice'],
  10413. 'expensesType' => $abDetail ['expensesType']
  10414. );
  10415. } else {
  10416. $item += array (
  10417. 'inComePrice' => $abDetail ['receivedPrice'],
  10418. 'expensesType' => $abDetail ['expensesType']
  10419. );
  10420. }
  10421. }
  10422. $accountBookStatistics->setAccountBookStatistics ( $item );
  10423. // 为理财时需添加一条日常支出
  10424. if ($accountType == 7 || $accountType == 9) {
  10425. }
  10426. // 公司流水记录
  10427. Doo::loadModel ( 'wasteBook' );
  10428. $wasteBook = new wasteBook ();
  10429. // 银行
  10430. // if (empty($abDetail)){
  10431. $itemWaste += array (
  10432. 'accountPriceShow' => $receivedPrice,
  10433. 'dataID' => $id,
  10434. 'accountType' => $accountTypeWaste,
  10435. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10436. 'accountBank' => $accountBank,
  10437. 'category' => $this->staff [0] ['category'],
  10438. 'cid' => $this->staff [0] ['cid'],
  10439. 'name' => $this->staff [0] ['username'],
  10440. 'sid' => $this->staff [0] ['sid'],
  10441. 'inputDate' => date ( "Y-m-d H:i:s" )
  10442. );
  10443. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10444. // }
  10445. // 类型为理财7或者9 要添加一笔理财支出
  10446. if ($accountType == 7 || $accountType == 9) {
  10447. $accountBank = 'CGBDeposit';
  10448. $expenditureBank = '纵横广发';
  10449. $dailyExpenditureType = 4;
  10450. if ($accountType == 9) {
  10451. $accountBank = 'ICBCDeposit';
  10452. $expenditureBank = '纵横工行';
  10453. $dailyExpenditureType = 6;
  10454. }
  10455. // 添加一条支出
  10456. $accountBook = new accountBook ();
  10457. $accountBook->expenditureType = $dailyExpenditureType;
  10458. $accountBook->expenditureMsg = $accountMsg;
  10459. $accountBook->expenditurePrice = $receivedPrice;
  10460. $accountBook->expenditureBank = $expenditureBank;
  10461. $accountBook->expenditureDate = $receivedDate;
  10462. $accountBook->remarks = $remarks;
  10463. $accountBook->expensesType = 2;
  10464. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10465. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10466. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10467. $id = $accountBook->insert ();
  10468. // 添加一条收入流水
  10469. $itemWaste = array (
  10470. 'accountPriceShow' => $receivedPrice,
  10471. 'accountPrice' => $receivedPrice,
  10472. 'dataID' => $id,
  10473. 'expensesType' => 2,
  10474. 'accountType' => $accountTypeWaste,
  10475. 'dailyExpenditureType' => $dailyExpenditureType,
  10476. 'accountBank' => $accountBank,
  10477. 'category' => $this->staff [0] ['category'],
  10478. 'cid' => $this->staff [0] ['cid'],
  10479. 'name' => $this->staff [0] ['username'],
  10480. 'sid' => $this->staff [0] ['sid'],
  10481. 'inputDate' => date ( "Y-m-d H:i:s" )
  10482. );
  10483. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10484. }
  10485. }
  10486. return '/payments';
  10487. }
  10488. function paymentsExpenditureDo() {
  10489. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10490. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10491. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10492. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10493. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10494. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10495. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10496. // 理财支出特殊处理
  10497. Doo::loadModel ( "accountBook" );
  10498. Doo::loadModel ( "accountBookStatistics" );
  10499. Doo::loadModel ( 'wasteBook' );
  10500. $accountBank = '';
  10501. if ($expenditureBank == '纵横广发') {
  10502. $accountBank = 'CGBDeposit';
  10503. } elseif ($expenditureBank == '纵横工行') {
  10504. $accountBank = 'ICBCDeposit';
  10505. } elseif ($expenditureBank == '华润银行') {
  10506. $accountBank = 'HUADeposit';
  10507. } elseif ($expenditureBank == '个人广发') {
  10508. $accountBank = 'PersonalDeposit';
  10509. }
  10510. if (empty ( $accountBank ))
  10511. die ( 'illegal request' );
  10512. if ($expenditureType == 4 || $expenditureType == 6) {
  10513. if ($expenditureBank == '个人广发') {
  10514. die ( '个人广发 illegal request' );
  10515. }
  10516. // 添加一笔日常支出
  10517. $accountBook = new accountBook ();
  10518. $accountBook->expensesType = 2;
  10519. $accountBook->expenditureType = 7;
  10520. $accountBook->expenditureMsg = $expenditureMsg;
  10521. $accountBook->expenditurePrice = $expenditurePrice;
  10522. $accountBook->expenditureBank = $expenditureBank;
  10523. $accountBook->expenditureDate = $expenditureDate;
  10524. $accountBook->remarks = $remarks;
  10525. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10526. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10527. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10528. $expenditureId = $accountBook->insert ();
  10529. // 添加日常支出汇总
  10530. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10531. $accountBookStatistics = new accountBookStatistics ();
  10532. $item = array (
  10533. 'date' => date ( "Y-m-d" ),
  10534. 'expenditureType' => $abDetail ['expenditureType'],
  10535. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10536. 'aid' => $abDetail ['aid'],
  10537. 'payPrice' => $abDetail ['expenditurePrice'],
  10538. 'expensesType' => $abDetail ['expensesType']
  10539. );
  10540. $accountBookStatistics->setAccountBookStatistics ( $item );
  10541. // 公司日常支出流水
  10542. $wasteBook = new wasteBook ();
  10543. $itemWaste = array (
  10544. 'accountPrice' => - $expenditurePrice
  10545. );
  10546. if ($expenditureBank == '个人广发') {
  10547. $itemWaste = array (
  10548. 'accountPrice' => $expenditurePrice
  10549. );
  10550. }
  10551. $itemWaste += array (
  10552. 'expensesType' => 2,
  10553. 'accountType' => 5,
  10554. 'dailyExpenditureType' => $expenditureType,
  10555. 'accountPriceShow' => $expenditurePrice,
  10556. 'accountPrice' => - $expenditurePrice,
  10557. 'dataID' => $expenditureId,
  10558. 'accountBank' => $accountBank,
  10559. 'category' => $this->staff [0] ['category'],
  10560. 'cid' => $this->staff [0] ['cid'],
  10561. 'name' => $this->staff [0] ['username'],
  10562. 'sid' => $this->staff [0] ['sid'],
  10563. 'inputDate' => date ( "Y-m-d H:i:s" )
  10564. );
  10565. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10566. // 添加一笔理财收入
  10567. $accountBank = 'CGBDeposit';
  10568. $dailyIncomeType = 7;
  10569. $receivedBank = '纵横广发';
  10570. if ($expenditureType == 6) {
  10571. $accountBank = 'ICBCDeposit';
  10572. $receivedBank = '纵横工行';
  10573. $dailyIncomeType = 9;
  10574. }
  10575. $accountBook = new accountBook ();
  10576. $accountBook->expensesType = 1;
  10577. $accountBook->accountType = $dailyIncomeType;
  10578. $accountBook->accountMsg = $expenditureMsg;
  10579. $accountBook->receivedPrice = $expenditurePrice;
  10580. $accountBook->receivedBank = $receivedBank;
  10581. $accountBook->receivedDate = $expenditureDate;
  10582. $accountBook->remarks = $remarks;
  10583. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10584. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10585. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10586. $id = $accountBook->insert ();
  10587. // 添加日常理财收入汇总
  10588. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10589. $accountBookStatistics = new accountBookStatistics ();
  10590. $item = array (
  10591. 'date' => date ( "Y-m-d" ),
  10592. 'expenditureType' => $abDetail ['expenditureType'],
  10593. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10594. 'aid' => $abDetail ['aid'],
  10595. 'financingPrice' => $expenditurePrice,
  10596. 'expensesType' => 3
  10597. );
  10598. $accountBookStatistics->setAccountBookStatistics ( $item );
  10599. // 添加一笔收入流水
  10600. if ($expenditureMsg == '公司固定') {
  10601. $accountTypeWaste = 9;
  10602. } elseif ($expenditureMsg == '公司活期') {
  10603. $accountTypeWaste = 10;
  10604. } elseif ($expenditureMsg == '个人(GR)') {
  10605. $accountBank = 'PersonalDeposit';
  10606. }
  10607. $itemWaste = array (
  10608. 'expensesType' => 1,
  10609. 'accountType' => $accountTypeWaste,
  10610. 'accountPriceShow' => $expenditurePrice,
  10611. 'accountPrice' => $expenditurePrice,
  10612. 'dataID' => $id,
  10613. 'dailyIncomeType' => $dailyIncomeType,
  10614. 'accountBank' => $accountBank,
  10615. 'category' => $this->staff [0] ['category'],
  10616. 'cid' => $this->staff [0] ['cid'],
  10617. 'name' => $this->staff [0] ['username'],
  10618. 'sid' => $this->staff [0] ['sid'],
  10619. 'inputDate' => date ( "Y-m-d H:i:s" )
  10620. );
  10621. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10622. } else {
  10623. // 添加一笔日常支出
  10624. $accountBook = new accountBook ();
  10625. $accountBook->expensesType = 2;
  10626. $accountBook->expenditureType = $expenditureType;
  10627. $accountBook->expenditureMsg = $expenditureMsg;
  10628. $accountBook->expenditurePrice = $expenditurePrice;
  10629. $accountBook->expenditureBank = $expenditureBank;
  10630. $accountBook->expenditureDate = $expenditureDate;
  10631. $accountBook->remarks = $remarks;
  10632. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10633. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10634. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10635. $id = $accountBook->insert ();
  10636. // 添加日常支出汇总
  10637. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10638. $accountBookStatistics = new accountBookStatistics ();
  10639. $item = array (
  10640. 'date' => date ( "Y-m-d" ),
  10641. 'expenditureType' => $abDetail ['expenditureType'],
  10642. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10643. 'aid' => $abDetail ['aid'],
  10644. 'expensesType' => $abDetail ['expensesType']
  10645. );
  10646. if ($expenditureType == 5) {
  10647. $item += array (
  10648. 'payPrice' => - $abDetail ['expenditurePrice']
  10649. );
  10650. } else {
  10651. $item += array (
  10652. 'payPrice' => $abDetail ['expenditurePrice']
  10653. );
  10654. }
  10655. $accountBookStatistics->setAccountBookStatistics ( $item );
  10656. // 公司日常支出流水
  10657. $wasteBook = new wasteBook ();
  10658. $itemWaste = array (
  10659. 'accountPrice' => - $expenditurePrice
  10660. );
  10661. if ($expenditureBank == '个人广发') {
  10662. $itemWaste = array (
  10663. 'accountPrice' => $expenditurePrice
  10664. );
  10665. }
  10666. $itemWaste += array (
  10667. 'expensesType' => 2,
  10668. 'accountType' => 5,
  10669. 'accountPriceShow' => $expenditurePrice,
  10670. 'dataID' => $id,
  10671. 'dailyExpenditureType' => $expenditureType,
  10672. 'accountBank' => $accountBank,
  10673. 'category' => $this->staff [0] ['category'],
  10674. 'cid' => $this->staff [0] ['cid'],
  10675. 'name' => $this->staff [0] ['username'],
  10676. 'sid' => $this->staff [0] ['sid'],
  10677. 'inputDate' => date ( "Y-m-d H:i:s" )
  10678. );
  10679. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10680. }
  10681. }
  10682. return '/payments';
  10683. }
  10684. /**
  10685. * 添加支出
  10686. */
  10687. function paymentsExpenditureDo_() {
  10688. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10689. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10690. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10691. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10692. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10693. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10694. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10695. $dailyExpenditureType = '';
  10696. $accountTypeWaste = 5;
  10697. $accountBank = '';
  10698. if ($expenditureBank == '纵横广发') {
  10699. $accountBank = 'CGBDeposit';
  10700. } elseif ($expenditureBank == '纵横工行') {
  10701. $accountBank = 'ICBCDeposit';
  10702. } elseif ($expenditureBank == '华润银行') {
  10703. $accountBank = 'HUADeposit';
  10704. } elseif ($expenditureBank == '个人广发') {
  10705. $accountBank = 'PersonalDeposit';
  10706. }
  10707. if (empty ( $accountBank ))
  10708. die ( 'illegal request' );
  10709. $itemWaste = array (
  10710. 'accountPrice' => - $expenditurePrice
  10711. );
  10712. if ($expenditureBank == '个人广发') {
  10713. $itemWaste = array (
  10714. 'accountPrice' => $expenditurePrice
  10715. );
  10716. }
  10717. if ($expenditureType == 4 || $expenditureType == 6) {
  10718. $dailyExpenditureType = 4;
  10719. if ($expenditureMsg == '公司固定') {
  10720. $accountTypeWaste = 9;
  10721. } elseif ($expenditureMsg == '公司活期') {
  10722. $accountTypeWaste = 10;
  10723. } elseif ($expenditureMsg == '个人(GR)') {
  10724. $accountBank = 'PersonalDeposit';
  10725. }
  10726. $itemWaste = array (
  10727. 'accountPrice' => $expenditurePrice
  10728. );
  10729. } elseif ($expenditureType == 1) {
  10730. $dailyExpenditureType = 1;
  10731. } elseif ($expenditureType == 2) {
  10732. $dailyExpenditureType = 2;
  10733. } elseif ($expenditureType == 3) {
  10734. $dailyExpenditureType = 3;
  10735. } elseif ($expenditureType == 5) {
  10736. $dailyExpenditureType = 5;
  10737. }
  10738. if (empty ( $dailyExpenditureType ))
  10739. die ( 'illegal request' );
  10740. Doo::loadModel ( "accountBook" );
  10741. $accountBook = new accountBook ();
  10742. $accountBook->expenditureType = $expenditureType;
  10743. $accountBook->expenditureMsg = $expenditureMsg;
  10744. $accountBook->expenditurePrice = $expenditurePrice;
  10745. $accountBook->expenditureBank = $expenditureBank;
  10746. $accountBook->expenditureDate = $expenditureDate;
  10747. $accountBook->remarks = $remarks;
  10748. $accountBook->expensesType = 2;
  10749. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10750. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10751. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10752. $id = $accountBook->insert ();
  10753. //
  10754. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10755. Doo::loadModel ( "accountBookStatistics" );
  10756. $accountBookStatistics = new accountBookStatistics ();
  10757. $item = array (
  10758. 'date' => date ( "Y-m-d" ),
  10759. 'expenditureType' => $abDetail ['expenditureType'],
  10760. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10761. 'aid' => $abDetail ['aid']
  10762. );
  10763. if ($abDetail ['expensesType'] == 2) {
  10764. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10765. $item += array (
  10766. 'financingPrice' => $expenditurePrice,
  10767. 'expensesType' => 3
  10768. );
  10769. } elseif ($abDetail ['expenditureType'] == 5) {
  10770. $item += array (
  10771. 'payPrice' => $abDetail ['expenditurePrice'],
  10772. 'expensesType' => $abDetail ['expensesType']
  10773. );
  10774. } else {
  10775. $item += array (
  10776. 'payPrice' => $abDetail ['expenditurePrice'],
  10777. 'expensesType' => $abDetail ['expensesType']
  10778. );
  10779. }
  10780. }
  10781. $accountBookStatistics->setAccountBookStatistics ( $item );
  10782. // 公司流水记录
  10783. Doo::loadModel ( 'wasteBook' );
  10784. $wasteBook = new wasteBook ();
  10785. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10786. // 银行
  10787. if (empty ( $abDetail )) {
  10788. $itemWaste += array (
  10789. 'accountPriceShow' => $expenditurePrice,
  10790. 'dataID' => $id,
  10791. 'expensesType' => 2,
  10792. 'accountType' => $accountTypeWaste,
  10793. 'dailyExpenditureType' => $expenditureType,
  10794. 'accountBank' => $accountBank,
  10795. 'category' => $this->staff [0] ['category'],
  10796. 'cid' => $this->staff [0] ['cid'],
  10797. 'name' => $this->staff [0] ['username'],
  10798. 'sid' => $this->staff [0] ['sid'],
  10799. 'inputDate' => date ( "Y-m-d H:i:s" )
  10800. );
  10801. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10802. }
  10803. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10804. if ($expenditureType == 4 || $expenditureType == 6) {
  10805. $accountBank = 'CGBDeposit';
  10806. $dailyIncomeType = 7;
  10807. $receivedBank = '纵横广发';
  10808. if ($expenditureType == 6) {
  10809. $accountBank = 'ICBCDeposit';
  10810. $receivedBank = '纵横工行';
  10811. $dailyIncomeType = 9;
  10812. }
  10813. // 添加一笔收入
  10814. $accountBook = new accountBook ();
  10815. $accountBook->accountType = $dailyIncomeType;
  10816. $accountBook->accountMsg = $expenditureMsg;
  10817. $accountBook->receivedPrice = $expenditurePrice;
  10818. $accountBook->receivedBank = $receivedBank;
  10819. $accountBook->receivedDate = $expenditureDate;
  10820. $accountBook->remarks = $remarks;
  10821. $accountBook->expensesType = 1;
  10822. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10823. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10824. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10825. $id = $accountBook->insert ();
  10826. // 添加一笔收入流水
  10827. $itemWaste = array (
  10828. 'accountPriceShow' => $expenditurePrice,
  10829. 'accountPrice' => - $expenditurePrice,
  10830. 'dataID' => $id,
  10831. 'expensesType' => 1,
  10832. 'accountType' => $accountTypeWaste,
  10833. 'dailyIncomeType' => $dailyIncomeType,
  10834. 'accountBank' => $accountBank,
  10835. 'category' => $this->staff [0] ['category'],
  10836. 'cid' => $this->staff [0] ['cid'],
  10837. 'name' => $this->staff [0] ['username'],
  10838. 'sid' => $this->staff [0] ['sid'],
  10839. 'inputDate' => date ( "Y-m-d H:i:s" )
  10840. );
  10841. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10842. }
  10843. }
  10844. return '/payments';
  10845. }
  10846. /**
  10847. * 所有收支
  10848. */
  10849. function paymentsAchieve() {
  10850. $page_size = 12;
  10851. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10852. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10853. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10854. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10855. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10856. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10857. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10858. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10859. Doo::loadModel ( "accountBookStatistics" );
  10860. $accountBookStatistics = new accountBookStatistics ();
  10861. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10862. $data ['statisticsList'] = $statisticsList;
  10863. Doo::loadModel ( "accountBook" );
  10864. $accountBook = new accountBook ();
  10865. $con = '';
  10866. if ($expensesType == 'INCOME')
  10867. $con = ' and expensesType=1 ';
  10868. elseif ($expensesType == 'PAY')
  10869. $con = ' and expensesType=2 ';
  10870. $dateArr = explode ( ':', $date );
  10871. $D1 = $dateString = '';
  10872. $D2 = '';
  10873. if (! empty ( $date )) {
  10874. $D1 = $dateArr [0];
  10875. if (isset ( $dateArr [1] ))
  10876. $D2 = $dateArr [1];
  10877. else
  10878. $D2 = '';
  10879. $dateString = $D1 . " : " . $D2;
  10880. }
  10881. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10882. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10883. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10884. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10885. if (! empty ( $price ))
  10886. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10887. if ($submitType == 1) {
  10888. if ($accountType != '') {
  10889. $expenditureType = '';
  10890. $con .= ' and accountType=' . $accountType;
  10891. if (! empty ( $accountMsg ))
  10892. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10893. }
  10894. } elseif ($submitType == 2) {
  10895. if ($expenditureType != '') {
  10896. $accountType = $accountMsg = '';
  10897. $con .= ' and expenditureType=' . $expenditureType;
  10898. }
  10899. } else {
  10900. $accountType = $accountMsg = $expenditureType = '';
  10901. }
  10902. $sql = "" . $con;
  10903. $action = "paymentsAchieve";
  10904. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10905. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10906. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10907. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10908. $data ['expenditureType'] = $expenditureType;
  10909. $data ['accountMsg'] = $accountMsg;
  10910. $data ['accountType'] = $accountType;
  10911. $data ['inputDate'] = $date;
  10912. $data ['price'] = $price;
  10913. $data ['expensesType'] = $expensesType;
  10914. $data ['page'] = $pageinfo;
  10915. $data ['list'] = $list;
  10916. $data ['memu'] = "receipt";
  10917. $data ['staff'] = $this->staff;
  10918. $data ['receiptMemu'] = 'payments';
  10919. $data ['verifyId'] = $this->verifyId;
  10920. $data ['executeId'] = $this->executeId;
  10921. $this->render ( "/expenses/paymentsAchieve", $data );
  10922. }
  10923. function paymentsIncomeUpdateDo() {
  10924. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10925. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10926. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10927. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10928. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10929. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10930. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10931. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10932. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10933. Doo::loadClass ( 'XDeode' );
  10934. $XDeode = new XDeode ( 5 );
  10935. $aid = $XDeode->decode ( $aidKey );
  10936. Doo::loadModel ( "accountBook" );
  10937. $accountBook = new accountBook ();
  10938. //
  10939. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10940. $price = $receivedPrice - $abDetail [inComePrice];
  10941. Doo::loadModel ( "accountBookStatistics" );
  10942. $accountBookStatistics = new accountBookStatistics ();
  10943. if ($abDetail ['accountType'] == 7) {
  10944. $item += array (
  10945. 'date' => date ( "Y-m-d" ),
  10946. 'financingPrice' => - $price,
  10947. 'expensesType' => 3,
  10948. 'aid' => $abDetail ['aid']
  10949. );
  10950. } elseif ($abDetail ['accountType'] == 8) {
  10951. $item += array (
  10952. 'date' => date ( "Y-m-d" ),
  10953. 'expensesType' => $abDetail ['expensesType'],
  10954. 'inComePrice' => - $price,
  10955. 'aid' => $abDetail ['aid']
  10956. );
  10957. } else {
  10958. $item = array (
  10959. 'date' => date ( "Y-m-d" ),
  10960. 'expensesType' => $abDetail ['expensesType'],
  10961. 'inComePrice' => $price,
  10962. 'aid' => $abDetail ['aid']
  10963. );
  10964. }
  10965. $accountBookStatistics->setAccountBookStatistics ( $item );
  10966. $accountBook->accountType = $accountType;
  10967. $accountBook->accountMsg = $accountMsg;
  10968. $accountBook->receivedPrice = $receivedPrice;
  10969. $accountBook->receivedMsg = $receivedMsg;
  10970. $accountBook->receivedBank = $receivedBank;
  10971. $accountBook->receivedDate = $receivedDate;
  10972. $accountBook->remarks = $remarks;
  10973. $accountBook->aid = $aid;
  10974. $accountBook->update ();
  10975. }
  10976. return '/paymentsAchieve';
  10977. }
  10978. function paymentsExpenditureEdiDo() {
  10979. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10980. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10981. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10982. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10983. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10984. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10985. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10986. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10987. Doo::loadClass ( 'XDeode' );
  10988. $XDeode = new XDeode ( 5 );
  10989. $aid = $XDeode->decode ( $aidKey );
  10990. Doo::loadModel ( "accountBook" );
  10991. $accountBook = new accountBook ();
  10992. // 汇总信息
  10993. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10994. $price = $expenditurePrice - $abDetail [expenditurePrice];
  10995. Doo::loadModel ( "accountBookStatistics" );
  10996. $accountBookStatistics = new accountBookStatistics ();
  10997. if ($abDetail ['expenditureType'] == 4) {
  10998. $item += array (
  10999. 'date' => date ( "Y-m-d" ),
  11000. 'financingPrice' => $price,
  11001. 'expensesType' => 3,
  11002. 'aid' => $abDetail ['aid']
  11003. );
  11004. } elseif ($abDetail ['expenditureType'] == 5) {
  11005. $item += array (
  11006. 'date' => date ( "Y-m-d" ),
  11007. 'expensesType' => $abDetail ['expensesType'],
  11008. 'payPrice' => $price,
  11009. 'aid' => $abDetail ['aid']
  11010. );
  11011. } else {
  11012. $item = array (
  11013. 'date' => date ( "Y-m-d" ),
  11014. 'expensesType' => $abDetail ['expensesType'],
  11015. 'payPrice' => $price,
  11016. 'aid' => $abDetail ['aid']
  11017. );
  11018. }
  11019. $accountBookStatistics->setAccountBookStatistics ( $item );
  11020. //
  11021. $accountBook->expenditureType = $expenditureType;
  11022. $accountBook->expenditureMsg = $expenditureMsg;
  11023. $accountBook->expenditurePrice = $expenditurePrice;
  11024. $accountBook->expenditureBank = $expenditureBank;
  11025. $accountBook->remarks = $remarks;
  11026. $accountBook->expenditureDate = $expenditureDate;
  11027. $accountBook->aid = $aid;
  11028. $id = $accountBook->update ();
  11029. }
  11030. return '/paymentsAchieve';
  11031. }
  11032. function paymentsDelDo() {
  11033. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11034. if (! empty ( $aidKey )) {
  11035. Doo::loadClass ( 'XDeode' );
  11036. $XDeode = new XDeode ( 5 );
  11037. $aid = $XDeode->decode ( $aidKey );
  11038. Doo::loadModel ( "accountBook" );
  11039. $accountBook = new accountBook ();
  11040. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11041. if (empty ( $abDetail ))
  11042. die ( 'illegal request' );
  11043. // 删除收支
  11044. Doo::loadModel ( "accountBookStatistics" );
  11045. $accountBookStatistics = new accountBookStatistics ();
  11046. $item = array (
  11047. 'date' => date ( "Y-m-d" ),
  11048. 'aid' => $abDetail ['aid']
  11049. );
  11050. $accountType = '';
  11051. if ($abDetail ['expensesType'] == 1) {
  11052. $accountType = 6;
  11053. if ($abDetail ['accountType'] != 7) {
  11054. $item += array (
  11055. 'expensesType' => $abDetail ['expensesType'],
  11056. 'inComePrice' => - $abDetail ['receivedPrice']
  11057. );
  11058. } else {
  11059. $item += array (
  11060. 'financingPrice' => $abDetail ['receivedPrice'],
  11061. 'expensesType' => 3
  11062. );
  11063. }
  11064. } elseif ($abDetail ['expensesType'] == 2) {
  11065. $accountType = 5;
  11066. if ($abDetail ['accountType'] != 7) {
  11067. $item += array (
  11068. 'expensesType' => $abDetail ['expensesType'],
  11069. 'payPrice' => - $abDetail ['expenditurePrice']
  11070. );
  11071. } else {
  11072. $item += array (
  11073. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11074. 'expensesType' => 3
  11075. );
  11076. }
  11077. }
  11078. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11079. if ($abDetail ['expenditureMsg'] == '公司固定')
  11080. $accountType = 9;
  11081. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11082. $accountType = 10;
  11083. }
  11084. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11085. if ($abDetail ['accountMsg'] == '公司固定')
  11086. $accountType = 9;
  11087. elseif ($abDetail ['accountMsg'] == '公司活期')
  11088. $accountType = 10;
  11089. }
  11090. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11091. $accountType = 10;
  11092. }
  11093. $accountBookStatistics->setAccountBookStatistics ( $item );
  11094. $accountBook->delete ( array (
  11095. 'where' => 'aid=' . $aid,
  11096. 'limit' => 1
  11097. ) );
  11098. // 删除收入流水
  11099. if (! empty ( $accountType )) {
  11100. Doo::loadModel ( 'wasteBook' );
  11101. $wasteBook = new wasteBook ();
  11102. $wasteBook->delete ( array (
  11103. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11104. 'limit' => 1
  11105. ) );
  11106. }
  11107. }
  11108. return '/paymentsAchieve';
  11109. }
  11110. function paymentsCollect() {
  11111. Doo::loadModel ( "execute" );
  11112. $execute = new execute ();
  11113. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11114. die ( 'illegal request' );
  11115. }
  11116. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11117. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11118. Doo::loadModel ( "accountBookStatistics" );
  11119. $accountBookStatistics = new accountBookStatistics ();
  11120. Doo::loadClass ( 'receipt.func' );
  11121. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11122. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11123. $data ['html'] = $html ['html'];
  11124. $data ['inSum'] = $html ['sum'];
  11125. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11126. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11127. $data ['payHtml'] = $html ['html'];
  11128. $data ['paySum'] = $html ['sum'];
  11129. // 余额统计
  11130. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11131. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11132. include './protected/config/wasteBook.conf.php';
  11133. Doo::loadModel ( 'wasteBook' );
  11134. $wasteBook = new wasteBook ();
  11135. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11136. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11137. // 获得年份之前所有金额
  11138. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11139. // print_r($detail);
  11140. // $waste['total'];
  11141. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11142. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11143. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11144. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11145. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11146. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11147. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11148. if (date ( 'Y' ) > $year) {
  11149. $limitMonth = 12;
  11150. }
  11151. for($i = 1; $i <= 12; $i ++) {
  11152. $inComeA = $payB = 0;
  11153. $falg = true;
  11154. foreach ( $inComePay as $key => $value ) {
  11155. if ($value ['month'] == $i) {
  11156. $falg = false;
  11157. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11158. $inSum += $value ['accountPrice'];
  11159. $showInSum += $value ['accountPriceShow'];
  11160. $inComeA = $value ['accountPrice'];
  11161. break;
  11162. }
  11163. }
  11164. if ($falg)
  11165. $inComeHtml .= '<td class="taR">-</td>';
  11166. $payFalg = true;
  11167. foreach ( $pay as $key => $value ) {
  11168. if ($value ['month'] == $i) {
  11169. $payFalg = false;
  11170. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11171. $paySum += $value ['accountPrice'];
  11172. $showPaySum += $value ['accountPriceShow'];
  11173. $payB = $value ['accountPrice'];
  11174. break;
  11175. }
  11176. }
  11177. if ($payFalg)
  11178. $payHtml .= '<td class="taR">-</td>';
  11179. if (empty ( $balanceC ) || $limitMonth < $i)
  11180. $lastBalanceHtml .= '<td class="taR">-</td>';
  11181. else
  11182. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11183. $balanceC = $balanceC + $inComeA + $payB;
  11184. $balanceSum += $balanceC;
  11185. if (empty ( $balanceC ) || $limitMonth < $i)
  11186. $BalanceHtml .= '<td class="taR">-</td>';
  11187. else
  11188. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11189. // 余额统计
  11190. }
  11191. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11192. $data ['inComeHtml'] = $inComeHtml;
  11193. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11194. $data ['payBalanceHtml'] = $payHtml;
  11195. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11196. $data ['BalanceHtml'] = $BalanceHtml;
  11197. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11198. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11199. $mothHtml = "";
  11200. for($i = 1; $i <= 12; $i ++) {
  11201. if ($moth == $i)
  11202. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11203. else
  11204. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11205. }
  11206. $data ['mothHtml'] = $mothHtml;
  11207. $dateHtml = "";
  11208. $now = date ( "Y" );
  11209. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11210. if ($YEARD <= $now) {
  11211. $dateHtml .= '<option ';
  11212. if ($year == $YEARD) {
  11213. $dateHtml .= 'selected ';
  11214. }
  11215. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11216. }
  11217. }
  11218. $data ['dateHtml'] = $dateHtml;
  11219. $data ['year'] = $year;
  11220. $data ['memu'] = "receipt";
  11221. $data ['staff'] = $this->staff;
  11222. $data ['receiptMemu'] = 'paymentsCollect';
  11223. $data ['verifyId'] = $this->verifyId;
  11224. $data ['executeId'] = $this->executeId;
  11225. $this->render ( "/expenses/paymentsCollect", $data );
  11226. }
  11227. function paymentsCollectDay() {
  11228. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11229. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11230. if (empty ( $moth ))
  11231. return 'paymentsCollect';
  11232. Doo::loadModel ( "accountBookStatistics" );
  11233. $accountBookStatistics = new accountBookStatistics ();
  11234. $i = 2;
  11235. $y = 2013;
  11236. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11237. Doo::loadClass ( 'receipt.func' );
  11238. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11239. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11240. $data ['html'] = $html ['html'];
  11241. $data ['inSum'] = $html ['sum'];
  11242. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11243. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11244. $data ['payHtml'] = $html ['html'];
  11245. $data ['paySum'] = $html ['sum'];
  11246. $mothHtml = "";
  11247. for($i = 1; $i <= 12; $i ++) {
  11248. if ($moth == $i)
  11249. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11250. else
  11251. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11252. }
  11253. $data ['mothHtml'] = $mothHtml;
  11254. $data ['year'] = $year;
  11255. // 余额
  11256. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11257. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11258. include './protected/config/wasteBook.conf.php';
  11259. Doo::loadModel ( 'wasteBook' );
  11260. $wasteBook = new wasteBook ();
  11261. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11262. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11263. // 获得年份之前所有金额
  11264. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11265. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11266. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11267. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11268. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11269. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11270. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11271. // $balanceC = 0;
  11272. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11273. $limitDay = date ( 'd' );
  11274. $monthLK = ( int ) date ( 'm' );
  11275. if (date ( 'Y' ) > $year) {
  11276. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11277. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11278. $limitDay = 0;
  11279. }
  11280. for($i = 1; $i <= $day; $i ++) {
  11281. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11282. $inComeA = $payB = 0;
  11283. $falg = true;
  11284. foreach ( $inComePay as $key => $value ) {
  11285. if ($value ['day'] == $i) {
  11286. $falg = false;
  11287. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11288. $inSum += $value ['accountPrice'];
  11289. $showInSum += $value ['accountPriceShow'];
  11290. $inComeA = $value ['accountPrice'];
  11291. break;
  11292. }
  11293. }
  11294. if ($falg)
  11295. $inComeHtml .= '<td class="taR">-</td>';
  11296. $payFalg = true;
  11297. foreach ( $pay as $key => $value ) {
  11298. if ($value ['day'] == $i) {
  11299. $payFalg = false;
  11300. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11301. $paySum += $value ['accountPrice'];
  11302. $showPaySum += $value ['accountPriceShow'];
  11303. $payB = $value ['accountPrice'];
  11304. break;
  11305. }
  11306. }
  11307. if ($payFalg)
  11308. $payHtml .= '<td class="taR">-</td>';
  11309. if (empty ( $balanceC ) || $limitDay < $i)
  11310. $lastBalanceHtml .= '<td class="taR">-</td>';
  11311. else
  11312. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11313. $balanceC = $balanceC + $inComeA + $payB;
  11314. $balanceSum += $balanceC;
  11315. if (empty ( $balanceC ) || $limitDay < $i)
  11316. $BalanceHtml .= '<td class="taR">-</td>';
  11317. else
  11318. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11319. }
  11320. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11321. $data ['inComeHtml'] = $inComeHtml;
  11322. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11323. $data ['payBalanceHtml'] = $payHtml;
  11324. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11325. $data ['BalanceHtml'] = $BalanceHtml;
  11326. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11327. $data ['dayHtml'] = $dayHtml;
  11328. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11329. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11330. $dateHtml = "";
  11331. $now = date ( "Y" );
  11332. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11333. if ($YEARD <= $now) {
  11334. $dateHtml .= '<option ';
  11335. if ($year == $YEARD) {
  11336. $dateHtml .= 'selected ';
  11337. }
  11338. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11339. }
  11340. }
  11341. $data ['dateHtml'] = $dateHtml;
  11342. $data ['memu'] = "receipt";
  11343. $data ['staff'] = $this->staff;
  11344. $data ['receiptMemu'] = 'paymentsCollect';
  11345. $data ['verifyId'] = $this->verifyId;
  11346. $data ['executeId'] = $this->executeId;
  11347. $this->render ( "/expenses/paymentsCollectDay", $data );
  11348. }
  11349. // 公司流水
  11350. function wasteBook() {
  11351. Doo::loadModel ( "execute" );
  11352. $execute = new execute ();
  11353. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11354. die ( 'illegal request' );
  11355. }
  11356. include './protected/config/wasteBook.conf.php';
  11357. Doo::loadModel ( 'wasteBook' );
  11358. $wasteBook = new wasteBook ();
  11359. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11360. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11361. $total = $waste ['bank'] ['CGBDeposit'] + $waste ['bank'] ['ICBCDeposit'] + $waste ['bank'] ['HUADeposit'] + $waste ['bank'] ['PersonalDeposit'] + $waste ['financial'] ['current'] ['CGBDeposit'] + $waste ['financial'] ['current'] ['ICBCDeposit'] + $waste ['financial'] ['fixed'] ['CGBDeposit'] + $waste ['financial'] ['fixed'] ['ICBCDeposit'];
  11362. // print_r($waste);
  11363. $data ['waste'] = $waste;
  11364. $data ['total'] = $total;
  11365. // 月流水数据结构
  11366. $monthStatistics = array ();
  11367. $incomeMothStatistics = array ();
  11368. $expenditureMothStatistics = array ();
  11369. for($i = 1; $i <= 12; $i ++) {
  11370. $month = date ( 'Y' ) . '-' . $i;
  11371. if ($i < 10)
  11372. $month = date ( 'Y' ) . '-0' . $i;
  11373. array_push ( $monthStatistics, $month );
  11374. }
  11375. foreach ( $monthStatistics as $value ) {
  11376. $falg = true;
  11377. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11378. if ($value == $v ['inputDate']) {
  11379. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11380. $falg = false;
  11381. }
  11382. }
  11383. if ($falg) {
  11384. array_push ( $incomeMothStatistics, '' );
  11385. }
  11386. $falgEx = true;
  11387. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11388. if ($value == $v ['inputDate']) {
  11389. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11390. $falg = false;
  11391. }
  11392. }
  11393. if ($falgEx) {
  11394. array_push ( $expenditureMothStatistics, '' );
  11395. }
  11396. }
  11397. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11398. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11399. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11400. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11401. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11402. // print_r($incomeList);
  11403. $data ['expenditureList'] = $expenditureList;
  11404. $data ['incomeList'] = $incomeList;
  11405. $data ['memu'] = "receipt";
  11406. $data ['staff'] = $this->staff;
  11407. $data ['receiptMemu'] = 'wasteBook';
  11408. $data ['verifyId'] = $this->verifyId;
  11409. $data ['executeId'] = $this->executeId;
  11410. $this->render ( "/expenses/wasteBook", $data );
  11411. }
  11412. function wasteBookIncome() {
  11413. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11414. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11415. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11416. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11417. $data ['dailyIncomeType'] = $dailyIncomeType;
  11418. Doo::loadModel ( 'wasteBook' );
  11419. $wasteBook = new wasteBook ();
  11420. Doo::loadModel ( 'L_category' );
  11421. $L_category = new L_category ();
  11422. Doo::loadClass ( 'XDeode' );
  11423. $XDeode = new XDeode ( 5 );
  11424. // echo $XDeode->encode(1).'<br>';
  11425. // echo $XDeode->encode(2).'<br>';
  11426. // echo $XDeode->encode(3).'<br>';
  11427. // echo $XDeode->encode(4).'<br>';
  11428. // echo $XDeode->encode(5).'<br>';
  11429. // echo $XDeode->encode(6).'<br>';
  11430. // echo $XDeode->encode(7).'<br>';
  11431. // echo $XDeode->encode(8).'<br>';
  11432. // echo $XDeode->encode(9).'<br>';
  11433. // echo $XDeode->encode(10).'<br>';
  11434. $dateArr = explode ( ':', $date );
  11435. $D1 = '';
  11436. $D2 = '';
  11437. $con = '';
  11438. if (! empty ( $date )) {
  11439. $D1 = $dateArr [0];
  11440. $D2 = $dateArr [1];
  11441. }
  11442. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11443. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11444. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11445. $con = ' and inputDate = "' . $D1 . '"';
  11446. if ($cid != 'ALL') {
  11447. $cid = $XDeode->decode ( $cid );
  11448. $con .= ' and cid = "' . $cid . '"';
  11449. }
  11450. if ($accountType != 'ALL') {
  11451. if ($accountType == 'INVOICE') {
  11452. $con .= ' and (accountType = 7 or accountType = 8)';
  11453. } elseif ($accountType == 'PAYMENTS') {
  11454. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11455. if ($dailyIncomeType != 'ALL') {
  11456. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11457. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11458. }
  11459. }
  11460. }
  11461. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11462. $sum = 0;
  11463. foreach ( $incomeList as $key => $value ) {
  11464. $sum += $value ['accountPrice'];
  11465. }
  11466. // print_r($incomeList);
  11467. // 获得办事和部门
  11468. $categoryList = $L_category->getCategory ();
  11469. $data ['accountType'] = $accountType;
  11470. $data ['cid'] = $cid;
  11471. $data ['categoryList'] = $categoryList;
  11472. $data ['sum'] = $sum;
  11473. $data ['incomeList'] = $incomeList;
  11474. $data ['inputDate'] = $date;
  11475. $data ['memu'] = "receipt";
  11476. $data ['staff'] = $this->staff;
  11477. $data ['receiptMemu'] = 'wasteBook';
  11478. $data ['verifyId'] = $this->verifyId;
  11479. $data ['executeId'] = $this->executeId;
  11480. $this->render ( "/expenses/wasteBookIncome", $data );
  11481. }
  11482. /**
  11483. * 所有支出
  11484. */
  11485. function wasteBookExpenditure() {
  11486. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11487. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11488. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11489. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11490. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11491. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11492. $data ['receiptType'] = $receiptType;
  11493. Doo::loadModel ( 'wasteBook' );
  11494. $wasteBook = new wasteBook ();
  11495. Doo::loadModel ( 'L_category' );
  11496. $L_category = new L_category ();
  11497. Doo::loadClass ( 'XDeode' );
  11498. $XDeode = new XDeode ( 5 );
  11499. $dateArr = explode ( ':', $date );
  11500. $D1 = '';
  11501. $D2 = '';
  11502. $con = '';
  11503. if (! empty ( $date )) {
  11504. $D1 = $dateArr [0];
  11505. $D2 = $dateArr [1];
  11506. }
  11507. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11508. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11509. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11510. $con = ' and inputDate = "' . $D1 . '"';
  11511. if ($cid != 'ALL') {
  11512. $cid = $XDeode->decode ( $cid );
  11513. $con .= ' and cid = "' . $cid . '"';
  11514. }
  11515. if ($accountType != 'ALL') {
  11516. if ($accountType == 'INVOICE') {
  11517. $con .= ' and accountType = 11';
  11518. } elseif ($accountType == 'PAYMENTS') {
  11519. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11520. if ($dailyExpenditureType != 'ALL') {
  11521. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11522. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11523. }
  11524. } elseif ($accountType == 'RECEIPT') {
  11525. if ($receiptType == 'ALL') {
  11526. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11527. } else {
  11528. $receiptType = $XDeode->decode ( $receiptType );
  11529. echo $receiptType;
  11530. if ($receiptType == 1) {
  11531. $con .= ' and (accountType = 1 or accountType=2)';
  11532. } else {
  11533. $con .= ' and accountType = ' . $receiptType;
  11534. }
  11535. }
  11536. }
  11537. }
  11538. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11539. $sum = 0;
  11540. foreach ( $incomeList as $key => $value ) {
  11541. $sum += $value ['accountPriceShow'];
  11542. }
  11543. // print_r($incomeList);
  11544. // 获得办事和部门
  11545. $categoryList = $L_category->getCategory ();
  11546. $data ['accountType'] = $accountType;
  11547. $data ['cid'] = $cid;
  11548. $data ['categoryList'] = $categoryList;
  11549. $data ['sum'] = $sum;
  11550. $data ['incomeList'] = $incomeList;
  11551. $data ['inputDate'] = $date;
  11552. $data ['memu'] = "receipt";
  11553. $data ['staff'] = $this->staff;
  11554. $data ['receiptMemu'] = 'wasteBook';
  11555. $data ['verifyId'] = $this->verifyId;
  11556. $data ['executeId'] = $this->executeId;
  11557. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11558. }
  11559. function ajaxGetWasteinvoiceReceivables() {
  11560. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11561. Doo::loadClass ( 'XDeode' );
  11562. $XDeode = new XDeode ( 5 );
  11563. $irid = $XDeode->decode ( $serial );
  11564. Doo::loadModel ( 'invoiceReceivables' );
  11565. $invoiceReceivables = new invoiceReceivables ();
  11566. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11567. echo json_encode ( array (
  11568. 'status' => 1,
  11569. 'detail' => $detail
  11570. ) );
  11571. }
  11572. function ajaxGetPaymentsByAid() {
  11573. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11574. Doo::loadModel ( "accountBook" );
  11575. $accountBook = new accountBook ();
  11576. $detail = $accountBook->getAccountBookByAid ( $serial );
  11577. echo json_encode ( array (
  11578. 'status' => 1,
  11579. 'detail' => $detail
  11580. ) );
  11581. }
  11582. function ajaxGetWasteInvoice() {
  11583. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11584. Doo::loadModel ( 'invoice' );
  11585. $invoice = new invoice ();
  11586. Doo::loadModel ( 'invoiceReceivables' );
  11587. $invoiceReceivables = new invoiceReceivables ();
  11588. $detail = $invoice->getInvoiceByIid ( $serial );
  11589. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11590. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11591. echo json_encode ( array (
  11592. 'status' => 1,
  11593. 'detail' => $detail
  11594. ) );
  11595. }
  11596. /**
  11597. */
  11598. function ajaxGetWasteReceipt() {
  11599. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11600. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11601. Doo::loadModel ( 'receipt' );
  11602. $receipt = new receipt ();
  11603. Doo::loadClass ( 'XDeode' );
  11604. $XDeode = new XDeode ( 5 );
  11605. $rid = $XDeode->decode ( $serial );
  11606. $accountType= $XDeode->decode ( $accountTypeKey );
  11607. // 获得个数据
  11608. $detail = $receipt->getReceiptByRid ( $rid );
  11609. // 初始化
  11610. $detail ['reviseDetail'] = array ();
  11611. if (! empty ( $value ['reviseDetail'] ))
  11612. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11613. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11614. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11615. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11616. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11617. // 获得费用html
  11618. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11619. // 获得费用审批人数据
  11620. $detail = $this->getReceiptApproverHtml ( $detail );
  11621. // 审批执行
  11622. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11623. <th class="taC" width="90">审批人</th>
  11624. <th class="taC">审批意见</th></tr>';
  11625. foreach ( $detail ['verifyList'] as $key => $value ) {
  11626. $html .= '<tr>
  11627. <td>' . $value [1] . '</td>
  11628. <td>' . $value ['opinion'] . '</td>
  11629. </tr>
  11630. ';
  11631. }
  11632. $html .= ' </tbody></table>';
  11633. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11634. <th class="taC" width="90">执行人</th>
  11635. <th class="taC">执行意见</th></tr>';
  11636. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11637. $html .= '<tr>
  11638. <td>' . $value [1] . '</td>
  11639. <td>' . $value ['opinion'] . '</td>
  11640. </tr>
  11641. ';
  11642. }
  11643. $html .= ' </tbody></table>';
  11644. if($accountType==1){
  11645. Doo::loadModel ( 'loanReceipt' );
  11646. $loanReceipt = new loanReceipt ();
  11647. $loanList = $loanReceipt->getOne ( array (
  11648. 'where' => 'rid=' . $detail ['loanRid'],
  11649. 'desc' => 'rid',
  11650. 'asArray' => true
  11651. ) );
  11652. $html .= '<table class="table table-bordered table-condensed">
  11653. <tr class="warning">
  11654. <td class="taR"><b>汇款金额</b></td>
  11655. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11656. </tr>
  11657. </table>';
  11658. }else{
  11659. $html .= '<table class="table table-bordered table-condensed">
  11660. <tr class="warning">
  11661. <td class="taR"><b>汇款金额</b></td>
  11662. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11663. </tr>
  11664. </table>';
  11665. }
  11666. // print_r($detail['verifyList']);
  11667. // header ( 'Content-Type:text/html;charset=utf-8' );
  11668. // echo $html;
  11669. echo json_encode ( array (
  11670. 'status' => 1,
  11671. 'html' => $html,
  11672. 'detail' => $detail
  11673. ) );
  11674. }
  11675. function getReceiptApproverHtml($detail = array()) {
  11676. Doo::loadModel ( 'loanReceipt' );
  11677. $loanReceipt = new loanReceipt ();
  11678. Doo::loadModel ( 'verify' );
  11679. $verify = new verify ();
  11680. Doo::loadModel ( 'staff' );
  11681. $staff = new staff ();
  11682. if (empty ( $detail ))
  11683. return array ();
  11684. $loanList = $loanReceipt->getOne ( array (
  11685. 'where' => 'rid=' . $detail ['loanRid'],
  11686. 'desc' => 'rid',
  11687. 'asArray' => true
  11688. ) );
  11689. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11690. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11691. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11692. else
  11693. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11694. } else
  11695. $verifyList = $verify->getOne ( array (
  11696. 'where' => 'vid=' . $detail ['verify'],
  11697. 'asArray' => true
  11698. ) );
  11699. $verifyList = json_decode ( $verifyList ['staff'], true );
  11700. Doo::loadModel ( 'role' );
  11701. $role = new role ();
  11702. $roleId = 0;
  11703. $flag = true;
  11704. $roleKey = 0;
  11705. $endStaffArray = array ();
  11706. $roleArrayCopy = array ();
  11707. foreach ( $verifyList as $k => $v ) {
  11708. // init verifyStaff
  11709. if ($v [1] == 'ROLE') {
  11710. if (! empty ( $verifyStaff )) {
  11711. $endStaffArray = end ( $verifyStaff );
  11712. }
  11713. $roleVerify = json_decode ( $v [3], true );
  11714. $roleKey = $k;
  11715. $roleArray = array ();
  11716. $rolename = $role->getOne ( array (
  11717. 'where' => 'rid=' . $v [0],
  11718. 'asArray' => true
  11719. ) );
  11720. foreach ( $roleVerify as $o => $p ) {
  11721. $staffID = explode ( '_', $p );
  11722. $staffInfo = $staff->getOne ( array (
  11723. 'where' => 'sid=' . $staffID [0],
  11724. 'asArray' => true
  11725. ) );
  11726. // print_r($staffID);
  11727. $exp = array (
  11728. 0 => $staffInfo ['sid'],
  11729. 1 => $staffID [1],
  11730. 2 => $staffInfo ['avatar'],
  11731. 'date' => '',
  11732. 'date' => '',
  11733. 'opinion' => '',
  11734. 'status' => '',
  11735. 'rolename' => $rolename ['name']
  11736. );
  11737. array_push ( $roleArray, $exp );
  11738. }
  11739. $roleArrayCopy [$v [0]] = $roleArray;
  11740. // $verifyList[$k]['roleArray']=$roleArray;
  11741. }
  11742. $verifyList [$k] ['date'] = "";
  11743. $verifyList [$k] ['opinion'] = "";
  11744. $verifyList [$k] ['status'] = "";
  11745. if (empty ( $verifyStaff )) {
  11746. $verifyList [$k] ['date'] = "";
  11747. $verifyList [$k] ['opinion'] = "";
  11748. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11749. $verifyList [$k] ['status'] = 4;
  11750. $flag = false;
  11751. }
  11752. } else {
  11753. foreach ( $verifyStaff as $m => $u ) {
  11754. if ($v [0] == $m) {
  11755. $verifyList [$k] ['date'] = $u ['date'];
  11756. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11757. $verifyList [$k] ['status'] = $u ['status'];
  11758. $flag = false;
  11759. break;
  11760. }
  11761. }
  11762. $endStaffArray = end ( $verifyStaff );
  11763. }
  11764. }
  11765. $rolename ['name'] = '';
  11766. if (! empty ( $roleId )) {
  11767. Doo::loadModel ( 'role' );
  11768. $role = new role ();
  11769. $rolename = $role->getOne ( array (
  11770. 'where' => 'rid=' . $roleId,
  11771. 'asArray' => true
  11772. ) );
  11773. }
  11774. if (! empty ( $verifyStaff ))
  11775. $endStaffArray = end ( $verifyStaff );
  11776. $KOP = false;
  11777. foreach ( $roleArrayCopy as $P => $A ) {
  11778. foreach ( $A as $MKI => $AVL ) {
  11779. if (! empty ( $verifyStaff )) {
  11780. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11781. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11782. $button = 4;
  11783. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11784. }
  11785. foreach ( $verifyStaff as $m => $u ) {
  11786. $AVLFK = $AVL [0] . '_R';
  11787. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11788. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11789. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11790. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11791. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11792. break;
  11793. }
  11794. }
  11795. } else {
  11796. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11797. $button = 4;
  11798. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11799. }
  11800. }
  11801. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11802. $KOP = true;
  11803. }
  11804. }
  11805. foreach ( $roleArrayCopy as $k => $v ) {
  11806. foreach ( $verifyList as $m => $n ) {
  11807. if ($n [0] == $k) {
  11808. array_splice ( $verifyList, $m, 1, $v );
  11809. }
  11810. }
  11811. }
  11812. // 费用执行人相关数据
  11813. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11814. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11815. foreach ( $executeCopy as $k => $v ) {
  11816. $executeCopy [$k] ['date'] = '';
  11817. $executeCopy [$k] ['opinion'] = '';
  11818. $executeCopy [$k] ['status'] = '';
  11819. if (! empty ( $executeStaff ))
  11820. foreach ( $executeStaff as $m => $u ) {
  11821. if ($v [0] == $m) {
  11822. $executeCopy [$k] ['date'] = $u ['date'];
  11823. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11824. $executeCopy [$k] ['status'] = $u ['status'];
  11825. break;
  11826. }
  11827. }
  11828. }
  11829. $detail ['executeCopy'] = $executeCopy;
  11830. $detail ['verifyList'] = $verifyList;
  11831. return $detail;
  11832. }
  11833. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11834. if (empty ( $detail ))
  11835. return '';
  11836. $html = '';
  11837. if ($detail ['Rtype'] == 0) { // 报销单
  11838. $html .= '<table class="table table-bordered table-condensed">
  11839. <tbody>
  11840. <tr>
  11841. <th colspan="2" class="taC">日常相关费用</th>
  11842. </tr>';
  11843. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11844. $html .= '
  11845. <tr>
  11846. <th>' . $value ['name'] . '</th>
  11847. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11848. </tr>';
  11849. }
  11850. $html .= '
  11851. <tr>
  11852. <th class="taR">合计</th>
  11853. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11854. </tr>';
  11855. $html .= '<tr>
  11856. <th colspan="2" class="taC">差旅相关费用</th>
  11857. </tr>';
  11858. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11859. $html .= '
  11860. <tr>
  11861. <th>' . $value ['name'] . '</th>
  11862. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11863. </tr>';
  11864. }
  11865. $html .= '
  11866. <tr>
  11867. <th class="taR">合计</th>
  11868. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11869. </tr>';
  11870. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11871. $html .= '<tr>
  11872. <th colspan="2" class="taC">内部培训费用</th>
  11873. </tr>';
  11874. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11875. $html .= '
  11876. <tr>
  11877. <th>' . $value ['name'] . '</th>
  11878. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11879. </tr>';
  11880. }
  11881. $html .= '
  11882. <tr>
  11883. <th class="taR">合计</th>
  11884. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11885. </tr>';
  11886. }
  11887. $html .= '<tr>
  11888. <th colspan="2" class="taC">其他</th>
  11889. </tr>';
  11890. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11891. $html .= '
  11892. <tr>
  11893. <th>' . $value ['name'] . '</th>
  11894. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11895. </tr>';
  11896. }
  11897. $html .= '
  11898. <tr>
  11899. <th class="taR">合计</th>
  11900. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11901. </tr>';
  11902. $html .= '<tr>
  11903. <th colspan="2" class="taC">报销金额调整</th>
  11904. </tr>';
  11905. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11906. $html .= '
  11907. <tr>
  11908. <th>' . $value ['name'] . '</th>
  11909. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11910. </tr>';
  11911. }
  11912. $html .= '
  11913. <tr>
  11914. <th class="taR">合计</th>
  11915. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11916. </tr>';
  11917. $html .= '
  11918. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11919. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11920. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11921. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11922. <tr class="warning">
  11923. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11924. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11925. </tr>
  11926. </tbody>
  11927. </table>';
  11928. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  11929. $html .= '
  11930. <table class="table table-bordered table-condensed">
  11931. <tbody>
  11932. <tr>
  11933. <th colspan="2" class="taC">办事处相关费用</th>
  11934. </tr>';
  11935. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11936. $html .= '
  11937. <tr>
  11938. <th>' . $value ['name'] . '</th>
  11939. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11940. </tr>';
  11941. }
  11942. $html .= '
  11943. <tr>
  11944. <th class="taR">合计</th>
  11945. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11946. </tr>';
  11947. $html .= '
  11948. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11949. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11950. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11951. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11952. <tr class="warning">
  11953. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11954. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11955. </tr>
  11956. </tbody>
  11957. </table>';
  11958. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  11959. Doo::loadModel ( 'loanReceipt' );
  11960. $loanReceipt = new loanReceipt ();
  11961. $loanList = $loanReceipt->getOne ( array (
  11962. 'where' => 'rid=' . $detail ['loanRid'],
  11963. 'desc' => 'rid',
  11964. 'asArray' => true
  11965. ) );
  11966. // print_r($loanList);
  11967. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  11968. $html .= '<table class="table table-bordered table-condensed">
  11969. <tbody>
  11970. <tr>
  11971. <th colspan="2" class="taC">借款费用</th>
  11972. </tr>';
  11973. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  11974. $html .= '<tr>
  11975. <th>' . $value ['name'] . '</th>
  11976. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11977. </tr>';
  11978. }
  11979. $html .= '<tr>
  11980. <th class="taC" colspan="2">产生费用所在办事处</th>
  11981. </tr>
  11982. <tr>
  11983. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  11984. </tr>
  11985. <tr>
  11986. <th class="taC" colspan="2">费用说明</th>
  11987. </tr>
  11988. <tr>
  11989. <td colspan="2">' . $loanList ['explanation'] . '</td>
  11990. </tr>
  11991. <tr class="warning">
  11992. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  11993. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  11994. </tr>
  11995. </tbody>
  11996. </table>
  11997. ';
  11998. if ( $accountType==2) {
  11999. $balance=$detail ['sum']-$loanList ['sum'];
  12000. $balanceCN=$this->num_to_rmb($balance);
  12001. $html .= '<table class="table table-bordered table-condensed">
  12002. <tbody>
  12003. <tr>
  12004. <th colspan="2" class="taC">日常相关费用</th>
  12005. </tr>';
  12006. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12007. $html .= '
  12008. <tr>
  12009. <th>' . $value ['name'] . '</th>
  12010. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12011. </tr>';
  12012. }
  12013. $html .= '
  12014. <tr>
  12015. <th class="taR">合计</th>
  12016. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12017. </tr>';
  12018. $html .= '<tr>
  12019. <th colspan="2" class="taC">差旅相关费用</th>
  12020. </tr>';
  12021. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12022. $html .= '
  12023. <tr>
  12024. <th>' . $value ['name'] . '</th>
  12025. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12026. </tr>';
  12027. }
  12028. $html .= '
  12029. <tr>
  12030. <th class="taR">合计</th>
  12031. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12032. </tr>';
  12033. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12034. $html .= '<tr>
  12035. <th colspan="2" class="taC">内部培训费用</th>
  12036. </tr>';
  12037. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12038. $html .= '
  12039. <tr>
  12040. <th>' . $value ['name'] . '</th>
  12041. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12042. </tr>';
  12043. }
  12044. $html .= '
  12045. <tr>
  12046. <th class="taR">合计</th>
  12047. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12048. </tr>';
  12049. }
  12050. $html .= '<tr>
  12051. <th colspan="2" class="taC">其他</th>
  12052. </tr>';
  12053. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12054. $html .= '
  12055. <tr>
  12056. <th>' . $value ['name'] . '</th>
  12057. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12058. </tr>';
  12059. }
  12060. $html .= '
  12061. <tr>
  12062. <th class="taR">合计</th>
  12063. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12064. </tr>';
  12065. $html .= '<tr>
  12066. <th colspan="2" class="taC">报销金额调整</th>
  12067. </tr>';
  12068. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12069. $html .= '
  12070. <tr>
  12071. <th>' . $value ['name'] . '</th>
  12072. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12073. </tr>';
  12074. }
  12075. $html .= '
  12076. <tr>
  12077. <th class="taR">合计</th>
  12078. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12079. </tr>';
  12080. $html .= '
  12081. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12082. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12083. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12084. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12085. <tr class="warning">
  12086. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12087. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12088. </tr>
  12089. <tr class="success">
  12090. <td class="taR"><b>借款结余</b></td>
  12091. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12092. </tr>
  12093. </tbody>
  12094. </table>';
  12095. }
  12096. }
  12097. return $html;
  12098. }
  12099. /**
  12100. * 计算流水
  12101. */
  12102. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12103. $bakWaste ['bank'] = array (
  12104. 'CGBDeposit' => 0,
  12105. 'ICBCDeposit' => 0,
  12106. 'HUADeposit' => 0,
  12107. 'PersonalDeposit' => 0
  12108. );
  12109. $bakWaste ['financial'] = array (
  12110. 'current' => array (
  12111. 'CGBDeposit' => 0,
  12112. 'ICBCDeposit' => 0
  12113. ),
  12114. 'fixed' => array (
  12115. 'CGBDeposit' => 0,
  12116. 'ICBCDeposit' => 0
  12117. )
  12118. );
  12119. // 存款
  12120. foreach ( $waste ['bank'] as $key => $value ) {
  12121. // 收入
  12122. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12123. // 广发
  12124. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12125. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12126. }
  12127. // 工商
  12128. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12129. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12130. }
  12131. // 华润
  12132. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12133. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12134. }
  12135. // 个人
  12136. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12137. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12138. }
  12139. }
  12140. }
  12141. foreach ( $waste ['bank'] as $key => $value ) {
  12142. // 支出
  12143. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12144. // 广发
  12145. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12146. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12147. }
  12148. // 工商
  12149. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12150. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12151. }
  12152. // 华润
  12153. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12154. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12155. }
  12156. // 个人
  12157. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12158. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12159. }
  12160. }
  12161. }
  12162. // 活期
  12163. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12164. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12165. // 广发
  12166. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12167. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12168. }
  12169. // 工商
  12170. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12171. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12172. }
  12173. // 个人
  12174. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12175. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12176. }
  12177. }
  12178. }
  12179. // print_r($inComeStatistics ['fixedStatistics']);
  12180. // 固期
  12181. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12182. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12183. // 广发
  12184. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12185. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12186. }
  12187. // 工商
  12188. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12189. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12190. }
  12191. // 个人
  12192. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12193. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12194. }
  12195. }
  12196. }
  12197. return $waste;
  12198. }
  12199. function lyt() {
  12200. Doo::loadModel ( "receiptDetail" );
  12201. $receiptDetail = new receiptDetail ();
  12202. $receiptCollectList = $receiptDetail->find ( array (
  12203. 'where' => 'status=1 ',
  12204. 'asArray' => true
  12205. ) );
  12206. foreach ( $receiptCollectList as $key => $value ) {
  12207. $receiptDetail = new receiptDetail ();
  12208. $receiptDetail->pastDate = $value ['date'];
  12209. $receiptDetail->update ( array (
  12210. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12211. ) );
  12212. }
  12213. }
  12214. function staffCollectMonthDetail() {
  12215. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12216. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12217. if (! $year)
  12218. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12219. if (! $month)
  12220. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12221. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12222. if (! $nature){
  12223. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12224. }
  12225. Doo::loadModel ( 'staff' );
  12226. $staff = new staff ();
  12227. Doo::loadModel ( "receiptDetail" );
  12228. $receiptDetail = new receiptDetail ();
  12229. Doo::loadModel ( 'accountItem' );
  12230. $accountItem = new accountItem ();
  12231. Doo::loadModel ( 'statistics' );
  12232. $statistics = new statistics ();
  12233. Doo::loadModel ( "receiptAuthorityManage" );
  12234. $receiptAuthorityManage = new receiptAuthorityManage ();
  12235. $aiList=$accountItem->getAccountItem();
  12236. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12237. $cidList = array ();
  12238. foreach ( $imcStaff as $key => $value ) {
  12239. array_push ( $cidList, $value ['cid'] );
  12240. }
  12241. $cidString = implode ( ',', $cidList );
  12242. $naturecon='';
  12243. if ($nature=='ONJOB'){
  12244. $naturecon=' and (nature!=4 )';
  12245. }elseif($nature=='LEAVEJOB'){
  12246. $naturecon=' and (nature=4 )';
  12247. }else{
  12248. die ( 'illegal request--nature' );
  12249. }
  12250. $staffList = $staff->find ( array (
  12251. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12252. 'asArray' => true
  12253. ) );
  12254. $categoryList = $staff->find ( array (
  12255. 'select' => 'COUNT(*) as count,cid,category',
  12256. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12257. 'groupby' => 'cid',
  12258. 'asArray' => true
  12259. ) );
  12260. $list = array ();
  12261. foreach($aiList as $key=>$value){
  12262. foreach ($value as $v){
  12263. $subtotal[$key][$v['name']]=0;
  12264. }
  12265. }
  12266. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12267. foreach ( $categoryList as $vlu ) {
  12268. $s1 = 0;
  12269. $m1 = 0;
  12270. foreach ( $staffList as $value ) {
  12271. if ($vlu ['cid'] == $value ['cid']) {
  12272. // pastDate
  12273. $receiptCollectList = $receiptDetail->find ( array (
  12274. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12275. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12276. 'groupby' => 'item,Month(pastDate),itemCategory',
  12277. 'asArray' => true
  12278. ) );
  12279. if (! empty ( $receiptCollectList )) {
  12280. $receiptL = array (
  12281. '日常相关费用' => array (),
  12282. '差旅相关费用' => array (),
  12283. '内部培训费用' => array (),
  12284. '培训班费用' => array (),
  12285. '其他' => array ()
  12286. );
  12287. $html = "";
  12288. $psum = 0;
  12289. foreach ( $aiList[$this->AGENCY] as $va ) {
  12290. $falg = true;
  12291. foreach ( $receiptCollectList as $v ) {
  12292. if ($v ['itemCategory'] == '日常相关费用') {
  12293. if ($v ['item'] == $va['name']) {
  12294. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12295. $psum += $v ['price'];
  12296. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12297. $falg = false;
  12298. break;
  12299. }
  12300. }
  12301. }
  12302. if ($falg)
  12303. $html .= '<td class="taR">-</td>';
  12304. }
  12305. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12306. if (! empty ( $psum ))
  12307. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12308. else
  12309. $psum = '<td class="colGreen taR">-</td>';
  12310. $receiptL ['日常相关费用'] = $psum . $html;
  12311. /* ----------------------------------- */
  12312. $html = "";
  12313. $psum = 0;
  12314. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12315. $falg = true;
  12316. foreach ( $receiptCollectList as $v ) {
  12317. if ($v ['itemCategory'] == '差旅相关费用') {
  12318. if ($v ['item'] == $va['name']) {
  12319. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12320. $psum += $v ['price'];
  12321. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12322. $falg = false;
  12323. break;
  12324. }
  12325. }
  12326. }
  12327. if ($falg)
  12328. $html .= '<td class="taR">-</td>';
  12329. }
  12330. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12331. if (! empty ( $psum ))
  12332. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12333. else
  12334. $psum = '<td class="colGreen taR">-</td>';
  12335. $receiptL ['差旅相关费用'] = $psum . $html;
  12336. /* ------------------------------------- */
  12337. $html = "";
  12338. $psum = 0;
  12339. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12340. $falg = true;
  12341. foreach ( $receiptCollectList as $v ) {
  12342. if ($v ['itemCategory'] == '内部培训费用') {
  12343. if ($v ['item'] == $va['name']) {
  12344. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12345. $psum += $v ['price'];
  12346. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12347. $falg = false;
  12348. break;
  12349. }
  12350. }
  12351. }
  12352. if ($falg)
  12353. $html .= '<td class="taR">-</td>';
  12354. }
  12355. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12356. if (! empty ( $psum ))
  12357. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12358. else
  12359. $psum = '<td class="colGreen taR">-</td>';
  12360. $receiptL ['内部培训费用'] = $psum . $html;
  12361. /* ----------------------------------- */
  12362. $html = "";
  12363. $psum = 0;
  12364. foreach ( $aiList[$this->TRAIN] as $va ) {
  12365. $falg = true;
  12366. foreach ( $receiptCollectList as $v ) {
  12367. if ($v ['itemCategory'] == '培训班费用') {
  12368. if ($v ['item'] == $va['name']) {
  12369. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12370. $psum += $v ['price'];
  12371. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12372. $falg = false;
  12373. break;
  12374. }
  12375. }
  12376. }
  12377. if ($falg)
  12378. $html .= '<td class="taR">-</td>';
  12379. }
  12380. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12381. if (! empty ( $psum ))
  12382. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12383. else
  12384. $psum = '<td class="colGreen taR">-</td>';
  12385. $receiptL ['培训班费用'] = $psum . $html;
  12386. /* ------------------------------------- */
  12387. $html = "";
  12388. $psum = 0;
  12389. foreach ( $aiList[$this->OTHER] as $va ) {
  12390. $falg = true;
  12391. foreach ( $receiptCollectList as $v ) {
  12392. if ($v ['itemCategory'] == '其他') {
  12393. if (trim ( $v ['item'] ) == $va['name']) {
  12394. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12395. $psum += $v ['price'];
  12396. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12397. $falg = false;
  12398. break;
  12399. }
  12400. }
  12401. }
  12402. if ($falg)
  12403. $html .= '<td class="taR">-</td>';
  12404. }
  12405. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12406. if (! empty ( $psum ))
  12407. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12408. else
  12409. $psum = '<td class="colGreen taR">-</td>';
  12410. $receiptL ['其他'] = $psum . $html;
  12411. /* ------------------------------------- */
  12412. $html = "";
  12413. $psum = 0;
  12414. foreach ( $receiptCollectList as $v ) {
  12415. if ($v ['itemCategory'] == '报销金额调整') {
  12416. if (! empty ( $v ['price'] )) {
  12417. $psum += $v ['price'];
  12418. }
  12419. }
  12420. }
  12421. $s1 += $psum;
  12422. if (! empty ( $psum ))
  12423. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12424. else
  12425. $psum = '<td class="taR colOrange">-</td>';
  12426. $receiptL ['报销金额调整'] = $psum . $html;
  12427. } else {
  12428. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12429. foreach ( $aiList[$this->AGENCY] as $va ) {
  12430. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12431. }
  12432. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12433. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12434. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12435. }
  12436. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12437. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12438. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12439. }
  12440. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12441. foreach ( $aiList[$this->TRAIN] as $va ) {
  12442. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12443. }
  12444. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12445. foreach ( $aiList[$this->OTHER] as $va ) {
  12446. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12447. }
  12448. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12449. }
  12450. $monthStaffPrice = $receiptDetail->find ( array (
  12451. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12452. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12453. 'groupby' => 'Month(pastDate)',
  12454. 'asArray' => true
  12455. ) );
  12456. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12457. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12458. $m1 += $monthStaffPrice [0] ['price'];
  12459. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12460. } else
  12461. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12462. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12463. $list [$value ['username']] = $receiptL;
  12464. }
  12465. }
  12466. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12467. foreach ( $aiList[$this->AGENCY] as $va ) {
  12468. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12469. }
  12470. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12471. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12472. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12473. }
  12474. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12475. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12476. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12477. }
  12478. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12479. foreach ( $aiList[$this->TRAIN] as $va ) {
  12480. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12481. }
  12482. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12483. foreach ( $aiList[$this->OTHER] as $va ) {
  12484. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12485. }
  12486. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12487. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12488. $receiptL ['usernameEn'] =false;
  12489. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12490. }
  12491. $data ['list'] = $list;
  12492. // print_r($list);
  12493. $receiptCollectList = $receiptDetail->find ( array (
  12494. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12495. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12496. 'groupby' => 'item,Month(pastDate),itemCategory',
  12497. 'asArray' => true
  12498. ) );
  12499. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12500. // statistics html
  12501. $stList = $statistics->getOne ( array (
  12502. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12503. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12504. 'groupby' => 'Month(date)',
  12505. 'asArray' => true
  12506. ) );
  12507. if (empty ( $stList ))
  12508. $stList = array (
  12509. 'rePrice' => 0,
  12510. 'agPrice' => 0
  12511. );
  12512. $data ['stList'] = array (
  12513. 'rePrice' => $stList ['rePrice'],
  12514. 'agPrice' => $stList ['agPrice'],
  12515. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12516. );
  12517. $monthHtml = "";
  12518. for($i = 1; $i <= 12; $i ++) {
  12519. if ($i == $month)
  12520. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12521. else
  12522. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12523. }
  12524. $data ['monthHtml'] = $monthHtml;
  12525. $data ['year'] = $year;
  12526. $data ['month'] = $month;
  12527. $data ['nature'] = $nature;
  12528. $data ['aiList'] = $aiList;
  12529. $data ['memu'] = "receipt";
  12530. $data ['staff'] = $this->staff;
  12531. $data ['receiptMemu'] = 'companyCategoryCollect';
  12532. $data ['verifyId'] = $this->verifyId;
  12533. $data ['executeId'] = $this->executeId;
  12534. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12535. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12536. }
  12537. function staffCollectMonthDetail2() {
  12538. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12539. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12540. if (! $year)
  12541. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12542. if (! $month)
  12543. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12544. Doo::loadModel ( 'staff' );
  12545. $staff = new staff ();
  12546. Doo::loadModel ( "receiptDetail" );
  12547. $receiptDetail = new receiptDetail ();
  12548. Doo::loadModel ( 'accountItem' );
  12549. $accountItem = new accountItem ();
  12550. Doo::loadModel ( 'statistics' );
  12551. $statistics = new statistics ();
  12552. Doo::loadModel ( 'L_category' );
  12553. $lCategory = new L_category ();
  12554. $staffList = $staff->find ( array (
  12555. 'where' => 'username!="admin"',
  12556. 'asArray' => true
  12557. ) );
  12558. $categoryList = $staff->find ( array (
  12559. 'select' => 'COUNT(*) as count,cid,category',
  12560. 'where' => 'username !="admin"',
  12561. 'groupby' => 'cid',
  12562. 'asArray' => true
  12563. ) );
  12564. $list = array ();
  12565. foreach ( $categoryList as $vlu ) {
  12566. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12567. $r1 = 0;
  12568. $r2 = 0;
  12569. $r3 = 0;
  12570. $r4 = 0;
  12571. $r5 = 0;
  12572. $r6 = 0;
  12573. $r7 = 0;
  12574. $r8 = 0;
  12575. $r9 = 0;
  12576. $r10 = 0;
  12577. $r11 = 0;
  12578. $r12 = 0;
  12579. $r13 = 0;
  12580. $r14 = 0;
  12581. $r15 = 0;
  12582. $c1 = 0;
  12583. $c2 = 0;
  12584. $c3 = 0;
  12585. $c4 = 0;
  12586. $c5 = 0;
  12587. $c6 = 0;
  12588. $p1 = 0;
  12589. $p2 = 0;
  12590. $p3 = 0;
  12591. $p4 = 0;
  12592. $p5 = 0;
  12593. $p6 = 0;
  12594. $p7 = 0;
  12595. $p8 = 0;
  12596. $p9 = 0;
  12597. $t1 = 0;
  12598. $t2 = 0;
  12599. $t3 = 0;
  12600. $t4 = 0;
  12601. $t5 = 0;
  12602. $s1 = 0;
  12603. $m1 = 0;
  12604. foreach ( $staffList as $value ) {
  12605. if ($vlu ['cid'] == $value ['cid']) {
  12606. $receiptCollectList = $receiptDetail->find ( array (
  12607. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12608. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12609. 'groupby' => 'item,Month(date),itemCategory',
  12610. 'asArray' => true
  12611. ) );
  12612. if (! empty ( $receiptCollectList )) {
  12613. $receiptL = array (
  12614. '日常相关费用' => array (),
  12615. '差旅相关费用' => array (),
  12616. '培训班费用' => array (),
  12617. '其他' => array ()
  12618. );
  12619. $html = "";
  12620. $psum = 0;
  12621. $item = array (
  12622. '市内交通费',
  12623. '市内出租费',
  12624. '办事处房租',
  12625. '电话费',
  12626. '水费',
  12627. '电费',
  12628. '办公费用',
  12629. '邮寄费',
  12630. '其他费用',
  12631. '车辆费用',
  12632. '广告费',
  12633. '团队建设费',
  12634. '物业管理费',
  12635. '宽带费'
  12636. );
  12637. foreach ( $item as $va ) {
  12638. $falg = true;
  12639. foreach ( $receiptCollectList as $v ) {
  12640. if ($v ['itemCategory'] == '日常相关费用') {
  12641. if ($v ['item'] == $va) {
  12642. if ($va == '市内交通费')
  12643. $r1 += $v ['price'];
  12644. if ($va == '市内出租费')
  12645. $r2 += $v ['price'];
  12646. if ($va == '办事处房租')
  12647. $r3 += $v ['price'];
  12648. if ($va == '电话费')
  12649. $r4 += $v ['price'];
  12650. if ($va == '水费')
  12651. $r5 += $v ['price'];
  12652. if ($va == '电费')
  12653. $r6 += $v ['price'];
  12654. if ($va == '办公费用')
  12655. $r7 += $v ['price'];
  12656. if ($va == '邮寄费')
  12657. $r8 += $v ['price'];
  12658. if ($va == '其他费用')
  12659. $r9 += $v ['price'];
  12660. if ($va == '车辆费用')
  12661. $r10 += $v ['price'];
  12662. if ($va == '广告费')
  12663. $r11 += $v ['price'];
  12664. if ($va == '团队建设费')
  12665. $r13 += $v ['price'];
  12666. if ($va == '物业管理费')
  12667. $r14 += $v ['price'];
  12668. if ($va == '宽带费')
  12669. $r15 += $v ['price'];
  12670. $psum += $v ['price'];
  12671. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12672. $falg = false;
  12673. break;
  12674. }
  12675. }
  12676. }
  12677. if ($falg)
  12678. $html .= '<td class="taR">-</td>';
  12679. }
  12680. $r12 += $psum;
  12681. if (! empty ( $psum ))
  12682. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12683. else
  12684. $psum = '<td class="colGreen taR">-</td>';
  12685. $receiptL ['日常相关费用'] = $psum . $html;
  12686. /* ----------------------------------- */
  12687. $html = "";
  12688. $psum = 0;
  12689. $item = array (
  12690. '往来交通费',
  12691. '市内交通费',
  12692. '出差住宿费',
  12693. '出差补助',
  12694. '其他费用'
  12695. );
  12696. foreach ( $item as $va ) {
  12697. $falg = true;
  12698. foreach ( $receiptCollectList as $v ) {
  12699. if ($v ['itemCategory'] == '差旅相关费用') {
  12700. if ($v ['item'] == $va) {
  12701. if ($va == '往来交通费')
  12702. $c1 += $v ['price'];
  12703. if ($va == '市内交通费')
  12704. $c2 += $v ['price'];
  12705. if ($va == '出差住宿费')
  12706. $c3 += $v ['price'];
  12707. if ($va == '出差补助')
  12708. $c4 += $v ['price'];
  12709. if ($va == '其他费用')
  12710. $c5 += $v ['price'];
  12711. $psum += $v ['price'];
  12712. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12713. $falg = false;
  12714. break;
  12715. }
  12716. }
  12717. }
  12718. if ($falg)
  12719. $html .= '<td class="taR">-</td>';
  12720. }
  12721. $c6 += $psum;
  12722. if (! empty ( $psum ))
  12723. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12724. else
  12725. $psum = '<td class="colGreen taR">-</td>';
  12726. $receiptL ['差旅相关费用'] = $psum . $html;
  12727. /* ------------------------------------- */
  12728. $html = "";
  12729. $psum = 0;
  12730. $item = array (
  12731. '场租费',
  12732. '薪酬',
  12733. '住宿费',
  12734. '交通费',
  12735. '餐饮费',
  12736. '办公费',
  12737. '公关费',
  12738. '其他'
  12739. );
  12740. foreach ( $item as $va ) {
  12741. $falg = true;
  12742. foreach ( $receiptCollectList as $v ) {
  12743. if ($v ['itemCategory'] == '培训班费用') {
  12744. if ($v ['item'] == $va) {
  12745. if ($va == '场租费')
  12746. $p1 += $v ['price'];
  12747. if ($va == '薪酬')
  12748. $p2 += $v ['price'];
  12749. if ($va == '住宿费')
  12750. $p3 += $v ['price'];
  12751. if ($va == '交通费')
  12752. $p4 += $v ['price'];
  12753. if ($va == '餐饮费')
  12754. $p5 += $v ['price'];
  12755. if ($va == '办公费')
  12756. $p6 += $v ['price'];
  12757. if ($va == '公关费')
  12758. $p7 += $v ['price'];
  12759. if ($va == '其他')
  12760. $p8 += $v ['price'];
  12761. $psum += $v ['price'];
  12762. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12763. $falg = false;
  12764. break;
  12765. }
  12766. }
  12767. }
  12768. if ($falg)
  12769. $html .= '<td class="taR">-</td>';
  12770. }
  12771. $p9 += $psum;
  12772. if (! empty ( $psum ))
  12773. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12774. else
  12775. $psum = '<td class="colGreen taR">-</td>';
  12776. $receiptL ['培训班费用'] = $psum . $html;
  12777. /* ------------------------------------- */
  12778. $html = "";
  12779. $psum = 0;
  12780. $item = array (
  12781. '公关费',
  12782. '广告费',
  12783. '借款',
  12784. '可自加费用'
  12785. );
  12786. foreach ( $item as $va ) {
  12787. $falg = true;
  12788. foreach ( $receiptCollectList as $v ) {
  12789. if ($v ['itemCategory'] == '其他') {
  12790. if ($v ['item'] == $va) {
  12791. if ($va == '公关费')
  12792. $t1 += $v ['price'];
  12793. if ($va == '广告费')
  12794. $t2 += $v ['price'];
  12795. if ($va == '借款')
  12796. $t3 += $v ['price'];
  12797. if ($va == '可自加费用')
  12798. $t4 += $v ['price'];
  12799. $psum += $v ['price'];
  12800. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12801. $falg = false;
  12802. break;
  12803. }
  12804. }
  12805. }
  12806. if ($falg)
  12807. $html .= '<td class="taR">-</td>';
  12808. }
  12809. $t5 += $psum;
  12810. if (! empty ( $psum ))
  12811. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12812. else
  12813. $psum = '<td class="colGreen taR">-</td>';
  12814. $receiptL ['其他'] = $psum . $html;
  12815. /* ------------------------------------- */
  12816. $html = "";
  12817. $psum = 0;
  12818. foreach ( $receiptCollectList as $v ) {
  12819. if ($v ['itemCategory'] == '报销金额调整') {
  12820. if (! empty ( $v ['price'] )) {
  12821. $psum += $v ['price'];
  12822. }
  12823. }
  12824. }
  12825. $s1 += $psum;
  12826. if (! empty ( $psum ))
  12827. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12828. else
  12829. $psum = '<td class="taR colOrange">-</td>';
  12830. $receiptL ['报销金额调整'] = $psum . $html;
  12831. } else {
  12832. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12833. <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>';
  12834. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12835. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12836. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12837. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12838. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12839. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12840. }
  12841. $monthStaffPrice = $receiptDetail->find ( array (
  12842. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12843. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12844. 'asArray' => true
  12845. ) );
  12846. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12847. $m1 += $monthStaffPrice [0] ['price'];
  12848. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12849. } else
  12850. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12851. $list [$value ['username']] = $receiptL;
  12852. }
  12853. }
  12854. $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>
  12855. <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>
  12856. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12857. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12858. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12859. $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>
  12860. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12861. $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>';
  12862. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12863. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12864. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12865. }
  12866. $data ['list'] = $list;
  12867. $receiptCollectList = $receiptDetail->find ( array (
  12868. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12869. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12870. 'groupby' => 'item,Month(date),itemCategory',
  12871. 'asArray' => true
  12872. ) );
  12873. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12874. // statistics html
  12875. $stList = $statistics->getOne ( array (
  12876. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12877. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12878. 'groupby' => 'Month(date)',
  12879. 'asArray' => true
  12880. ) );
  12881. if (empty ( $stList ))
  12882. $stList = array (
  12883. 'rePrice' => 0,
  12884. 'agPrice' => 0
  12885. );
  12886. $data ['stList'] = array (
  12887. 'rePrice' => $stList ['rePrice'],
  12888. 'agPrice' => $stList ['agPrice'],
  12889. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12890. );
  12891. $monthHtml = "";
  12892. for($i = 1; $i <= 12; $i ++) {
  12893. if ($i == $month)
  12894. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12895. else
  12896. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12897. }
  12898. $data ['monthHtml'] = $monthHtml;
  12899. $data ['year'] = $year;
  12900. $data ['month'] = $month;
  12901. $data ['memu'] = "receipt";
  12902. $data ['staff'] = $this->staff;
  12903. $data ['receiptMemu'] = 'companyCategoryCollect';
  12904. $data ['verifyId'] = $this->verifyId;
  12905. $data ['executeId'] = $this->executeId;
  12906. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12907. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12908. }
  12909. /**
  12910. * 用户报销单列表
  12911. */
  12912. function receiptStatisticsStaffDetail() {
  12913. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12914. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12915. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  12916. Doo::loadModel ( "receipt" );
  12917. $receipt = new receipt ();
  12918. Doo::loadModel ( "receiptDetail" );
  12919. $receiptDetail = new receiptDetail ();
  12920. Doo::loadModel ( 'staff' );
  12921. $staff = new staff ();
  12922. Doo::loadModel ( 'accountItem' );
  12923. $accountItem = new accountItem ();
  12924. Doo::loadModel ( 'statistics' );
  12925. $statistics = new statistics ();
  12926. if (! empty ( $username )) {
  12927. $username = addslashes ( urldecode ( $username ) );
  12928. $staffDetail = $staff->getStaffByName ( $username );
  12929. if (empty ( $staffDetail ))
  12930. die ( 'illegal request' );
  12931. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  12932. $itemList = $accountItem->getAccountItem ();
  12933. $itemHtml = '';
  12934. $categoryHtml = '';
  12935. $itemKeyList = array_keys ( $itemList );
  12936. $revisePrice = 0;
  12937. // 报销单内容详情
  12938. foreach ( $list as $key => $value ) {
  12939. $accountItemList = json_decode ( $value ['accountItem'], true );
  12940. $list [$key] ['accountItemList'] = $accountItemList;
  12941. $receiptItemHtml = '';
  12942. foreach ( $itemKeyList as $v ) {
  12943. if ($v == '日常相关费用')
  12944. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  12945. elseif ($v == '差旅相关费用')
  12946. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  12947. elseif ($v == '培训班费用')
  12948. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  12949. elseif ($v == '内部培训费用'){
  12950. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  12951. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  12952. }else{
  12953. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  12954. }
  12955. }elseif ($v == '其他')
  12956. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  12957. foreach ( $itemList [$v] as $ke => $va ) {
  12958. $falg = true;
  12959. if (! empty ( $accountItemList [$v] )) {
  12960. foreach ( $accountItemList [$v] as $ve ) {
  12961. if ($va ['name'] == $ve ['name']) {
  12962. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  12963. $falg = false;
  12964. break;
  12965. }
  12966. }
  12967. }
  12968. if ($falg)
  12969. $receiptItemHtml .= '<td class="taR"></td>';
  12970. }
  12971. }
  12972. // 金额调整和费用查看
  12973. $revisePrice += $value ['revisePrice'];
  12974. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  12975. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  12976. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  12977. }
  12978. // 报销单合计
  12979. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  12980. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  12981. $receiptTotalHtml = '';
  12982. // 报销单项目抬头
  12983. foreach ( $itemKeyList as $value ) {
  12984. $count = count ( $itemList [$value] ) + 1;
  12985. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  12986. $categoryHtml .= '<th class="taC">合计</th>';
  12987. $sumfalg=true;
  12988. foreach ( $rtl as $rtlValue ) {
  12989. if ($rtlValue ['itemCategory'] == $value) {
  12990. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  12991. $sumfalg=false;
  12992. break;
  12993. }
  12994. }
  12995. if ($sumfalg)
  12996. $receiptTotalHtml .= '<th></th>';
  12997. foreach ( $itemList [$value] as $k => $v ) {
  12998. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  12999. // 合计
  13000. $falg = true;
  13001. foreach ( $receiptTotalList as $ve ) {
  13002. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13003. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13004. $falg = false;
  13005. break;
  13006. }
  13007. }
  13008. if ($falg)
  13009. $receiptTotalHtml .= '<th></th>';
  13010. }
  13011. }
  13012. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13013. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13014. if (empty ( $stList ))
  13015. $stList = array (
  13016. 'rePrice' => 0,
  13017. 'agPrice' => 0
  13018. );
  13019. $data ['stList'] = array (
  13020. 'rePrice' => $stList ['rePrice'],
  13021. 'agPrice' => $stList ['agPrice'],
  13022. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13023. );
  13024. $monthHtml = "";
  13025. for($i = 1; $i <= 12; $i ++) {
  13026. if ($i == $month)
  13027. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13028. else
  13029. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13030. }
  13031. $data ['username'] = urlencode ( $username );
  13032. $data ['usernameEN'] = $username;
  13033. $data ['monthHtml'] = $monthHtml;
  13034. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13035. $data ['list'] = $list;
  13036. $data ['categoryHtml'] = $categoryHtml;
  13037. $data ['itemHtml'] = $itemHtml;
  13038. $data ['itemList'] = $itemList;
  13039. $data ['year'] = $year;
  13040. $data ['month'] = $month;
  13041. $data ['memu'] = "receipt";
  13042. $data ['staff'] = $this->staff;
  13043. $data ['receiptMemu'] = 'companyCategoryCollect';
  13044. $data ['verifyId'] = $this->verifyId;
  13045. $data ['executeId'] = $this->executeId;
  13046. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13047. }
  13048. die ( 'illegal request' );
  13049. }
  13050. function companyMonthCollectDetail() {
  13051. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13052. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13053. if (! $year)
  13054. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13055. if (! $month)
  13056. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13057. Doo::loadModel ( 'staff' );
  13058. $staff = new staff ();
  13059. Doo::loadModel ( "receiptDetail" );
  13060. $receiptDetail = new receiptDetail ();
  13061. Doo::loadModel ( 'accountItem' );
  13062. $accountItem = new accountItem ();
  13063. Doo::loadModel ( 'statistics' );
  13064. $statistics = new statistics ();
  13065. Doo::loadModel ( 'L_category' );
  13066. $lCategory = new L_category ();
  13067. $staffList = $staff->find ( array (
  13068. 'where' => 'username!="admin"',
  13069. 'asArray' => true
  13070. ) );
  13071. $categoryList = $lCategory->find ( array (
  13072. 'asArray' => true
  13073. ) );
  13074. $aiList=$accountItem->getAccountItem();
  13075. $list = array ();
  13076. foreach ( $categoryList as $value ) {
  13077. $receiptCollectList = $receiptDetail->find ( array (
  13078. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13079. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13080. 'groupby' => 'item,Month(pastDate),itemCategory',
  13081. 'asArray' => true
  13082. ) );
  13083. if (! empty ( $receiptCollectList )) {
  13084. $receiptL = array (
  13085. '日常相关费用' => array (),
  13086. '差旅相关费用' => array (),
  13087. '内部培训费用' => array (),
  13088. '培训班费用' => array (),
  13089. '其他' => array ()
  13090. );
  13091. $html = "";
  13092. $psum = 0;
  13093. foreach ( $aiList[$this->AGENCY] as $va ) {
  13094. $falg = true;
  13095. foreach ( $receiptCollectList as $v ) {
  13096. if ($v ['itemCategory'] == $this->AGENCY) {
  13097. if ($v ['item'] == $va['name']) {
  13098. $psum += $v ['price'];
  13099. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13100. $falg = false;
  13101. break;
  13102. }
  13103. }
  13104. }
  13105. if ($falg)
  13106. $html .= '<td class="taR">-</td>';
  13107. }
  13108. if (! empty ( $psum ))
  13109. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13110. else
  13111. $psum = '<td class="colGreen taR">-</td>';
  13112. $receiptL [$this->AGENCY] = $psum . $html;
  13113. /* ----------------------------------- */
  13114. $html = "";
  13115. $psum = 0;
  13116. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13117. $falg = true;
  13118. foreach ( $receiptCollectList as $v ) {
  13119. if ($v ['itemCategory'] == $this->TRAVEL) {
  13120. if ($v ['item'] == $va['name']) {
  13121. $psum += $v ['price'];
  13122. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13123. $falg = false;
  13124. break;
  13125. }
  13126. }
  13127. }
  13128. if ($falg)
  13129. $html .= '<td class="taR">-</td>';
  13130. }
  13131. if (! empty ( $psum ))
  13132. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13133. else
  13134. $psum = '<td class="colGreen taR">-</td>';
  13135. $receiptL [$this->TRAVEL] = $psum . $html;
  13136. /* ------------------------------------- */
  13137. $html = "";
  13138. $psum = 0;
  13139. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13140. $falg = true;
  13141. foreach ( $receiptCollectList as $v ) {
  13142. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13143. if ($v ['item'] == $va['name']) {
  13144. $psum += $v ['price'];
  13145. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13146. $falg = false;
  13147. break;
  13148. }
  13149. }
  13150. }
  13151. if ($falg)
  13152. $html .= '<td class="taR">-</td>';
  13153. }
  13154. if (! empty ( $psum ))
  13155. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13156. else
  13157. $psum = '<td class="colGreen taR">-</td>';
  13158. $receiptL [$this->INTTRAIN] = $psum . $html;
  13159. /* ------------------------------------- */
  13160. $html = "";
  13161. $psum = 0;
  13162. foreach ( $aiList[$this->TRAIN] as $va ) {
  13163. $falg = true;
  13164. foreach ( $receiptCollectList as $v ) {
  13165. if ($v ['itemCategory'] == $this->TRAIN) {
  13166. if ($v ['item'] == $va['name']) {
  13167. $psum += $v ['price'];
  13168. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13169. $falg = false;
  13170. break;
  13171. }
  13172. }
  13173. }
  13174. if ($falg)
  13175. $html .= '<td class="taR">-</td>';
  13176. }
  13177. if (! empty ( $psum ))
  13178. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13179. else
  13180. $psum = '<td class="colGreen taR">-</td>';
  13181. $receiptL [$this->TRAIN] = $psum . $html;
  13182. /* ------------------------------------- */
  13183. $html = "";
  13184. $psum = 0;
  13185. foreach ( $aiList[$this->OTHER] as $va ) {
  13186. $falg = true;
  13187. foreach ( $receiptCollectList as $v ) {
  13188. if ($v ['itemCategory'] == $this->OTHER) {
  13189. if ($v ['item'] == $va['name']) {
  13190. $psum += $v ['price'];
  13191. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13192. $falg = false;
  13193. break;
  13194. }
  13195. }
  13196. }
  13197. if ($falg)
  13198. $html .= '<td class="taR">-</td>';
  13199. }
  13200. if (! empty ( $psum ))
  13201. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13202. else
  13203. $psum = '<td class="colGreen taR">-</td>';
  13204. $receiptL [$this->OTHER] = $psum . $html;
  13205. /* ------------------------------------- */
  13206. $html = "";
  13207. $psum = 0;
  13208. foreach ( $receiptCollectList as $v ) {
  13209. if ($v ['itemCategory'] == '报销金额调整') {
  13210. if (! empty ( $v ['price'] ))
  13211. $psum += $v ['price'];
  13212. }
  13213. }
  13214. if (! empty ( $psum ))
  13215. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13216. else
  13217. $psum = '<td class="taR colOrange">-</td>';
  13218. $receiptL ['报销金额调整'] = $psum . $html;
  13219. } else {
  13220. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13221. foreach ( $aiList[$this->AGENCY] as $va ) {
  13222. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13223. }
  13224. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13225. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13226. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13227. }
  13228. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13229. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13230. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13231. }
  13232. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13233. foreach ( $aiList[$this->TRAIN] as $va ) {
  13234. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13235. }
  13236. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13237. foreach ( $aiList[$this->OTHER] as $va ) {
  13238. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13239. }
  13240. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13241. }
  13242. $monthStaffPrice = $receiptDetail->find ( array (
  13243. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13244. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13245. 'asArray' => true
  13246. ) );
  13247. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13248. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13249. else
  13250. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13251. $list [$value ['title']] = $receiptL;
  13252. }
  13253. $data ['list'] = $list;
  13254. $receiptCollectList = $receiptDetail->find ( array (
  13255. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13256. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13257. 'groupby' => 'item,Month(pastDate),itemCategory',
  13258. 'asArray' => true
  13259. ) );
  13260. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13261. //print_r($data['monthPriceHtml']);
  13262. // foreach ($data['monthPriceHtml'] as $value){
  13263. // echo $value;
  13264. // }
  13265. // die;
  13266. // statistics html
  13267. $stList = $statistics->getOne ( array (
  13268. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13269. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13270. 'groupby' => 'Month(date)',
  13271. 'asArray' => true
  13272. ) );
  13273. if (empty ( $stList ))
  13274. $stList = array (
  13275. 'rePrice' => 0,
  13276. 'agPrice' => 0
  13277. );
  13278. $data ['stList'] = array (
  13279. 'rePrice' => $stList ['rePrice'],
  13280. 'agPrice' => $stList ['agPrice'],
  13281. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13282. );
  13283. $monthHtml = "";
  13284. for($i = 1; $i <= 12; $i ++) {
  13285. if ($i == $month)
  13286. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13287. else
  13288. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13289. }
  13290. $data ['aiList'] = $aiList;
  13291. $data ['monthHtml'] = $monthHtml;
  13292. $data ['year'] = $year;
  13293. $data ['month'] = $month;
  13294. $data ['memu'] = "receipt";
  13295. $data ['staff'] = $this->staff;
  13296. $data ['receiptMemu'] = 'companyCategoryCollect';
  13297. $data ['verifyId'] = $this->verifyId;
  13298. $data ['executeId'] = $this->executeId;
  13299. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13300. }
  13301. function staffCollectDetail() {
  13302. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13303. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13304. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13305. if (! $staffname) {
  13306. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13307. $staffname = urldecode ( $staffname );
  13308. }
  13309. Doo::loadModel ( 'staff' );
  13310. $staff = new staff ();
  13311. Doo::loadModel ( "receiptDetail" );
  13312. $receiptDetail = new receiptDetail ();
  13313. Doo::loadModel ( 'accountItem' );
  13314. $accountItem = new accountItem ();
  13315. Doo::loadModel ( 'statistics' );
  13316. $statistics = new statistics ();
  13317. Doo::loadModel ( 'L_category' );
  13318. $lCategory = new L_category ();
  13319. Doo::loadModel ( "receiptAuthorityManage" );
  13320. $receiptAuthorityManage = new receiptAuthorityManage ();
  13321. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13322. $cidList = array ();
  13323. foreach ( $imcStaff as $key => $value ) {
  13324. array_push ( $cidList, $value ['cid'] );
  13325. }
  13326. $cidString = implode ( ',', $cidList );
  13327. $staffList = $staff->find ( array (
  13328. 'where' => ' cid in (' . $cidString . ')',
  13329. 'asArray' => true
  13330. ) );
  13331. $stHtml = '';
  13332. $stTitle = "";
  13333. $staffId = 0;
  13334. $cid = 0;
  13335. $ocid = 0;
  13336. foreach ( $staffList as $value ) {
  13337. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13338. $stTitle = $value ['category'] . '-' . $value ['username'];
  13339. $staffId = $value ['sid'];
  13340. $cid = $value ['cid'];
  13341. $ocid = $value ['cid'];
  13342. if (! empty ( $value ['othercid'] ))
  13343. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13344. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13345. } elseif ($value ['username'] != 'admin')
  13346. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13347. }
  13348. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13349. 'where' => 'cid in(' . $cid . ')',
  13350. 'asArray' => true
  13351. ) );
  13352. if (empty ( $pcid ))
  13353. $pcid = $ocid;
  13354. $data ['ocid'] = $pcid;
  13355. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13356. $this->showCache ( $path );
  13357. //
  13358. $receiptCollectList = $receiptDetail->find ( array (
  13359. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13360. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13361. 'groupby' => 'item,Month(pastDate),itemCategory',
  13362. 'asArray' => true
  13363. ) );
  13364. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13365. // print_r($receiptCollectList);
  13366. $accountList = $accountItem->find ( array (
  13367. 'asArray' => true
  13368. ) );
  13369. // create CollectDetail HTML
  13370. $collectHtml = array ();
  13371. foreach ( $accountList as $key => $value ) {
  13372. $html = "";
  13373. $asum = 0;
  13374. for($i = 1; $i <= 12; $i ++) {
  13375. $falg = true;
  13376. foreach ( $receiptCollectList as $v ) {
  13377. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13378. if ($v ['item'] == '可自加费用') {
  13379. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13380. }
  13381. $asum += $v ['price'];
  13382. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13383. $falg = false;
  13384. break;
  13385. }
  13386. }
  13387. if ($falg)
  13388. $html .= '<td class="taR">-</td>';
  13389. }
  13390. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13391. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13392. }
  13393. $data ['collectHtml'] = $collectHtml;
  13394. // print_r($collectHtml);
  13395. // create Adjustment price html
  13396. $receiptCollectList = $receiptDetail->find ( array (
  13397. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13398. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13399. 'groupby' => 'itemCategory,Month(pastDate)',
  13400. 'asArray' => true
  13401. ) );
  13402. $adjustment = array ();
  13403. $collectArray = array (
  13404. '日常相关费用' => array (),
  13405. '差旅相关费用' => array (),
  13406. '培训班费用' => array (),
  13407. '内部培训费用'=>array(),
  13408. '其他' => array ()
  13409. );
  13410. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13411. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13412. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13413. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13414. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13415. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13416. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13417. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13418. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13419. array_push ( $collectArray ['其他'], $collectHtml );
  13420. $data ['collectArray'] = $collectArray;
  13421. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13422. array_push ( $adjustment, $collectHtml );
  13423. $data ['adjustment'] = $adjustment;
  13424. // total price html
  13425. $collectHtml = "";
  13426. $total = 0;
  13427. for($i = 1; $i <= 12; $i ++) {
  13428. $sumPrice = 0;
  13429. foreach ( $receiptCollectList as $key => $value ) {
  13430. if ($value ['month'] == $i) {
  13431. $sumPrice += $value ['price'];
  13432. }
  13433. }
  13434. if ($sumPrice == 0)
  13435. $collectHtml .= '<td class="taR">-</td>';
  13436. else
  13437. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13438. $total += $sumPrice;
  13439. }
  13440. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13441. // statistics html
  13442. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13443. if (empty ( $stList ))
  13444. $stList = array (
  13445. 'rePrice' => 0,
  13446. 'agPrice' => 0
  13447. );
  13448. $data ['stList'] = array (
  13449. 'rePrice' => $stList ['rePrice'],
  13450. 'agPrice' => $stList ['agPrice'],
  13451. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13452. );
  13453. $data ['totalPrice'] = $collectHtml;
  13454. $data ['totalYear'] = $total;
  13455. $data ['stHtml'] = $stHtml;
  13456. $data ['year'] = $year;
  13457. $data ['stTitle'] = $stTitle;
  13458. $data ['staffname'] = urlencode ( $staffname );
  13459. $data ['memu'] = "receipt";
  13460. $data ['staff'] = $this->staff;
  13461. $data ['receiptMemu'] = 'companyCategoryCollect';
  13462. $data ['verifyId'] = $this->verifyId;
  13463. $data ['executeId'] = $this->executeId;
  13464. if ($year < date ( "Y" )) {
  13465. Doo::loadModel ( 'receipt' );
  13466. $receipt = new receipt ();
  13467. $receiptList = $receipt->find ( array (
  13468. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13469. 'asArray' => true
  13470. ) );
  13471. if (empty ( $receiptList )) { // generated files
  13472. ob_start ();
  13473. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13474. $this->cacheFile ( $path );
  13475. die ();
  13476. }
  13477. }
  13478. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13479. }
  13480. function BUGFLAG() {
  13481. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13482. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13483. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13484. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13485. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13486. if (empty ( $status ))
  13487. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13488. $page_size = 12;
  13489. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13490. $vidList = array ();
  13491. $button = 0;
  13492. Doo::loadModel ( 'verify' );
  13493. $verify = new verify ();
  13494. Doo::loadModel ( 'receipt' );
  13495. $receipt = new receipt ();
  13496. Doo::loadModel ( 'staff' );
  13497. $staff = new staff ();
  13498. Doo::loadModel ( 'L_category' );
  13499. $Lcategory = new L_category ();
  13500. $dateCondition = " and Year(date) =" . $year;
  13501. if (! empty ( $month ))
  13502. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13503. $categoryList = $Lcategory->find ( array (
  13504. 'asArray' => true
  13505. ) );
  13506. $staffList = $staff->find ( array (
  13507. 'where' => 'cid=' . $cid,
  13508. 'asArray' => true
  13509. ) );
  13510. $cateCondition = "";
  13511. $staffCondition = "";
  13512. $approvalCondition = "";
  13513. if (! empty ( $cid ))
  13514. $cateCondition = ' and cid=' . $cid;
  13515. if (! empty ( $sid )) {
  13516. $staffCondition = ' and staff=' . $sid;
  13517. $cateCondition = "";
  13518. }
  13519. $approvalCondition = " and status=" . $status;
  13520. if ($status == 2) {
  13521. // 查找角色审批人
  13522. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13523. }
  13524. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13525. $approvalCondition = ' and status=2 ';
  13526. }
  13527. if ($status == 1) {
  13528. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13529. }
  13530. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13531. $pageinfo ['page'] = array (
  13532. 'previous' => ''
  13533. );
  13534. if ($status == 0) {
  13535. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13536. $receiptList = $receipt->find ( array (
  13537. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13538. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13539. 'desc' => 'rid',
  13540. 'asArray' => true
  13541. ) );
  13542. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13543. } else
  13544. $receiptList = $receipt->find ( array (
  13545. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13546. 'desc' => 'rid',
  13547. 'asArray' => true
  13548. ) );
  13549. $rLRes = $receipt->find ( array (
  13550. '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,
  13551. 'desc' => 'rid',
  13552. 'asArray' => true
  13553. ) );
  13554. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13555. // print_r($pageinfo);
  13556. $Locate = 0;
  13557. foreach ( $receiptList as $key => $value ) {
  13558. $receiptList [$key] ['Locate'] = $Locate;
  13559. $Locate ++;
  13560. $receiptList [$key] ['reviseDetail'] = array ();
  13561. if (! empty ( $value ['reviseDetail'] ))
  13562. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13563. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13564. $categoryDetil = $Lcategory->getOne ( array (
  13565. 'where' => 'cid=' . $value ['cid'],
  13566. 'asArray' => true
  13567. ) );
  13568. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13569. $verifyList = $verify->getOne ( array (
  13570. 'where' => 'vid=' . $value ['verify'],
  13571. 'asArray' => true
  13572. ) );
  13573. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13574. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13575. foreach ( $verifyList as $k => $v ) {
  13576. // init verifyStaff
  13577. $verifyList [$k] ['date'] = "";
  13578. $verifyList [$k] ['opinion'] = "";
  13579. $verifyList [$k] ['status'] = "";
  13580. if (empty ( $verifyStaff )) {
  13581. $verifyList [$k] ['date'] = "";
  13582. $verifyList [$k] ['opinion'] = "";
  13583. if ($v [0] == $this->staff [0] ['sid']) {
  13584. $verifyList [$k] ['status'] = 4;
  13585. $button = 4;
  13586. }
  13587. } else {
  13588. $flag = true;
  13589. foreach ( $verifyStaff as $m => $u ) {
  13590. if ($v [0] == $m) {
  13591. $verifyList [$k] ['date'] = $u ['date'];
  13592. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13593. $verifyList [$k] ['status'] = $u ['status'];
  13594. $flag = false;
  13595. break;
  13596. }
  13597. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13598. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13599. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13600. }
  13601. if ($flag) { // 检测可编辑
  13602. if ($v [0] == $this->staff [0] ['sid']) {
  13603. $verifyList [$k] ['status'] = 4;
  13604. $button = 4;
  13605. }
  13606. }
  13607. }
  13608. }
  13609. $receiptList [$key] ['verifyList'] = $verifyList;
  13610. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13611. 'where' => 'sid=' . $value ['staff'],
  13612. 'asArray' => true
  13613. ) );
  13614. $receiptList [$key] ['button'] = $button;
  13615. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13616. }
  13617. // print_r($receiptList);die;
  13618. // $data['verifyDetail']=$verifyDetail;
  13619. $mothHtml = "";
  13620. for($i = 1; $i <= 12; $i ++) {
  13621. if ($month == $i)
  13622. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13623. else
  13624. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13625. }
  13626. $data ['mothHtml'] = $mothHtml;
  13627. $data ['page'] = $pageinfo;
  13628. $data ['receiptList'] = $receiptList;
  13629. $data ['receiptApprovalCount'] = count ( $rLRes );
  13630. $data ['status'] = $status;
  13631. $data ['year'] = $year;
  13632. $data ['categoryList'] = $categoryList;
  13633. $data ['staffList'] = $staffList;
  13634. $data ['cid'] = $cid;
  13635. $data ['sid'] = $sid;
  13636. // print_r($receiptList);
  13637. $data ['memu'] = "receipt";
  13638. $data ['staff'] = $this->staff;
  13639. $data ['receiptMemu'] = 'approvalExpenses';
  13640. $data ['verifyId'] = $this->verifyId;
  13641. $data ['executeId'] = $this->executeId;
  13642. $this->render ( "/admin/FALG", $data );
  13643. }
  13644. function ajaxGetReceiptOrder() {
  13645. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13646. if (! empty ( $receiptOrder )) {
  13647. Doo::loadModel ( 'receipt' );
  13648. $receipt = new receipt ();
  13649. Doo::loadModel ( 'staff' );
  13650. $staff = new staff ();
  13651. $receiptInfo = $receipt->getOne ( array (
  13652. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13653. 'asArray' => true
  13654. ) );
  13655. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13656. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13657. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13658. </tbody></table><table class="table table table-bordered"><tbody>';
  13659. foreach ( $verifyStaff as $key => $value ) {
  13660. $staffInfo = $staff->getOne ( array (
  13661. 'select' => 'username',
  13662. 'where' => ' sid="' . $key . '"',
  13663. 'asArray' => true
  13664. ) );
  13665. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13666. }
  13667. $html .= '</tbody></table></div></div>';
  13668. echo json_encode ( array (
  13669. 'status' => 1,
  13670. 'receiptHtml' => $html
  13671. ) );
  13672. die ();
  13673. }
  13674. echo json_encode ( array (
  13675. 'status' => 2,
  13676. 'receiptHtml' => ''
  13677. ) );
  13678. die ();
  13679. }
  13680. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13681. if (! empty ( $receiptCollectList )) {
  13682. $receiptL = array (
  13683. '日常相关费用' => array (),
  13684. '差旅相关费用' => array (),
  13685. '内部培训费用'=>array(),
  13686. '培训班费用' => array (),
  13687. '其他' => array ()
  13688. );
  13689. $html = "";
  13690. $psum = 0;
  13691. foreach ( $aiList[$this->AGENCY] as $value ) {
  13692. $falg = true;
  13693. foreach ( $receiptCollectList as $v ) {
  13694. if ($v ['itemCategory'] == '日常相关费用') {
  13695. if ($v ['item'] == $value['name']) {
  13696. $psum += $v ['price'];
  13697. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13698. $falg = false;
  13699. break;
  13700. }
  13701. }
  13702. }
  13703. if ($falg)
  13704. $html .= '<td class="taR">-</td>';
  13705. }
  13706. if (! empty ( $psum ))
  13707. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13708. else
  13709. $psum = '<td class="colGreen taR">-</td>';
  13710. $receiptL ['日常相关费用'] = $psum . $html;
  13711. /* ----------------------------------- */
  13712. $html = "";
  13713. $psum = 0;
  13714. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13715. $falg = true;
  13716. foreach ( $receiptCollectList as $v ) {
  13717. if ($v ['itemCategory'] == '差旅相关费用') {
  13718. if ($v ['item'] == $value['name']) {
  13719. $psum += $v ['price'];
  13720. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13721. $falg = false;
  13722. break;
  13723. }
  13724. }
  13725. }
  13726. if ($falg)
  13727. $html .= '<td class="taR">-</td>';
  13728. }
  13729. if (! empty ( $psum ))
  13730. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13731. else
  13732. $psum = '<td class="colGreen taR">-</td>';
  13733. $receiptL ['差旅相关费用'] = $psum . $html;
  13734. /* ----------------------------------- */
  13735. $html = "";
  13736. $psum = 0;
  13737. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13738. $falg = true;
  13739. foreach ( $receiptCollectList as $v ) {
  13740. if ($v ['itemCategory'] == '内部培训费用') {
  13741. if ($v ['item'] == $value['name']) {
  13742. $psum += $v ['price'];
  13743. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13744. $falg = false;
  13745. break;
  13746. }
  13747. }
  13748. }
  13749. if ($falg)
  13750. $html .= '<td class="taR">-</td>';
  13751. }
  13752. if (! empty ( $psum ))
  13753. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13754. else
  13755. $psum = '<td class="colGreen taR">-</td>';
  13756. $receiptL ['内部培训费用'] = $psum . $html;
  13757. /* ------------------------------------- */
  13758. $html = "";
  13759. $psum = 0;
  13760. foreach ( $aiList[$this->TRAIN] as $value ) {
  13761. $falg = true;
  13762. foreach ( $receiptCollectList as $v ) {
  13763. if ($v ['itemCategory'] == '培训班费用') {
  13764. if ($v ['item'] == $value['name']) {
  13765. $psum += $v ['price'];
  13766. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13767. $falg = false;
  13768. break;
  13769. }
  13770. }
  13771. }
  13772. if ($falg)
  13773. $html .= '<td class="taR">-</td>';
  13774. }
  13775. if (! empty ( $psum ))
  13776. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13777. else
  13778. $psum = '<td class="colGreen taR">-</td>';
  13779. $receiptL ['培训班费用'] = $psum . $html;
  13780. /* ------------------------------------- */
  13781. $html = "";
  13782. $psum = 0;
  13783. foreach ( $aiList[$this->OTHER] as $value ) {
  13784. $falg = true;
  13785. foreach ( $receiptCollectList as $v ) {
  13786. if ($v ['itemCategory'] == '其他') {
  13787. if ($v ['item'] == $value['name']) {
  13788. $psum += $v ['price'];
  13789. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13790. $falg = false;
  13791. break;
  13792. }
  13793. }
  13794. }
  13795. if ($falg)
  13796. $html .= '<td class="taR">-</td>';
  13797. }
  13798. if (! empty ( $psum ))
  13799. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13800. else
  13801. $psum = '<td class="colGreen taR">-</td>';
  13802. $receiptL ['其他'] = $psum . $html;
  13803. /* ------------------------------------- */
  13804. $html = "";
  13805. $psum = 0;
  13806. foreach ( $receiptCollectList as $v ) {
  13807. if ($v ['itemCategory'] == '报销金额调整') {
  13808. if (! empty ( $v ['price'] ))
  13809. $psum += $v ['price'];
  13810. }
  13811. }
  13812. if (! empty ( $psum ))
  13813. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13814. else
  13815. $psum = '<td class="taR colOrange">-</td>';
  13816. $receiptL ['报销金额调整'] = $psum . $html;
  13817. } else {
  13818. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13819. foreach ( $aiList[$this->AGENCY] as $va ) {
  13820. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13821. }
  13822. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13823. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13824. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13825. }
  13826. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13827. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13828. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13829. }
  13830. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13831. foreach ( $aiList[$this->TRAIN] as $va ) {
  13832. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13833. }
  13834. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13835. foreach ( $aiList[$this->OTHER] as $va ) {
  13836. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13837. }
  13838. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13839. }
  13840. return $receiptL;
  13841. }
  13842. function eMail() {
  13843. Doo::loadModel ( 'staff' );
  13844. $staff = new staff ();
  13845. Doo::loadModel ( 'receipt' );
  13846. $receipt = new receipt ();
  13847. Doo::loadModel ( 'L_category' );
  13848. $Lcategory = new L_category ();
  13849. Doo::loadModel ( "verify" );
  13850. $verify = new verify ();
  13851. $staffList = $staff->find ( array (
  13852. 'asArray' => true
  13853. ) );
  13854. foreach ( $staffList as $key => $value ) {
  13855. if ($value ['username'] != 'admin') {
  13856. // 提交人
  13857. $receiptList = $receipt->find ( array (
  13858. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13859. 'asArray' => true
  13860. ) );
  13861. if (! empty ( $receiptList )) {
  13862. $html = '<br><div><style></style>
  13863. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13864. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13865. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13866. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13867. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13868. <tbody><tr>
  13869. <td style="padding: 0 40px;" align="left">
  13870. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13871. </td></tr><tr>
  13872. <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>
  13873. </tr>
  13874. </tbody> </table></td> </tr> <tr><td>
  13875. <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">
  13876. <tbody> <tr><td>
  13877. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13878. 以下报销单完成了审批,等着收款吧:</p>
  13879. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13880. foreach ( $receiptList as $k => $v ) {
  13881. $category = $Lcategory->getOne ( array (
  13882. 'where' => 'cid=' . $v ['cid'],
  13883. 'asArray' => true
  13884. ) );
  13885. $html .= '
  13886. <tr>
  13887. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13888. <td align="left">
  13889. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13890. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13891. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13892. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13893. </tr>';
  13894. }
  13895. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13896. <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>
  13897. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13898. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13899. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13900. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13901. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13902. $receipt = new receipt ();
  13903. $receipt->notice = 1;
  13904. $receipt->update ( array (
  13905. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13906. ) );
  13907. }
  13908. }
  13909. // 审批人
  13910. $verifyList = $verify->find ( array (
  13911. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13912. 'asArray' => true
  13913. ) );
  13914. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  13915. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  13916. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13917. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  13918. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13919. <tbody><tr><td style="padding: 0 40px;" align="left">
  13920. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13921. </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>
  13922. </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">
  13923. <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>
  13924. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  13925. foreach ( $verifyList as $k => $v ) {
  13926. $receiptList = $receipt->find ( array (
  13927. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  13928. 'asArray' => true
  13929. ) );
  13930. foreach ( $receiptList as $r => $l ) {
  13931. $category = $Lcategory->getOne ( array (
  13932. 'where' => 'cid=' . $l ['cid'],
  13933. 'asArray' => true
  13934. ) );
  13935. $staffDetile = $staff->getOne ( array (
  13936. 'where' => 'sid=' . $l ['staff'],
  13937. 'asArray' => true
  13938. ) );
  13939. $html .= '
  13940. <tr>
  13941. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13942. <td align="left">
  13943. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  13944. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  13945. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  13946. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  13947. </tr>';
  13948. }
  13949. }
  13950. $html .= '
  13951. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  13952. <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>
  13953. </tr></tbody></table></td></tr></tbody></table></div><br>';
  13954. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  13955. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  13956. // $receipt=new receipt();
  13957. // $receipt->notice=1;
  13958. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  13959. }
  13960. }
  13961. }
  13962. }
  13963. function setWXMsg($rid, $type) {
  13964. Doo::loadModel ( "receipt" );
  13965. $receipt = new receipt ();
  13966. $receiptDetail = $receipt->getOne ( array (
  13967. 'where' => 'rid=' . $rid,
  13968. 'asArray' => true
  13969. ) );
  13970. if (! empty ( $receiptDetail )) {
  13971. Doo::loadModel ( 'staff' );
  13972. $staff = new staff ();
  13973. $staffmsg = $staff->getOne ( array (
  13974. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  13975. 'asArray' => TRUE
  13976. ) );
  13977. if (! empty ( $staffmsg ['wxid'] )) {
  13978. require_once (SITE_PATH . '/protected/class/client.php');
  13979. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  13980. $user = $staffmsg ['wxid'];
  13981. $receiptName = '';
  13982. $msg = '';
  13983. switch ($receiptDetail ['Rtype']) {
  13984. case 0 :
  13985. $receiptName = '报销';
  13986. break;
  13987. case 1 :
  13988. $receiptName = '借款';
  13989. break;
  13990. case 2 :
  13991. $receiptName = '对公汇款';
  13992. break;
  13993. }
  13994. switch ($type) {
  13995. case 1 :
  13996. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  13997. break;
  13998. case 2 :
  13999. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14000. break;
  14001. case 3 :
  14002. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14003. break;
  14004. }
  14005. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14006. }
  14007. }
  14008. }
  14009. // Email发送函数
  14010. function SMail($toemail, $subject, $contents) {
  14011. Doo::loadClass ( 'class.phpmailer' );
  14012. $mail = new PHPMailer ();
  14013. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14014. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14015. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14016. $mail->Password = "cDO1GjtY1seH"; // 密码
  14017. $mail->CharSet = "UTF8";
  14018. $mail->SMTPAuth = true;
  14019. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14020. $mail->Mailer = "smtp";
  14021. $mail->Port = 25;
  14022. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14023. $mail->MsgHTML ( $contents );
  14024. $mail->AddAddress ( $toemail );
  14025. $mail->CharSet = "UTF-8";
  14026. return $mail->Send ();
  14027. }
  14028. function h5Upload() {
  14029. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14030. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14031. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14032. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14033. header ( "HTTP/1.1 500 Internal Server Error" );
  14034. echo "POST exceeded maximum allowed size.";
  14035. exit ( 0 );
  14036. }
  14037. // Settings
  14038. $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)
  14039. $upload_name = "Filedata";
  14040. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14041. $extension_whitelist = array (
  14042. "doc",
  14043. "txt",
  14044. "jpg",
  14045. "gif",
  14046. "png"
  14047. ); // Allowed file extensions
  14048. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14049. // Other variables
  14050. $MAX_FILENAME_LENGTH = 260;
  14051. $file_name = "";
  14052. $file_extension = "";
  14053. $uploadErrors = array (
  14054. 0 => "文件上传成功",
  14055. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14056. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14057. 3 => "上传的文件仅为部分文件",
  14058. 4 => "没有文件上传",
  14059. 6 => "缺少临时文件夹"
  14060. );
  14061. $nk = time ();
  14062. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14063. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14064. echo "文件无法保存.";
  14065. exit ( 0 );
  14066. }
  14067. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14068. echo json_encode ( array (
  14069. 'filename' => $file_name,
  14070. 'id' => $nk
  14071. ) );
  14072. exit ( 0 );
  14073. }
  14074. function swfupload() {
  14075. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14076. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14077. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14078. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14079. header ( "HTTP/1.1 500 Internal Server Error" );
  14080. echo "POST exceeded maximum allowed size.";
  14081. exit ( 0 );
  14082. }
  14083. // Settings
  14084. $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)
  14085. $upload_name = "Filedata";
  14086. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14087. $extension_whitelist = array (
  14088. "doc",
  14089. "txt",
  14090. "jpg",
  14091. "gif",
  14092. "png"
  14093. ); // Allowed file extensions
  14094. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14095. // Other variables
  14096. $MAX_FILENAME_LENGTH = 260;
  14097. $file_name = "";
  14098. $file_extension = "";
  14099. $uploadErrors = array (
  14100. 0 => "文件上传成功",
  14101. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14102. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14103. 3 => "上传的文件仅为部分文件",
  14104. 4 => "没有文件上传",
  14105. 6 => "缺少临时文件夹"
  14106. );
  14107. $nk = time ();
  14108. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14109. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14110. echo "文件无法保存.";
  14111. exit ( 0 );
  14112. }
  14113. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14114. echo json_encode ( array (
  14115. 'filename' => $file_name,
  14116. 'id' => $nk
  14117. ) );
  14118. exit ( 0 );
  14119. }
  14120. function _GetFileEXT($filename) {
  14121. $pics = explode ( '.', $filename );
  14122. $num = count ( $pics );
  14123. return $pics [$num - 1];
  14124. }
  14125. /**
  14126. * 获取get或者POST值
  14127. * @param string $name 属性名称
  14128. * @return fixed 值
  14129. */
  14130. function get_args($name) {
  14131. if (isset ( $_GET [$name] )) {
  14132. if (is_array ( $_GET [$name] ))
  14133. return $_GET [$name];
  14134. else
  14135. return addslashes ( $_GET [$name] );
  14136. } elseif (isset ( $_POST [$name] )) {
  14137. if (is_array ( $_POST [$name] ))
  14138. return $_POST [$name];
  14139. else
  14140. return addslashes ( $_POST [$name] );
  14141. } else
  14142. return false;
  14143. }
  14144. function num_to_rmb($num) {
  14145. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14146. $c2 = "分角元拾佰仟万拾佰仟亿";
  14147. // 精确到分后面就不要了,所以只留两个小数位
  14148. $num = round ( $num, 2 );
  14149. // 将数字转化为整数
  14150. $num = $num * 100;
  14151. if (strlen ( $num ) > 10) {
  14152. return "金额太大,请检查";
  14153. }
  14154. $i = 0;
  14155. $c = "";
  14156. while ( 1 ) {
  14157. if ($i == 0) {
  14158. // 获取最后一位数字
  14159. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14160. } else {
  14161. $n = $num % 10;
  14162. }
  14163. // 每次将最后一位数字转化为中文
  14164. $p1 = substr ( $c1, 3 * $n, 3 );
  14165. $p2 = substr ( $c2, 3 * $i, 3 );
  14166. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14167. $c = $p1 . $p2 . $c;
  14168. } else {
  14169. $c = $p1 . $c;
  14170. }
  14171. $i = $i + 1;
  14172. // 去掉数字最后一位了
  14173. $num = $num / 10;
  14174. // echo $num.'</br>';
  14175. $num = ( int ) $num;
  14176. // $num =floor($num);
  14177. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14178. // echo $num.'</br>';
  14179. // 结束循环
  14180. if ($num == 0) {
  14181. break;
  14182. }
  14183. }
  14184. // echo $c.'</br>';
  14185. $j = 0;
  14186. $slen = strlen ( $c );
  14187. while ( $j < $slen ) {
  14188. // utf8一个汉字相当3个字符
  14189. $m = substr ( $c, $j, 6 );
  14190. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14191. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14192. $left = substr ( $c, 0, $j );
  14193. $right = substr ( $c, $j + 3 );
  14194. $c = $left . $right;
  14195. $j = $j - 3;
  14196. $slen = $slen - 3;
  14197. }
  14198. $j = $j + 3;
  14199. }
  14200. // 这个是为了去掉类似23.0中最后一个“零”字
  14201. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14202. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14203. }
  14204. // 将处理的汉字加上“整”
  14205. if (empty ( $c )) {
  14206. return "零元整";
  14207. } else {
  14208. return $c . "整";
  14209. }
  14210. }
  14211. /**
  14212. * 获得分页数据
  14213. * @param unknown_type $table
  14214. * @param unknown_type $condition
  14215. * @param unknown_type $on_page
  14216. * @param unknown_type $page_size
  14217. */
  14218. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14219. $page_c = "";
  14220. $page ['previous'] = $this->get_previous ( $on_page );
  14221. $page ['on_page'] = $on_page;
  14222. $total_count = $this->get_table_count ( $table, $condition );
  14223. $total = intval ( $total_count / $page_size );
  14224. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14225. $page ['total_data'] = $total_count;
  14226. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14227. $i = 1;
  14228. $page_max = 1;
  14229. $page_width = 3;
  14230. if ($on_page >= $page_width) {
  14231. $page_max = intval ( $on_page / $page_width ) + 1;
  14232. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14233. }
  14234. for(; $i <= $page ['total_page']; $i ++) {
  14235. if ($i == $on_page)
  14236. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14237. else
  14238. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14239. if ($i == ($page_width * $page_max))
  14240. break;
  14241. }
  14242. $page ['page'] = $page_c;
  14243. $page ['lower'] = (-- $on_page) * $page_size;
  14244. return $page;
  14245. }
  14246. /**
  14247. * 获取总页数
  14248. * @param unknown_type $table
  14249. * @param unknown_type $condition
  14250. */
  14251. public function get_table_count($table = "", $condition = "") {
  14252. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14253. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14254. // echo $sql;die;
  14255. $query = Doo::db ()->query ( $sql );
  14256. $result = $query->fetch ();
  14257. return $result ['count'];
  14258. }
  14259. /**
  14260. * 获取上一页
  14261. * @param unknown_type $on_page
  14262. */
  14263. function get_previous($on_page = 1) {
  14264. return $on_page != 0 ? $on_page - 1 : $on_page;
  14265. }
  14266. }
  14267. ?>