ReceiptController.php 535 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307
  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 "社保") and category like "'.$this->AGENCY.'"',
  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. print_r($aItem);
  278. foreach ( $aItem as $key => $value ) {
  279. if ($value ['category'] == $this->AGENCY) {
  280. if (isset ( $agency [$ag] )) {
  281. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  282. array_push ( $accountJson [$this->AGENCY], array (
  283. 'aid' => $value ['aid'],
  284. 'name' => $value ['name'],
  285. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  286. ) );
  287. $sum += $agency [$ag];
  288. $agencySum += $agency [$ag];
  289. }
  290. }
  291. $ag ++;
  292. }
  293. }
  294. $accountJson ['cSum'] = array (
  295. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  296. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  297. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  298. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  299. );
  300. //die;
  301. // 报销单
  302. $receipt->accountItem = json_encode ( $accountJson );
  303. $receipt->staff = $this->staff [0] ['sid'];
  304. $receipt->sum = number_format ( $sum, 2, '.', '' );
  305. $receipt->date = date ( "Y-m-d" );
  306. $receipt->cid = $cid;
  307. $receipt->status = 5;
  308. $receipt->Rtype = 2;
  309. // 修改审批流程加入角色
  310. $receipt->verify = $verify;
  311. $receipt->executeCopy = $executeDetail ['staff'];
  312. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  313. $order = array (
  314. "\r\n",
  315. "\n",
  316. "\r"
  317. );
  318. $replace = '<br/>';
  319. $explanation = str_replace ( $order, $replace, $explanation );
  320. $receipt->explanation = $explanation;
  321. $receipt->remittanceName = $remittanceName;
  322. $receipt->bankName = $bankName;
  323. $receipt->bankNumber = $bankNumber;
  324. $receipt->remittanceBankType = $remittanceBankType;
  325. if ($remittanceBankType == 1)
  326. $receipt->coupletNumber = $coupletNumber;
  327. $rid = $receipt->insert ();
  328. // 附件
  329. if (! empty ( $enclosurName )) {
  330. $enclosurArray = explode ( '-', $enclosurName );
  331. foreach ( $enclosurArray as $value ) {
  332. $enclosur = new enclosur ();
  333. $enclosur->name = $value;
  334. $enclosur->rid = $rid;
  335. $enclosur->insert ();
  336. }
  337. // print_r($enclosurArray);die;
  338. }
  339. // 报销详情
  340. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  341. $receiptDetail = new receiptDetail ();
  342. $receiptDetail->staff = $this->staff [0] ['sid'];
  343. $receiptDetail->item = $value ['name'];
  344. $receiptDetail->itemCategory = $this->AGENCY;
  345. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  346. $receiptDetail->date = date ( "Y-m-d" );
  347. $receiptDetail->cid = $cid;
  348. $receiptDetail->rid = $rid;
  349. $receiptDetail->status = 4;
  350. $receiptDetail->insert ();
  351. }
  352. return "/saeaBorad";
  353. } else
  354. die ( 'illegal request' );
  355. }
  356. function remitEdit() {
  357. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  358. Doo::loadClass ( 'XDeode' );
  359. $XDeode = new XDeode ( 7 );
  360. $rid = $XDeode->decode ( $ridKey );
  361. if (! is_numeric ( $rid ))
  362. die ( 'illegal request' );
  363. Doo::loadModel ( 'accountItem' );
  364. Doo::loadModel ( 'verify' );
  365. Doo::loadModel ( 'receipt' );
  366. $receipt = new receipt ();
  367. $verify = new verify ();
  368. $accountItem = new accountItem ();
  369. Doo::loadModel ( 'L_category' );
  370. $lCategory = new L_category ();
  371. Doo::loadModel ( "role" );
  372. $role = new role ();
  373. Doo::loadModel ( 'enclosur' );
  374. $enclosur = new enclosur ();
  375. $receiptDetail = $receipt->getOne ( array (
  376. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  377. 'asArray' => true
  378. ) );
  379. if (empty ( $receiptDetail ))
  380. return "/saeaCreate";
  381. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  382. $acItem = $accountItem->find ( array (
  383. 'asArray' => true
  384. ) );
  385. $veList = $verify->getVerifyBySubordinate('REMIT');
  386. // 配置编辑信息
  387. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  388. foreach ( $acItem as $key => $value ) {
  389. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  390. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  391. $acItem [$key] ['price'] = $v ['price'];
  392. }
  393. }
  394. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  395. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  396. $acItem [$key] ['price'] = $v ['price'];
  397. }
  398. }
  399. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  400. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  401. $acItem [$key] ['price'] = $v ['price'];
  402. }
  403. }
  404. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  405. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  406. $acItem [$key] ['price'] = $v ['price'];
  407. }
  408. }
  409. }
  410. $data ['category'] = $lCategory->find ( array (
  411. 'asArray' => true
  412. ) );
  413. $data ['enclosurList'] = $enclosurList;
  414. $data ['cSum'] = $accountItemList ['cSum'];
  415. $data ['sum'] = $receiptDetail ['sum'];
  416. $data ['receiptDetail'] = $receiptDetail;
  417. $data ['veList'] = $veList;
  418. $data ['acItem'] = $acItem;
  419. $data ['memu'] = "receipt";
  420. $data ['staff'] = $this->staff;
  421. $data ['receiptMemu'] = 'saeaBorad';
  422. $data ['verify'] = $receiptDetail ['verify'];
  423. $data ['verifyId'] = $this->verifyId;
  424. $data ['executeId'] = $this->executeId;
  425. $data ['rid'] = $rid;
  426. $data ['ridKey'] = $ridKey;
  427. $this->render ( "/admin/remitEdit", $data );
  428. }
  429. function remitEdiDo() {
  430. $agency = $this->get_args ( 'agency' );
  431. $travel = $this->get_args ( 'travel' );
  432. $train = $this->get_args ( 'train' );
  433. $other = $this->get_args ( 'other' );
  434. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  435. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  436. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  437. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  438. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  439. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  440. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  441. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  442. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  443. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  444. Doo::loadClass ( 'XDeode' );
  445. $XDeode = new XDeode ( 7 );
  446. $rid = $XDeode->decode ( $ridKey );
  447. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  448. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  449. header ( 'Content-Type:text/html;charset=utf-8' );
  450. die ( '请填写联行号' );
  451. }
  452. Doo::loadModel ( 'receipt' );
  453. Doo::loadModel ( 'receiptDetail' );
  454. Doo::loadModel ( 'accountItem' );
  455. $accountItem = new accountItem ();
  456. $receipt = new receipt ();
  457. Doo::loadModel ( 'enclosur' );
  458. $enclosur = new enclosur ();
  459. Doo::loadModel ( 'execute' );
  460. $execute = new execute ();
  461. $executeDetail = $execute->getOne ( array (
  462. 'where' => 'mold="对公汇款执行人"',
  463. 'asArray' => true
  464. ) );
  465. $receiptDetail = $receipt->getOne ( array (
  466. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  467. 'asArray' => true
  468. ) );
  469. if (empty ( $receiptDetail ))
  470. return "/saeaBorad";
  471. $aItem = $accountItem->find ( array (
  472. 'where' => '(name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  473. 'asArray' => true
  474. ) );
  475. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  476. $ag = $tr = $ta = $ot = 0;
  477. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  478. foreach ( $aItem as $key => $value ) {
  479. if ($value ['category'] == $this->AGENCY) {
  480. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  481. array_push ( $accountJson [$this->AGENCY], array (
  482. 'aid' => $value ['aid'],
  483. 'name' => $value ['name'],
  484. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  485. ) );
  486. $sum += $agency [$ag];
  487. $agencySum += $agency [$ag];
  488. }
  489. $ag ++;
  490. }
  491. }
  492. $accountJson ['cSum'] = array (
  493. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  494. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  495. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  496. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  497. );
  498. // 报销单
  499. $rid = $receipt->rid = $receiptDetail ['rid'];
  500. $receipt->accountItem = json_encode ( $accountJson );
  501. $receipt->staff = $this->staff [0] ['sid'];
  502. $receipt->sum = number_format ( $sum, 2, '.', '' );
  503. $receipt->date = date ( "Y-m-d" );
  504. $receipt->cid = $cid;
  505. if ($receiptDetail ['Rtype'] == 1)
  506. $receipt->status = 7;
  507. else
  508. $receipt->status = 5;
  509. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  510. $receipt->verify = $verify;
  511. $receipt->executeCopy = $executeDetail ['staff'];
  512. $order = array (
  513. "\r\n",
  514. "\n",
  515. "\r"
  516. );
  517. $replace = '<br/>';
  518. $explanation = str_replace ( $order, $replace, $explanation );
  519. $receipt->explanation = $explanation;
  520. $receipt->remittanceName = $remittanceName;
  521. $receipt->bankName = $bankName;
  522. $receipt->bankNumber = $bankNumber;
  523. $receipt->remittanceBankType = $remittanceBankType;
  524. if ($remittanceBankType == 1)
  525. $receipt->coupletNumber = $coupletNumber;
  526. $receipt->update ();
  527. $receiptDetail = new receiptDetail ();
  528. $receiptDetail->delete ( array (
  529. 'where' => 'rid=' . $rid
  530. ) );
  531. // 报销详情
  532. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  533. $receiptDetail = new receiptDetail ();
  534. $receiptDetail->staff = $this->staff [0] ['sid'];
  535. $receiptDetail->item = $value ['name'];
  536. $receiptDetail->itemCategory = $this->AGENCY;
  537. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  538. $receiptDetail->date = date ( "Y-m-d" );
  539. $receiptDetail->cid = $cid;
  540. $receiptDetail->rid = $rid;
  541. $receiptDetail->status = 4;
  542. $receiptDetail->insert ();
  543. }
  544. // 附件
  545. if (! empty ( $enclosurName )) {
  546. $enclosurArray = explode ( '-', $enclosurName );
  547. foreach ( $enclosurArray as $value ) {
  548. $enclosur = new enclosur ();
  549. $enclosur->name = $value;
  550. $enclosur->rid = $rid;
  551. $enclosur->insert ();
  552. }
  553. }
  554. }
  555. return "/saeaBorad";
  556. }
  557. function remitApproval() {
  558. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  559. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  561. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  562. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  563. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  564. if (empty ( $status ))
  565. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  566. $vidList = array ();
  567. $button = 0;
  568. Doo::loadModel ( 'verify' );
  569. Doo::loadModel ( 'receipt' );
  570. Doo::loadModel ( 'staff' );
  571. $staff = new staff ();
  572. $receipt = new receipt ();
  573. $verify = new verify ();
  574. Doo::loadModel ( 'L_category' );
  575. $Lcategory = new L_category ();
  576. Doo::loadModel ( 'enclosur' );
  577. $enclosur = new enclosur ();
  578. // user verify ID
  579. $verifyDetail = $verify->find ( array (
  580. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  581. 'asArray' => true
  582. ) );
  583. foreach ( $verifyDetail as $key => $value ) {
  584. array_push ( $vidList, $value ['vid'] );
  585. }
  586. $vid = implode ( ",", $vidList );
  587. if (empty ( $verifyDetail ))
  588. $vid = 0;
  589. $categoryList = $Lcategory->find ( array (
  590. 'asArray' => true
  591. ) );
  592. $staffList = $staff->find ( array (
  593. 'where' => 'cid=' . $cid,
  594. 'asArray' => true
  595. ) );
  596. $ap = "";
  597. if ($status == 4) {
  598. $ap = 4;
  599. $status = 2;
  600. }
  601. // get Receipt By verifyID status 2
  602. $receiptList = $receipt->find ( array (
  603. 'where' => 'rid =' . $rid . ' and status=2',
  604. 'desc' => 'rid',
  605. 'asArray' => true
  606. ) );
  607. if (empty ( $receiptList )) {
  608. die ( 'illegal request' );
  609. }
  610. $Locate = 0;
  611. $roleId = 0;
  612. if ($ap == 4)
  613. $status = 4;
  614. foreach ( $receiptList as $key => $value ) {
  615. $receiptList [$key] ['Locate'] = $Locate;
  616. $Locate ++;
  617. $receiptList [$key] ['reviseDetail'] = array ();
  618. if (! empty ( $value ['reviseDetail'] ))
  619. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  620. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  621. $categoryDetil = $Lcategory->getOne ( array (
  622. 'where' => 'cid=' . $value ['cid'],
  623. 'asArray' => true
  624. ) );
  625. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  626. // 检测编辑状态
  627. $verifyList = $verify->getOne ( array (
  628. 'where' => 'vid=' . $value ['verify'],
  629. 'asArray' => true
  630. ) );
  631. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  632. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  633. Doo::loadModel ( 'role' );
  634. $role = new role ();
  635. // print_r($verifyList);
  636. $flag = true;
  637. $roleKey = 0;
  638. $endStaffArray = array ();
  639. $roleArrayCopy = array ();
  640. foreach ( $verifyList as $k => $v ) {
  641. // init verifyStaff
  642. if ($v [1] == 'ROLE') {
  643. if (! empty ( $verifyStaff )) {
  644. $endStaffArray = end ( $verifyStaff );
  645. if ($v [0] == $endStaffArray ['nextStaff']) {
  646. $roleId = $v [0];
  647. }
  648. }
  649. $roleVerify = json_decode ( $v [3], true );
  650. $roleKey = $k;
  651. $roleArray = array ();
  652. $rolename = $role->getOne ( array (
  653. 'where' => 'rid=' . $v [0],
  654. 'asArray' => true
  655. ) );
  656. foreach ( $roleVerify as $o => $p ) {
  657. $staffID = explode ( '_', $p );
  658. $staffInfo = $staff->getOne ( array (
  659. 'where' => 'sid=' . $staffID [0],
  660. 'asArray' => true
  661. ) );
  662. // print_r($staffID);
  663. $exp = array (
  664. 0 => $staffInfo ['sid'],
  665. 1 => $staffID [1],
  666. 2 => $staffInfo ['avatar'],
  667. 'date' => '',
  668. 'date' => '',
  669. 'opinion' => '',
  670. 'status' => '',
  671. 'rolename' => $rolename ['name']
  672. );
  673. array_push ( $roleArray, $exp );
  674. }
  675. $roleArrayCopy [$v [0]] = $roleArray;
  676. // $verifyList[$k]['roleArray']=$roleArray;
  677. }
  678. // print_r($roleArray);
  679. $verifyList [$k] ['date'] = "";
  680. $verifyList [$k] ['opinion'] = "";
  681. $verifyList [$k] ['status'] = "";
  682. if (empty ( $verifyStaff )) {
  683. $verifyList [$k] ['date'] = "";
  684. $verifyList [$k] ['opinion'] = "";
  685. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  686. $verifyList [$k] ['status'] = 4;
  687. $button = 4;
  688. $flag = false;
  689. }
  690. } else {
  691. foreach ( $verifyStaff as $m => $u ) {
  692. if ($v [0] == $m) {
  693. $verifyList [$k] ['date'] = $u ['date'];
  694. $verifyList [$k] ['opinion'] = $u ['opinion'];
  695. $verifyList [$k] ['status'] = $u ['status'];
  696. $flag = false;
  697. break;
  698. }
  699. }
  700. $endStaffArray = end ( $verifyStaff );
  701. if (isset ( $endStaffArray ['ROLE'] )) {
  702. } else {
  703. $endKey = key ( $verifyStaff );
  704. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  705. $button = 4;
  706. $verifyList [$k] ['status'] = 4;
  707. }
  708. }
  709. }
  710. }
  711. $rolename ['name'] = '';
  712. if (! empty ( $roleId )) {
  713. Doo::loadModel ( 'role' );
  714. $role = new role ();
  715. $rolename = $role->getOne ( array (
  716. 'where' => 'rid=' . $roleId,
  717. 'asArray' => true
  718. ) );
  719. }
  720. if (! empty ( $verifyStaff ))
  721. $endStaffArray = end ( $verifyStaff );
  722. $KOP = false;
  723. foreach ( $roleArrayCopy as $P => $A ) {
  724. foreach ( $A as $MKI => $AVL ) {
  725. if (! empty ( $verifyStaff )) {
  726. // &&$rolename['rid']==$endStaffArray['nextStaff']
  727. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  728. $button = 4;
  729. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  730. }
  731. foreach ( $verifyStaff as $m => $u ) {
  732. $AVLFK = $AVL [0] . '_R';
  733. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  734. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  735. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  736. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  737. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  738. break;
  739. }
  740. }
  741. } else {
  742. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  743. $button = 4;
  744. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  745. }
  746. }
  747. // $roleArray[$MKI]['rolename']=$rolename['name'];
  748. $KOP = true;
  749. }
  750. }
  751. foreach ( $roleArrayCopy as $k => $v ) {
  752. foreach ( $verifyList as $m => $n ) {
  753. if ($n [0] == $k) {
  754. array_splice ( $verifyList, $m, 1, $v );
  755. }
  756. }
  757. }
  758. $receiptList [$key] ['verifyList'] = $verifyList;
  759. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  760. 'where' => 'sid=' . $value ['staff'],
  761. 'asArray' => true
  762. ) );
  763. $receiptList [$key] ['button'] = $button;
  764. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  765. }
  766. $mothHtml = "";
  767. for($i = 1; $i <= 12; $i ++) {
  768. if ($month == $i)
  769. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  770. else
  771. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  772. }
  773. // 获取审批日志
  774. Doo::loadModel ( 'receiptLog' );
  775. $receiptLog = new receiptLog ();
  776. $rlList = array ();
  777. $rlInfo = $receiptLog->getOne ( array (
  778. 'where' => 'rid=' . $rid . ' and status=4',
  779. 'asArray' => true
  780. ) );
  781. $tijdate = $receiptLog->getOne ( array (
  782. 'where' => 'rid=' . $rid . ' and status=2',
  783. 'asc' => 'rlid',
  784. 'asArray' => true
  785. ) );
  786. if (! empty ( $rlInfo )) {
  787. $rlList = $receiptLog->find ( array (
  788. 'where' => 'rid=' . $rid,
  789. 'asc' => 'rlid',
  790. 'asArray' => true
  791. ) );
  792. }
  793. $receiptList [0] ['rlList'] = $rlList;
  794. $enclosurList = $enclosur->find ( array (
  795. 'where' => 'rid=' . $rid,
  796. 'asArray' => true
  797. ) );
  798. $enclosurHtml = '';
  799. foreach ( $enclosurList as $value ) {
  800. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  801. }
  802. // print_r($receiptList);
  803. $data ['enclosurHtml'] = $enclosurHtml;
  804. $data ['rolename'] = $rolename ['name'];
  805. $data ['datetij'] = $tijdate ['date'];
  806. $data ['mothHtml'] = $mothHtml;
  807. $data ['rid'] = $rid;
  808. $data ['receiptList'] = $receiptList;
  809. $data ['receiptApprovalCount'] = count ( $receiptList );
  810. $data ['status'] = $status;
  811. $data ['year'] = $year;
  812. $data ['categoryList'] = $categoryList;
  813. $data ['staffList'] = $staffList;
  814. $data ['cid'] = $cid;
  815. $data ['sid'] = $sid;
  816. $data ['ap'] = $ap;
  817. $data ['memu'] = "receipt";
  818. $data ['staff'] = $this->staff;
  819. $data ['receiptMemu'] = 'approvalExpenses';
  820. $data ['verifyId'] = $this->verifyId;
  821. $data ['executeId'] = $this->executeId;
  822. $this->render ( "/admin/remitApproval", $data );
  823. }
  824. function saeaLoanAdd() {
  825. Doo::loadModel ( 'verify' );
  826. $verify = new verify ();
  827. Doo::loadModel ( "role" );
  828. $role = new role ();
  829. Doo::loadModel ( 'L_category' );
  830. $lCategory = new L_category ();
  831. $veList = $verify->getVerifyBySubordinate('LOAN');
  832. $data ['category'] = $lCategory->find ( array (
  833. 'asArray' => true
  834. ) );
  835. $data ['veList'] = $veList;
  836. $data ['memu'] = "receipt";
  837. $data ['staff'] = $this->staff;
  838. $data ['receiptMemu'] = 'saeaBorad';
  839. $data ['verifyId'] = $this->verifyId;
  840. $data ['executeId'] = $this->executeId;
  841. $this->render ( "/admin/saeaLoanAdd", $data );
  842. }
  843. function saeaLoanAddDo() {
  844. $agency = $this->get_args ( 'agency' );
  845. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  846. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  847. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  848. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  849. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  850. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  851. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  852. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  853. // die;
  854. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  855. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  856. header ( 'Content-Type:text/html;charset=utf-8' );
  857. die ( '请填写联行号' );
  858. }
  859. Doo::loadModel ( 'receipt' );
  860. Doo::loadModel ( 'receiptDetail' );
  861. Doo::loadModel ( 'accountItem' );
  862. $accountItem = new accountItem ();
  863. $receipt = new receipt ();
  864. Doo::loadModel ( 'loanReceipt' );
  865. $loanReceipt = new loanReceipt ();
  866. Doo::loadModel ( 'execute' );
  867. $execute = new execute ();
  868. Doo::loadModel ( 'enclosur' );
  869. $executeDetail = $execute->getOne ( array (
  870. 'where' => 'mold="借款执行人"',
  871. 'asArray' => true
  872. ) );
  873. $aItem = $accountItem->find ( array (
  874. 'asArray' => true
  875. ) );
  876. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  877. $ag = $tr = $ta = $ot = 0;
  878. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  879. array_push ( $accountJson ['借款费用'], array (
  880. 'aid' => 0,
  881. 'name' => '申请金额',
  882. 'price' => number_format ( $agency, 2, '.', '' )
  883. ) );
  884. $sum += $agency;
  885. $agencySum += $agency;
  886. $accountJson ['cSum'] = array (
  887. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  888. 'agencySum' => number_format ( 0, 2, '.', '' ),
  889. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  890. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  891. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  892. );
  893. // 借款数据备份
  894. $loanReceipt->loanItem = json_encode ( $accountJson );
  895. $loanReceipt->staff = $this->staff [0] ['sid'];
  896. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  897. $loanReceipt->date = date ( "Y-m-d" );
  898. $loanReceipt->cid = $cid;
  899. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  900. $loanReceipt->status = 5;
  901. $loanReceipt->Rtype = 1;
  902. $loanReceipt->verify = $verify;
  903. $receipt->receiptOrder = $receipt->receiptOrder;
  904. // 添加HTML换行符
  905. // var_dump($explanation);
  906. $order = array (
  907. "\r\n",
  908. "\n",
  909. "\r"
  910. );
  911. $replace = '<br/>';
  912. $explanation = str_replace ( $order, $replace, $explanation );
  913. // $explanation=str_replace('\r',"<br/>",$explanation);
  914. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  915. $loanReceipt->explanation = $explanation;
  916. $loanRid = $loanReceipt->insert ();
  917. // 报销单
  918. $receipt->loanItem = json_encode ( $accountJson );
  919. $receipt->staff = $this->staff [0] ['sid'];
  920. $receipt->sum = number_format ( $sum, 2, '.', '' );
  921. $receipt->date = date ( "Y-m-d" );
  922. $receipt->cid = $cid;
  923. // 特殊状态
  924. $receipt->status = 5;
  925. $receipt->Rtype = 1;
  926. $receipt->loanRid = $loanRid;
  927. // 修改审批流程加入角色
  928. $receipt->verify = $verify;
  929. $receipt->executeCopy = $executeDetail ['staff'];
  930. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  931. $receipt->explanation = $explanation;
  932. $receipt->remittanceName = $remittanceName;
  933. $receipt->bankName = $bankName;
  934. $receipt->bankNumber = $bankNumber;
  935. $receipt->remittanceBankType = $remittanceBankType;
  936. if ($remittanceBankType == 1)
  937. $receipt->coupletNumber = $coupletNumber;
  938. $rid = $receipt->insert ();
  939. return "/saeaBorad";
  940. } else
  941. die ( 'illegal request' );
  942. }
  943. function saeaLoanEdi() {
  944. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  945. Doo::loadClass ( 'XDeode' );
  946. $XDeode = new XDeode ( 7 );
  947. $rid = $XDeode->decode ( $ridKey );
  948. if (! is_numeric ( $rid ))
  949. die ( 'illegal request' );
  950. Doo::loadModel ( 'verify' );
  951. $verify = new verify ();
  952. Doo::loadModel ( "role" );
  953. $role = new role ();
  954. Doo::loadModel ( 'L_category' );
  955. $lCategory = new L_category ();
  956. Doo::loadModel ( 'receipt' );
  957. $receipt = new receipt ();
  958. $receiptInfo = $receipt->getOne ( array (
  959. 'where' => 'rid=' . $rid,
  960. 'asArray' => true
  961. ) );
  962. $veList = $verify->find ( array (
  963. 'where'=>'subordinate like "%LOAN%"',
  964. 'asArray' => true
  965. ) );
  966. foreach ( $veList as $key => $value ) {
  967. $v = json_decode ( $value ['staff'] );
  968. $list = array ();
  969. foreach ( $v as $n => $m ) {
  970. if ($m ['1'] == 'ROLE') {
  971. $roleInfo = $role->getOne ( array (
  972. 'where' => 'rid=' . $m [0],
  973. 'asArray' => true
  974. ) );
  975. $v [$n] [1] = $roleInfo ['name'];
  976. array_push ( $list, $roleInfo ['name'] );
  977. } else {
  978. array_push ( $list, $v [$n] [1] );
  979. }
  980. }
  981. $veList [$key] ['staff'] = implode ( '>', $list );
  982. }
  983. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  984. // print_r($receiptInfo);
  985. $data ['receiptInfo'] = $receiptInfo;
  986. $data ['category'] = $lCategory->find ( array (
  987. 'asArray' => true
  988. ) );
  989. $data ['veList'] = $veList;
  990. $data ['ridKey'] = $ridKey;
  991. $data ['memu'] = "receipt";
  992. $data ['staff'] = $this->staff;
  993. $data ['receiptMemu'] = 'saeaBorad';
  994. $data ['verifyId'] = $this->verifyId;
  995. $data ['executeId'] = $this->executeId;
  996. $this->render ( "/admin/saeaLoanEdi", $data );
  997. }
  998. function saeaLoanEdiDo() {
  999. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1000. $agency = $this->get_args ( 'agency' );
  1001. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1002. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1003. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1004. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1005. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1006. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1007. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1008. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1009. // die;
  1010. Doo::loadClass ( 'XDeode' );
  1011. $XDeode = new XDeode ( 7 );
  1012. $rid = $XDeode->decode ( $ridKey );
  1013. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1014. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1015. header ( 'Content-Type:text/html;charset=utf-8' );
  1016. die ( '请填写联行号' );
  1017. }
  1018. Doo::loadModel ( 'receipt' );
  1019. Doo::loadModel ( 'receiptDetail' );
  1020. Doo::loadModel ( 'accountItem' );
  1021. $accountItem = new accountItem ();
  1022. $receipt = new receipt ();
  1023. Doo::loadModel ( 'loanReceipt' );
  1024. $loanReceipt = new loanReceipt ();
  1025. Doo::loadModel ( 'enclosur' );
  1026. Doo::loadModel ( 'execute' );
  1027. $execute = new execute ();
  1028. $executeDetail = $execute->getOne ( array (
  1029. 'where' => 'mold="借款执行人"',
  1030. 'asArray' => true
  1031. ) );
  1032. $receiptDetail = $receipt->getOne ( array (
  1033. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1034. 'asArray' => true
  1035. ) );
  1036. if (empty ( $receiptDetail ))
  1037. die ( '参数错误' );
  1038. $aItem = $accountItem->find ( array (
  1039. 'asArray' => true
  1040. ) );
  1041. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1042. $ag = $tr = $ta = $ot = 0;
  1043. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1044. array_push ( $accountJson ['借款费用'], array (
  1045. 'aid' => 0,
  1046. 'name' => '申请金额',
  1047. 'price' => number_format ( $agency, 2, '.', '' )
  1048. ) );
  1049. $sum += $agency;
  1050. $agencySum += $agency;
  1051. $accountJson ['cSum'] = array (
  1052. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1053. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1054. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1055. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1056. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1057. );
  1058. // 报销单
  1059. $receipt->loanItem = json_encode ( $accountJson );
  1060. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1061. $receipt->cid = $cid;
  1062. // 特殊状态
  1063. // 修改审批流程加入角色
  1064. if ($receiptDetail ['status'] != 4)
  1065. $receipt->verify = $verify;
  1066. $order = array (
  1067. "\r\n",
  1068. "\n",
  1069. "\r"
  1070. );
  1071. $replace = '<br/>';
  1072. $explanation = str_replace ( $order, $replace, $explanation );
  1073. $receipt->explanation = $explanation;
  1074. $receipt->remittanceName = $remittanceName;
  1075. $receipt->bankName = $bankName;
  1076. $receipt->bankNumber = $bankNumber;
  1077. $receipt->remittanceBankType = $remittanceBankType;
  1078. if ($remittanceBankType == 1)
  1079. $receipt->coupletNumber = $coupletNumber;
  1080. $receipt->update ( array (
  1081. 'where' => 'rid=' . $rid
  1082. ) );
  1083. // 借款数据更新
  1084. $loanReceipt->loanItem = json_encode ( $accountJson );
  1085. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1086. $loanReceipt->cid = $cid;
  1087. if ($receiptDetail ['status'] != 4)
  1088. $loanReceipt->verify = $verify;
  1089. $loanReceipt->explanation = $explanation;
  1090. $receipt->executeCopy = $executeDetail ['staff'];
  1091. $loanReceipt->update ( array (
  1092. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1093. ) );
  1094. }
  1095. return "/saeaBorad";
  1096. }
  1097. function saeaLoanReceiptAdd() {
  1098. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. Doo::loadModel ( 'loanReceipt' );
  1102. $loanReceipt = new loanReceipt ();
  1103. Doo::loadModel ( 'L_category' );
  1104. $Lcategory = new L_category ();
  1105. Doo::loadModel ( 'verify' );
  1106. Doo::loadModel ( 'statistics' );
  1107. $statistics = new statistics ();
  1108. $verify = new verify ();
  1109. Doo::loadModel ( 'staff' );
  1110. $staff = new staff ();
  1111. $receiptDetail = $receipt->getOne ( array (
  1112. 'where' => 'rid=' . $rid,
  1113. 'desc' => 'rid',
  1114. 'asArray' => true
  1115. ) );
  1116. $receiptList = $loanReceipt->find ( array (
  1117. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1118. 'desc' => 'rid',
  1119. 'asArray' => true
  1120. ) );
  1121. $Locate = 0;
  1122. $roleId = 0;
  1123. $button = 0;
  1124. foreach ( $receiptList as $key => $value ) {
  1125. $receiptList [$key] ['Locate'] = $Locate;
  1126. $Locate ++;
  1127. $receiptList [$key] ['reviseDetail'] = array ();
  1128. if (! empty ( $value ['reviseDetail'] ))
  1129. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1130. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1131. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1132. $categoryDetil = $Lcategory->getOne ( array (
  1133. 'where' => 'cid=' . $value ['cid'],
  1134. 'asArray' => true
  1135. ) );
  1136. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1137. // 检测编辑状态
  1138. $verifyList = $verify->getOne ( array (
  1139. 'where' => 'vid=' . $value ['verify'],
  1140. 'asArray' => true
  1141. ) );
  1142. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1143. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1144. Doo::loadModel ( 'role' );
  1145. $role = new role ();
  1146. $flag = true;
  1147. $roleKey = 0;
  1148. $endStaffArray = array ();
  1149. $roleArrayCopy = array ();
  1150. foreach ( $verifyList as $k => $v ) {
  1151. // init verifyStaff
  1152. if ($v [1] == 'ROLE') {
  1153. if (! empty ( $verifyStaff )) {
  1154. $endStaffArray = end ( $verifyStaff );
  1155. // if ($v[0]==$endStaffArray['nextStaff']){
  1156. // $roleId=$v[0];
  1157. // }
  1158. }
  1159. $roleVerify = json_decode ( $v [3], true );
  1160. $roleKey = $k;
  1161. $roleArray = array ();
  1162. $rolename = $role->getOne ( array (
  1163. 'where' => 'rid=' . $v [0],
  1164. 'asArray' => true
  1165. ) );
  1166. foreach ( $roleVerify as $o => $p ) {
  1167. $staffID = explode ( '_', $p );
  1168. $staffInfo = $staff->getOne ( array (
  1169. 'where' => 'sid=' . $staffID [0],
  1170. 'asArray' => true
  1171. ) );
  1172. // print_r($staffID);
  1173. $exp = array (
  1174. 0 => $staffInfo ['sid'],
  1175. 1 => $staffID [1],
  1176. 2 => $staffInfo ['avatar'],
  1177. 'date' => '',
  1178. 'date' => '',
  1179. 'opinion' => '',
  1180. 'status' => '',
  1181. 'rolename' => $rolename ['name']
  1182. );
  1183. array_push ( $roleArray, $exp );
  1184. }
  1185. $roleArrayCopy [$v [0]] = $roleArray;
  1186. // $verifyList[$k]['roleArray']=$roleArray;
  1187. }
  1188. $verifyList [$k] ['date'] = "";
  1189. $verifyList [$k] ['opinion'] = "";
  1190. $verifyList [$k] ['status'] = "";
  1191. if (empty ( $verifyStaff )) {
  1192. $verifyList [$k] ['date'] = "";
  1193. $verifyList [$k] ['opinion'] = "";
  1194. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1195. $verifyList [$k] ['status'] = 4;
  1196. $flag = false;
  1197. }
  1198. } else {
  1199. foreach ( $verifyStaff as $m => $u ) {
  1200. if ($v [0] == $m) {
  1201. $verifyList [$k] ['date'] = $u ['date'];
  1202. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1203. $verifyList [$k] ['status'] = $u ['status'];
  1204. $flag = false;
  1205. break;
  1206. }
  1207. }
  1208. $endStaffArray = end ( $verifyStaff );
  1209. if (isset ( $endStaffArray ['ROLE'] )) {
  1210. } else {
  1211. // $endKey=key($verifyStaff);
  1212. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1213. // $button=4;
  1214. // $verifyList[$k]['status']=4;
  1215. // }
  1216. }
  1217. }
  1218. }
  1219. $rolename ['name'] = '';
  1220. if (! empty ( $roleId )) {
  1221. Doo::loadModel ( 'role' );
  1222. $role = new role ();
  1223. $rolename = $role->getOne ( array (
  1224. 'where' => 'rid=' . $roleId,
  1225. 'asArray' => true
  1226. ) );
  1227. }
  1228. if (! empty ( $verifyStaff ))
  1229. $endStaffArray = end ( $verifyStaff );
  1230. $KOP = false;
  1231. foreach ( $roleArrayCopy as $P => $A ) {
  1232. foreach ( $A as $MKI => $AVL ) {
  1233. if (! empty ( $verifyStaff )) {
  1234. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1235. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1236. $button = 4;
  1237. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1238. }
  1239. foreach ( $verifyStaff as $m => $u ) {
  1240. $AVLFK = $AVL [0] . '_R';
  1241. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1242. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1243. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1244. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1245. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1246. break;
  1247. }
  1248. }
  1249. } else {
  1250. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1251. $button = 4;
  1252. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1253. }
  1254. }
  1255. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1256. $KOP = true;
  1257. }
  1258. }
  1259. foreach ( $roleArrayCopy as $k => $v ) {
  1260. foreach ( $verifyList as $m => $n ) {
  1261. if ($n [0] == $k) {
  1262. array_splice ( $verifyList, $m, 1, $v );
  1263. }
  1264. }
  1265. }
  1266. $receiptList [$key] ['verifyList'] = $verifyList;
  1267. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1268. 'where' => 'sid=' . $value ['staff'],
  1269. 'asArray' => true
  1270. ) );
  1271. $receiptList [$key] ['button'] = $button;
  1272. //
  1273. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1274. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1275. }
  1276. $data ['receiptList'] = $receiptList;
  1277. $data ['receiptDetail'] = $receiptDetail;
  1278. Doo::loadModel ( 'L_category' );
  1279. $lCategory = new L_category ();
  1280. Doo::loadModel ( 'accountItem' );
  1281. $accountItem = new accountItem ();
  1282. $acItem = $accountItem->find ( array (
  1283. 'asArray' => true
  1284. ) );
  1285. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1286. $data ['rid'] = $rid;
  1287. $data ['category'] = $lCategory->find ( array (
  1288. 'asArray' => true
  1289. ) );
  1290. $data ['veList'] = $veList;
  1291. $data ['acItem'] = $acItem;
  1292. $data ['memu'] = "receipt";
  1293. $data ['staff'] = $this->staff;
  1294. $data ['receiptMemu'] = 'saeaBorad';
  1295. $data ['verifyId'] = $this->verifyId;
  1296. $data ['executeId'] = $this->executeId;
  1297. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1298. }
  1299. function saeaLoanReceiptAddDo() {
  1300. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1301. $agency = $this->get_args ( 'agency' );
  1302. $travel = $this->get_args ( 'travel' );
  1303. $train = $this->get_args ( 'train' );
  1304. $other = $this->get_args ( 'other' );
  1305. $inttrain = $this->get_args ( 'inttrain' );
  1306. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1307. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1308. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1309. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1310. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1311. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1312. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1313. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1314. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1315. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1316. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1317. header ( 'Content-Type:text/html;charset=utf-8' );
  1318. die ( '请填写联行号' );
  1319. }
  1320. Doo::loadModel ( 'receipt' );
  1321. Doo::loadModel ( 'receiptDetail' );
  1322. Doo::loadModel ( 'accountItem' );
  1323. $accountItem = new accountItem ();
  1324. $receipt = new receipt ();
  1325. Doo::loadModel ( 'enclosur' );
  1326. Doo::loadModel ( 'execute' );
  1327. $execute = new execute ();
  1328. $executeDetail = $execute->getOne ( array (
  1329. 'where' => 'mold="借款费用执行人"',
  1330. 'asArray' => true
  1331. ) );
  1332. $receiptDet = $receipt->getOne ( array (
  1333. 'where' => 'rid=' . $rid,
  1334. 'asArray' => true
  1335. ) );
  1336. // if(!empty($receiptDetail))
  1337. // return "/referReceipt/".$receiptDetail['rid'];
  1338. $aItem = $accountItem->find ( array (
  1339. 'asArray' => true
  1340. ) );
  1341. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1342. $ag = $tr = $ta = $ot =$it = 0;
  1343. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1344. foreach ( $aItem as $key => $value ) {
  1345. if ($value ['category'] == $this->AGENCY) {
  1346. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1347. array_push ( $accountJson [$this->AGENCY], array (
  1348. 'aid' => $value ['aid'],
  1349. 'name' => $value ['name'],
  1350. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1351. ) );
  1352. $sum += $agency [$ag];
  1353. $agencySum += $agency [$ag];
  1354. }
  1355. $ag ++;
  1356. }
  1357. if ($value ['category'] == $this->TRAVEL) {
  1358. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1359. array_push ( $accountJson [$this->TRAVEL], array (
  1360. 'aid' => $value ['aid'],
  1361. 'name' => $value ['name'],
  1362. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1363. ) );
  1364. $sum += $travel [$tr];
  1365. $travelSum += $travel [$tr];
  1366. }
  1367. $tr ++;
  1368. }
  1369. if ($value ['category'] == $this->INTTRAIN) {
  1370. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1371. array_push ( $accountJson [$this->INTTRAIN], array (
  1372. 'aid' => $value ['aid'],
  1373. 'name' => $value ['name'],
  1374. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1375. ) );
  1376. $sum += $inttrain [$it];
  1377. $inttrainSum += $inttrain [$it];
  1378. }
  1379. $it ++;
  1380. }
  1381. if ($value ['category'] == $this->TRAIN) {
  1382. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1383. array_push ( $accountJson [$this->TRAIN], array (
  1384. 'aid' => $value ['aid'],
  1385. 'name' => $value ['name'],
  1386. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1387. ) );
  1388. $sum += $train [$ta];
  1389. $trainSum += $train [$ta];
  1390. }
  1391. $ta ++;
  1392. }
  1393. if ($value ['category'] == $this->OTHER) {
  1394. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1395. array_push ( $accountJson [$this->OTHER], array (
  1396. 'aid' => $value ['aid'],
  1397. 'name' => $value ['name'],
  1398. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1399. ) );
  1400. $sum += $other [$ot];
  1401. $otherSum += $other [$ot];
  1402. }
  1403. $ot ++;
  1404. }
  1405. }
  1406. $accountJson ['cSum'] = array (
  1407. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1408. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1409. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1410. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1411. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1412. );
  1413. // 报销单
  1414. $receipt->accountItem = json_encode ( $accountJson );
  1415. $receipt->staff = $this->staff [0] ['sid'];
  1416. $receipt->loanSum = $receiptDet ['sum'];
  1417. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1418. $receipt->date = date ( "Y-m-d" );
  1419. $receipt->pastDate = '';
  1420. $receipt->cid = $cid;
  1421. $receipt->status = 7;
  1422. // 修改审批流程加入角色
  1423. $receipt->verify = $verify;
  1424. $receipt->verifyStaff = '';
  1425. $receipt->executeStaff = '';
  1426. $receipt->executeCopy = $executeDetail ['staff'];
  1427. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1428. $receipt->explanation = $explanation;
  1429. $receipt->remittanceName = $remittanceName;
  1430. $receipt->bankName = $bankName;
  1431. $receipt->bankNumber = $bankNumber;
  1432. $receipt->remittanceBankType = $remittanceBankType;
  1433. if ($remittanceBankType == 1)
  1434. $receipt->coupletNumber = $coupletNumber;
  1435. $receipt->update ( array (
  1436. 'where' => 'rid=' . $rid
  1437. ) );
  1438. // 附件
  1439. if (! empty ( $enclosurName )) {
  1440. $enclosurArray = explode ( '-', $enclosurName );
  1441. foreach ( $enclosurArray as $value ) {
  1442. $enclosur = new enclosur ();
  1443. $enclosur->name = $value;
  1444. $enclosur->rid = $rid;
  1445. $enclosur->insert ();
  1446. }
  1447. // print_r($enclosurArray);die;
  1448. }
  1449. // 报销详情
  1450. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1451. $receiptDetail = new receiptDetail ();
  1452. $receiptDetail->staff = $this->staff [0] ['sid'];
  1453. $receiptDetail->item = $value ['name'];
  1454. $receiptDetail->itemCategory = $this->AGENCY;
  1455. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1456. $receiptDetail->date = date ( "Y-m-d" );
  1457. $receiptDetail->cid = $cid;
  1458. $receiptDetail->rid = $rid;
  1459. $receiptDetail->status = 4;
  1460. $receiptDetail->insert ();
  1461. }
  1462. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1463. $receiptDetail = new receiptDetail ();
  1464. $receiptDetail->staff = $this->staff [0] ['sid'];
  1465. $receiptDetail->item = $value ['name'];
  1466. $receiptDetail->itemCategory = $this->TRAVEL;
  1467. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1468. $receiptDetail->date = date ( "Y-m-d" );
  1469. $receiptDetail->cid = $cid;
  1470. $receiptDetail->rid = $rid;
  1471. $receiptDetail->status = 4;
  1472. $receiptDetail->insert ();
  1473. }
  1474. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1475. $receiptDetail = new receiptDetail ();
  1476. $receiptDetail->staff = $this->staff [0] ['sid'];
  1477. $receiptDetail->item = $value ['name'];
  1478. $receiptDetail->itemCategory = $this->TRAIN;
  1479. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1480. $receiptDetail->date = date ( "Y-m-d" );
  1481. $receiptDetail->cid = $cid;
  1482. $receiptDetail->rid = $rid;
  1483. $receiptDetail->status = 4;
  1484. $receiptDetail->insert ();
  1485. }
  1486. //内训
  1487. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1488. $receiptDetail = new receiptDetail ();
  1489. $receiptDetail->staff = $this->staff [0] ['sid'];
  1490. $receiptDetail->item = $value ['name'];
  1491. $receiptDetail->itemCategory = $this->INTTRAIN;
  1492. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1493. $receiptDetail->date = date ( "Y-m-d" );
  1494. $receiptDetail->cid = $cid;
  1495. $receiptDetail->rid = $rid;
  1496. $receiptDetail->status = 4;
  1497. $receiptDetail->insert ();
  1498. }
  1499. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1500. $receiptDetail = new receiptDetail ();
  1501. $receiptDetail->staff = $this->staff [0] ['sid'];
  1502. $receiptDetail->item = $value ['name'];
  1503. $receiptDetail->itemCategory = $this->OTHER;
  1504. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1505. $receiptDetail->date = date ( "Y-m-d" );
  1506. $receiptDetail->cid = $cid;
  1507. $receiptDetail->rid = $rid;
  1508. $receiptDetail->status = 4;
  1509. $receiptDetail->insert ();
  1510. }
  1511. return "/saeaBorad";
  1512. }
  1513. return "/saeaLoanReceiptAdd/" . $rid;
  1514. }
  1515. function saeaLoanReceiptEdi() {
  1516. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1517. Doo::loadClass ( 'XDeode' );
  1518. $XDeode = new XDeode ( 7 );
  1519. $rid = $XDeode->decode ( $ridKey );
  1520. if (! is_numeric ( $rid ))
  1521. die ( 'illegal request' );
  1522. Doo::loadModel ( 'accountItem' );
  1523. Doo::loadModel ( 'verify' );
  1524. Doo::loadModel ( 'receipt' );
  1525. $receipt = new receipt ();
  1526. $verify = new verify ();
  1527. $accountItem = new accountItem ();
  1528. Doo::loadModel ( 'L_category' );
  1529. $Lcategory = new L_category ();
  1530. Doo::loadModel ( "role" );
  1531. $role = new role ();
  1532. Doo::loadModel ( 'loanReceipt' );
  1533. $loanReceipt = new loanReceipt ();
  1534. Doo::loadModel ( 'staff' );
  1535. $staff = new staff ();
  1536. $receiptDetail = $receipt->getOne ( array (
  1537. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1538. 'asArray' => true
  1539. ) );
  1540. if (empty ( $receiptDetail ))
  1541. return "/saeaBorad";
  1542. $receiptList = $loanReceipt->find ( array (
  1543. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1544. 'desc' => 'rid',
  1545. 'asArray' => true
  1546. ) );
  1547. $Locate = 0;
  1548. $roleId = 0;
  1549. $button = 0;
  1550. foreach ( $receiptList as $key => $value ) {
  1551. $receiptList [$key] ['Locate'] = $Locate;
  1552. $Locate ++;
  1553. $receiptList [$key] ['reviseDetail'] = array ();
  1554. if (! empty ( $value ['reviseDetail'] ))
  1555. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1556. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1557. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1558. $categoryDetil = $Lcategory->getOne ( array (
  1559. 'where' => 'cid=' . $value ['cid'],
  1560. 'asArray' => true
  1561. ) );
  1562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1563. // 检测编辑状态
  1564. $verifyList = $verify->getOne ( array (
  1565. 'where' => 'vid=' . $value ['verify'],
  1566. 'asArray' => true
  1567. ) );
  1568. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1569. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1570. Doo::loadModel ( 'role' );
  1571. $role = new role ();
  1572. $flag = true;
  1573. $roleKey = 0;
  1574. $endStaffArray = array ();
  1575. $roleArrayCopy = array ();
  1576. foreach ( $verifyList as $k => $v ) {
  1577. // init verifyStaff
  1578. if ($v [1] == 'ROLE') {
  1579. if (! empty ( $verifyStaff )) {
  1580. $endStaffArray = end ( $verifyStaff );
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify = json_decode ( $v [3], true );
  1586. $roleKey = $k;
  1587. $roleArray = array ();
  1588. $rolename = $role->getOne ( array (
  1589. 'where' => 'rid=' . $v [0],
  1590. 'asArray' => true
  1591. ) );
  1592. foreach ( $roleVerify as $o => $p ) {
  1593. $staffID = explode ( '_', $p );
  1594. $staffInfo = $staff->getOne ( array (
  1595. 'where' => 'sid=' . $staffID [0],
  1596. 'asArray' => true
  1597. ) );
  1598. // print_r($staffID);
  1599. $exp = array (
  1600. 0 => $staffInfo ['sid'],
  1601. 1 => $staffID [1],
  1602. 2 => $staffInfo ['avatar'],
  1603. 'date' => '',
  1604. 'date' => '',
  1605. 'opinion' => '',
  1606. 'status' => '',
  1607. 'rolename' => $rolename ['name']
  1608. );
  1609. array_push ( $roleArray, $exp );
  1610. }
  1611. $roleArrayCopy [$v [0]] = $roleArray;
  1612. // $verifyList[$k]['roleArray']=$roleArray;
  1613. }
  1614. $verifyList [$k] ['date'] = "";
  1615. $verifyList [$k] ['opinion'] = "";
  1616. $verifyList [$k] ['status'] = "";
  1617. if (empty ( $verifyStaff )) {
  1618. $verifyList [$k] ['date'] = "";
  1619. $verifyList [$k] ['opinion'] = "";
  1620. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1621. $verifyList [$k] ['status'] = 4;
  1622. $flag = false;
  1623. }
  1624. } else {
  1625. foreach ( $verifyStaff as $m => $u ) {
  1626. if ($v [0] == $m) {
  1627. $verifyList [$k] ['date'] = $u ['date'];
  1628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1629. $verifyList [$k] ['status'] = $u ['status'];
  1630. $flag = false;
  1631. break;
  1632. }
  1633. }
  1634. $endStaffArray = end ( $verifyStaff );
  1635. if (isset ( $endStaffArray ['ROLE'] )) {
  1636. } else {
  1637. // $endKey=key($verifyStaff);
  1638. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1639. // $button=4;
  1640. // $verifyList[$k]['status']=4;
  1641. // }
  1642. }
  1643. }
  1644. }
  1645. $rolename ['name'] = '';
  1646. if (! empty ( $roleId )) {
  1647. Doo::loadModel ( 'role' );
  1648. $role = new role ();
  1649. $rolename = $role->getOne ( array (
  1650. 'where' => 'rid=' . $roleId,
  1651. 'asArray' => true
  1652. ) );
  1653. }
  1654. if (! empty ( $verifyStaff ))
  1655. $endStaffArray = end ( $verifyStaff );
  1656. $KOP = false;
  1657. foreach ( $roleArrayCopy as $P => $A ) {
  1658. foreach ( $A as $MKI => $AVL ) {
  1659. if (! empty ( $verifyStaff )) {
  1660. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. foreach ( $verifyStaff as $m => $u ) {
  1666. $AVLFK = $AVL [0] . '_R';
  1667. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1668. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1669. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1670. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1671. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1672. break;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1677. $button = 4;
  1678. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1679. }
  1680. }
  1681. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1682. $KOP = true;
  1683. }
  1684. }
  1685. foreach ( $roleArrayCopy as $k => $v ) {
  1686. foreach ( $verifyList as $m => $n ) {
  1687. if ($n [0] == $k) {
  1688. array_splice ( $verifyList, $m, 1, $v );
  1689. }
  1690. }
  1691. }
  1692. $receiptList [$key] ['verifyList'] = $verifyList;
  1693. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1694. 'where' => 'sid=' . $value ['staff'],
  1695. 'asArray' => true
  1696. ) );
  1697. $receiptList [$key] ['button'] = $button;
  1698. //
  1699. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1700. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1701. }
  1702. $data ['receiptList'] = $receiptList;
  1703. $acItem = $accountItem->find ( array (
  1704. 'asArray' => true
  1705. ) );
  1706. $veList = $verify->find ( array (
  1707. 'asArray' => true
  1708. ) );
  1709. foreach ( $veList as $key => $value ) {
  1710. $v = json_decode ( $value ['staff'] );
  1711. $list = array ();
  1712. foreach ( $v as $n => $m ) {
  1713. if ($m ['1'] == 'ROLE') {
  1714. $roleInfo = $role->getOne ( array (
  1715. 'where' => 'rid=' . $m [0],
  1716. 'asArray' => true
  1717. ) );
  1718. $v [$n] [1] = $roleInfo ['name'];
  1719. array_push ( $list, $roleInfo ['name'] );
  1720. } else {
  1721. array_push ( $list, $v [$n] [1] );
  1722. }
  1723. }
  1724. $veList [$key] ['staff'] = implode ( '>', $list );
  1725. }
  1726. // 配置编辑信息
  1727. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1728. foreach ( $acItem as $key => $value ) {
  1729. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1730. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1731. $acItem [$key] ['price'] = $v ['price'];
  1732. }
  1733. }
  1734. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1735. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1736. $acItem [$key] ['price'] = $v ['price'];
  1737. }
  1738. }
  1739. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1740. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1741. $acItem [$key] ['price'] = $v ['price'];
  1742. }
  1743. }
  1744. //内训
  1745. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1746. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1747. $acItem [$key] ['price'] = $v ['price'];
  1748. }
  1749. }
  1750. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1751. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1752. $acItem [$key] ['price'] = $v ['price'];
  1753. }
  1754. }
  1755. }
  1756. $data ['category'] = $Lcategory->find ( array (
  1757. 'asArray' => true
  1758. ) );
  1759. $data ['ridKey'] = $ridKey;
  1760. $data ['cSum'] = $accountItemList ['cSum'];
  1761. $data ['sum'] = $receiptDetail ['sum'];
  1762. $data ['receiptDetail'] = $receiptDetail;
  1763. $data ['veList'] = $veList;
  1764. $data ['acItem'] = $acItem;
  1765. $data ['memu'] = "receipt";
  1766. $data ['staff'] = $this->staff;
  1767. $data ['receiptMemu'] = 'saeaBorad';
  1768. $data ['verify'] = $receiptDetail ['verify'];
  1769. $data ['verifyId'] = $this->verifyId;
  1770. $data ['executeId'] = $this->executeId;
  1771. $data ['rid'] = $rid;
  1772. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1773. }
  1774. /**
  1775. * 培训班结算
  1776. */
  1777. function receiptTrainAdd() {
  1778. Doo::loadModel ( 'accountItem' );
  1779. $accountItem = new accountItem ();
  1780. $acItem = $accountItem->find ( array (
  1781. 'asArray' => true
  1782. ) );
  1783. // 审批组
  1784. Doo::loadModel ( 'verify' );
  1785. $verify = new verify ();
  1786. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1787. // 办事处
  1788. Doo::loadModel ( 'L_category' );
  1789. $lCategory = new L_category ();
  1790. $data ['category'] = $lCategory->getCategory ();
  1791. $data ['veList'] = $veList;
  1792. $data ['memu'] = "receipt";
  1793. $data ['staff'] = $this->staff;
  1794. $data ['acItem'] = $acItem;
  1795. $data ['receiptMemu'] = 'saeaBorad';
  1796. $data ['verifyId'] = $this->verifyId;
  1797. $data ['executeId'] = $this->executeId;
  1798. $this->render ( "/receipt/receiptTrainAdd", $data );
  1799. }
  1800. /**
  1801. * 添加培训班结算
  1802. */
  1803. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1804. // 培训班信息
  1805. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1806. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1807. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1808. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1809. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1810. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1811. // 发票信息
  1812. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1813. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1814. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1815. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1816. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1817. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1818. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1819. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1820. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1821. header ( 'Content-Type:text/html;charset=utf-8' );
  1822. die ( '请填写联行号' );
  1823. }
  1824. Doo::loadModel ( 'execute' );
  1825. $execute = new execute ();
  1826. $executeDetail = $execute->getOne ( array (
  1827. 'where' => 'mold="培训班结算"',
  1828. 'asArray' => true
  1829. ) );
  1830. if (empty ( $executeDetail )) {
  1831. header ( 'Content-Type:text/html;charset=utf-8' );
  1832. die ( '未设置执行人' );
  1833. }
  1834. Doo::loadClass ( 'XDeode' );
  1835. $XDeode = new XDeode ( 5 );
  1836. $cid = $XDeode->decode ( $cid );
  1837. Doo::loadModel ( 'receipt' );
  1838. $receipt = new receipt ();
  1839. Doo::loadModel ( 'receiptTraining' );
  1840. $receiptTraining = new receiptTraining ();
  1841. // 创建费用培训班
  1842. $item = array (
  1843. 'cid' => $this->staff [0] ['cid'],
  1844. 'categoryName' => $this->staff [0] ['category'],
  1845. 'trainName' => $trainName,
  1846. 'trainStartDate' => $trainStartDate,
  1847. 'trainEndDate' => $trainEndDate,
  1848. 'participants' => $participants,
  1849. 'trainAddress' => $trainAddress,
  1850. 'trainRemarks' => $trainRemarks,
  1851. 'creator' => $this->staff [0] ['sid'],
  1852. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1853. );
  1854. $irid = $receiptTraining->addReceiptTraining ( $item );
  1855. // 报销单
  1856. $receipt->status = 5;
  1857. $receipt->trainId = $irid;
  1858. $receipt->Rtype = 3;
  1859. $receipt->staff = $this->staff [0] ['sid'];
  1860. $receipt->cid = $cid;
  1861. $receipt->verify = $verify;
  1862. $receipt->date = date ( "Y-m-d" );
  1863. $receipt->executeCopy = $executeDetail ['staff'];
  1864. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1865. $receipt->remittanceName = $remittanceName;
  1866. $receipt->bankName = $bankName;
  1867. $receipt->bankNumber = $bankNumber;
  1868. $receipt->remittanceBankType = $remittanceBankType;
  1869. if ($remittanceBankType == 1)
  1870. $receipt->coupletNumber = $coupletNumber;
  1871. $rid = $receipt->insert ();
  1872. $XDeode = new XDeode ( 7 );
  1873. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1874. } else
  1875. die ( 'illegal request' );
  1876. }
  1877. /**
  1878. * 培训班编辑
  1879. */
  1880. function receiptTrainEdi() {
  1881. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1882. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1883. Doo::loadClass ( 'XDeode' );
  1884. $XDeode = new XDeode ( 7 );
  1885. $rid = $XDeode->decode ( $ridKey );
  1886. if (! is_numeric ( $rid ))
  1887. die ( 'illegal request' );
  1888. Doo::loadModel ( 'receipt' );
  1889. $receipt = new receipt ();
  1890. Doo::loadModel ( 'receiptTraining' );
  1891. $receiptTraining = new receiptTraining ();
  1892. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1893. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1894. die ('illegal request--status');
  1895. }
  1896. //如有已入账已收款的发票,自动取消办事处已收款
  1897. // Doo::loadModel ( 'RIExtend' );
  1898. // $RIExtend = new RIExtend ();
  1899. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1900. // if (!empty($RIExtendList)){
  1901. // foreach ($RIExtendList as $key=>$value){
  1902. // $RIExtend = new RIExtend ();
  1903. // $RIExtend->delete(array (
  1904. // 'where' => 'iid=' . $value['iid'],
  1905. // 'limit' => 1
  1906. // ));
  1907. // }
  1908. // }
  1909. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1910. // 汇总表合计
  1911. // 收入合计--加入开票合计
  1912. Doo::loadModel ( 'invoiceTraining' );
  1913. $invoiceTraining = new invoiceTraining ();
  1914. $invoiceTrainingDetail = array (
  1915. 'invoiceArriveAmount' => 0,
  1916. 'RIAmount' => 0,
  1917. 'invoiceTotalAmount' => 0,
  1918. 'invoiceCompanyAmount'=>0
  1919. );
  1920. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1921. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1922. }
  1923. // print_r($invoiceTrainingDetail);
  1924. $invoiceArriveAmount = $RIAmount = 0;
  1925. if (! empty ( $invoiceTrainingDetail )) {
  1926. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1927. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1928. }
  1929. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1930. //print_r($invoiceTrainingDetail);
  1931. // 支出项目
  1932. Doo::loadModel ( 'accountItem' );
  1933. $accountItem = new accountItem ();
  1934. // 项目金额合计
  1935. Doo::loadModel ( 'RItem' );
  1936. $RItem = new RItem ();
  1937. // 讲师获得
  1938. Doo::loadModel ( 'RILecturer' );
  1939. $RILecturer = new RILecturer ();
  1940. $RItemList = $RItem->getRItemByRid ( $rid );
  1941. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1942. // 支出项金额详情
  1943. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1944. // print_r($aiData);
  1945. // 利润
  1946. $profit=$invoiceArriveAmount - $aiData ['total'];
  1947. $companyProfit=$profit * 0.6;
  1948. $categoryProfit=$profit * 0.4;
  1949. $data ['profit'] = sprintf("%.2f",$profit);
  1950. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1951. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1952. //发票利润
  1953. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1954. //发票公司利润
  1955. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1956. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1957. //办事处利润
  1958. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1959. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1960. // print_r($aiData['dataList']);
  1961. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1962. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1963. // 备用金
  1964. $sum = 0;
  1965. $data ['receiptLoanDetail'] = array (
  1966. 'sum' => '0.00'
  1967. );
  1968. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1969. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1970. $sum = $data ['receiptLoanDetail'] ['sum'];
  1971. }
  1972. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1973. $data ['payment'] = sprintf("%.2f",$payment);
  1974. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1975. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1976. $data ['aiList'] = $aiData ['dataList'];
  1977. // 占比计算
  1978. if ($invoiceArriveAmount != 0) {
  1979. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1980. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1981. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1982. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1983. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1984. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1985. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1986. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1987. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1988. } else {
  1989. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1990. }
  1991. //发票金额占比计算
  1992. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1993. //支出
  1994. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1995. //利润
  1996. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //公司利润
  1998. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //办事处利润
  2000. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //公司收款
  2002. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //备用金
  2004. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //办事处收款
  2006. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //办事处实际支出
  2008. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. //付总部款
  2010. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2011. }else{
  2012. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2013. }
  2014. //讲师人数
  2015. Doo::loadModel ( 'RILecturer' );
  2016. $RILecturer = new RILecturer ();
  2017. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2018. $data['lectureCount']=count($RILecturerList);
  2019. // 审批组
  2020. Doo::loadModel ( 'verify' );
  2021. $verify = new verify ();
  2022. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2023. // 办事处
  2024. Doo::loadModel ( 'L_category' );
  2025. $lCategory = new L_category ();
  2026. $data ['category'] = $lCategory->getCategory ();
  2027. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2028. $data ['receiptDetail'] = $receiptDetail;
  2029. $data ['veList'] = $veList;
  2030. $data ['trainEdiType'] = $trainEdiType;
  2031. $data ['ridKey'] = $ridKey;
  2032. $data ['memu'] = "receipt";
  2033. $data ['staff'] = $this->staff;
  2034. $data ['receiptMemu'] = 'saeaBorad';
  2035. $data ['verifyId'] = $this->verifyId;
  2036. $data ['executeId'] = $this->executeId;
  2037. $this->render ( "/receipt/receiptTrainEdi", $data );
  2038. }
  2039. /**
  2040. * 培训班借款编辑
  2041. */
  2042. function receiptTrainLoanEdi() {
  2043. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2044. Doo::loadClass ( 'XDeode' );
  2045. $XDeode = new XDeode ( 7 );
  2046. $rid = $XDeode->decode ( $ridKey );
  2047. if (! is_numeric ( $rid ))
  2048. die ( 'illegal request' );
  2049. Doo::loadModel ( 'receipt' );
  2050. $receipt = new receipt ();
  2051. Doo::loadModel ( 'receiptTraining' );
  2052. $receiptTraining = new receiptTraining ();
  2053. Doo::loadModel ( 'verify' );
  2054. $verify = new verify ();
  2055. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2056. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2057. die ();
  2058. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2059. // 借款详情HTML
  2060. // 获得借款信息
  2061. $receiptLoanHtml = '';
  2062. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2063. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2064. // 获得某费用单审批信息
  2065. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2066. Doo::loadClass ( 'receipt.func' );
  2067. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2068. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2069. }
  2070. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2071. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2072. $data ['receiptDetail'] = $receiptDetail;
  2073. $data ['trainEdiType'] = "LOAN";
  2074. $data ['ridKey'] = $ridKey;
  2075. $data ['memu'] = "receipt";
  2076. $data ['staff'] = $this->staff;
  2077. $data ['receiptMemu'] = 'saeaBorad';
  2078. $data ['verifyId'] = $this->verifyId;
  2079. $data ['executeId'] = $this->executeId;
  2080. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2081. }
  2082. /**
  2083. * 更新培训班结算基本信息
  2084. */
  2085. function receiptTrainInfoEdiDo() {
  2086. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2087. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2088. // 培训班信息
  2089. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2090. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2091. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2092. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2093. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2094. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2095. // 发票信息
  2096. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2097. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2098. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2099. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2100. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2101. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2102. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2103. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2104. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2105. header ( 'Content-Type:text/html;charset=utf-8' );
  2106. die ( '请填写联行号' );
  2107. }
  2108. Doo::loadClass ( 'XDeode' );
  2109. $XDeode = new XDeode ( 5 );
  2110. $cid = $XDeode->decode ( $cid );
  2111. $rtid = $XDeode->decode ( $rtid );
  2112. $rid = $XDeode->decode ( $rid );
  2113. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2114. die ( 'illegal request-IdError' );
  2115. }
  2116. Doo::loadModel ( 'receipt' );
  2117. $receipt = new receipt ();
  2118. Doo::loadModel ( 'receiptTraining' );
  2119. $receiptTraining = new receiptTraining ();
  2120. // 更新费用培训班
  2121. $item = array (
  2122. 'rtid' => $rtid,
  2123. 'trainName' => $trainName,
  2124. 'trainStartDate' => $trainStartDate,
  2125. 'trainEndDate' => $trainEndDate,
  2126. 'participants' => $participants,
  2127. 'trainAddress' => $trainAddress,
  2128. 'trainRemarks' => $trainRemarks
  2129. );
  2130. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2131. // 报销单
  2132. $receipt->rid = $rid;
  2133. $receipt->cid = $cid;
  2134. $receipt->verify = $verify;
  2135. $receipt->remittanceName = $remittanceName;
  2136. $receipt->bankName = $bankName;
  2137. $receipt->bankNumber = $bankNumber;
  2138. $receipt->remittanceBankType = $remittanceBankType;
  2139. if ($remittanceBankType == 1)
  2140. $receipt->coupletNumber = $coupletNumber;
  2141. $receipt->update ();
  2142. $XDeode = new XDeode ( 7 );
  2143. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2144. } else
  2145. die ( 'illegal request' );
  2146. }
  2147. /**
  2148. * 编辑培训班结算---更新借款
  2149. */
  2150. function receiptTrainLoanEdiDo() {
  2151. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2152. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2153. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2154. Doo::loadModel ( 'receipt' );
  2155. $receipt = new receipt ();
  2156. Doo::loadClass ( 'XDeode' );
  2157. $XDeode = new XDeode ( 5 );
  2158. $rid = $XDeode->decode ( $ridKey );
  2159. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2160. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2161. die ( 'illegal request-ridError' );
  2162. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2163. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2164. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2165. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2166. die ( 'illegal request-receiptError' );
  2167. }
  2168. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2169. die ( 'illegal request-receipLoantError' );
  2170. }
  2171. // 培训班结算挂钩借款
  2172. $receipt = new receipt ();
  2173. $item = array (
  2174. 'rid' => $rid,
  2175. 'trainLoanRid' => $ridLoan
  2176. );
  2177. $receipt->setReceiptByCondition ( $item );
  2178. // 更新借款状态变成已挂钩
  2179. $receipt = new receipt ();
  2180. $item = array (
  2181. 'rid' => $ridLoan,
  2182. 'status' => 10,
  2183. 'statusTrain' => 1
  2184. );
  2185. $receipt->setReceiptByCondition ( $item );
  2186. $XDeode = new XDeode ( 7 );
  2187. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2188. } else
  2189. die ( 'illegal request' );
  2190. }
  2191. /**
  2192. * 编辑培训班结算--移除借款
  2193. */
  2194. function receiptTrainLoanRemoveDo() {
  2195. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2196. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2197. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2198. Doo::loadModel ( 'receipt' );
  2199. $receipt = new receipt ();
  2200. Doo::loadClass ( 'XDeode' );
  2201. $XDeode = new XDeode ( 5 );
  2202. $rid = $XDeode->decode ( $ridKey );
  2203. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2204. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2205. die ( 'illegal request-ridError' );
  2206. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2207. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2208. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2209. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2210. die ( 'illegal request-receiptError' );
  2211. }
  2212. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2213. die ( 'illegal request-receipLoantError' );
  2214. }
  2215. // 培训班结算挂钩借款
  2216. $receipt = new receipt ();
  2217. $item = array (
  2218. 'rid' => $rid,
  2219. 'trainLoanRid' => 0
  2220. );
  2221. $receipt->setReceiptByCondition ( $item );
  2222. // 更新借款状态变成已挂钩
  2223. $receipt = new receipt ();
  2224. $item = array (
  2225. 'rid' => $ridLoan,
  2226. 'status' => 8,
  2227. 'statusTrain' => 0
  2228. );
  2229. $receipt->setReceiptByCondition ( $item );
  2230. $XDeode = new XDeode ( 7 );
  2231. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2232. } else
  2233. die ( 'illegal request' );
  2234. }
  2235. /**
  2236. * 编辑培训班结算 ---开票
  2237. */
  2238. function receiptTrainInvoiceEdi() {
  2239. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2240. Doo::loadClass ( 'XDeode' );
  2241. $XDeode = new XDeode ( 7 );
  2242. $rid = $XDeode->decode ( $ridKey );
  2243. if (! is_numeric ( $rid ))
  2244. die ( 'illegal request' );
  2245. Doo::loadModel ( 'receipt' );
  2246. $receipt = new receipt ();
  2247. Doo::loadModel ( 'receiptTraining' );
  2248. $receiptTraining = new receiptTraining ();
  2249. Doo::loadModel ( 'invoice' );
  2250. $invoice = new invoice ();
  2251. Doo::loadModel ( 'invoiceTraining' );
  2252. $invoiceTraining = new invoiceTraining ();
  2253. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2254. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2255. die ();
  2256. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2257. $invoiceList = $invoiceTrainingDetail = array ();
  2258. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2259. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2260. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2261. }
  2262. //print_r($invoiceList);
  2263. $data ['invoiceList'] = $invoiceList;
  2264. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2265. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2266. $data ['receiptDetail'] = $receiptDetail;
  2267. $data ['trainEdiType'] = "INVOICE";
  2268. $data ['ridKey'] = $ridKey;
  2269. $data ['memu'] = "receipt";
  2270. $data ['staff'] = $this->staff;
  2271. $data ['receiptMemu'] = 'saeaBorad';
  2272. $data ['verifyId'] = $this->verifyId;
  2273. $data ['executeId'] = $this->executeId;
  2274. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2275. }
  2276. /**
  2277. * 编辑培训班结算---更新开票
  2278. */
  2279. function receiptTrainInvoiceEdiDo() {
  2280. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2281. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2282. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2283. Doo::loadModel ( 'receipt' );
  2284. $receipt = new receipt ();
  2285. Doo::loadModel ( 'invoiceTraining' );
  2286. $invoiceTraining = new invoiceTraining ();
  2287. Doo::loadClass ( 'XDeode' );
  2288. $XDeode = new XDeode ( 5 );
  2289. $rid = $XDeode->decode ( $ridKey );
  2290. $itid = $XDeode->decode ( $itidKey );
  2291. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2292. die ( 'illegal request-idError' );
  2293. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2294. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2295. // 不合法的数据
  2296. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2297. die ( 'illegal request-receiptError' );
  2298. }
  2299. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2300. die ( 'illegal request-receipLoantError' );
  2301. }
  2302. // 培训班结算挂钩借款
  2303. $receipt = new receipt ();
  2304. $item = array (
  2305. 'rid' => $rid,
  2306. 'invoiceTrainId' => $itid
  2307. );
  2308. $receipt->setReceiptByCondition ( $item );
  2309. $invoiceTraining = new invoiceTraining ();
  2310. $item = array (
  2311. 'bindReceipt' => 1,
  2312. 'itid' => $itid
  2313. );
  2314. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2315. $XDeode = new XDeode ( 7 );
  2316. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2317. } else
  2318. die ( 'illegal request' );
  2319. }
  2320. /**
  2321. * 更新培训班结算 收款和取消收款
  2322. */
  2323. function receiptTrainReceivables() {
  2324. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2325. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2326. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2327. Doo::loadClass ( 'XDeode' );
  2328. $XDeode = new XDeode ( 5 );
  2329. $rid = $XDeode->decode ( $ridKey );
  2330. $iid = $XDeode->decode ( $iidKey );
  2331. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2332. die ( 'illegal request-iid' );
  2333. Doo::loadModel ( 'RIExtend' );
  2334. $RIExtend = new RIExtend ();
  2335. if ($doType == 'CONFIRM') {
  2336. $RIExtend->rid = $rid;
  2337. $RIExtend->iid = $iid;
  2338. $RIExtend->RIstatus = 1;
  2339. $RIExtend->insert ();
  2340. echo json_encode ( array (
  2341. 'status' => 1,
  2342. ) );
  2343. die ( );
  2344. } elseif ($doType == 'CANCEL') {
  2345. $RIExtend->delete ( array (
  2346. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2347. 'limit' => 1
  2348. ) );
  2349. echo json_encode ( array (
  2350. 'status' => 1,
  2351. ) );
  2352. die ( );
  2353. } else {
  2354. echo json_encode ( array (
  2355. 'status' => 2,
  2356. ) );
  2357. die ( );
  2358. }
  2359. }
  2360. /**
  2361. * 移除挂钩的培训班发票
  2362. */
  2363. function receiptTrainReceivablesDelDo() {
  2364. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2365. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2366. Doo::loadModel ( 'receipt' );
  2367. $receipt = new receipt ();
  2368. Doo::loadModel ( 'RIExtend' );
  2369. $RIExtend = new RIExtend ();
  2370. Doo::loadClass ( 'XDeode' );
  2371. $XDeode = new XDeode ( 5 );
  2372. $rid = $XDeode->decode ( $ridKey );
  2373. $itid = $XDeode->decode ( $itidKey );
  2374. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2375. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2376. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2377. die ( 'illegal request-status' );
  2378. }
  2379. $receipt = new receipt ();
  2380. $receipt->rid = $rid;
  2381. $receipt->invoiceTrainId = 0;
  2382. $receipt->update ();
  2383. Doo::loadModel ( 'invoiceTraining' );
  2384. $invoiceTraining = new invoiceTraining ();
  2385. $item = array (
  2386. 'bindReceipt' => 0,
  2387. 'itid' => $itid
  2388. );
  2389. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2390. $RIExtend->delete ( array (
  2391. 'where' => 'rid=' . $rid
  2392. ) );
  2393. $XDeode = new XDeode ( 7 );
  2394. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2395. } else
  2396. die ( 'illegal request-iid' );
  2397. }
  2398. /**
  2399. * 编辑培训班结算
  2400. */
  2401. function receiptTrainItemEdi() {
  2402. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2403. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2404. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2405. Doo::loadClass ( 'XDeode' );
  2406. $XDeode = new XDeode ( 7 );
  2407. $rid = $XDeode->decode ( $ridKey );
  2408. if (! is_numeric ( $rid ))
  2409. die ( 'illegal request' );
  2410. Doo::loadModel ( 'receipt' );
  2411. $receipt = new receipt ();
  2412. Doo::loadModel ( 'receiptTraining' );
  2413. $receiptTraining = new receiptTraining ();
  2414. Doo::loadModel ( 'RItem' );
  2415. $RItem = new RItem ();
  2416. Doo::loadModel ( 'accountItem' );
  2417. $accountItem = new accountItem ();
  2418. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2419. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2420. die ();
  2421. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2422. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2423. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2424. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2425. // if($value['name']=='税款'){
  2426. // unset($aiList[$key]);break;
  2427. // }
  2428. // }
  2429. //print_r($RItemList);
  2430. $data ['name'] = $name;
  2431. $data ['RItemList'] = $RItemList;
  2432. $data ['aiList'] = $aiList;
  2433. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2434. $data ['receiptDetail'] = $receiptDetail;
  2435. $data ['trainEdiType'] = "ITEM";
  2436. $data ['ridKey'] = $ridKey;
  2437. $data ['memu'] = "receipt";
  2438. $data ['staff'] = $this->staff;
  2439. $data ['receiptMemu'] = 'saeaBorad';
  2440. $data ['verifyId'] = $this->verifyId;
  2441. $data ['executeId'] = $this->executeId;
  2442. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2443. }
  2444. /**
  2445. * 添加支出项 需要修改 费用金额合计
  2446. */
  2447. function receiptTrainItemAddDo() {
  2448. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2449. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2450. // 支出项信息
  2451. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2452. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2453. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2454. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2455. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2456. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2457. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2458. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2459. Doo::loadClass ( 'XDeode' );
  2460. $XDeode = new XDeode ( 5 );
  2461. Doo::loadModel ( 'RItem' );
  2462. $RItem = new RItem ();
  2463. $rid = $XDeode->decode ( $ridKey );
  2464. $rtid= $XDeode->decode ( $rtidKey );
  2465. if (! is_numeric ( $rid )){
  2466. die ( 'illegal request' );
  2467. }
  2468. Doo::loadModel ( 'receiptDetail' );
  2469. $receiptDetail = new receiptDetail ();
  2470. Doo::loadModel ( 'receipt' );
  2471. $receipt = new receipt ();
  2472. Doo::loadModel ( 'receiptTraining' );
  2473. $receiptTraining = new receiptTraining ();
  2474. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2475. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2476. echo $rtDetail['identifyingTotal'];die;
  2477. $order = array (
  2478. "\r\n",
  2479. "\n",
  2480. "\r"
  2481. );
  2482. $replace = '<br/>';
  2483. $describe = str_replace ( $order, $replace, $describe );
  2484. $itemData = array (
  2485. 'rid' => $rid,
  2486. 'item' => $item,
  2487. 'price' => $price,
  2488. 'date' => $date,
  2489. 'inputer' => $inputer,
  2490. 'describe' => $describe,
  2491. 'creater' => $this->staff['0']['username'],
  2492. 'createrId' => $this->staff['0']['sid'],
  2493. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2494. 'identifying'=>$identifyingTotal
  2495. );
  2496. if($payType=='company'){
  2497. $itemData += array (
  2498. 'payType' => 1
  2499. );
  2500. }
  2501. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2502. //更新支出项标识总数
  2503. $itemData = array (
  2504. 'rtid'=>$rtid,
  2505. 'identifyingTotal'=>$identifyingTotal
  2506. );
  2507. $receiptTraining->setReceiptTrainByCondition($itemData);
  2508. $XDeode = new XDeode ( 7 );
  2509. if($payType=='company'){
  2510. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2511. }else{
  2512. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2513. }
  2514. } else
  2515. die ( 'illegal request-dataError' );
  2516. }
  2517. /**
  2518. * 培训班结算-讲师
  2519. */
  2520. function receiptTrainLecturerEdi() {
  2521. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2522. Doo::loadClass ( 'XDeode' );
  2523. $XDeode = new XDeode ( 7 );
  2524. $rid = $XDeode->decode ( $ridKey );
  2525. if (! is_numeric ( $rid ))
  2526. die ( 'illegal request' );
  2527. Doo::loadModel ( 'receipt' );
  2528. $receipt = new receipt ();
  2529. Doo::loadModel ( 'receiptTraining' );
  2530. $receiptTraining = new receiptTraining ();
  2531. Doo::loadModel ( 'RILecturer' );
  2532. $RILecturer = new RILecturer ();
  2533. Doo::loadModel ( 'lecturer' );
  2534. $lecturer = new lecturer ();
  2535. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2536. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2537. die ();
  2538. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2539. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2540. $lecturerList = $lecturer->getLecturerAll ();
  2541. $INSIDEhtml = $OUTSIDEhtml = '';
  2542. foreach ( $lecturerList as $key => $value ) {
  2543. if ($value ['ltype'] == 'INSIDE') {
  2544. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2545. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2546. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2547. }
  2548. }
  2549. $data ['INSIDEhtml'] = $INSIDEhtml;
  2550. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2551. // print_r($RItemList);
  2552. $data ['RILecturerList'] = $RILecturerList;
  2553. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2554. $data ['receiptDetail'] = $receiptDetail;
  2555. $data ['trainEdiType'] = "LECTURER";
  2556. $data ['ridKey'] = $ridKey;
  2557. $data ['memu'] = "receipt";
  2558. $data ['staff'] = $this->staff;
  2559. $data ['receiptMemu'] = 'saeaBorad';
  2560. $data ['verifyId'] = $this->verifyId;
  2561. $data ['executeId'] = $this->executeId;
  2562. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2563. }
  2564. /**
  2565. * 添加讲师
  2566. */
  2567. function receiptTrainLecturerAddDo() {
  2568. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2569. // 支出项信息
  2570. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2571. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2572. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2573. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2574. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2575. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2576. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2577. Doo::loadClass ( 'XDeode' );
  2578. $XDeode = new XDeode ( 5 );
  2579. Doo::loadModel ( 'RILecturer' );
  2580. $RILecturer = new RILecturer ();
  2581. $rid = $XDeode->decode ( $ridKey );
  2582. if (! is_numeric ( $rid ))
  2583. die ( 'illegal request' );
  2584. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2585. die ( 'illegal request-taxationError' );
  2586. $RILecturer->rid = $rid;
  2587. $RILecturer->ltype = $ltype;
  2588. if ($ltype == 'OUTSIDE') {
  2589. if ($taxation == 'TAXATION') {
  2590. $RILecturer->taxation = 1;
  2591. } elseif ($taxation == 'NOTAXATION') {
  2592. $RILecturer->taxation = 0;
  2593. }
  2594. }
  2595. $RILecturer->lecturerName = $lecturerName;
  2596. $RILecturer->schoolDay = $schoolDay;
  2597. $RILecturer->price = $price;
  2598. $RILecturer->fees=$fees;
  2599. $RILecturer->insert ();
  2600. // 添加公司汇总
  2601. // 报销详情
  2602. Doo::loadModel ( 'receiptDetail' );
  2603. $receiptDetail = new receiptDetail ();
  2604. Doo::loadModel ( 'receipt' );
  2605. $receipt = new receipt ();
  2606. // 金额总计
  2607. $price = $price * $schoolDay;
  2608. $rInfo = $receipt->getReceiptByRid ( $rid );
  2609. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2610. if (empty ( $rdInfo )) {
  2611. $receiptDetail = new receiptDetail ();
  2612. $receiptDetail->staff = $rInfo ['staff'];
  2613. $receiptDetail->item = '讲课费';
  2614. $receiptDetail->itemCategory = '培训班费用';
  2615. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2616. $receiptDetail->date = date ( "Y-m-d" );
  2617. $receiptDetail->cid = $rInfo ['cid'];
  2618. $receiptDetail->rid = $rid;
  2619. $receiptDetail->status = 4;
  2620. $receiptDetail->insert ();
  2621. } else {
  2622. $receiptDetail = new receiptDetail ();
  2623. $rdInfo ['price'] += $fees;
  2624. $receiptDetail->price = $rdInfo ['price'];
  2625. $receiptDetail->update ( array (
  2626. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2627. ) );
  2628. }
  2629. $receipt = new receipt ();
  2630. $receipt->sum=$rInfo['sum']+$fees;
  2631. $receipt->update ( array (
  2632. 'where' => 'rid=' . $rid
  2633. ) );
  2634. $XDeode = new XDeode ( 7 );
  2635. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2636. } else
  2637. die ( 'illegal request' );
  2638. }
  2639. /**
  2640. * 移除讲师
  2641. */
  2642. function receiptTrainLecturerDelDo() {
  2643. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2644. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2645. Doo::loadModel ( 'receipt' );
  2646. $receipt = new receipt ();
  2647. Doo::loadModel ( 'RILecturer' );
  2648. $RILecturer = new RILecturer ();
  2649. Doo::loadClass ( 'XDeode' );
  2650. $XDeode = new XDeode ( 5 );
  2651. $rid = $XDeode->decode ( $ridKey );
  2652. $rlid = $XDeode->decode ( $rlidKey );
  2653. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2654. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2655. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2656. die ( 'illegal request-status' );
  2657. }
  2658. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2659. if (empty($detail)){
  2660. die ( 'illegal request-data' );
  2661. }
  2662. $RILecturer->delete ( array (
  2663. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2664. ) );
  2665. //更新费用合计金额
  2666. $rInfo = $receipt->getReceiptByRid ( $rid );
  2667. $receipt = new receipt ();
  2668. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2669. $receipt->update ( array (
  2670. 'where' => 'rid=' . $rid
  2671. ) );
  2672. Doo::loadModel ( 'receiptDetail' );
  2673. $receiptDetail = new receiptDetail ();
  2674. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2675. $receiptDetail = new receiptDetail ();
  2676. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2677. $receiptDetail->price = $rdInfo ['price'];
  2678. $receiptDetail->update ( array (
  2679. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2680. ) );
  2681. $XDeode = new XDeode ( 7 );
  2682. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2683. } else
  2684. die ( 'illegal request-iid' );
  2685. }
  2686. /**
  2687. * 培训班提交审批
  2688. */
  2689. function receiptTrainDo() {
  2690. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2691. Doo::loadClass ( 'XDeode' );
  2692. $XDeode = new XDeode ( 7 );
  2693. $rid = $XDeode->decode ( $ridKey );
  2694. Doo::loadModel ( 'receipt' );
  2695. $receipt = new receipt ();
  2696. Doo::loadModel ( 'receiptDetail' );
  2697. $receiptDetail = new receiptDetail ();
  2698. Doo::loadModel ( 'statistics' );
  2699. $statistics = new statistics ();
  2700. Doo::loadModel ( "verify" );
  2701. $verify = new verify ();
  2702. // 审批状态的判定
  2703. $receiptDetailList = $receipt->getOne ( array (
  2704. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2705. 'asArray' => true
  2706. ) );
  2707. if (empty ( $receiptDetailList ))
  2708. return "/saeaBorad";
  2709. $verifyDetail = $verify->getOne ( array (
  2710. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2711. 'asArray' => true
  2712. ) );
  2713. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2714. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2715. $nowStaff = "";
  2716. $nowStaffList = array ();
  2717. if ($verifyDetail [0] [1] == 'ROLE') {
  2718. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2719. foreach ( $vStaffString as $key => $value ) {
  2720. $staffK = explode ( "_", $value );
  2721. array_push ( $nowStaffList, $staffK [0] );
  2722. }
  2723. $nowStaff = implode ( ',', $nowStaffList );
  2724. } else {
  2725. $nowStaff = $verifyDetail [0] [0];
  2726. }
  2727. $receipt->nowStaff = $nowStaff;
  2728. }
  2729. // echo $nowStaff;
  2730. // print_r($verifyDetail);die;
  2731. $receipt->rid = $receiptDetailList ['rid'];
  2732. $receipt->date = date ( "Y-m-d" );
  2733. $receipt->status = 2;
  2734. $receipt->update ();
  2735. $receiptDetail->status = 2;
  2736. $receiptDetail->update ( array (
  2737. 'where' => 'rid=' . $receiptDetailList ['rid']
  2738. ) );
  2739. Doo::loadModel ( "receiptLog" );
  2740. $receiptLog = new receiptLog ();
  2741. Doo::loadModel ( "verify" );
  2742. $verify = new verify ();
  2743. $vr = $verify->getOne ( array (
  2744. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2745. 'asArray' => true
  2746. ) );
  2747. $jd = json_decode ( $vr ['staff'] );
  2748. $roleId = 0;
  2749. foreach ( $jd as $key => $value ) {
  2750. if ($value [1] == 'ROLE') {
  2751. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2752. if ($pos !== false) {
  2753. $roleId = $value [0];
  2754. }
  2755. }
  2756. }
  2757. // 审批日志
  2758. // echo $roleId;die;
  2759. if (! empty ( $roleId )) {
  2760. Doo::loadModel ( "role" );
  2761. $role = new role ();
  2762. $roleInfo = $role->getOne ( array (
  2763. 'where' => 'rid=' . $roleId,
  2764. 'asArray' => true
  2765. ) );
  2766. // $receiptLog->rolename = $roleInfo ['name'];
  2767. }
  2768. $receiptLog->username = $this->staff [0] ['username'];
  2769. $receiptLog->uid = $this->staff [0] ['sid'];
  2770. $receiptLog->date = date ( "Y-m-d" );
  2771. $receiptLog->opinion = '提交审批';
  2772. $receiptLog->img = $this->staff [0] ['avatar'];
  2773. $receiptLog->status = 2;
  2774. $receiptLog->rid = $rid;
  2775. $receiptLog->insert ();
  2776. // 写入列表项
  2777. Doo::loadModel ( 'accountItem' );
  2778. $accountItem = new accountItem ();
  2779. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2780. // 项目金额合计
  2781. Doo::loadModel ( 'RItem' );
  2782. $RItem = new RItem ();
  2783. // 讲师获得
  2784. Doo::loadModel ( 'RILecturer' );
  2785. $RILecturer = new RILecturer ();
  2786. $RItemList = $RItem->getRItemByRid ( $rid );
  2787. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2788. // 支出项金额详情
  2789. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2790. // print_r($aItem);
  2791. // print_r($aiData);
  2792. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2793. $ag = $tr = $ta = $ot = 0;
  2794. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2795. foreach ( $aItem as $key => $value ) {
  2796. if ($value ['category'] == $this->TRAIN) {
  2797. foreach ( $aiData ['dataList'] as $k => $v ) {
  2798. if ($value ['name'] == $v ['name']) {
  2799. array_push ( $accountJson [$this->TRAIN], array (
  2800. 'aid' => $value ['aid'],
  2801. 'name' => $value ['name'],
  2802. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2803. ) );
  2804. $sum += $v ['price'];
  2805. $trainSum += $v ['price'];
  2806. unset ( $aiData ['dataList'] [$k] );
  2807. break;
  2808. }
  2809. }
  2810. }
  2811. }
  2812. $accountJson ['cSum'] = array (
  2813. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2814. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2815. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2816. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2817. );
  2818. // 报销单
  2819. $receipt = new receipt ();
  2820. $receipt->accountItem = json_encode ( $accountJson );
  2821. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2822. $receipt->update ( array (
  2823. 'where' => 'rid=' . $rid
  2824. ) );
  2825. // print_r($accountJson);
  2826. // statistics item 统计写入
  2827. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2828. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2829. $accountItem = $accountJson;
  2830. $stat = $statistics->getOne ( array (
  2831. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2832. 'asArray' => true
  2833. ) );
  2834. if (empty ( $stat )) {
  2835. $statistics->date = date ( "Y-m-d" );
  2836. $statistics->cid = $this->staff [0] ['cid'];
  2837. $statistics->staff = $this->staff [0] ['sid'];
  2838. $statistics->agPrice = 0;
  2839. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2840. $statistics->insert ();
  2841. } else {
  2842. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2843. $statistics->update ( array (
  2844. 'where' => 'sid=' . $stat ['sid']
  2845. ) );
  2846. }
  2847. return "/saeaBorad";
  2848. }
  2849. function confirmation() {
  2850. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2851. Doo::loadModel ( 'receipt' );
  2852. Doo::loadModel ( 'receiptDetail' );
  2853. $receipt = new receipt ();
  2854. $receiptDetail = new receiptDetail ();
  2855. Doo::loadModel ( 'statistics' );
  2856. Doo::loadModel ( 'itemStatistics' );
  2857. $statistics = new statistics ();
  2858. $itemStatistics = new itemStatistics ();
  2859. Doo::loadModel ( "verify" );
  2860. $verify = new verify ();
  2861. $receiptDetailList = $receipt->getOne ( array (
  2862. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2863. 'asArray' => true
  2864. ) );
  2865. if (empty ( $receiptDetailList ))
  2866. return "/saeaBorad";
  2867. $verifyDetail = $verify->getOne ( array (
  2868. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2869. 'asArray' => true
  2870. ) );
  2871. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2872. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2873. $nowStaff = "";
  2874. $nowStaffList = array ();
  2875. if ($verifyDetail [0] [1] == 'ROLE') {
  2876. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2877. foreach ( $vStaffString as $key => $value ) {
  2878. $staffK = explode ( "_", $value );
  2879. array_push ( $nowStaffList, $staffK [0] );
  2880. }
  2881. $nowStaff = implode ( ',', $nowStaffList );
  2882. } else {
  2883. $nowStaff = $verifyDetail [0] [0];
  2884. }
  2885. $receipt->nowStaff = $nowStaff;
  2886. }
  2887. // echo $nowStaff;
  2888. // print_r($verifyDetail);die;
  2889. $receipt->rid = $receiptDetailList ['rid'];
  2890. $receipt->status = 2;
  2891. $receipt->update ();
  2892. // 操作日志
  2893. Doo::loadModel ( "receiptLog" );
  2894. $receiptLog = new receiptLog ();
  2895. $verify = new verify ();
  2896. $receiptInfo = $receipt->getOne ( array (
  2897. 'where' => 'rid=' . $rid,
  2898. 'asArray' => true
  2899. ) );
  2900. $vr = $verify->getOne ( array (
  2901. 'where' => 'vid=' . $receiptInfo ['verify'],
  2902. 'asArray' => true
  2903. ) );
  2904. $jd = json_decode ( $vr ['staff'] );
  2905. $roleId = 0;
  2906. foreach ( $jd as $key => $value ) {
  2907. if ($value [1] == 'ROLE') {
  2908. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2909. if ($pos !== false) {
  2910. $roleId = $value [0];
  2911. }
  2912. }
  2913. }
  2914. // 审批日志
  2915. // echo $roleId;die;
  2916. if (! empty ( $roleId )) {
  2917. Doo::loadModel ( "role" );
  2918. $role = new role ();
  2919. $roleInfo = $role->getOne ( array (
  2920. 'where' => 'rid=' . $roleId,
  2921. 'asArray' => true
  2922. ) );
  2923. // $receiptLog->rolename = $roleInfo ['name'];
  2924. }
  2925. $receiptLog->username = $this->staff [0] ['username'];
  2926. $receiptLog->uid = $this->staff [0] ['sid'];
  2927. $receiptLog->date = date ( "Y-m-d" );
  2928. $receiptLog->opinion = '提交审批';
  2929. $receiptLog->img = $this->staff [0] ['avatar'];
  2930. $receiptLog->status = 2;
  2931. $receiptLog->rid = $rid;
  2932. $receiptLog->insert ();
  2933. return "/expenses";
  2934. }
  2935. function expenses() {
  2936. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2937. if (empty ( $item ))
  2938. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2939. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2940. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2941. Doo::loadClass ( 'XDeode' );
  2942. $XDeode = new XDeode ( 7 );
  2943. Doo::loadModel ( 'receipt' );
  2944. $receipt = new receipt ();
  2945. Doo::loadModel ( 'L_category' );
  2946. $Lcategory = new L_category ();
  2947. Doo::loadModel ( 'verify' );
  2948. Doo::loadModel ( 'statistics' );
  2949. $statistics = new statistics ();
  2950. $verify = new verify ();
  2951. Doo::loadModel ( 'staff' );
  2952. $staff = new staff ();
  2953. $condition = "";
  2954. if ($item == "expenses")
  2955. $condition = " and Rtype=1 ";
  2956. elseif ($item == "receipts")
  2957. $condition = " and Rtype=0 ";
  2958. elseif ($item == "remits")
  2959. $condition = " and Rtype=2 ";
  2960. elseif ($item == "train")
  2961. $condition = " and Rtype=3 ";
  2962. $dateCondition = " and Year(date) =" . $year;
  2963. if (! empty ( $moth )) {
  2964. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2965. $stList = $statistics->getOne ( array (
  2966. 'select' => 'rePrice ,agPrice',
  2967. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2968. 'asArray' => true
  2969. ) );
  2970. } else
  2971. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2972. if (empty ( $stList ))
  2973. $stList = array (
  2974. 'rePrice' => 0,
  2975. 'agPrice' => 0
  2976. );
  2977. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2978. if (! isset ( $noPassSum ['sum'] ))
  2979. $noPassSum ['sum'] = 0;
  2980. $data ['stList'] = array (
  2981. 'rePrice' => $stList ['rePrice'],
  2982. 'agPrice' => $stList ['agPrice'],
  2983. 'skPrice' => ($noPassSum ['sum'])
  2984. );
  2985. $receiptList = $receipt->find ( array (
  2986. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2987. 'desc' => 'rid',
  2988. 'asArray' => true
  2989. ) );
  2990. $Locate = 0;
  2991. $roleId = 0;
  2992. $button = 0;
  2993. foreach ( $receiptList as $key => $value ) {
  2994. $receiptList [$key] ['Locate'] = $Locate;
  2995. $Locate ++;
  2996. $receiptList [$key] ['reviseDetail'] = array ();
  2997. if (! empty ( $value ['reviseDetail'] ))
  2998. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2999. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3000. $categoryDetil = $Lcategory->getOne ( array (
  3001. 'where' => 'cid=' . $value ['cid'],
  3002. 'asArray' => true
  3003. ) );
  3004. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3005. // 检测编辑状态
  3006. $verifyList = $verify->getOne ( array (
  3007. 'where' => 'vid=' . $value ['verify'],
  3008. 'asArray' => true
  3009. ) );
  3010. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3011. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3012. Doo::loadModel ( 'role' );
  3013. $role = new role ();
  3014. $flag = true;
  3015. $roleKey = 0;
  3016. $endStaffArray = array ();
  3017. $roleArrayCopy = array ();
  3018. foreach ( $verifyList as $k => $v ) {
  3019. // init verifyStaff
  3020. if ($v [1] == 'ROLE') {
  3021. if (! empty ( $verifyStaff )) {
  3022. $endStaffArray = end ( $verifyStaff );
  3023. // if ($v[0]==$endStaffArray['nextStaff']){
  3024. // $roleId=$v[0];
  3025. // }
  3026. }
  3027. $roleVerify = json_decode ( $v [3], true );
  3028. $roleKey = $k;
  3029. $roleArray = array ();
  3030. $rolename = $role->getOne ( array (
  3031. 'where' => 'rid=' . $v [0],
  3032. 'asArray' => true
  3033. ) );
  3034. foreach ( $roleVerify as $o => $p ) {
  3035. $staffID = explode ( '_', $p );
  3036. $staffInfo = $staff->getOne ( array (
  3037. 'where' => 'sid=' . $staffID [0],
  3038. 'asArray' => true
  3039. ) );
  3040. // print_r($staffID);
  3041. $exp = array (
  3042. 0 => $staffInfo ['sid'],
  3043. 1 => $staffID [1],
  3044. 2 => $staffInfo ['avatar'],
  3045. 'date' => '',
  3046. 'date' => '',
  3047. 'opinion' => '',
  3048. 'status' => '',
  3049. 'rolename' => $rolename ['name']
  3050. );
  3051. array_push ( $roleArray, $exp );
  3052. }
  3053. $roleArrayCopy [$v [0]] = $roleArray;
  3054. // $verifyList[$k]['roleArray']=$roleArray;
  3055. }
  3056. $verifyList [$k] ['date'] = "";
  3057. $verifyList [$k] ['opinion'] = "";
  3058. $verifyList [$k] ['status'] = "";
  3059. if (empty ( $verifyStaff )) {
  3060. $verifyList [$k] ['date'] = "";
  3061. $verifyList [$k] ['opinion'] = "";
  3062. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3063. $verifyList [$k] ['status'] = 4;
  3064. $flag = false;
  3065. }
  3066. } else {
  3067. foreach ( $verifyStaff as $m => $u ) {
  3068. if ($v [0] == $m) {
  3069. $verifyList [$k] ['date'] = $u ['date'];
  3070. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3071. $verifyList [$k] ['status'] = $u ['status'];
  3072. $flag = false;
  3073. break;
  3074. }
  3075. }
  3076. $endStaffArray = end ( $verifyStaff );
  3077. if (isset ( $endStaffArray ['ROLE'] )) {
  3078. } else {
  3079. // $endKey=key($verifyStaff);
  3080. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3081. // $button=4;
  3082. // $verifyList[$k]['status']=4;
  3083. // }
  3084. }
  3085. }
  3086. }
  3087. $rolename ['name'] = '';
  3088. if (! empty ( $roleId )) {
  3089. Doo::loadModel ( 'role' );
  3090. $role = new role ();
  3091. $rolename = $role->getOne ( array (
  3092. 'where' => 'rid=' . $roleId,
  3093. 'asArray' => true
  3094. ) );
  3095. }
  3096. if (! empty ( $verifyStaff ))
  3097. $endStaffArray = end ( $verifyStaff );
  3098. $KOP = false;
  3099. foreach ( $roleArrayCopy as $P => $A ) {
  3100. foreach ( $A as $MKI => $AVL ) {
  3101. if (! empty ( $verifyStaff )) {
  3102. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3103. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3104. $button = 4;
  3105. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3106. }
  3107. foreach ( $verifyStaff as $m => $u ) {
  3108. $AVLFK = $AVL [0] . '_R';
  3109. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3110. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3111. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3112. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3113. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3114. break;
  3115. }
  3116. }
  3117. } else {
  3118. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3119. $button = 4;
  3120. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3121. }
  3122. }
  3123. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3124. $KOP = true;
  3125. }
  3126. }
  3127. foreach ( $roleArrayCopy as $k => $v ) {
  3128. foreach ( $verifyList as $m => $n ) {
  3129. if ($n [0] == $k) {
  3130. array_splice ( $verifyList, $m, 1, $v );
  3131. }
  3132. }
  3133. }
  3134. $receiptList [$key] ['verifyList'] = $verifyList;
  3135. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3136. 'where' => 'sid=' . $value ['staff'],
  3137. 'asArray' => true
  3138. ) );
  3139. $receiptList [$key] ['button'] = $button;
  3140. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3141. }
  3142. // print_r($receiptList);die;
  3143. $mothHtml = "";
  3144. for($i = 1; $i <= 12; $i ++) {
  3145. if ($moth == $i)
  3146. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3147. else
  3148. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3149. }
  3150. $dateHtml = "";
  3151. $now = date ( "Y" );
  3152. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3153. if ($YEARD <= $now) {
  3154. $dateHtml .= '<option ';
  3155. if ($year == $YEARD) {
  3156. $dateHtml .= 'selected ';
  3157. }
  3158. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3159. }
  3160. }
  3161. $data ['dateHtml'] = $dateHtml;
  3162. $data ['mothHtml'] = $mothHtml;
  3163. $data ['receiptList'] = $receiptList;
  3164. $data ['memu'] = "receipt";
  3165. $data ['staff'] = $this->staff;
  3166. $data ['receiptMemu'] = 'expenses';
  3167. $data ['verifyId'] = $this->verifyId;
  3168. $data ['executeId'] = $this->executeId;
  3169. $data ['item'] = $item;
  3170. $data ['year'] = $year;
  3171. $this->render ( "/admin/expenses", $data );
  3172. }
  3173. function expensesCollect() {
  3174. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3175. Doo::loadModel ( 'receipt' );
  3176. $receipt = new receipt ();
  3177. Doo::loadModel ( 'L_category' );
  3178. $Lcategory = new L_category ();
  3179. Doo::loadModel ( 'verify' );
  3180. Doo::loadModel ( 'statistics' );
  3181. $statistics = new statistics ();
  3182. $verify = new verify ();
  3183. Doo::loadModel ( 'staff' );
  3184. $staff = new staff ();
  3185. Doo::loadModel ( 'loanReceipt' );
  3186. $loanReceipt = new loanReceipt ();
  3187. $receiptList = $receipt->find ( array (//去掉
  3188. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3189. 'desc' => 'rid',
  3190. 'asArray' => true
  3191. ) );
  3192. $loanList = $loanReceipt->find ( array (
  3193. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3194. 'desc' => 'rid',
  3195. 'asArray' => true
  3196. ) );
  3197. /*
  3198. * $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;
  3199. */
  3200. $data ['explanation'] = '';
  3201. if (! empty ( $loanList ))
  3202. $data ['explanation'] = $loanList [0] ['explanation'];
  3203. $Locate = 0;
  3204. $roleId = 0;
  3205. $button = 0;
  3206. foreach ( $receiptList as $key => $value ) {
  3207. $receiptList [$key] ['Locate'] = $Locate;
  3208. $Locate ++;
  3209. $receiptList [$key] ['reviseDetail'] = array ();
  3210. if (! empty ( $value ['reviseDetail'] ))
  3211. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3212. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3213. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3214. $categoryDetil = $Lcategory->getOne ( array (
  3215. 'where' => 'cid=' . $value ['cid'],
  3216. 'asArray' => true
  3217. ) );
  3218. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3219. // 检测编辑状态
  3220. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3221. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3222. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3223. else
  3224. $verifyList ['staff'] = $value ['verifyBreakup'];
  3225. } else
  3226. $verifyList = $verify->getOne ( array (
  3227. 'where' => 'vid=' . $value ['verify'],
  3228. 'asArray' => true
  3229. ) );
  3230. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3231. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3232. Doo::loadModel ( 'role' );
  3233. $role = new role ();
  3234. $flag = true;
  3235. $roleKey = 0;
  3236. $endStaffArray = array ();
  3237. $roleArrayCopy = array ();
  3238. foreach ( $verifyList as $k => $v ) {
  3239. // init verifyStaff
  3240. if ($v [1] == 'ROLE') {
  3241. if (! empty ( $verifyStaff )) {
  3242. $endStaffArray = end ( $verifyStaff );
  3243. // if ($v[0]==$endStaffArray['nextStaff']){
  3244. // $roleId=$v[0];
  3245. // }
  3246. }
  3247. $roleVerify = json_decode ( $v [3], true );
  3248. $roleKey = $k;
  3249. $roleArray = array ();
  3250. $rolename = $role->getOne ( array (
  3251. 'where' => 'rid=' . $v [0],
  3252. 'asArray' => true
  3253. ) );
  3254. foreach ( $roleVerify as $o => $p ) {
  3255. $staffID = explode ( '_', $p );
  3256. $staffInfo = $staff->getOne ( array (
  3257. 'where' => 'sid=' . $staffID [0],
  3258. 'asArray' => true
  3259. ) );
  3260. // print_r($staffID);
  3261. $exp = array (
  3262. 0 => $staffInfo ['sid'],
  3263. 1 => $staffID [1],
  3264. 2 => $staffInfo ['avatar'],
  3265. 'date' => '',
  3266. 'date' => '',
  3267. 'opinion' => '',
  3268. 'status' => '',
  3269. 'rolename' => $rolename ['name']
  3270. );
  3271. array_push ( $roleArray, $exp );
  3272. }
  3273. $roleArrayCopy [$v [0]] = $roleArray;
  3274. // $verifyList[$k]['roleArray']=$roleArray;
  3275. }
  3276. $verifyList [$k] ['date'] = "";
  3277. $verifyList [$k] ['opinion'] = "";
  3278. $verifyList [$k] ['status'] = "";
  3279. if (empty ( $verifyStaff )) {
  3280. $verifyList [$k] ['date'] = "";
  3281. $verifyList [$k] ['opinion'] = "";
  3282. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3283. $verifyList [$k] ['status'] = 4;
  3284. $flag = false;
  3285. }
  3286. } else {
  3287. foreach ( $verifyStaff as $m => $u ) {
  3288. if ($v [0] == $m) {
  3289. $verifyList [$k] ['date'] = $u ['date'];
  3290. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3291. $verifyList [$k] ['status'] = $u ['status'];
  3292. $flag = false;
  3293. break;
  3294. }
  3295. }
  3296. $endStaffArray = end ( $verifyStaff );
  3297. if (isset ( $endStaffArray ['ROLE'] )) {
  3298. } else {
  3299. // $endKey=key($verifyStaff);
  3300. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3301. // $button=4;
  3302. // $verifyList[$k]['status']=4;
  3303. // }
  3304. }
  3305. }
  3306. }
  3307. $rolename ['name'] = '';
  3308. if (! empty ( $roleId )) {
  3309. Doo::loadModel ( 'role' );
  3310. $role = new role ();
  3311. $rolename = $role->getOne ( array (
  3312. 'where' => 'rid=' . $roleId,
  3313. 'asArray' => true
  3314. ) );
  3315. }
  3316. if (! empty ( $verifyStaff ))
  3317. $endStaffArray = end ( $verifyStaff );
  3318. $KOP = false;
  3319. foreach ( $roleArrayCopy as $P => $A ) {
  3320. foreach ( $A as $MKI => $AVL ) {
  3321. if (! empty ( $verifyStaff )) {
  3322. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3323. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3324. $button = 4;
  3325. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3326. }
  3327. foreach ( $verifyStaff as $m => $u ) {
  3328. $AVLFK = $AVL [0] . '_R';
  3329. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3330. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3331. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3332. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3333. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3334. break;
  3335. }
  3336. }
  3337. } else {
  3338. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3339. $button = 4;
  3340. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3341. }
  3342. }
  3343. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3344. $KOP = true;
  3345. }
  3346. }
  3347. foreach ( $roleArrayCopy as $k => $v ) {
  3348. foreach ( $verifyList as $m => $n ) {
  3349. if ($n [0] == $k) {
  3350. array_splice ( $verifyList, $m, 1, $v );
  3351. }
  3352. }
  3353. }
  3354. // 费用执行人相关数据
  3355. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3356. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3357. foreach ( $executeCopy as $k => $v ) {
  3358. $executeCopy [$k] ['date'] = '';
  3359. $executeCopy [$k] ['opinion'] = '';
  3360. $executeCopy [$k] ['status'] = '';
  3361. if (! empty ( $executeStaff ))
  3362. foreach ( $executeStaff as $m => $u ) {
  3363. if ($v [0] == $m) {
  3364. $executeCopy [$k] ['date'] = $u ['date'];
  3365. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3366. $executeCopy [$k] ['status'] = $u ['status'];
  3367. break;
  3368. }
  3369. }
  3370. }
  3371. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3372. $receiptList [$key] ['verifyList'] = $verifyList;
  3373. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3374. 'where' => 'sid=' . $value ['staff'],
  3375. 'asArray' => true
  3376. ) );
  3377. $receiptList [$key] ['button'] = $button;
  3378. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3379. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3380. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3381. $receiptList [$key] ['relust'] = $relust;
  3382. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3383. }
  3384. Doo::loadModel ( 'enclosur' );
  3385. $enclosur = new enclosur ();
  3386. $enclosurList = $enclosur->find ( array (
  3387. 'where' => 'rid=' . $rid,
  3388. 'asArray' => true
  3389. ) );
  3390. $enclosurHtml = '';
  3391. foreach ( $enclosurList as $value ) {
  3392. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3393. }
  3394. $data ['enclosurHtml'] = $enclosurHtml;
  3395. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3396. $data ['receiptList'] = $receiptList;
  3397. $data ['memu'] = "receipt";
  3398. $data ['staff'] = $this->staff;
  3399. $data ['receiptMemu'] = 'expenses';
  3400. $data ['verifyId'] = $this->verifyId;
  3401. $data ['executeId'] = $this->executeId;
  3402. $this->render ( "/admin/expensesCollect", $data );
  3403. }
  3404. function approvalExpenses() {
  3405. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3406. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3407. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3408. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3409. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3410. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3411. // echo $rdate;
  3412. if (empty ( $status ))
  3413. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3414. $page_size = 8;
  3415. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3416. $vidList = array ();
  3417. $button = 0;
  3418. Doo::loadModel ( 'verify' );
  3419. $verify = new verify ();
  3420. Doo::loadModel ( 'receipt' );
  3421. $receipt = new receipt ();
  3422. Doo::loadModel ( 'staff' );
  3423. $staff = new staff ();
  3424. Doo::loadModel ( 'L_category' );
  3425. $Lcategory = new L_category ();
  3426. // user verify ID
  3427. $verifyDetail = $verify->find ( array (
  3428. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3429. 'asArray' => true
  3430. ) );
  3431. foreach ( $verifyDetail as $key => $value ) {
  3432. array_push ( $vidList, $value ['vid'] );
  3433. }
  3434. $vid = implode ( ",", $vidList );
  3435. if (empty ( $verifyDetail ))
  3436. $vid = 0;
  3437. // if ($status==0)
  3438. // $dateCondition="";
  3439. // else
  3440. $dateCondition = " ";
  3441. // if (! empty ( $month ))
  3442. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3443. if ($status == 'done' || $status == 'termination') {
  3444. if (! empty ( $year )) {
  3445. $dateCondition = " and Year(pastDate) =" . $year;
  3446. if (! empty ( $month ))
  3447. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3448. }
  3449. } elseif ($status == 'finish') {
  3450. if (! empty ( $year )) {
  3451. $dateCondition = " and Year(pastDate) =" . $year;
  3452. if (! empty ( $month ))
  3453. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3454. }
  3455. }
  3456. // date ( 'Y-m' )
  3457. // if (! empty ( $rdate ) && $status == 'done')
  3458. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3459. // elseif (! empty ( $rdate ))
  3460. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3461. $categoryList = $Lcategory->find ( array (
  3462. 'asArray' => true
  3463. ) );
  3464. $staffList = $staff->find ( array (
  3465. 'where' => 'cid=' . $cid,
  3466. 'asArray' => true
  3467. ) );
  3468. $cateCondition = "";
  3469. $staffCondition = "";
  3470. $approvalCondition = "";
  3471. if (! empty ( $cid )) {
  3472. $cateCondition = ' and cid=' . $cid;
  3473. }
  3474. if (! empty ( $sid )) {
  3475. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3476. $cateCondition = "";
  3477. }
  3478. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3479. if ($status == 'pendApproval') {
  3480. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3481. }
  3482. if ($status == 'ongoing') {
  3483. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3484. }
  3485. if ($status == 'done') {
  3486. $approvalCondition = ' and (status=8 or status=9 ) ';
  3487. }
  3488. if ($status == 'termination') {
  3489. $approvalCondition = " and status=3";
  3490. }
  3491. if ($status == 'finish') {
  3492. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3493. }
  3494. $pageinfo ['page'] = array (
  3495. 'previous' => ''
  3496. );
  3497. if(!empty($receiptOrder)){
  3498. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3499. $receiptList = $receipt->find ( array ( // $dateCondition
  3500. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3501. 'desc' => 'rid',
  3502. 'asArray' => true
  3503. ) );
  3504. }else{
  3505. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3506. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3507. $receiptList = $receipt->find ( array ( // $dateCondition.
  3508. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3509. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3510. 'desc' => 'rid',
  3511. 'asArray' => true
  3512. ) );
  3513. } else {
  3514. $receiptList = $receipt->find ( array ( // $dateCondition
  3515. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3516. 'desc' => 'rid',
  3517. 'asArray' => true
  3518. ) );
  3519. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3520. }
  3521. }
  3522. $rLRes = $receipt->find ( array (
  3523. '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 . ')',
  3524. 'desc' => 'rid',
  3525. 'asArray' => true
  3526. ) );
  3527. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3528. // print_r($receiptList);
  3529. Doo::loadClass ( 'XDeode' );
  3530. $XDeode = new XDeode ( 7 );
  3531. $Locate = 0;
  3532. $reportList = $reportCateList = array ();
  3533. foreach ( $receiptList as $key => $value ) {
  3534. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3535. $receiptList [$key] ['Locate'] = $Locate;
  3536. $Locate ++;
  3537. $receiptList [$key] ['reviseDetail'] = array ();
  3538. if (! empty ( $value ['reviseDetail'] ))
  3539. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3540. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3541. $categoryDetil = $Lcategory->getOne ( array (
  3542. 'where' => 'cid=' . $value ['cid'],
  3543. 'asArray' => true
  3544. ) );
  3545. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3546. $verifyList = $verify->getOne ( array (
  3547. 'where' => 'vid=' . $value ['verify'],
  3548. 'asArray' => true
  3549. ) );
  3550. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3551. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3552. foreach ( $verifyList as $k => $v ) {
  3553. // init verifyStaff
  3554. $verifyList [$k] ['date'] = "";
  3555. $verifyList [$k] ['opinion'] = "";
  3556. $verifyList [$k] ['status'] = "";
  3557. if (empty ( $verifyStaff )) {
  3558. $verifyList [$k] ['date'] = "";
  3559. $verifyList [$k] ['opinion'] = "";
  3560. if ($v [0] == $this->staff [0] ['sid']) {
  3561. $verifyList [$k] ['status'] = 4;
  3562. $button = 4;
  3563. }
  3564. } else {
  3565. $flag = true;
  3566. foreach ( $verifyStaff as $m => $u ) {
  3567. if ($v [0] == $m) {
  3568. $verifyList [$k] ['date'] = $u ['date'];
  3569. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3570. $verifyList [$k] ['status'] = $u ['status'];
  3571. $flag = false;
  3572. break;
  3573. }
  3574. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3575. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3576. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3577. }
  3578. if ($flag) { // 检测可编辑
  3579. if ($v [0] == $this->staff [0] ['sid']) {
  3580. $verifyList [$k] ['status'] = 4;
  3581. $button = 4;
  3582. }
  3583. }
  3584. }
  3585. }
  3586. $receiptList [$key] ['verifyList'] = $verifyList;
  3587. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3588. 'where' => 'sid=' . $value ['staff'],
  3589. 'asArray' => true
  3590. ) );
  3591. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3592. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3593. $receiptList [$key] ['button'] = $button;
  3594. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3595. //获得培训班结算RID 借款费用--已经锁定
  3596. if($value['status']==10){
  3597. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  3598. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  3599. }
  3600. }
  3601. $reportList = array_unique ( $reportList );
  3602. $reportHtml = '';
  3603. foreach ( $reportList as $key => $value ) {
  3604. $v = explode ( "-", $value );
  3605. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3606. }
  3607. // print_r($reportList)
  3608. $data ['reportHtml'] = $reportHtml;
  3609. $reportCateList = array_unique ( $reportCateList );
  3610. $reportCateHtml = '';
  3611. foreach ( $reportCateList as $key => $value ) {
  3612. $v = explode ( "-", $value );
  3613. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3614. }
  3615. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3616. $data ['reportCateHtml'] = $reportCateHtml;
  3617. // print_r($receiptList);die;
  3618. // $data['verifyDetail']=$verifyDetail;
  3619. $mothHtml = "";
  3620. for($i = 1; $i <= 12; $i ++) {
  3621. if ($month == $i)
  3622. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3623. else
  3624. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3625. }
  3626. $data ['mothHtml'] = $mothHtml;
  3627. $dateHtml = "";
  3628. $now = date ( "Y" );
  3629. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3630. if ($YEARD <= $now) {
  3631. $dateHtml .= '<option ';
  3632. if ($year == $YEARD) {
  3633. $dateHtml .= 'selected ';
  3634. }
  3635. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3636. }
  3637. }
  3638. $data ['dateHtml'] = $dateHtml;
  3639. $data ['page'] = $pageinfo;
  3640. $data ['receiptList'] = $receiptList;
  3641. $data ['receiptApprovalCount'] = count ( $rLRes );
  3642. $data ['status'] = $status;
  3643. $data ['year'] = $year;
  3644. $data ['month'] = $month;
  3645. $data ['categoryList'] = $categoryList;
  3646. $data ['staffList'] = $staffList;
  3647. $data ['cid'] = $cid;
  3648. $data ['sid'] = $sid;
  3649. // print_r($receiptList);
  3650. $data['receiptOrder']=$receiptOrder;
  3651. $data ['memu'] = "receipt";
  3652. $data ['staff'] = $this->staff;
  3653. $data ['receiptMemu'] = 'approvalExpenses';
  3654. $data ['verifyId'] = $this->verifyId;
  3655. $data ['executeId'] = $this->executeId;
  3656. $this->render ( "/admin/approvalExpenses", $data );
  3657. }
  3658. function expensesDoc() {
  3659. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3660. Doo::loadClass ( 'XDeode' );
  3661. $XDeode = new XDeode ( 5 );
  3662. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3663. $rid = $XDeode->decode ( $rid );
  3664. if (! is_numeric ( $rid ))
  3665. die ( 'illegal request' );
  3666. Doo::loadModel ( 'receipt' );
  3667. $receipt = new receipt ();
  3668. Doo::loadModel ( 'L_category' );
  3669. $Lcategory = new L_category ();
  3670. Doo::loadModel ( 'verify' );
  3671. Doo::loadModel ( 'statistics' );
  3672. $statistics = new statistics ();
  3673. $verify = new verify ();
  3674. Doo::loadModel ( 'staff' );
  3675. $staff = new staff ();
  3676. Doo::loadModel ( 'loanReceipt' );
  3677. $loanReceipt = new loanReceipt ();
  3678. $receiptList = $receipt->find ( array (
  3679. 'where' => ' rid=' . $rid,
  3680. 'desc' => 'rid',
  3681. 'asArray' => true
  3682. ) );
  3683. $loanList = array ();
  3684. if (! empty ( $receiptList ))
  3685. $loanList = $loanReceipt->find ( array (
  3686. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3687. 'desc' => 'rid',
  3688. 'asArray' => true
  3689. ) );
  3690. $Locate = 0;
  3691. $roleId = 0;
  3692. $button = 0;
  3693. foreach ( $loanList as $key => $value ) {
  3694. $loanList [$key] ['Locate'] = $Locate;
  3695. $Locate ++;
  3696. $loanList [$key] ['reviseDetail'] = array ();
  3697. if (! empty ( $value ['reviseDetail'] ))
  3698. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3699. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3700. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3701. $categoryDetil = $Lcategory->getOne ( array (
  3702. 'where' => 'cid=' . $value ['cid'],
  3703. 'asArray' => true
  3704. ) );
  3705. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3706. // 检测编辑状态
  3707. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3708. $verifyList ['staff'] = $value ['verifyBreakup'];
  3709. else
  3710. $verifyList = $verify->getOne ( array (
  3711. 'where' => 'vid=' . $value ['verify'],
  3712. 'asArray' => true
  3713. ) );
  3714. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3715. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3716. Doo::loadModel ( 'role' );
  3717. $role = new role ();
  3718. $flag = true;
  3719. $roleKey = 0;
  3720. $endStaffArray = array ();
  3721. $roleArrayCopy = array ();
  3722. foreach ( $verifyList as $k => $v ) {
  3723. // init verifyStaff
  3724. if ($v [1] == 'ROLE') {
  3725. if (! empty ( $verifyStaff )) {
  3726. $endStaffArray = end ( $verifyStaff );
  3727. // if ($v[0]==$endStaffArray['nextStaff']){
  3728. // $roleId=$v[0];
  3729. // }
  3730. }
  3731. $roleVerify = json_decode ( $v [3], true );
  3732. $roleKey = $k;
  3733. $roleArray = array ();
  3734. $rolename = $role->getOne ( array (
  3735. 'where' => 'rid=' . $v [0],
  3736. 'asArray' => true
  3737. ) );
  3738. foreach ( $roleVerify as $o => $p ) {
  3739. $staffID = explode ( '_', $p );
  3740. $staffInfo = $staff->getOne ( array (
  3741. 'where' => 'sid=' . $staffID [0],
  3742. 'asArray' => true
  3743. ) );
  3744. // print_r($staffID);
  3745. $exp = array (
  3746. 0 => $staffInfo ['sid'],
  3747. 1 => $staffID [1],
  3748. 2 => $staffInfo ['avatar'],
  3749. 'date' => '',
  3750. 'date' => '',
  3751. 'opinion' => '',
  3752. 'status' => '',
  3753. 'rolename' => $rolename ['name']
  3754. );
  3755. array_push ( $roleArray, $exp );
  3756. }
  3757. $roleArrayCopy [$v [0]] = $roleArray;
  3758. // $verifyList[$k]['roleArray']=$roleArray;
  3759. }
  3760. $verifyList [$k] ['date'] = "";
  3761. $verifyList [$k] ['opinion'] = "";
  3762. $verifyList [$k] ['status'] = "";
  3763. if (empty ( $verifyStaff )) {
  3764. $verifyList [$k] ['date'] = "";
  3765. $verifyList [$k] ['opinion'] = "";
  3766. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3767. $verifyList [$k] ['status'] = 4;
  3768. $flag = false;
  3769. }
  3770. } else {
  3771. foreach ( $verifyStaff as $m => $u ) {
  3772. if ($v [0] == $m) {
  3773. $verifyList [$k] ['date'] = $u ['date'];
  3774. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3775. $verifyList [$k] ['status'] = $u ['status'];
  3776. $flag = false;
  3777. break;
  3778. }
  3779. }
  3780. $endStaffArray = end ( $verifyStaff );
  3781. if (isset ( $endStaffArray ['ROLE'] )) {
  3782. } else {
  3783. // $endKey=key($verifyStaff);
  3784. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3785. // $button=4;
  3786. // $verifyList[$k]['status']=4;
  3787. // }
  3788. }
  3789. }
  3790. }
  3791. $rolename ['name'] = '';
  3792. if (! empty ( $roleId )) {
  3793. Doo::loadModel ( 'role' );
  3794. $role = new role ();
  3795. $rolename = $role->getOne ( array (
  3796. 'where' => 'rid=' . $roleId,
  3797. 'asArray' => true
  3798. ) );
  3799. }
  3800. if (! empty ( $verifyStaff ))
  3801. $endStaffArray = end ( $verifyStaff );
  3802. $KOP = false;
  3803. foreach ( $roleArrayCopy as $P => $A ) {
  3804. foreach ( $A as $MKI => $AVL ) {
  3805. if (! empty ( $verifyStaff )) {
  3806. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3807. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3808. $button = 4;
  3809. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3810. }
  3811. foreach ( $verifyStaff as $m => $u ) {
  3812. $AVLFK = $AVL [0] . '_R';
  3813. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3814. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3815. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3816. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3817. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3818. break;
  3819. }
  3820. }
  3821. } else {
  3822. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3823. $button = 4;
  3824. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3825. }
  3826. }
  3827. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3828. $KOP = true;
  3829. }
  3830. }
  3831. foreach ( $roleArrayCopy as $k => $v ) {
  3832. foreach ( $verifyList as $m => $n ) {
  3833. if ($n [0] == $k) {
  3834. array_splice ( $verifyList, $m, 1, $v );
  3835. }
  3836. }
  3837. }
  3838. $loanList [$key] ['verifyList'] = $verifyList;
  3839. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3840. 'where' => 'sid=' . $value ['staff'],
  3841. 'asArray' => true
  3842. ) );
  3843. $loanList [$key] ['button'] = $button;
  3844. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3845. }
  3846. $data ['loanList'] = $loanList;
  3847. //print_r($loanList);
  3848. $Locate = 0;
  3849. $roleId = 0;
  3850. $button = 0;
  3851. foreach ( $receiptList as $key => $value ) {
  3852. $receiptList [$key] ['Locate'] = $Locate;
  3853. $Locate ++;
  3854. $receiptList [$key] ['reviseDetail'] = array ();
  3855. if (! empty ( $value ['reviseDetail'] ))
  3856. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3857. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3858. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3859. $categoryDetil = $Lcategory->getOne ( array (
  3860. 'where' => 'cid=' . $value ['cid'],
  3861. 'asArray' => true
  3862. ) );
  3863. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3864. // 检测编辑状态
  3865. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3866. $verifyList ['staff'] = $value ['verifyBreakup'];
  3867. } else
  3868. $verifyList = $verify->getOne ( array (
  3869. 'where' => 'vid=' . $value ['verify'],
  3870. 'asArray' => true
  3871. ) );
  3872. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3873. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3874. Doo::loadModel ( 'role' );
  3875. $role = new role ();
  3876. if ($verifyList == NULL)
  3877. $verifyList = array ();
  3878. $flag = true;
  3879. $roleKey = 0;
  3880. $endStaffArray = array ();
  3881. $roleArrayCopy = array ();
  3882. foreach ( $verifyList as $k => $v ) {
  3883. // init verifyStaff
  3884. if ($v [1] == 'ROLE') {
  3885. if (! empty ( $verifyStaff )) {
  3886. $endStaffArray = end ( $verifyStaff );
  3887. // if ($v[0]==$endStaffArray['nextStaff']){
  3888. // $roleId=$v[0];
  3889. // }
  3890. }
  3891. $roleVerify = json_decode ( $v [3], true );
  3892. $roleKey = $k;
  3893. $roleArray = array ();
  3894. $rolename = $role->getOne ( array (
  3895. 'where' => 'rid=' . $v [0],
  3896. 'asArray' => true
  3897. ) );
  3898. foreach ( $roleVerify as $o => $p ) {
  3899. $staffID = explode ( '_', $p );
  3900. $staffInfo = $staff->getOne ( array (
  3901. 'where' => 'sid=' . $staffID [0],
  3902. 'asArray' => true
  3903. ) );
  3904. // print_r($staffID);
  3905. $exp = array (
  3906. 0 => $staffInfo ['sid'],
  3907. 1 => $staffID [1],
  3908. 2 => $staffInfo ['avatar'],
  3909. 'date' => '',
  3910. 'date' => '',
  3911. 'opinion' => '',
  3912. 'status' => '',
  3913. 'rolename' => $rolename ['name']
  3914. );
  3915. array_push ( $roleArray, $exp );
  3916. }
  3917. $roleArrayCopy [$v [0]] = $roleArray;
  3918. // $verifyList[$k]['roleArray']=$roleArray;
  3919. }
  3920. $verifyList [$k] ['date'] = "";
  3921. $verifyList [$k] ['opinion'] = "";
  3922. $verifyList [$k] ['status'] = "";
  3923. if (empty ( $verifyStaff )) {
  3924. $verifyList [$k] ['date'] = "";
  3925. $verifyList [$k] ['opinion'] = "";
  3926. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3927. $verifyList [$k] ['status'] = 4;
  3928. $flag = false;
  3929. }
  3930. } else {
  3931. foreach ( $verifyStaff as $m => $u ) {
  3932. if ($v [0] == $m) {
  3933. $verifyList [$k] ['date'] = $u ['date'];
  3934. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3935. $verifyList [$k] ['status'] = $u ['status'];
  3936. $flag = false;
  3937. break;
  3938. }
  3939. }
  3940. $endStaffArray = end ( $verifyStaff );
  3941. if (isset ( $endStaffArray ['ROLE'] )) {
  3942. } else {
  3943. // $endKey=key($verifyStaff);
  3944. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3945. // $button=4;
  3946. // $verifyList[$k]['status']=4;
  3947. // }
  3948. }
  3949. }
  3950. }
  3951. $FC = @$rolename ['name'];
  3952. $rolename ['name'] = '';
  3953. if (! empty ( $roleId )) {
  3954. Doo::loadModel ( 'role' );
  3955. $role = new role ();
  3956. $rolename = $role->getOne ( array (
  3957. 'where' => 'rid=' . $roleId,
  3958. 'asArray' => true
  3959. ) );
  3960. }
  3961. if (! empty ( $verifyStaff ))
  3962. $endStaffArray = end ( $verifyStaff );
  3963. $KOP = false;
  3964. foreach ( $roleArrayCopy as $P => $A ) {
  3965. foreach ( $A as $MKI => $AVL ) {
  3966. if (! empty ( $verifyStaff )) {
  3967. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3968. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3969. $button = 4;
  3970. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3971. }
  3972. foreach ( $verifyStaff as $m => $u ) {
  3973. $AVLFK = $AVL [0] . '_R';
  3974. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3975. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3976. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3977. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3978. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3979. break;
  3980. }
  3981. }
  3982. } else {
  3983. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3984. $button = 4;
  3985. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3986. }
  3987. }
  3988. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3989. $KOP = true;
  3990. }
  3991. }
  3992. foreach ( $roleArrayCopy as $k => $v ) {
  3993. foreach ( $verifyList as $m => $n ) {
  3994. if ($n [0] == $k) {
  3995. array_splice ( $verifyList, $m, 1, $v );
  3996. }
  3997. }
  3998. }
  3999. // 费用执行人相关数据
  4000. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4001. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4002. foreach ( $executeCopy as $k => $v ) {
  4003. $executeCopy [$k] ['date'] = '';
  4004. $executeCopy [$k] ['opinion'] = '';
  4005. $executeCopy [$k] ['status'] = '';
  4006. if (! empty ( $executeStaff ))
  4007. foreach ( $executeStaff as $m => $u ) {
  4008. if ($v [0] == $m) {
  4009. $executeCopy [$k] ['date'] = $u ['date'];
  4010. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4011. $executeCopy [$k] ['status'] = $u ['status'];
  4012. break;
  4013. }
  4014. }
  4015. }
  4016. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4017. // print_r($verifyList);
  4018. $receiptList [$key] ['verifyList'] = $verifyList;
  4019. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4020. 'where' => 'sid=' . $value ['staff'],
  4021. 'asArray' => true
  4022. ) );
  4023. $receiptList [$key] ['button'] = $button;
  4024. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4025. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4026. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4027. $receiptList [$key] ['relust'] = $relust;
  4028. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4029. }
  4030. // print_r($receiptList);
  4031. // 获取审批日志
  4032. Doo::loadModel ( 'receiptLog' );
  4033. $receiptLog = new receiptLog ();
  4034. $rlList = array ();
  4035. $rlInfo = $receiptLog->getOne ( array (
  4036. 'where' => 'rid=' . $rid . ' and status=4',
  4037. 'asArray' => true
  4038. ) );
  4039. // $tijdate = $receiptLog->getOne ( array (
  4040. // 'where' => 'rid=' . $rid . ' and status=2',
  4041. // 'asc' => 'rlid',
  4042. // 'asArray' => true
  4043. // ) );
  4044. if (! empty ( $rlInfo )) {
  4045. $rlList = $receiptLog->find ( array (
  4046. 'where' => 'rid=' . $rid,
  4047. 'asc' => 'rlid',
  4048. 'asArray' => true
  4049. ) );
  4050. }
  4051. $RN=array();
  4052. if (!empty( $rolename ['staff'])){
  4053. $RN = @json_decode ( $rolename ['staff'] );
  4054. }
  4055. //
  4056. foreach ( $rlList as $key => $value ) {
  4057. $rlList [$key] ['rolename'] = '';
  4058. foreach ( $RN as $k => $v ) {
  4059. $id = explode ( "_", $v );
  4060. if ($id [0] == $value ['uid']) {
  4061. $rlList [$key] ['rolename'] = $FC;
  4062. break;
  4063. }
  4064. }
  4065. }
  4066. Doo::loadModel ( 'enclosur' );
  4067. $enclosur = new enclosur ();
  4068. $enclosurList = $enclosur->find ( array (
  4069. 'where' => 'rid=' . $rid,
  4070. 'asArray' => true
  4071. ) );
  4072. $enclosurHtml = '';
  4073. foreach ( $enclosurList as $value ) {
  4074. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4075. }
  4076. $data ['enclosurHtml'] = $enclosurHtml;
  4077. $receiptList [0] ['rlList'] = $rlList;
  4078. $data ['receiptList'] = $receiptList;
  4079. // print_r($receiptList);
  4080. $data ['memu'] = "receipt";
  4081. $data ['staff'] = $this->staff;
  4082. $data ['receiptMemu'] = 'approvalExpenses';
  4083. $data ['verifyId'] = $this->verifyId;
  4084. $data ['executeId'] = $this->executeId;
  4085. $this->render ( "/admin/expensesDoc", $data );
  4086. }
  4087. function expensesEdi() {
  4088. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4089. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4090. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4091. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4092. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4093. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4094. if (empty ( $status ))
  4095. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4096. $vidList = array ();
  4097. $button = 0;
  4098. Doo::loadModel ( 'verify' );
  4099. Doo::loadModel ( 'receipt' );
  4100. Doo::loadModel ( 'staff' );
  4101. $staff = new staff ();
  4102. $receipt = new receipt ();
  4103. $verify = new verify ();
  4104. Doo::loadModel ( 'L_category' );
  4105. $Lcategory = new L_category ();
  4106. Doo::loadModel ( 'enclosur' );
  4107. $enclosur = new enclosur ();
  4108. // user verify ID
  4109. $verifyDetail = $verify->find ( array (
  4110. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4111. 'asArray' => true
  4112. ) );
  4113. foreach ( $verifyDetail as $key => $value ) {
  4114. array_push ( $vidList, $value ['vid'] );
  4115. }
  4116. $vid = implode ( ",", $vidList );
  4117. if (empty ( $verifyDetail ))
  4118. $vid = 0;
  4119. $categoryList = $Lcategory->find ( array (
  4120. 'asArray' => true
  4121. ) );
  4122. $staffList = $staff->find ( array (
  4123. 'where' => 'cid=' . $cid,
  4124. 'asArray' => true
  4125. ) );
  4126. $ap = "";
  4127. if ($status == 4) {
  4128. $ap = 4;
  4129. $status = 2;
  4130. }
  4131. // get Receipt By verifyID status 2
  4132. $receiptList = $receipt->find ( array (
  4133. 'where' => 'rid =' . $rid . ' and status=2',
  4134. 'desc' => 'rid',
  4135. 'asArray' => true
  4136. ) );
  4137. if (empty ( $receiptList )) {
  4138. die ( 'illegal request' );
  4139. }
  4140. $Locate = 0;
  4141. $roleId = 0;
  4142. if ($ap == 4)
  4143. $status = 4;
  4144. foreach ( $receiptList as $key => $value ) {
  4145. $receiptList [$key] ['Locate'] = $Locate;
  4146. $Locate ++;
  4147. $receiptList [$key] ['reviseDetail'] = array ();
  4148. if (! empty ( $value ['reviseDetail'] ))
  4149. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4150. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4151. $categoryDetil = $Lcategory->getOne ( array (
  4152. 'where' => 'cid=' . $value ['cid'],
  4153. 'asArray' => true
  4154. ) );
  4155. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4156. // 检测编辑状态
  4157. $verifyList = $verify->getOne ( array (
  4158. 'where' => 'vid=' . $value ['verify'],
  4159. 'asArray' => true
  4160. ) );
  4161. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4162. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4163. Doo::loadModel ( 'role' );
  4164. $role = new role ();
  4165. // print_r($verifyList);
  4166. $flag = true;
  4167. $roleKey = 0;
  4168. $endStaffArray = array ();
  4169. $roleArrayCopy = array ();
  4170. foreach ( $verifyList as $k => $v ) {
  4171. // init verifyStaff
  4172. if ($v [1] == 'ROLE') {
  4173. if (! empty ( $verifyStaff )) {
  4174. $endStaffArray = end ( $verifyStaff );
  4175. if ($v [0] == $endStaffArray ['nextStaff']) {
  4176. $roleId = $v [0];
  4177. }
  4178. }
  4179. $roleVerify = json_decode ( $v [3], true );
  4180. $roleKey = $k;
  4181. $roleArray = array ();
  4182. $rolename = $role->getOne ( array (
  4183. 'where' => 'rid=' . $v [0],
  4184. 'asArray' => true
  4185. ) );
  4186. foreach ( $roleVerify as $o => $p ) {
  4187. $staffID = explode ( '_', $p );
  4188. $staffInfo = $staff->getOne ( array (
  4189. 'where' => 'sid=' . $staffID [0],
  4190. 'asArray' => true
  4191. ) );
  4192. // print_r($staffID);
  4193. $exp = array (
  4194. 0 => $staffInfo ['sid'],
  4195. 1 => $staffID [1],
  4196. 2 => $staffInfo ['avatar'],
  4197. 'date' => '',
  4198. 'date' => '',
  4199. 'opinion' => '',
  4200. 'status' => '',
  4201. 'rolename' => $rolename ['name']
  4202. );
  4203. array_push ( $roleArray, $exp );
  4204. }
  4205. $roleArrayCopy [$v [0]] = $roleArray;
  4206. // $verifyList[$k]['roleArray']=$roleArray;
  4207. }
  4208. // print_r($roleArray);
  4209. $verifyList [$k] ['date'] = "";
  4210. $verifyList [$k] ['opinion'] = "";
  4211. $verifyList [$k] ['status'] = "";
  4212. if (empty ( $verifyStaff )) {
  4213. $verifyList [$k] ['date'] = "";
  4214. $verifyList [$k] ['opinion'] = "";
  4215. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4216. $verifyList [$k] ['status'] = 4;
  4217. $button = 4;
  4218. $flag = false;
  4219. }
  4220. } else {
  4221. foreach ( $verifyStaff as $m => $u ) {
  4222. if ($v [0] == $m) {
  4223. $verifyList [$k] ['date'] = $u ['date'];
  4224. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4225. $verifyList [$k] ['status'] = $u ['status'];
  4226. $flag = false;
  4227. break;
  4228. }
  4229. }
  4230. $endStaffArray = end ( $verifyStaff );
  4231. if (isset ( $endStaffArray ['ROLE'] )) {
  4232. } else {
  4233. $endKey = key ( $verifyStaff );
  4234. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4235. $button = 4;
  4236. $verifyList [$k] ['status'] = 4;
  4237. }
  4238. }
  4239. }
  4240. }
  4241. $rolename ['name'] = '';
  4242. if (! empty ( $roleId )) {
  4243. Doo::loadModel ( 'role' );
  4244. $role = new role ();
  4245. $rolename = $role->getOne ( array (
  4246. 'where' => 'rid=' . $roleId,
  4247. 'asArray' => true
  4248. ) );
  4249. }
  4250. if (! empty ( $verifyStaff ))
  4251. $endStaffArray = end ( $verifyStaff );
  4252. $KOP = false;
  4253. foreach ( $roleArrayCopy as $P => $A ) {
  4254. foreach ( $A as $MKI => $AVL ) {
  4255. if (! empty ( $verifyStaff )) {
  4256. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4257. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4258. $button = 4;
  4259. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4260. }
  4261. foreach ( $verifyStaff as $m => $u ) {
  4262. $AVLFK = $AVL [0] . '_R';
  4263. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4264. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4265. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4266. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4267. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4268. break;
  4269. }
  4270. }
  4271. } else {
  4272. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4273. $button = 4;
  4274. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4275. }
  4276. }
  4277. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4278. $KOP = true;
  4279. }
  4280. }
  4281. // print_r($roleArrayCopy);
  4282. // echo $roleKey;
  4283. foreach ( $roleArrayCopy as $k => $v ) {
  4284. foreach ( $verifyList as $m => $n ) {
  4285. if ($n [0] == $k) {
  4286. array_splice ( $verifyList, $m, 1, $v );
  4287. }
  4288. }
  4289. }
  4290. $receiptList [$key] ['verifyList'] = $verifyList;
  4291. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4292. 'where' => 'sid=' . $value ['staff'],
  4293. 'asArray' => true
  4294. ) );
  4295. $receiptList [$key] ['button'] = $button;
  4296. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4297. }
  4298. // $data['verifyDetail']=$verifyDetail;
  4299. $mothHtml = "";
  4300. for($i = 1; $i <= 12; $i ++) {
  4301. if ($month == $i)
  4302. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4303. else
  4304. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4305. }
  4306. // 获取审批日志
  4307. Doo::loadModel ( 'receiptLog' );
  4308. $receiptLog = new receiptLog ();
  4309. $rlList = array ();
  4310. $rlInfo = $receiptLog->getOne ( array (
  4311. 'where' => 'rid=' . $rid . ' and status=4',
  4312. 'asArray' => true
  4313. ) );
  4314. $tijdate = $receiptLog->getOne ( array (
  4315. 'where' => 'rid=' . $rid . ' and status=2',
  4316. 'asc' => 'rlid',
  4317. 'asArray' => true
  4318. ) );
  4319. if (! empty ( $rlInfo )) {
  4320. $rlList = $receiptLog->find ( array (
  4321. 'where' => 'rid=' . $rid,
  4322. 'asc' => 'rlid',
  4323. 'asArray' => true
  4324. ) );
  4325. }
  4326. $receiptList [0] ['rlList'] = $rlList;
  4327. $enclosurList = $enclosur->find ( array (
  4328. 'where' => 'rid=' . $rid,
  4329. 'asArray' => true
  4330. ) );
  4331. $enclosurHtml = '';
  4332. foreach ( $enclosurList as $value ) {
  4333. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4334. }
  4335. // print_r($receiptList);
  4336. $data ['rid'] = $rid;
  4337. $data ['enclosurHtml'] = $enclosurHtml;
  4338. $data ['rolename'] = $rolename ['name'];
  4339. $data ['datetij'] = $tijdate ['date'];
  4340. $data ['mothHtml'] = $mothHtml;
  4341. $data ['receiptList'] = $receiptList;
  4342. $data ['receiptApprovalCount'] = count ( $receiptList );
  4343. $data ['status'] = $status;
  4344. $data ['year'] = $year;
  4345. $data ['categoryList'] = $categoryList;
  4346. $data ['staffList'] = $staffList;
  4347. $data ['cid'] = $cid;
  4348. $data ['sid'] = $sid;
  4349. $data ['ap'] = $ap;
  4350. $data ['memu'] = "receipt";
  4351. $data ['staff'] = $this->staff;
  4352. $data ['receiptMemu'] = 'approvalExpenses';
  4353. $data ['verifyId'] = $this->verifyId;
  4354. $data ['executeId'] = $this->executeId;
  4355. $this->render ( "/admin/expensesEdi", $data );
  4356. }
  4357. function expensesDefray() {
  4358. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4359. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4360. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4361. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4362. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4363. if (! empty ( $rid )) {
  4364. Doo::loadModel ( "verify" );
  4365. $verify = new verify ();
  4366. Doo::loadModel ( "receiptDetail" );
  4367. $receiptDetailObj = new receiptDetail ();
  4368. Doo::loadModel ( "itemStatistics" );
  4369. Doo::loadModel ( "statistics" );
  4370. $statistics = new statistics ();
  4371. $itemStatistics = new itemStatistics ();
  4372. Doo::loadModel ( "receipt" );
  4373. $receipt = new receipt ();
  4374. Doo::loadModel ( "loanReceipt" );
  4375. $loanReceipt = new loanReceipt ();
  4376. $receiptDetail = $receipt->getOne ( array (
  4377. 'where' => 'rid=' . $rid . ' and status=2 ',
  4378. 'asArray' => true
  4379. ) );
  4380. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4381. $nsflag = true;
  4382. foreach ( $nslist as $value ) {
  4383. if ($value == $this->staff ['0'] ['sid']) {
  4384. $nsflag = false;
  4385. break;
  4386. }
  4387. }
  4388. // print_r($nslist);die;
  4389. if (empty ( $receiptDetail ) || $nsflag)
  4390. return "/approvalExpenses/pendApproval";
  4391. $verifyDetail = $verify->getOne ( array (
  4392. 'where' => ' vid =' . $receiptDetail ['verify'],
  4393. 'asArray' => true
  4394. ) );
  4395. $verifyString = $verifyDetail ['staff'];
  4396. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4397. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4398. if (empty ( $opinion )) {
  4399. if ($status == 3)
  4400. $opinion = "终止";
  4401. else
  4402. $opinion = "同意支付";
  4403. }
  4404. $nowStaff = 0;
  4405. $nowStaffList = array ();
  4406. if (empty ( $verifyStaff )) {
  4407. // 还需加入是否已经进入角色审批
  4408. if ($verifyDetail [0] [1] == 'ROLE') {
  4409. // print_r($verifyDetail);echo "ddd";
  4410. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4411. foreach ( $vStaffString as $key => $value ) {
  4412. $staffK = explode ( "_", $value );
  4413. if ($staffK [0] != $this->staff [0] ['sid'])
  4414. array_push ( $nowStaffList, $staffK [0] );
  4415. }
  4416. // print_r($verifyDetail);
  4417. // die;
  4418. if (! empty ( $nowStaffList )) {
  4419. $nowStaff = implode ( ',', $nowStaffList );
  4420. $verifyStaff = array (
  4421. $this->staff [0] ['sid'] . "_R" => array (
  4422. 'date' => date ( 'Y-m-d' ),
  4423. 'opinion' => $opinion,
  4424. 'status' => $status,
  4425. 'nextStaff' => $verifyDetail [0] [0],
  4426. 'ROLE' => 1
  4427. )
  4428. );
  4429. } else {
  4430. $nowStaff = $verifyDetail [1] [0];
  4431. $verifyStaff = array (
  4432. $this->staff [0] ['sid'] . "_R" => array (
  4433. 'date' => date ( 'Y-m-d' ),
  4434. 'opinion' => $opinion,
  4435. 'status' => $status,
  4436. 'nextStaff' => $verifyDetail [1] [0]
  4437. )
  4438. );
  4439. }
  4440. } else {
  4441. if ($verifyDetail [1] [1] == 'ROLE') {
  4442. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4443. // echo "dd";
  4444. foreach ( $vStaffString as $key => $value ) {
  4445. $staffK = explode ( "_", $value );
  4446. array_push ( $nowStaffList, $staffK [0] );
  4447. }
  4448. $nowStaff = implode ( ',', $nowStaffList );
  4449. $verifyStaff = array (
  4450. $this->staff [0] ['sid'] => array (
  4451. 'date' => date ( 'Y-m-d' ),
  4452. 'opinion' => $opinion,
  4453. 'status' => $status,
  4454. 'nextStaff' => $verifyDetail [1] [0],
  4455. 'ROLE' => 1
  4456. )
  4457. );
  4458. } else {
  4459. $nowStaff = $verifyDetail [1] [0];
  4460. $verifyStaff = array (
  4461. $this->staff [0] ['sid'] => array (
  4462. 'date' => date ( 'Y-m-d' ),
  4463. 'opinion' => $opinion,
  4464. 'status' => $status,
  4465. 'nextStaff' => $verifyDetail [1] [0]
  4466. )
  4467. );
  4468. }
  4469. }
  4470. if ($status == 3)
  4471. $verifyStaff = array (
  4472. 'final' => $status,
  4473. $this->staff [0] ['sid'] => array (
  4474. 'date' => date ( 'Y-m-d' ),
  4475. 'opinion' => $opinion,
  4476. 'status' => $status
  4477. )
  4478. );
  4479. $vStaffString = json_encode ( $verifyStaff );
  4480. $receipt->nowStaff = $nowStaff;
  4481. $receipt->verifyStaff = $vStaffString;
  4482. $loanReceipt->nowStaff = $nowStaff;
  4483. $loanReceipt->verifyStaff = $vStaffString;
  4484. } else {
  4485. $VS = end ( $verifyStaff );
  4486. // 非角色审批
  4487. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4488. $nextStaff = 0;
  4489. $roleSTF = false;
  4490. foreach ( $verifyDetail as $key => $value ) {
  4491. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4492. if (isset ( $verifyDetail [$key + 1] )) {
  4493. $nextStaff = $verifyDetail [$key + 1] [0];
  4494. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4495. $roleSTF = true;
  4496. }
  4497. break;
  4498. }
  4499. }
  4500. if (! $roleSTF) {
  4501. $nowStaff = $nextStaff;
  4502. $verifyStaff [$this->staff [0] ['sid']] = array (
  4503. 'date' => date ( 'Y-m-d' ),
  4504. 'opinion' => $opinion,
  4505. 'status' => $status,
  4506. 'nextStaff' => $nextStaff
  4507. );
  4508. } else {
  4509. // 获取角色下的所有用户ID
  4510. $nowStaffList = array ();
  4511. foreach ( $verifyDetail as $vfk ) {
  4512. if ($vfk [1] == 'ROLE') {
  4513. $vStaffString = json_decode ( $vfk [3] );
  4514. foreach ( $vStaffString as $key => $value ) {
  4515. $staffK = explode ( "_", $value );
  4516. array_push ( $nowStaffList, $staffK [0] );
  4517. }
  4518. }
  4519. }
  4520. $nowStaff = implode ( ',', $nowStaffList );
  4521. $verifyStaff [$this->staff [0] ['sid']] = array (
  4522. 'date' => date ( 'Y-m-d' ),
  4523. 'opinion' => $opinion,
  4524. 'status' => $status,
  4525. 'nextStaff' => $nextStaff,
  4526. 'ROLE' => 0
  4527. );
  4528. }
  4529. if ($status == 3) {
  4530. $verifyStaff ['final'] = $status;
  4531. $verifyStaff [$this->staff [0] ['sid']] = array (
  4532. 'date' => date ( 'Y-m-d' ),
  4533. 'opinion' => $opinion,
  4534. 'status' => $status
  4535. );
  4536. }
  4537. $vStaffString = json_encode ( $verifyStaff );
  4538. $receipt->nowStaff = $nowStaff;
  4539. $receipt->verifyStaff = $vStaffString;
  4540. $loanReceipt->nowStaff = $nowStaff;
  4541. $loanReceipt->verifyStaff = $vStaffString;
  4542. }
  4543. // 角色审批
  4544. if (isset ( $VS ['ROLE'] )) {
  4545. // 找出角色人 当前审批角色组
  4546. $verifyJSStaff = array ();
  4547. $nowStaffList2 = array ();
  4548. foreach ( $verifyDetail as $key => $value ) {
  4549. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4550. $verifyJSStaff = json_decode ( $value [3] );
  4551. foreach ( $verifyJSStaff as $m ) {
  4552. $staffK = explode ( "_", $m );
  4553. array_push ( $nowStaffList2, $staffK [0] );
  4554. }
  4555. // print_r($nowStaffList2);
  4556. }
  4557. }
  4558. $RoleVerifyStaff = array ();
  4559. foreach ( $verifyStaff as $key => $value ) {
  4560. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4561. foreach ( $nowStaffList2 as $m ) {
  4562. if ($key == $m . "_R")
  4563. $RoleVerifyStaff [$key] = $value;
  4564. }
  4565. }
  4566. }
  4567. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4568. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4569. // 下一个审批人ID
  4570. $nextStaff = 0;
  4571. $falg = false;
  4572. foreach ( $verifyDetail as $key => $value ) {
  4573. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4574. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4575. $falg = true;
  4576. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4577. $nowStaffList = array ();
  4578. foreach ( $vStaffString as $v ) {
  4579. $staffK = explode ( "_", $v );
  4580. array_push ( $nowStaffList, $staffK [0] );
  4581. }
  4582. $nowStaff = implode ( ',', $nowStaffList );
  4583. $nextStaff = $verifyDetail [$key + 1] [0];
  4584. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4585. $nextStaff = $verifyDetail [$key + 1] [0];
  4586. $nowStaff = $nextStaff;
  4587. } else
  4588. $nowStaff = '';
  4589. break;
  4590. }
  4591. }
  4592. if ($falg)
  4593. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4594. 'date' => date ( 'Y-m-d' ),
  4595. 'opinion' => $opinion,
  4596. 'status' => $status,
  4597. 'nextStaff' => $nextStaff,
  4598. 'ROLE' => 1
  4599. );
  4600. else
  4601. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4602. 'date' => date ( 'Y-m-d' ),
  4603. 'opinion' => $opinion,
  4604. 'status' => $status,
  4605. 'nextStaff' => $nextStaff
  4606. );
  4607. // print_r($verifyStaff);
  4608. // echo $nowStaff;die;
  4609. } else { // 进入下一个角色或者审批人
  4610. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  4611. //
  4612. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4613. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4614. 'date' => date ( 'Y-m-d' ),
  4615. 'opinion' => $opinion,
  4616. 'status' => $status,
  4617. 'nextStaff' => $VS ['nextStaff'],
  4618. 'ROLE' => 1
  4619. );
  4620. // print_r($verifyStaff);
  4621. // die;
  4622. }
  4623. if ($status == 3) {
  4624. $verifyStaff ['final'] = $status;
  4625. $verifyStaff [$this->staff [0] ['sid']] = array (
  4626. 'date' => date ( 'Y-m-d' ),
  4627. 'opinion' => $opinion,
  4628. 'status' => $status
  4629. );
  4630. }
  4631. $vStaffString = json_encode ( $verifyStaff );
  4632. $receipt->verifyStaff = $vStaffString;
  4633. $receipt->nowStaff = $nowStaff;
  4634. $loanReceipt->nowStaff = $nowStaff;
  4635. $loanReceipt->verifyStaff = $vStaffString;
  4636. // die;
  4637. // }
  4638. // print_r($verifyStaff);
  4639. // die;
  4640. }
  4641. // print_r($verifyStaff);die;
  4642. }
  4643. // print_r($verifyDetail);
  4644. $roleKey = 0;
  4645. $roleId = 0;
  4646. $verifyDetailCopy = array ();
  4647. foreach ( $verifyDetail as $k => $v ) {
  4648. if ($v [1] == 'ROLE') {
  4649. $roleId = $v [0];
  4650. $roleVerify = json_decode ( $v [3], true );
  4651. $roleKey = $k;
  4652. $roleArray = array ();
  4653. foreach ( $roleVerify as $o => $p ) {
  4654. $staffID = explode ( '_', $p );
  4655. $exp = array (
  4656. 0 => $staffID [0],
  4657. 1 => $staffID [1]
  4658. );
  4659. array_push ( $roleArray, $exp );
  4660. }
  4661. $verifyDetailCopy [$v [0]] = $roleArray;
  4662. }
  4663. }
  4664. // print_r($verifyDetail);
  4665. foreach ( $verifyDetailCopy as $k => $v ) {
  4666. foreach ( $verifyDetail as $m => $n ) {
  4667. if ($n [0] == $k) {
  4668. array_splice ( $verifyDetail, $m, 1, $v );
  4669. }
  4670. }
  4671. }
  4672. // 审批日志
  4673. if (! isset ( $verifyStaff ['final'] )) {
  4674. Doo::loadModel ( "receiptLog" );
  4675. $receiptLog = new receiptLog ();
  4676. if (! empty ( $roleId )) {
  4677. Doo::loadModel ( "role" );
  4678. $role = new role ();
  4679. $roleInfo = $role->getOne ( array (
  4680. 'where' => 'rid=' . $roleId,
  4681. 'asArray' => true
  4682. ) );
  4683. $receiptLog->rolename = $roleInfo ['name'];
  4684. }
  4685. $receiptLog->username = $this->staff [0] ['username'];
  4686. $receiptLog->uid = $this->staff [0] ['sid'];
  4687. $receiptLog->date = date ( "Y-m-d" );
  4688. $receiptLog->opinion = $opinion;
  4689. $receiptLog->img = $this->staff [0] ['avatar'];
  4690. $receiptLog->status = 1;
  4691. $receiptLog->rid = $rid;
  4692. $receiptLog->insert ();
  4693. }
  4694. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4695. $receipt->status = 3;
  4696. $receipt->verifyBreakup = $verifyString;
  4697. $receiptDetailObj->status = 3;
  4698. $receiptDetailObj->update ( array (
  4699. 'where' => 'rid=' . $rid
  4700. ) );
  4701. // 微信企业号通知
  4702. $this->setWXMsg ( $rid, 3 );
  4703. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4704. $receipt->status = 6;
  4705. $receipt->pastDate = date ( "Y-m-d" );
  4706. $receipt->isBK = 1;
  4707. $loanReceipt->verifyBreakup = $verifyString;
  4708. $loanReceipt->status = 1;
  4709. $loanReceipt->pastDate = date ( "Y-m-d" );
  4710. //生成流水后 不更新汇款金额
  4711. Doo::loadModel ( 'wasteBook' );
  4712. $wasteBook = new wasteBook ();
  4713. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4714. if (empty($wbDetail)){
  4715. $loanReceipt->amount = $receiptDetail ['amount'];
  4716. }
  4717. $loanReceipt->update ( array (
  4718. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4719. ) );
  4720. // 微信企业号通知
  4721. $this->setWXMsg ( $rid, 1 );
  4722. }
  4723. $receipt->amount = $amount;
  4724. $receipt->update ( array (
  4725. 'where' => ' rid = ' . $rid
  4726. ) );
  4727. // 进入下一条审批费用新加需求
  4728. $vidList = array ();
  4729. $verifyDetail = $verify->find ( array (
  4730. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4731. 'asArray' => true
  4732. ) );
  4733. foreach ( $verifyDetail as $key => $value ) {
  4734. array_push ( $vidList, $value ['vid'] );
  4735. }
  4736. $vid = implode ( ",", $vidList );
  4737. if (empty ( $verifyDetail ))
  4738. $vid = 0;
  4739. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4740. $receipt = new receipt ();
  4741. $rd = $receipt->getOne ( array (
  4742. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4743. 'asc' => 'rid',
  4744. 'asArray' => true
  4745. ) );
  4746. if (empty ( $rd )) {
  4747. return '/approvalExpenses/pendApproval';
  4748. }
  4749. if ($rd ['Rtype'] == 1) {
  4750. if ($rd ['isBK'] == 1) {
  4751. return '/receiptburEdi/' . $rd ['rid'];
  4752. } else {
  4753. return '/expensesEdi/' . $rd ['rid'];
  4754. }
  4755. } elseif ($rd ['Rtype'] == 2) {
  4756. return '/remitApproval/' . $rd ['rid'];
  4757. } else {
  4758. return '/receiptburEdi/' . $rd ['rid'];
  4759. }
  4760. // return "/approvalExpenses/pendApproval";
  4761. }
  4762. }
  4763. function ajaxExamineExe() {
  4764. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4765. Doo::loadModel ( 'receipt' );
  4766. $receipt = new receipt ();
  4767. Doo::loadClass ( 'XDeode' );
  4768. $XDeode = new XDeode ( 5 );
  4769. if (! empty ( $rid )) {
  4770. $rLRes = $receipt->find ( array (
  4771. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4772. 'asArray' => true
  4773. ) );
  4774. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4775. echo json_encode ( array (
  4776. 'status' => 1,
  4777. 'receipt' => $rLRes [0]
  4778. ) );
  4779. die ();
  4780. }
  4781. echo json_encode ( array (
  4782. 'status' => 0,
  4783. 'receipt' => array ()
  4784. ) );
  4785. die ();
  4786. }
  4787. function implement() {
  4788. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4789. Doo::loadClass ( 'XDeode' );
  4790. $XDeode = new XDeode ( 5 );
  4791. Doo::loadModel ( 'receipt' );
  4792. $receipt = new receipt ();
  4793. Doo::loadModel ( 'L_category' );
  4794. $Lcategory = new L_category ();
  4795. Doo::loadModel ( 'verify' );
  4796. $verify = new verify ();
  4797. Doo::loadModel ( 'staff' );
  4798. $staff = new staff ();
  4799. Doo::loadModel ( "execute" );
  4800. $execute = new execute ();
  4801. $rid = $XDeode->decode ( $rid );
  4802. $receiptList = $receipt->find ( array (
  4803. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4804. 'desc' => 'rid',
  4805. 'asArray' => true
  4806. ) );
  4807. Doo::loadModel ( 'loanReceipt' );
  4808. $loanReceipt = new loanReceipt ();
  4809. // print_r($receiptList);
  4810. $loanList = array ();
  4811. if (! isset ( $receiptList ))
  4812. $loanList = $loanReceipt->find ( array (
  4813. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4814. 'desc' => 'rid',
  4815. 'asArray' => true
  4816. ) );
  4817. $Locate = 0;
  4818. $roleId = 0;
  4819. $button = 0;
  4820. foreach ( $loanList as $key => $value ) {
  4821. $loanList [$key] ['Locate'] = $Locate;
  4822. $Locate ++;
  4823. $loanList [$key] ['reviseDetail'] = array ();
  4824. if (! empty ( $value ['reviseDetail'] ))
  4825. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4826. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4827. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4828. $categoryDetil = $Lcategory->getOne ( array (
  4829. 'where' => 'cid=' . $value ['cid'],
  4830. 'asArray' => true
  4831. ) );
  4832. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4833. // 检测编辑状态
  4834. $verifyList = $verify->getOne ( array (
  4835. 'where' => 'vid=' . $value ['verify'],
  4836. 'asArray' => true
  4837. ) );
  4838. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4839. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4840. Doo::loadModel ( 'role' );
  4841. $role = new role ();
  4842. $flag = true;
  4843. $roleKey = 0;
  4844. $endStaffArray = array ();
  4845. $roleArrayCopy = array ();
  4846. foreach ( $verifyList as $k => $v ) {
  4847. // init verifyStaff
  4848. if ($v [1] == 'ROLE') {
  4849. if (! empty ( $verifyStaff )) {
  4850. $endStaffArray = end ( $verifyStaff );
  4851. // if ($v[0]==$endStaffArray['nextStaff']){
  4852. // $roleId=$v[0];
  4853. // }
  4854. }
  4855. $roleVerify = json_decode ( $v [3], true );
  4856. $roleKey = $k;
  4857. $roleArray = array ();
  4858. $rolename = $role->getOne ( array (
  4859. 'where' => 'rid=' . $v [0],
  4860. 'asArray' => true
  4861. ) );
  4862. foreach ( $roleVerify as $o => $p ) {
  4863. $staffID = explode ( '_', $p );
  4864. $staffInfo = $staff->getOne ( array (
  4865. 'where' => 'sid=' . $staffID [0],
  4866. 'asArray' => true
  4867. ) );
  4868. // print_r($staffID);
  4869. $exp = array (
  4870. 0 => $staffInfo ['sid'],
  4871. 1 => $staffID [1],
  4872. 2 => $staffInfo ['avatar'],
  4873. 'date' => '',
  4874. 'date' => '',
  4875. 'opinion' => '',
  4876. 'status' => '',
  4877. 'rolename' => $rolename ['name']
  4878. );
  4879. array_push ( $roleArray, $exp );
  4880. }
  4881. $roleArrayCopy [$v [0]] = $roleArray;
  4882. // $verifyList[$k]['roleArray']=$roleArray;
  4883. }
  4884. $verifyList [$k] ['date'] = "";
  4885. $verifyList [$k] ['opinion'] = "";
  4886. $verifyList [$k] ['status'] = "";
  4887. if (empty ( $verifyStaff )) {
  4888. $verifyList [$k] ['date'] = "";
  4889. $verifyList [$k] ['opinion'] = "";
  4890. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4891. $verifyList [$k] ['status'] = 4;
  4892. $flag = false;
  4893. }
  4894. } else {
  4895. foreach ( $verifyStaff as $m => $u ) {
  4896. if ($v [0] == $m) {
  4897. $verifyList [$k] ['date'] = $u ['date'];
  4898. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4899. $verifyList [$k] ['status'] = $u ['status'];
  4900. $flag = false;
  4901. break;
  4902. }
  4903. }
  4904. $endStaffArray = end ( $verifyStaff );
  4905. if (isset ( $endStaffArray ['ROLE'] )) {
  4906. } else {
  4907. // $endKey=key($verifyStaff);
  4908. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4909. // $button=4;
  4910. // $verifyList[$k]['status']=4;
  4911. // }
  4912. }
  4913. }
  4914. }
  4915. $rolename ['name'] = '';
  4916. if (! empty ( $roleId )) {
  4917. Doo::loadModel ( 'role' );
  4918. $role = new role ();
  4919. $rolename = $role->getOne ( array (
  4920. 'where' => 'rid=' . $roleId,
  4921. 'asArray' => true
  4922. ) );
  4923. }
  4924. if (! empty ( $verifyStaff ))
  4925. $endStaffArray = end ( $verifyStaff );
  4926. $KOP = false;
  4927. foreach ( $roleArrayCopy as $P => $A ) {
  4928. foreach ( $A as $MKI => $AVL ) {
  4929. if (! empty ( $verifyStaff )) {
  4930. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4931. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4932. $button = 4;
  4933. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4934. }
  4935. foreach ( $verifyStaff as $m => $u ) {
  4936. $AVLFK = $AVL [0] . '_R';
  4937. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4938. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4939. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4940. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4941. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4942. break;
  4943. }
  4944. }
  4945. } else {
  4946. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4947. $button = 4;
  4948. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4949. }
  4950. }
  4951. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4952. $KOP = true;
  4953. }
  4954. }
  4955. foreach ( $roleArrayCopy as $k => $v ) {
  4956. foreach ( $verifyList as $m => $n ) {
  4957. if ($n [0] == $k) {
  4958. array_splice ( $verifyList, $m, 1, $v );
  4959. }
  4960. }
  4961. }
  4962. $loanList [$key] ['verifyList'] = $verifyList;
  4963. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4964. 'where' => 'sid=' . $value ['staff'],
  4965. 'asArray' => true
  4966. ) );
  4967. }
  4968. $data ['loanList'] = $loanList;
  4969. $Locate = 0;
  4970. $roleId = 0;
  4971. $button = 0;
  4972. Doo::loadClass ( 'XDeode' );
  4973. $XDeode = new XDeode ( 5 );
  4974. foreach ( $receiptList as $key => $value ) {
  4975. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4976. $button2 = 0;
  4977. $receiptList [$key] ['Locate'] = $Locate;
  4978. $Locate ++;
  4979. $receiptList [$key] ['reviseDetail'] = array ();
  4980. if (! empty ( $value ['reviseDetail'] ))
  4981. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4982. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4983. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4984. $categoryDetil = $Lcategory->getOne ( array (
  4985. 'where' => 'cid=' . $value ['cid'],
  4986. 'asArray' => true
  4987. ) );
  4988. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4989. $executeList = json_decode ( $value ['executeCopy'], true );
  4990. $executeStaff = array ();
  4991. if (! empty ( $value ['executeStaff'] ))
  4992. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4993. if (isset ( $executeList )) {
  4994. foreach ( $executeList as $op => $lo ) {
  4995. $executeList [$op] ['date'] = "";
  4996. $executeList [$op] ['opinion'] = "";
  4997. $executeList [$op] ['status'] = "";
  4998. foreach ( $executeStaff as $m => $u ) {
  4999. if ($lo [0] == $m) {
  5000. $executeList [$op] ['date'] = $u ['date'];
  5001. $executeList [$op] ['opinion'] = $u ['opinion'];
  5002. $executeList [$op] ['status'] = $u ['status'];
  5003. break;
  5004. }
  5005. }
  5006. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5007. $button2 = 1;
  5008. $executeList [$op] ['status'] = 4;
  5009. }
  5010. }
  5011. }
  5012. // 检测编辑状态
  5013. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5014. $verifyList ['staff'] = $value ['verifyBreakup'];
  5015. } else
  5016. $verifyList = $verify->getOne ( array (
  5017. 'where' => 'vid=' . $value ['verify'],
  5018. 'asArray' => true
  5019. ) );
  5020. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5021. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5022. Doo::loadModel ( 'role' );
  5023. $role = new role ();
  5024. if ($verifyList == NULL)
  5025. $verifyList = array ();
  5026. $flag = true;
  5027. $roleKey = 0;
  5028. $endStaffArray = array ();
  5029. $roleArrayCopy = array ();
  5030. foreach ( $verifyList as $k => $v ) {
  5031. // init verifyStaff
  5032. if ($v [1] == 'ROLE') {
  5033. if (! empty ( $verifyStaff )) {
  5034. $endStaffArray = end ( $verifyStaff );
  5035. // if ($v[0]==$endStaffArray['nextStaff']){
  5036. // $roleId=$v[0];
  5037. // }
  5038. }
  5039. $roleVerify = json_decode ( $v [3], true );
  5040. $roleKey = $k;
  5041. $roleArray = array ();
  5042. $rolename = $role->getOne ( array (
  5043. 'where' => 'rid=' . $v [0],
  5044. 'asArray' => true
  5045. ) );
  5046. foreach ( $roleVerify as $o => $p ) {
  5047. $staffID = explode ( '_', $p );
  5048. $staffInfo = $staff->getOne ( array (
  5049. 'where' => 'sid=' . $staffID [0],
  5050. 'asArray' => true
  5051. ) );
  5052. // print_r($staffID);
  5053. $exp = array (
  5054. 0 => $staffInfo ['sid'],
  5055. 1 => $staffID [1],
  5056. 2 => $staffInfo ['avatar'],
  5057. 'date' => '',
  5058. 'date' => '',
  5059. 'opinion' => '',
  5060. 'status' => '',
  5061. 'rolename' => $rolename ['name']
  5062. );
  5063. array_push ( $roleArray, $exp );
  5064. }
  5065. $roleArrayCopy [$v [0]] = $roleArray;
  5066. // $verifyList[$k]['roleArray']=$roleArray;
  5067. }
  5068. $verifyList [$k] ['date'] = "";
  5069. $verifyList [$k] ['opinion'] = "";
  5070. $verifyList [$k] ['status'] = "";
  5071. if (empty ( $verifyStaff )) {
  5072. $verifyList [$k] ['date'] = "";
  5073. $verifyList [$k] ['opinion'] = "";
  5074. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5075. $verifyList [$k] ['status'] = 4;
  5076. $flag = false;
  5077. }
  5078. } else {
  5079. foreach ( $verifyStaff as $m => $u ) {
  5080. if ($v [0] == $m) {
  5081. $verifyList [$k] ['date'] = $u ['date'];
  5082. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5083. $verifyList [$k] ['status'] = $u ['status'];
  5084. $flag = false;
  5085. break;
  5086. }
  5087. }
  5088. $endStaffArray = end ( $verifyStaff );
  5089. if (isset ( $endStaffArray ['ROLE'] )) {
  5090. } else {
  5091. // $endKey=key($verifyStaff);
  5092. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5093. // $button=4;
  5094. // $verifyList[$k]['status']=4;
  5095. // }
  5096. }
  5097. }
  5098. }
  5099. $rolename ['name'] = '';
  5100. if (! empty ( $roleId )) {
  5101. Doo::loadModel ( 'role' );
  5102. $role = new role ();
  5103. $rolename = $role->getOne ( array (
  5104. 'where' => 'rid=' . $roleId,
  5105. 'asArray' => true
  5106. ) );
  5107. }
  5108. if (! empty ( $verifyStaff ))
  5109. $endStaffArray = end ( $verifyStaff );
  5110. $KOP = false;
  5111. foreach ( $roleArrayCopy as $P => $A ) {
  5112. foreach ( $A as $MKI => $AVL ) {
  5113. if (! empty ( $verifyStaff )) {
  5114. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5115. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5116. $button = 4;
  5117. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5118. }
  5119. foreach ( $verifyStaff as $m => $u ) {
  5120. $AVLFK = $AVL [0] . '_R';
  5121. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5122. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5123. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5124. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5125. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5126. break;
  5127. }
  5128. }
  5129. } else {
  5130. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5131. $button = 4;
  5132. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5133. }
  5134. }
  5135. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5136. $KOP = true;
  5137. }
  5138. }
  5139. foreach ( $roleArrayCopy as $k => $v ) {
  5140. foreach ( $verifyList as $m => $n ) {
  5141. if ($n [0] == $k) {
  5142. array_splice ( $verifyList, $m, 1, $v );
  5143. }
  5144. }
  5145. }
  5146. $receiptList [$key] ['verifyList'] = $verifyList;
  5147. $receiptList [$key] ['executeList'] = $executeList;
  5148. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5149. 'where' => 'sid=' . $value ['staff'],
  5150. 'asArray' => true
  5151. ) );
  5152. $receiptList [$key] ['button2'] = $button2;
  5153. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5154. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5155. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5156. $receiptList [$key] ['relust'] = $relust;
  5157. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5158. }
  5159. // 是否写入过流水
  5160. $accountType = 0;
  5161. if ($receiptList [0] ['Rtype'] == 0) {
  5162. $accountType = 3;
  5163. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5164. if (!empty($receiptList [0]['accountItem']) )
  5165. $accountType = 2;
  5166. else
  5167. $accountType = 1;
  5168. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5169. $accountType = 4;
  5170. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5171. $accountType = 12;
  5172. }
  5173. Doo::loadModel ( 'wasteBook' );
  5174. $wasteBook = new wasteBook ();
  5175. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5176. $data ['wbDetail'] = $wbDetail;
  5177. $wbDetailLoan=array();
  5178. if ($accountType==2){
  5179. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5180. }
  5181. $data ['wbDetailLoan'] = $wbDetailLoan;
  5182. //print_r($receiptList);
  5183. $data ['receiptList'] = $receiptList;
  5184. $data ['memu'] = "receipt";
  5185. $data ['staff'] = $this->staff;
  5186. $data ['receiptMemu'] = 'implement';
  5187. $data ['verifyId'] = $this->verifyId;
  5188. $data ['executeId'] = $this->executeId;
  5189. $this->render ( "/admin/implement", $data );
  5190. }
  5191. function implementDo() {
  5192. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5193. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5194. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5195. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5196. // $ab = '';
  5197. // if ($accountBank == 'CGBDeposit')
  5198. // $ab = '纵横广发';
  5199. // elseif ($accountBank == 'ICBCDeposit')
  5200. // $ab = '纵横工行';
  5201. // elseif ($accountBank == 'HUADeposit')
  5202. // $ab = '华润银行';
  5203. // elseif ($accountBank == 'PersonalDeposit')
  5204. // $ab = '个人广发';
  5205. // if (empty ( $ab ))
  5206. // die ( 'illegal request--22' );
  5207. if (! empty ( $rid )) {
  5208. Doo::loadModel ( 'receipt' );
  5209. $receipt = new receipt ();
  5210. // Doo::loadClass ( 'XDeode' );
  5211. // $XDeode = new XDeode ( 5 );
  5212. // $rinfo = $receipt->getOne ( array (
  5213. // 'where' => 'rid=' . $rid,
  5214. // 'asArray' => true
  5215. // ) );
  5216. $rinfo = $receipt->getReceiptByRid ( $rid );
  5217. // $accountType = '';
  5218. // if ($rinfo ['Rtype'] == 1) {
  5219. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5220. // $accountType = 2;
  5221. // else
  5222. // $accountType = 1;
  5223. // } elseif ($rinfo ['Rtype'] == 2) {
  5224. // $accountType = 4;
  5225. // } elseif ($rinfo ['Rtype'] == 0)
  5226. // $accountType = 3;
  5227. // if (empty ( $accountType ))
  5228. // die ( 'illegal request' );
  5229. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5230. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5231. if (empty ( $executeStaff )) {
  5232. $executeStaff = array (
  5233. $this->staff [0] ['sid'] => array (
  5234. 'date' => date ( 'Y-m-d' ),
  5235. 'opinion' => $implementOpinions,
  5236. 'status' => 1
  5237. )
  5238. );
  5239. } else {
  5240. $executeStaff [$this->staff [0] ['sid']] = array (
  5241. 'date' => date ( 'Y-m-d' ),
  5242. 'opinion' => $implementOpinions,
  5243. 'status' => 1
  5244. );
  5245. }
  5246. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5247. $receipt->executeStaff = json_encode ( $executeStaff );
  5248. $receipt->status = 8;
  5249. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5250. $receipt->status = 9;
  5251. if ($rinfo ['status'] == 6) {
  5252. $receipt->loanDate = date ( "Y-m-d" );
  5253. }
  5254. $receipt->executeDate = date ( "Y-m-d" );
  5255. } else {
  5256. $receipt->executeStaff = json_encode ( $executeStaff );
  5257. }
  5258. //$receipt->amount = $amount;
  5259. $receipt->update ( array (
  5260. 'where' => 'rid=' . $rid
  5261. ) );
  5262. // 公司流水记录
  5263. // Doo::loadModel ( 'wasteBook' );
  5264. // $wasteBook = new wasteBook ();
  5265. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5266. // // 银行
  5267. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5268. // $item = array (
  5269. // 'dataID' => $rid,
  5270. // 'expensesType' => 2,
  5271. // 'accountType' => $accountType,
  5272. // 'accountPriceShow' => $amount,
  5273. // 'accountPrice' => - $amount,
  5274. // 'accountBank' => $accountBank,
  5275. // 'category' => $rinfo ['category'] [0] ['title'],
  5276. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5277. // 'name' => $rinfo ['staffDetail'] ['username'],
  5278. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5279. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5280. // );
  5281. // $wasteBook->setAccountBookStatistics ( $item );
  5282. // }
  5283. }
  5284. //$ridKey = $XDeode->encode ( $rid );
  5285. return "/hisImplement";
  5286. // return "/implement/" . $ridKey . ".html";
  5287. }
  5288. function receiptburEdi() {
  5289. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5290. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5291. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5292. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5293. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5294. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5295. if (empty ( $status ))
  5296. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5297. $vidList = array ();
  5298. $button = 0;
  5299. Doo::loadModel ( 'verify' );
  5300. Doo::loadModel ( 'receipt' );
  5301. Doo::loadModel ( 'staff' );
  5302. $staff = new staff ();
  5303. $receipt = new receipt ();
  5304. $verify = new verify ();
  5305. Doo::loadModel ( 'L_category' );
  5306. $Lcategory = new L_category ();
  5307. Doo::loadModel ( 'enclosur' );
  5308. $enclosur = new enclosur ();
  5309. Doo::loadModel ( 'loanReceipt' );
  5310. $loanReceipt = new loanReceipt ();
  5311. // user verify ID
  5312. $verifyDetail = $verify->find ( array (
  5313. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5314. 'asArray' => true
  5315. ) );
  5316. foreach ( $verifyDetail as $key => $value ) {
  5317. array_push ( $vidList, $value ['vid'] );
  5318. }
  5319. $vid = implode ( ",", $vidList );
  5320. if (empty ( $verifyDetail ))
  5321. $vid = 0;
  5322. $categoryList = $Lcategory->find ( array (
  5323. 'asArray' => true
  5324. ) );
  5325. $staffList = $staff->find ( array (
  5326. 'where' => 'cid=' . $cid,
  5327. 'asArray' => true
  5328. ) );
  5329. $ap = "";
  5330. if ($status == 4) {
  5331. $ap = 4;
  5332. $status = 2;
  5333. }
  5334. // get Receipt By verifyID status 2
  5335. $receiptList = $receipt->find ( array (
  5336. 'where' => 'rid =' . $rid . ' and status=2',
  5337. 'desc' => 'rid',
  5338. 'asArray' => true
  5339. ) );
  5340. if (empty ( $receiptList )) {
  5341. die ( 'illegal request' );
  5342. }
  5343. $loanList = $loanReceipt->find ( array (
  5344. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5345. 'desc' => 'rid',
  5346. 'asArray' => true
  5347. ) );
  5348. $data ['explanation'] = '';
  5349. if (! empty ( $loanList ))
  5350. $data ['explanation'] = $loanList [0] ['explanation'];
  5351. $Locate = 0;
  5352. $roleId = 0;
  5353. $button = 0;
  5354. foreach ( $loanList as $key => $value ) {
  5355. $loanList [$key] ['Locate'] = $Locate;
  5356. $Locate ++;
  5357. $loanList [$key] ['reviseDetail'] = array ();
  5358. if (! empty ( $value ['reviseDetail'] ))
  5359. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5360. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5361. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5362. $categoryDetil = $Lcategory->getOne ( array (
  5363. 'where' => 'cid=' . $value ['cid'],
  5364. 'asArray' => true
  5365. ) );
  5366. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5367. // 检测编辑状态
  5368. $verifyList = $verify->getOne ( array (
  5369. 'where' => 'vid=' . $value ['verify'],
  5370. 'asArray' => true
  5371. ) );
  5372. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5373. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5374. Doo::loadModel ( 'role' );
  5375. $role = new role ();
  5376. $flag = true;
  5377. $roleKey = 0;
  5378. $endStaffArray = array ();
  5379. $roleArrayCopy = array ();
  5380. foreach ( $verifyList as $k => $v ) {
  5381. // init verifyStaff
  5382. if ($v [1] == 'ROLE') {
  5383. if (! empty ( $verifyStaff )) {
  5384. $endStaffArray = end ( $verifyStaff );
  5385. }
  5386. $roleVerify = json_decode ( $v [3], true );
  5387. $roleKey = $k;
  5388. $roleArray = array ();
  5389. $rolename = $role->getOne ( array (
  5390. 'where' => 'rid=' . $v [0],
  5391. 'asArray' => true
  5392. ) );
  5393. foreach ( $roleVerify as $o => $p ) {
  5394. $staffID = explode ( '_', $p );
  5395. $staffInfo = $staff->getOne ( array (
  5396. 'where' => 'sid=' . $staffID [0],
  5397. 'asArray' => true
  5398. ) );
  5399. // print_r($staffID);
  5400. $exp = array (
  5401. 0 => $staffInfo ['sid'],
  5402. 1 => $staffID [1],
  5403. 2 => $staffInfo ['avatar'],
  5404. 'date' => '',
  5405. 'date' => '',
  5406. 'opinion' => '',
  5407. 'status' => '',
  5408. 'rolename' => $rolename ['name']
  5409. );
  5410. array_push ( $roleArray, $exp );
  5411. }
  5412. $roleArrayCopy [$v [0]] = $roleArray;
  5413. // $verifyList[$k]['roleArray']=$roleArray;
  5414. }
  5415. $verifyList [$k] ['date'] = "";
  5416. $verifyList [$k] ['opinion'] = "";
  5417. $verifyList [$k] ['status'] = "";
  5418. if (empty ( $verifyStaff )) {
  5419. $verifyList [$k] ['date'] = "";
  5420. $verifyList [$k] ['opinion'] = "";
  5421. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5422. $verifyList [$k] ['status'] = 4;
  5423. $flag = false;
  5424. }
  5425. } else {
  5426. foreach ( $verifyStaff as $m => $u ) {
  5427. if ($v [0] == $m) {
  5428. $verifyList [$k] ['date'] = $u ['date'];
  5429. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5430. $verifyList [$k] ['status'] = $u ['status'];
  5431. $flag = false;
  5432. break;
  5433. }
  5434. }
  5435. $endStaffArray = end ( $verifyStaff );
  5436. if (isset ( $endStaffArray ['ROLE'] )) {
  5437. } else {
  5438. }
  5439. }
  5440. }
  5441. $rolename ['name'] = '';
  5442. if (! empty ( $roleId )) {
  5443. Doo::loadModel ( 'role' );
  5444. $role = new role ();
  5445. $rolename = $role->getOne ( array (
  5446. 'where' => 'rid=' . $roleId,
  5447. 'asArray' => true
  5448. ) );
  5449. }
  5450. if (! empty ( $verifyStaff ))
  5451. $endStaffArray = end ( $verifyStaff );
  5452. $KOP = false;
  5453. foreach ( $roleArrayCopy as $P => $A ) {
  5454. foreach ( $A as $MKI => $AVL ) {
  5455. if (! empty ( $verifyStaff )) {
  5456. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5457. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5458. $button = 4;
  5459. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5460. }
  5461. foreach ( $verifyStaff as $m => $u ) {
  5462. $AVLFK = $AVL [0] . '_R';
  5463. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5464. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5465. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5466. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5467. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5468. break;
  5469. }
  5470. }
  5471. } else {
  5472. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5473. $button = 4;
  5474. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5475. }
  5476. }
  5477. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5478. $KOP = true;
  5479. }
  5480. }
  5481. foreach ( $roleArrayCopy as $k => $v ) {
  5482. foreach ( $verifyList as $m => $n ) {
  5483. if ($n [0] == $k) {
  5484. array_splice ( $verifyList, $m, 1, $v );
  5485. }
  5486. }
  5487. }
  5488. $loanList [$key] ['verifyList'] = $verifyList;
  5489. }
  5490. $htmlLoan = '';
  5491. $data ['loanReceiptDate'] = '';
  5492. if (isset ( $loanList [0] )) {
  5493. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5494. if ($value ['status'] == 1)
  5495. $htmlLoan .= '<li class="done" >';
  5496. elseif ($value ['status'] == 3)
  5497. $htmlLoan .= '<li class="undone" >';
  5498. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5499. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5500. if (isset ( $value ['rolename'] ))
  5501. $htmlLoan .= $value ['rolename'];
  5502. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5503. }
  5504. $data ['loanDate'] = $loanList [0] ['date'];
  5505. } else {
  5506. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5507. }
  5508. $data ['htmlLoan'] = $htmlLoan;
  5509. // $data ['LoanReceipt']=$loanList[0];
  5510. // print_r($loanList);
  5511. $Locate = 0;
  5512. $roleId = 0;
  5513. $button = 0;
  5514. if ($ap == 4)
  5515. $status = 4;
  5516. Doo::loadClass ( 'XDeode' );
  5517. $XDeode = new XDeode ( 5 );
  5518. foreach ( $receiptList as $key => $value ) {
  5519. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5520. $receiptList [$key] ['Locate'] = $Locate;
  5521. $Locate ++;
  5522. $receiptList [$key] ['reviseDetail'] = array ();
  5523. // 调整金额 代码调整
  5524. if (! empty ( $value ['reviseDetail'] )) {
  5525. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5526. foreach ( $reviseDetail as $ry => $re ) {
  5527. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5528. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5529. }
  5530. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5531. // print_r($reviseDetail);
  5532. }
  5533. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5534. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5535. $categoryDetil = $Lcategory->getOne ( array (
  5536. 'where' => 'cid=' . $value ['cid'],
  5537. 'asArray' => true
  5538. ) );
  5539. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5540. // 检测编辑状态
  5541. $verifyList = $verify->getOne ( array (
  5542. 'where' => 'vid=' . $value ['verify'],
  5543. 'asArray' => true
  5544. ) );
  5545. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5546. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5547. Doo::loadModel ( 'role' );
  5548. $role = new role ();
  5549. // print_r($verifyList);
  5550. $flag = true;
  5551. $roleKey = 0;
  5552. $endStaffArray = array ();
  5553. $roleArrayCopy = array ();
  5554. foreach ( $verifyList as $k => $v ) {
  5555. // init verifyStaff
  5556. if ($v [1] == 'ROLE') {
  5557. if (! empty ( $verifyStaff )) {
  5558. $endStaffArray = end ( $verifyStaff );
  5559. if ($v [0] == $endStaffArray ['nextStaff']) {
  5560. $roleId = $v [0];
  5561. }
  5562. }
  5563. $roleVerify = json_decode ( $v [3], true );
  5564. $roleKey = $k;
  5565. $roleArray = array ();
  5566. $rolename = $role->getOne ( array (
  5567. 'where' => 'rid=' . $v [0],
  5568. 'asArray' => true
  5569. ) );
  5570. foreach ( $roleVerify as $o => $p ) {
  5571. $staffID = explode ( '_', $p );
  5572. $staffInfo = $staff->getOne ( array (
  5573. 'where' => 'sid=' . $staffID [0],
  5574. 'asArray' => true
  5575. ) );
  5576. // print_r($staffID);
  5577. $exp = array (
  5578. 0 => $staffInfo ['sid'],
  5579. 1 => $staffID [1],
  5580. 2 => $staffInfo ['avatar'],
  5581. 'date' => '',
  5582. 'date' => '',
  5583. 'opinion' => '',
  5584. 'status' => '',
  5585. 'rolename' => $rolename ['name']
  5586. );
  5587. array_push ( $roleArray, $exp );
  5588. }
  5589. $roleArrayCopy [$v [0]] = $roleArray;
  5590. // $verifyList[$k]['roleArray']=$roleArray;
  5591. }
  5592. // print_r($roleArray);
  5593. $verifyList [$k] ['date'] = "";
  5594. $verifyList [$k] ['opinion'] = "";
  5595. $verifyList [$k] ['status'] = "";
  5596. if (empty ( $verifyStaff )) {
  5597. $verifyList [$k] ['date'] = "";
  5598. $verifyList [$k] ['opinion'] = "";
  5599. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5600. $verifyList [$k] ['status'] = 4;
  5601. $button = 4;
  5602. $flag = false;
  5603. }
  5604. } else {
  5605. foreach ( $verifyStaff as $m => $u ) {
  5606. if ($v [0] == $m) {
  5607. $verifyList [$k] ['date'] = $u ['date'];
  5608. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5609. $verifyList [$k] ['status'] = $u ['status'];
  5610. $flag = false;
  5611. break;
  5612. }
  5613. }
  5614. $endStaffArray = end ( $verifyStaff );
  5615. if (isset ( $endStaffArray ['ROLE'] )) {
  5616. } else {
  5617. $endKey = key ( $verifyStaff );
  5618. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5619. $button = 4;
  5620. $verifyList [$k] ['status'] = 4;
  5621. }
  5622. }
  5623. }
  5624. }
  5625. $rolename ['name'] = '';
  5626. if (! empty ( $roleId )) {
  5627. Doo::loadModel ( 'role' );
  5628. $role = new role ();
  5629. $rolename = $role->getOne ( array (
  5630. 'where' => 'rid=' . $roleId,
  5631. 'asArray' => true
  5632. ) );
  5633. }
  5634. if (! empty ( $verifyStaff ))
  5635. $endStaffArray = end ( $verifyStaff );
  5636. $KOP = false;
  5637. foreach ( $roleArrayCopy as $P => $A ) {
  5638. foreach ( $A as $MKI => $AVL ) {
  5639. if (! empty ( $verifyStaff )) {
  5640. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5641. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5642. $button = 4;
  5643. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5644. }
  5645. foreach ( $verifyStaff as $m => $u ) {
  5646. $AVLFK = $AVL [0] . '_R';
  5647. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5648. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5649. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5650. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5651. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5652. break;
  5653. }
  5654. }
  5655. } else {
  5656. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5657. $button = 4;
  5658. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5659. }
  5660. }
  5661. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5662. $KOP = true;
  5663. }
  5664. }
  5665. foreach ( $roleArrayCopy as $k => $v ) {
  5666. foreach ( $verifyList as $m => $n ) {
  5667. if ($n [0] == $k) {
  5668. array_splice ( $verifyList, $m, 1, $v );
  5669. }
  5670. }
  5671. }
  5672. // print_r($verifyList);
  5673. $receiptList [$key] ['verifyList'] = $verifyList;
  5674. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5675. 'where' => 'sid=' . $value ['staff'],
  5676. 'asArray' => true
  5677. ) );
  5678. $receiptList [$key] ['button'] = $button;
  5679. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5680. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5681. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5682. $receiptList [$key] ['relust'] = $relust;
  5683. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5684. }
  5685. //print_r($receiptList);die;
  5686. // $data['verifyDetail']=$verifyDetail;
  5687. $mothHtml = "";
  5688. for($i = 1; $i <= 12; $i ++) {
  5689. if ($month == $i)
  5690. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5691. else
  5692. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5693. }
  5694. // 获取审批日志
  5695. Doo::loadModel ( 'receiptLog' );
  5696. $receiptLog = new receiptLog ();
  5697. $rlList = array ();
  5698. $rlInfo = $receiptLog->getOne ( array (
  5699. 'where' => 'rid=' . $rid . ' and status=4',
  5700. 'asArray' => true
  5701. ) );
  5702. $tijdate = $receiptLog->getOne ( array (
  5703. 'where' => 'rid=' . $rid . ' and status=2',
  5704. 'asc' => 'rlid',
  5705. 'asArray' => true
  5706. ) );
  5707. if (! empty ( $rlInfo )) {
  5708. $rlList = $receiptLog->find ( array (
  5709. 'where' => 'rid=' . $rid,
  5710. 'asc' => 'rlid',
  5711. 'asArray' => true
  5712. ) );
  5713. }
  5714. // echo $rid;
  5715. // print_r($receiptList);
  5716. $receiptList [0] ['rlList'] = $rlList;
  5717. // print_r($receiptList);
  5718. $enclosurList = $enclosur->find ( array (
  5719. 'where' => 'rid=' . $rid,
  5720. 'asArray' => true
  5721. ) );
  5722. $enclosurHtml = '';
  5723. foreach ( $enclosurList as $value ) {
  5724. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5725. }
  5726. $data ['enclosurHtml'] = $enclosurHtml;
  5727. $data ['rolename'] = $rolename ['name'];
  5728. $data ['mothHtml'] = $mothHtml;
  5729. // print_r($receiptList);
  5730. $data ['rid'] = $rid;
  5731. $data ['tijdate'] = $tijdate ['date'];
  5732. $data ['receiptList'] = $receiptList;
  5733. $data ['receiptApprovalCount'] = count ( $receiptList );
  5734. $data ['status'] = $status;
  5735. $data ['year'] = $year;
  5736. $data ['categoryList'] = $categoryList;
  5737. $data ['staffList'] = $staffList;
  5738. $data ['cid'] = $cid;
  5739. $data ['sid'] = $sid;
  5740. $data ['ap'] = $ap;
  5741. $data ['memu'] = "receipt";
  5742. $data ['staff'] = $this->staff;
  5743. $data ['receiptMemu'] = 'approvalExpenses';
  5744. $data ['verifyId'] = $this->verifyId;
  5745. $data ['executeId'] = $this->executeId;
  5746. $this->render ( "/admin/receiptburEdi", $data );
  5747. }
  5748. function hisImplement() {
  5749. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5750. if (empty ( $item ))
  5751. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5752. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5753. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5754. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5755. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5756. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5757. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5758. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5759. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5760. Doo::loadClass ( 'XDeode' );
  5761. $XDeode = new XDeode ( 5 );
  5762. Doo::loadModel ( 'receipt' );
  5763. $receipt = new receipt ();
  5764. Doo::loadModel ( 'L_category' );
  5765. $Lcategory = new L_category ();
  5766. Doo::loadModel ( 'verify' );
  5767. Doo::loadModel ( 'statistics' );
  5768. $statistics = new statistics ();
  5769. $verify = new verify ();
  5770. Doo::loadModel ( 'staff' );
  5771. $staff = new staff ();
  5772. Doo::loadClass ( 'XDeode' );
  5773. $XDeode = new XDeode ( 5 );
  5774. $XDeode7 = new XDeode ( 7 );
  5775. $cid = $XDeode->decode ( $cidKey );
  5776. $condition = "";
  5777. if ($item == "expenses")
  5778. $condition = " and Rtype=1 ";
  5779. elseif ($item == "receipts")
  5780. $condition = " and Rtype=0 ";
  5781. elseif ($item == "remits")
  5782. $condition = " and Rtype=2 ";
  5783. elseif($item == "train")
  5784. $condition = " and Rtype=3 ";
  5785. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5786. $sopString = $cidString = "";
  5787. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5788. if (empty ( $rdate ))
  5789. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5790. else
  5791. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5792. if ($status == 'pendImplement') {
  5793. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5794. } elseif ($status == 'alerpts') {
  5795. $statusCon = '(status=8 or status=9 )';
  5796. if (empty ( $rdate ))
  5797. $dateCondition .= " and Year(date) =" . $year;
  5798. else
  5799. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5800. }
  5801. if ($sop != 'SOP')
  5802. $sopString = " and staff=" . $sop;
  5803. if ($cidKey != 'ALL')
  5804. $cidString = " and cid=" . $cid;
  5805. if(!empty($receiptOrder)){
  5806. $receiptList = $receipt->find ( array (
  5807. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5808. 'desc' => 'rid',
  5809. 'asArray' => true
  5810. ) );
  5811. // 员工筛选
  5812. $receiptList2 = $receipt->find ( array (
  5813. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5814. 'desc' => 'rid',
  5815. 'asArray' => true
  5816. ) );
  5817. }else{
  5818. $receiptList = $receipt->find ( array (
  5819. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5820. 'desc' => 'rid',
  5821. 'asArray' => true
  5822. ) );
  5823. // 员工筛选
  5824. $receiptList2 = $receipt->find ( array (
  5825. 'where' => $statusCon . $condition . $dateCondition,
  5826. 'desc' => 'rid',
  5827. 'asArray' => true
  5828. ) );
  5829. }
  5830. $sopStaff = array ();
  5831. foreach ( $receiptList2 as $key => $value ) {
  5832. $staffDetail = $staff->getOne ( array (
  5833. 'select' => 'username',
  5834. 'where' => 'sid=' . $value ['staff'],
  5835. 'asArray' => true
  5836. ) );
  5837. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5838. }
  5839. // 办事处筛选
  5840. $categoryScreen = array ();
  5841. $categorList = $Lcategory->getCategory ();
  5842. foreach ( $receiptList2 as $key => $value ) {
  5843. foreach ( $categorList as $k => $v ) {
  5844. if ($value ['cid'] == $v ['cid']) {
  5845. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5846. break;
  5847. }
  5848. }
  5849. }
  5850. $categoryScreenHtml = "";
  5851. foreach ( $categoryScreen as $key => $value ) {
  5852. if ($cidKey == $key)
  5853. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5854. else
  5855. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5856. }
  5857. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5858. $data ['cidKey'] = $cidKey;
  5859. $Locate = 0;
  5860. $roleId = 0;
  5861. $button = 0;
  5862. $staffBatchNumber = 100001;
  5863. $remittanceList = array ();
  5864. foreach ( $receiptList as $key => $value ) {
  5865. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5866. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5867. $receiptList [$key] ['Texe'] = 'false';
  5868. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5869. $receiptList [$key] ['Texe'] = 'true';
  5870. }
  5871. $receiptList [$key] ['TRexe'] = 'true';
  5872. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5873. $receiptList [$key] ['TRexe'] = 'false';
  5874. }
  5875. $receiptList [$key] ['Locate'] = $Locate;
  5876. $Locate ++;
  5877. $receiptList [$key] ['reviseDetail'] = array ();
  5878. if (! empty ( $value ['reviseDetail'] ))
  5879. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5880. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5881. $categoryDetil = $Lcategory->getOne ( array (
  5882. 'where' => 'cid=' . $value ['cid'],
  5883. 'asArray' => true
  5884. ) );
  5885. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5886. // 检测编辑状态
  5887. $verifyList = $verify->getOne ( array (
  5888. 'where' => 'vid=' . $value ['verify'],
  5889. 'asArray' => true
  5890. ) );
  5891. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5892. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5893. Doo::loadModel ( 'role' );
  5894. $role = new role ();
  5895. $flag = true;
  5896. $roleKey = 0;
  5897. $endStaffArray = array ();
  5898. $roleArrayCopy = array ();
  5899. foreach ( $verifyList as $k => $v ) {
  5900. // init verifyStaff
  5901. if ($v [1] == 'ROLE') {
  5902. if (! empty ( $verifyStaff )) {
  5903. $endStaffArray = end ( $verifyStaff );
  5904. }
  5905. $roleVerify = json_decode ( $v [3], true );
  5906. $roleKey = $k;
  5907. $roleArray = array ();
  5908. $rolename = $role->getOne ( array (
  5909. 'where' => 'rid=' . $v [0],
  5910. 'asArray' => true
  5911. ) );
  5912. foreach ( $roleVerify as $o => $p ) {
  5913. $staffID = explode ( '_', $p );
  5914. $staffInfo = $staff->getOne ( array (
  5915. 'where' => 'sid=' . $staffID [0],
  5916. 'asArray' => true
  5917. ) );
  5918. $exp = array (
  5919. 0 => $staffInfo ['sid'],
  5920. 1 => $staffID [1],
  5921. 2 => $staffInfo ['avatar'],
  5922. 'date' => '',
  5923. 'date' => '',
  5924. 'opinion' => '',
  5925. 'status' => '',
  5926. 'rolename' => $rolename ['name']
  5927. );
  5928. array_push ( $roleArray, $exp );
  5929. }
  5930. $roleArrayCopy [$v [0]] = $roleArray;
  5931. }
  5932. $verifyList [$k] ['date'] = "";
  5933. $verifyList [$k] ['opinion'] = "";
  5934. $verifyList [$k] ['status'] = "";
  5935. if (empty ( $verifyStaff )) {
  5936. $verifyList [$k] ['date'] = "";
  5937. $verifyList [$k] ['opinion'] = "";
  5938. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5939. $verifyList [$k] ['status'] = 4;
  5940. $flag = false;
  5941. }
  5942. } else {
  5943. foreach ( $verifyStaff as $m => $u ) {
  5944. if ($v [0] == $m) {
  5945. $verifyList [$k] ['date'] = $u ['date'];
  5946. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5947. $verifyList [$k] ['status'] = $u ['status'];
  5948. $flag = false;
  5949. break;
  5950. }
  5951. }
  5952. $endStaffArray = end ( $verifyStaff );
  5953. }
  5954. }
  5955. $rolename ['name'] = '';
  5956. if (! empty ( $roleId )) {
  5957. Doo::loadModel ( 'role' );
  5958. $role = new role ();
  5959. $rolename = $role->getOne ( array (
  5960. 'where' => 'rid=' . $roleId,
  5961. 'asArray' => true
  5962. ) );
  5963. }
  5964. if (! empty ( $verifyStaff ))
  5965. $endStaffArray = end ( $verifyStaff );
  5966. $KOP = false;
  5967. foreach ( $roleArrayCopy as $P => $A ) {
  5968. foreach ( $A as $MKI => $AVL ) {
  5969. if (! empty ( $verifyStaff )) {
  5970. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5971. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5972. $button = 4;
  5973. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5974. }
  5975. foreach ( $verifyStaff as $m => $u ) {
  5976. $AVLFK = $AVL [0] . '_R';
  5977. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5978. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5979. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5980. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5981. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5982. break;
  5983. }
  5984. }
  5985. } else {
  5986. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5987. $button = 4;
  5988. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5989. }
  5990. }
  5991. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5992. $KOP = true;
  5993. }
  5994. }
  5995. foreach ( $roleArrayCopy as $k => $v ) {
  5996. foreach ( $verifyList as $m => $n ) {
  5997. if ($n [0] == $k) {
  5998. array_splice ( $verifyList, $m, 1, $v );
  5999. }
  6000. }
  6001. }
  6002. $receiptList [$key] ['verifyList'] = $verifyList;
  6003. $staffDetail = $staff->getOne ( array (
  6004. 'where' => 'sid=' . $value ['staff'],
  6005. 'asArray' => true
  6006. ) );
  6007. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6008. $receiptList [$key] ['button'] = $button;
  6009. // 设置导出汇款execl
  6010. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6011. $remittanceDetail = array (
  6012. $staffBatchNumber,
  6013. $value ['remittanceName'],
  6014. $value ['bankNumber'],
  6015. $value ['bankName'],
  6016. $value ['remittanceBankType'],
  6017. $value ['coupletNumber'],
  6018. $value ['sum']
  6019. );
  6020. array_push ( $remittanceList, $remittanceDetail );
  6021. $staffBatchNumber ++;
  6022. }
  6023. }
  6024. $data ['remittanceList'] = json_encode ( $remittanceList );
  6025. // print_r($receiptList);
  6026. $mothHtml = "";
  6027. for($i = 1; $i <= 12; $i ++) {
  6028. if ($moth == $i)
  6029. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6030. else
  6031. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6032. }
  6033. $dayHtml = "";
  6034. if ($day != "DAY" || $moth != "MONTH") {
  6035. for($i = 1; $i <= 31; $i ++) {
  6036. if ($day == $i)
  6037. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6038. else
  6039. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6040. }
  6041. }
  6042. $sopHtml = "";
  6043. foreach ( $sopStaff as $key => $value ) {
  6044. if ($sop == $key)
  6045. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6046. else
  6047. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6048. }
  6049. $data ['status'] = $status;
  6050. $data ['rdate'] = $rdate;
  6051. $data ['sopHtml'] = $sopHtml;
  6052. $data ['dayHtml'] = $dayHtml;
  6053. $data ['mothHtml'] = $mothHtml;
  6054. $data ['receiptList'] = $receiptList;
  6055. $data ['memu'] = "receipt";
  6056. $data ['staff'] = $this->staff;
  6057. $data ['receiptMemu'] = 'implement';
  6058. $data ['verifyId'] = $this->verifyId;
  6059. $data ['executeId'] = $this->executeId;
  6060. $data ['item'] = $item;
  6061. $data ['year'] = $year;
  6062. $data ['moth'] = $moth;
  6063. $data['receiptOrder']=$receiptOrder;
  6064. $data ['day'] = $day;
  6065. $data ['sop'] = $sop;
  6066. $this->render ( "/admin/hisImplement", $data );
  6067. }
  6068. /**
  6069. * 导出汇款信息的exelc
  6070. */
  6071. function exportRemittance() {
  6072. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6073. if (empty ( $remittanceInfo ))
  6074. die ( 'illegal request' );
  6075. $title = array (
  6076. '员工编号',
  6077. '姓名',
  6078. '员工账号',
  6079. '员工账户开户行',
  6080. '转账类型',
  6081. '联行号',
  6082. '金额'
  6083. );
  6084. $data = json_decode ( $remittanceInfo, true );
  6085. if (empty ( $data ))
  6086. die ( 'illegal request' );
  6087. Doo::loadClass ( 'receipt.func' );
  6088. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6089. header ( 'Content-Type:text/html;charset=utf-8' );
  6090. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6091. }
  6092. function ajaxExamine() {
  6093. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6094. Doo::loadModel ( 'receipt' );
  6095. $receipt = new receipt ();
  6096. if (! empty ( $rid )) {
  6097. $rLRes = $receipt->find ( array (
  6098. '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,
  6099. 'asArray' => true
  6100. ) );
  6101. echo json_encode ( array (
  6102. 'status' => 1,
  6103. 'receipt' => $rLRes [0]
  6104. ) );
  6105. die ();
  6106. }
  6107. echo json_encode ( array (
  6108. 'status' => 0,
  6109. 'receipt' => array ()
  6110. ) );
  6111. die ();
  6112. }
  6113. /*
  6114. * 废弃
  6115. */
  6116. function myReceipt() {
  6117. // all approval past withdraw
  6118. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6119. if (empty ( $item ))
  6120. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6121. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6122. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6123. Doo::loadModel ( 'receipt' );
  6124. $receipt = new receipt ();
  6125. // pre-loaded
  6126. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6127. // have cache
  6128. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6129. if (! empty ( $moth )) // yearPage
  6130. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6131. $this->showCache ( $path );
  6132. }
  6133. Doo::loadModel ( 'L_category' );
  6134. $Lcategory = new L_category ();
  6135. Doo::loadModel ( 'verify' );
  6136. Doo::loadModel ( 'statistics' );
  6137. $statistics = new statistics ();
  6138. $verify = new verify ();
  6139. Doo::loadModel ( 'staff' );
  6140. $staff = new staff ();
  6141. $condition = " and status!=0 ";
  6142. if ($item == "approval")
  6143. $condition = " and status=2 ";
  6144. elseif ($item == "withdraw")
  6145. $condition = " and status=3 ";
  6146. elseif ($item == "past")
  6147. $condition = " and status=1 ";
  6148. elseif ($item == "whdw")
  6149. $condition = " and status=4 ";
  6150. $dateCondition = " and Year(date) =" . $year;
  6151. if (! empty ( $moth )) {
  6152. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6153. $stList = $statistics->getOne ( array (
  6154. 'select' => 'rePrice ,agPrice',
  6155. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6156. 'asArray' => true
  6157. ) );
  6158. } else
  6159. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6160. if (empty ( $stList ))
  6161. $stList = array (
  6162. 'rePrice' => 0,
  6163. 'agPrice' => 0
  6164. );
  6165. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6166. $data ['stList'] = array (
  6167. 'rePrice' => $stList ['rePrice'],
  6168. 'agPrice' => $stList ['agPrice'],
  6169. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6170. );
  6171. $receiptList = $receipt->find ( array (
  6172. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6173. 'desc' => 'rid',
  6174. 'asArray' => true
  6175. ) );
  6176. $Locate = 0;
  6177. $roleId = 0;
  6178. $button = 0;
  6179. foreach ( $receiptList as $key => $value ) {
  6180. $receiptList [$key] ['Locate'] = $Locate;
  6181. $Locate ++;
  6182. $receiptList [$key] ['reviseDetail'] = array ();
  6183. if (! empty ( $value ['reviseDetail'] ))
  6184. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6185. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6186. $categoryDetil = $Lcategory->getOne ( array (
  6187. 'where' => 'cid=' . $value ['cid'],
  6188. 'asArray' => true
  6189. ) );
  6190. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6191. // 检测编辑状态
  6192. $verifyList = $verify->getOne ( array (
  6193. 'where' => 'vid=' . $value ['verify'],
  6194. 'asArray' => true
  6195. ) );
  6196. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6197. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6198. Doo::loadModel ( 'role' );
  6199. $role = new role ();
  6200. $flag = true;
  6201. $roleKey = 0;
  6202. $endStaffArray = array ();
  6203. $roleArrayCopy = array ();
  6204. foreach ( $verifyList as $k => $v ) {
  6205. // init verifyStaff
  6206. if ($v [1] == 'ROLE') {
  6207. if (! empty ( $verifyStaff )) {
  6208. $endStaffArray = end ( $verifyStaff );
  6209. // if ($v[0]==$endStaffArray['nextStaff']){
  6210. // $roleId=$v[0];
  6211. // }
  6212. }
  6213. $roleVerify = json_decode ( $v [3], true );
  6214. $roleKey = $k;
  6215. $roleArray = array ();
  6216. $rolename = $role->getOne ( array (
  6217. 'where' => 'rid=' . $v [0],
  6218. 'asArray' => true
  6219. ) );
  6220. foreach ( $roleVerify as $o => $p ) {
  6221. $staffID = explode ( '_', $p );
  6222. $staffInfo = $staff->getOne ( array (
  6223. 'where' => 'sid=' . $staffID [0],
  6224. 'asArray' => true
  6225. ) );
  6226. // print_r($staffID);
  6227. $exp = array (
  6228. 0 => $staffInfo ['sid'],
  6229. 1 => $staffID [1],
  6230. 2 => $staffInfo ['avatar'],
  6231. 'date' => '',
  6232. 'date' => '',
  6233. 'opinion' => '',
  6234. 'status' => '',
  6235. 'rolename' => $rolename ['name']
  6236. );
  6237. array_push ( $roleArray, $exp );
  6238. }
  6239. $roleArrayCopy [$v [0]] = $roleArray;
  6240. // $verifyList[$k]['roleArray']=$roleArray;
  6241. }
  6242. $verifyList [$k] ['date'] = "";
  6243. $verifyList [$k] ['opinion'] = "";
  6244. $verifyList [$k] ['status'] = "";
  6245. if (empty ( $verifyStaff )) {
  6246. $verifyList [$k] ['date'] = "";
  6247. $verifyList [$k] ['opinion'] = "";
  6248. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6249. $verifyList [$k] ['status'] = 4;
  6250. $flag = false;
  6251. }
  6252. } else {
  6253. foreach ( $verifyStaff as $m => $u ) {
  6254. if ($v [0] == $m) {
  6255. $verifyList [$k] ['date'] = $u ['date'];
  6256. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6257. $verifyList [$k] ['status'] = $u ['status'];
  6258. $flag = false;
  6259. break;
  6260. }
  6261. }
  6262. $endStaffArray = end ( $verifyStaff );
  6263. if (isset ( $endStaffArray ['ROLE'] )) {
  6264. } else {
  6265. // $endKey=key($verifyStaff);
  6266. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6267. // $button=4;
  6268. // $verifyList[$k]['status']=4;
  6269. // }
  6270. }
  6271. }
  6272. }
  6273. $rolename ['name'] = '';
  6274. if (! empty ( $roleId )) {
  6275. Doo::loadModel ( 'role' );
  6276. $role = new role ();
  6277. $rolename = $role->getOne ( array (
  6278. 'where' => 'rid=' . $roleId,
  6279. 'asArray' => true
  6280. ) );
  6281. }
  6282. if (! empty ( $verifyStaff ))
  6283. $endStaffArray = end ( $verifyStaff );
  6284. $KOP = false;
  6285. foreach ( $roleArrayCopy as $P => $A ) {
  6286. foreach ( $A as $MKI => $AVL ) {
  6287. if (! empty ( $verifyStaff )) {
  6288. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6289. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6290. $button = 4;
  6291. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6292. }
  6293. foreach ( $verifyStaff as $m => $u ) {
  6294. $AVLFK = $AVL [0] . '_R';
  6295. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6296. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6297. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6298. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6299. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6300. break;
  6301. }
  6302. }
  6303. } else {
  6304. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6305. $button = 4;
  6306. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6307. }
  6308. }
  6309. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6310. $KOP = true;
  6311. }
  6312. }
  6313. foreach ( $roleArrayCopy as $k => $v ) {
  6314. foreach ( $verifyList as $m => $n ) {
  6315. if ($n [0] == $k) {
  6316. array_splice ( $verifyList, $m, 1, $v );
  6317. }
  6318. }
  6319. }
  6320. $receiptList [$key] ['verifyList'] = $verifyList;
  6321. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6322. 'where' => 'sid=' . $value ['staff'],
  6323. 'asArray' => true
  6324. ) );
  6325. $receiptList [$key] ['button'] = $button;
  6326. }
  6327. // print_r($receiptList);die;
  6328. $mothHtml = "";
  6329. for($i = 1; $i <= 12; $i ++) {
  6330. if ($moth == $i)
  6331. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6332. else
  6333. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6334. }
  6335. $data ['mothHtml'] = $mothHtml;
  6336. $data ['receiptList'] = $receiptList;
  6337. $data ['memu'] = "receipt";
  6338. $data ['staff'] = $this->staff;
  6339. $data ['receiptMemu'] = 'receipt';
  6340. $data ['verifyId'] = $this->verifyId;
  6341. $data ['executeId'] = $this->executeId;
  6342. $data ['item'] = $item;
  6343. $data ['year'] = $year;
  6344. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6345. // sufficient condition to generate cache
  6346. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6347. $receiptList = $receipt->find ( array (
  6348. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6349. 'asArray' => true
  6350. ) );
  6351. if (empty ( $receiptList )) { // generated files
  6352. ob_start ();
  6353. $this->render ( "/admin/saea_myList", $data );
  6354. $this->cacheFile ( $path );
  6355. die ();
  6356. // $content = ob_get_contents();
  6357. // $fp = fopen($path, "w");
  6358. // fwrite($fp, $content);
  6359. // fclose($fp);
  6360. }
  6361. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6362. $receiptList = $receipt->find ( array (
  6363. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6364. 'asArray' => true
  6365. ) );
  6366. if (empty ( $receiptList )) { // generated files
  6367. ob_start ();
  6368. $this->render ( "/admin/saea_myList", $data );
  6369. $this->cacheFile ( $path );
  6370. die ();
  6371. }
  6372. }
  6373. }
  6374. $this->render ( "/admin/saea_myList", $data );
  6375. }
  6376. function saeaCreate() {
  6377. Doo::loadModel ( 'accountItem' );
  6378. Doo::loadModel ( 'verify' );
  6379. Doo::loadModel ( 'receipt' );
  6380. Doo::loadModel ( 'L_category' );
  6381. $lCategory = new L_category ();
  6382. $receipt = new receipt ();
  6383. $verify = new verify ();
  6384. $accountItem = new accountItem ();
  6385. Doo::loadModel ( "role" );
  6386. $role = new role ();
  6387. $acItem = $accountItem->find ( array (
  6388. 'asArray' => true
  6389. ) );
  6390. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6391. $data ['category'] = $lCategory->find ( array (
  6392. 'asArray' => true
  6393. ) );
  6394. $data ['veList'] = $veList;
  6395. $data ['acItem'] = $acItem;
  6396. $data ['memu'] = "receipt";
  6397. $data ['staff'] = $this->staff;
  6398. $data ['receiptMemu'] = 'saeaBorad';
  6399. $data ['verifyId'] = $this->verifyId;
  6400. $data ['executeId'] = $this->executeId;
  6401. $this->render ( "/admin/saea_create", $data );
  6402. }
  6403. function addReceipt() {
  6404. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6405. $agency = $this->get_args ( 'agency' );
  6406. $travel = $this->get_args ( 'travel' );
  6407. $train = $this->get_args ( 'train' );
  6408. $other = $this->get_args ( 'other' );
  6409. $inttrain = $this->get_args ( 'inttrain' );
  6410. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6411. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6412. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6413. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6414. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6415. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6416. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6417. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6418. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6419. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6420. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6421. header ( 'Content-Type:text/html;charset=utf-8' );
  6422. die ( '请填写联行号' );
  6423. }
  6424. Doo::loadModel ( 'receipt' );
  6425. Doo::loadModel ( 'receiptDetail' );
  6426. Doo::loadModel ( 'accountItem' );
  6427. $accountItem = new accountItem ();
  6428. $receipt = new receipt ();
  6429. Doo::loadModel ( 'enclosur' );
  6430. Doo::loadModel ( 'execute' );
  6431. $execute = new execute ();
  6432. $executeDetail = $execute->getOne ( array (
  6433. 'where' => 'mold="报销单执行人"',
  6434. 'asArray' => true
  6435. ) );
  6436. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6437. // if(!empty($receiptDetail))
  6438. // return "/referReceipt/".$receiptDetail['rid'];
  6439. $aItem = $accountItem->find ( array (
  6440. 'asArray' => true
  6441. ) );
  6442. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6443. $ag = $tr = $ta = $ot= $it = 0;
  6444. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6445. foreach ( $aItem as $key => $value ) {
  6446. if ($value ['category'] == $this->AGENCY) {
  6447. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6448. array_push ( $accountJson [$this->AGENCY], array (
  6449. 'aid' => $value ['aid'],
  6450. 'name' => $value ['name'],
  6451. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6452. ) );
  6453. $sum += $agency [$ag];
  6454. $agencySum += $agency [$ag];
  6455. }
  6456. $ag ++;
  6457. }
  6458. if ($value ['category'] == $this->TRAVEL) {
  6459. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6460. array_push ( $accountJson [$this->TRAVEL], array (
  6461. 'aid' => $value ['aid'],
  6462. 'name' => $value ['name'],
  6463. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6464. ) );
  6465. $sum += $travel [$tr];
  6466. $travelSum += $travel [$tr];
  6467. }
  6468. $tr ++;
  6469. }
  6470. if ($value ['category'] == $this->TRAIN) {
  6471. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6472. array_push ( $accountJson [$this->TRAIN], array (
  6473. 'aid' => $value ['aid'],
  6474. 'name' => $value ['name'],
  6475. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6476. ) );
  6477. $sum += $train [$ta];
  6478. $trainSum += $train [$ta];
  6479. }
  6480. $ta ++;
  6481. }
  6482. if ($value ['category'] == $this->INTTRAIN) {
  6483. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6484. array_push ( $accountJson [$this->INTTRAIN], array (
  6485. 'aid' => $value ['aid'],
  6486. 'name' => $value ['name'],
  6487. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6488. ) );
  6489. $sum += $inttrain [$it];
  6490. $inttrainSum += $inttrain [$it];
  6491. }
  6492. $it ++;
  6493. }
  6494. if ($value ['category'] == $this->OTHER) {
  6495. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6496. array_push ( $accountJson [$this->OTHER], array (
  6497. 'aid' => $value ['aid'],
  6498. 'name' => $value ['name'],
  6499. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6500. ) );
  6501. $sum += $other [$ot];
  6502. $otherSum += $other [$ot];
  6503. }
  6504. $ot ++;
  6505. }
  6506. }
  6507. $accountJson ['cSum'] = array (
  6508. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6509. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6510. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6511. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6512. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6513. );
  6514. // 报销单
  6515. $receipt->accountItem = json_encode ( $accountJson );
  6516. $receipt->staff = $this->staff [0] ['sid'];
  6517. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6518. $receipt->date = date ( "Y-m-d" );
  6519. $receipt->cid = $cid;
  6520. $receipt->status = 5;
  6521. // 修改审批流程加入角色
  6522. $receipt->verify = $verify;
  6523. $receipt->executeCopy = $executeDetail ['staff'];
  6524. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6525. $order = array (
  6526. "\r\n",
  6527. "\n",
  6528. "\r"
  6529. );
  6530. $replace = '<br/>';
  6531. $explanation = str_replace ( $order, $replace, $explanation );
  6532. $receipt->explanation = $explanation;
  6533. $receipt->remittanceName = $remittanceName;
  6534. $receipt->bankName = $bankName;
  6535. $receipt->bankNumber = $bankNumber;
  6536. $receipt->remittanceBankType = $remittanceBankType;
  6537. if ($remittanceBankType == 1)
  6538. $receipt->coupletNumber = $coupletNumber;
  6539. $rid = $receipt->insert ();
  6540. // 附件
  6541. if (! empty ( $enclosurName )) {
  6542. $enclosurArray = explode ( '-', $enclosurName );
  6543. foreach ( $enclosurArray as $value ) {
  6544. $enclosur = new enclosur ();
  6545. $enclosur->name = $value;
  6546. $enclosur->rid = $rid;
  6547. $enclosur->insert ();
  6548. }
  6549. // print_r($enclosurArray);die;
  6550. }
  6551. // 报销详情
  6552. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6553. $receiptDetail = new receiptDetail ();
  6554. $receiptDetail->staff = $this->staff [0] ['sid'];
  6555. $receiptDetail->item = $value ['name'];
  6556. $receiptDetail->itemCategory = $this->AGENCY;
  6557. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6558. $receiptDetail->date = date ( "Y-m-d" );
  6559. $receiptDetail->cid = $cid;
  6560. $receiptDetail->rid = $rid;
  6561. $receiptDetail->status = 4;
  6562. $receiptDetail->insert ();
  6563. }
  6564. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6565. $receiptDetail = new receiptDetail ();
  6566. $receiptDetail->staff = $this->staff [0] ['sid'];
  6567. $receiptDetail->item = $value ['name'];
  6568. $receiptDetail->itemCategory = $this->TRAVEL;
  6569. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6570. $receiptDetail->date = date ( "Y-m-d" );
  6571. $receiptDetail->cid = $cid;
  6572. $receiptDetail->rid = $rid;
  6573. $receiptDetail->status = 4;
  6574. $receiptDetail->insert ();
  6575. }
  6576. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6577. $receiptDetail = new receiptDetail ();
  6578. $receiptDetail->staff = $this->staff [0] ['sid'];
  6579. $receiptDetail->item = $value ['name'];
  6580. $receiptDetail->itemCategory = $this->TRAIN;
  6581. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6582. $receiptDetail->date = date ( "Y-m-d" );
  6583. $receiptDetail->cid = $cid;
  6584. $receiptDetail->rid = $rid;
  6585. $receiptDetail->status = 4;
  6586. $receiptDetail->insert ();
  6587. }
  6588. //内训
  6589. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6590. $receiptDetail = new receiptDetail ();
  6591. $receiptDetail->staff = $this->staff [0] ['sid'];
  6592. $receiptDetail->item = $value ['name'];
  6593. $receiptDetail->itemCategory = $this->INTTRAIN;
  6594. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6595. $receiptDetail->date = date ( "Y-m-d" );
  6596. $receiptDetail->cid = $cid;
  6597. $receiptDetail->rid = $rid;
  6598. $receiptDetail->status = 4;
  6599. $receiptDetail->insert ();
  6600. }
  6601. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6602. $receiptDetail = new receiptDetail ();
  6603. $receiptDetail->staff = $this->staff [0] ['sid'];
  6604. $receiptDetail->item = $value ['name'];
  6605. $receiptDetail->itemCategory = $this->OTHER;
  6606. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6607. $receiptDetail->date = date ( "Y-m-d" );
  6608. $receiptDetail->cid = $cid;
  6609. $receiptDetail->rid = $rid;
  6610. $receiptDetail->status = 4;
  6611. $receiptDetail->insert ();
  6612. }
  6613. return "/saeaBorad";
  6614. } else
  6615. die ( 'illegal request' );
  6616. }
  6617. function referReceipt() {
  6618. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6619. Doo::loadModel ( 'receipt' );
  6620. Doo::loadModel ( 'verify' );
  6621. $verify = new verify ();
  6622. $receipt = new receipt ();
  6623. Doo::loadModel ( 'L_category' );
  6624. $lCategory = new L_category ();
  6625. Doo::loadModel ( "role" );
  6626. $role = new role ();
  6627. $receiptDetail = $receipt->find ( array (
  6628. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6629. 'asArray' => true
  6630. ) );
  6631. if (empty ( $receiptDetail ))
  6632. return "/addReceipt";
  6633. foreach ( $receiptDetail as $key => $value ) {
  6634. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6635. $veList = $verify->getOne ( array (
  6636. 'where' => 'vid=' . $value ['verify'],
  6637. 'asArray' => true
  6638. ) );
  6639. $v = json_decode ( $veList ['staff'] );
  6640. array_push ( $v [0], $veList ['description'] );
  6641. foreach ( $v as $n => $m ) {
  6642. if ($m ['1'] == 'ROLE') {
  6643. $roleInfo = $role->getOne ( array (
  6644. 'where' => 'rid=' . $m [0],
  6645. 'asArray' => true
  6646. ) );
  6647. $v [$n] [1] = $roleInfo ['name'];
  6648. }
  6649. }
  6650. $receiptDetail [$key] ['staff'] = $v;
  6651. $category = $lCategory->getOne ( array (
  6652. 'where' => 'cid=' . $value ['cid'],
  6653. 'asArray' => true
  6654. ) );
  6655. $receiptDetail [$key] ['category'] = $category ['title'];
  6656. }
  6657. // print_r($receiptDetail);
  6658. $data ['receiptDetail'] = $receiptDetail;
  6659. $data ['memu'] = "receipt";
  6660. $data ['staff'] = $this->staff;
  6661. $data ['receiptMemu'] = 'saeaCreate';
  6662. $data ['verifyId'] = $this->verifyId;
  6663. $data ['executeId'] = $this->executeId;
  6664. $this->render ( "/admin/saea_confirm", $data );
  6665. }
  6666. function editReceipt() {
  6667. // edit status 4
  6668. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6669. Doo::loadClass ( 'XDeode' );
  6670. $XDeode = new XDeode ( 7 );
  6671. $rid = $XDeode->decode ( $ridKey );
  6672. if (empty ( $rid ))
  6673. die ( 'illegal request' );
  6674. // echo $rid.'sd';
  6675. Doo::loadModel ( 'accountItem' );
  6676. Doo::loadModel ( 'verify' );
  6677. Doo::loadModel ( 'receipt' );
  6678. $receipt = new receipt ();
  6679. $verify = new verify ();
  6680. $accountItem = new accountItem ();
  6681. Doo::loadModel ( 'L_category' );
  6682. $lCategory = new L_category ();
  6683. Doo::loadModel ( "role" );
  6684. $role = new role ();
  6685. Doo::loadModel ( 'enclosur' );
  6686. $enclosur = new enclosur ();
  6687. $receiptDetail = $receipt->getOne ( array (
  6688. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6689. 'asArray' => true
  6690. ) );
  6691. if (empty ( $receiptDetail ))
  6692. die ( 'illegal request' );
  6693. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6694. $acItem = $accountItem->find ( array (
  6695. 'asArray' => true
  6696. ) );
  6697. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6698. // 配置编辑信息
  6699. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6700. foreach ( $acItem as $key => $value ) {
  6701. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6702. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6703. $acItem [$key] ['price'] = $v ['price'];
  6704. }
  6705. }
  6706. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6707. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6708. $acItem [$key] ['price'] = $v ['price'];
  6709. }
  6710. }
  6711. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6712. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6713. $acItem [$key] ['price'] = $v ['price'];
  6714. }
  6715. }
  6716. //内训
  6717. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6718. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6719. $acItem [$key] ['price'] = $v ['price'];
  6720. }
  6721. }
  6722. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6723. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6724. $acItem [$key] ['price'] = $v ['price'];
  6725. }
  6726. }
  6727. }
  6728. $data ['category'] = $lCategory->find ( array (
  6729. 'asArray' => true
  6730. ) );
  6731. $data ['cSum'] = $accountItemList ['cSum'];
  6732. $data ['sum'] = $receiptDetail ['sum'];
  6733. $data ['enclosurList'] = $enclosurList;
  6734. $data ['receiptDetail'] = $receiptDetail;
  6735. $data ['veList'] = $veList;
  6736. $data ['acItem'] = $acItem;
  6737. $data ['memu'] = "receipt";
  6738. $data ['staff'] = $this->staff;
  6739. $data ['receiptMemu'] = 'saeaBorad';
  6740. $data ['verify'] = $receiptDetail ['verify'];
  6741. $data ['verifyId'] = $this->verifyId;
  6742. $data ['executeId'] = $this->executeId;
  6743. $data ['rid'] = $ridKey;
  6744. $this->render ( "/admin/saea_edit", $data );
  6745. }
  6746. function updateReceipt() {
  6747. $agency = $this->get_args ( 'agency' );
  6748. $travel = $this->get_args ( 'travel' );
  6749. $train = $this->get_args ( 'train' );
  6750. $other = $this->get_args ( 'other' );
  6751. $inttrain = $this->get_args ( 'inttrain' );
  6752. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6753. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6754. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6755. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6756. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6757. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6758. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6759. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6760. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6761. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6762. Doo::loadClass ( 'XDeode' );
  6763. $XDeode = new XDeode ( 7 );
  6764. $rid = $XDeode->decode ( $ridKey );
  6765. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6766. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6767. header ( 'Content-Type:text/html;charset=utf-8' );
  6768. die ( '请填写联行号' );
  6769. }
  6770. Doo::loadModel ( 'receipt' );
  6771. Doo::loadModel ( 'receiptDetail' );
  6772. Doo::loadModel ( 'accountItem' );
  6773. $accountItem = new accountItem ();
  6774. $receipt = new receipt ();
  6775. Doo::loadModel ( 'enclosur' );
  6776. Doo::loadModel ( 'execute' );
  6777. $execute = new execute ();
  6778. $receiptDetail = $receipt->getOne ( array (
  6779. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6780. 'asArray' => true
  6781. ) );
  6782. if (empty ( $receiptDetail ))
  6783. return "/saeaBorad";
  6784. if ($receiptDetail ['Rtype'] == 1)
  6785. $executeDetail = $execute->getOne ( array (
  6786. 'where' => 'mold="借款费用执行人"',
  6787. 'asArray' => true
  6788. ) );
  6789. else
  6790. $executeDetail = $execute->getOne ( array (
  6791. 'where' => 'mold="报销单执行人"',
  6792. 'asArray' => true
  6793. ) );
  6794. $aItem = $accountItem->find ( array (
  6795. 'asArray' => true
  6796. ) );
  6797. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6798. $ag = $tr = $ta = $ot = $it = 0 ;
  6799. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6800. foreach ( $aItem as $key => $value ) {
  6801. if ($value ['category'] == $this->AGENCY) {
  6802. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6803. array_push ( $accountJson [$this->AGENCY], array (
  6804. 'aid' => $value ['aid'],
  6805. 'name' => $value ['name'],
  6806. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6807. ) );
  6808. $sum += $agency [$ag];
  6809. $agencySum += $agency [$ag];
  6810. }
  6811. $ag ++;
  6812. }
  6813. if ($value ['category'] == $this->TRAVEL) {
  6814. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6815. array_push ( $accountJson [$this->TRAVEL], array (
  6816. 'aid' => $value ['aid'],
  6817. 'name' => $value ['name'],
  6818. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6819. ) );
  6820. $sum += $travel [$tr];
  6821. $travelSum += $travel [$tr];
  6822. }
  6823. $tr ++;
  6824. }
  6825. if ($value ['category'] == $this->TRAIN) {
  6826. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6827. array_push ( $accountJson [$this->TRAIN], array (
  6828. 'aid' => $value ['aid'],
  6829. 'name' => $value ['name'],
  6830. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6831. ) );
  6832. $sum += $train [$ta];
  6833. $trainSum += $train [$ta];
  6834. }
  6835. $ta ++;
  6836. }
  6837. if ($value ['category'] == $this->INTTRAIN) {
  6838. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6839. array_push ( $accountJson [$this->INTTRAIN], array (
  6840. 'aid' => $value ['aid'],
  6841. 'name' => $value ['name'],
  6842. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6843. ) );
  6844. $sum += $inttrain [$it];
  6845. $inttrainSum += $inttrain [$it];
  6846. }
  6847. $it ++;
  6848. }
  6849. if ($value ['category'] == $this->OTHER) {
  6850. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6851. array_push ( $accountJson [$this->OTHER], array (
  6852. 'aid' => $value ['aid'],
  6853. 'name' => $value ['name'],
  6854. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6855. ) );
  6856. $sum += $other [$ot];
  6857. $otherSum += $other [$ot];
  6858. }
  6859. $ot ++;
  6860. }
  6861. }
  6862. $accountJson ['cSum'] = array (
  6863. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6864. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6865. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6866. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6867. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6868. );
  6869. // 报销单
  6870. $rid = $receipt->rid = $receiptDetail ['rid'];
  6871. $receipt->accountItem = json_encode ( $accountJson );
  6872. $receipt->staff = $this->staff [0] ['sid'];
  6873. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6874. $receipt->date = date ( "Y-m-d" );
  6875. $receipt->cid = $cid;
  6876. if (($receiptDetail ['status'] != 4)) {
  6877. if ($receiptDetail ['Rtype'] == 1)
  6878. $receipt->status = 7;
  6879. else
  6880. $receipt->status = 5;
  6881. }
  6882. if ($receiptDetail != 4 && ! empty ( $verify ))
  6883. $receipt->verify = $verify;
  6884. $receipt->executeCopy = $executeDetail ['staff'];
  6885. $order = array (
  6886. "\r\n",
  6887. "\n",
  6888. "\r"
  6889. );
  6890. $replace = '<br/>';
  6891. $explanation = str_replace ( $order, $replace, $explanation );
  6892. $receipt->explanation = $explanation;
  6893. $receipt->remittanceName = $remittanceName;
  6894. $receipt->bankName = $bankName;
  6895. $receipt->bankNumber = $bankNumber;
  6896. $receipt->remittanceBankType = $remittanceBankType;
  6897. if ($remittanceBankType == 1)
  6898. $receipt->coupletNumber = $coupletNumber;
  6899. $receipt->update ();
  6900. $receiptDetail = new receiptDetail ();
  6901. $receiptDetail->delete ( array (
  6902. 'where' => 'rid=' . $rid
  6903. ) );
  6904. // 报销详情
  6905. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6906. $receiptDetail = new receiptDetail ();
  6907. $receiptDetail->staff = $this->staff [0] ['sid'];
  6908. $receiptDetail->item = $value ['name'];
  6909. $receiptDetail->itemCategory = $this->AGENCY;
  6910. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6911. $receiptDetail->date = date ( "Y-m-d" );
  6912. $receiptDetail->cid = $cid;
  6913. $receiptDetail->rid = $rid;
  6914. $receiptDetail->status = 4;
  6915. $receiptDetail->insert ();
  6916. }
  6917. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6918. $receiptDetail = new receiptDetail ();
  6919. $receiptDetail->staff = $this->staff [0] ['sid'];
  6920. $receiptDetail->item = $value ['name'];
  6921. $receiptDetail->itemCategory = $this->TRAVEL;
  6922. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6923. $receiptDetail->date = date ( "Y-m-d" );
  6924. $receiptDetail->cid = $cid;
  6925. $receiptDetail->rid = $rid;
  6926. $receiptDetail->status = 4;
  6927. $receiptDetail->insert ();
  6928. }
  6929. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6930. $receiptDetail = new receiptDetail ();
  6931. $receiptDetail->staff = $this->staff [0] ['sid'];
  6932. $receiptDetail->item = $value ['name'];
  6933. $receiptDetail->itemCategory = $this->TRAIN;
  6934. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6935. $receiptDetail->date = date ( "Y-m-d" );
  6936. $receiptDetail->cid = $cid;
  6937. $receiptDetail->rid = $rid;
  6938. $receiptDetail->status = 4;
  6939. $receiptDetail->insert ();
  6940. }
  6941. //内训
  6942. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6943. $receiptDetail = new receiptDetail ();
  6944. $receiptDetail->staff = $this->staff [0] ['sid'];
  6945. $receiptDetail->item = $value ['name'];
  6946. $receiptDetail->itemCategory = $this->INTTRAIN;
  6947. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6948. $receiptDetail->date = date ( "Y-m-d" );
  6949. $receiptDetail->cid = $cid;
  6950. $receiptDetail->rid = $rid;
  6951. $receiptDetail->status = 4;
  6952. $receiptDetail->insert ();
  6953. }
  6954. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6955. $receiptDetail = new receiptDetail ();
  6956. $receiptDetail->staff = $this->staff [0] ['sid'];
  6957. $receiptDetail->item = $value ['name'];
  6958. $receiptDetail->itemCategory = $this->OTHER;
  6959. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6960. $receiptDetail->date = date ( "Y-m-d" );
  6961. $receiptDetail->cid = $cid;
  6962. $receiptDetail->rid = $rid;
  6963. $receiptDetail->status = 4;
  6964. $receiptDetail->insert ();
  6965. }
  6966. // 附件
  6967. if (! empty ( $enclosurName )) {
  6968. $enclosurArray = explode ( '-', $enclosurName );
  6969. foreach ( $enclosurArray as $value ) {
  6970. $enclosur = new enclosur ();
  6971. $enclosur->name = $value;
  6972. $enclosur->rid = $rid;
  6973. $enclosur->insert ();
  6974. }
  6975. }
  6976. // return "/referReceipt/".$rid;
  6977. }
  6978. return "/saeaBorad";
  6979. }
  6980. function approvedReceipt() {
  6981. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6982. Doo::loadModel ( 'receipt' );
  6983. Doo::loadModel ( 'receiptDetail' );
  6984. $receipt = new receipt ();
  6985. $receiptDetail = new receiptDetail ();
  6986. Doo::loadModel ( 'statistics' );
  6987. Doo::loadModel ( 'itemStatistics' );
  6988. $statistics = new statistics ();
  6989. $itemStatistics = new itemStatistics ();
  6990. Doo::loadModel ( "verify" );
  6991. $verify = new verify ();
  6992. // 审批状态的判定
  6993. $receiptDetailList = $receipt->getOne ( array (
  6994. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  6995. 'asArray' => true
  6996. ) );
  6997. if (empty ( $receiptDetailList ))
  6998. return "/saeaBorad";
  6999. $verifyDetail = $verify->getOne ( array (
  7000. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7001. 'asArray' => true
  7002. ) );
  7003. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7004. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7005. $nowStaff = "";
  7006. $nowStaffList = array ();
  7007. if ($verifyDetail [0] [1] == 'ROLE') {
  7008. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7009. foreach ( $vStaffString as $key => $value ) {
  7010. $staffK = explode ( "_", $value );
  7011. array_push ( $nowStaffList, $staffK [0] );
  7012. }
  7013. $nowStaff = implode ( ',', $nowStaffList );
  7014. } else {
  7015. $nowStaff = $verifyDetail [0] [0];
  7016. }
  7017. $receipt->nowStaff = $nowStaff;
  7018. }
  7019. // echo $nowStaff;
  7020. // print_r($verifyDetail);die;
  7021. $receipt->rid = $receiptDetailList ['rid'];
  7022. $receipt->date = date ( "Y-m-d" );
  7023. $receipt->status = 2;
  7024. $receipt->update ();
  7025. $receiptDetail->status = 2;
  7026. $receiptDetail->update ( array (
  7027. 'where' => 'rid=' . $receiptDetailList ['rid']
  7028. ) );
  7029. Doo::loadModel ( "receiptLog" );
  7030. $receiptLog = new receiptLog ();
  7031. Doo::loadModel ( "verify" );
  7032. $verify = new verify ();
  7033. $receiptInfo = $receipt->getOne ( array (
  7034. 'where' => 'rid=' . $rid,
  7035. 'asArray' => true
  7036. ) );
  7037. $vr = $verify->getOne ( array (
  7038. 'where' => 'vid=' . $receiptInfo ['verify'],
  7039. 'asArray' => true
  7040. ) );
  7041. $jd = json_decode ( $vr ['staff'] );
  7042. $roleId = 0;
  7043. foreach ( $jd as $key => $value ) {
  7044. if ($value [1] == 'ROLE') {
  7045. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7046. if ($pos !== false) {
  7047. $roleId = $value [0];
  7048. }
  7049. }
  7050. }
  7051. // 审批日志
  7052. // echo $roleId;die;
  7053. if (! empty ( $roleId )) {
  7054. Doo::loadModel ( "role" );
  7055. $role = new role ();
  7056. $roleInfo = $role->getOne ( array (
  7057. 'where' => 'rid=' . $roleId,
  7058. 'asArray' => true
  7059. ) );
  7060. // $receiptLog->rolename = $roleInfo ['name'];
  7061. }
  7062. $receiptLog->username = $this->staff [0] ['username'];
  7063. $receiptLog->uid = $this->staff [0] ['sid'];
  7064. $receiptLog->date = date ( "Y-m-d" );
  7065. $receiptLog->opinion = '提交审批';
  7066. $receiptLog->img = $this->staff [0] ['avatar'];
  7067. $receiptLog->status = 2;
  7068. $receiptLog->rid = $rid;
  7069. $receiptLog->insert ();
  7070. // statistics item
  7071. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7072. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7073. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7074. $stat = $statistics->getOne ( array (
  7075. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7076. 'asArray' => true
  7077. ) );
  7078. if (empty ( $stat )) {
  7079. $statistics->date = date ( "Y-m-d" );
  7080. $statistics->cid = $this->staff [0] ['cid'];
  7081. $statistics->staff = $this->staff [0] ['sid'];
  7082. $statistics->agPrice = 0;
  7083. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7084. $statistics->insert ();
  7085. } else {
  7086. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7087. $statistics->update ( array (
  7088. 'where' => 'sid=' . $stat ['sid']
  7089. ) );
  7090. }
  7091. return "/expenses";
  7092. }
  7093. function approval() {
  7094. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7095. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7096. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7097. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7098. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7099. if (empty ( $status ))
  7100. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7101. $vidList = array ();
  7102. $button = 0;
  7103. Doo::loadModel ( 'verify' );
  7104. $verify = new verify ();
  7105. Doo::loadModel ( 'receipt' );
  7106. $receipt = new receipt ();
  7107. Doo::loadModel ( 'staff' );
  7108. $staff = new staff ();
  7109. Doo::loadModel ( 'L_category' );
  7110. $Lcategory = new L_category ();
  7111. // user verify ID
  7112. $verifyDetail = $verify->find ( array (
  7113. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7114. 'asArray' => true
  7115. ) );
  7116. foreach ( $verifyDetail as $key => $value ) {
  7117. array_push ( $vidList, $value ['vid'] );
  7118. }
  7119. $vid = implode ( ",", $vidList );
  7120. if (empty ( $verifyDetail ))
  7121. $vid = 0;
  7122. /*
  7123. */
  7124. $dateCondition = " and Year(date) =" . $year;
  7125. if (! empty ( $month ))
  7126. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7127. $categoryList = $Lcategory->find ( array (
  7128. 'asArray' => true
  7129. ) );
  7130. $staffList = $staff->find ( array (
  7131. 'where' => 'cid=' . $cid,
  7132. 'asArray' => true
  7133. ) );
  7134. $cateCondition = "";
  7135. $staffCondition = "";
  7136. $approvalCondition = "";
  7137. if (! empty ( $cid ))
  7138. $cateCondition = ' and cid=' . $cid;
  7139. if (! empty ( $sid )) {
  7140. $staffCondition = ' and staff=' . $sid;
  7141. $cateCondition = "";
  7142. }
  7143. // elseif($status==1){
  7144. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7145. // }
  7146. if ($status == 2) {
  7147. // 查找角色审批人
  7148. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7149. }
  7150. $ap = "";
  7151. if ($status == 4) {
  7152. $ap = 4;
  7153. $status = 2;
  7154. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7155. }
  7156. if ($status == 5) {
  7157. $status = 4;
  7158. $ap = 5;
  7159. }
  7160. // echo $vid;
  7161. // get Receipt By verifyID status 2 .$approvalCondition
  7162. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7163. $receiptList = $receipt->find ( array (
  7164. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7165. 'desc' => 'rid',
  7166. 'asArray' => true
  7167. ) );
  7168. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7169. $Locate = 0;
  7170. if ($ap == 4)
  7171. $status = 4;
  7172. elseif ($ap == 5)
  7173. $status = 5;
  7174. foreach ( $receiptList as $key => $value ) {
  7175. $receiptList [$key] ['Locate'] = $Locate;
  7176. $Locate ++;
  7177. $receiptList [$key] ['reviseDetail'] = array ();
  7178. if (! empty ( $value ['reviseDetail'] ))
  7179. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7180. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7181. $categoryDetil = $Lcategory->getOne ( array (
  7182. 'where' => 'cid=' . $value ['cid'],
  7183. 'asArray' => true
  7184. ) );
  7185. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7186. $verifyList = $verify->getOne ( array (
  7187. 'where' => 'vid=' . $value ['verify'],
  7188. 'asArray' => true
  7189. ) );
  7190. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7191. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7192. foreach ( $verifyList as $k => $v ) {
  7193. // init verifyStaff
  7194. $verifyList [$k] ['date'] = "";
  7195. $verifyList [$k] ['opinion'] = "";
  7196. $verifyList [$k] ['status'] = "";
  7197. if (empty ( $verifyStaff )) {
  7198. $verifyList [$k] ['date'] = "";
  7199. $verifyList [$k] ['opinion'] = "";
  7200. if ($v [0] == $this->staff [0] ['sid']) {
  7201. $verifyList [$k] ['status'] = 4;
  7202. $button = 4;
  7203. }
  7204. } else {
  7205. $flag = true;
  7206. foreach ( $verifyStaff as $m => $u ) {
  7207. if ($v [0] == $m) {
  7208. $verifyList [$k] ['date'] = $u ['date'];
  7209. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7210. $verifyList [$k] ['status'] = $u ['status'];
  7211. $flag = false;
  7212. break;
  7213. }
  7214. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7215. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7216. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7217. }
  7218. if ($flag) { // 检测可编辑
  7219. if ($v [0] == $this->staff [0] ['sid']) {
  7220. $verifyList [$k] ['status'] = 4;
  7221. $button = 4;
  7222. }
  7223. }
  7224. }
  7225. }
  7226. $receiptList [$key] ['verifyList'] = $verifyList;
  7227. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7228. 'where' => 'sid=' . $value ['staff'],
  7229. 'asArray' => true
  7230. ) );
  7231. $receiptList [$key] ['button'] = $button;
  7232. }
  7233. // print_r($receiptList);die;
  7234. // $data['verifyDetail']=$verifyDetail;
  7235. $mothHtml = "";
  7236. for($i = 1; $i <= 12; $i ++) {
  7237. if ($month == $i)
  7238. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7239. else
  7240. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7241. }
  7242. $data ['mothHtml'] = $mothHtml;
  7243. $data ['receiptList'] = $receiptList;
  7244. $data ['receiptApprovalCount'] = count ( $receiptList );
  7245. $data ['status'] = $status;
  7246. $data ['year'] = $year;
  7247. $data ['categoryList'] = $categoryList;
  7248. $data ['staffList'] = $staffList;
  7249. $data ['cid'] = $cid;
  7250. $data ['sid'] = $sid;
  7251. $data ['ap'] = $ap;
  7252. $data ['memu'] = "receipt";
  7253. $data ['staff'] = $this->staff;
  7254. $data ['receiptMemu'] = 'approval';
  7255. $data ['verifyId'] = $this->verifyId;
  7256. $data ['executeId'] = $this->executeId;
  7257. $this->render ( "/admin/saea_reportList", $data );
  7258. }
  7259. function approvalDetails() {
  7260. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7261. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7262. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7263. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7264. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7265. Doo::loadModel ( 'verify' );
  7266. $verify = new verify ();
  7267. Doo::loadModel ( 'receipt' );
  7268. $receipt = new receipt ();
  7269. Doo::loadModel ( 'staff' );
  7270. $staff = new staff ();
  7271. Doo::loadModel ( 'L_category' );
  7272. $Lcategory = new L_category ();
  7273. Doo::loadModel ( 'enclosur' );
  7274. $enclosur = new enclosur ();
  7275. $vidList = array ();
  7276. $verifyDetail = $verify->find ( array (
  7277. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7278. 'asArray' => true
  7279. ) );
  7280. foreach ( $verifyDetail as $key => $value ) {
  7281. array_push ( $vidList, $value ['vid'] );
  7282. }
  7283. $vid = implode ( ",", $vidList );
  7284. if (empty ( $verifyDetail ))
  7285. $vid = 0;
  7286. $categoryList = $Lcategory->find ( array (
  7287. 'asArray' => true
  7288. ) );
  7289. $staffList = $staff->find ( array (
  7290. 'where' => 'cid=' . $cid,
  7291. 'asArray' => true
  7292. ) );
  7293. $ap = 0;
  7294. $receiptList = $receipt->find ( array (
  7295. 'where' => 'rid =' . $rid,
  7296. 'desc' => 'rid',
  7297. 'asArray' => true
  7298. ) );
  7299. $Locate = 0;
  7300. $roleId = 0;
  7301. $button = 0;
  7302. foreach ( $receiptList as $key => $value ) {
  7303. $receiptList [$key] ['Locate'] = $Locate;
  7304. $Locate ++;
  7305. $receiptList [$key] ['reviseDetail'] = array ();
  7306. if (! empty ( $value ['reviseDetail'] ))
  7307. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7308. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7309. $categoryDetil = $Lcategory->getOne ( array (
  7310. 'where' => 'cid=' . $value ['cid'],
  7311. 'asArray' => true
  7312. ) );
  7313. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7314. // 检测编辑状态
  7315. $verifyList = $verify->getOne ( array (
  7316. 'where' => 'vid=' . $value ['verify'],
  7317. 'asArray' => true
  7318. ) );
  7319. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7320. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7321. Doo::loadModel ( 'role' );
  7322. $role = new role ();
  7323. // print_r($verifyList);
  7324. $flag = true;
  7325. $roleKey = 0;
  7326. $endStaffArray = array ();
  7327. $roleArrayCopy = array ();
  7328. foreach ( $verifyList as $k => $v ) {
  7329. // init verifyStaff
  7330. if ($v [1] == 'ROLE') {
  7331. if (! empty ( $verifyStaff )) {
  7332. $endStaffArray = end ( $verifyStaff );
  7333. if ($v [0] == $endStaffArray ['nextStaff']) {
  7334. $roleId = $v [0];
  7335. }
  7336. }
  7337. $roleVerify = json_decode ( $v [3], true );
  7338. $roleKey = $k;
  7339. $roleArray = array ();
  7340. $rolename = $role->getOne ( array (
  7341. 'where' => 'rid=' . $v [0],
  7342. 'asArray' => true
  7343. ) );
  7344. foreach ( $roleVerify as $o => $p ) {
  7345. $staffID = explode ( '_', $p );
  7346. $staffInfo = $staff->getOne ( array (
  7347. 'where' => 'sid=' . $staffID [0],
  7348. 'asArray' => true
  7349. ) );
  7350. // print_r($staffID);
  7351. $exp = array (
  7352. 0 => $staffInfo ['sid'],
  7353. 1 => $staffID [1],
  7354. 2 => $staffInfo ['avatar'],
  7355. 'date' => '',
  7356. 'date' => '',
  7357. 'opinion' => '',
  7358. 'status' => '',
  7359. 'rolename' => $rolename ['name']
  7360. );
  7361. array_push ( $roleArray, $exp );
  7362. }
  7363. $roleArrayCopy [$v [0]] = $roleArray;
  7364. // $verifyList[$k]['roleArray']=$roleArray;
  7365. }
  7366. // print_r($roleArray);
  7367. $verifyList [$k] ['date'] = "";
  7368. $verifyList [$k] ['opinion'] = "";
  7369. $verifyList [$k] ['status'] = "";
  7370. if (empty ( $verifyStaff )) {
  7371. $verifyList [$k] ['date'] = "";
  7372. $verifyList [$k] ['opinion'] = "";
  7373. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7374. $verifyList [$k] ['status'] = 4;
  7375. $button = 4;
  7376. $flag = false;
  7377. }
  7378. } else {
  7379. foreach ( $verifyStaff as $m => $u ) {
  7380. if ($v [0] == $m) {
  7381. $verifyList [$k] ['date'] = $u ['date'];
  7382. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7383. $verifyList [$k] ['status'] = $u ['status'];
  7384. $flag = false;
  7385. break;
  7386. }
  7387. }
  7388. $endStaffArray = end ( $verifyStaff );
  7389. if (isset ( $endStaffArray ['ROLE'] )) {
  7390. } else {
  7391. $endKey = key ( $verifyStaff );
  7392. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7393. $button = 4;
  7394. $verifyList [$k] ['status'] = 4;
  7395. }
  7396. }
  7397. }
  7398. }
  7399. $rolename ['name'] = '';
  7400. if (! empty ( $roleId )) {
  7401. Doo::loadModel ( 'role' );
  7402. $role = new role ();
  7403. $rolename = $role->getOne ( array (
  7404. 'where' => 'rid=' . $roleId,
  7405. 'asArray' => true
  7406. ) );
  7407. }
  7408. if (! empty ( $verifyStaff ))
  7409. $endStaffArray = end ( $verifyStaff );
  7410. $KOP = false;
  7411. foreach ( $roleArrayCopy as $P => $A ) {
  7412. foreach ( $A as $MKI => $AVL ) {
  7413. if (! empty ( $verifyStaff )) {
  7414. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7415. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7416. $button = 4;
  7417. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7418. }
  7419. foreach ( $verifyStaff as $m => $u ) {
  7420. $AVLFK = $AVL [0] . '_R';
  7421. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7422. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7423. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7424. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7425. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7426. break;
  7427. }
  7428. }
  7429. } else {
  7430. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7431. $button = 4;
  7432. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7433. }
  7434. }
  7435. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7436. $KOP = true;
  7437. }
  7438. }
  7439. foreach ( $roleArrayCopy as $k => $v ) {
  7440. foreach ( $verifyList as $m => $n ) {
  7441. if ($n [0] == $k) {
  7442. array_splice ( $verifyList, $m, 1, $v );
  7443. }
  7444. }
  7445. }
  7446. $receiptList [$key] ['verifyList'] = $verifyList;
  7447. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7448. 'where' => 'sid=' . $value ['staff'],
  7449. 'asArray' => true
  7450. ) );
  7451. $receiptList [$key] ['button'] = $button;
  7452. }
  7453. $mothHtml = "";
  7454. for($i = 1; $i <= 12; $i ++) {
  7455. if ($month == $i)
  7456. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7457. else
  7458. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7459. }
  7460. // 获取审批日志
  7461. Doo::loadModel ( 'receiptLog' );
  7462. $receiptLog = new receiptLog ();
  7463. $rlList = array ();
  7464. $rlInfo = $receiptLog->getOne ( array (
  7465. 'where' => 'rid=' . $rid . ' and status=4',
  7466. 'asArray' => true
  7467. ) );
  7468. $tijdate = $receiptLog->getOne ( array (
  7469. 'where' => 'rid=' . $rid . ' and status=2',
  7470. 'asc' => 'rlid',
  7471. 'asArray' => true
  7472. ) );
  7473. if (! empty ( $rlInfo )) {
  7474. $rlList = $receiptLog->find ( array (
  7475. 'where' => 'rid=' . $rid,
  7476. 'asc' => 'rlid',
  7477. 'asArray' => true
  7478. ) );
  7479. }
  7480. $receiptList [0] ['rlList'] = $rlList;
  7481. $enclosurList = $enclosur->find ( array (
  7482. 'where' => 'rid=' . $rid,
  7483. 'asArray' => true
  7484. ) );
  7485. $enclosurHtml = '';
  7486. foreach ( $enclosurList as $value ) {
  7487. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7488. }
  7489. $data ['enclosurHtml'] = $enclosurHtml;
  7490. $data ['rolename'] = $rolename ['name'];
  7491. $data ['datetij'] = $tijdate ['date'];
  7492. $data ['mothHtml'] = $mothHtml;
  7493. $data ['receiptList'] = $receiptList;
  7494. $data ['receiptApprovalCount'] = count ( $receiptList );
  7495. $data ['year'] = $year;
  7496. $data ['categoryList'] = $categoryList;
  7497. $data ['staffList'] = $staffList;
  7498. $data ['cid'] = $cid;
  7499. $data ['sid'] = $sid;
  7500. $data ['status'] = 0;
  7501. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7502. $ap = 4;
  7503. } else
  7504. $data ['status'] = $receiptList [0] ['status'];
  7505. if ($receiptList [0] ['status'] == 4) {
  7506. $data ['status'] = 5;
  7507. $ap = 0;
  7508. }
  7509. $data ['ap'] = $ap;
  7510. $data ['memu'] = "receipt";
  7511. $data ['staff'] = $this->staff;
  7512. $data ['receiptMemu'] = 'approval';
  7513. $data ['verifyId'] = $this->verifyId;
  7514. $data ['executeId'] = $this->executeId;
  7515. $this->render ( "/admin/saeaReportListReport", $data );
  7516. }
  7517. function approvalEdi() {
  7518. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7519. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7520. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7521. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7522. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7523. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7524. if (empty ( $status ))
  7525. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7526. $vidList = array ();
  7527. $button = 0;
  7528. Doo::loadModel ( 'verify' );
  7529. Doo::loadModel ( 'receipt' );
  7530. Doo::loadModel ( 'staff' );
  7531. $staff = new staff ();
  7532. $receipt = new receipt ();
  7533. $verify = new verify ();
  7534. Doo::loadModel ( 'L_category' );
  7535. $Lcategory = new L_category ();
  7536. Doo::loadModel ( 'enclosur' );
  7537. $enclosur = new enclosur ();
  7538. // user verify ID
  7539. $verifyDetail = $verify->find ( array (
  7540. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7541. 'asArray' => true
  7542. ) );
  7543. foreach ( $verifyDetail as $key => $value ) {
  7544. array_push ( $vidList, $value ['vid'] );
  7545. }
  7546. $vid = implode ( ",", $vidList );
  7547. if (empty ( $verifyDetail ))
  7548. $vid = 0;
  7549. $categoryList = $Lcategory->find ( array (
  7550. 'asArray' => true
  7551. ) );
  7552. $staffList = $staff->find ( array (
  7553. 'where' => 'cid=' . $cid,
  7554. 'asArray' => true
  7555. ) );
  7556. $ap = "";
  7557. if ($status == 4) {
  7558. $ap = 4;
  7559. $status = 2;
  7560. }
  7561. // get Receipt By verifyID status 2
  7562. $receiptList = $receipt->find ( array (
  7563. 'where' => 'rid =' . $rid,
  7564. 'desc' => 'rid',
  7565. 'asArray' => true
  7566. ) );
  7567. $Locate = 0;
  7568. $roleId = 0;
  7569. if ($ap == 4)
  7570. $status = 4;
  7571. foreach ( $receiptList as $key => $value ) {
  7572. $receiptList [$key] ['Locate'] = $Locate;
  7573. $Locate ++;
  7574. $receiptList [$key] ['reviseDetail'] = array ();
  7575. if (! empty ( $value ['reviseDetail'] ))
  7576. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7577. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7578. $categoryDetil = $Lcategory->getOne ( array (
  7579. 'where' => 'cid=' . $value ['cid'],
  7580. 'asArray' => true
  7581. ) );
  7582. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7583. // 检测编辑状态
  7584. $verifyList = $verify->getOne ( array (
  7585. 'where' => 'vid=' . $value ['verify'],
  7586. 'asArray' => true
  7587. ) );
  7588. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7589. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7590. // print_r($verifyList);
  7591. //
  7592. // if (empty($verifyStaff)){
  7593. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7594. // $verifyList[0]['status']=4;$button=4;
  7595. // }
  7596. //
  7597. // }else{
  7598. //
  7599. // }
  7600. // die;
  7601. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7602. // echo array_search("green",$a);
  7603. //
  7604. Doo::loadModel ( 'role' );
  7605. $role = new role ();
  7606. // print_r($verifyList);
  7607. $flag = true;
  7608. $roleKey = 0;
  7609. $endStaffArray = array ();
  7610. $roleArrayCopy = array ();
  7611. foreach ( $verifyList as $k => $v ) {
  7612. // init verifyStaff
  7613. if ($v [1] == 'ROLE') {
  7614. if (! empty ( $verifyStaff )) {
  7615. $endStaffArray = end ( $verifyStaff );
  7616. if ($v [0] == $endStaffArray ['nextStaff']) {
  7617. $roleId = $v [0];
  7618. }
  7619. }
  7620. $roleVerify = json_decode ( $v [3], true );
  7621. $roleKey = $k;
  7622. $roleArray = array ();
  7623. $rolename = $role->getOne ( array (
  7624. 'where' => 'rid=' . $v [0],
  7625. 'asArray' => true
  7626. ) );
  7627. foreach ( $roleVerify as $o => $p ) {
  7628. $staffID = explode ( '_', $p );
  7629. $staffInfo = $staff->getOne ( array (
  7630. 'where' => 'sid=' . $staffID [0],
  7631. 'asArray' => true
  7632. ) );
  7633. // print_r($staffID);
  7634. $exp = array (
  7635. 0 => $staffInfo ['sid'],
  7636. 1 => $staffID [1],
  7637. 2 => $staffInfo ['avatar'],
  7638. 'date' => '',
  7639. 'date' => '',
  7640. 'opinion' => '',
  7641. 'status' => '',
  7642. 'rolename' => $rolename ['name']
  7643. );
  7644. array_push ( $roleArray, $exp );
  7645. }
  7646. $roleArrayCopy [$v [0]] = $roleArray;
  7647. // $verifyList[$k]['roleArray']=$roleArray;
  7648. }
  7649. // print_r($roleArray);
  7650. $verifyList [$k] ['date'] = "";
  7651. $verifyList [$k] ['opinion'] = "";
  7652. $verifyList [$k] ['status'] = "";
  7653. if (empty ( $verifyStaff )) {
  7654. $verifyList [$k] ['date'] = "";
  7655. $verifyList [$k] ['opinion'] = "";
  7656. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7657. $verifyList [$k] ['status'] = 4;
  7658. $button = 4;
  7659. $flag = false;
  7660. }
  7661. } else {
  7662. foreach ( $verifyStaff as $m => $u ) {
  7663. if ($v [0] == $m) {
  7664. $verifyList [$k] ['date'] = $u ['date'];
  7665. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7666. $verifyList [$k] ['status'] = $u ['status'];
  7667. $flag = false;
  7668. break;
  7669. }
  7670. }
  7671. $endStaffArray = end ( $verifyStaff );
  7672. if (isset ( $endStaffArray ['ROLE'] )) {
  7673. } else {
  7674. $endKey = key ( $verifyStaff );
  7675. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7676. $button = 4;
  7677. $verifyList [$k] ['status'] = 4;
  7678. }
  7679. }
  7680. // print_r($endStaffArray);die;
  7681. // if (empty($verifyStaff)){
  7682. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7683. // $verifyList[$k]['status']=4;$button=4;
  7684. // }
  7685. //
  7686. // }else{
  7687. //
  7688. // }
  7689. // if($flag){//检测可编辑
  7690. // if($v[0]==$this->staff[0]['sid']){
  7691. // $verifyList[$k]['status']=4;$button=4;
  7692. // }
  7693. // }
  7694. }
  7695. }
  7696. $rolename ['name'] = '';
  7697. if (! empty ( $roleId )) {
  7698. Doo::loadModel ( 'role' );
  7699. $role = new role ();
  7700. $rolename = $role->getOne ( array (
  7701. 'where' => 'rid=' . $roleId,
  7702. 'asArray' => true
  7703. ) );
  7704. }
  7705. if (! empty ( $verifyStaff ))
  7706. $endStaffArray = end ( $verifyStaff );
  7707. $KOP = false;
  7708. foreach ( $roleArrayCopy as $P => $A ) {
  7709. foreach ( $A as $MKI => $AVL ) {
  7710. if (! empty ( $verifyStaff )) {
  7711. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7712. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7713. $button = 4;
  7714. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7715. }
  7716. foreach ( $verifyStaff as $m => $u ) {
  7717. $AVLFK = $AVL [0] . '_R';
  7718. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7719. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7720. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7721. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7722. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7723. break;
  7724. }
  7725. }
  7726. } else {
  7727. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7728. $button = 4;
  7729. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7730. }
  7731. }
  7732. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7733. $KOP = true;
  7734. }
  7735. }
  7736. // print_r($roleArrayCopy);
  7737. // echo $roleKey;
  7738. foreach ( $roleArrayCopy as $k => $v ) {
  7739. foreach ( $verifyList as $m => $n ) {
  7740. if ($n [0] == $k) {
  7741. array_splice ( $verifyList, $m, 1, $v );
  7742. }
  7743. }
  7744. }
  7745. // if ($KOP)
  7746. // array_splice($verifyList,$roleKey,1,$roleArray);
  7747. // print_r($verifyList);
  7748. $receiptList [$key] ['verifyList'] = $verifyList;
  7749. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7750. 'where' => 'sid=' . $value ['staff'],
  7751. 'asArray' => true
  7752. ) );
  7753. $receiptList [$key] ['button'] = $button;
  7754. }
  7755. // $data['verifyDetail']=$verifyDetail;
  7756. $mothHtml = "";
  7757. for($i = 1; $i <= 12; $i ++) {
  7758. if ($month == $i)
  7759. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7760. else
  7761. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7762. }
  7763. // 获取审批日志
  7764. Doo::loadModel ( 'receiptLog' );
  7765. $receiptLog = new receiptLog ();
  7766. $rlList = array ();
  7767. $rlInfo = $receiptLog->getOne ( array (
  7768. 'where' => 'rid=' . $rid . ' and status=4',
  7769. 'asArray' => true
  7770. ) );
  7771. $tijdate = $receiptLog->getOne ( array (
  7772. 'where' => 'rid=' . $rid . ' and status=2',
  7773. 'asc' => 'rlid',
  7774. 'asArray' => true
  7775. ) );
  7776. if (! empty ( $rlInfo )) {
  7777. $rlList = $receiptLog->find ( array (
  7778. 'where' => 'rid=' . $rid,
  7779. 'asc' => 'rlid',
  7780. 'asArray' => true
  7781. ) );
  7782. }
  7783. $receiptList [0] ['rlList'] = $rlList;
  7784. $enclosurList = $enclosur->find ( array (
  7785. 'where' => 'rid=' . $rid,
  7786. 'asArray' => true
  7787. ) );
  7788. $enclosurHtml = '';
  7789. foreach ( $enclosurList as $value ) {
  7790. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7791. }
  7792. $data ['enclosurHtml'] = $enclosurHtml;
  7793. $data ['rolename'] = $rolename ['name'];
  7794. $data ['datetij'] = $tijdate ['date'];
  7795. $data ['mothHtml'] = $mothHtml;
  7796. $data ['receiptList'] = $receiptList;
  7797. $data ['receiptApprovalCount'] = count ( $receiptList );
  7798. $data ['status'] = $status;
  7799. $data ['year'] = $year;
  7800. $data ['categoryList'] = $categoryList;
  7801. $data ['staffList'] = $staffList;
  7802. $data ['cid'] = $cid;
  7803. $data ['sid'] = $sid;
  7804. $data ['ap'] = $ap;
  7805. $data ['memu'] = "receipt";
  7806. $data ['staff'] = $this->staff;
  7807. $data ['receiptMemu'] = 'approval';
  7808. $data ['verifyId'] = $this->verifyId;
  7809. $data ['executeId'] = $this->executeId;
  7810. $this->render ( "/admin/saeaReportListReport", $data );
  7811. }
  7812. function remittanceHky() {
  7813. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7814. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7815. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7816. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7817. $page_size = 15;
  7818. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7819. Doo::loadModel ( 'receipt' );
  7820. $receipt = new receipt ();
  7821. Doo::loadModel ( 'staff' );
  7822. $staff = new staff ();
  7823. $dateCondition = " and Year(executeDate) =" . $year;
  7824. if ($moth != 'MONTH')
  7825. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7826. if ($day != 'DAY' && $moth != 'MONTH')
  7827. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7828. $sql = ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition;
  7829. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7830. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7831. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7832. $dayList = $receipt->find ( array (
  7833. 'select' => 'executeDate,sum(amount) as amount',
  7834. 'where' => $sql,
  7835. 'desc' => 'executeDate',
  7836. 'groupby' => 'executeDate',
  7837. 'limit' => $limit,
  7838. 'asArray' => true
  7839. ) );
  7840. // print_r($dayList);
  7841. foreach ( $dayList as $key => $value ) {
  7842. $remitString = "";
  7843. $receiptList = $receipt->find ( array (
  7844. 'select' => 'rid,executeDate,amount,staff,cid',
  7845. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7846. 'desc' => 'executeDate',
  7847. 'asArray' => true
  7848. ) );
  7849. foreach ( $receiptList as $k => $v ) {
  7850. $sinfo = $staff->getOne ( array (
  7851. 'select' => 'username,category',
  7852. 'where' => ' sid=' . $v ['staff'],
  7853. 'asArray' => true
  7854. ) );
  7855. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7856. }
  7857. $dayList [$key] ['staff'] = $remitString;
  7858. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7859. }
  7860. // print_r($dayList);
  7861. $mothHtml = "";
  7862. for($i = 1; $i <= 12; $i ++) {
  7863. if ($moth == $i)
  7864. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7865. else
  7866. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7867. }
  7868. $dayHtml = "";
  7869. if ($day != "DAY" || $moth != "MONTH") {
  7870. for($i = 1; $i <= 31; $i ++) {
  7871. if ($day == $i)
  7872. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7873. else
  7874. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7875. }
  7876. }
  7877. $dateHtml = "";
  7878. $now = date ( "Y" );
  7879. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7880. if ($YEARD <= $now) {
  7881. $dateHtml .= '<option ';
  7882. if ($year == $YEARD) {
  7883. $dateHtml .= 'selected ';
  7884. }
  7885. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7886. }
  7887. }
  7888. $data ['dateHtml'] = $dateHtml;
  7889. $data ['page'] = $pageinfo;
  7890. $data ['year'] = $year;
  7891. $data ['moth'] = $moth;
  7892. $data ['day'] = $day;
  7893. $data ['get'] = $get;
  7894. $data ['dayHtml'] = $dayHtml;
  7895. $data ['mothHtml'] = $mothHtml;
  7896. $data ['receiptList'] = $dayList;
  7897. $data ['memu'] = "receipt";
  7898. $data ['staff'] = $this->staff;
  7899. $data ['receiptMemu'] = 'remittanceHky';
  7900. $data ['verifyId'] = $this->verifyId;
  7901. $data ['executeId'] = $this->executeId;
  7902. $this->render ( "/admin/remittanceHky", $data );
  7903. }
  7904. function remittancep() {
  7905. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7906. Doo::loadModel ( 'receipt' );
  7907. $receipt = new receipt ();
  7908. Doo::loadModel ( 'staff' );
  7909. $staff = new staff ();
  7910. Doo::loadClass ( 'XDeode' );
  7911. $XDeode = new XDeode ( 5 );
  7912. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7913. $rplist = $receipt->find ( array (
  7914. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7915. 'asArray' => true
  7916. ) );
  7917. $dayList = $receipt->find ( array (
  7918. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7919. 'desc' => 'executeDate',
  7920. 'groupby' => 'staff',
  7921. 'asArray' => true
  7922. ) );
  7923. $html = '';
  7924. foreach ( $dayList as $key => $value ) {
  7925. $sinfo = $staff->getOne ( array (
  7926. 'select' => 'username,category',
  7927. 'where' => ' sid=' . $value ['staff'],
  7928. 'asArray' => true
  7929. ) );
  7930. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  7931. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  7932. $au = 0;
  7933. foreach ( $rplist as $k => $v ) {
  7934. if ($value ['staff'] == $v ['staff']) {
  7935. $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>';
  7936. $au += $v ['amount'];
  7937. }
  7938. }
  7939. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  7940. }
  7941. $data ['html'] = $html;
  7942. $data ['memu'] = "receipt";
  7943. $data ['staff'] = $this->staff;
  7944. $data ['receiptMemu'] = 'remittanceHky';
  7945. $data ['verifyId'] = $this->verifyId;
  7946. $data ['executeId'] = $this->executeId;
  7947. $this->render ( "/admin/remittancep", $data );
  7948. }
  7949. function ajaxGetReceiptDetails() {
  7950. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  7951. Doo::loadClass ( 'XDeode' );
  7952. $XDeode = new XDeode ( 5 );
  7953. $rid = $XDeode->decode ( $rid );
  7954. if (empty ( $rid )) {
  7955. echo json_encode ( array (
  7956. 'status' => 2,
  7957. 'msg' => 'illegal request'
  7958. ) );
  7959. die ();
  7960. }
  7961. Doo::loadModel ( 'receipt' );
  7962. $receipt = new receipt ();
  7963. Doo::loadModel ( 'staff' );
  7964. $staff = new staff ();
  7965. $rinfo = $receipt->getOne ( array (
  7966. 'where' => 'rid= ' . $rid,
  7967. 'asArray' => true
  7968. ) );
  7969. $sinfo = $staff->getOne ( array (
  7970. 'select' => 'username,category',
  7971. 'where' => ' sid=' . $rinfo ['staff'],
  7972. 'asArray' => true
  7973. ) );
  7974. $rinfo ['reviseDetail'] = array ();
  7975. if (! empty ( $rinfo ['reviseDetail'] ))
  7976. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  7977. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  7978. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  7979. $rinfo ['category'] = $sinfo ['category'];
  7980. $verifyStaff = array ();
  7981. if (! empty ( $rinfo ['verifyStaff'] ))
  7982. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  7983. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  7984. $rinfo ['relust'] = $relust;
  7985. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  7986. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  7987. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  7988. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  7989. // 费用执行人相关数据
  7990. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  7991. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  7992. foreach ( $executeCopy as $k => $v ) {
  7993. $executeCopy [$k] ['date'] = '';
  7994. $executeCopy [$k] ['opinion'] = '';
  7995. $executeCopy [$k] ['status'] = '';
  7996. if (! empty ( $executeStaff ))
  7997. foreach ( $executeStaff as $m => $u ) {
  7998. if ($v [0] == $m) {
  7999. $executeCopy [$k] ['date'] = $u ['date'];
  8000. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8001. $executeCopy [$k] ['status'] = $u ['status'];
  8002. break;
  8003. }
  8004. }
  8005. }
  8006. $rinfo ['executeCopy'] = $executeCopy;
  8007. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8008. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8009. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8010. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8011. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8012. $html .= '<tr><th>' . $value ['name'] . '</th>
  8013. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8014. }
  8015. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8016. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8017. <tr><th class="taC" colspan="2">费用说明</th>
  8018. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8019. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8020. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8021. </tbody></table>';
  8022. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8023. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8024. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8025. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8026. $html .= '<tr><th>' . $value ['name'] . '</th>
  8027. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8028. }
  8029. $html .= '<tr><th class="taR">合计</th>
  8030. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8031. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8032. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8033. $html .= '<tr><th>' . $value ['name'] . '</th>
  8034. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8035. }
  8036. $html .= '<tr><th class="taR">合计</th>
  8037. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8038. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8039. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8040. $html .= '<tr><th>' . $value ['name'] . '</th>
  8041. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8042. }
  8043. $html .= '<tr><th class="taR">合计</th>
  8044. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8045. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8046. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8047. $html .= '<tr><th>' . $value ['name'] . '</th>
  8048. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8049. }
  8050. $html .= '<tr><th class="taR">合计</th>
  8051. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8052. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8053. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8054. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8055. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8056. }
  8057. $html .= '<tr><th class="taR">合计</th>
  8058. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8059. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8060. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8061. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8062. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8063. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8064. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8065. <tr';
  8066. if ($rinfo ['relust'] >= 0) {
  8067. $html .= 'class="success"';
  8068. } else {
  8069. $html .= 'class="error"';
  8070. }
  8071. $html .= '><td class="taR"><b>借款结余</b></td>
  8072. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8073. </tbody></table>
  8074. ';
  8075. }
  8076. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8077. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8078. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8079. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8080. $html .= '<tr><th>' . $value ['name'] . '</th>
  8081. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8082. }
  8083. $html .= '<tr><th class="taR">合计</th>
  8084. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8085. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8086. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8087. <tr><th class="taC" colspan="2">费用说明</th>
  8088. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8089. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8090. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8091. </tbody></table>';
  8092. } else {
  8093. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8094. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8095. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8096. $html .= '<tr><th>' . $value ['name'] . '</th>
  8097. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8098. }
  8099. $html .= '<tr><th class="taR">合计</th>
  8100. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8101. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8102. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8103. $html .= '<tr><th>' . $value ['name'] . '</th>
  8104. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8105. }
  8106. $html .= '<tr><th class="taR">合计</th>
  8107. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8108. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8109. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8110. $html .= '<tr><th>' . $value ['name'] . '</th>
  8111. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8112. }
  8113. $html .= '<tr><th class="taR">合计</th>
  8114. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8115. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8116. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8117. $html .= '<tr><th>' . $value ['name'] . '</th>
  8118. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8119. }
  8120. $html .= '<tr><th class="taR">合计</th>
  8121. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8122. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8123. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8124. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8125. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8126. }
  8127. $html .= '<tr><th class="taR">合计</th>
  8128. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8129. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8130. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8131. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8132. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8133. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8134. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8135. $html .= '</tbody></table>';
  8136. /*
  8137. * <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>
  8138. */
  8139. }
  8140. // print_r($verifyStaff);die;
  8141. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8142. foreach ( $verifyStaff as $key => $value ) {
  8143. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8144. $sinfo = $staff->getOne ( array (
  8145. 'select' => 'username',
  8146. 'where' => ' sid=' . $key,
  8147. 'asArray' => true
  8148. ) );
  8149. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8150. }
  8151. $html .= '</tbody></table>';
  8152. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8153. foreach ( $rinfo ['executeCopy'] as $value ) {
  8154. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8155. }
  8156. $html .= '</tbody></table>';
  8157. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8158. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8159. </tr></table>';
  8160. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8161. echo json_encode ( array (
  8162. 'status' => 1,
  8163. 'html' => $html
  8164. ) );
  8165. die ();
  8166. }
  8167. /**
  8168. * 删除附件
  8169. */
  8170. function ajaxRemEnclousur() {
  8171. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8172. if (empty ( $key ))
  8173. echo json_encode ( array (
  8174. 'status' => 2
  8175. ) );
  8176. Doo::loadModel ( 'enclosur' );
  8177. $enclosur = new enclosur ();
  8178. $enclosur->delEnclosurByEid ( $key );
  8179. echo json_encode ( array (
  8180. 'status' => 1
  8181. ) );
  8182. }
  8183. function remittance() {
  8184. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8185. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8186. Doo::loadModel ( 'receipt' );
  8187. $receipt = new receipt ();
  8188. Doo::loadModel ( 'staff' );
  8189. $staff = new staff ();
  8190. $dateCondition = " and Year(pastDate) =" . $year;
  8191. if (! empty ( $month ))
  8192. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8193. // get Receipt By verifyID status 1
  8194. $receiptList = $receipt->find ( array (
  8195. 'select' => 'sum(sum) as sum,staff,pastDate',
  8196. 'where' => ' status=1' . $dateCondition,
  8197. 'desc' => 'pastDate',
  8198. 'groupby' => 'staff,pastDate',
  8199. 'asArray' => true
  8200. ) );
  8201. $dateList = $receipt->find ( array (
  8202. 'select' => 'pastDate,verifyStaff',
  8203. 'where' => ' status=1' . $dateCondition,
  8204. 'desc' => 'pastDate',
  8205. 'groupby' => 'pastDate',
  8206. 'asArray' => true
  8207. ) );
  8208. $dataList = array ();
  8209. foreach ( $dateList as $d => $a ) {
  8210. $dataList [$a ['pastDate']] = array ();
  8211. $daySum = 0;
  8212. foreach ( $receiptList as $key => $value ) {
  8213. if ($a ['pastDate'] == $value ['pastDate']) {
  8214. $oderList = $receipt->find ( array (
  8215. 'select' => 'receiptOrder',
  8216. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8217. 'asArray' => true
  8218. ) );
  8219. $list = array ();
  8220. $html = "";
  8221. foreach ( $oderList as $v ) {
  8222. array_push ( $list, $v ['receiptOrder'] );
  8223. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8224. }
  8225. $receiptList [$key] ['receiptOrder'] = $html;
  8226. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8227. $sinfo = $staff->getOne ( array (
  8228. 'select' => 'username ',
  8229. 'where' => ' sid=' . $value ['staff'],
  8230. 'asArray' => true
  8231. ) );
  8232. $receiptList [$key] ['username'] = $sinfo ['username'];
  8233. $daySum += $value ['sum'];
  8234. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8235. }
  8236. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8237. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8238. }
  8239. }
  8240. // print_r($dataList);
  8241. $data ['dataList'] = $dataList;
  8242. $mothHtml = "";
  8243. for($i = 1; $i <= 12; $i ++) {
  8244. if ($month == $i)
  8245. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8246. else
  8247. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8248. }
  8249. $data ['year'] = $year;
  8250. $data ['mothHtml'] = $mothHtml;
  8251. $data ['memu'] = "receipt";
  8252. $data ['staff'] = $this->staff;
  8253. $data ['receiptMemu'] = 'approval';
  8254. $data ['verifyId'] = $this->verifyId;
  8255. $data ['executeId'] = $this->executeId;
  8256. $this->render ( "/admin/saeaReportListPay", $data );
  8257. }
  8258. /**
  8259. * 金额调整,提高稳定性
  8260. * @return string
  8261. */
  8262. function revocationAdjustment() {
  8263. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8264. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8265. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8266. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8267. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8268. Doo::loadClass ( 'XDeode' );
  8269. $XDeode = new XDeode ( 5 );
  8270. Doo::loadModel ( 'receipt' );
  8271. $receipt = new receipt ();
  8272. $sid = $XDeode->decode ( $sidKey );
  8273. $rid = $XDeode->decode ( $ridKey );
  8274. $reviseKey = $XDeode->decode ( $reviseKey );
  8275. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8276. die ( 'illegal request' );
  8277. $receiptDetail = $receipt->getOne ( array (
  8278. 'where' => 'rid=' . $rid,
  8279. 'asArray' => true
  8280. ) );
  8281. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8282. die ( 'illegal request' );
  8283. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8284. if (! isset ( $reviseDetail [$reviseKey] ))
  8285. die ( 'illegal request' );
  8286. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8287. unset ( $reviseDetail [$reviseKey] );
  8288. $revisePrice = 0;
  8289. foreach ( $reviseDetail as $key => $value ) {
  8290. $revisePrice += $value ['price'];
  8291. }
  8292. $reviseDetailString = json_encode ( $reviseDetail );
  8293. $receipt->reviseDetail = $reviseDetailString;
  8294. $receipt->sum = $receiptDetail ['sum'] - $price;
  8295. $receipt->revisePrice = $revisePrice;
  8296. $receipt->update ( array (
  8297. 'where' => 'rid=' . $rid
  8298. ) );
  8299. return '/receiptburEdi/' . $rid;
  8300. } else
  8301. die ( 'illegal request2' );
  8302. }
  8303. function updateApprovalReceipt() {
  8304. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8305. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8306. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8307. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8308. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8309. if (! empty ( $rid )) {
  8310. Doo::loadModel ( "verify" );
  8311. $verify = new verify ();
  8312. Doo::loadModel ( "receiptDetail" );
  8313. $receiptDetailObj = new receiptDetail ();
  8314. Doo::loadModel ( "itemStatistics" );
  8315. Doo::loadModel ( "statistics" );
  8316. $statistics = new statistics ();
  8317. $itemStatistics = new itemStatistics ();
  8318. Doo::loadModel ( "receipt" );
  8319. $receipt = new receipt ();
  8320. $receiptDetail = $receipt->getOne ( array (
  8321. 'where' => 'rid=' . $rid . ' and status=2 ',
  8322. 'asArray' => true
  8323. ) );
  8324. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8325. $nsflag = true;
  8326. foreach ( $nslist as $value ) {
  8327. if ($value == $this->staff ['0'] ['sid']) {
  8328. $nsflag = false;
  8329. break;
  8330. }
  8331. }
  8332. if (empty ( $receiptDetail ) || $nsflag)
  8333. return "/approvalExpenses/pendApproval";
  8334. $verifyDetail = $verify->getOne ( array (
  8335. 'where' => ' vid =' . $receiptDetail ['verify'],
  8336. 'asArray' => true
  8337. ) );
  8338. $verifyString = $verifyDetail ['staff'];
  8339. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8340. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8341. if (empty ( $opinion )) {
  8342. if ($status == 3)
  8343. $opinion = "终止";
  8344. else
  8345. $opinion = "同意支付";
  8346. }
  8347. $nowStaff = 0;
  8348. $nowStaffList = array ();
  8349. if (empty ( $verifyStaff )) {
  8350. // 还需加入是否已经进入角色审批
  8351. if ($verifyDetail [0] [1] == 'ROLE') {
  8352. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8353. foreach ( $vStaffString as $key => $value ) {
  8354. $staffK = explode ( "_", $value );
  8355. if ($staffK [0] != $this->staff [0] ['sid'])
  8356. array_push ( $nowStaffList, $staffK [0] );
  8357. }
  8358. // print_r($verifyDetail);
  8359. // die;
  8360. if (! empty ( $nowStaffList )) {
  8361. $nowStaff = implode ( ',', $nowStaffList );
  8362. $verifyStaff = array (
  8363. $this->staff [0] ['sid'] . "_R" => array (
  8364. 'date' => date ( 'Y-m-d' ),
  8365. 'opinion' => $opinion,
  8366. 'status' => $status,
  8367. 'nextStaff' => $verifyDetail [0] [0],
  8368. 'ROLE' => 1
  8369. )
  8370. );
  8371. } else {
  8372. $nowStaff = $verifyDetail [1] [0];
  8373. $verifyStaff = array (
  8374. $this->staff [0] ['sid'] . "_R" => array (
  8375. 'date' => date ( 'Y-m-d' ),
  8376. 'opinion' => $opinion,
  8377. 'status' => $status,
  8378. 'nextStaff' => $verifyDetail [1] [0]
  8379. )
  8380. );
  8381. }
  8382. } else {
  8383. if ($verifyDetail [1] [1] == 'ROLE') {
  8384. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8385. // echo "dd";
  8386. foreach ( $vStaffString as $key => $value ) {
  8387. $staffK = explode ( "_", $value );
  8388. array_push ( $nowStaffList, $staffK [0] );
  8389. }
  8390. $nowStaff = implode ( ',', $nowStaffList );
  8391. $verifyStaff = array (
  8392. $this->staff [0] ['sid'] => array (
  8393. 'date' => date ( 'Y-m-d' ),
  8394. 'opinion' => $opinion,
  8395. 'status' => $status,
  8396. 'nextStaff' => $verifyDetail [1] [0],
  8397. 'ROLE' => 1
  8398. )
  8399. );
  8400. } else {
  8401. $nowStaff = $verifyDetail [1] [0];
  8402. $verifyStaff = array (
  8403. $this->staff [0] ['sid'] => array (
  8404. 'date' => date ( 'Y-m-d' ),
  8405. 'opinion' => $opinion,
  8406. 'status' => $status,
  8407. 'nextStaff' => $verifyDetail [1] [0]
  8408. )
  8409. );
  8410. }
  8411. }
  8412. if ($status == 3)
  8413. $verifyStaff = array (
  8414. 'final' => $status,
  8415. $this->staff [0] ['sid'] => array (
  8416. 'date' => date ( 'Y-m-d' ),
  8417. 'opinion' => $opinion,
  8418. 'status' => $status
  8419. )
  8420. );
  8421. $vStaffString = json_encode ( $verifyStaff );
  8422. $receipt->nowStaff = $nowStaff;
  8423. $receipt->verifyStaff = $vStaffString;
  8424. } else {
  8425. $VS = end ( $verifyStaff );
  8426. // 非角色审批
  8427. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8428. $nextStaff = 0;
  8429. $roleSTF = false;
  8430. foreach ( $verifyDetail as $key => $value ) {
  8431. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8432. if (isset ( $verifyDetail [$key + 1] )) {
  8433. $nextStaff = $verifyDetail [$key + 1] [0];
  8434. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8435. $roleSTF = true;
  8436. }
  8437. break;
  8438. }
  8439. }
  8440. if (! $roleSTF) {
  8441. $nowStaff = $nextStaff;
  8442. $verifyStaff [$this->staff [0] ['sid']] = array (
  8443. 'date' => date ( 'Y-m-d' ),
  8444. 'opinion' => $opinion,
  8445. 'status' => $status,
  8446. 'nextStaff' => $nextStaff
  8447. );
  8448. } else {
  8449. // 获取角色下的所有用户ID
  8450. $nowStaffList = array ();
  8451. foreach ( $verifyDetail as $vfk ) {
  8452. if ($vfk [1] == 'ROLE') {
  8453. $vStaffString = json_decode ( $vfk [3] );
  8454. foreach ( $vStaffString as $key => $value ) {
  8455. $staffK = explode ( "_", $value );
  8456. array_push ( $nowStaffList, $staffK [0] );
  8457. }
  8458. }
  8459. }
  8460. $nowStaff = implode ( ',', $nowStaffList );
  8461. $verifyStaff [$this->staff [0] ['sid']] = array (
  8462. 'date' => date ( 'Y-m-d' ),
  8463. 'opinion' => $opinion,
  8464. 'status' => $status,
  8465. 'nextStaff' => $nextStaff,
  8466. 'ROLE' => 0
  8467. );
  8468. }
  8469. if ($status == 3) {
  8470. $verifyStaff ['final'] = $status;
  8471. $verifyStaff [$this->staff [0] ['sid']] = array (
  8472. 'date' => date ( 'Y-m-d' ),
  8473. 'opinion' => $opinion,
  8474. 'status' => $status
  8475. );
  8476. }
  8477. $vStaffString = json_encode ( $verifyStaff );
  8478. $receipt->nowStaff = $nowStaff;
  8479. $receipt->verifyStaff = $vStaffString;
  8480. }
  8481. // 角色审批
  8482. if (isset ( $VS ['ROLE'] )) {
  8483. // 找出角色人 当前审批角色组
  8484. $verifyJSStaff = array ();
  8485. $nowStaffList2 = array ();
  8486. foreach ( $verifyDetail as $key => $value ) {
  8487. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8488. $verifyJSStaff = json_decode ( $value [3] );
  8489. foreach ( $verifyJSStaff as $m ) {
  8490. $staffK = explode ( "_", $m );
  8491. array_push ( $nowStaffList2, $staffK [0] );
  8492. }
  8493. // print_r($nowStaffList2);
  8494. }
  8495. }
  8496. $RoleVerifyStaff = array ();
  8497. foreach ( $verifyStaff as $key => $value ) {
  8498. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8499. foreach ( $nowStaffList2 as $m ) {
  8500. if ($key == $m . "_R")
  8501. $RoleVerifyStaff [$key] = $value;
  8502. }
  8503. }
  8504. }
  8505. // print_r($verifyStaff);
  8506. // print_r($nowStaffList2);
  8507. // print_r($RoleVerifyStaff);
  8508. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8509. // print_r($verifyJSStaff);
  8510. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8511. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8512. // 下一个审批人ID
  8513. $nextStaff = 0;
  8514. $falg = false;
  8515. foreach ( $verifyDetail as $key => $value ) {
  8516. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8517. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8518. $falg = true;
  8519. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8520. $nowStaffList = array ();
  8521. foreach ( $vStaffString as $v ) {
  8522. $staffK = explode ( "_", $v );
  8523. array_push ( $nowStaffList, $staffK [0] );
  8524. }
  8525. $nowStaff = implode ( ',', $nowStaffList );
  8526. $nextStaff = $verifyDetail [$key + 1] [0];
  8527. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8528. $nextStaff = $verifyDetail [$key + 1] [0];
  8529. $nowStaff = $nextStaff;
  8530. } else
  8531. $nowStaff = '';
  8532. break;
  8533. }
  8534. }
  8535. if ($falg)
  8536. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8537. 'date' => date ( 'Y-m-d' ),
  8538. 'opinion' => $opinion,
  8539. 'status' => $status,
  8540. 'nextStaff' => $nextStaff,
  8541. 'ROLE' => 1
  8542. );
  8543. else
  8544. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8545. 'date' => date ( 'Y-m-d' ),
  8546. 'opinion' => $opinion,
  8547. 'status' => $status,
  8548. 'nextStaff' => $nextStaff
  8549. );
  8550. // print_r($verifyStaff);
  8551. // echo $nowStaff;die;
  8552. } else { // 进入下一个角色或者审批人
  8553. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8554. //
  8555. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8556. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8557. 'date' => date ( 'Y-m-d' ),
  8558. 'opinion' => $opinion,
  8559. 'status' => $status,
  8560. 'nextStaff' => $VS ['nextStaff'],
  8561. 'ROLE' => 1
  8562. );
  8563. // print_r($verifyStaff);
  8564. // die;
  8565. }
  8566. if ($status == 3) {
  8567. $verifyStaff ['final'] = $status;
  8568. $verifyStaff [$this->staff [0] ['sid']] = array (
  8569. 'date' => date ( 'Y-m-d' ),
  8570. 'opinion' => $opinion,
  8571. 'status' => $status
  8572. );
  8573. }
  8574. $vStaffString = json_encode ( $verifyStaff );
  8575. $receipt->verifyStaff = $vStaffString;
  8576. $receipt->nowStaff = $nowStaff;
  8577. // die;
  8578. // }
  8579. // print_r($verifyStaff);
  8580. // die;
  8581. }
  8582. // print_r($verifyStaff);die;
  8583. }
  8584. // print_r($verifyDetail);
  8585. $roleKey = 0;
  8586. $roleId = 0;
  8587. $verifyDetailCopy = array ();
  8588. foreach ( $verifyDetail as $k => $v ) {
  8589. if ($v [1] == 'ROLE') {
  8590. $roleId = $v [0];
  8591. $roleVerify = json_decode ( $v [3], true );
  8592. $roleKey = $k;
  8593. $roleArray = array ();
  8594. foreach ( $roleVerify as $o => $p ) {
  8595. $staffID = explode ( '_', $p );
  8596. $exp = array (
  8597. 0 => $staffID [0],
  8598. 1 => $staffID [1]
  8599. );
  8600. array_push ( $roleArray, $exp );
  8601. }
  8602. $verifyDetailCopy [$v [0]] = $roleArray;
  8603. }
  8604. }
  8605. // print_r($verifyDetail);
  8606. foreach ( $verifyDetailCopy as $k => $v ) {
  8607. foreach ( $verifyDetail as $m => $n ) {
  8608. if ($n [0] == $k) {
  8609. array_splice ( $verifyDetail, $m, 1, $v );
  8610. }
  8611. }
  8612. }
  8613. // die;
  8614. // if (!empty($roleArray))
  8615. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8616. // echo $roleId;
  8617. // print_r($verifyStaff);
  8618. // print_r($verifyDetail);
  8619. // die;
  8620. Doo::loadModel ( "receiptLog" );
  8621. $receiptLog = new receiptLog ();
  8622. // 审批日志
  8623. if (! isset ( $verifyStaff ['final'] )) {
  8624. if (! empty ( $roleId )) {
  8625. Doo::loadModel ( "role" );
  8626. $role = new role ();
  8627. $roleInfo = $role->getOne ( array (
  8628. 'where' => 'rid=' . $roleId,
  8629. 'asArray' => true
  8630. ) );
  8631. $receiptLog->rolename = $roleInfo ['name'];
  8632. }
  8633. $receiptLog->username = $this->staff [0] ['username'];
  8634. $receiptLog->uid = $this->staff [0] ['sid'];
  8635. $receiptLog->date = date ( "Y-m-d" );
  8636. $receiptLog->opinion = $opinion;
  8637. $receiptLog->img = $this->staff [0] ['avatar'];
  8638. $receiptLog->status = 1;
  8639. $receiptLog->rid = $rid;
  8640. $receiptLog->insert ();
  8641. }
  8642. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8643. $receipt->verifyBreakup = $verifyString;
  8644. $receipt->status = 3;
  8645. $receiptDetailObj->status = 3;
  8646. $receiptDetailObj->update ( array (
  8647. 'where' => 'rid=' . $rid
  8648. ) );
  8649. if (! empty ( $roleId )) {
  8650. Doo::loadModel ( "role" );
  8651. $role = new role ();
  8652. $roleInfo = $role->getOne ( array (
  8653. 'where' => 'rid=' . $roleId,
  8654. 'asArray' => true
  8655. ) );
  8656. $receiptLog->rolename = $roleInfo ['name'];
  8657. }
  8658. $receiptLog->username = $this->staff [0] ['username'];
  8659. $receiptLog->uid = $this->staff [0] ['sid'];
  8660. $receiptLog->date = date ( "Y-m-d" );
  8661. $receiptLog->opinion = $opinion;
  8662. $receiptLog->img = $this->staff [0] ['avatar'];
  8663. $receiptLog->status = 3;
  8664. $receiptLog->rid = $rid;
  8665. $receiptLog->insert ();
  8666. // 微信企业号通知
  8667. $this->setWXMsg ( $rid, 3 );
  8668. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8669. $receipt->status = 1;
  8670. $reviseSum = 0;
  8671. $receipt->verifyBreakup = $verifyString;
  8672. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8673. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8674. foreach ( $reviseDetail as $key => $value ) {
  8675. $receiptDetailObj = new receiptDetail ();
  8676. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8677. $receiptDetailObj->item = $value ['description'];
  8678. $receiptDetailObj->itemCategory = "报销金额调整";
  8679. $receiptDetailObj->price = $value ['price'];
  8680. $receiptDetailObj->date = $receiptDetail ['date'];
  8681. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8682. $receiptDetailObj->rid = $rid;
  8683. $receiptDetailObj->status = 1;
  8684. $receiptDetailObj->insert ();
  8685. $reviseSum += $value ['price'];
  8686. }
  8687. $itemStatistics = new itemStatistics ();
  8688. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8689. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8690. $itemStatistics->price = $reviseSum;
  8691. $itemStatistics->itemCategory = "报销金额调整";
  8692. $itemStatistics->date = $receiptDetail ['date'];
  8693. $itemStatistics->insert ();
  8694. }
  8695. $receiptDetailObj = new receiptDetail ();
  8696. $receiptDetailObj->status = 1;
  8697. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8698. $receiptDetailObj->update ( array (
  8699. 'where' => 'rid=' . $rid
  8700. ) );
  8701. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8702. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8703. $stat = $statistics->getOne ( array (
  8704. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8705. 'asArray' => true
  8706. ) );
  8707. if (empty ( $stat )) {
  8708. $statistics->date = $receiptDetail ['date'];
  8709. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8710. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8711. $statistics->agPrice = $receiptDetail ['sum'];
  8712. $statistics->rePrice = $reviseSum;
  8713. $statistics->insert ();
  8714. } else {
  8715. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8716. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8717. $statistics->update ( array (
  8718. 'where' => 'sid=' . $stat ['sid']
  8719. ) );
  8720. }
  8721. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8722. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8723. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8724. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8725. if ($key == "agencySum") {
  8726. $iStatistics = $itemStatistics->getOne ( array (
  8727. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8728. 'asArray' => true
  8729. ) );
  8730. if (empty ( $iStatistics )) {
  8731. $itemStatistics->cid = $receiptDetail ['cid'];
  8732. ;
  8733. $itemStatistics->staff = $receiptDetail ['staff'];
  8734. $itemStatistics->price = $value;
  8735. $itemStatistics->itemCategory = $this->AGENCY;
  8736. $itemStatistics->date = $receiptDetail ['date'];
  8737. $itemStatistics->insert ();
  8738. } else {
  8739. if (! empty ( $value )) {
  8740. $itemStatistics->price = $value + $iStatistics ['price'];
  8741. $itemStatistics->update ( array (
  8742. 'where' => 'sid=' . $iStatistics ['sid']
  8743. ) );
  8744. }
  8745. }
  8746. } elseif ($key == "travelSum") {
  8747. $iStatistics = $itemStatistics->getOne ( array (
  8748. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8749. 'asArray' => true
  8750. ) );
  8751. if (empty ( $iStatistics )) {
  8752. $itemStatistics->cid = $receiptDetail ['cid'];
  8753. $itemStatistics->staff = $receiptDetail ['staff'];
  8754. $itemStatistics->price = $value;
  8755. $itemStatistics->itemCategory = $this->TRAVEL;
  8756. $itemStatistics->date = $receiptDetail ['date'];
  8757. $itemStatistics->insert ();
  8758. } else {
  8759. if (! empty ( $value )) {
  8760. $itemStatistics->price = $value + $iStatistics ['price'];
  8761. $itemStatistics->update ( array (
  8762. 'where' => 'sid=' . $iStatistics ['sid']
  8763. ) );
  8764. }
  8765. }
  8766. } elseif ($key == "trainSum") {
  8767. $iStatistics = $itemStatistics->getOne ( array (
  8768. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8769. 'asArray' => true
  8770. ) );
  8771. if (empty ( $iStatistics )) {
  8772. $itemStatistics->cid = $receiptDetail ['cid'];
  8773. $itemStatistics->staff = $receiptDetail ['staff'];
  8774. $itemStatistics->price = $value;
  8775. $itemStatistics->itemCategory = $this->TRAIN;
  8776. $itemStatistics->date = $receiptDetail ['date'];
  8777. $itemStatistics->insert ();
  8778. } else {
  8779. if (! empty ( $value )) {
  8780. $itemStatistics->price = $value + $iStatistics ['price'];
  8781. $itemStatistics->update ( array (
  8782. 'where' => 'sid=' . $iStatistics ['sid']
  8783. ) );
  8784. }
  8785. }
  8786. } elseif ($key == "otherSum") {
  8787. $iStatistics = $itemStatistics->getOne ( array (
  8788. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8789. 'asArray' => true
  8790. ) );
  8791. if (empty ( $iStatistics )) {
  8792. $itemStatistics->cid = $receiptDetail ['cid'];
  8793. $itemStatistics->staff = $receiptDetail ['staff'];
  8794. $itemStatistics->price = $value;
  8795. $itemStatistics->itemCategory = $this->OTHER;
  8796. $itemStatistics->date = $receiptDetail ['date'];
  8797. $itemStatistics->insert ();
  8798. } else {
  8799. if (! empty ( $value )) {
  8800. $itemStatistics->price = $value + $iStatistics ['price'];
  8801. $itemStatistics->update ( array (
  8802. 'where' => 'sid=' . $iStatistics ['sid']
  8803. ) );
  8804. }
  8805. }
  8806. }
  8807. }
  8808. $receipt->pastDate = date ( "Y-m-d" );
  8809. // 微信企业号通知
  8810. $this->setWXMsg ( $rid, 1 );
  8811. }
  8812. //是否有流水
  8813. Doo::loadModel ( 'wasteBook' );
  8814. $wasteBook = new wasteBook ();
  8815. $accountType=3;
  8816. if ($receiptDetail['Rtype']==1){
  8817. $accountType=2;
  8818. }elseif($receiptDetail['Rtype']==2){
  8819. $accountType=4;
  8820. }
  8821. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8822. if (empty($wbDetail)){
  8823. $receipt->amount = $amount;
  8824. }
  8825. $receipt->update ( array (
  8826. 'where' => ' rid = ' . $rid
  8827. ) );
  8828. // 进入下一条审批费用新加需求
  8829. $vidList = array ();
  8830. $verifyDetail = $verify->find ( array (
  8831. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8832. 'asArray' => true
  8833. ) );
  8834. foreach ( $verifyDetail as $key => $value ) {
  8835. array_push ( $vidList, $value ['vid'] );
  8836. }
  8837. $vid = implode ( ",", $vidList );
  8838. if (empty ( $verifyDetail ))
  8839. $vid = 0;
  8840. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8841. $receipt = new receipt ();
  8842. $rd = $receipt->getOne ( array (
  8843. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8844. 'asc' => 'rid',
  8845. 'asArray' => true
  8846. ) );
  8847. if (empty ( $rd )) {
  8848. return '/approvalExpenses/pendApproval';
  8849. }
  8850. if ($rd ['Rtype'] == 1) {
  8851. if ($rd ['isBK'] == 1) {
  8852. return '/receiptburEdi/' . $rd ['rid'];
  8853. } else {
  8854. return '/expensesEdi/' . $rd ['rid'];
  8855. }
  8856. } elseif ($rd ['Rtype'] == 2) {
  8857. return '/remitApproval/' . $rd ['rid'];
  8858. } else {
  8859. return '/receiptburEdi/' . $rd ['rid'];
  8860. }
  8861. // return "/approvalExpenses/pendApproval";
  8862. }
  8863. }
  8864. function expensesRetreats() {
  8865. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8866. if (! empty ( $rid )) {
  8867. // 操作记录
  8868. Doo::loadModel ( "receipt" );
  8869. $receipt = new receipt ();
  8870. Doo::loadModel ( "receiptLog" );
  8871. $receiptLog = new receiptLog ();
  8872. Doo::loadModel ( "verify" );
  8873. $verify = new verify ();
  8874. $receiptInfo = $receipt->getOne ( array (
  8875. 'where' => 'rid=' . $rid,
  8876. 'asArray' => true
  8877. ) );
  8878. $vr = $verify->getOne ( array (
  8879. 'where' => 'vid=' . $receiptInfo ['verify'],
  8880. 'asArray' => true
  8881. ) );
  8882. $jd = json_decode ( $vr ['staff'] );
  8883. $roleId = 0;
  8884. foreach ( $jd as $key => $value ) {
  8885. if ($value [1] == 'ROLE') {
  8886. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8887. if ($pos !== false) {
  8888. $roleId = $value [0];
  8889. }
  8890. }
  8891. }
  8892. // 审批日志
  8893. // echo $roleId;die;
  8894. if (! empty ( $roleId )) {
  8895. Doo::loadModel ( "role" );
  8896. $role = new role ();
  8897. $roleInfo = $role->getOne ( array (
  8898. 'where' => 'rid=' . $roleId,
  8899. 'asArray' => true
  8900. ) );
  8901. $receiptLog->rolename = $roleInfo ['name'];
  8902. }
  8903. $receiptLog->username = $this->staff [0] ['username'];
  8904. $receiptLog->uid = $this->staff [0] ['sid'];
  8905. $receiptLog->date = date ( "Y-m-d" );
  8906. $receiptLog->opinion = '撤回';
  8907. $receiptLog->img = $this->staff [0] ['avatar'];
  8908. $receiptLog->status = 4;
  8909. $receiptLog->rid = $rid;
  8910. $receiptLog->insert ();
  8911. $receipt->status = 4;
  8912. $receipt->update ( array (
  8913. 'where' => 'rid=' . $rid
  8914. ) );
  8915. // 微信企业号通知
  8916. $this->setWXMsg ( $rid, 2 );
  8917. }
  8918. // echo "ddd";
  8919. return '/approvalExpenses/pendApproval';
  8920. }
  8921. function updateCheReceipt() {
  8922. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8923. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8924. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8925. if (! empty ( $rid )) {
  8926. // 操作记录
  8927. Doo::loadModel ( "receipt" );
  8928. $receipt = new receipt ();
  8929. Doo::loadModel ( "receiptLog" );
  8930. $receiptLog = new receiptLog ();
  8931. Doo::loadModel ( "verify" );
  8932. $verify = new verify ();
  8933. $receiptInfo = $receipt->getOne ( array (
  8934. 'where' => 'rid=' . $rid . ' and status=2',
  8935. 'asArray' => true
  8936. ) );
  8937. if (empty ( $receiptInfo )) {
  8938. echo json_encode ( array (
  8939. 'status' => 2
  8940. ) );
  8941. die ();
  8942. }
  8943. $vr = $verify->getOne ( array (
  8944. 'where' => 'vid=' . $receiptInfo ['verify'],
  8945. 'asArray' => true
  8946. ) );
  8947. $jd = json_decode ( $vr ['staff'] );
  8948. $roleId = 0;
  8949. foreach ( $jd as $key => $value ) {
  8950. if ($value [1] == 'ROLE') {
  8951. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8952. if ($pos !== false) {
  8953. $roleId = $value [0];
  8954. }
  8955. }
  8956. }
  8957. // 审批日志
  8958. // echo $roleId;die;
  8959. if (! empty ( $roleId )) {
  8960. Doo::loadModel ( "role" );
  8961. $role = new role ();
  8962. $roleInfo = $role->getOne ( array (
  8963. 'where' => 'rid=' . $roleId,
  8964. 'asArray' => true
  8965. ) );
  8966. $receiptLog->rolename = $roleInfo ['name'];
  8967. }
  8968. $receiptLog->username = $this->staff [0] ['username'];
  8969. $receiptLog->uid = $this->staff [0] ['sid'];
  8970. $receiptLog->date = date ( "Y-m-d" );
  8971. $receiptLog->opinion = $opinion;
  8972. $receiptLog->img = $this->staff [0] ['avatar'];
  8973. $receiptLog->status = 4;
  8974. $receiptLog->rid = $rid;
  8975. $receiptLog->insert ();
  8976. $receipt->status = 4;
  8977. $receipt->update ( array (
  8978. 'where' => 'rid=' . $rid
  8979. ) );
  8980. // 微信企业号通知
  8981. $this->setWXMsg ( $rid, 2 );
  8982. echo json_encode ( array (
  8983. 'status' => 1
  8984. ) );
  8985. // Header("HTTP/1.1 303 See Other");
  8986. // Header("Location: /approvalExpenses/pendApproval");
  8987. die ();
  8988. }
  8989. echo json_encode ( array (
  8990. 'status' => 2
  8991. ) );
  8992. die ();
  8993. // echo "ddd";
  8994. // return '/saeaBorad';
  8995. }
  8996. function revisePrice() {
  8997. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  8998. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  8999. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9000. // echo $price;die;
  9001. if (! empty ( $rid )) {
  9002. Doo::loadModel ( "receipt" );
  9003. $receipt = new receipt ();
  9004. $receiptDetail = $receipt->getOne ( array (
  9005. 'where' => 'rid=' . $rid . ' and status=2 ',
  9006. 'asArray' => true
  9007. ) );
  9008. if (empty ( $receiptDetail ))
  9009. die ( 'illegal request' );
  9010. $reviseDetail = array ();
  9011. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9012. array_push ( $reviseDetail, array (
  9013. 'sid' => $this->staff [0] ['sid'],
  9014. 'name' => $this->staff [0] ['username'],
  9015. 'description' => $description,
  9016. 'price' => $price
  9017. ) );
  9018. $reviseDetailString = json_encode ( $reviseDetail );
  9019. $receipt->reviseDetail = $reviseDetailString;
  9020. $receipt->revisePrice = $price;
  9021. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9022. } else {
  9023. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9024. array_push ( $reviseDetail, array (
  9025. 'sid' => $this->staff [0] ['sid'],
  9026. 'name' => $this->staff [0] ['username'],
  9027. 'description' => $description,
  9028. 'price' => $price
  9029. ) );
  9030. $reviseDetailString = json_encode ( $reviseDetail );
  9031. $receipt->reviseDetail = $reviseDetailString;
  9032. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9033. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9034. }
  9035. $receipt->update ( array (
  9036. 'where' => 'rid=' . $rid
  9037. ) );
  9038. if ($receiptDetail ['Rtype'] == 1) {
  9039. if ($receiptDetail ['isBK'] == 1) {
  9040. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9041. }
  9042. } elseif ($receiptDetail ['Rtype'] == 2) {
  9043. } else {
  9044. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9045. }
  9046. }
  9047. die ( 'illegal request' );
  9048. }
  9049. function personalCollect() {
  9050. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9051. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9052. $this->showCache ( $path );
  9053. Doo::loadModel ( "receiptDetail" );
  9054. Doo::loadModel ( "itemStatistics" );
  9055. Doo::loadModel ( 'statistics' );
  9056. $statistics = new statistics ();
  9057. $itemStatistics = new itemStatistics ();
  9058. $receiptDetail = new receiptDetail ();
  9059. $receiptCollectList = $receiptDetail->find ( array (
  9060. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9061. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9062. 'groupby' => 'itemCategory,Month(date)',
  9063. 'asArray' => true
  9064. ) );
  9065. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9066. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9067. 'asArray' => true
  9068. ) );
  9069. // create collect html
  9070. $collectArray = array (
  9071. '日常相关费用' => array (),
  9072. '差旅相关费用' => array (),
  9073. '培训班费用' => array (),
  9074. '其他' => array ()
  9075. );
  9076. $adjustment = array ();
  9077. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9078. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9079. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9080. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9081. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9082. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9083. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9084. array_push ( $collectArray ['其他'], $collectHtml );
  9085. $data ['collectArray'] = $collectArray;
  9086. // statistics html
  9087. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9088. if (empty ( $stList ))
  9089. $stList = array (
  9090. 'rePrice' => 0,
  9091. 'agPrice' => 0
  9092. );
  9093. $data ['stList'] = array (
  9094. 'rePrice' => $stList ['rePrice'],
  9095. 'agPrice' => $stList ['agPrice'],
  9096. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9097. );
  9098. // Adjustment price html
  9099. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9100. array_push ( $adjustment, $collectHtml );
  9101. $data ['adjustment'] = $adjustment;
  9102. // total price html
  9103. $collectHtml = "";
  9104. $total = 0;
  9105. for($i = 1; $i <= 12; $i ++) {
  9106. $sumPrice = 0;
  9107. foreach ( $receiptCollectList as $key => $value ) {
  9108. if ($value ['month'] == $i) {
  9109. $sumPrice += $value ['price'];
  9110. }
  9111. }
  9112. if ($sumPrice == 0)
  9113. $collectHtml .= '<td class="taR">-</td>';
  9114. else
  9115. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9116. $total += $sumPrice;
  9117. }
  9118. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9119. $data ['totalPrice'] = $collectHtml;
  9120. $dateHtml = "";
  9121. $now = date ( "Y" );
  9122. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9123. if ($YEARD <= $now) {
  9124. $dateHtml .= '<option ';
  9125. if ($year == $YEARD) {
  9126. $dateHtml .= 'selected ';
  9127. }
  9128. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9129. }
  9130. }
  9131. $data ['dateHtml'] = $dateHtml;
  9132. $data ['year'] = $year;
  9133. $data ['totalYear'] = $total;
  9134. $data ['memu'] = "receipt";
  9135. $data ['staff'] = $this->staff;
  9136. $data ['receiptMemu'] = 'personalCollect';
  9137. $data ['verifyId'] = $this->verifyId;
  9138. $data ['executeId'] = $this->executeId;
  9139. // year staff status 2,4
  9140. if ($year < date ( "Y" )) {
  9141. Doo::loadModel ( 'receipt' );
  9142. $receipt = new receipt ();
  9143. $receiptList = $receipt->find ( array (
  9144. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9145. 'asArray' => true
  9146. ) );
  9147. if (empty ( $receiptList )) {
  9148. ob_start ();
  9149. $this->render ( "/admin/saea_slist_collect", $data );
  9150. $this->cacheFile ( $path );
  9151. die ();
  9152. }
  9153. }
  9154. $this->render ( "/admin/saea_slist_collect", $data );
  9155. }
  9156. function personalCollectDetail() {
  9157. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9158. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9159. $this->showCache ( $path );
  9160. Doo::loadModel ( "receiptDetail" );
  9161. Doo::loadModel ( "itemStatistics" );
  9162. Doo::loadModel ( 'statistics' );
  9163. Doo::loadModel ( 'accountItem' );
  9164. $accountItem = new accountItem ();
  9165. $statistics = new statistics ();
  9166. $itemStatistics = new itemStatistics ();
  9167. $receiptDetail = new receiptDetail ();
  9168. $receiptCollectList = $receiptDetail->find ( array (
  9169. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9170. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9171. 'groupby' => 'item,Month(date)',
  9172. 'asArray' => true
  9173. ) );
  9174. $accountList = $accountItem->find ( array (
  9175. 'asArray' => true
  9176. ) );
  9177. // create CollectDetail HTML
  9178. $collectHtml = array ();
  9179. foreach ( $accountList as $key => $value ) {
  9180. $html = "";
  9181. $asum = 0;
  9182. for($i = 1; $i <= 12; $i ++) {
  9183. $falg = true;
  9184. foreach ( $receiptCollectList as $v ) {
  9185. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9186. $asum += $v ['price'];
  9187. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9188. $falg = false;
  9189. break;
  9190. }
  9191. }
  9192. if ($falg)
  9193. $html .= '<td class="taR">-</td>';
  9194. }
  9195. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9196. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9197. }
  9198. $data ['collectHtml'] = $collectHtml;
  9199. // create Adjustment price html
  9200. $receiptCollectList = $receiptDetail->find ( array (
  9201. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9202. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9203. 'groupby' => 'itemCategory,Month(date)',
  9204. 'asArray' => true
  9205. ) );
  9206. $adjustment = array ();
  9207. $collectArray = array (
  9208. '日常相关费用' => array (),
  9209. '差旅相关费用' => array (),
  9210. '培训班费用' => array (),
  9211. '其他' => array ()
  9212. );
  9213. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9214. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9215. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9216. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9217. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9218. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9219. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9220. array_push ( $collectArray ['其他'], $collectHtml );
  9221. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9222. array_push ( $adjustment, $collectHtml );
  9223. // total price html
  9224. $collectHtml = "";
  9225. $total = 0;
  9226. for($i = 1; $i <= 12; $i ++) {
  9227. $sumPrice = 0;
  9228. foreach ( $receiptCollectList as $key => $value ) {
  9229. if ($value ['month'] == $i) {
  9230. $sumPrice += $value ['price'];
  9231. }
  9232. }
  9233. if ($sumPrice == 0)
  9234. $collectHtml .= '<td class="taR">-</td>';
  9235. else
  9236. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9237. $total += $sumPrice;
  9238. }
  9239. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9240. // statistics html
  9241. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9242. if (empty ( $stList ))
  9243. $stList = array (
  9244. 'rePrice' => 0,
  9245. 'agPrice' => 0
  9246. );
  9247. $data ['stList'] = array (
  9248. 'rePrice' => $stList ['rePrice'],
  9249. 'agPrice' => $stList ['agPrice'],
  9250. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9251. );
  9252. $data ['collectArray'] = $collectArray;
  9253. $data ['adjustment'] = $adjustment;
  9254. $data ['totalPrice'] = $collectHtml;
  9255. $data ['totalYear'] = $total;
  9256. $data ['year'] = $year;
  9257. $dateHtml = "";
  9258. $now = date ( "Y" );
  9259. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9260. if ($YEARD <= $now) {
  9261. $dateHtml .= '<option ';
  9262. if ($year == $YEARD) {
  9263. $dateHtml .= 'selected ';
  9264. }
  9265. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9266. }
  9267. }
  9268. $data ['dateHtml'] = $dateHtml;
  9269. $data ['memu'] = "receipt";
  9270. $data ['staff'] = $this->staff;
  9271. $data ['receiptMemu'] = 'personalCollect';
  9272. $data ['verifyId'] = $this->verifyId;
  9273. $data ['executeId'] = $this->executeId;
  9274. // year staff status 2,4
  9275. if ($year < date ( "Y" )) {
  9276. Doo::loadModel ( 'receipt' );
  9277. $receipt = new receipt ();
  9278. $receiptList = $receipt->find ( array (
  9279. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9280. 'asArray' => true
  9281. ) );
  9282. if (empty ( $receiptList )) {
  9283. ob_start ();
  9284. $this->render ( "/admin/saeaCollectArticles", $data );
  9285. $this->cacheFile ( $path );
  9286. die ();
  9287. }
  9288. }
  9289. $this->render ( "/admin/saeaCollectArticles", $data );
  9290. }
  9291. function companyCategoryCollect() {
  9292. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9293. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9294. $this->showCache ( $path );
  9295. Doo::loadModel ( 'L_category' );
  9296. Doo::loadModel ( 'itemStatistics' );
  9297. Doo::loadModel ( 'statistics' );
  9298. $statistics = new statistics ();
  9299. $Lcategory = new L_category ();
  9300. $itemStatistics = new itemStatistics ();
  9301. Doo::loadModel ( "receiptAuthorityManage" );
  9302. $receiptAuthorityManage = new receiptAuthorityManage ();
  9303. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9304. $cidList = array ();
  9305. foreach ( $imcStaff as $key => $value ) {
  9306. array_push ( $cidList, $value ['cid'] );
  9307. }
  9308. $cidString = implode ( ',', $cidList );
  9309. $LcategoryList = $Lcategory->find ( array (
  9310. 'where' => ' cid in (' . $cidString . ')',
  9311. 'asArray' => true
  9312. ) ); // 'staff='.$this->staff[0]['sid']." and
  9313. $itemStatisticsList = $itemStatistics->find ( array (
  9314. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9315. 'where' => " Year(date)=" . $year,
  9316. 'groupby' => 'cid,Month(date)',
  9317. 'asArray' => true
  9318. ) );
  9319. // ceatre companyCollectHtml
  9320. foreach ( $LcategoryList as $value ) {
  9321. $html = "";
  9322. $asum = 0;
  9323. for($i = 1; $i <= 12; $i ++) {
  9324. $falg = true;
  9325. foreach ( $itemStatisticsList as $v ) {
  9326. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9327. $asum += $v ['price'];
  9328. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9329. $falg = false;
  9330. break;
  9331. }
  9332. }
  9333. if ($falg)
  9334. $html .= '<td class="taR">-</td>';
  9335. }
  9336. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9337. $collectHtml [$value ['title']] = array (
  9338. 'html' => $html,
  9339. 'cid' => $value ['cid']
  9340. );
  9341. }
  9342. $data ['companyHtml'] = $collectHtml;
  9343. // total price html
  9344. $collectHtml = "";
  9345. $total = 0;
  9346. for($i = 1; $i <= 12; $i ++) {
  9347. $sumPrice = 0;
  9348. foreach ( $itemStatisticsList as $key => $value ) {
  9349. if ($value ['month'] == $i) {
  9350. $sumPrice += $value ['price'];
  9351. }
  9352. }
  9353. if ($sumPrice == 0)
  9354. $collectHtml .= '<td class="taR">-</td>';
  9355. else
  9356. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9357. $total += $sumPrice;
  9358. }
  9359. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9360. $data ['companyTotalHtml'] = $collectHtml;
  9361. $data ['total'] = $total;
  9362. // statistics html
  9363. // echo $cidString;
  9364. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9365. if (empty ( $stList ))
  9366. $stList = array (
  9367. 'rePrice' => 0,
  9368. 'agPrice' => 0
  9369. );
  9370. $data ['stList'] = array (
  9371. 'rePrice' => $stList ['rePrice'],
  9372. 'agPrice' => $stList ['agPrice'],
  9373. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9374. );
  9375. $data ['year'] = $year;
  9376. $data ['memu'] = "receipt";
  9377. $data ['staff'] = $this->staff;
  9378. $data ['receiptMemu'] = 'companyCategoryCollect';
  9379. $data ['verifyId'] = $this->verifyId;
  9380. $data ['executeId'] = $this->executeId;
  9381. $dateHtml = "";
  9382. $now = date ( "Y" );
  9383. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9384. if ($YEARD <= $now) {
  9385. $dateHtml .= '<option ';
  9386. if ($year == $YEARD) {
  9387. $dateHtml .= 'selected ';
  9388. }
  9389. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9390. }
  9391. }
  9392. $data ['dateHtml'] = $dateHtml;
  9393. // year staff status 2,4
  9394. if ($year < date ( "Y" )) {
  9395. Doo::loadModel ( 'receipt' );
  9396. $receipt = new receipt ();
  9397. $receiptList = $receipt->find ( array (
  9398. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9399. 'asArray' => true
  9400. ) );
  9401. if (empty ( $receiptList )) {
  9402. ob_start ();
  9403. $this->render ( "/admin/saeaCompanyCollect", $data );
  9404. $this->cacheFile ( $path );
  9405. die ();
  9406. }
  9407. }
  9408. $this->render ( "/admin/saeaCompanyCollect", $data );
  9409. }
  9410. function categoryCollectDetail() {
  9411. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9412. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9413. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9414. $this->showCache ( $path );
  9415. Doo::loadModel ( 'statistics' );
  9416. $statistics = new statistics ();
  9417. Doo::loadModel ( "receiptDetail" );
  9418. $receiptDetail = new receiptDetail ();
  9419. Doo::loadModel ( 'L_category' );
  9420. $Lcategory = new L_category ();
  9421. Doo::loadModel ( 'accountItem' );
  9422. $accountItem = new accountItem ();
  9423. Doo::loadModel ( "receiptAuthorityManage" );
  9424. $receiptAuthorityManage = new receiptAuthorityManage ();
  9425. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9426. $cidList = array ();
  9427. foreach ( $imcStaff as $key => $value ) {
  9428. array_push ( $cidList, $value ['cid'] );
  9429. }
  9430. $cidString = implode ( ',', $cidList );
  9431. $LcategoryList = $Lcategory->find ( array (
  9432. 'where' => 'cid in (' . $cidString . ')',
  9433. 'asArray' => true
  9434. ) );
  9435. if ($cid == 0) {
  9436. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9437. if ($cid == 0)
  9438. $cid = $LcategoryList [0] ['cid'];
  9439. }
  9440. $data ['LcategoryList'] = $LcategoryList;
  9441. $receiptCollectList = $receiptDetail->find ( array (
  9442. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9443. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9444. 'groupby' => 'item,Month(pastDate)',
  9445. 'asArray' => true
  9446. ) );
  9447. $accountList = $accountItem->find ( array (
  9448. 'asArray' => true
  9449. ) );
  9450. // create CollectDetail HTML
  9451. $collectHtml = array ();
  9452. foreach ( $accountList as $key => $value ) {
  9453. $html = "";
  9454. $asum = 0;
  9455. for($i = 1; $i <= 12; $i ++) {
  9456. $falg = true;
  9457. foreach ( $receiptCollectList as $v ) {
  9458. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9459. $asum += $v ['price'];
  9460. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9461. $falg = false;
  9462. break;
  9463. }
  9464. }
  9465. if ($falg)
  9466. $html .= '<td class="taR">-</td>';
  9467. }
  9468. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9469. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9470. }
  9471. $data ['collectHtml'] = $collectHtml;
  9472. // create Adjustment price html
  9473. $receiptCollectList = $receiptDetail->find ( array (
  9474. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9475. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9476. 'groupby' => 'itemCategory,Month(pastDate)',
  9477. 'asArray' => true
  9478. ) );
  9479. $adjustment = array ();
  9480. $collectArray = array (
  9481. '日常相关费用' => array (),
  9482. '差旅相关费用' => array (),
  9483. '培训班费用' => array (),
  9484. '内部培训费用'=>array(),
  9485. '其他' => array ()
  9486. );
  9487. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9488. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9489. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9490. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9491. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9492. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9493. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9494. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9495. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9496. array_push ( $collectArray ['其他'], $collectHtml );
  9497. $data ['collectArray'] = $collectArray;
  9498. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9499. array_push ( $adjustment, $collectHtml );
  9500. $data ['adjustment'] = $adjustment;
  9501. // total price html
  9502. $collectHtml = "";
  9503. $total = 0;
  9504. for($i = 1; $i <= 12; $i ++) {
  9505. $sumPrice = 0;
  9506. foreach ( $receiptCollectList as $key => $value ) {
  9507. if ($value ['month'] == $i) {
  9508. $sumPrice += $value ['price'];
  9509. }
  9510. }
  9511. if ($sumPrice == 0)
  9512. $collectHtml .= '<td class="taR">-</td>';
  9513. else
  9514. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9515. $total += $sumPrice;
  9516. }
  9517. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9518. // statistics html
  9519. $stList = $statistics->statisticsByCid ( $year, $cid );
  9520. if (empty ( $stList ))
  9521. $stList = array (
  9522. 'rePrice' => 0,
  9523. 'agPrice' => 0
  9524. );
  9525. $data ['stList'] = array (
  9526. 'rePrice' => $stList ['rePrice'],
  9527. 'agPrice' => $stList ['agPrice'],
  9528. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9529. );
  9530. $data ['totalYear'] = $total;
  9531. $data ['year'] = $year;
  9532. $data ['cid'] = $cid;
  9533. $data ['memu'] = "receipt";
  9534. $data ['staff'] = $this->staff;
  9535. $data ['receiptMemu'] = 'companyCategoryCollect';
  9536. $data ['verifyId'] = $this->verifyId;
  9537. $data ['executeId'] = $this->executeId;
  9538. // year staff status 2,4
  9539. if ($year < date ( "Y" )) {
  9540. Doo::loadModel ( 'receipt' );
  9541. $receipt = new receipt ();
  9542. $receiptList = $receipt->find ( array (
  9543. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9544. 'asArray' => true
  9545. ) );
  9546. if (empty ( $receiptList )) {
  9547. ob_start ();
  9548. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9549. $this->cacheFile ( $path );
  9550. die ();
  9551. }
  9552. }
  9553. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9554. }
  9555. function staffCollect() {
  9556. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9557. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9558. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9559. // $this->showCache($path);
  9560. Doo::loadModel ( 'statistics' );
  9561. $statistics = new statistics ();
  9562. Doo::loadModel ( "receiptDetail" );
  9563. $receiptDetail = new receiptDetail ();
  9564. Doo::loadModel ( 'L_category' );
  9565. $Lcategory = new L_category ();
  9566. Doo::loadModel ( 'accountItem' );
  9567. $accountItem = new accountItem ();
  9568. Doo::loadModel ( 'staff' );
  9569. $staff = new staff ();
  9570. Doo::loadModel ( 'itemStatistics' );
  9571. $itemStatistics = new itemStatistics ();
  9572. Doo::loadModel ( "receiptAuthorityManage" );
  9573. $receiptAuthorityManage = new receiptAuthorityManage ();
  9574. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9575. $cidList = array ();
  9576. foreach ( $imcStaff as $key => $value ) {
  9577. array_push ( $cidList, $value ['cid'] );
  9578. }
  9579. $cidString = implode ( ',', $cidList );
  9580. $naturecon='';
  9581. if ($nature=='ONJOB'){
  9582. $naturecon=' and (nature!=4 )';
  9583. }elseif($nature=='LEAVEJOB'){
  9584. $naturecon=' and (nature=4 )';
  9585. }else{
  9586. die ( 'illegal request--nature' );
  9587. }
  9588. // statistics html
  9589. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9590. if (empty ( $stList ))
  9591. $stList = array (
  9592. 'rePrice' => 0,
  9593. 'agPrice' => 0
  9594. );
  9595. $data ['stList'] = array (
  9596. 'rePrice' => $stList ['rePrice'],
  9597. 'agPrice' => $stList ['agPrice'],
  9598. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9599. );
  9600. // ---
  9601. $staffList = $staff->find ( array (
  9602. 'where' => 'username !="admin" '.$naturecon,
  9603. 'asArray' => true
  9604. ) );
  9605. $LcategoryList = $Lcategory->find ( array (
  9606. 'asArray' => true
  9607. ) ); // 'staff='.$this->staff[0]['sid']." and
  9608. $itemStatisticsList = $itemStatistics->find ( array (
  9609. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9610. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9611. 'groupby' => 'staff,Month(date)',
  9612. 'asArray' => true
  9613. ) );
  9614. $categoryList = $staff->find ( array (
  9615. 'select' => 'COUNT(*) as count,cid,category',
  9616. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9617. 'groupby' => 'cid',
  9618. 'asArray' => true
  9619. ) );
  9620. // print_r($itemStatisticsList);die;
  9621. // ceatre companyCollectHtml
  9622. foreach ( $categoryList as $vlu ) {
  9623. $count = $vlu ['count'] + 1;
  9624. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9625. $m1 = 0;
  9626. $m2 = 0;
  9627. $m3 = 0;
  9628. $m4 = 0;
  9629. $m5 = 0;
  9630. $m6 = 0;
  9631. $m7 = 0;
  9632. $m8 = 0;
  9633. $m9 = 0;
  9634. $m10 = 0;
  9635. $m11 = 0;
  9636. $m12 = 0;
  9637. $m13 = 0;
  9638. foreach ( $staffList as $value ) {
  9639. if ($vlu ['cid'] == $value ['cid']) {
  9640. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9641. $asum = 0;
  9642. for($i = 1; $i <= 12; $i ++) {
  9643. $falg = true;
  9644. foreach ( $itemStatisticsList as $v ) {
  9645. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9646. if ($v ['month'] == 1)
  9647. $m1 += $v ['price'];
  9648. if ($v ['month'] == 2)
  9649. $m2 += $v ['price'];
  9650. if ($v ['month'] == 3)
  9651. $m3 += $v ['price'];
  9652. if ($v ['month'] == 4)
  9653. $m4 += $v ['price'];
  9654. if ($v ['month'] == 5)
  9655. $m5 += $v ['price'];
  9656. if ($v ['month'] == 6)
  9657. $m6 += $v ['price'];
  9658. if ($v ['month'] == 7)
  9659. $m7 += $v ['price'];
  9660. if ($v ['month'] == 8)
  9661. $m8 += $v ['price'];
  9662. if ($v ['month'] == 9)
  9663. $m9 += $v ['price'];
  9664. if ($v ['month'] == 10)
  9665. $m10 += $v ['price'];
  9666. if ($v ['month'] == 11)
  9667. $m11 += $v ['price'];
  9668. if ($v ['month'] == 12)
  9669. $m12 += $v ['price'];
  9670. $asum += $v ['price'];
  9671. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9672. $falg = false;
  9673. break;
  9674. }
  9675. }
  9676. if ($falg)
  9677. $html .= '<td class="taR">-</td>';
  9678. }
  9679. $m13 += $asum;
  9680. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9681. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9682. 'html' => $html,
  9683. 'sid' => $value ['sid']
  9684. );
  9685. $html = "";
  9686. }
  9687. }
  9688. $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>
  9689. <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>
  9690. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9691. $collectHtml [$vlu ['cid']] = array (
  9692. 'html' => $hl,
  9693. 'sid' => ''
  9694. );
  9695. }
  9696. $data ['companyHtml'] = $collectHtml;
  9697. // total price html
  9698. $collectHtml = "";
  9699. $total = 0;
  9700. for($i = 1; $i <= 12; $i ++) {
  9701. $sumPrice = 0;
  9702. foreach ( $itemStatisticsList as $key => $value ) {
  9703. if ($value ['month'] == $i) {
  9704. $sumPrice += $value ['price'];
  9705. }
  9706. }
  9707. if ($sumPrice == 0)
  9708. $collectHtml .= '<td class="taR">-</td>';
  9709. else
  9710. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9711. $total += $sumPrice;
  9712. }
  9713. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9714. $data ['companyTotalHtml'] = $collectHtml;
  9715. $data ['total'] = $total;
  9716. $data ['nature'] =$nature;
  9717. $data ['year'] = $year;
  9718. $data ['memu'] = "receipt";
  9719. $data ['staff'] = $this->staff;
  9720. $data ['receiptMemu'] = 'companyCategoryCollect';
  9721. $data ['verifyId'] = $this->verifyId;
  9722. $data ['executeId'] = $this->executeId;
  9723. if ($year <= date ( "Y" )) {
  9724. Doo::loadModel ( 'receipt' );
  9725. $receipt = new receipt ();
  9726. $receiptList = $receipt->find ( array (
  9727. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9728. 'asArray' => true
  9729. ) );
  9730. if (empty ( $receiptList )) { // generated files
  9731. ob_start ();
  9732. $this->render ( "/admin/saeaStaffCollectB", $data );
  9733. $this->cacheFile ( $path );
  9734. die ();
  9735. }
  9736. }
  9737. $this->render ( "/admin/saeaStaffCollectB", $data );
  9738. }
  9739. function staffCollectBak() {
  9740. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9741. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9742. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9743. $this->showCache ( $path );
  9744. Doo::loadModel ( 'statistics' );
  9745. $statistics = new statistics ();
  9746. Doo::loadModel ( "receiptDetail" );
  9747. $receiptDetail = new receiptDetail ();
  9748. Doo::loadModel ( 'L_category' );
  9749. $Lcategory = new L_category ();
  9750. Doo::loadModel ( 'accountItem' );
  9751. $accountItem = new accountItem ();
  9752. Doo::loadModel ( 'staff' );
  9753. $staff = new staff ();
  9754. Doo::loadModel ( 'itemStatistics' );
  9755. $itemStatistics = new itemStatistics ();
  9756. $itemStatisticsList = $itemStatistics->find ( array (
  9757. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9758. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9759. 'groupby' => 'staff,itemCategory,Month(date)',
  9760. 'asArray' => true
  9761. ) );
  9762. $itemCategoryList = $itemStatistics->find ( array (
  9763. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9764. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9765. 'groupby' => 'cid,itemCategory,Month(date)',
  9766. 'asArray' => true
  9767. ) );
  9768. $LcategoryList = $Lcategory->find ( array (
  9769. 'asArray' => true
  9770. ) );
  9771. $staffList = $staff->find ( array (
  9772. 'asArray' => true
  9773. ) );
  9774. $htmlArray = array ();
  9775. foreach ( $LcategoryList as $value ) {
  9776. $htmlArray [$value ['title']] = array ();
  9777. foreach ( $staffList as $v ) {
  9778. if ($value ['cid'] == $v ['cid']) {
  9779. $html = "";
  9780. $falg = true;
  9781. $staffSumPrice = 0;
  9782. foreach ( $itemStatisticsList as $a ) {
  9783. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9784. if (empty ( $a ['price'] )) {
  9785. $html .= '<td class="taR">-</td>';
  9786. $falg = false;
  9787. break;
  9788. } else {
  9789. $staffSumPrice += $a ['price'];
  9790. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9791. $falg = false;
  9792. break;
  9793. }
  9794. }
  9795. }
  9796. if ($falg) {
  9797. $html .= '<td class="taR">-</td>';
  9798. $falg = true;
  9799. }
  9800. $falg = true;
  9801. foreach ( $itemStatisticsList as $a ) {
  9802. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9803. if (empty ( $a ['price'] )) {
  9804. $html .= '<td class="taR">-</td>';
  9805. $falg = false;
  9806. break;
  9807. } else {
  9808. $staffSumPrice += $a ['price'];
  9809. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9810. $falg = false;
  9811. break;
  9812. }
  9813. }
  9814. }
  9815. if ($falg) {
  9816. $html .= '<td class="taR">-</td>';
  9817. $falg = true;
  9818. }
  9819. $falg = true;
  9820. foreach ( $itemStatisticsList as $a ) {
  9821. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9822. if (empty ( $a ['price'] )) {
  9823. $html .= '<td class="taR">-</td>';
  9824. $falg = false;
  9825. break;
  9826. } else {
  9827. $staffSumPrice += $a ['price'];
  9828. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9829. $falg = false;
  9830. break;
  9831. }
  9832. }
  9833. }
  9834. if ($falg) {
  9835. $html .= '<td class="taR">-</td>';
  9836. $falg = true;
  9837. }
  9838. $falg = true;
  9839. foreach ( $itemStatisticsList as $a ) {
  9840. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9841. if (! empty ( $a ['price'] )) {
  9842. $staffSumPrice += $a ['price'];
  9843. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9844. $falg = false;
  9845. break;
  9846. } else {
  9847. $html .= '<td class="taR">-</td>';
  9848. $falg = false;
  9849. break;
  9850. }
  9851. }
  9852. }
  9853. if ($falg) {
  9854. $html .= '<td class="taR">-</td>';
  9855. $falg = true;
  9856. }
  9857. $falg = true;
  9858. foreach ( $itemStatisticsList as $a ) {
  9859. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9860. if (! empty ( $a ['price'] )) {
  9861. $staffSumPrice += $a ['price'];
  9862. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9863. $falg = false;
  9864. break;
  9865. } else {
  9866. $html .= '<td class="taR">-</td>';
  9867. $falg = false;
  9868. break;
  9869. }
  9870. }
  9871. }
  9872. if ($falg) {
  9873. $html .= '<td class="taR">-</td>';
  9874. $falg = true;
  9875. }
  9876. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9877. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9878. }
  9879. }
  9880. /* -- --- */
  9881. // 合计费用
  9882. $cateHtml = "";
  9883. $catePrice = 0;
  9884. $cateFalg = true;
  9885. foreach ( $itemCategoryList as $l ) {
  9886. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9887. if (empty ( $l ['price'] )) {
  9888. $cateHtml .= '<td class="colGreen taR">-</td>';
  9889. $cateFalg = false;
  9890. break;
  9891. } else {
  9892. $catePrice += $l ['price'];
  9893. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9894. $cateFalg = false;
  9895. break;
  9896. }
  9897. }
  9898. }
  9899. if ($cateFalg) {
  9900. $cateHtml .= '<td class="colGreen taR">-</td>';
  9901. $cateFalg = true;
  9902. }
  9903. $cateFalg = true;
  9904. foreach ( $itemCategoryList as $l ) {
  9905. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9906. if (empty ( $l ['price'] )) {
  9907. $cateHtml .= '<td class="colGreen taR">-</td>';
  9908. $cateFalg = false;
  9909. break;
  9910. } else {
  9911. $catePrice += $l ['price'];
  9912. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9913. $cateFalg = false;
  9914. break;
  9915. }
  9916. }
  9917. }
  9918. if ($cateFalg) {
  9919. $cateHtml .= '<td class="colGreen taR">-</td>';
  9920. $cateFalg = true;
  9921. }
  9922. $cateFalg = true;
  9923. foreach ( $itemCategoryList as $l ) {
  9924. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9925. if (empty ( $l ['price'] )) {
  9926. $cateHtml .= '<td class="colGreen taR">-</td>';
  9927. $cateFalg = false;
  9928. break;
  9929. } else {
  9930. $catePrice += $l ['price'];
  9931. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9932. $cateFalg = false;
  9933. break;
  9934. }
  9935. }
  9936. }
  9937. if ($cateFalg) {
  9938. $cateHtml .= '<td class="colGreen taR">-</td>';
  9939. $cateFalg = true;
  9940. }
  9941. $cateFalg = true;
  9942. foreach ( $itemCategoryList as $l ) {
  9943. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  9944. if (empty ( $l ['price'] )) {
  9945. $cateHtml .= '<td class="colGreen taR">-</td>';
  9946. $cateFalg = false;
  9947. break;
  9948. } else {
  9949. $catePrice += $l ['price'];
  9950. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9951. $cateFalg = false;
  9952. break;
  9953. }
  9954. }
  9955. }
  9956. if ($cateFalg) {
  9957. $cateHtml .= '<td class="colGreen taR">-</td>';
  9958. $cateFalg = true;
  9959. }
  9960. $cateFalg = true;
  9961. foreach ( $itemCategoryList as $l ) {
  9962. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  9963. if (empty ( $l ['price'] )) {
  9964. $cateHtml .= '<td class="colGreen taR">-</td>';
  9965. $cateFalg = false;
  9966. break;
  9967. } else {
  9968. $catePrice += $l ['price'];
  9969. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9970. $cateFalg = false;
  9971. break;
  9972. }
  9973. }
  9974. }
  9975. if ($cateFalg) {
  9976. $cateHtml .= '<td class="colGreen taR">-</td>';
  9977. $cateFalg = true;
  9978. }
  9979. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  9980. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  9981. /* -- --- */
  9982. }
  9983. // print_r($htmlArray);die;
  9984. $data ['htmlArray'] = $htmlArray;
  9985. // statistics html
  9986. $stList = $statistics->getOne ( array (
  9987. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  9988. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9989. 'groupby' => 'Month(date)',
  9990. 'asArray' => true
  9991. ) );
  9992. if (empty ( $stList ))
  9993. $stList = array (
  9994. 'rePrice' => 0,
  9995. 'agPrice' => 0
  9996. );
  9997. $data ['stList'] = array (
  9998. 'rePrice' => $stList ['rePrice'],
  9999. 'agPrice' => $stList ['agPrice'],
  10000. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10001. );
  10002. $monthHtml = "";
  10003. for($i = 1; $i <= 12; $i ++) {
  10004. if ($i == $month)
  10005. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10006. else
  10007. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10008. }
  10009. $data ['monthHtml'] = $monthHtml;
  10010. $data ['year'] = $year;
  10011. $data ['month'] = $month;
  10012. $data ['memu'] = "receipt";
  10013. $data ['staff'] = $this->staff;
  10014. $data ['receiptMemu'] = 'companyCategoryCollect';
  10015. $data ['verifyId'] = $this->verifyId;
  10016. $data ['executeId'] = $this->executeId;
  10017. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10018. Doo::loadModel ( 'receipt' );
  10019. $receipt = new receipt ();
  10020. $receiptList = $receipt->find ( array (
  10021. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10022. 'asArray' => true
  10023. ) );
  10024. if (empty ( $receiptList )) { // generated files
  10025. ob_start ();
  10026. $this->render ( "/admin/saeaStaffCollect", $data );
  10027. $this->cacheFile ( $path );
  10028. die ();
  10029. }
  10030. }
  10031. $this->render ( "/admin/saeaStaffCollect", $data );
  10032. }
  10033. /**
  10034. * 日常收支
  10035. */
  10036. function payments() {
  10037. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10038. Doo::loadModel ( "execute" );
  10039. $execute = new execute ();
  10040. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10041. die ( 'illegal request' );
  10042. }
  10043. Doo::loadModel ( "accountBook" );
  10044. $accountBook = new accountBook ();
  10045. Doo::loadModel ( "accountBookStatistics" );
  10046. $accountBookStatistics = new accountBookStatistics ();
  10047. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10048. $list = $accountBook->getAccountBookByLimit ( 10 );
  10049. $data ['date'] = date ( "Y-m-d" );
  10050. $data ['statisticsList'] = $statisticsList;
  10051. $data ['list'] = $list;
  10052. $data ['memu'] = "receipt";
  10053. $data ['staff'] = $this->staff;
  10054. $data ['receiptMemu'] = 'payments';
  10055. $data ['verifyId'] = $this->verifyId;
  10056. $data ['executeId'] = $this->executeId;
  10057. $this->render ( "/expenses/payments", $data );
  10058. }
  10059. function paymentsIncomeDo() {
  10060. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10061. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10062. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10063. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10064. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10065. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10066. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10067. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10068. Doo::loadClass ( 'XDeode' );
  10069. $XDeode = new XDeode ( 5 );
  10070. Doo::loadModel ( "accountBook" );
  10071. Doo::loadModel ( "accountBookStatistics" );
  10072. Doo::loadModel ( 'wasteBook' );
  10073. // 记录流水时银行的转换
  10074. $accountBank = '';
  10075. if ($receivedBank == '纵横广发') {
  10076. $accountBank = 'CGBDeposit';
  10077. } elseif ($receivedBank == '纵横工行') {
  10078. $accountBank = 'ICBCDeposit';
  10079. } elseif ($receivedBank == '华润银行') {
  10080. $accountBank = 'HUADeposit';
  10081. } elseif ($receivedBank == '个人广发') {
  10082. $accountBank = 'PersonalDeposit';
  10083. }
  10084. if (empty ( $accountBank ))
  10085. die ( 'illegal request' );
  10086. // 收入为理财时特殊处理
  10087. if ($accountType == 7 || $accountType == 9) {
  10088. if ($receivedBank == '个人广发') {
  10089. die ( '个人广发 illegal request' );
  10090. }
  10091. // 添加一条收入
  10092. $accountBook = new accountBook ();
  10093. $accountBook->accountType = 10;
  10094. $accountBook->accountMsg = $accountMsg;
  10095. $accountBook->receivedPrice = $receivedPrice;
  10096. $accountBook->receivedMsg = $receivedMsg;
  10097. $accountBook->receivedBank = $receivedBank;
  10098. $accountBook->receivedDate = $receivedDate;
  10099. $accountBook->remarks = $remarks;
  10100. $accountBook->expensesType = 1;
  10101. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10102. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10103. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10104. $inComeId = $accountBook->insert ();
  10105. // 收支汇总-添加一条收入日常汇总
  10106. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10107. $accountBookStatistics = new accountBookStatistics ();
  10108. $item = array (
  10109. 'date' => date ( "Y-m-d" ),
  10110. 'accountType' => $abDetail ['accountType'],
  10111. 'accountMsg' => $abDetail ['accountMsg'],
  10112. 'aid' => $abDetail ['aid'],
  10113. 'inComePrice' => $abDetail ['receivedPrice'],
  10114. 'expensesType' => $abDetail ['expensesType']
  10115. );
  10116. $accountBookStatistics->setAccountBookStatistics ( $item );
  10117. // 添加收入流水
  10118. $wasteBook = new wasteBook ();
  10119. $itemWaste = array (
  10120. 'accountPriceShow' => $receivedPrice,
  10121. 'accountPrice' => $receivedPrice,
  10122. 'expensesType' => 1,
  10123. 'accountType' => 6, // 流水类型
  10124. 'dataID' => $inComeId,
  10125. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10126. 'accountBank' => $accountBank,
  10127. 'category' => $this->staff [0] ['category'],
  10128. 'cid' => $this->staff [0] ['cid'],
  10129. 'name' => $this->staff [0] ['username'],
  10130. 'sid' => $this->staff [0] ['sid'],
  10131. 'inputDate' => date ( "Y-m-d H:i:s" )
  10132. );
  10133. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10134. // 添加一条理财支出
  10135. $accountBank = 'CGBDeposit';
  10136. $expenditureBank = '纵横广发';
  10137. $dailyExpenditureType = 4;
  10138. if ($accountType == 9) {
  10139. $accountBank = 'ICBCDeposit';
  10140. $expenditureBank = '纵横工行';
  10141. $dailyExpenditureType = 6;
  10142. }
  10143. $accountBook = new accountBook ();
  10144. $accountBook->expensesType = 2;
  10145. $accountBook->expenditureType = $dailyExpenditureType;
  10146. $accountBook->expenditureMsg = $accountMsg;
  10147. $accountBook->expenditurePrice = $receivedPrice;
  10148. $accountBook->expenditureBank = $expenditureBank;
  10149. $accountBook->expenditureDate = $receivedDate;
  10150. $accountBook->remarks = $remarks;
  10151. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10152. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10153. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10154. $id = $accountBook->insert ();
  10155. // 收支汇总-添加一条理财支出汇总
  10156. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10157. $accountBookStatistics = new accountBookStatistics ();
  10158. $item = array (
  10159. 'date' => date ( "Y-m-d" ),
  10160. 'accountType' => $abDetail ['accountType'],
  10161. 'accountMsg' => $abDetail ['accountMsg'],
  10162. 'aid' => $abDetail ['aid'],
  10163. 'financingPrice' => - $receivedPrice,
  10164. 'expensesType' => 3
  10165. );
  10166. $accountBookStatistics->setAccountBookStatistics ( $item );
  10167. // 添加一条支出理财流水
  10168. $accountTypeWaste = 5;
  10169. if ($accountMsg == '公司固定') {
  10170. $accountTypeWaste = 9;
  10171. } elseif ($accountMsg == '公司活期') {
  10172. $accountTypeWaste = 10;
  10173. } elseif ($accountMsg == '个人(GR)') {
  10174. $accountBank = 'PersonalDeposit';
  10175. }
  10176. $itemWaste = array (
  10177. 'expensesType' => 2,
  10178. 'accountType' => $accountTypeWaste,
  10179. 'accountPriceShow' => $receivedPrice,
  10180. 'accountPrice' => - $receivedPrice,
  10181. 'dataID' => $id,
  10182. 'dailyExpenditureType' => $dailyExpenditureType,
  10183. 'accountBank' => $accountBank,
  10184. 'category' => $this->staff [0] ['category'],
  10185. 'cid' => $this->staff [0] ['cid'],
  10186. 'name' => $this->staff [0] ['username'],
  10187. 'sid' => $this->staff [0] ['sid'],
  10188. 'inputDate' => date ( "Y-m-d H:i:s" )
  10189. );
  10190. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10191. } elseif ($accountType == 1) {
  10192. if ($receivedBank == '个人广发')
  10193. die ( 'illegal request' );
  10194. // 添加一条收入
  10195. $accountBook = new accountBook ();
  10196. $accountBook->accountType = $accountType;
  10197. $accountBook->accountMsg = $accountMsg;
  10198. $accountBook->receivedPrice = $receivedPrice;
  10199. $accountBook->receivedMsg = $receivedMsg;
  10200. $accountBook->receivedBank = $receivedBank;
  10201. $accountBook->receivedDate = $receivedDate;
  10202. $accountBook->remarks = $remarks;
  10203. $accountBook->expensesType = 1;
  10204. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10205. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10206. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10207. $id = $accountBook->insert ();
  10208. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10209. // 收支汇总-添加一条收入日常汇总
  10210. $accountBookStatistics = new accountBookStatistics ();
  10211. $item = array (
  10212. 'date' => date ( "Y-m-d" ),
  10213. 'accountType' => $abDetail ['accountType'],
  10214. 'accountMsg' => $abDetail ['accountMsg'],
  10215. 'aid' => $abDetail ['aid'],
  10216. 'expensesType' => $abDetail ['expensesType']
  10217. );
  10218. if ($abDetail ['accountType'] == 8) {
  10219. $item += array (
  10220. 'inComePrice' => $abDetail ['receivedPrice']
  10221. );
  10222. } else {
  10223. $item += array (
  10224. 'inComePrice' => $abDetail ['receivedPrice']
  10225. );
  10226. }
  10227. $accountBookStatistics->setAccountBookStatistics ( $item );
  10228. // 流水存储方向
  10229. $itemWaste = array (
  10230. 'accountType' => 6
  10231. ); // 流水类型
  10232. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10233. // }else
  10234. if ($accountMsg == '活期理财收益') {
  10235. $itemWaste = array (
  10236. 'accountType' => 10
  10237. ); // 流水类型
  10238. }
  10239. // 添加收入流水
  10240. $wasteBook = new wasteBook ();
  10241. $itemWaste += array (
  10242. 'accountPrice' => $receivedPrice,
  10243. 'accountPriceShow' => $receivedPrice,
  10244. 'expensesType' => 1,
  10245. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10246. 'dataID' => $id,
  10247. 'accountBank' => $accountBank,
  10248. 'category' => $this->staff [0] ['category'],
  10249. 'cid' => $this->staff [0] ['cid'],
  10250. 'name' => $this->staff [0] ['username'],
  10251. 'sid' => $this->staff [0] ['sid'],
  10252. 'inputDate' => date ( "Y-m-d H:i:s" )
  10253. );
  10254. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10255. } else { // 普通日常收入处理
  10256. // 添加一条收入
  10257. $accountBook = new accountBook ();
  10258. $accountBook->accountType = $accountType;
  10259. $accountBook->accountMsg = $accountMsg;
  10260. $accountBook->receivedPrice = $receivedPrice;
  10261. $accountBook->receivedMsg = $receivedMsg;
  10262. $accountBook->receivedBank = $receivedBank;
  10263. $accountBook->receivedDate = $receivedDate;
  10264. $accountBook->remarks = $remarks;
  10265. $accountBook->expensesType = 1;
  10266. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10267. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10268. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10269. $id = $accountBook->insert ();
  10270. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10271. // 收支汇总-添加一条收入日常汇总
  10272. $accountBookStatistics = new accountBookStatistics ();
  10273. $item = array (
  10274. 'date' => date ( "Y-m-d" ),
  10275. 'accountType' => $abDetail ['accountType'],
  10276. 'accountMsg' => $abDetail ['accountMsg'],
  10277. 'aid' => $abDetail ['aid'],
  10278. 'expensesType' => $abDetail ['expensesType']
  10279. );
  10280. if ($abDetail ['accountType'] == 8) {
  10281. $item += array (
  10282. 'inComePrice' => $abDetail ['receivedPrice']
  10283. );
  10284. } else {
  10285. $item += array (
  10286. 'inComePrice' => $abDetail ['receivedPrice']
  10287. );
  10288. }
  10289. $accountBookStatistics->setAccountBookStatistics ( $item );
  10290. // 添加收入流水
  10291. $itemWaste = array (
  10292. 'accountPrice' => $receivedPrice
  10293. );
  10294. if ($receivedBank == '个人广发') {
  10295. $itemWaste = array (
  10296. 'accountPrice' => - $receivedPrice
  10297. );
  10298. }
  10299. $wasteBook = new wasteBook ();
  10300. $itemWaste += array (
  10301. 'accountPriceShow' => $receivedPrice,
  10302. 'expensesType' => 1,
  10303. 'accountType' => 6, // 流水类型
  10304. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10305. 'dataID' => $id,
  10306. 'accountBank' => $accountBank,
  10307. 'category' => $this->staff [0] ['category'],
  10308. 'cid' => $this->staff [0] ['cid'],
  10309. 'name' => $this->staff [0] ['username'],
  10310. 'sid' => $this->staff [0] ['sid'],
  10311. 'inputDate' => date ( "Y-m-d H:i:s" )
  10312. );
  10313. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10314. }
  10315. }
  10316. return '/payments';
  10317. }
  10318. /**
  10319. * 添加收入
  10320. * @return string
  10321. */
  10322. function paymentsIncomeDo_() {
  10323. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10324. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10325. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10326. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10327. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10328. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10329. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10330. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10331. Doo::loadClass ( 'XDeode' );
  10332. $XDeode = new XDeode ( 5 );
  10333. Doo::loadModel ( "accountBook" );
  10334. $accountBook = new accountBook ();
  10335. $accountBank = '';
  10336. $accountTypeWaste = 6;
  10337. if ($receivedBank == '纵横广发') {
  10338. $accountBank = 'CGBDeposit';
  10339. } elseif ($receivedBank == '纵横工行') {
  10340. $accountBank = 'ICBCDeposit';
  10341. } elseif ($receivedBank == '华润银行') {
  10342. $accountBank = 'HUADeposit';
  10343. } elseif ($receivedBank == '个人广发') {
  10344. $accountBank = 'PersonalDeposit';
  10345. }
  10346. if (empty ( $accountBank ))
  10347. die ( 'illegal request' );
  10348. $dailyIncomeType = '';
  10349. $itemWaste = array (
  10350. 'accountPrice' => $receivedPrice,
  10351. 'expensesType' => 1
  10352. );
  10353. if ($receivedBank == '个人广发') {
  10354. $itemWaste = array (
  10355. 'accountPrice' => - $receivedPrice,
  10356. 'expensesType' => 1
  10357. );
  10358. }
  10359. if ($accountType == 4) {
  10360. $dailyIncomeType = 4;
  10361. } elseif ($accountType == 1) {
  10362. $dailyIncomeType = 1;
  10363. } elseif ($accountType == 2) {
  10364. $dailyIncomeType = 2;
  10365. } elseif ($accountType == 3) {
  10366. $dailyIncomeType = 3;
  10367. } elseif ($accountType == 5) {
  10368. $dailyIncomeType = 5;
  10369. } elseif ($accountType == 6) {
  10370. $dailyIncomeType = 6;
  10371. } elseif ($accountType == 7 || $accountType == 9) {
  10372. $dailyIncomeType = 7;
  10373. if ($accountMsg == '公司固定') {
  10374. $accountTypeWaste = 9;
  10375. } elseif ($accountMsg == '公司活期') {
  10376. $accountTypeWaste = 10;
  10377. } elseif ($accountMsg == '个人(GR)') {
  10378. $accountBank = 'PersonalDeposit';
  10379. }
  10380. $itemWaste = array (
  10381. 'accountPrice' => - $receivedPrice,
  10382. 'expensesType' => 2
  10383. );
  10384. } elseif ($accountType == 8) {
  10385. $dailyIncomeType = 8;
  10386. }
  10387. if (empty ( $dailyIncomeType ))
  10388. die ( 'illegal request' );
  10389. $accountBook->accountType = $accountType;
  10390. $accountBook->accountMsg = $accountMsg;
  10391. $accountBook->receivedPrice = $receivedPrice;
  10392. $accountBook->receivedMsg = $receivedMsg;
  10393. $accountBook->receivedBank = $receivedBank;
  10394. $accountBook->receivedDate = $receivedDate;
  10395. $accountBook->remarks = $remarks;
  10396. $accountBook->expensesType = 1;
  10397. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10398. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10399. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10400. $id = $accountBook->insert ();
  10401. //
  10402. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10403. // 收支汇总
  10404. Doo::loadModel ( "accountBookStatistics" );
  10405. $accountBookStatistics = new accountBookStatistics ();
  10406. $item = array (
  10407. 'date' => date ( "Y-m-d" ),
  10408. 'accountType' => $abDetail ['accountType'],
  10409. 'accountMsg' => $abDetail ['accountMsg'],
  10410. 'aid' => $abDetail ['aid']
  10411. );
  10412. if ($abDetail ['expensesType'] == 1) {
  10413. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10414. $item += array (
  10415. 'financingPrice' => - $receivedPrice,
  10416. 'expensesType' => 3
  10417. );
  10418. } else if ($abDetail ['accountType'] == 8) {
  10419. $item += array (
  10420. 'inComePrice' => - $abDetail ['receivedPrice'],
  10421. 'expensesType' => $abDetail ['expensesType']
  10422. );
  10423. } else {
  10424. $item += array (
  10425. 'inComePrice' => $abDetail ['receivedPrice'],
  10426. 'expensesType' => $abDetail ['expensesType']
  10427. );
  10428. }
  10429. }
  10430. $accountBookStatistics->setAccountBookStatistics ( $item );
  10431. // 为理财时需添加一条日常支出
  10432. if ($accountType == 7 || $accountType == 9) {
  10433. }
  10434. // 公司流水记录
  10435. Doo::loadModel ( 'wasteBook' );
  10436. $wasteBook = new wasteBook ();
  10437. // 银行
  10438. // if (empty($abDetail)){
  10439. $itemWaste += array (
  10440. 'accountPriceShow' => $receivedPrice,
  10441. 'dataID' => $id,
  10442. 'accountType' => $accountTypeWaste,
  10443. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10444. 'accountBank' => $accountBank,
  10445. 'category' => $this->staff [0] ['category'],
  10446. 'cid' => $this->staff [0] ['cid'],
  10447. 'name' => $this->staff [0] ['username'],
  10448. 'sid' => $this->staff [0] ['sid'],
  10449. 'inputDate' => date ( "Y-m-d H:i:s" )
  10450. );
  10451. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10452. // }
  10453. // 类型为理财7或者9 要添加一笔理财支出
  10454. if ($accountType == 7 || $accountType == 9) {
  10455. $accountBank = 'CGBDeposit';
  10456. $expenditureBank = '纵横广发';
  10457. $dailyExpenditureType = 4;
  10458. if ($accountType == 9) {
  10459. $accountBank = 'ICBCDeposit';
  10460. $expenditureBank = '纵横工行';
  10461. $dailyExpenditureType = 6;
  10462. }
  10463. // 添加一条支出
  10464. $accountBook = new accountBook ();
  10465. $accountBook->expenditureType = $dailyExpenditureType;
  10466. $accountBook->expenditureMsg = $accountMsg;
  10467. $accountBook->expenditurePrice = $receivedPrice;
  10468. $accountBook->expenditureBank = $expenditureBank;
  10469. $accountBook->expenditureDate = $receivedDate;
  10470. $accountBook->remarks = $remarks;
  10471. $accountBook->expensesType = 2;
  10472. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10473. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10474. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10475. $id = $accountBook->insert ();
  10476. // 添加一条收入流水
  10477. $itemWaste = array (
  10478. 'accountPriceShow' => $receivedPrice,
  10479. 'accountPrice' => $receivedPrice,
  10480. 'dataID' => $id,
  10481. 'expensesType' => 2,
  10482. 'accountType' => $accountTypeWaste,
  10483. 'dailyExpenditureType' => $dailyExpenditureType,
  10484. 'accountBank' => $accountBank,
  10485. 'category' => $this->staff [0] ['category'],
  10486. 'cid' => $this->staff [0] ['cid'],
  10487. 'name' => $this->staff [0] ['username'],
  10488. 'sid' => $this->staff [0] ['sid'],
  10489. 'inputDate' => date ( "Y-m-d H:i:s" )
  10490. );
  10491. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10492. }
  10493. }
  10494. return '/payments';
  10495. }
  10496. function paymentsExpenditureDo() {
  10497. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10498. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10499. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10500. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10501. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10502. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10503. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10504. // 理财支出特殊处理
  10505. Doo::loadModel ( "accountBook" );
  10506. Doo::loadModel ( "accountBookStatistics" );
  10507. Doo::loadModel ( 'wasteBook' );
  10508. $accountBank = '';
  10509. if ($expenditureBank == '纵横广发') {
  10510. $accountBank = 'CGBDeposit';
  10511. } elseif ($expenditureBank == '纵横工行') {
  10512. $accountBank = 'ICBCDeposit';
  10513. } elseif ($expenditureBank == '华润银行') {
  10514. $accountBank = 'HUADeposit';
  10515. } elseif ($expenditureBank == '个人广发') {
  10516. $accountBank = 'PersonalDeposit';
  10517. }
  10518. if (empty ( $accountBank ))
  10519. die ( 'illegal request' );
  10520. if ($expenditureType == 4 || $expenditureType == 6) {
  10521. if ($expenditureBank == '个人广发') {
  10522. die ( '个人广发 illegal request' );
  10523. }
  10524. // 添加一笔日常支出
  10525. $accountBook = new accountBook ();
  10526. $accountBook->expensesType = 2;
  10527. $accountBook->expenditureType = 7;
  10528. $accountBook->expenditureMsg = $expenditureMsg;
  10529. $accountBook->expenditurePrice = $expenditurePrice;
  10530. $accountBook->expenditureBank = $expenditureBank;
  10531. $accountBook->expenditureDate = $expenditureDate;
  10532. $accountBook->remarks = $remarks;
  10533. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10534. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10535. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10536. $expenditureId = $accountBook->insert ();
  10537. // 添加日常支出汇总
  10538. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10539. $accountBookStatistics = new accountBookStatistics ();
  10540. $item = array (
  10541. 'date' => date ( "Y-m-d" ),
  10542. 'expenditureType' => $abDetail ['expenditureType'],
  10543. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10544. 'aid' => $abDetail ['aid'],
  10545. 'payPrice' => $abDetail ['expenditurePrice'],
  10546. 'expensesType' => $abDetail ['expensesType']
  10547. );
  10548. $accountBookStatistics->setAccountBookStatistics ( $item );
  10549. // 公司日常支出流水
  10550. $wasteBook = new wasteBook ();
  10551. $itemWaste = array (
  10552. 'accountPrice' => - $expenditurePrice
  10553. );
  10554. if ($expenditureBank == '个人广发') {
  10555. $itemWaste = array (
  10556. 'accountPrice' => $expenditurePrice
  10557. );
  10558. }
  10559. $itemWaste += array (
  10560. 'expensesType' => 2,
  10561. 'accountType' => 5,
  10562. 'dailyExpenditureType' => $expenditureType,
  10563. 'accountPriceShow' => $expenditurePrice,
  10564. 'accountPrice' => - $expenditurePrice,
  10565. 'dataID' => $expenditureId,
  10566. 'accountBank' => $accountBank,
  10567. 'category' => $this->staff [0] ['category'],
  10568. 'cid' => $this->staff [0] ['cid'],
  10569. 'name' => $this->staff [0] ['username'],
  10570. 'sid' => $this->staff [0] ['sid'],
  10571. 'inputDate' => date ( "Y-m-d H:i:s" )
  10572. );
  10573. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10574. // 添加一笔理财收入
  10575. $accountBank = 'CGBDeposit';
  10576. $dailyIncomeType = 7;
  10577. $receivedBank = '纵横广发';
  10578. if ($expenditureType == 6) {
  10579. $accountBank = 'ICBCDeposit';
  10580. $receivedBank = '纵横工行';
  10581. $dailyIncomeType = 9;
  10582. }
  10583. $accountBook = new accountBook ();
  10584. $accountBook->expensesType = 1;
  10585. $accountBook->accountType = $dailyIncomeType;
  10586. $accountBook->accountMsg = $expenditureMsg;
  10587. $accountBook->receivedPrice = $expenditurePrice;
  10588. $accountBook->receivedBank = $receivedBank;
  10589. $accountBook->receivedDate = $expenditureDate;
  10590. $accountBook->remarks = $remarks;
  10591. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10592. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10593. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10594. $id = $accountBook->insert ();
  10595. // 添加日常理财收入汇总
  10596. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10597. $accountBookStatistics = new accountBookStatistics ();
  10598. $item = array (
  10599. 'date' => date ( "Y-m-d" ),
  10600. 'expenditureType' => $abDetail ['expenditureType'],
  10601. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10602. 'aid' => $abDetail ['aid'],
  10603. 'financingPrice' => $expenditurePrice,
  10604. 'expensesType' => 3
  10605. );
  10606. $accountBookStatistics->setAccountBookStatistics ( $item );
  10607. // 添加一笔收入流水
  10608. if ($expenditureMsg == '公司固定') {
  10609. $accountTypeWaste = 9;
  10610. } elseif ($expenditureMsg == '公司活期') {
  10611. $accountTypeWaste = 10;
  10612. } elseif ($expenditureMsg == '个人(GR)') {
  10613. $accountBank = 'PersonalDeposit';
  10614. }
  10615. $itemWaste = array (
  10616. 'expensesType' => 1,
  10617. 'accountType' => $accountTypeWaste,
  10618. 'accountPriceShow' => $expenditurePrice,
  10619. 'accountPrice' => $expenditurePrice,
  10620. 'dataID' => $id,
  10621. 'dailyIncomeType' => $dailyIncomeType,
  10622. 'accountBank' => $accountBank,
  10623. 'category' => $this->staff [0] ['category'],
  10624. 'cid' => $this->staff [0] ['cid'],
  10625. 'name' => $this->staff [0] ['username'],
  10626. 'sid' => $this->staff [0] ['sid'],
  10627. 'inputDate' => date ( "Y-m-d H:i:s" )
  10628. );
  10629. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10630. } else {
  10631. // 添加一笔日常支出
  10632. $accountBook = new accountBook ();
  10633. $accountBook->expensesType = 2;
  10634. $accountBook->expenditureType = $expenditureType;
  10635. $accountBook->expenditureMsg = $expenditureMsg;
  10636. $accountBook->expenditurePrice = $expenditurePrice;
  10637. $accountBook->expenditureBank = $expenditureBank;
  10638. $accountBook->expenditureDate = $expenditureDate;
  10639. $accountBook->remarks = $remarks;
  10640. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10641. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10642. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10643. $id = $accountBook->insert ();
  10644. // 添加日常支出汇总
  10645. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10646. $accountBookStatistics = new accountBookStatistics ();
  10647. $item = array (
  10648. 'date' => date ( "Y-m-d" ),
  10649. 'expenditureType' => $abDetail ['expenditureType'],
  10650. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10651. 'aid' => $abDetail ['aid'],
  10652. 'expensesType' => $abDetail ['expensesType']
  10653. );
  10654. if ($expenditureType == 5) {
  10655. $item += array (
  10656. 'payPrice' => - $abDetail ['expenditurePrice']
  10657. );
  10658. } else {
  10659. $item += array (
  10660. 'payPrice' => $abDetail ['expenditurePrice']
  10661. );
  10662. }
  10663. $accountBookStatistics->setAccountBookStatistics ( $item );
  10664. // 公司日常支出流水
  10665. $wasteBook = new wasteBook ();
  10666. $itemWaste = array (
  10667. 'accountPrice' => - $expenditurePrice
  10668. );
  10669. if ($expenditureBank == '个人广发') {
  10670. $itemWaste = array (
  10671. 'accountPrice' => $expenditurePrice
  10672. );
  10673. }
  10674. $itemWaste += array (
  10675. 'expensesType' => 2,
  10676. 'accountType' => 5,
  10677. 'accountPriceShow' => $expenditurePrice,
  10678. 'dataID' => $id,
  10679. 'dailyExpenditureType' => $expenditureType,
  10680. 'accountBank' => $accountBank,
  10681. 'category' => $this->staff [0] ['category'],
  10682. 'cid' => $this->staff [0] ['cid'],
  10683. 'name' => $this->staff [0] ['username'],
  10684. 'sid' => $this->staff [0] ['sid'],
  10685. 'inputDate' => date ( "Y-m-d H:i:s" )
  10686. );
  10687. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10688. }
  10689. }
  10690. return '/payments';
  10691. }
  10692. /**
  10693. * 添加支出
  10694. */
  10695. function paymentsExpenditureDo_() {
  10696. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10697. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10698. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10699. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10700. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10701. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10702. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10703. $dailyExpenditureType = '';
  10704. $accountTypeWaste = 5;
  10705. $accountBank = '';
  10706. if ($expenditureBank == '纵横广发') {
  10707. $accountBank = 'CGBDeposit';
  10708. } elseif ($expenditureBank == '纵横工行') {
  10709. $accountBank = 'ICBCDeposit';
  10710. } elseif ($expenditureBank == '华润银行') {
  10711. $accountBank = 'HUADeposit';
  10712. } elseif ($expenditureBank == '个人广发') {
  10713. $accountBank = 'PersonalDeposit';
  10714. }
  10715. if (empty ( $accountBank ))
  10716. die ( 'illegal request' );
  10717. $itemWaste = array (
  10718. 'accountPrice' => - $expenditurePrice
  10719. );
  10720. if ($expenditureBank == '个人广发') {
  10721. $itemWaste = array (
  10722. 'accountPrice' => $expenditurePrice
  10723. );
  10724. }
  10725. if ($expenditureType == 4 || $expenditureType == 6) {
  10726. $dailyExpenditureType = 4;
  10727. if ($expenditureMsg == '公司固定') {
  10728. $accountTypeWaste = 9;
  10729. } elseif ($expenditureMsg == '公司活期') {
  10730. $accountTypeWaste = 10;
  10731. } elseif ($expenditureMsg == '个人(GR)') {
  10732. $accountBank = 'PersonalDeposit';
  10733. }
  10734. $itemWaste = array (
  10735. 'accountPrice' => $expenditurePrice
  10736. );
  10737. } elseif ($expenditureType == 1) {
  10738. $dailyExpenditureType = 1;
  10739. } elseif ($expenditureType == 2) {
  10740. $dailyExpenditureType = 2;
  10741. } elseif ($expenditureType == 3) {
  10742. $dailyExpenditureType = 3;
  10743. } elseif ($expenditureType == 5) {
  10744. $dailyExpenditureType = 5;
  10745. }
  10746. if (empty ( $dailyExpenditureType ))
  10747. die ( 'illegal request' );
  10748. Doo::loadModel ( "accountBook" );
  10749. $accountBook = new accountBook ();
  10750. $accountBook->expenditureType = $expenditureType;
  10751. $accountBook->expenditureMsg = $expenditureMsg;
  10752. $accountBook->expenditurePrice = $expenditurePrice;
  10753. $accountBook->expenditureBank = $expenditureBank;
  10754. $accountBook->expenditureDate = $expenditureDate;
  10755. $accountBook->remarks = $remarks;
  10756. $accountBook->expensesType = 2;
  10757. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10758. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10759. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10760. $id = $accountBook->insert ();
  10761. //
  10762. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10763. Doo::loadModel ( "accountBookStatistics" );
  10764. $accountBookStatistics = new accountBookStatistics ();
  10765. $item = array (
  10766. 'date' => date ( "Y-m-d" ),
  10767. 'expenditureType' => $abDetail ['expenditureType'],
  10768. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10769. 'aid' => $abDetail ['aid']
  10770. );
  10771. if ($abDetail ['expensesType'] == 2) {
  10772. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10773. $item += array (
  10774. 'financingPrice' => $expenditurePrice,
  10775. 'expensesType' => 3
  10776. );
  10777. } elseif ($abDetail ['expenditureType'] == 5) {
  10778. $item += array (
  10779. 'payPrice' => $abDetail ['expenditurePrice'],
  10780. 'expensesType' => $abDetail ['expensesType']
  10781. );
  10782. } else {
  10783. $item += array (
  10784. 'payPrice' => $abDetail ['expenditurePrice'],
  10785. 'expensesType' => $abDetail ['expensesType']
  10786. );
  10787. }
  10788. }
  10789. $accountBookStatistics->setAccountBookStatistics ( $item );
  10790. // 公司流水记录
  10791. Doo::loadModel ( 'wasteBook' );
  10792. $wasteBook = new wasteBook ();
  10793. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10794. // 银行
  10795. if (empty ( $abDetail )) {
  10796. $itemWaste += array (
  10797. 'accountPriceShow' => $expenditurePrice,
  10798. 'dataID' => $id,
  10799. 'expensesType' => 2,
  10800. 'accountType' => $accountTypeWaste,
  10801. 'dailyExpenditureType' => $expenditureType,
  10802. 'accountBank' => $accountBank,
  10803. 'category' => $this->staff [0] ['category'],
  10804. 'cid' => $this->staff [0] ['cid'],
  10805. 'name' => $this->staff [0] ['username'],
  10806. 'sid' => $this->staff [0] ['sid'],
  10807. 'inputDate' => date ( "Y-m-d H:i:s" )
  10808. );
  10809. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10810. }
  10811. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10812. if ($expenditureType == 4 || $expenditureType == 6) {
  10813. $accountBank = 'CGBDeposit';
  10814. $dailyIncomeType = 7;
  10815. $receivedBank = '纵横广发';
  10816. if ($expenditureType == 6) {
  10817. $accountBank = 'ICBCDeposit';
  10818. $receivedBank = '纵横工行';
  10819. $dailyIncomeType = 9;
  10820. }
  10821. // 添加一笔收入
  10822. $accountBook = new accountBook ();
  10823. $accountBook->accountType = $dailyIncomeType;
  10824. $accountBook->accountMsg = $expenditureMsg;
  10825. $accountBook->receivedPrice = $expenditurePrice;
  10826. $accountBook->receivedBank = $receivedBank;
  10827. $accountBook->receivedDate = $expenditureDate;
  10828. $accountBook->remarks = $remarks;
  10829. $accountBook->expensesType = 1;
  10830. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10831. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10832. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10833. $id = $accountBook->insert ();
  10834. // 添加一笔收入流水
  10835. $itemWaste = array (
  10836. 'accountPriceShow' => $expenditurePrice,
  10837. 'accountPrice' => - $expenditurePrice,
  10838. 'dataID' => $id,
  10839. 'expensesType' => 1,
  10840. 'accountType' => $accountTypeWaste,
  10841. 'dailyIncomeType' => $dailyIncomeType,
  10842. 'accountBank' => $accountBank,
  10843. 'category' => $this->staff [0] ['category'],
  10844. 'cid' => $this->staff [0] ['cid'],
  10845. 'name' => $this->staff [0] ['username'],
  10846. 'sid' => $this->staff [0] ['sid'],
  10847. 'inputDate' => date ( "Y-m-d H:i:s" )
  10848. );
  10849. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10850. }
  10851. }
  10852. return '/payments';
  10853. }
  10854. /**
  10855. * 所有收支
  10856. */
  10857. function paymentsAchieve() {
  10858. $page_size = 12;
  10859. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10860. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10861. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10862. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10863. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10864. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10865. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10866. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10867. Doo::loadModel ( "accountBookStatistics" );
  10868. $accountBookStatistics = new accountBookStatistics ();
  10869. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10870. $data ['statisticsList'] = $statisticsList;
  10871. Doo::loadModel ( "accountBook" );
  10872. $accountBook = new accountBook ();
  10873. $con = '';
  10874. if ($expensesType == 'INCOME')
  10875. $con = ' and expensesType=1 ';
  10876. elseif ($expensesType == 'PAY')
  10877. $con = ' and expensesType=2 ';
  10878. $dateArr = explode ( ':', $date );
  10879. $D1 = $dateString = '';
  10880. $D2 = '';
  10881. if (! empty ( $date )) {
  10882. $D1 = $dateArr [0];
  10883. if (isset ( $dateArr [1] ))
  10884. $D2 = $dateArr [1];
  10885. else
  10886. $D2 = '';
  10887. $dateString = $D1 . " : " . $D2;
  10888. }
  10889. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10890. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10891. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10892. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10893. if (! empty ( $price ))
  10894. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10895. if ($submitType == 1) {
  10896. if ($accountType != '') {
  10897. $expenditureType = '';
  10898. $con .= ' and accountType=' . $accountType;
  10899. if (! empty ( $accountMsg ))
  10900. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10901. }
  10902. } elseif ($submitType == 2) {
  10903. if ($expenditureType != '') {
  10904. $accountType = $accountMsg = '';
  10905. $con .= ' and expenditureType=' . $expenditureType;
  10906. }
  10907. } else {
  10908. $accountType = $accountMsg = $expenditureType = '';
  10909. }
  10910. $sql = "" . $con;
  10911. $action = "paymentsAchieve";
  10912. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10913. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10914. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10915. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10916. $data ['expenditureType'] = $expenditureType;
  10917. $data ['accountMsg'] = $accountMsg;
  10918. $data ['accountType'] = $accountType;
  10919. $data ['inputDate'] = $date;
  10920. $data ['price'] = $price;
  10921. $data ['expensesType'] = $expensesType;
  10922. $data ['page'] = $pageinfo;
  10923. $data ['list'] = $list;
  10924. $data ['memu'] = "receipt";
  10925. $data ['staff'] = $this->staff;
  10926. $data ['receiptMemu'] = 'payments';
  10927. $data ['verifyId'] = $this->verifyId;
  10928. $data ['executeId'] = $this->executeId;
  10929. $this->render ( "/expenses/paymentsAchieve", $data );
  10930. }
  10931. function paymentsIncomeUpdateDo() {
  10932. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10933. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10934. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10935. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10936. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10937. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10938. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10939. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10940. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10941. Doo::loadClass ( 'XDeode' );
  10942. $XDeode = new XDeode ( 5 );
  10943. $aid = $XDeode->decode ( $aidKey );
  10944. Doo::loadModel ( "accountBook" );
  10945. $accountBook = new accountBook ();
  10946. //
  10947. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10948. $price = $receivedPrice - $abDetail [inComePrice];
  10949. Doo::loadModel ( "accountBookStatistics" );
  10950. $accountBookStatistics = new accountBookStatistics ();
  10951. if ($abDetail ['accountType'] == 7) {
  10952. $item += array (
  10953. 'date' => date ( "Y-m-d" ),
  10954. 'financingPrice' => - $price,
  10955. 'expensesType' => 3,
  10956. 'aid' => $abDetail ['aid']
  10957. );
  10958. } elseif ($abDetail ['accountType'] == 8) {
  10959. $item += array (
  10960. 'date' => date ( "Y-m-d" ),
  10961. 'expensesType' => $abDetail ['expensesType'],
  10962. 'inComePrice' => - $price,
  10963. 'aid' => $abDetail ['aid']
  10964. );
  10965. } else {
  10966. $item = array (
  10967. 'date' => date ( "Y-m-d" ),
  10968. 'expensesType' => $abDetail ['expensesType'],
  10969. 'inComePrice' => $price,
  10970. 'aid' => $abDetail ['aid']
  10971. );
  10972. }
  10973. $accountBookStatistics->setAccountBookStatistics ( $item );
  10974. $accountBook->accountType = $accountType;
  10975. $accountBook->accountMsg = $accountMsg;
  10976. $accountBook->receivedPrice = $receivedPrice;
  10977. $accountBook->receivedMsg = $receivedMsg;
  10978. $accountBook->receivedBank = $receivedBank;
  10979. $accountBook->receivedDate = $receivedDate;
  10980. $accountBook->remarks = $remarks;
  10981. $accountBook->aid = $aid;
  10982. $accountBook->update ();
  10983. }
  10984. return '/paymentsAchieve';
  10985. }
  10986. function paymentsExpenditureEdiDo() {
  10987. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10988. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10989. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10990. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10991. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10992. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10993. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10994. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10995. Doo::loadClass ( 'XDeode' );
  10996. $XDeode = new XDeode ( 5 );
  10997. $aid = $XDeode->decode ( $aidKey );
  10998. Doo::loadModel ( "accountBook" );
  10999. $accountBook = new accountBook ();
  11000. // 汇总信息
  11001. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11002. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11003. Doo::loadModel ( "accountBookStatistics" );
  11004. $accountBookStatistics = new accountBookStatistics ();
  11005. if ($abDetail ['expenditureType'] == 4) {
  11006. $item += array (
  11007. 'date' => date ( "Y-m-d" ),
  11008. 'financingPrice' => $price,
  11009. 'expensesType' => 3,
  11010. 'aid' => $abDetail ['aid']
  11011. );
  11012. } elseif ($abDetail ['expenditureType'] == 5) {
  11013. $item += array (
  11014. 'date' => date ( "Y-m-d" ),
  11015. 'expensesType' => $abDetail ['expensesType'],
  11016. 'payPrice' => $price,
  11017. 'aid' => $abDetail ['aid']
  11018. );
  11019. } else {
  11020. $item = array (
  11021. 'date' => date ( "Y-m-d" ),
  11022. 'expensesType' => $abDetail ['expensesType'],
  11023. 'payPrice' => $price,
  11024. 'aid' => $abDetail ['aid']
  11025. );
  11026. }
  11027. $accountBookStatistics->setAccountBookStatistics ( $item );
  11028. //
  11029. $accountBook->expenditureType = $expenditureType;
  11030. $accountBook->expenditureMsg = $expenditureMsg;
  11031. $accountBook->expenditurePrice = $expenditurePrice;
  11032. $accountBook->expenditureBank = $expenditureBank;
  11033. $accountBook->remarks = $remarks;
  11034. $accountBook->expenditureDate = $expenditureDate;
  11035. $accountBook->aid = $aid;
  11036. $id = $accountBook->update ();
  11037. }
  11038. return '/paymentsAchieve';
  11039. }
  11040. function paymentsDelDo() {
  11041. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11042. if (! empty ( $aidKey )) {
  11043. Doo::loadClass ( 'XDeode' );
  11044. $XDeode = new XDeode ( 5 );
  11045. $aid = $XDeode->decode ( $aidKey );
  11046. Doo::loadModel ( "accountBook" );
  11047. $accountBook = new accountBook ();
  11048. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11049. if (empty ( $abDetail ))
  11050. die ( 'illegal request' );
  11051. // 删除收支
  11052. Doo::loadModel ( "accountBookStatistics" );
  11053. $accountBookStatistics = new accountBookStatistics ();
  11054. $item = array (
  11055. 'date' => date ( "Y-m-d" ),
  11056. 'aid' => $abDetail ['aid']
  11057. );
  11058. $accountType = '';
  11059. if ($abDetail ['expensesType'] == 1) {
  11060. $accountType = 6;
  11061. if ($abDetail ['accountType'] != 7) {
  11062. $item += array (
  11063. 'expensesType' => $abDetail ['expensesType'],
  11064. 'inComePrice' => - $abDetail ['receivedPrice']
  11065. );
  11066. } else {
  11067. $item += array (
  11068. 'financingPrice' => $abDetail ['receivedPrice'],
  11069. 'expensesType' => 3
  11070. );
  11071. }
  11072. } elseif ($abDetail ['expensesType'] == 2) {
  11073. $accountType = 5;
  11074. if ($abDetail ['accountType'] != 7) {
  11075. $item += array (
  11076. 'expensesType' => $abDetail ['expensesType'],
  11077. 'payPrice' => - $abDetail ['expenditurePrice']
  11078. );
  11079. } else {
  11080. $item += array (
  11081. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11082. 'expensesType' => 3
  11083. );
  11084. }
  11085. }
  11086. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11087. if ($abDetail ['expenditureMsg'] == '公司固定')
  11088. $accountType = 9;
  11089. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11090. $accountType = 10;
  11091. }
  11092. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11093. if ($abDetail ['accountMsg'] == '公司固定')
  11094. $accountType = 9;
  11095. elseif ($abDetail ['accountMsg'] == '公司活期')
  11096. $accountType = 10;
  11097. }
  11098. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11099. $accountType = 10;
  11100. }
  11101. $accountBookStatistics->setAccountBookStatistics ( $item );
  11102. $accountBook->delete ( array (
  11103. 'where' => 'aid=' . $aid,
  11104. 'limit' => 1
  11105. ) );
  11106. // 删除收入流水
  11107. if (! empty ( $accountType )) {
  11108. Doo::loadModel ( 'wasteBook' );
  11109. $wasteBook = new wasteBook ();
  11110. $wasteBook->delete ( array (
  11111. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11112. 'limit' => 1
  11113. ) );
  11114. }
  11115. }
  11116. return '/paymentsAchieve';
  11117. }
  11118. function paymentsCollect() {
  11119. Doo::loadModel ( "execute" );
  11120. $execute = new execute ();
  11121. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11122. die ( 'illegal request' );
  11123. }
  11124. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11125. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11126. Doo::loadModel ( "accountBookStatistics" );
  11127. $accountBookStatistics = new accountBookStatistics ();
  11128. Doo::loadClass ( 'receipt.func' );
  11129. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11130. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11131. $data ['html'] = $html ['html'];
  11132. $data ['inSum'] = $html ['sum'];
  11133. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11134. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11135. $data ['payHtml'] = $html ['html'];
  11136. $data ['paySum'] = $html ['sum'];
  11137. // 余额统计
  11138. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11139. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11140. include './protected/config/wasteBook.conf.php';
  11141. Doo::loadModel ( 'wasteBook' );
  11142. $wasteBook = new wasteBook ();
  11143. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11144. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11145. // 获得年份之前所有金额
  11146. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11147. // print_r($detail);
  11148. // $waste['total'];
  11149. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11150. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11151. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11152. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11153. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11154. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11155. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11156. if (date ( 'Y' ) > $year) {
  11157. $limitMonth = 12;
  11158. }
  11159. for($i = 1; $i <= 12; $i ++) {
  11160. $inComeA = $payB = 0;
  11161. $falg = true;
  11162. foreach ( $inComePay as $key => $value ) {
  11163. if ($value ['month'] == $i) {
  11164. $falg = false;
  11165. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11166. $inSum += $value ['accountPrice'];
  11167. $showInSum += $value ['accountPriceShow'];
  11168. $inComeA = $value ['accountPrice'];
  11169. break;
  11170. }
  11171. }
  11172. if ($falg)
  11173. $inComeHtml .= '<td class="taR">-</td>';
  11174. $payFalg = true;
  11175. foreach ( $pay as $key => $value ) {
  11176. if ($value ['month'] == $i) {
  11177. $payFalg = false;
  11178. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11179. $paySum += $value ['accountPrice'];
  11180. $showPaySum += $value ['accountPriceShow'];
  11181. $payB = $value ['accountPrice'];
  11182. break;
  11183. }
  11184. }
  11185. if ($payFalg)
  11186. $payHtml .= '<td class="taR">-</td>';
  11187. if (empty ( $balanceC ) || $limitMonth < $i)
  11188. $lastBalanceHtml .= '<td class="taR">-</td>';
  11189. else
  11190. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11191. $balanceC = $balanceC + $inComeA + $payB;
  11192. $balanceSum += $balanceC;
  11193. if (empty ( $balanceC ) || $limitMonth < $i)
  11194. $BalanceHtml .= '<td class="taR">-</td>';
  11195. else
  11196. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11197. // 余额统计
  11198. }
  11199. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11200. $data ['inComeHtml'] = $inComeHtml;
  11201. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11202. $data ['payBalanceHtml'] = $payHtml;
  11203. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11204. $data ['BalanceHtml'] = $BalanceHtml;
  11205. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11206. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11207. $mothHtml = "";
  11208. for($i = 1; $i <= 12; $i ++) {
  11209. if ($moth == $i)
  11210. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11211. else
  11212. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11213. }
  11214. $data ['mothHtml'] = $mothHtml;
  11215. $dateHtml = "";
  11216. $now = date ( "Y" );
  11217. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11218. if ($YEARD <= $now) {
  11219. $dateHtml .= '<option ';
  11220. if ($year == $YEARD) {
  11221. $dateHtml .= 'selected ';
  11222. }
  11223. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11224. }
  11225. }
  11226. $data ['dateHtml'] = $dateHtml;
  11227. $data ['year'] = $year;
  11228. $data ['memu'] = "receipt";
  11229. $data ['staff'] = $this->staff;
  11230. $data ['receiptMemu'] = 'paymentsCollect';
  11231. $data ['verifyId'] = $this->verifyId;
  11232. $data ['executeId'] = $this->executeId;
  11233. $this->render ( "/expenses/paymentsCollect", $data );
  11234. }
  11235. function paymentsCollectDay() {
  11236. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11237. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11238. if (empty ( $moth ))
  11239. return 'paymentsCollect';
  11240. Doo::loadModel ( "accountBookStatistics" );
  11241. $accountBookStatistics = new accountBookStatistics ();
  11242. $i = 2;
  11243. $y = 2013;
  11244. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11245. Doo::loadClass ( 'receipt.func' );
  11246. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11247. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11248. $data ['html'] = $html ['html'];
  11249. $data ['inSum'] = $html ['sum'];
  11250. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11251. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11252. $data ['payHtml'] = $html ['html'];
  11253. $data ['paySum'] = $html ['sum'];
  11254. $mothHtml = "";
  11255. for($i = 1; $i <= 12; $i ++) {
  11256. if ($moth == $i)
  11257. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11258. else
  11259. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11260. }
  11261. $data ['mothHtml'] = $mothHtml;
  11262. $data ['year'] = $year;
  11263. // 余额
  11264. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11265. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11266. include './protected/config/wasteBook.conf.php';
  11267. Doo::loadModel ( 'wasteBook' );
  11268. $wasteBook = new wasteBook ();
  11269. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11270. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11271. // 获得年份之前所有金额
  11272. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11273. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11274. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11275. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11276. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11277. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11278. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11279. // $balanceC = 0;
  11280. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11281. $limitDay = date ( 'd' );
  11282. $monthLK = ( int ) date ( 'm' );
  11283. if (date ( 'Y' ) > $year) {
  11284. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11285. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11286. $limitDay = 0;
  11287. }
  11288. for($i = 1; $i <= $day; $i ++) {
  11289. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11290. $inComeA = $payB = 0;
  11291. $falg = true;
  11292. foreach ( $inComePay as $key => $value ) {
  11293. if ($value ['day'] == $i) {
  11294. $falg = false;
  11295. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11296. $inSum += $value ['accountPrice'];
  11297. $showInSum += $value ['accountPriceShow'];
  11298. $inComeA = $value ['accountPrice'];
  11299. break;
  11300. }
  11301. }
  11302. if ($falg)
  11303. $inComeHtml .= '<td class="taR">-</td>';
  11304. $payFalg = true;
  11305. foreach ( $pay as $key => $value ) {
  11306. if ($value ['day'] == $i) {
  11307. $payFalg = false;
  11308. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11309. $paySum += $value ['accountPrice'];
  11310. $showPaySum += $value ['accountPriceShow'];
  11311. $payB = $value ['accountPrice'];
  11312. break;
  11313. }
  11314. }
  11315. if ($payFalg)
  11316. $payHtml .= '<td class="taR">-</td>';
  11317. if (empty ( $balanceC ) || $limitDay < $i)
  11318. $lastBalanceHtml .= '<td class="taR">-</td>';
  11319. else
  11320. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11321. $balanceC = $balanceC + $inComeA + $payB;
  11322. $balanceSum += $balanceC;
  11323. if (empty ( $balanceC ) || $limitDay < $i)
  11324. $BalanceHtml .= '<td class="taR">-</td>';
  11325. else
  11326. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11327. }
  11328. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11329. $data ['inComeHtml'] = $inComeHtml;
  11330. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11331. $data ['payBalanceHtml'] = $payHtml;
  11332. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11333. $data ['BalanceHtml'] = $BalanceHtml;
  11334. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11335. $data ['dayHtml'] = $dayHtml;
  11336. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11337. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11338. $dateHtml = "";
  11339. $now = date ( "Y" );
  11340. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11341. if ($YEARD <= $now) {
  11342. $dateHtml .= '<option ';
  11343. if ($year == $YEARD) {
  11344. $dateHtml .= 'selected ';
  11345. }
  11346. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11347. }
  11348. }
  11349. $data ['dateHtml'] = $dateHtml;
  11350. $data ['memu'] = "receipt";
  11351. $data ['staff'] = $this->staff;
  11352. $data ['receiptMemu'] = 'paymentsCollect';
  11353. $data ['verifyId'] = $this->verifyId;
  11354. $data ['executeId'] = $this->executeId;
  11355. $this->render ( "/expenses/paymentsCollectDay", $data );
  11356. }
  11357. // 公司流水
  11358. function wasteBook() {
  11359. Doo::loadModel ( "execute" );
  11360. $execute = new execute ();
  11361. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11362. die ( 'illegal request' );
  11363. }
  11364. include './protected/config/wasteBook.conf.php';
  11365. Doo::loadModel ( 'wasteBook' );
  11366. $wasteBook = new wasteBook ();
  11367. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11368. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11369. $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'];
  11370. // print_r($waste);
  11371. $data ['waste'] = $waste;
  11372. $data ['total'] = $total;
  11373. // 月流水数据结构
  11374. $monthStatistics = array ();
  11375. $incomeMothStatistics = array ();
  11376. $expenditureMothStatistics = array ();
  11377. for($i = 1; $i <= 12; $i ++) {
  11378. $month = date ( 'Y' ) . '-' . $i;
  11379. if ($i < 10)
  11380. $month = date ( 'Y' ) . '-0' . $i;
  11381. array_push ( $monthStatistics, $month );
  11382. }
  11383. foreach ( $monthStatistics as $value ) {
  11384. $falg = true;
  11385. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11386. if ($value == $v ['inputDate']) {
  11387. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11388. $falg = false;
  11389. }
  11390. }
  11391. if ($falg) {
  11392. array_push ( $incomeMothStatistics, '' );
  11393. }
  11394. $falgEx = true;
  11395. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11396. if ($value == $v ['inputDate']) {
  11397. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11398. $falg = false;
  11399. }
  11400. }
  11401. if ($falgEx) {
  11402. array_push ( $expenditureMothStatistics, '' );
  11403. }
  11404. }
  11405. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11406. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11407. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11408. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11409. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11410. // print_r($incomeList);
  11411. $data ['expenditureList'] = $expenditureList;
  11412. $data ['incomeList'] = $incomeList;
  11413. $data ['memu'] = "receipt";
  11414. $data ['staff'] = $this->staff;
  11415. $data ['receiptMemu'] = 'wasteBook';
  11416. $data ['verifyId'] = $this->verifyId;
  11417. $data ['executeId'] = $this->executeId;
  11418. $this->render ( "/expenses/wasteBook", $data );
  11419. }
  11420. function wasteBookIncome() {
  11421. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11422. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11423. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11424. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11425. $data ['dailyIncomeType'] = $dailyIncomeType;
  11426. Doo::loadModel ( 'wasteBook' );
  11427. $wasteBook = new wasteBook ();
  11428. Doo::loadModel ( 'L_category' );
  11429. $L_category = new L_category ();
  11430. Doo::loadClass ( 'XDeode' );
  11431. $XDeode = new XDeode ( 5 );
  11432. // echo $XDeode->encode(1).'<br>';
  11433. // echo $XDeode->encode(2).'<br>';
  11434. // echo $XDeode->encode(3).'<br>';
  11435. // echo $XDeode->encode(4).'<br>';
  11436. // echo $XDeode->encode(5).'<br>';
  11437. // echo $XDeode->encode(6).'<br>';
  11438. // echo $XDeode->encode(7).'<br>';
  11439. // echo $XDeode->encode(8).'<br>';
  11440. // echo $XDeode->encode(9).'<br>';
  11441. // echo $XDeode->encode(10).'<br>';
  11442. $dateArr = explode ( ':', $date );
  11443. $D1 = '';
  11444. $D2 = '';
  11445. $con = '';
  11446. if (! empty ( $date )) {
  11447. $D1 = $dateArr [0];
  11448. $D2 = $dateArr [1];
  11449. }
  11450. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11451. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11452. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11453. $con = ' and inputDate = "' . $D1 . '"';
  11454. if ($cid != 'ALL') {
  11455. $cid = $XDeode->decode ( $cid );
  11456. $con .= ' and cid = "' . $cid . '"';
  11457. }
  11458. if ($accountType != 'ALL') {
  11459. if ($accountType == 'INVOICE') {
  11460. $con .= ' and (accountType = 7 or accountType = 8)';
  11461. } elseif ($accountType == 'PAYMENTS') {
  11462. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11463. if ($dailyIncomeType != 'ALL') {
  11464. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11465. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11466. }
  11467. }
  11468. }
  11469. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11470. $sum = 0;
  11471. foreach ( $incomeList as $key => $value ) {
  11472. $sum += $value ['accountPrice'];
  11473. }
  11474. // print_r($incomeList);
  11475. // 获得办事和部门
  11476. $categoryList = $L_category->getCategory ();
  11477. $data ['accountType'] = $accountType;
  11478. $data ['cid'] = $cid;
  11479. $data ['categoryList'] = $categoryList;
  11480. $data ['sum'] = $sum;
  11481. $data ['incomeList'] = $incomeList;
  11482. $data ['inputDate'] = $date;
  11483. $data ['memu'] = "receipt";
  11484. $data ['staff'] = $this->staff;
  11485. $data ['receiptMemu'] = 'wasteBook';
  11486. $data ['verifyId'] = $this->verifyId;
  11487. $data ['executeId'] = $this->executeId;
  11488. $this->render ( "/expenses/wasteBookIncome", $data );
  11489. }
  11490. /**
  11491. * 所有支出
  11492. */
  11493. function wasteBookExpenditure() {
  11494. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11495. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11496. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11497. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11498. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11499. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11500. $data ['receiptType'] = $receiptType;
  11501. Doo::loadModel ( 'wasteBook' );
  11502. $wasteBook = new wasteBook ();
  11503. Doo::loadModel ( 'L_category' );
  11504. $L_category = new L_category ();
  11505. Doo::loadClass ( 'XDeode' );
  11506. $XDeode = new XDeode ( 5 );
  11507. $dateArr = explode ( ':', $date );
  11508. $D1 = '';
  11509. $D2 = '';
  11510. $con = '';
  11511. if (! empty ( $date )) {
  11512. $D1 = $dateArr [0];
  11513. $D2 = $dateArr [1];
  11514. }
  11515. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11516. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11517. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11518. $con = ' and inputDate = "' . $D1 . '"';
  11519. if ($cid != 'ALL') {
  11520. $cid = $XDeode->decode ( $cid );
  11521. $con .= ' and cid = "' . $cid . '"';
  11522. }
  11523. if ($accountType != 'ALL') {
  11524. if ($accountType == 'INVOICE') {
  11525. $con .= ' and accountType = 11';
  11526. } elseif ($accountType == 'PAYMENTS') {
  11527. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11528. if ($dailyExpenditureType != 'ALL') {
  11529. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11530. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11531. }
  11532. } elseif ($accountType == 'RECEIPT') {
  11533. if ($receiptType == 'ALL') {
  11534. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11535. } else {
  11536. $receiptType = $XDeode->decode ( $receiptType );
  11537. echo $receiptType;
  11538. if ($receiptType == 1) {
  11539. $con .= ' and (accountType = 1 or accountType=2)';
  11540. } else {
  11541. $con .= ' and accountType = ' . $receiptType;
  11542. }
  11543. }
  11544. }
  11545. }
  11546. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11547. $sum = 0;
  11548. foreach ( $incomeList as $key => $value ) {
  11549. $sum += $value ['accountPriceShow'];
  11550. }
  11551. // print_r($incomeList);
  11552. // 获得办事和部门
  11553. $categoryList = $L_category->getCategory ();
  11554. $data ['accountType'] = $accountType;
  11555. $data ['cid'] = $cid;
  11556. $data ['categoryList'] = $categoryList;
  11557. $data ['sum'] = $sum;
  11558. $data ['incomeList'] = $incomeList;
  11559. $data ['inputDate'] = $date;
  11560. $data ['memu'] = "receipt";
  11561. $data ['staff'] = $this->staff;
  11562. $data ['receiptMemu'] = 'wasteBook';
  11563. $data ['verifyId'] = $this->verifyId;
  11564. $data ['executeId'] = $this->executeId;
  11565. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11566. }
  11567. function ajaxGetWasteinvoiceReceivables() {
  11568. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11569. Doo::loadClass ( 'XDeode' );
  11570. $XDeode = new XDeode ( 5 );
  11571. $irid = $XDeode->decode ( $serial );
  11572. Doo::loadModel ( 'invoiceReceivables' );
  11573. $invoiceReceivables = new invoiceReceivables ();
  11574. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11575. echo json_encode ( array (
  11576. 'status' => 1,
  11577. 'detail' => $detail
  11578. ) );
  11579. }
  11580. function ajaxGetPaymentsByAid() {
  11581. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11582. Doo::loadModel ( "accountBook" );
  11583. $accountBook = new accountBook ();
  11584. $detail = $accountBook->getAccountBookByAid ( $serial );
  11585. echo json_encode ( array (
  11586. 'status' => 1,
  11587. 'detail' => $detail
  11588. ) );
  11589. }
  11590. function ajaxGetWasteInvoice() {
  11591. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11592. Doo::loadModel ( 'invoice' );
  11593. $invoice = new invoice ();
  11594. Doo::loadModel ( 'invoiceReceivables' );
  11595. $invoiceReceivables = new invoiceReceivables ();
  11596. $detail = $invoice->getInvoiceByIid ( $serial );
  11597. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11598. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11599. echo json_encode ( array (
  11600. 'status' => 1,
  11601. 'detail' => $detail
  11602. ) );
  11603. }
  11604. /**
  11605. */
  11606. function ajaxGetWasteReceipt() {
  11607. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11608. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11609. Doo::loadModel ( 'receipt' );
  11610. $receipt = new receipt ();
  11611. Doo::loadClass ( 'XDeode' );
  11612. $XDeode = new XDeode ( 5 );
  11613. $rid = $XDeode->decode ( $serial );
  11614. $accountType= $XDeode->decode ( $accountTypeKey );
  11615. // 获得个数据
  11616. $detail = $receipt->getReceiptByRid ( $rid );
  11617. // 初始化
  11618. $detail ['reviseDetail'] = array ();
  11619. if (! empty ( $value ['reviseDetail'] ))
  11620. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11621. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11622. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11623. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11624. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11625. // 获得费用html
  11626. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11627. // 获得费用审批人数据
  11628. $detail = $this->getReceiptApproverHtml ( $detail );
  11629. // 审批执行
  11630. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11631. <th class="taC" width="90">审批人</th>
  11632. <th class="taC">审批意见</th></tr>';
  11633. foreach ( $detail ['verifyList'] as $key => $value ) {
  11634. $html .= '<tr>
  11635. <td>' . $value [1] . '</td>
  11636. <td>' . $value ['opinion'] . '</td>
  11637. </tr>
  11638. ';
  11639. }
  11640. $html .= ' </tbody></table>';
  11641. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11642. <th class="taC" width="90">执行人</th>
  11643. <th class="taC">执行意见</th></tr>';
  11644. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11645. $html .= '<tr>
  11646. <td>' . $value [1] . '</td>
  11647. <td>' . $value ['opinion'] . '</td>
  11648. </tr>
  11649. ';
  11650. }
  11651. $html .= ' </tbody></table>';
  11652. if($accountType==1){
  11653. Doo::loadModel ( 'loanReceipt' );
  11654. $loanReceipt = new loanReceipt ();
  11655. $loanList = $loanReceipt->getOne ( array (
  11656. 'where' => 'rid=' . $detail ['loanRid'],
  11657. 'desc' => 'rid',
  11658. 'asArray' => true
  11659. ) );
  11660. $html .= '<table class="table table-bordered table-condensed">
  11661. <tr class="warning">
  11662. <td class="taR"><b>汇款金额</b></td>
  11663. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11664. </tr>
  11665. </table>';
  11666. }else{
  11667. $html .= '<table class="table table-bordered table-condensed">
  11668. <tr class="warning">
  11669. <td class="taR"><b>汇款金额</b></td>
  11670. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11671. </tr>
  11672. </table>';
  11673. }
  11674. // print_r($detail['verifyList']);
  11675. // header ( 'Content-Type:text/html;charset=utf-8' );
  11676. // echo $html;
  11677. echo json_encode ( array (
  11678. 'status' => 1,
  11679. 'html' => $html,
  11680. 'detail' => $detail
  11681. ) );
  11682. }
  11683. function getReceiptApproverHtml($detail = array()) {
  11684. Doo::loadModel ( 'loanReceipt' );
  11685. $loanReceipt = new loanReceipt ();
  11686. Doo::loadModel ( 'verify' );
  11687. $verify = new verify ();
  11688. Doo::loadModel ( 'staff' );
  11689. $staff = new staff ();
  11690. if (empty ( $detail ))
  11691. return array ();
  11692. $loanList = $loanReceipt->getOne ( array (
  11693. 'where' => 'rid=' . $detail ['loanRid'],
  11694. 'desc' => 'rid',
  11695. 'asArray' => true
  11696. ) );
  11697. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11698. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11699. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11700. else
  11701. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11702. } else
  11703. $verifyList = $verify->getOne ( array (
  11704. 'where' => 'vid=' . $detail ['verify'],
  11705. 'asArray' => true
  11706. ) );
  11707. $verifyList = json_decode ( $verifyList ['staff'], true );
  11708. Doo::loadModel ( 'role' );
  11709. $role = new role ();
  11710. $roleId = 0;
  11711. $flag = true;
  11712. $roleKey = 0;
  11713. $endStaffArray = array ();
  11714. $roleArrayCopy = array ();
  11715. foreach ( $verifyList as $k => $v ) {
  11716. // init verifyStaff
  11717. if ($v [1] == 'ROLE') {
  11718. if (! empty ( $verifyStaff )) {
  11719. $endStaffArray = end ( $verifyStaff );
  11720. }
  11721. $roleVerify = json_decode ( $v [3], true );
  11722. $roleKey = $k;
  11723. $roleArray = array ();
  11724. $rolename = $role->getOne ( array (
  11725. 'where' => 'rid=' . $v [0],
  11726. 'asArray' => true
  11727. ) );
  11728. foreach ( $roleVerify as $o => $p ) {
  11729. $staffID = explode ( '_', $p );
  11730. $staffInfo = $staff->getOne ( array (
  11731. 'where' => 'sid=' . $staffID [0],
  11732. 'asArray' => true
  11733. ) );
  11734. // print_r($staffID);
  11735. $exp = array (
  11736. 0 => $staffInfo ['sid'],
  11737. 1 => $staffID [1],
  11738. 2 => $staffInfo ['avatar'],
  11739. 'date' => '',
  11740. 'date' => '',
  11741. 'opinion' => '',
  11742. 'status' => '',
  11743. 'rolename' => $rolename ['name']
  11744. );
  11745. array_push ( $roleArray, $exp );
  11746. }
  11747. $roleArrayCopy [$v [0]] = $roleArray;
  11748. // $verifyList[$k]['roleArray']=$roleArray;
  11749. }
  11750. $verifyList [$k] ['date'] = "";
  11751. $verifyList [$k] ['opinion'] = "";
  11752. $verifyList [$k] ['status'] = "";
  11753. if (empty ( $verifyStaff )) {
  11754. $verifyList [$k] ['date'] = "";
  11755. $verifyList [$k] ['opinion'] = "";
  11756. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11757. $verifyList [$k] ['status'] = 4;
  11758. $flag = false;
  11759. }
  11760. } else {
  11761. foreach ( $verifyStaff as $m => $u ) {
  11762. if ($v [0] == $m) {
  11763. $verifyList [$k] ['date'] = $u ['date'];
  11764. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11765. $verifyList [$k] ['status'] = $u ['status'];
  11766. $flag = false;
  11767. break;
  11768. }
  11769. }
  11770. $endStaffArray = end ( $verifyStaff );
  11771. }
  11772. }
  11773. $rolename ['name'] = '';
  11774. if (! empty ( $roleId )) {
  11775. Doo::loadModel ( 'role' );
  11776. $role = new role ();
  11777. $rolename = $role->getOne ( array (
  11778. 'where' => 'rid=' . $roleId,
  11779. 'asArray' => true
  11780. ) );
  11781. }
  11782. if (! empty ( $verifyStaff ))
  11783. $endStaffArray = end ( $verifyStaff );
  11784. $KOP = false;
  11785. foreach ( $roleArrayCopy as $P => $A ) {
  11786. foreach ( $A as $MKI => $AVL ) {
  11787. if (! empty ( $verifyStaff )) {
  11788. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11789. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11790. $button = 4;
  11791. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11792. }
  11793. foreach ( $verifyStaff as $m => $u ) {
  11794. $AVLFK = $AVL [0] . '_R';
  11795. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11796. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11797. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11798. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11799. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11800. break;
  11801. }
  11802. }
  11803. } else {
  11804. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11805. $button = 4;
  11806. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11807. }
  11808. }
  11809. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11810. $KOP = true;
  11811. }
  11812. }
  11813. foreach ( $roleArrayCopy as $k => $v ) {
  11814. foreach ( $verifyList as $m => $n ) {
  11815. if ($n [0] == $k) {
  11816. array_splice ( $verifyList, $m, 1, $v );
  11817. }
  11818. }
  11819. }
  11820. // 费用执行人相关数据
  11821. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11822. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11823. foreach ( $executeCopy as $k => $v ) {
  11824. $executeCopy [$k] ['date'] = '';
  11825. $executeCopy [$k] ['opinion'] = '';
  11826. $executeCopy [$k] ['status'] = '';
  11827. if (! empty ( $executeStaff ))
  11828. foreach ( $executeStaff as $m => $u ) {
  11829. if ($v [0] == $m) {
  11830. $executeCopy [$k] ['date'] = $u ['date'];
  11831. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11832. $executeCopy [$k] ['status'] = $u ['status'];
  11833. break;
  11834. }
  11835. }
  11836. }
  11837. $detail ['executeCopy'] = $executeCopy;
  11838. $detail ['verifyList'] = $verifyList;
  11839. return $detail;
  11840. }
  11841. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11842. if (empty ( $detail ))
  11843. return '';
  11844. $html = '';
  11845. if ($detail ['Rtype'] == 0) { // 报销单
  11846. $html .= '<table class="table table-bordered table-condensed">
  11847. <tbody>
  11848. <tr>
  11849. <th colspan="2" class="taC">日常相关费用</th>
  11850. </tr>';
  11851. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11852. $html .= '
  11853. <tr>
  11854. <th>' . $value ['name'] . '</th>
  11855. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11856. </tr>';
  11857. }
  11858. $html .= '
  11859. <tr>
  11860. <th class="taR">合计</th>
  11861. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11862. </tr>';
  11863. $html .= '<tr>
  11864. <th colspan="2" class="taC">差旅相关费用</th>
  11865. </tr>';
  11866. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11867. $html .= '
  11868. <tr>
  11869. <th>' . $value ['name'] . '</th>
  11870. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11871. </tr>';
  11872. }
  11873. $html .= '
  11874. <tr>
  11875. <th class="taR">合计</th>
  11876. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11877. </tr>';
  11878. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11879. $html .= '<tr>
  11880. <th colspan="2" class="taC">内部培训费用</th>
  11881. </tr>';
  11882. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11883. $html .= '
  11884. <tr>
  11885. <th>' . $value ['name'] . '</th>
  11886. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11887. </tr>';
  11888. }
  11889. $html .= '
  11890. <tr>
  11891. <th class="taR">合计</th>
  11892. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11893. </tr>';
  11894. }
  11895. $html .= '<tr>
  11896. <th colspan="2" class="taC">其他</th>
  11897. </tr>';
  11898. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11899. $html .= '
  11900. <tr>
  11901. <th>' . $value ['name'] . '</th>
  11902. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11903. </tr>';
  11904. }
  11905. $html .= '
  11906. <tr>
  11907. <th class="taR">合计</th>
  11908. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11909. </tr>';
  11910. $html .= '<tr>
  11911. <th colspan="2" class="taC">报销金额调整</th>
  11912. </tr>';
  11913. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11914. $html .= '
  11915. <tr>
  11916. <th>' . $value ['name'] . '</th>
  11917. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11918. </tr>';
  11919. }
  11920. $html .= '
  11921. <tr>
  11922. <th class="taR">合计</th>
  11923. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11924. </tr>';
  11925. $html .= '
  11926. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11927. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11928. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11929. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11930. <tr class="warning">
  11931. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11932. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11933. </tr>
  11934. </tbody>
  11935. </table>';
  11936. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  11937. $html .= '
  11938. <table class="table table-bordered table-condensed">
  11939. <tbody>
  11940. <tr>
  11941. <th colspan="2" class="taC">办事处相关费用</th>
  11942. </tr>';
  11943. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11944. $html .= '
  11945. <tr>
  11946. <th>' . $value ['name'] . '</th>
  11947. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11948. </tr>';
  11949. }
  11950. $html .= '
  11951. <tr>
  11952. <th class="taR">合计</th>
  11953. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11954. </tr>';
  11955. $html .= '
  11956. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11957. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11958. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11959. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11960. <tr class="warning">
  11961. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11962. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11963. </tr>
  11964. </tbody>
  11965. </table>';
  11966. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  11967. Doo::loadModel ( 'loanReceipt' );
  11968. $loanReceipt = new loanReceipt ();
  11969. $loanList = $loanReceipt->getOne ( array (
  11970. 'where' => 'rid=' . $detail ['loanRid'],
  11971. 'desc' => 'rid',
  11972. 'asArray' => true
  11973. ) );
  11974. // print_r($loanList);
  11975. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  11976. $html .= '<table class="table table-bordered table-condensed">
  11977. <tbody>
  11978. <tr>
  11979. <th colspan="2" class="taC">借款费用</th>
  11980. </tr>';
  11981. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  11982. $html .= '<tr>
  11983. <th>' . $value ['name'] . '</th>
  11984. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11985. </tr>';
  11986. }
  11987. $html .= '<tr>
  11988. <th class="taC" colspan="2">产生费用所在办事处</th>
  11989. </tr>
  11990. <tr>
  11991. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  11992. </tr>
  11993. <tr>
  11994. <th class="taC" colspan="2">费用说明</th>
  11995. </tr>
  11996. <tr>
  11997. <td colspan="2">' . $loanList ['explanation'] . '</td>
  11998. </tr>
  11999. <tr class="warning">
  12000. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12001. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12002. </tr>
  12003. </tbody>
  12004. </table>
  12005. ';
  12006. if ( $accountType==2) {
  12007. $balance=$detail ['sum']-$loanList ['sum'];
  12008. $balanceCN=$this->num_to_rmb($balance);
  12009. $html .= '<table class="table table-bordered table-condensed">
  12010. <tbody>
  12011. <tr>
  12012. <th colspan="2" class="taC">日常相关费用</th>
  12013. </tr>';
  12014. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12015. $html .= '
  12016. <tr>
  12017. <th>' . $value ['name'] . '</th>
  12018. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12019. </tr>';
  12020. }
  12021. $html .= '
  12022. <tr>
  12023. <th class="taR">合计</th>
  12024. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12025. </tr>';
  12026. $html .= '<tr>
  12027. <th colspan="2" class="taC">差旅相关费用</th>
  12028. </tr>';
  12029. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12030. $html .= '
  12031. <tr>
  12032. <th>' . $value ['name'] . '</th>
  12033. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12034. </tr>';
  12035. }
  12036. $html .= '
  12037. <tr>
  12038. <th class="taR">合计</th>
  12039. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12040. </tr>';
  12041. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12042. $html .= '<tr>
  12043. <th colspan="2" class="taC">内部培训费用</th>
  12044. </tr>';
  12045. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12046. $html .= '
  12047. <tr>
  12048. <th>' . $value ['name'] . '</th>
  12049. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12050. </tr>';
  12051. }
  12052. $html .= '
  12053. <tr>
  12054. <th class="taR">合计</th>
  12055. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12056. </tr>';
  12057. }
  12058. $html .= '<tr>
  12059. <th colspan="2" class="taC">其他</th>
  12060. </tr>';
  12061. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12062. $html .= '
  12063. <tr>
  12064. <th>' . $value ['name'] . '</th>
  12065. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12066. </tr>';
  12067. }
  12068. $html .= '
  12069. <tr>
  12070. <th class="taR">合计</th>
  12071. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12072. </tr>';
  12073. $html .= '<tr>
  12074. <th colspan="2" class="taC">报销金额调整</th>
  12075. </tr>';
  12076. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12077. $html .= '
  12078. <tr>
  12079. <th>' . $value ['name'] . '</th>
  12080. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12081. </tr>';
  12082. }
  12083. $html .= '
  12084. <tr>
  12085. <th class="taR">合计</th>
  12086. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12087. </tr>';
  12088. $html .= '
  12089. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12090. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12091. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12092. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12093. <tr class="warning">
  12094. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12095. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12096. </tr>
  12097. <tr class="success">
  12098. <td class="taR"><b>借款结余</b></td>
  12099. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12100. </tr>
  12101. </tbody>
  12102. </table>';
  12103. }
  12104. }
  12105. return $html;
  12106. }
  12107. /**
  12108. * 计算流水
  12109. */
  12110. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12111. $bakWaste ['bank'] = array (
  12112. 'CGBDeposit' => 0,
  12113. 'ICBCDeposit' => 0,
  12114. 'HUADeposit' => 0,
  12115. 'PersonalDeposit' => 0
  12116. );
  12117. $bakWaste ['financial'] = array (
  12118. 'current' => array (
  12119. 'CGBDeposit' => 0,
  12120. 'ICBCDeposit' => 0
  12121. ),
  12122. 'fixed' => array (
  12123. 'CGBDeposit' => 0,
  12124. 'ICBCDeposit' => 0
  12125. )
  12126. );
  12127. // 存款
  12128. foreach ( $waste ['bank'] as $key => $value ) {
  12129. // 收入
  12130. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12131. // 广发
  12132. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12133. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12134. }
  12135. // 工商
  12136. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12137. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12138. }
  12139. // 华润
  12140. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12141. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12142. }
  12143. // 个人
  12144. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12145. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12146. }
  12147. }
  12148. }
  12149. foreach ( $waste ['bank'] as $key => $value ) {
  12150. // 支出
  12151. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12152. // 广发
  12153. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12154. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12155. }
  12156. // 工商
  12157. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12158. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12159. }
  12160. // 华润
  12161. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12162. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12163. }
  12164. // 个人
  12165. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12166. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12167. }
  12168. }
  12169. }
  12170. // 活期
  12171. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12172. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12173. // 广发
  12174. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12175. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12176. }
  12177. // 工商
  12178. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12179. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12180. }
  12181. // 个人
  12182. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12183. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12184. }
  12185. }
  12186. }
  12187. // print_r($inComeStatistics ['fixedStatistics']);
  12188. // 固期
  12189. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12190. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12191. // 广发
  12192. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12193. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12194. }
  12195. // 工商
  12196. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12197. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12198. }
  12199. // 个人
  12200. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12201. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12202. }
  12203. }
  12204. }
  12205. return $waste;
  12206. }
  12207. function lyt() {
  12208. Doo::loadModel ( "receiptDetail" );
  12209. $receiptDetail = new receiptDetail ();
  12210. $receiptCollectList = $receiptDetail->find ( array (
  12211. 'where' => 'status=1 ',
  12212. 'asArray' => true
  12213. ) );
  12214. foreach ( $receiptCollectList as $key => $value ) {
  12215. $receiptDetail = new receiptDetail ();
  12216. $receiptDetail->pastDate = $value ['date'];
  12217. $receiptDetail->update ( array (
  12218. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12219. ) );
  12220. }
  12221. }
  12222. function staffCollectMonthDetail() {
  12223. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12224. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12225. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12226. if (! $year)
  12227. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12228. if (! $month)
  12229. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12230. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12231. if (! $nature){
  12232. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12233. }
  12234. Doo::loadModel ( 'staff' );
  12235. $staff = new staff ();
  12236. Doo::loadModel ( "receiptDetail" );
  12237. $receiptDetail = new receiptDetail ();
  12238. Doo::loadModel ( 'accountItem' );
  12239. $accountItem = new accountItem ();
  12240. Doo::loadModel ( 'statistics' );
  12241. $statistics = new statistics ();
  12242. Doo::loadModel ( "receiptAuthorityManage" );
  12243. $receiptAuthorityManage = new receiptAuthorityManage ();
  12244. $aiList=$accountItem->getAccountItem();
  12245. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12246. $cidList = array ();
  12247. foreach ( $imcStaff as $key => $value ) {
  12248. array_push ( $cidList, $value ['cid'] );
  12249. }
  12250. $cidString = implode ( ',', $cidList );
  12251. $naturecon='';
  12252. if ($nature=='ONJOB'){
  12253. $naturecon=' and (nature!=4 )';
  12254. }elseif($nature=='LEAVEJOB'){
  12255. $naturecon=' and (nature=4 )';
  12256. }else{
  12257. die ( 'illegal request--nature' );
  12258. }
  12259. $staffList = $staff->find ( array (
  12260. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12261. 'asArray' => true
  12262. ) );
  12263. $categoryList = $staff->find ( array (
  12264. 'select' => 'COUNT(*) as count,cid,category',
  12265. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12266. 'groupby' => 'cid',
  12267. 'asArray' => true
  12268. ) );
  12269. $list = array ();
  12270. foreach($aiList as $key=>$value){
  12271. foreach ($value as $v){
  12272. $subtotal[$key][$v['name']]=0;
  12273. }
  12274. }
  12275. foreach ( $categoryList as $vlu ) {
  12276. $s1 = 0;
  12277. $m1 = 0;
  12278. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12279. foreach ( $staffList as $value ) {
  12280. if ($vlu ['cid'] == $value ['cid']) {
  12281. // pastDate
  12282. $receiptCollectList = $receiptDetail->find ( array (
  12283. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12284. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12285. 'groupby' => 'item,Month(pastDate),itemCategory',
  12286. 'asArray' => true
  12287. ) );
  12288. if (! empty ( $receiptCollectList )) {
  12289. $receiptL = array (
  12290. '日常相关费用' => array (),
  12291. '差旅相关费用' => array (),
  12292. '内部培训费用' => array (),
  12293. '培训班费用' => array (),
  12294. '其他' => array ()
  12295. );
  12296. $html = "";
  12297. $psum = 0;
  12298. foreach ( $aiList[$this->AGENCY] as $va ) {
  12299. $falg = true;
  12300. foreach ( $receiptCollectList as $v ) {
  12301. if ($v ['itemCategory'] == '日常相关费用') {
  12302. if ($v ['item'] == $va['name']) {
  12303. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12304. $psum += $v ['price'];
  12305. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12306. $falg = false;
  12307. break;
  12308. }
  12309. }
  12310. }
  12311. if ($falg)
  12312. $html .= '<td class="taR">-</td>';
  12313. }
  12314. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12315. if (! empty ( $psum ))
  12316. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12317. else
  12318. $psum = '<td class="colGreen taR">-</td>';
  12319. $receiptL ['日常相关费用'] = $psum . $html;
  12320. /* ----------------------------------- */
  12321. $html = "";
  12322. $psum = 0;
  12323. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12324. $falg = true;
  12325. foreach ( $receiptCollectList as $v ) {
  12326. if ($v ['itemCategory'] == '差旅相关费用') {
  12327. if ($v ['item'] == $va['name']) {
  12328. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12329. $psum += $v ['price'];
  12330. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12331. $falg = false;
  12332. break;
  12333. }
  12334. }
  12335. }
  12336. if ($falg)
  12337. $html .= '<td class="taR">-</td>';
  12338. }
  12339. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12340. if (! empty ( $psum ))
  12341. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12342. else
  12343. $psum = '<td class="colGreen taR">-</td>';
  12344. $receiptL ['差旅相关费用'] = $psum . $html;
  12345. /* ------------------------------------- */
  12346. $html = "";
  12347. $psum = 0;
  12348. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12349. $falg = true;
  12350. foreach ( $receiptCollectList as $v ) {
  12351. if ($v ['itemCategory'] == '内部培训费用') {
  12352. if ($v ['item'] == $va['name']) {
  12353. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12354. $psum += $v ['price'];
  12355. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12356. $falg = false;
  12357. break;
  12358. }
  12359. }
  12360. }
  12361. if ($falg)
  12362. $html .= '<td class="taR">-</td>';
  12363. }
  12364. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12365. if (! empty ( $psum ))
  12366. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12367. else
  12368. $psum = '<td class="colGreen taR">-</td>';
  12369. $receiptL ['内部培训费用'] = $psum . $html;
  12370. /* ----------------------------------- */
  12371. $html = "";
  12372. $psum = 0;
  12373. foreach ( $aiList[$this->TRAIN] as $va ) {
  12374. $falg = true;
  12375. foreach ( $receiptCollectList as $v ) {
  12376. if ($v ['itemCategory'] == '培训班费用') {
  12377. if ($v ['item'] == $va['name']) {
  12378. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12379. $psum += $v ['price'];
  12380. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12381. $falg = false;
  12382. break;
  12383. }
  12384. }
  12385. }
  12386. if ($falg)
  12387. $html .= '<td class="taR">-</td>';
  12388. }
  12389. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12390. if (! empty ( $psum ))
  12391. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12392. else
  12393. $psum = '<td class="colGreen taR">-</td>';
  12394. $receiptL ['培训班费用'] = $psum . $html;
  12395. /* ------------------------------------- */
  12396. $html = "";
  12397. $psum = 0;
  12398. foreach ( $aiList[$this->OTHER] as $va ) {
  12399. $falg = true;
  12400. foreach ( $receiptCollectList as $v ) {
  12401. if ($v ['itemCategory'] == '其他') {
  12402. if (trim ( $v ['item'] ) == $va['name']) {
  12403. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12404. $psum += $v ['price'];
  12405. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12406. $falg = false;
  12407. break;
  12408. }
  12409. }
  12410. }
  12411. if ($falg)
  12412. $html .= '<td class="taR">-</td>';
  12413. }
  12414. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12415. if (! empty ( $psum ))
  12416. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12417. else
  12418. $psum = '<td class="colGreen taR">-</td>';
  12419. $receiptL ['其他'] = $psum . $html;
  12420. /* ------------------------------------- */
  12421. $html = "";
  12422. $psum = 0;
  12423. foreach ( $receiptCollectList as $v ) {
  12424. if ($v ['itemCategory'] == '报销金额调整') {
  12425. if (! empty ( $v ['price'] )) {
  12426. $psum += $v ['price'];
  12427. }
  12428. }
  12429. }
  12430. $s1 += $psum;
  12431. if (! empty ( $psum ))
  12432. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12433. else
  12434. $psum = '<td class="taR colOrange">-</td>';
  12435. $receiptL ['报销金额调整'] = $psum . $html;
  12436. } else {
  12437. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12438. foreach ( $aiList[$this->AGENCY] as $va ) {
  12439. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12440. }
  12441. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12442. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12443. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12444. }
  12445. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12446. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12447. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12448. }
  12449. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12450. foreach ( $aiList[$this->TRAIN] as $va ) {
  12451. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12452. }
  12453. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12454. foreach ( $aiList[$this->OTHER] as $va ) {
  12455. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12456. }
  12457. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12458. }
  12459. $monthStaffPrice = $receiptDetail->find ( array (
  12460. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12461. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12462. 'groupby' => 'Month(pastDate)',
  12463. 'asArray' => true
  12464. ) );
  12465. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12466. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12467. $m1 += $monthStaffPrice [0] ['price'];
  12468. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12469. } else
  12470. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12471. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12472. $list [$value ['username']] = $receiptL;
  12473. }
  12474. }
  12475. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12476. foreach ( $aiList[$this->AGENCY] as $va ) {
  12477. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12478. $subtotal[$this->AGENCY][$va['name']]=0;
  12479. }
  12480. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12481. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12482. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12483. $subtotal[$this->TRAVEL][$va['name']]=0;
  12484. }
  12485. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12486. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12487. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12488. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12489. }
  12490. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12491. foreach ( $aiList[$this->TRAIN] as $va ) {
  12492. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12493. $subtotal[$this->TRAIN][$va['name']]=0;
  12494. }
  12495. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12496. foreach ( $aiList[$this->OTHER] as $va ) {
  12497. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12498. $subtotal[$this->OTHER][$va['name']]=0;
  12499. }
  12500. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12501. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12502. $receiptL ['usernameEn'] =false;
  12503. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12504. }
  12505. $data ['list'] = $list;
  12506. // print_r($list);
  12507. $receiptCollectList = $receiptDetail->find ( array (
  12508. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12509. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12510. 'groupby' => 'item,Month(pastDate),itemCategory',
  12511. 'asArray' => true
  12512. ) );
  12513. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12514. // statistics html
  12515. $stList = $statistics->getOne ( array (
  12516. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12517. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12518. 'groupby' => 'Month(date)',
  12519. 'asArray' => true
  12520. ) );
  12521. if (empty ( $stList ))
  12522. $stList = array (
  12523. 'rePrice' => 0,
  12524. 'agPrice' => 0
  12525. );
  12526. $data ['stList'] = array (
  12527. 'rePrice' => $stList ['rePrice'],
  12528. 'agPrice' => $stList ['agPrice'],
  12529. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12530. );
  12531. $monthHtml = "";
  12532. for($i = 1; $i <= 12; $i ++) {
  12533. if ($i == $month)
  12534. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12535. else
  12536. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12537. }
  12538. $data ['monthHtml'] = $monthHtml;
  12539. $data ['year'] = $year;
  12540. $data ['month'] = $month;
  12541. $data ['nature'] = $nature;
  12542. $data ['aiList'] = $aiList;
  12543. $data ['memu'] = "receipt";
  12544. $data ['staff'] = $this->staff;
  12545. $data ['receiptMemu'] = 'companyCategoryCollect';
  12546. $data ['verifyId'] = $this->verifyId;
  12547. $data ['executeId'] = $this->executeId;
  12548. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12549. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12550. }
  12551. function staffCollectMonthDetail2() {
  12552. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12553. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12554. if (! $year)
  12555. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12556. if (! $month)
  12557. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12558. Doo::loadModel ( 'staff' );
  12559. $staff = new staff ();
  12560. Doo::loadModel ( "receiptDetail" );
  12561. $receiptDetail = new receiptDetail ();
  12562. Doo::loadModel ( 'accountItem' );
  12563. $accountItem = new accountItem ();
  12564. Doo::loadModel ( 'statistics' );
  12565. $statistics = new statistics ();
  12566. Doo::loadModel ( 'L_category' );
  12567. $lCategory = new L_category ();
  12568. $staffList = $staff->find ( array (
  12569. 'where' => 'username!="admin"',
  12570. 'asArray' => true
  12571. ) );
  12572. $categoryList = $staff->find ( array (
  12573. 'select' => 'COUNT(*) as count,cid,category',
  12574. 'where' => 'username !="admin"',
  12575. 'groupby' => 'cid',
  12576. 'asArray' => true
  12577. ) );
  12578. $list = array ();
  12579. foreach ( $categoryList as $vlu ) {
  12580. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12581. $r1 = 0;
  12582. $r2 = 0;
  12583. $r3 = 0;
  12584. $r4 = 0;
  12585. $r5 = 0;
  12586. $r6 = 0;
  12587. $r7 = 0;
  12588. $r8 = 0;
  12589. $r9 = 0;
  12590. $r10 = 0;
  12591. $r11 = 0;
  12592. $r12 = 0;
  12593. $r13 = 0;
  12594. $r14 = 0;
  12595. $r15 = 0;
  12596. $c1 = 0;
  12597. $c2 = 0;
  12598. $c3 = 0;
  12599. $c4 = 0;
  12600. $c5 = 0;
  12601. $c6 = 0;
  12602. $p1 = 0;
  12603. $p2 = 0;
  12604. $p3 = 0;
  12605. $p4 = 0;
  12606. $p5 = 0;
  12607. $p6 = 0;
  12608. $p7 = 0;
  12609. $p8 = 0;
  12610. $p9 = 0;
  12611. $t1 = 0;
  12612. $t2 = 0;
  12613. $t3 = 0;
  12614. $t4 = 0;
  12615. $t5 = 0;
  12616. $s1 = 0;
  12617. $m1 = 0;
  12618. foreach ( $staffList as $value ) {
  12619. if ($vlu ['cid'] == $value ['cid']) {
  12620. $receiptCollectList = $receiptDetail->find ( array (
  12621. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12622. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12623. 'groupby' => 'item,Month(date),itemCategory',
  12624. 'asArray' => true
  12625. ) );
  12626. if (! empty ( $receiptCollectList )) {
  12627. $receiptL = array (
  12628. '日常相关费用' => array (),
  12629. '差旅相关费用' => array (),
  12630. '培训班费用' => array (),
  12631. '其他' => array ()
  12632. );
  12633. $html = "";
  12634. $psum = 0;
  12635. $item = array (
  12636. '市内交通费',
  12637. '市内出租费',
  12638. '办事处房租',
  12639. '电话费',
  12640. '水费',
  12641. '电费',
  12642. '办公费用',
  12643. '邮寄费',
  12644. '其他费用',
  12645. '车辆费用',
  12646. '广告费',
  12647. '团队建设费',
  12648. '物业管理费',
  12649. '宽带费'
  12650. );
  12651. foreach ( $item as $va ) {
  12652. $falg = true;
  12653. foreach ( $receiptCollectList as $v ) {
  12654. if ($v ['itemCategory'] == '日常相关费用') {
  12655. if ($v ['item'] == $va) {
  12656. if ($va == '市内交通费')
  12657. $r1 += $v ['price'];
  12658. if ($va == '市内出租费')
  12659. $r2 += $v ['price'];
  12660. if ($va == '办事处房租')
  12661. $r3 += $v ['price'];
  12662. if ($va == '电话费')
  12663. $r4 += $v ['price'];
  12664. if ($va == '水费')
  12665. $r5 += $v ['price'];
  12666. if ($va == '电费')
  12667. $r6 += $v ['price'];
  12668. if ($va == '办公费用')
  12669. $r7 += $v ['price'];
  12670. if ($va == '邮寄费')
  12671. $r8 += $v ['price'];
  12672. if ($va == '其他费用')
  12673. $r9 += $v ['price'];
  12674. if ($va == '车辆费用')
  12675. $r10 += $v ['price'];
  12676. if ($va == '广告费')
  12677. $r11 += $v ['price'];
  12678. if ($va == '团队建设费')
  12679. $r13 += $v ['price'];
  12680. if ($va == '物业管理费')
  12681. $r14 += $v ['price'];
  12682. if ($va == '宽带费')
  12683. $r15 += $v ['price'];
  12684. $psum += $v ['price'];
  12685. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12686. $falg = false;
  12687. break;
  12688. }
  12689. }
  12690. }
  12691. if ($falg)
  12692. $html .= '<td class="taR">-</td>';
  12693. }
  12694. $r12 += $psum;
  12695. if (! empty ( $psum ))
  12696. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12697. else
  12698. $psum = '<td class="colGreen taR">-</td>';
  12699. $receiptL ['日常相关费用'] = $psum . $html;
  12700. /* ----------------------------------- */
  12701. $html = "";
  12702. $psum = 0;
  12703. $item = array (
  12704. '往来交通费',
  12705. '市内交通费',
  12706. '出差住宿费',
  12707. '出差补助',
  12708. '其他费用'
  12709. );
  12710. foreach ( $item as $va ) {
  12711. $falg = true;
  12712. foreach ( $receiptCollectList as $v ) {
  12713. if ($v ['itemCategory'] == '差旅相关费用') {
  12714. if ($v ['item'] == $va) {
  12715. if ($va == '往来交通费')
  12716. $c1 += $v ['price'];
  12717. if ($va == '市内交通费')
  12718. $c2 += $v ['price'];
  12719. if ($va == '出差住宿费')
  12720. $c3 += $v ['price'];
  12721. if ($va == '出差补助')
  12722. $c4 += $v ['price'];
  12723. if ($va == '其他费用')
  12724. $c5 += $v ['price'];
  12725. $psum += $v ['price'];
  12726. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12727. $falg = false;
  12728. break;
  12729. }
  12730. }
  12731. }
  12732. if ($falg)
  12733. $html .= '<td class="taR">-</td>';
  12734. }
  12735. $c6 += $psum;
  12736. if (! empty ( $psum ))
  12737. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12738. else
  12739. $psum = '<td class="colGreen taR">-</td>';
  12740. $receiptL ['差旅相关费用'] = $psum . $html;
  12741. /* ------------------------------------- */
  12742. $html = "";
  12743. $psum = 0;
  12744. $item = array (
  12745. '场租费',
  12746. '薪酬',
  12747. '住宿费',
  12748. '交通费',
  12749. '餐饮费',
  12750. '办公费',
  12751. '公关费',
  12752. '其他'
  12753. );
  12754. foreach ( $item as $va ) {
  12755. $falg = true;
  12756. foreach ( $receiptCollectList as $v ) {
  12757. if ($v ['itemCategory'] == '培训班费用') {
  12758. if ($v ['item'] == $va) {
  12759. if ($va == '场租费')
  12760. $p1 += $v ['price'];
  12761. if ($va == '薪酬')
  12762. $p2 += $v ['price'];
  12763. if ($va == '住宿费')
  12764. $p3 += $v ['price'];
  12765. if ($va == '交通费')
  12766. $p4 += $v ['price'];
  12767. if ($va == '餐饮费')
  12768. $p5 += $v ['price'];
  12769. if ($va == '办公费')
  12770. $p6 += $v ['price'];
  12771. if ($va == '公关费')
  12772. $p7 += $v ['price'];
  12773. if ($va == '其他')
  12774. $p8 += $v ['price'];
  12775. $psum += $v ['price'];
  12776. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12777. $falg = false;
  12778. break;
  12779. }
  12780. }
  12781. }
  12782. if ($falg)
  12783. $html .= '<td class="taR">-</td>';
  12784. }
  12785. $p9 += $psum;
  12786. if (! empty ( $psum ))
  12787. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12788. else
  12789. $psum = '<td class="colGreen taR">-</td>';
  12790. $receiptL ['培训班费用'] = $psum . $html;
  12791. /* ------------------------------------- */
  12792. $html = "";
  12793. $psum = 0;
  12794. $item = array (
  12795. '公关费',
  12796. '广告费',
  12797. '借款',
  12798. '可自加费用'
  12799. );
  12800. foreach ( $item as $va ) {
  12801. $falg = true;
  12802. foreach ( $receiptCollectList as $v ) {
  12803. if ($v ['itemCategory'] == '其他') {
  12804. if ($v ['item'] == $va) {
  12805. if ($va == '公关费')
  12806. $t1 += $v ['price'];
  12807. if ($va == '广告费')
  12808. $t2 += $v ['price'];
  12809. if ($va == '借款')
  12810. $t3 += $v ['price'];
  12811. if ($va == '可自加费用')
  12812. $t4 += $v ['price'];
  12813. $psum += $v ['price'];
  12814. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12815. $falg = false;
  12816. break;
  12817. }
  12818. }
  12819. }
  12820. if ($falg)
  12821. $html .= '<td class="taR">-</td>';
  12822. }
  12823. $t5 += $psum;
  12824. if (! empty ( $psum ))
  12825. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12826. else
  12827. $psum = '<td class="colGreen taR">-</td>';
  12828. $receiptL ['其他'] = $psum . $html;
  12829. /* ------------------------------------- */
  12830. $html = "";
  12831. $psum = 0;
  12832. foreach ( $receiptCollectList as $v ) {
  12833. if ($v ['itemCategory'] == '报销金额调整') {
  12834. if (! empty ( $v ['price'] )) {
  12835. $psum += $v ['price'];
  12836. }
  12837. }
  12838. }
  12839. $s1 += $psum;
  12840. if (! empty ( $psum ))
  12841. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12842. else
  12843. $psum = '<td class="taR colOrange">-</td>';
  12844. $receiptL ['报销金额调整'] = $psum . $html;
  12845. } else {
  12846. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12847. <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>';
  12848. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12849. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12850. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12851. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12852. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12853. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12854. }
  12855. $monthStaffPrice = $receiptDetail->find ( array (
  12856. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12857. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12858. 'asArray' => true
  12859. ) );
  12860. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12861. $m1 += $monthStaffPrice [0] ['price'];
  12862. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12863. } else
  12864. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12865. $list [$value ['username']] = $receiptL;
  12866. }
  12867. }
  12868. $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>
  12869. <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>
  12870. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12871. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12872. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12873. $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>
  12874. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12875. $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>';
  12876. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12877. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12878. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12879. }
  12880. $data ['list'] = $list;
  12881. $receiptCollectList = $receiptDetail->find ( array (
  12882. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12883. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12884. 'groupby' => 'item,Month(date),itemCategory',
  12885. 'asArray' => true
  12886. ) );
  12887. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12888. // statistics html
  12889. $stList = $statistics->getOne ( array (
  12890. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12891. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12892. 'groupby' => 'Month(date)',
  12893. 'asArray' => true
  12894. ) );
  12895. if (empty ( $stList ))
  12896. $stList = array (
  12897. 'rePrice' => 0,
  12898. 'agPrice' => 0
  12899. );
  12900. $data ['stList'] = array (
  12901. 'rePrice' => $stList ['rePrice'],
  12902. 'agPrice' => $stList ['agPrice'],
  12903. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12904. );
  12905. $monthHtml = "";
  12906. for($i = 1; $i <= 12; $i ++) {
  12907. if ($i == $month)
  12908. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12909. else
  12910. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12911. }
  12912. $data ['monthHtml'] = $monthHtml;
  12913. $data ['year'] = $year;
  12914. $data ['month'] = $month;
  12915. $data ['memu'] = "receipt";
  12916. $data ['staff'] = $this->staff;
  12917. $data ['receiptMemu'] = 'companyCategoryCollect';
  12918. $data ['verifyId'] = $this->verifyId;
  12919. $data ['executeId'] = $this->executeId;
  12920. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12921. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12922. }
  12923. /**
  12924. * 用户报销单列表
  12925. */
  12926. function receiptStatisticsStaffDetail() {
  12927. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12928. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12929. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  12930. Doo::loadModel ( "receipt" );
  12931. $receipt = new receipt ();
  12932. Doo::loadModel ( "receiptDetail" );
  12933. $receiptDetail = new receiptDetail ();
  12934. Doo::loadModel ( 'staff' );
  12935. $staff = new staff ();
  12936. Doo::loadModel ( 'accountItem' );
  12937. $accountItem = new accountItem ();
  12938. Doo::loadModel ( 'statistics' );
  12939. $statistics = new statistics ();
  12940. if (! empty ( $username )) {
  12941. $username = addslashes ( urldecode ( $username ) );
  12942. $staffDetail = $staff->getStaffByName ( $username );
  12943. if (empty ( $staffDetail ))
  12944. die ( 'illegal request' );
  12945. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  12946. $itemList = $accountItem->getAccountItem ();
  12947. $itemHtml = '';
  12948. $categoryHtml = '';
  12949. $itemKeyList = array_keys ( $itemList );
  12950. $revisePrice = 0;
  12951. // 报销单内容详情
  12952. foreach ( $list as $key => $value ) {
  12953. $accountItemList = json_decode ( $value ['accountItem'], true );
  12954. $list [$key] ['accountItemList'] = $accountItemList;
  12955. $receiptItemHtml = '';
  12956. foreach ( $itemKeyList as $v ) {
  12957. if ($v == '日常相关费用')
  12958. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  12959. elseif ($v == '差旅相关费用')
  12960. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  12961. elseif ($v == '培训班费用')
  12962. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  12963. elseif ($v == '内部培训费用'){
  12964. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  12965. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  12966. }else{
  12967. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  12968. }
  12969. }elseif ($v == '其他')
  12970. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  12971. foreach ( $itemList [$v] as $ke => $va ) {
  12972. $falg = true;
  12973. if (! empty ( $accountItemList [$v] )) {
  12974. foreach ( $accountItemList [$v] as $ve ) {
  12975. if ($va ['name'] == $ve ['name']) {
  12976. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  12977. $falg = false;
  12978. break;
  12979. }
  12980. }
  12981. }
  12982. if ($falg)
  12983. $receiptItemHtml .= '<td class="taR"></td>';
  12984. }
  12985. }
  12986. // 金额调整和费用查看
  12987. $revisePrice += $value ['revisePrice'];
  12988. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  12989. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  12990. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  12991. }
  12992. // 报销单合计
  12993. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  12994. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  12995. $receiptTotalHtml = '';
  12996. // 报销单项目抬头
  12997. foreach ( $itemKeyList as $value ) {
  12998. $count = count ( $itemList [$value] ) + 1;
  12999. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13000. $categoryHtml .= '<th class="taC">合计</th>';
  13001. $sumfalg=true;
  13002. foreach ( $rtl as $rtlValue ) {
  13003. if ($rtlValue ['itemCategory'] == $value) {
  13004. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13005. $sumfalg=false;
  13006. break;
  13007. }
  13008. }
  13009. if ($sumfalg)
  13010. $receiptTotalHtml .= '<th></th>';
  13011. foreach ( $itemList [$value] as $k => $v ) {
  13012. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13013. // 合计
  13014. $falg = true;
  13015. foreach ( $receiptTotalList as $ve ) {
  13016. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13017. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13018. $falg = false;
  13019. break;
  13020. }
  13021. }
  13022. if ($falg)
  13023. $receiptTotalHtml .= '<th></th>';
  13024. }
  13025. }
  13026. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13027. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13028. if (empty ( $stList ))
  13029. $stList = array (
  13030. 'rePrice' => 0,
  13031. 'agPrice' => 0
  13032. );
  13033. $data ['stList'] = array (
  13034. 'rePrice' => $stList ['rePrice'],
  13035. 'agPrice' => $stList ['agPrice'],
  13036. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13037. );
  13038. $monthHtml = "";
  13039. for($i = 1; $i <= 12; $i ++) {
  13040. if ($i == $month)
  13041. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13042. else
  13043. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13044. }
  13045. $data ['username'] = urlencode ( $username );
  13046. $data ['usernameEN'] = $username;
  13047. $data ['monthHtml'] = $monthHtml;
  13048. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13049. $data ['list'] = $list;
  13050. $data ['categoryHtml'] = $categoryHtml;
  13051. $data ['itemHtml'] = $itemHtml;
  13052. $data ['itemList'] = $itemList;
  13053. $data ['year'] = $year;
  13054. $data ['month'] = $month;
  13055. $data ['memu'] = "receipt";
  13056. $data ['staff'] = $this->staff;
  13057. $data ['receiptMemu'] = 'companyCategoryCollect';
  13058. $data ['verifyId'] = $this->verifyId;
  13059. $data ['executeId'] = $this->executeId;
  13060. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13061. }
  13062. die ( 'illegal request' );
  13063. }
  13064. function companyMonthCollectDetail() {
  13065. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13066. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13067. if (! $year)
  13068. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13069. if (! $month)
  13070. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13071. Doo::loadModel ( 'staff' );
  13072. $staff = new staff ();
  13073. Doo::loadModel ( "receiptDetail" );
  13074. $receiptDetail = new receiptDetail ();
  13075. Doo::loadModel ( 'accountItem' );
  13076. $accountItem = new accountItem ();
  13077. Doo::loadModel ( 'statistics' );
  13078. $statistics = new statistics ();
  13079. Doo::loadModel ( 'L_category' );
  13080. $lCategory = new L_category ();
  13081. $staffList = $staff->find ( array (
  13082. 'where' => 'username!="admin"',
  13083. 'asArray' => true
  13084. ) );
  13085. $categoryList = $lCategory->find ( array (
  13086. 'asArray' => true
  13087. ) );
  13088. $aiList=$accountItem->getAccountItem();
  13089. $list = array ();
  13090. foreach ( $categoryList as $value ) {
  13091. $receiptCollectList = $receiptDetail->find ( array (
  13092. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13093. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13094. 'groupby' => 'item,Month(pastDate),itemCategory',
  13095. 'asArray' => true
  13096. ) );
  13097. if (! empty ( $receiptCollectList )) {
  13098. $receiptL = array (
  13099. '日常相关费用' => array (),
  13100. '差旅相关费用' => array (),
  13101. '内部培训费用' => array (),
  13102. '培训班费用' => array (),
  13103. '其他' => array ()
  13104. );
  13105. $html = "";
  13106. $psum = 0;
  13107. foreach ( $aiList[$this->AGENCY] as $va ) {
  13108. $falg = true;
  13109. foreach ( $receiptCollectList as $v ) {
  13110. if ($v ['itemCategory'] == $this->AGENCY) {
  13111. if ($v ['item'] == $va['name']) {
  13112. $psum += $v ['price'];
  13113. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13114. $falg = false;
  13115. break;
  13116. }
  13117. }
  13118. }
  13119. if ($falg)
  13120. $html .= '<td class="taR">-</td>';
  13121. }
  13122. if (! empty ( $psum ))
  13123. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13124. else
  13125. $psum = '<td class="colGreen taR">-</td>';
  13126. $receiptL [$this->AGENCY] = $psum . $html;
  13127. /* ----------------------------------- */
  13128. $html = "";
  13129. $psum = 0;
  13130. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13131. $falg = true;
  13132. foreach ( $receiptCollectList as $v ) {
  13133. if ($v ['itemCategory'] == $this->TRAVEL) {
  13134. if ($v ['item'] == $va['name']) {
  13135. $psum += $v ['price'];
  13136. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13137. $falg = false;
  13138. break;
  13139. }
  13140. }
  13141. }
  13142. if ($falg)
  13143. $html .= '<td class="taR">-</td>';
  13144. }
  13145. if (! empty ( $psum ))
  13146. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13147. else
  13148. $psum = '<td class="colGreen taR">-</td>';
  13149. $receiptL [$this->TRAVEL] = $psum . $html;
  13150. /* ------------------------------------- */
  13151. $html = "";
  13152. $psum = 0;
  13153. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13154. $falg = true;
  13155. foreach ( $receiptCollectList as $v ) {
  13156. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13157. if ($v ['item'] == $va['name']) {
  13158. $psum += $v ['price'];
  13159. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13160. $falg = false;
  13161. break;
  13162. }
  13163. }
  13164. }
  13165. if ($falg)
  13166. $html .= '<td class="taR">-</td>';
  13167. }
  13168. if (! empty ( $psum ))
  13169. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13170. else
  13171. $psum = '<td class="colGreen taR">-</td>';
  13172. $receiptL [$this->INTTRAIN] = $psum . $html;
  13173. /* ------------------------------------- */
  13174. $html = "";
  13175. $psum = 0;
  13176. foreach ( $aiList[$this->TRAIN] as $va ) {
  13177. $falg = true;
  13178. foreach ( $receiptCollectList as $v ) {
  13179. if ($v ['itemCategory'] == $this->TRAIN) {
  13180. if ($v ['item'] == $va['name']) {
  13181. $psum += $v ['price'];
  13182. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13183. $falg = false;
  13184. break;
  13185. }
  13186. }
  13187. }
  13188. if ($falg)
  13189. $html .= '<td class="taR">-</td>';
  13190. }
  13191. if (! empty ( $psum ))
  13192. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13193. else
  13194. $psum = '<td class="colGreen taR">-</td>';
  13195. $receiptL [$this->TRAIN] = $psum . $html;
  13196. /* ------------------------------------- */
  13197. $html = "";
  13198. $psum = 0;
  13199. foreach ( $aiList[$this->OTHER] as $va ) {
  13200. $falg = true;
  13201. foreach ( $receiptCollectList as $v ) {
  13202. if ($v ['itemCategory'] == $this->OTHER) {
  13203. if ($v ['item'] == $va['name']) {
  13204. $psum += $v ['price'];
  13205. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13206. $falg = false;
  13207. break;
  13208. }
  13209. }
  13210. }
  13211. if ($falg)
  13212. $html .= '<td class="taR">-</td>';
  13213. }
  13214. if (! empty ( $psum ))
  13215. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13216. else
  13217. $psum = '<td class="colGreen taR">-</td>';
  13218. $receiptL [$this->OTHER] = $psum . $html;
  13219. /* ------------------------------------- */
  13220. $html = "";
  13221. $psum = 0;
  13222. foreach ( $receiptCollectList as $v ) {
  13223. if ($v ['itemCategory'] == '报销金额调整') {
  13224. if (! empty ( $v ['price'] ))
  13225. $psum += $v ['price'];
  13226. }
  13227. }
  13228. if (! empty ( $psum ))
  13229. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13230. else
  13231. $psum = '<td class="taR colOrange">-</td>';
  13232. $receiptL ['报销金额调整'] = $psum . $html;
  13233. } else {
  13234. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13235. foreach ( $aiList[$this->AGENCY] as $va ) {
  13236. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13237. }
  13238. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13239. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13240. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13241. }
  13242. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13243. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13244. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13245. }
  13246. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13247. foreach ( $aiList[$this->TRAIN] as $va ) {
  13248. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13249. }
  13250. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13251. foreach ( $aiList[$this->OTHER] as $va ) {
  13252. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13253. }
  13254. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13255. }
  13256. $monthStaffPrice = $receiptDetail->find ( array (
  13257. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13258. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13259. 'asArray' => true
  13260. ) );
  13261. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13262. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13263. else
  13264. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13265. $list [$value ['title']] = $receiptL;
  13266. }
  13267. $data ['list'] = $list;
  13268. $receiptCollectList = $receiptDetail->find ( array (
  13269. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13270. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13271. 'groupby' => 'item,Month(pastDate),itemCategory',
  13272. 'asArray' => true
  13273. ) );
  13274. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13275. //print_r($data['monthPriceHtml']);
  13276. // foreach ($data['monthPriceHtml'] as $value){
  13277. // echo $value;
  13278. // }
  13279. // die;
  13280. // statistics html
  13281. $stList = $statistics->getOne ( array (
  13282. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13283. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13284. 'groupby' => 'Month(date)',
  13285. 'asArray' => true
  13286. ) );
  13287. if (empty ( $stList ))
  13288. $stList = array (
  13289. 'rePrice' => 0,
  13290. 'agPrice' => 0
  13291. );
  13292. $data ['stList'] = array (
  13293. 'rePrice' => $stList ['rePrice'],
  13294. 'agPrice' => $stList ['agPrice'],
  13295. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13296. );
  13297. $monthHtml = "";
  13298. for($i = 1; $i <= 12; $i ++) {
  13299. if ($i == $month)
  13300. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13301. else
  13302. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13303. }
  13304. $data ['aiList'] = $aiList;
  13305. $data ['monthHtml'] = $monthHtml;
  13306. $data ['year'] = $year;
  13307. $data ['month'] = $month;
  13308. $data ['memu'] = "receipt";
  13309. $data ['staff'] = $this->staff;
  13310. $data ['receiptMemu'] = 'companyCategoryCollect';
  13311. $data ['verifyId'] = $this->verifyId;
  13312. $data ['executeId'] = $this->executeId;
  13313. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13314. }
  13315. function staffCollectDetail() {
  13316. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13317. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13318. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13319. if (! $staffname) {
  13320. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13321. $staffname = urldecode ( $staffname );
  13322. }
  13323. Doo::loadModel ( 'staff' );
  13324. $staff = new staff ();
  13325. Doo::loadModel ( "receiptDetail" );
  13326. $receiptDetail = new receiptDetail ();
  13327. Doo::loadModel ( 'accountItem' );
  13328. $accountItem = new accountItem ();
  13329. Doo::loadModel ( 'statistics' );
  13330. $statistics = new statistics ();
  13331. Doo::loadModel ( 'L_category' );
  13332. $lCategory = new L_category ();
  13333. Doo::loadModel ( "receiptAuthorityManage" );
  13334. $receiptAuthorityManage = new receiptAuthorityManage ();
  13335. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13336. $cidList = array ();
  13337. foreach ( $imcStaff as $key => $value ) {
  13338. array_push ( $cidList, $value ['cid'] );
  13339. }
  13340. $cidString = implode ( ',', $cidList );
  13341. $staffList = $staff->find ( array (
  13342. 'where' => ' cid in (' . $cidString . ')',
  13343. 'asArray' => true
  13344. ) );
  13345. $stHtml = '';
  13346. $stTitle = "";
  13347. $staffId = 0;
  13348. $cid = 0;
  13349. $ocid = 0;
  13350. foreach ( $staffList as $value ) {
  13351. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13352. $stTitle = $value ['category'] . '-' . $value ['username'];
  13353. $staffId = $value ['sid'];
  13354. $cid = $value ['cid'];
  13355. $ocid = $value ['cid'];
  13356. if (! empty ( $value ['othercid'] ))
  13357. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13358. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13359. } elseif ($value ['username'] != 'admin')
  13360. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13361. }
  13362. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13363. 'where' => 'cid in(' . $cid . ')',
  13364. 'asArray' => true
  13365. ) );
  13366. if (empty ( $pcid ))
  13367. $pcid = $ocid;
  13368. $data ['ocid'] = $pcid;
  13369. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13370. $this->showCache ( $path );
  13371. //
  13372. $receiptCollectList = $receiptDetail->find ( array (
  13373. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13374. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13375. 'groupby' => 'item,Month(pastDate),itemCategory',
  13376. 'asArray' => true
  13377. ) );
  13378. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13379. // print_r($receiptCollectList);
  13380. $accountList = $accountItem->find ( array (
  13381. 'asArray' => true
  13382. ) );
  13383. // create CollectDetail HTML
  13384. $collectHtml = array ();
  13385. foreach ( $accountList as $key => $value ) {
  13386. $html = "";
  13387. $asum = 0;
  13388. for($i = 1; $i <= 12; $i ++) {
  13389. $falg = true;
  13390. foreach ( $receiptCollectList as $v ) {
  13391. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13392. if ($v ['item'] == '可自加费用') {
  13393. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13394. }
  13395. $asum += $v ['price'];
  13396. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13397. $falg = false;
  13398. break;
  13399. }
  13400. }
  13401. if ($falg)
  13402. $html .= '<td class="taR">-</td>';
  13403. }
  13404. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13405. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13406. }
  13407. $data ['collectHtml'] = $collectHtml;
  13408. // print_r($collectHtml);
  13409. // create Adjustment price html
  13410. $receiptCollectList = $receiptDetail->find ( array (
  13411. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13412. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13413. 'groupby' => 'itemCategory,Month(pastDate)',
  13414. 'asArray' => true
  13415. ) );
  13416. $adjustment = array ();
  13417. $collectArray = array (
  13418. '日常相关费用' => array (),
  13419. '差旅相关费用' => array (),
  13420. '培训班费用' => array (),
  13421. '内部培训费用'=>array(),
  13422. '其他' => array ()
  13423. );
  13424. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13425. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13426. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13427. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13428. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13429. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13430. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13431. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13432. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13433. array_push ( $collectArray ['其他'], $collectHtml );
  13434. $data ['collectArray'] = $collectArray;
  13435. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13436. array_push ( $adjustment, $collectHtml );
  13437. $data ['adjustment'] = $adjustment;
  13438. // total price html
  13439. $collectHtml = "";
  13440. $total = 0;
  13441. for($i = 1; $i <= 12; $i ++) {
  13442. $sumPrice = 0;
  13443. foreach ( $receiptCollectList as $key => $value ) {
  13444. if ($value ['month'] == $i) {
  13445. $sumPrice += $value ['price'];
  13446. }
  13447. }
  13448. if ($sumPrice == 0)
  13449. $collectHtml .= '<td class="taR">-</td>';
  13450. else
  13451. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13452. $total += $sumPrice;
  13453. }
  13454. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13455. // statistics html
  13456. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13457. if (empty ( $stList ))
  13458. $stList = array (
  13459. 'rePrice' => 0,
  13460. 'agPrice' => 0
  13461. );
  13462. $data ['stList'] = array (
  13463. 'rePrice' => $stList ['rePrice'],
  13464. 'agPrice' => $stList ['agPrice'],
  13465. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13466. );
  13467. $data ['totalPrice'] = $collectHtml;
  13468. $data ['totalYear'] = $total;
  13469. $data ['stHtml'] = $stHtml;
  13470. $data ['year'] = $year;
  13471. $data ['stTitle'] = $stTitle;
  13472. $data ['staffname'] = urlencode ( $staffname );
  13473. $data ['memu'] = "receipt";
  13474. $data ['staff'] = $this->staff;
  13475. $data ['receiptMemu'] = 'companyCategoryCollect';
  13476. $data ['verifyId'] = $this->verifyId;
  13477. $data ['executeId'] = $this->executeId;
  13478. if ($year < date ( "Y" )) {
  13479. Doo::loadModel ( 'receipt' );
  13480. $receipt = new receipt ();
  13481. $receiptList = $receipt->find ( array (
  13482. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13483. 'asArray' => true
  13484. ) );
  13485. if (empty ( $receiptList )) { // generated files
  13486. ob_start ();
  13487. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13488. $this->cacheFile ( $path );
  13489. die ();
  13490. }
  13491. }
  13492. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13493. }
  13494. function BUGFLAG() {
  13495. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13496. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13497. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13498. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13499. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13500. if (empty ( $status ))
  13501. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13502. $page_size = 12;
  13503. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13504. $vidList = array ();
  13505. $button = 0;
  13506. Doo::loadModel ( 'verify' );
  13507. $verify = new verify ();
  13508. Doo::loadModel ( 'receipt' );
  13509. $receipt = new receipt ();
  13510. Doo::loadModel ( 'staff' );
  13511. $staff = new staff ();
  13512. Doo::loadModel ( 'L_category' );
  13513. $Lcategory = new L_category ();
  13514. $dateCondition = " and Year(date) =" . $year;
  13515. if (! empty ( $month ))
  13516. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13517. $categoryList = $Lcategory->find ( array (
  13518. 'asArray' => true
  13519. ) );
  13520. $staffList = $staff->find ( array (
  13521. 'where' => 'cid=' . $cid,
  13522. 'asArray' => true
  13523. ) );
  13524. $cateCondition = "";
  13525. $staffCondition = "";
  13526. $approvalCondition = "";
  13527. if (! empty ( $cid ))
  13528. $cateCondition = ' and cid=' . $cid;
  13529. if (! empty ( $sid )) {
  13530. $staffCondition = ' and staff=' . $sid;
  13531. $cateCondition = "";
  13532. }
  13533. $approvalCondition = " and status=" . $status;
  13534. if ($status == 2) {
  13535. // 查找角色审批人
  13536. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13537. }
  13538. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13539. $approvalCondition = ' and status=2 ';
  13540. }
  13541. if ($status == 1) {
  13542. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13543. }
  13544. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13545. $pageinfo ['page'] = array (
  13546. 'previous' => ''
  13547. );
  13548. if ($status == 0) {
  13549. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13550. $receiptList = $receipt->find ( array (
  13551. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13552. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13553. 'desc' => 'rid',
  13554. 'asArray' => true
  13555. ) );
  13556. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13557. } else
  13558. $receiptList = $receipt->find ( array (
  13559. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13560. 'desc' => 'rid',
  13561. 'asArray' => true
  13562. ) );
  13563. $rLRes = $receipt->find ( array (
  13564. '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,
  13565. 'desc' => 'rid',
  13566. 'asArray' => true
  13567. ) );
  13568. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13569. // print_r($pageinfo);
  13570. $Locate = 0;
  13571. foreach ( $receiptList as $key => $value ) {
  13572. $receiptList [$key] ['Locate'] = $Locate;
  13573. $Locate ++;
  13574. $receiptList [$key] ['reviseDetail'] = array ();
  13575. if (! empty ( $value ['reviseDetail'] ))
  13576. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13577. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13578. $categoryDetil = $Lcategory->getOne ( array (
  13579. 'where' => 'cid=' . $value ['cid'],
  13580. 'asArray' => true
  13581. ) );
  13582. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13583. $verifyList = $verify->getOne ( array (
  13584. 'where' => 'vid=' . $value ['verify'],
  13585. 'asArray' => true
  13586. ) );
  13587. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13588. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13589. foreach ( $verifyList as $k => $v ) {
  13590. // init verifyStaff
  13591. $verifyList [$k] ['date'] = "";
  13592. $verifyList [$k] ['opinion'] = "";
  13593. $verifyList [$k] ['status'] = "";
  13594. if (empty ( $verifyStaff )) {
  13595. $verifyList [$k] ['date'] = "";
  13596. $verifyList [$k] ['opinion'] = "";
  13597. if ($v [0] == $this->staff [0] ['sid']) {
  13598. $verifyList [$k] ['status'] = 4;
  13599. $button = 4;
  13600. }
  13601. } else {
  13602. $flag = true;
  13603. foreach ( $verifyStaff as $m => $u ) {
  13604. if ($v [0] == $m) {
  13605. $verifyList [$k] ['date'] = $u ['date'];
  13606. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13607. $verifyList [$k] ['status'] = $u ['status'];
  13608. $flag = false;
  13609. break;
  13610. }
  13611. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13612. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13613. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13614. }
  13615. if ($flag) { // 检测可编辑
  13616. if ($v [0] == $this->staff [0] ['sid']) {
  13617. $verifyList [$k] ['status'] = 4;
  13618. $button = 4;
  13619. }
  13620. }
  13621. }
  13622. }
  13623. $receiptList [$key] ['verifyList'] = $verifyList;
  13624. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13625. 'where' => 'sid=' . $value ['staff'],
  13626. 'asArray' => true
  13627. ) );
  13628. $receiptList [$key] ['button'] = $button;
  13629. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13630. }
  13631. // print_r($receiptList);die;
  13632. // $data['verifyDetail']=$verifyDetail;
  13633. $mothHtml = "";
  13634. for($i = 1; $i <= 12; $i ++) {
  13635. if ($month == $i)
  13636. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13637. else
  13638. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13639. }
  13640. $data ['mothHtml'] = $mothHtml;
  13641. $data ['page'] = $pageinfo;
  13642. $data ['receiptList'] = $receiptList;
  13643. $data ['receiptApprovalCount'] = count ( $rLRes );
  13644. $data ['status'] = $status;
  13645. $data ['year'] = $year;
  13646. $data ['categoryList'] = $categoryList;
  13647. $data ['staffList'] = $staffList;
  13648. $data ['cid'] = $cid;
  13649. $data ['sid'] = $sid;
  13650. // print_r($receiptList);
  13651. $data ['memu'] = "receipt";
  13652. $data ['staff'] = $this->staff;
  13653. $data ['receiptMemu'] = 'approvalExpenses';
  13654. $data ['verifyId'] = $this->verifyId;
  13655. $data ['executeId'] = $this->executeId;
  13656. $this->render ( "/admin/FALG", $data );
  13657. }
  13658. function ajaxGetReceiptOrder() {
  13659. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13660. if (! empty ( $receiptOrder )) {
  13661. Doo::loadModel ( 'receipt' );
  13662. $receipt = new receipt ();
  13663. Doo::loadModel ( 'staff' );
  13664. $staff = new staff ();
  13665. $receiptInfo = $receipt->getOne ( array (
  13666. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13667. 'asArray' => true
  13668. ) );
  13669. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13670. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13671. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13672. </tbody></table><table class="table table table-bordered"><tbody>';
  13673. foreach ( $verifyStaff as $key => $value ) {
  13674. $staffInfo = $staff->getOne ( array (
  13675. 'select' => 'username',
  13676. 'where' => ' sid="' . $key . '"',
  13677. 'asArray' => true
  13678. ) );
  13679. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13680. }
  13681. $html .= '</tbody></table></div></div>';
  13682. echo json_encode ( array (
  13683. 'status' => 1,
  13684. 'receiptHtml' => $html
  13685. ) );
  13686. die ();
  13687. }
  13688. echo json_encode ( array (
  13689. 'status' => 2,
  13690. 'receiptHtml' => ''
  13691. ) );
  13692. die ();
  13693. }
  13694. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13695. if (! empty ( $receiptCollectList )) {
  13696. $receiptL = array (
  13697. '日常相关费用' => array (),
  13698. '差旅相关费用' => array (),
  13699. '内部培训费用'=>array(),
  13700. '培训班费用' => array (),
  13701. '其他' => array ()
  13702. );
  13703. $html = "";
  13704. $psum = 0;
  13705. foreach ( $aiList[$this->AGENCY] as $value ) {
  13706. $falg = true;
  13707. foreach ( $receiptCollectList as $v ) {
  13708. if ($v ['itemCategory'] == '日常相关费用') {
  13709. if ($v ['item'] == $value['name']) {
  13710. $psum += $v ['price'];
  13711. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13712. $falg = false;
  13713. break;
  13714. }
  13715. }
  13716. }
  13717. if ($falg)
  13718. $html .= '<td class="taR">-</td>';
  13719. }
  13720. if (! empty ( $psum ))
  13721. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13722. else
  13723. $psum = '<td class="colGreen taR">-</td>';
  13724. $receiptL ['日常相关费用'] = $psum . $html;
  13725. /* ----------------------------------- */
  13726. $html = "";
  13727. $psum = 0;
  13728. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13729. $falg = true;
  13730. foreach ( $receiptCollectList as $v ) {
  13731. if ($v ['itemCategory'] == '差旅相关费用') {
  13732. if ($v ['item'] == $value['name']) {
  13733. $psum += $v ['price'];
  13734. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13735. $falg = false;
  13736. break;
  13737. }
  13738. }
  13739. }
  13740. if ($falg)
  13741. $html .= '<td class="taR">-</td>';
  13742. }
  13743. if (! empty ( $psum ))
  13744. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13745. else
  13746. $psum = '<td class="colGreen taR">-</td>';
  13747. $receiptL ['差旅相关费用'] = $psum . $html;
  13748. /* ----------------------------------- */
  13749. $html = "";
  13750. $psum = 0;
  13751. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13752. $falg = true;
  13753. foreach ( $receiptCollectList as $v ) {
  13754. if ($v ['itemCategory'] == '内部培训费用') {
  13755. if ($v ['item'] == $value['name']) {
  13756. $psum += $v ['price'];
  13757. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13758. $falg = false;
  13759. break;
  13760. }
  13761. }
  13762. }
  13763. if ($falg)
  13764. $html .= '<td class="taR">-</td>';
  13765. }
  13766. if (! empty ( $psum ))
  13767. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13768. else
  13769. $psum = '<td class="colGreen taR">-</td>';
  13770. $receiptL ['内部培训费用'] = $psum . $html;
  13771. /* ------------------------------------- */
  13772. $html = "";
  13773. $psum = 0;
  13774. foreach ( $aiList[$this->TRAIN] as $value ) {
  13775. $falg = true;
  13776. foreach ( $receiptCollectList as $v ) {
  13777. if ($v ['itemCategory'] == '培训班费用') {
  13778. if ($v ['item'] == $value['name']) {
  13779. $psum += $v ['price'];
  13780. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13781. $falg = false;
  13782. break;
  13783. }
  13784. }
  13785. }
  13786. if ($falg)
  13787. $html .= '<td class="taR">-</td>';
  13788. }
  13789. if (! empty ( $psum ))
  13790. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13791. else
  13792. $psum = '<td class="colGreen taR">-</td>';
  13793. $receiptL ['培训班费用'] = $psum . $html;
  13794. /* ------------------------------------- */
  13795. $html = "";
  13796. $psum = 0;
  13797. foreach ( $aiList[$this->OTHER] as $value ) {
  13798. $falg = true;
  13799. foreach ( $receiptCollectList as $v ) {
  13800. if ($v ['itemCategory'] == '其他') {
  13801. if ($v ['item'] == $value['name']) {
  13802. $psum += $v ['price'];
  13803. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13804. $falg = false;
  13805. break;
  13806. }
  13807. }
  13808. }
  13809. if ($falg)
  13810. $html .= '<td class="taR">-</td>';
  13811. }
  13812. if (! empty ( $psum ))
  13813. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13814. else
  13815. $psum = '<td class="colGreen taR">-</td>';
  13816. $receiptL ['其他'] = $psum . $html;
  13817. /* ------------------------------------- */
  13818. $html = "";
  13819. $psum = 0;
  13820. foreach ( $receiptCollectList as $v ) {
  13821. if ($v ['itemCategory'] == '报销金额调整') {
  13822. if (! empty ( $v ['price'] ))
  13823. $psum += $v ['price'];
  13824. }
  13825. }
  13826. if (! empty ( $psum ))
  13827. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13828. else
  13829. $psum = '<td class="taR colOrange">-</td>';
  13830. $receiptL ['报销金额调整'] = $psum . $html;
  13831. } else {
  13832. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13833. foreach ( $aiList[$this->AGENCY] as $va ) {
  13834. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13835. }
  13836. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13837. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13838. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13839. }
  13840. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13841. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13842. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13843. }
  13844. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13845. foreach ( $aiList[$this->TRAIN] as $va ) {
  13846. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13847. }
  13848. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13849. foreach ( $aiList[$this->OTHER] as $va ) {
  13850. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13851. }
  13852. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13853. }
  13854. return $receiptL;
  13855. }
  13856. function eMail() {
  13857. Doo::loadModel ( 'staff' );
  13858. $staff = new staff ();
  13859. Doo::loadModel ( 'receipt' );
  13860. $receipt = new receipt ();
  13861. Doo::loadModel ( 'L_category' );
  13862. $Lcategory = new L_category ();
  13863. Doo::loadModel ( "verify" );
  13864. $verify = new verify ();
  13865. $staffList = $staff->find ( array (
  13866. 'asArray' => true
  13867. ) );
  13868. foreach ( $staffList as $key => $value ) {
  13869. if ($value ['username'] != 'admin') {
  13870. // 提交人
  13871. $receiptList = $receipt->find ( array (
  13872. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13873. 'asArray' => true
  13874. ) );
  13875. if (! empty ( $receiptList )) {
  13876. $html = '<br><div><style></style>
  13877. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13878. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13879. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13880. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13881. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13882. <tbody><tr>
  13883. <td style="padding: 0 40px;" align="left">
  13884. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13885. </td></tr><tr>
  13886. <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>
  13887. </tr>
  13888. </tbody> </table></td> </tr> <tr><td>
  13889. <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">
  13890. <tbody> <tr><td>
  13891. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13892. 以下报销单完成了审批,等着收款吧:</p>
  13893. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13894. foreach ( $receiptList as $k => $v ) {
  13895. $category = $Lcategory->getOne ( array (
  13896. 'where' => 'cid=' . $v ['cid'],
  13897. 'asArray' => true
  13898. ) );
  13899. $html .= '
  13900. <tr>
  13901. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13902. <td align="left">
  13903. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13904. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13905. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13906. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13907. </tr>';
  13908. }
  13909. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13910. <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>
  13911. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13912. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13913. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13914. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13915. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13916. $receipt = new receipt ();
  13917. $receipt->notice = 1;
  13918. $receipt->update ( array (
  13919. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13920. ) );
  13921. }
  13922. }
  13923. // 审批人
  13924. $verifyList = $verify->find ( array (
  13925. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13926. 'asArray' => true
  13927. ) );
  13928. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  13929. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  13930. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13931. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  13932. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13933. <tbody><tr><td style="padding: 0 40px;" align="left">
  13934. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13935. </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>
  13936. </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">
  13937. <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>
  13938. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  13939. foreach ( $verifyList as $k => $v ) {
  13940. $receiptList = $receipt->find ( array (
  13941. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  13942. 'asArray' => true
  13943. ) );
  13944. foreach ( $receiptList as $r => $l ) {
  13945. $category = $Lcategory->getOne ( array (
  13946. 'where' => 'cid=' . $l ['cid'],
  13947. 'asArray' => true
  13948. ) );
  13949. $staffDetile = $staff->getOne ( array (
  13950. 'where' => 'sid=' . $l ['staff'],
  13951. 'asArray' => true
  13952. ) );
  13953. $html .= '
  13954. <tr>
  13955. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13956. <td align="left">
  13957. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  13958. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  13959. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  13960. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  13961. </tr>';
  13962. }
  13963. }
  13964. $html .= '
  13965. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  13966. <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>
  13967. </tr></tbody></table></td></tr></tbody></table></div><br>';
  13968. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  13969. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  13970. // $receipt=new receipt();
  13971. // $receipt->notice=1;
  13972. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  13973. }
  13974. }
  13975. }
  13976. }
  13977. function setWXMsg($rid, $type) {
  13978. Doo::loadModel ( "receipt" );
  13979. $receipt = new receipt ();
  13980. $receiptDetail = $receipt->getOne ( array (
  13981. 'where' => 'rid=' . $rid,
  13982. 'asArray' => true
  13983. ) );
  13984. if (! empty ( $receiptDetail )) {
  13985. Doo::loadModel ( 'staff' );
  13986. $staff = new staff ();
  13987. $staffmsg = $staff->getOne ( array (
  13988. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  13989. 'asArray' => TRUE
  13990. ) );
  13991. if (! empty ( $staffmsg ['wxid'] )) {
  13992. require_once (SITE_PATH . '/protected/class/client.php');
  13993. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  13994. $user = $staffmsg ['wxid'];
  13995. $receiptName = '';
  13996. $msg = '';
  13997. switch ($receiptDetail ['Rtype']) {
  13998. case 0 :
  13999. $receiptName = '报销';
  14000. break;
  14001. case 1 :
  14002. $receiptName = '借款';
  14003. break;
  14004. case 2 :
  14005. $receiptName = '对公汇款';
  14006. break;
  14007. }
  14008. switch ($type) {
  14009. case 1 :
  14010. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14011. break;
  14012. case 2 :
  14013. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14014. break;
  14015. case 3 :
  14016. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14017. break;
  14018. }
  14019. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14020. }
  14021. }
  14022. }
  14023. // Email发送函数
  14024. function SMail($toemail, $subject, $contents) {
  14025. Doo::loadClass ( 'class.phpmailer' );
  14026. $mail = new PHPMailer ();
  14027. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14028. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14029. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14030. $mail->Password = "cDO1GjtY1seH"; // 密码
  14031. $mail->CharSet = "UTF8";
  14032. $mail->SMTPAuth = true;
  14033. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14034. $mail->Mailer = "smtp";
  14035. $mail->Port = 25;
  14036. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14037. $mail->MsgHTML ( $contents );
  14038. $mail->AddAddress ( $toemail );
  14039. $mail->CharSet = "UTF-8";
  14040. return $mail->Send ();
  14041. }
  14042. function h5Upload() {
  14043. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14044. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14045. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14046. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14047. header ( "HTTP/1.1 500 Internal Server Error" );
  14048. echo "POST exceeded maximum allowed size.";
  14049. exit ( 0 );
  14050. }
  14051. // Settings
  14052. $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)
  14053. $upload_name = "Filedata";
  14054. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14055. $extension_whitelist = array (
  14056. "doc",
  14057. "txt",
  14058. "jpg",
  14059. "gif",
  14060. "png"
  14061. ); // Allowed file extensions
  14062. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14063. // Other variables
  14064. $MAX_FILENAME_LENGTH = 260;
  14065. $file_name = "";
  14066. $file_extension = "";
  14067. $uploadErrors = array (
  14068. 0 => "文件上传成功",
  14069. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14070. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14071. 3 => "上传的文件仅为部分文件",
  14072. 4 => "没有文件上传",
  14073. 6 => "缺少临时文件夹"
  14074. );
  14075. $nk = time ();
  14076. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14077. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14078. echo "文件无法保存.";
  14079. exit ( 0 );
  14080. }
  14081. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14082. echo json_encode ( array (
  14083. 'filename' => $file_name,
  14084. 'id' => $nk
  14085. ) );
  14086. exit ( 0 );
  14087. }
  14088. function swfupload() {
  14089. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14090. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14091. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14092. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14093. header ( "HTTP/1.1 500 Internal Server Error" );
  14094. echo "POST exceeded maximum allowed size.";
  14095. exit ( 0 );
  14096. }
  14097. // Settings
  14098. $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)
  14099. $upload_name = "Filedata";
  14100. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14101. $extension_whitelist = array (
  14102. "doc",
  14103. "txt",
  14104. "jpg",
  14105. "gif",
  14106. "png"
  14107. ); // Allowed file extensions
  14108. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14109. // Other variables
  14110. $MAX_FILENAME_LENGTH = 260;
  14111. $file_name = "";
  14112. $file_extension = "";
  14113. $uploadErrors = array (
  14114. 0 => "文件上传成功",
  14115. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14116. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14117. 3 => "上传的文件仅为部分文件",
  14118. 4 => "没有文件上传",
  14119. 6 => "缺少临时文件夹"
  14120. );
  14121. $nk = time ();
  14122. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14123. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14124. echo "文件无法保存.";
  14125. exit ( 0 );
  14126. }
  14127. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14128. echo json_encode ( array (
  14129. 'filename' => $file_name,
  14130. 'id' => $nk
  14131. ) );
  14132. exit ( 0 );
  14133. }
  14134. function _GetFileEXT($filename) {
  14135. $pics = explode ( '.', $filename );
  14136. $num = count ( $pics );
  14137. return $pics [$num - 1];
  14138. }
  14139. /**
  14140. * 获取get或者POST值
  14141. * @param string $name 属性名称
  14142. * @return fixed 值
  14143. */
  14144. function get_args($name) {
  14145. if (isset ( $_GET [$name] )) {
  14146. if (is_array ( $_GET [$name] ))
  14147. return $_GET [$name];
  14148. else
  14149. return addslashes ( $_GET [$name] );
  14150. } elseif (isset ( $_POST [$name] )) {
  14151. if (is_array ( $_POST [$name] ))
  14152. return $_POST [$name];
  14153. else
  14154. return addslashes ( $_POST [$name] );
  14155. } else
  14156. return false;
  14157. }
  14158. function num_to_rmb($num) {
  14159. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14160. $c2 = "分角元拾佰仟万拾佰仟亿";
  14161. // 精确到分后面就不要了,所以只留两个小数位
  14162. $num = round ( $num, 2 );
  14163. // 将数字转化为整数
  14164. $num = $num * 100;
  14165. if (strlen ( $num ) > 10) {
  14166. return "金额太大,请检查";
  14167. }
  14168. $i = 0;
  14169. $c = "";
  14170. while ( 1 ) {
  14171. if ($i == 0) {
  14172. // 获取最后一位数字
  14173. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14174. } else {
  14175. $n = $num % 10;
  14176. }
  14177. // 每次将最后一位数字转化为中文
  14178. $p1 = substr ( $c1, 3 * $n, 3 );
  14179. $p2 = substr ( $c2, 3 * $i, 3 );
  14180. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14181. $c = $p1 . $p2 . $c;
  14182. } else {
  14183. $c = $p1 . $c;
  14184. }
  14185. $i = $i + 1;
  14186. // 去掉数字最后一位了
  14187. $num = $num / 10;
  14188. // echo $num.'</br>';
  14189. $num = ( int ) $num;
  14190. // $num =floor($num);
  14191. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14192. // echo $num.'</br>';
  14193. // 结束循环
  14194. if ($num == 0) {
  14195. break;
  14196. }
  14197. }
  14198. // echo $c.'</br>';
  14199. $j = 0;
  14200. $slen = strlen ( $c );
  14201. while ( $j < $slen ) {
  14202. // utf8一个汉字相当3个字符
  14203. $m = substr ( $c, $j, 6 );
  14204. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14205. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14206. $left = substr ( $c, 0, $j );
  14207. $right = substr ( $c, $j + 3 );
  14208. $c = $left . $right;
  14209. $j = $j - 3;
  14210. $slen = $slen - 3;
  14211. }
  14212. $j = $j + 3;
  14213. }
  14214. // 这个是为了去掉类似23.0中最后一个“零”字
  14215. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14216. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14217. }
  14218. // 将处理的汉字加上“整”
  14219. if (empty ( $c )) {
  14220. return "零元整";
  14221. } else {
  14222. return $c . "整";
  14223. }
  14224. }
  14225. /**
  14226. * 获得分页数据
  14227. * @param unknown_type $table
  14228. * @param unknown_type $condition
  14229. * @param unknown_type $on_page
  14230. * @param unknown_type $page_size
  14231. */
  14232. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14233. $page_c = "";
  14234. $page ['previous'] = $this->get_previous ( $on_page );
  14235. $page ['on_page'] = $on_page;
  14236. $total_count = $this->get_table_count ( $table, $condition );
  14237. $total = intval ( $total_count / $page_size );
  14238. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14239. $page ['total_data'] = $total_count;
  14240. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14241. $i = 1;
  14242. $page_max = 1;
  14243. $page_width = 3;
  14244. if ($on_page >= $page_width) {
  14245. $page_max = intval ( $on_page / $page_width ) + 1;
  14246. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14247. }
  14248. for(; $i <= $page ['total_page']; $i ++) {
  14249. if ($i == $on_page)
  14250. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14251. else
  14252. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14253. if ($i == ($page_width * $page_max))
  14254. break;
  14255. }
  14256. $page ['page'] = $page_c;
  14257. $page ['lower'] = (-- $on_page) * $page_size;
  14258. return $page;
  14259. }
  14260. /**
  14261. * 获取总页数
  14262. * @param unknown_type $table
  14263. * @param unknown_type $condition
  14264. */
  14265. public function get_table_count($table = "", $condition = "") {
  14266. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14267. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14268. // echo $sql;die;
  14269. $query = Doo::db ()->query ( $sql );
  14270. $result = $query->fetch ();
  14271. return $result ['count'];
  14272. }
  14273. /**
  14274. * 获取上一页
  14275. * @param unknown_type $on_page
  14276. */
  14277. function get_previous($on_page = 1) {
  14278. return $on_page != 0 ? $on_page - 1 : $on_page;
  14279. }
  14280. }
  14281. ?>