ReceiptController.php 534 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. public function beforeRun($resource, $action) {
  58. Doo::loadClass ( 'XDeode' );
  59. $XDeode = new XDeode ( 5 );
  60. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  61. // 单独判断公司汇总的访问权限
  62. if ($action == 'companyCategoryCollect') {
  63. Doo::loadModel ( "receiptAuthorityManage" );
  64. $invoiceCompanyManage = new receiptAuthorityManage ();
  65. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  66. if (empty ( $icm ))
  67. die ( 'illegal request' );
  68. }
  69. Doo::loadModel ( 'staff' );
  70. $staff = new staff ();
  71. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  72. $accessModular = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'where'=>'mold !="日常收支"',
  121. 'select' => 'staff',
  122. 'asArray' => true
  123. ) );
  124. $list2 = array ();
  125. foreach ( $executeList as $key => $value ) {
  126. $ver = json_decode ( $value ['staff'] );
  127. foreach ( $ver as $k => $v ) {
  128. array_push ( $list2, $v [0] );
  129. }
  130. }
  131. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  132. $eidList = array_filter ( explode ( ",", $eidList ) );
  133. $this->executeId = array_merge ( $list2, $eidList );
  134. $this->verifyId = $list;
  135. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  136. // 检测用户信息完成
  137. $this->data ['isStaffCompleteMsg'] = false;
  138. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  139. if (! empty ( $detail ))
  140. $this->data ['isStaffCompleteMsg'] = true;
  141. return "/";
  142. }
  143. }
  144. Doo::loadCore ( 'uri/DooUriRouter' );
  145. $router = new DooUriRouter ();
  146. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  147. if ($routeRs ['1'] != "login") {
  148. header ( 'Content-Type:text/html;charset=utf-8' );
  149. @header ( "Location: /login" );
  150. }
  151. }
  152. function saeaBorad() {
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'verify' );
  156. $verify = new verify ();
  157. Doo::loadModel ( 'L_category' );
  158. $lCategory = new L_category ();
  159. Doo::loadModel ( "role" );
  160. $role = new role ();
  161. Doo::loadModel ( "receiptLog" );
  162. $receiptLog = new receiptLog ();
  163. Doo::loadClass ( 'XDeode' );
  164. $XDeode = new XDeode ( 7 );
  165. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  166. $receiptDetail = $receipt->find ( array (
  167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  168. 'desc' => 'rid',
  169. 'asArray' => true
  170. ) );
  171. foreach ( $receiptDetail as $key => $value ) {
  172. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  173. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  174. $veList = $verify->getOne ( array (
  175. 'where' => 'vid=' . $value ['verify'],
  176. 'asArray' => true
  177. ) );
  178. $v = json_decode ( $veList ['staff'] );
  179. array_push ( $v [0], $veList ['description'] );
  180. foreach ( $v as $n => $m ) {
  181. if ($m ['1'] == 'ROLE') {
  182. $roleInfo = $role->getOne ( array (
  183. 'where' => 'rid=' . $m [0],
  184. 'asArray' => true
  185. ) );
  186. $v [$n] [1] = $roleInfo ['name'];
  187. }
  188. }
  189. $receiptDetail [$key] ['staff'] = $v;
  190. $category = $lCategory->getOne ( array (
  191. 'where' => 'cid=' . $value ['cid'],
  192. 'asArray' => true
  193. ) );
  194. $receiptDetail [$key] ['category'] = $category ['title'];
  195. }
  196. // print_r($receiptLogList);
  197. Doo::loadModel ( 'RAssist' );
  198. $RAssist = new RAssist ();
  199. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  200. $data ['receiptExtendList'] = $receiptExtendList;
  201. $data ['receiptLogList'] = $receiptLogList;
  202. $data ['receiptDetail'] = $receiptDetail;
  203. $data ['memu'] = "receipt";
  204. $data ['staff'] = $this->staff;
  205. $data ['receiptMemu'] = 'saeaBorad';
  206. $data ['verifyId'] = $this->verifyId;
  207. $data ['executeId'] = $this->executeId;
  208. $this->render ( "/admin/saeaBorad", $data );
  209. }
  210. function remitAdd() {
  211. Doo::loadModel ( 'accountItem' );
  212. Doo::loadModel ( 'verify' );
  213. Doo::loadModel ( 'receipt' );
  214. Doo::loadModel ( 'L_category' );
  215. $lCategory = new L_category ();
  216. $receipt = new receipt ();
  217. $verify = new verify ();
  218. $accountItem = new accountItem ();
  219. Doo::loadModel ( "role" );
  220. $role = new role ();
  221. $acItem = $accountItem->find ( array (
  222. 'asArray' => true
  223. ) );
  224. $veList = $verify->getVerifyBySubordinate('REMIT');
  225. $data ['category'] = $lCategory->find ( array (
  226. 'asArray' => true
  227. ) );
  228. $data ['veList'] = $veList;
  229. $data ['acItem'] = $acItem;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/admin/remitAdd", $data );
  236. }
  237. function remitAddDo() {
  238. $agency = $this->get_args ( 'agency' );
  239. $travel = $this->get_args ( 'travel' );
  240. $train = $this->get_args ( 'train' );
  241. $other = $this->get_args ( 'other' );
  242. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  243. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  244. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  245. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  246. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  247. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  248. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  249. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  250. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  251. // print_r($agency);die;
  252. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  253. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  254. header ( 'Content-Type:text/html;charset=utf-8' );
  255. die ( '请填写联行号' );
  256. }
  257. Doo::loadModel ( 'receipt' );
  258. Doo::loadModel ( 'receiptDetail' );
  259. Doo::loadModel ( 'accountItem' );
  260. $accountItem = new accountItem ();
  261. $receipt = new receipt ();
  262. Doo::loadModel ( 'enclosur' );
  263. Doo::loadModel ( 'execute' );
  264. $execute = new execute ();
  265. $executeDetail = $execute->getOne ( array (
  266. 'where' => 'mold="对公汇款执行人"',
  267. 'asArray' => true
  268. ) );
  269. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  270. $aItem = $accountItem->find ( array (
  271. 'where' => 'name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保"',
  272. 'asArray' => true
  273. ) );
  274. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  275. $ag = $tr = $ta = $ot = 0;
  276. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  277. foreach ( $aItem as $key => $value ) {
  278. if ($value ['category'] == $this->AGENCY) {
  279. if (isset ( $agency [$ag] )) {
  280. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  281. array_push ( $accountJson [$this->AGENCY], array (
  282. 'aid' => $value ['aid'],
  283. 'name' => $value ['name'],
  284. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  285. ) );
  286. $sum += $agency [$ag];
  287. $agencySum += $agency [$ag];
  288. }
  289. }
  290. $ag ++;
  291. }
  292. }
  293. $accountJson ['cSum'] = array (
  294. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  295. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  296. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  297. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  298. );
  299. // 报销单
  300. $receipt->accountItem = json_encode ( $accountJson );
  301. $receipt->staff = $this->staff [0] ['sid'];
  302. $receipt->sum = number_format ( $sum, 2, '.', '' );
  303. $receipt->date = date ( "Y-m-d" );
  304. $receipt->cid = $cid;
  305. $receipt->status = 5;
  306. $receipt->Rtype = 2;
  307. // 修改审批流程加入角色
  308. $receipt->verify = $verify;
  309. $receipt->executeCopy = $executeDetail ['staff'];
  310. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  311. $order = array (
  312. "\r\n",
  313. "\n",
  314. "\r"
  315. );
  316. $replace = '<br/>';
  317. $explanation = str_replace ( $order, $replace, $explanation );
  318. $receipt->explanation = $explanation;
  319. $receipt->remittanceName = $remittanceName;
  320. $receipt->bankName = $bankName;
  321. $receipt->bankNumber = $bankNumber;
  322. $receipt->remittanceBankType = $remittanceBankType;
  323. if ($remittanceBankType == 1)
  324. $receipt->coupletNumber = $coupletNumber;
  325. $rid = $receipt->insert ();
  326. // 附件
  327. if (! empty ( $enclosurName )) {
  328. $enclosurArray = explode ( '-', $enclosurName );
  329. foreach ( $enclosurArray as $value ) {
  330. $enclosur = new enclosur ();
  331. $enclosur->name = $value;
  332. $enclosur->rid = $rid;
  333. $enclosur->insert ();
  334. }
  335. // print_r($enclosurArray);die;
  336. }
  337. // 报销详情
  338. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  339. $receiptDetail = new receiptDetail ();
  340. $receiptDetail->staff = $this->staff [0] ['sid'];
  341. $receiptDetail->item = $value ['name'];
  342. $receiptDetail->itemCategory = $this->AGENCY;
  343. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  344. $receiptDetail->date = date ( "Y-m-d" );
  345. $receiptDetail->cid = $cid;
  346. $receiptDetail->rid = $rid;
  347. $receiptDetail->status = 4;
  348. $receiptDetail->insert ();
  349. }
  350. return "/saeaBorad";
  351. } else
  352. die ( 'illegal request' );
  353. }
  354. function remitEdit() {
  355. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  356. Doo::loadClass ( 'XDeode' );
  357. $XDeode = new XDeode ( 7 );
  358. $rid = $XDeode->decode ( $ridKey );
  359. if (! is_numeric ( $rid ))
  360. die ( 'illegal request' );
  361. Doo::loadModel ( 'accountItem' );
  362. Doo::loadModel ( 'verify' );
  363. Doo::loadModel ( 'receipt' );
  364. $receipt = new receipt ();
  365. $verify = new verify ();
  366. $accountItem = new accountItem ();
  367. Doo::loadModel ( 'L_category' );
  368. $lCategory = new L_category ();
  369. Doo::loadModel ( "role" );
  370. $role = new role ();
  371. Doo::loadModel ( 'enclosur' );
  372. $enclosur = new enclosur ();
  373. $receiptDetail = $receipt->getOne ( array (
  374. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  375. 'asArray' => true
  376. ) );
  377. if (empty ( $receiptDetail ))
  378. return "/saeaCreate";
  379. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  380. $acItem = $accountItem->find ( array (
  381. 'asArray' => true
  382. ) );
  383. $veList = $verify->getVerifyBySubordinate('REMIT');
  384. // 配置编辑信息
  385. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  386. foreach ( $acItem as $key => $value ) {
  387. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  388. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  389. $acItem [$key] ['price'] = $v ['price'];
  390. }
  391. }
  392. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  393. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  394. $acItem [$key] ['price'] = $v ['price'];
  395. }
  396. }
  397. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  398. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  399. $acItem [$key] ['price'] = $v ['price'];
  400. }
  401. }
  402. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  403. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  404. $acItem [$key] ['price'] = $v ['price'];
  405. }
  406. }
  407. }
  408. $data ['category'] = $lCategory->find ( array (
  409. 'asArray' => true
  410. ) );
  411. $data ['enclosurList'] = $enclosurList;
  412. $data ['cSum'] = $accountItemList ['cSum'];
  413. $data ['sum'] = $receiptDetail ['sum'];
  414. $data ['receiptDetail'] = $receiptDetail;
  415. $data ['veList'] = $veList;
  416. $data ['acItem'] = $acItem;
  417. $data ['memu'] = "receipt";
  418. $data ['staff'] = $this->staff;
  419. $data ['receiptMemu'] = 'saeaBorad';
  420. $data ['verify'] = $receiptDetail ['verify'];
  421. $data ['verifyId'] = $this->verifyId;
  422. $data ['executeId'] = $this->executeId;
  423. $data ['rid'] = $rid;
  424. $data ['ridKey'] = $ridKey;
  425. $this->render ( "/admin/remitEdit", $data );
  426. }
  427. function remitEdiDo() {
  428. $agency = $this->get_args ( 'agency' );
  429. $travel = $this->get_args ( 'travel' );
  430. $train = $this->get_args ( 'train' );
  431. $other = $this->get_args ( 'other' );
  432. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  433. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  434. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  435. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  436. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  437. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  438. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  439. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  440. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  441. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  442. Doo::loadClass ( 'XDeode' );
  443. $XDeode = new XDeode ( 7 );
  444. $rid = $XDeode->decode ( $ridKey );
  445. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  446. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  447. header ( 'Content-Type:text/html;charset=utf-8' );
  448. die ( '请填写联行号' );
  449. }
  450. Doo::loadModel ( 'receipt' );
  451. Doo::loadModel ( 'receiptDetail' );
  452. Doo::loadModel ( 'accountItem' );
  453. $accountItem = new accountItem ();
  454. $receipt = new receipt ();
  455. Doo::loadModel ( 'enclosur' );
  456. $enclosur = new enclosur ();
  457. Doo::loadModel ( 'execute' );
  458. $execute = new execute ();
  459. $executeDetail = $execute->getOne ( array (
  460. 'where' => 'mold="对公汇款执行人"',
  461. 'asArray' => true
  462. ) );
  463. $receiptDetail = $receipt->getOne ( array (
  464. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  465. 'asArray' => true
  466. ) );
  467. if (empty ( $receiptDetail ))
  468. return "/saeaBorad";
  469. $aItem = $accountItem->find ( array (
  470. 'where' => 'name like "办公费用" or name like "其他费用" or name like "公积金" or name like "社保"',
  471. 'asArray' => true
  472. ) );
  473. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  474. $ag = $tr = $ta = $ot = 0;
  475. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  476. foreach ( $aItem as $key => $value ) {
  477. if ($value ['category'] == $this->AGENCY) {
  478. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  479. array_push ( $accountJson [$this->AGENCY], array (
  480. 'aid' => $value ['aid'],
  481. 'name' => $value ['name'],
  482. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  483. ) );
  484. $sum += $agency [$ag];
  485. $agencySum += $agency [$ag];
  486. }
  487. $ag ++;
  488. }
  489. }
  490. $accountJson ['cSum'] = array (
  491. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  492. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  493. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  494. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  495. );
  496. // 报销单
  497. $rid = $receipt->rid = $receiptDetail ['rid'];
  498. $receipt->accountItem = json_encode ( $accountJson );
  499. $receipt->staff = $this->staff [0] ['sid'];
  500. $receipt->sum = number_format ( $sum, 2, '.', '' );
  501. $receipt->date = date ( "Y-m-d" );
  502. $receipt->cid = $cid;
  503. if ($receiptDetail ['Rtype'] == 1)
  504. $receipt->status = 7;
  505. else
  506. $receipt->status = 5;
  507. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  508. $receipt->verify = $verify;
  509. $receipt->executeCopy = $executeDetail ['staff'];
  510. $order = array (
  511. "\r\n",
  512. "\n",
  513. "\r"
  514. );
  515. $replace = '<br/>';
  516. $explanation = str_replace ( $order, $replace, $explanation );
  517. $receipt->explanation = $explanation;
  518. $receipt->remittanceName = $remittanceName;
  519. $receipt->bankName = $bankName;
  520. $receipt->bankNumber = $bankNumber;
  521. $receipt->remittanceBankType = $remittanceBankType;
  522. if ($remittanceBankType == 1)
  523. $receipt->coupletNumber = $coupletNumber;
  524. $receipt->update ();
  525. $receiptDetail = new receiptDetail ();
  526. $receiptDetail->delete ( array (
  527. 'where' => 'rid=' . $rid
  528. ) );
  529. // 报销详情
  530. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  531. $receiptDetail = new receiptDetail ();
  532. $receiptDetail->staff = $this->staff [0] ['sid'];
  533. $receiptDetail->item = $value ['name'];
  534. $receiptDetail->itemCategory = $this->AGENCY;
  535. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  536. $receiptDetail->date = date ( "Y-m-d" );
  537. $receiptDetail->cid = $cid;
  538. $receiptDetail->rid = $rid;
  539. $receiptDetail->status = 4;
  540. $receiptDetail->insert ();
  541. }
  542. // 附件
  543. if (! empty ( $enclosurName )) {
  544. $enclosurArray = explode ( '-', $enclosurName );
  545. foreach ( $enclosurArray as $value ) {
  546. $enclosur = new enclosur ();
  547. $enclosur->name = $value;
  548. $enclosur->rid = $rid;
  549. $enclosur->insert ();
  550. }
  551. }
  552. }
  553. return "/saeaBorad";
  554. }
  555. function remitApproval() {
  556. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  557. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  558. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  559. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  560. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  561. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  562. if (empty ( $status ))
  563. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  564. $vidList = array ();
  565. $button = 0;
  566. Doo::loadModel ( 'verify' );
  567. Doo::loadModel ( 'receipt' );
  568. Doo::loadModel ( 'staff' );
  569. $staff = new staff ();
  570. $receipt = new receipt ();
  571. $verify = new verify ();
  572. Doo::loadModel ( 'L_category' );
  573. $Lcategory = new L_category ();
  574. Doo::loadModel ( 'enclosur' );
  575. $enclosur = new enclosur ();
  576. // user verify ID
  577. $verifyDetail = $verify->find ( array (
  578. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  579. 'asArray' => true
  580. ) );
  581. foreach ( $verifyDetail as $key => $value ) {
  582. array_push ( $vidList, $value ['vid'] );
  583. }
  584. $vid = implode ( ",", $vidList );
  585. if (empty ( $verifyDetail ))
  586. $vid = 0;
  587. $categoryList = $Lcategory->find ( array (
  588. 'asArray' => true
  589. ) );
  590. $staffList = $staff->find ( array (
  591. 'where' => 'cid=' . $cid,
  592. 'asArray' => true
  593. ) );
  594. $ap = "";
  595. if ($status == 4) {
  596. $ap = 4;
  597. $status = 2;
  598. }
  599. // get Receipt By verifyID status 2
  600. $receiptList = $receipt->find ( array (
  601. 'where' => 'rid =' . $rid . ' and status=2',
  602. 'desc' => 'rid',
  603. 'asArray' => true
  604. ) );
  605. if (empty ( $receiptList )) {
  606. die ( 'illegal request' );
  607. }
  608. $Locate = 0;
  609. $roleId = 0;
  610. if ($ap == 4)
  611. $status = 4;
  612. foreach ( $receiptList as $key => $value ) {
  613. $receiptList [$key] ['Locate'] = $Locate;
  614. $Locate ++;
  615. $receiptList [$key] ['reviseDetail'] = array ();
  616. if (! empty ( $value ['reviseDetail'] ))
  617. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  618. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  619. $categoryDetil = $Lcategory->getOne ( array (
  620. 'where' => 'cid=' . $value ['cid'],
  621. 'asArray' => true
  622. ) );
  623. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  624. // 检测编辑状态
  625. $verifyList = $verify->getOne ( array (
  626. 'where' => 'vid=' . $value ['verify'],
  627. 'asArray' => true
  628. ) );
  629. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  630. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  631. Doo::loadModel ( 'role' );
  632. $role = new role ();
  633. // print_r($verifyList);
  634. $flag = true;
  635. $roleKey = 0;
  636. $endStaffArray = array ();
  637. $roleArrayCopy = array ();
  638. foreach ( $verifyList as $k => $v ) {
  639. // init verifyStaff
  640. if ($v [1] == 'ROLE') {
  641. if (! empty ( $verifyStaff )) {
  642. $endStaffArray = end ( $verifyStaff );
  643. if ($v [0] == $endStaffArray ['nextStaff']) {
  644. $roleId = $v [0];
  645. }
  646. }
  647. $roleVerify = json_decode ( $v [3], true );
  648. $roleKey = $k;
  649. $roleArray = array ();
  650. $rolename = $role->getOne ( array (
  651. 'where' => 'rid=' . $v [0],
  652. 'asArray' => true
  653. ) );
  654. foreach ( $roleVerify as $o => $p ) {
  655. $staffID = explode ( '_', $p );
  656. $staffInfo = $staff->getOne ( array (
  657. 'where' => 'sid=' . $staffID [0],
  658. 'asArray' => true
  659. ) );
  660. // print_r($staffID);
  661. $exp = array (
  662. 0 => $staffInfo ['sid'],
  663. 1 => $staffID [1],
  664. 2 => $staffInfo ['avatar'],
  665. 'date' => '',
  666. 'date' => '',
  667. 'opinion' => '',
  668. 'status' => '',
  669. 'rolename' => $rolename ['name']
  670. );
  671. array_push ( $roleArray, $exp );
  672. }
  673. $roleArrayCopy [$v [0]] = $roleArray;
  674. // $verifyList[$k]['roleArray']=$roleArray;
  675. }
  676. // print_r($roleArray);
  677. $verifyList [$k] ['date'] = "";
  678. $verifyList [$k] ['opinion'] = "";
  679. $verifyList [$k] ['status'] = "";
  680. if (empty ( $verifyStaff )) {
  681. $verifyList [$k] ['date'] = "";
  682. $verifyList [$k] ['opinion'] = "";
  683. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  684. $verifyList [$k] ['status'] = 4;
  685. $button = 4;
  686. $flag = false;
  687. }
  688. } else {
  689. foreach ( $verifyStaff as $m => $u ) {
  690. if ($v [0] == $m) {
  691. $verifyList [$k] ['date'] = $u ['date'];
  692. $verifyList [$k] ['opinion'] = $u ['opinion'];
  693. $verifyList [$k] ['status'] = $u ['status'];
  694. $flag = false;
  695. break;
  696. }
  697. }
  698. $endStaffArray = end ( $verifyStaff );
  699. if (isset ( $endStaffArray ['ROLE'] )) {
  700. } else {
  701. $endKey = key ( $verifyStaff );
  702. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  703. $button = 4;
  704. $verifyList [$k] ['status'] = 4;
  705. }
  706. }
  707. }
  708. }
  709. $rolename ['name'] = '';
  710. if (! empty ( $roleId )) {
  711. Doo::loadModel ( 'role' );
  712. $role = new role ();
  713. $rolename = $role->getOne ( array (
  714. 'where' => 'rid=' . $roleId,
  715. 'asArray' => true
  716. ) );
  717. }
  718. if (! empty ( $verifyStaff ))
  719. $endStaffArray = end ( $verifyStaff );
  720. $KOP = false;
  721. foreach ( $roleArrayCopy as $P => $A ) {
  722. foreach ( $A as $MKI => $AVL ) {
  723. if (! empty ( $verifyStaff )) {
  724. // &&$rolename['rid']==$endStaffArray['nextStaff']
  725. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  726. $button = 4;
  727. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  728. }
  729. foreach ( $verifyStaff as $m => $u ) {
  730. $AVLFK = $AVL [0] . '_R';
  731. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  732. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  733. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  734. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  735. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  736. break;
  737. }
  738. }
  739. } else {
  740. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  741. $button = 4;
  742. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  743. }
  744. }
  745. // $roleArray[$MKI]['rolename']=$rolename['name'];
  746. $KOP = true;
  747. }
  748. }
  749. foreach ( $roleArrayCopy as $k => $v ) {
  750. foreach ( $verifyList as $m => $n ) {
  751. if ($n [0] == $k) {
  752. array_splice ( $verifyList, $m, 1, $v );
  753. }
  754. }
  755. }
  756. $receiptList [$key] ['verifyList'] = $verifyList;
  757. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  758. 'where' => 'sid=' . $value ['staff'],
  759. 'asArray' => true
  760. ) );
  761. $receiptList [$key] ['button'] = $button;
  762. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  763. }
  764. $mothHtml = "";
  765. for($i = 1; $i <= 12; $i ++) {
  766. if ($month == $i)
  767. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  768. else
  769. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  770. }
  771. // 获取审批日志
  772. Doo::loadModel ( 'receiptLog' );
  773. $receiptLog = new receiptLog ();
  774. $rlList = array ();
  775. $rlInfo = $receiptLog->getOne ( array (
  776. 'where' => 'rid=' . $rid . ' and status=4',
  777. 'asArray' => true
  778. ) );
  779. $tijdate = $receiptLog->getOne ( array (
  780. 'where' => 'rid=' . $rid . ' and status=2',
  781. 'asc' => 'rlid',
  782. 'asArray' => true
  783. ) );
  784. if (! empty ( $rlInfo )) {
  785. $rlList = $receiptLog->find ( array (
  786. 'where' => 'rid=' . $rid,
  787. 'asc' => 'rlid',
  788. 'asArray' => true
  789. ) );
  790. }
  791. $receiptList [0] ['rlList'] = $rlList;
  792. $enclosurList = $enclosur->find ( array (
  793. 'where' => 'rid=' . $rid,
  794. 'asArray' => true
  795. ) );
  796. $enclosurHtml = '';
  797. foreach ( $enclosurList as $value ) {
  798. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  799. }
  800. // print_r($receiptList);
  801. $data ['enclosurHtml'] = $enclosurHtml;
  802. $data ['rolename'] = $rolename ['name'];
  803. $data ['datetij'] = $tijdate ['date'];
  804. $data ['mothHtml'] = $mothHtml;
  805. $data ['rid'] = $rid;
  806. $data ['receiptList'] = $receiptList;
  807. $data ['receiptApprovalCount'] = count ( $receiptList );
  808. $data ['status'] = $status;
  809. $data ['year'] = $year;
  810. $data ['categoryList'] = $categoryList;
  811. $data ['staffList'] = $staffList;
  812. $data ['cid'] = $cid;
  813. $data ['sid'] = $sid;
  814. $data ['ap'] = $ap;
  815. $data ['memu'] = "receipt";
  816. $data ['staff'] = $this->staff;
  817. $data ['receiptMemu'] = 'approvalExpenses';
  818. $data ['verifyId'] = $this->verifyId;
  819. $data ['executeId'] = $this->executeId;
  820. $this->render ( "/admin/remitApproval", $data );
  821. }
  822. function saeaLoanAdd() {
  823. Doo::loadModel ( 'verify' );
  824. $verify = new verify ();
  825. Doo::loadModel ( "role" );
  826. $role = new role ();
  827. Doo::loadModel ( 'L_category' );
  828. $lCategory = new L_category ();
  829. $veList = $verify->getVerifyBySubordinate('LOAN');
  830. $data ['category'] = $lCategory->find ( array (
  831. 'asArray' => true
  832. ) );
  833. $data ['veList'] = $veList;
  834. $data ['memu'] = "receipt";
  835. $data ['staff'] = $this->staff;
  836. $data ['receiptMemu'] = 'saeaBorad';
  837. $data ['verifyId'] = $this->verifyId;
  838. $data ['executeId'] = $this->executeId;
  839. $this->render ( "/admin/saeaLoanAdd", $data );
  840. }
  841. function saeaLoanAddDo() {
  842. $agency = $this->get_args ( 'agency' );
  843. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  844. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  845. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  846. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  847. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  848. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  849. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  850. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  851. // die;
  852. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  853. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  854. header ( 'Content-Type:text/html;charset=utf-8' );
  855. die ( '请填写联行号' );
  856. }
  857. Doo::loadModel ( 'receipt' );
  858. Doo::loadModel ( 'receiptDetail' );
  859. Doo::loadModel ( 'accountItem' );
  860. $accountItem = new accountItem ();
  861. $receipt = new receipt ();
  862. Doo::loadModel ( 'loanReceipt' );
  863. $loanReceipt = new loanReceipt ();
  864. Doo::loadModel ( 'execute' );
  865. $execute = new execute ();
  866. Doo::loadModel ( 'enclosur' );
  867. $executeDetail = $execute->getOne ( array (
  868. 'where' => 'mold="借款执行人"',
  869. 'asArray' => true
  870. ) );
  871. $aItem = $accountItem->find ( array (
  872. 'asArray' => true
  873. ) );
  874. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  875. $ag = $tr = $ta = $ot = 0;
  876. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  877. array_push ( $accountJson ['借款费用'], array (
  878. 'aid' => 0,
  879. 'name' => '申请金额',
  880. 'price' => number_format ( $agency, 2, '.', '' )
  881. ) );
  882. $sum += $agency;
  883. $agencySum += $agency;
  884. $accountJson ['cSum'] = array (
  885. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  886. 'agencySum' => number_format ( 0, 2, '.', '' ),
  887. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  888. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  889. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  890. );
  891. // 借款数据备份
  892. $loanReceipt->loanItem = json_encode ( $accountJson );
  893. $loanReceipt->staff = $this->staff [0] ['sid'];
  894. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  895. $loanReceipt->date = date ( "Y-m-d" );
  896. $loanReceipt->cid = $cid;
  897. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  898. $loanReceipt->status = 5;
  899. $loanReceipt->Rtype = 1;
  900. $loanReceipt->verify = $verify;
  901. $receipt->receiptOrder = $receipt->receiptOrder;
  902. // 添加HTML换行符
  903. // var_dump($explanation);
  904. $order = array (
  905. "\r\n",
  906. "\n",
  907. "\r"
  908. );
  909. $replace = '<br/>';
  910. $explanation = str_replace ( $order, $replace, $explanation );
  911. // $explanation=str_replace('\r',"<br/>",$explanation);
  912. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  913. $loanReceipt->explanation = $explanation;
  914. $loanRid = $loanReceipt->insert ();
  915. // 报销单
  916. $receipt->loanItem = json_encode ( $accountJson );
  917. $receipt->staff = $this->staff [0] ['sid'];
  918. $receipt->sum = number_format ( $sum, 2, '.', '' );
  919. $receipt->date = date ( "Y-m-d" );
  920. $receipt->cid = $cid;
  921. // 特殊状态
  922. $receipt->status = 5;
  923. $receipt->Rtype = 1;
  924. $receipt->loanRid = $loanRid;
  925. // 修改审批流程加入角色
  926. $receipt->verify = $verify;
  927. $receipt->executeCopy = $executeDetail ['staff'];
  928. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  929. $receipt->explanation = $explanation;
  930. $receipt->remittanceName = $remittanceName;
  931. $receipt->bankName = $bankName;
  932. $receipt->bankNumber = $bankNumber;
  933. $receipt->remittanceBankType = $remittanceBankType;
  934. if ($remittanceBankType == 1)
  935. $receipt->coupletNumber = $coupletNumber;
  936. $rid = $receipt->insert ();
  937. return "/saeaBorad";
  938. } else
  939. die ( 'illegal request' );
  940. }
  941. function saeaLoanEdi() {
  942. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  943. Doo::loadClass ( 'XDeode' );
  944. $XDeode = new XDeode ( 7 );
  945. $rid = $XDeode->decode ( $ridKey );
  946. if (! is_numeric ( $rid ))
  947. die ( 'illegal request' );
  948. Doo::loadModel ( 'verify' );
  949. $verify = new verify ();
  950. Doo::loadModel ( "role" );
  951. $role = new role ();
  952. Doo::loadModel ( 'L_category' );
  953. $lCategory = new L_category ();
  954. Doo::loadModel ( 'receipt' );
  955. $receipt = new receipt ();
  956. $receiptInfo = $receipt->getOne ( array (
  957. 'where' => 'rid=' . $rid,
  958. 'asArray' => true
  959. ) );
  960. $veList = $verify->find ( array (
  961. 'where'=>'subordinate like "%LOAN%"',
  962. 'asArray' => true
  963. ) );
  964. foreach ( $veList as $key => $value ) {
  965. $v = json_decode ( $value ['staff'] );
  966. $list = array ();
  967. foreach ( $v as $n => $m ) {
  968. if ($m ['1'] == 'ROLE') {
  969. $roleInfo = $role->getOne ( array (
  970. 'where' => 'rid=' . $m [0],
  971. 'asArray' => true
  972. ) );
  973. $v [$n] [1] = $roleInfo ['name'];
  974. array_push ( $list, $roleInfo ['name'] );
  975. } else {
  976. array_push ( $list, $v [$n] [1] );
  977. }
  978. }
  979. $veList [$key] ['staff'] = implode ( '>', $list );
  980. }
  981. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  982. // print_r($receiptInfo);
  983. $data ['receiptInfo'] = $receiptInfo;
  984. $data ['category'] = $lCategory->find ( array (
  985. 'asArray' => true
  986. ) );
  987. $data ['veList'] = $veList;
  988. $data ['ridKey'] = $ridKey;
  989. $data ['memu'] = "receipt";
  990. $data ['staff'] = $this->staff;
  991. $data ['receiptMemu'] = 'saeaBorad';
  992. $data ['verifyId'] = $this->verifyId;
  993. $data ['executeId'] = $this->executeId;
  994. $this->render ( "/admin/saeaLoanEdi", $data );
  995. }
  996. function saeaLoanEdiDo() {
  997. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  998. $agency = $this->get_args ( 'agency' );
  999. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1000. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1001. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1002. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1003. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1004. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1005. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1006. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1007. // die;
  1008. Doo::loadClass ( 'XDeode' );
  1009. $XDeode = new XDeode ( 7 );
  1010. $rid = $XDeode->decode ( $ridKey );
  1011. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1012. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1013. header ( 'Content-Type:text/html;charset=utf-8' );
  1014. die ( '请填写联行号' );
  1015. }
  1016. Doo::loadModel ( 'receipt' );
  1017. Doo::loadModel ( 'receiptDetail' );
  1018. Doo::loadModel ( 'accountItem' );
  1019. $accountItem = new accountItem ();
  1020. $receipt = new receipt ();
  1021. Doo::loadModel ( 'loanReceipt' );
  1022. $loanReceipt = new loanReceipt ();
  1023. Doo::loadModel ( 'enclosur' );
  1024. Doo::loadModel ( 'execute' );
  1025. $execute = new execute ();
  1026. $executeDetail = $execute->getOne ( array (
  1027. 'where' => 'mold="借款执行人"',
  1028. 'asArray' => true
  1029. ) );
  1030. $receiptDetail = $receipt->getOne ( array (
  1031. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1032. 'asArray' => true
  1033. ) );
  1034. if (empty ( $receiptDetail ))
  1035. die ( '参数错误' );
  1036. $aItem = $accountItem->find ( array (
  1037. 'asArray' => true
  1038. ) );
  1039. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1040. $ag = $tr = $ta = $ot = 0;
  1041. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1042. array_push ( $accountJson ['借款费用'], array (
  1043. 'aid' => 0,
  1044. 'name' => '申请金额',
  1045. 'price' => number_format ( $agency, 2, '.', '' )
  1046. ) );
  1047. $sum += $agency;
  1048. $agencySum += $agency;
  1049. $accountJson ['cSum'] = array (
  1050. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1051. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1052. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1053. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1054. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1055. );
  1056. // 报销单
  1057. $receipt->loanItem = json_encode ( $accountJson );
  1058. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1059. $receipt->cid = $cid;
  1060. // 特殊状态
  1061. // 修改审批流程加入角色
  1062. if ($receiptDetail ['status'] != 4)
  1063. $receipt->verify = $verify;
  1064. $order = array (
  1065. "\r\n",
  1066. "\n",
  1067. "\r"
  1068. );
  1069. $replace = '<br/>';
  1070. $explanation = str_replace ( $order, $replace, $explanation );
  1071. $receipt->explanation = $explanation;
  1072. $receipt->remittanceName = $remittanceName;
  1073. $receipt->bankName = $bankName;
  1074. $receipt->bankNumber = $bankNumber;
  1075. $receipt->remittanceBankType = $remittanceBankType;
  1076. if ($remittanceBankType == 1)
  1077. $receipt->coupletNumber = $coupletNumber;
  1078. $receipt->update ( array (
  1079. 'where' => 'rid=' . $rid
  1080. ) );
  1081. // 借款数据更新
  1082. $loanReceipt->loanItem = json_encode ( $accountJson );
  1083. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1084. $loanReceipt->cid = $cid;
  1085. if ($receiptDetail ['status'] != 4)
  1086. $loanReceipt->verify = $verify;
  1087. $loanReceipt->explanation = $explanation;
  1088. $receipt->executeCopy = $executeDetail ['staff'];
  1089. $loanReceipt->update ( array (
  1090. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1091. ) );
  1092. }
  1093. return "/saeaBorad";
  1094. }
  1095. function saeaLoanReceiptAdd() {
  1096. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1097. Doo::loadModel ( 'receipt' );
  1098. $receipt = new receipt ();
  1099. Doo::loadModel ( 'loanReceipt' );
  1100. $loanReceipt = new loanReceipt ();
  1101. Doo::loadModel ( 'L_category' );
  1102. $Lcategory = new L_category ();
  1103. Doo::loadModel ( 'verify' );
  1104. Doo::loadModel ( 'statistics' );
  1105. $statistics = new statistics ();
  1106. $verify = new verify ();
  1107. Doo::loadModel ( 'staff' );
  1108. $staff = new staff ();
  1109. $receiptDetail = $receipt->getOne ( array (
  1110. 'where' => 'rid=' . $rid,
  1111. 'desc' => 'rid',
  1112. 'asArray' => true
  1113. ) );
  1114. $receiptList = $loanReceipt->find ( array (
  1115. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1116. 'desc' => 'rid',
  1117. 'asArray' => true
  1118. ) );
  1119. $Locate = 0;
  1120. $roleId = 0;
  1121. $button = 0;
  1122. foreach ( $receiptList as $key => $value ) {
  1123. $receiptList [$key] ['Locate'] = $Locate;
  1124. $Locate ++;
  1125. $receiptList [$key] ['reviseDetail'] = array ();
  1126. if (! empty ( $value ['reviseDetail'] ))
  1127. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1128. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1129. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1130. $categoryDetil = $Lcategory->getOne ( array (
  1131. 'where' => 'cid=' . $value ['cid'],
  1132. 'asArray' => true
  1133. ) );
  1134. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1135. // 检测编辑状态
  1136. $verifyList = $verify->getOne ( array (
  1137. 'where' => 'vid=' . $value ['verify'],
  1138. 'asArray' => true
  1139. ) );
  1140. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1141. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1142. Doo::loadModel ( 'role' );
  1143. $role = new role ();
  1144. $flag = true;
  1145. $roleKey = 0;
  1146. $endStaffArray = array ();
  1147. $roleArrayCopy = array ();
  1148. foreach ( $verifyList as $k => $v ) {
  1149. // init verifyStaff
  1150. if ($v [1] == 'ROLE') {
  1151. if (! empty ( $verifyStaff )) {
  1152. $endStaffArray = end ( $verifyStaff );
  1153. // if ($v[0]==$endStaffArray['nextStaff']){
  1154. // $roleId=$v[0];
  1155. // }
  1156. }
  1157. $roleVerify = json_decode ( $v [3], true );
  1158. $roleKey = $k;
  1159. $roleArray = array ();
  1160. $rolename = $role->getOne ( array (
  1161. 'where' => 'rid=' . $v [0],
  1162. 'asArray' => true
  1163. ) );
  1164. foreach ( $roleVerify as $o => $p ) {
  1165. $staffID = explode ( '_', $p );
  1166. $staffInfo = $staff->getOne ( array (
  1167. 'where' => 'sid=' . $staffID [0],
  1168. 'asArray' => true
  1169. ) );
  1170. // print_r($staffID);
  1171. $exp = array (
  1172. 0 => $staffInfo ['sid'],
  1173. 1 => $staffID [1],
  1174. 2 => $staffInfo ['avatar'],
  1175. 'date' => '',
  1176. 'date' => '',
  1177. 'opinion' => '',
  1178. 'status' => '',
  1179. 'rolename' => $rolename ['name']
  1180. );
  1181. array_push ( $roleArray, $exp );
  1182. }
  1183. $roleArrayCopy [$v [0]] = $roleArray;
  1184. // $verifyList[$k]['roleArray']=$roleArray;
  1185. }
  1186. $verifyList [$k] ['date'] = "";
  1187. $verifyList [$k] ['opinion'] = "";
  1188. $verifyList [$k] ['status'] = "";
  1189. if (empty ( $verifyStaff )) {
  1190. $verifyList [$k] ['date'] = "";
  1191. $verifyList [$k] ['opinion'] = "";
  1192. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1193. $verifyList [$k] ['status'] = 4;
  1194. $flag = false;
  1195. }
  1196. } else {
  1197. foreach ( $verifyStaff as $m => $u ) {
  1198. if ($v [0] == $m) {
  1199. $verifyList [$k] ['date'] = $u ['date'];
  1200. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1201. $verifyList [$k] ['status'] = $u ['status'];
  1202. $flag = false;
  1203. break;
  1204. }
  1205. }
  1206. $endStaffArray = end ( $verifyStaff );
  1207. if (isset ( $endStaffArray ['ROLE'] )) {
  1208. } else {
  1209. // $endKey=key($verifyStaff);
  1210. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1211. // $button=4;
  1212. // $verifyList[$k]['status']=4;
  1213. // }
  1214. }
  1215. }
  1216. }
  1217. $rolename ['name'] = '';
  1218. if (! empty ( $roleId )) {
  1219. Doo::loadModel ( 'role' );
  1220. $role = new role ();
  1221. $rolename = $role->getOne ( array (
  1222. 'where' => 'rid=' . $roleId,
  1223. 'asArray' => true
  1224. ) );
  1225. }
  1226. if (! empty ( $verifyStaff ))
  1227. $endStaffArray = end ( $verifyStaff );
  1228. $KOP = false;
  1229. foreach ( $roleArrayCopy as $P => $A ) {
  1230. foreach ( $A as $MKI => $AVL ) {
  1231. if (! empty ( $verifyStaff )) {
  1232. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1233. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1234. $button = 4;
  1235. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1236. }
  1237. foreach ( $verifyStaff as $m => $u ) {
  1238. $AVLFK = $AVL [0] . '_R';
  1239. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1240. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1241. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1242. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1243. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1244. break;
  1245. }
  1246. }
  1247. } else {
  1248. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1249. $button = 4;
  1250. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1251. }
  1252. }
  1253. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1254. $KOP = true;
  1255. }
  1256. }
  1257. foreach ( $roleArrayCopy as $k => $v ) {
  1258. foreach ( $verifyList as $m => $n ) {
  1259. if ($n [0] == $k) {
  1260. array_splice ( $verifyList, $m, 1, $v );
  1261. }
  1262. }
  1263. }
  1264. $receiptList [$key] ['verifyList'] = $verifyList;
  1265. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1266. 'where' => 'sid=' . $value ['staff'],
  1267. 'asArray' => true
  1268. ) );
  1269. $receiptList [$key] ['button'] = $button;
  1270. //
  1271. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1272. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1273. }
  1274. $data ['receiptList'] = $receiptList;
  1275. $data ['receiptDetail'] = $receiptDetail;
  1276. Doo::loadModel ( 'L_category' );
  1277. $lCategory = new L_category ();
  1278. Doo::loadModel ( 'accountItem' );
  1279. $accountItem = new accountItem ();
  1280. $acItem = $accountItem->find ( array (
  1281. 'asArray' => true
  1282. ) );
  1283. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1284. $data ['rid'] = $rid;
  1285. $data ['category'] = $lCategory->find ( array (
  1286. 'asArray' => true
  1287. ) );
  1288. $data ['veList'] = $veList;
  1289. $data ['acItem'] = $acItem;
  1290. $data ['memu'] = "receipt";
  1291. $data ['staff'] = $this->staff;
  1292. $data ['receiptMemu'] = 'saeaBorad';
  1293. $data ['verifyId'] = $this->verifyId;
  1294. $data ['executeId'] = $this->executeId;
  1295. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1296. }
  1297. function saeaLoanReceiptAddDo() {
  1298. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1299. $agency = $this->get_args ( 'agency' );
  1300. $travel = $this->get_args ( 'travel' );
  1301. $train = $this->get_args ( 'train' );
  1302. $other = $this->get_args ( 'other' );
  1303. $inttrain = $this->get_args ( 'inttrain' );
  1304. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1305. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1306. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1307. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1308. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1309. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1310. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1311. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1312. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1313. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1314. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1315. header ( 'Content-Type:text/html;charset=utf-8' );
  1316. die ( '请填写联行号' );
  1317. }
  1318. Doo::loadModel ( 'receipt' );
  1319. Doo::loadModel ( 'receiptDetail' );
  1320. Doo::loadModel ( 'accountItem' );
  1321. $accountItem = new accountItem ();
  1322. $receipt = new receipt ();
  1323. Doo::loadModel ( 'enclosur' );
  1324. Doo::loadModel ( 'execute' );
  1325. $execute = new execute ();
  1326. $executeDetail = $execute->getOne ( array (
  1327. 'where' => 'mold="借款费用执行人"',
  1328. 'asArray' => true
  1329. ) );
  1330. $receiptDet = $receipt->getOne ( array (
  1331. 'where' => 'rid=' . $rid,
  1332. 'asArray' => true
  1333. ) );
  1334. // if(!empty($receiptDetail))
  1335. // return "/referReceipt/".$receiptDetail['rid'];
  1336. $aItem = $accountItem->find ( array (
  1337. 'asArray' => true
  1338. ) );
  1339. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1340. $ag = $tr = $ta = $ot =$it = 0;
  1341. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1342. foreach ( $aItem as $key => $value ) {
  1343. if ($value ['category'] == $this->AGENCY) {
  1344. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1345. array_push ( $accountJson [$this->AGENCY], array (
  1346. 'aid' => $value ['aid'],
  1347. 'name' => $value ['name'],
  1348. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1349. ) );
  1350. $sum += $agency [$ag];
  1351. $agencySum += $agency [$ag];
  1352. }
  1353. $ag ++;
  1354. }
  1355. if ($value ['category'] == $this->TRAVEL) {
  1356. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1357. array_push ( $accountJson [$this->TRAVEL], array (
  1358. 'aid' => $value ['aid'],
  1359. 'name' => $value ['name'],
  1360. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1361. ) );
  1362. $sum += $travel [$tr];
  1363. $travelSum += $travel [$tr];
  1364. }
  1365. $tr ++;
  1366. }
  1367. if ($value ['category'] == $this->INTTRAIN) {
  1368. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1369. array_push ( $accountJson [$this->INTTRAIN], array (
  1370. 'aid' => $value ['aid'],
  1371. 'name' => $value ['name'],
  1372. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1373. ) );
  1374. $sum += $inttrain [$it];
  1375. $inttrainSum += $inttrain [$it];
  1376. }
  1377. $it ++;
  1378. }
  1379. if ($value ['category'] == $this->TRAIN) {
  1380. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1381. array_push ( $accountJson [$this->TRAIN], array (
  1382. 'aid' => $value ['aid'],
  1383. 'name' => $value ['name'],
  1384. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1385. ) );
  1386. $sum += $train [$ta];
  1387. $trainSum += $train [$ta];
  1388. }
  1389. $ta ++;
  1390. }
  1391. if ($value ['category'] == $this->OTHER) {
  1392. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1393. array_push ( $accountJson [$this->OTHER], array (
  1394. 'aid' => $value ['aid'],
  1395. 'name' => $value ['name'],
  1396. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1397. ) );
  1398. $sum += $other [$ot];
  1399. $otherSum += $other [$ot];
  1400. }
  1401. $ot ++;
  1402. }
  1403. }
  1404. $accountJson ['cSum'] = array (
  1405. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1406. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1407. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1408. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1409. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1410. );
  1411. // 报销单
  1412. $receipt->accountItem = json_encode ( $accountJson );
  1413. $receipt->staff = $this->staff [0] ['sid'];
  1414. $receipt->loanSum = $receiptDet ['sum'];
  1415. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1416. $receipt->date = date ( "Y-m-d" );
  1417. $receipt->pastDate = '';
  1418. $receipt->cid = $cid;
  1419. $receipt->status = 7;
  1420. // 修改审批流程加入角色
  1421. $receipt->verify = $verify;
  1422. $receipt->verifyStaff = '';
  1423. $receipt->executeStaff = '';
  1424. $receipt->executeCopy = $executeDetail ['staff'];
  1425. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1426. $receipt->explanation = $explanation;
  1427. $receipt->remittanceName = $remittanceName;
  1428. $receipt->bankName = $bankName;
  1429. $receipt->bankNumber = $bankNumber;
  1430. $receipt->remittanceBankType = $remittanceBankType;
  1431. if ($remittanceBankType == 1)
  1432. $receipt->coupletNumber = $coupletNumber;
  1433. $receipt->update ( array (
  1434. 'where' => 'rid=' . $rid
  1435. ) );
  1436. // 附件
  1437. if (! empty ( $enclosurName )) {
  1438. $enclosurArray = explode ( '-', $enclosurName );
  1439. foreach ( $enclosurArray as $value ) {
  1440. $enclosur = new enclosur ();
  1441. $enclosur->name = $value;
  1442. $enclosur->rid = $rid;
  1443. $enclosur->insert ();
  1444. }
  1445. // print_r($enclosurArray);die;
  1446. }
  1447. // 报销详情
  1448. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1449. $receiptDetail = new receiptDetail ();
  1450. $receiptDetail->staff = $this->staff [0] ['sid'];
  1451. $receiptDetail->item = $value ['name'];
  1452. $receiptDetail->itemCategory = $this->AGENCY;
  1453. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1454. $receiptDetail->date = date ( "Y-m-d" );
  1455. $receiptDetail->cid = $cid;
  1456. $receiptDetail->rid = $rid;
  1457. $receiptDetail->status = 4;
  1458. $receiptDetail->insert ();
  1459. }
  1460. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1461. $receiptDetail = new receiptDetail ();
  1462. $receiptDetail->staff = $this->staff [0] ['sid'];
  1463. $receiptDetail->item = $value ['name'];
  1464. $receiptDetail->itemCategory = $this->TRAVEL;
  1465. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1466. $receiptDetail->date = date ( "Y-m-d" );
  1467. $receiptDetail->cid = $cid;
  1468. $receiptDetail->rid = $rid;
  1469. $receiptDetail->status = 4;
  1470. $receiptDetail->insert ();
  1471. }
  1472. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1473. $receiptDetail = new receiptDetail ();
  1474. $receiptDetail->staff = $this->staff [0] ['sid'];
  1475. $receiptDetail->item = $value ['name'];
  1476. $receiptDetail->itemCategory = $this->TRAIN;
  1477. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1478. $receiptDetail->date = date ( "Y-m-d" );
  1479. $receiptDetail->cid = $cid;
  1480. $receiptDetail->rid = $rid;
  1481. $receiptDetail->status = 4;
  1482. $receiptDetail->insert ();
  1483. }
  1484. //内训
  1485. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1486. $receiptDetail = new receiptDetail ();
  1487. $receiptDetail->staff = $this->staff [0] ['sid'];
  1488. $receiptDetail->item = $value ['name'];
  1489. $receiptDetail->itemCategory = $this->INTTRAIN;
  1490. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1491. $receiptDetail->date = date ( "Y-m-d" );
  1492. $receiptDetail->cid = $cid;
  1493. $receiptDetail->rid = $rid;
  1494. $receiptDetail->status = 4;
  1495. $receiptDetail->insert ();
  1496. }
  1497. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1498. $receiptDetail = new receiptDetail ();
  1499. $receiptDetail->staff = $this->staff [0] ['sid'];
  1500. $receiptDetail->item = $value ['name'];
  1501. $receiptDetail->itemCategory = $this->OTHER;
  1502. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1503. $receiptDetail->date = date ( "Y-m-d" );
  1504. $receiptDetail->cid = $cid;
  1505. $receiptDetail->rid = $rid;
  1506. $receiptDetail->status = 4;
  1507. $receiptDetail->insert ();
  1508. }
  1509. return "/saeaBorad";
  1510. }
  1511. return "/saeaLoanReceiptAdd/" . $rid;
  1512. }
  1513. function saeaLoanReceiptEdi() {
  1514. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1515. Doo::loadClass ( 'XDeode' );
  1516. $XDeode = new XDeode ( 7 );
  1517. $rid = $XDeode->decode ( $ridKey );
  1518. if (! is_numeric ( $rid ))
  1519. die ( 'illegal request' );
  1520. Doo::loadModel ( 'accountItem' );
  1521. Doo::loadModel ( 'verify' );
  1522. Doo::loadModel ( 'receipt' );
  1523. $receipt = new receipt ();
  1524. $verify = new verify ();
  1525. $accountItem = new accountItem ();
  1526. Doo::loadModel ( 'L_category' );
  1527. $Lcategory = new L_category ();
  1528. Doo::loadModel ( "role" );
  1529. $role = new role ();
  1530. Doo::loadModel ( 'loanReceipt' );
  1531. $loanReceipt = new loanReceipt ();
  1532. Doo::loadModel ( 'staff' );
  1533. $staff = new staff ();
  1534. $receiptDetail = $receipt->getOne ( array (
  1535. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1536. 'asArray' => true
  1537. ) );
  1538. if (empty ( $receiptDetail ))
  1539. return "/saeaBorad";
  1540. $receiptList = $loanReceipt->find ( array (
  1541. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1542. 'desc' => 'rid',
  1543. 'asArray' => true
  1544. ) );
  1545. $Locate = 0;
  1546. $roleId = 0;
  1547. $button = 0;
  1548. foreach ( $receiptList as $key => $value ) {
  1549. $receiptList [$key] ['Locate'] = $Locate;
  1550. $Locate ++;
  1551. $receiptList [$key] ['reviseDetail'] = array ();
  1552. if (! empty ( $value ['reviseDetail'] ))
  1553. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1554. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1555. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1556. $categoryDetil = $Lcategory->getOne ( array (
  1557. 'where' => 'cid=' . $value ['cid'],
  1558. 'asArray' => true
  1559. ) );
  1560. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1561. // 检测编辑状态
  1562. $verifyList = $verify->getOne ( array (
  1563. 'where' => 'vid=' . $value ['verify'],
  1564. 'asArray' => true
  1565. ) );
  1566. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1567. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1568. Doo::loadModel ( 'role' );
  1569. $role = new role ();
  1570. $flag = true;
  1571. $roleKey = 0;
  1572. $endStaffArray = array ();
  1573. $roleArrayCopy = array ();
  1574. foreach ( $verifyList as $k => $v ) {
  1575. // init verifyStaff
  1576. if ($v [1] == 'ROLE') {
  1577. if (! empty ( $verifyStaff )) {
  1578. $endStaffArray = end ( $verifyStaff );
  1579. // if ($v[0]==$endStaffArray['nextStaff']){
  1580. // $roleId=$v[0];
  1581. // }
  1582. }
  1583. $roleVerify = json_decode ( $v [3], true );
  1584. $roleKey = $k;
  1585. $roleArray = array ();
  1586. $rolename = $role->getOne ( array (
  1587. 'where' => 'rid=' . $v [0],
  1588. 'asArray' => true
  1589. ) );
  1590. foreach ( $roleVerify as $o => $p ) {
  1591. $staffID = explode ( '_', $p );
  1592. $staffInfo = $staff->getOne ( array (
  1593. 'where' => 'sid=' . $staffID [0],
  1594. 'asArray' => true
  1595. ) );
  1596. // print_r($staffID);
  1597. $exp = array (
  1598. 0 => $staffInfo ['sid'],
  1599. 1 => $staffID [1],
  1600. 2 => $staffInfo ['avatar'],
  1601. 'date' => '',
  1602. 'date' => '',
  1603. 'opinion' => '',
  1604. 'status' => '',
  1605. 'rolename' => $rolename ['name']
  1606. );
  1607. array_push ( $roleArray, $exp );
  1608. }
  1609. $roleArrayCopy [$v [0]] = $roleArray;
  1610. // $verifyList[$k]['roleArray']=$roleArray;
  1611. }
  1612. $verifyList [$k] ['date'] = "";
  1613. $verifyList [$k] ['opinion'] = "";
  1614. $verifyList [$k] ['status'] = "";
  1615. if (empty ( $verifyStaff )) {
  1616. $verifyList [$k] ['date'] = "";
  1617. $verifyList [$k] ['opinion'] = "";
  1618. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1619. $verifyList [$k] ['status'] = 4;
  1620. $flag = false;
  1621. }
  1622. } else {
  1623. foreach ( $verifyStaff as $m => $u ) {
  1624. if ($v [0] == $m) {
  1625. $verifyList [$k] ['date'] = $u ['date'];
  1626. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1627. $verifyList [$k] ['status'] = $u ['status'];
  1628. $flag = false;
  1629. break;
  1630. }
  1631. }
  1632. $endStaffArray = end ( $verifyStaff );
  1633. if (isset ( $endStaffArray ['ROLE'] )) {
  1634. } else {
  1635. // $endKey=key($verifyStaff);
  1636. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1637. // $button=4;
  1638. // $verifyList[$k]['status']=4;
  1639. // }
  1640. }
  1641. }
  1642. }
  1643. $rolename ['name'] = '';
  1644. if (! empty ( $roleId )) {
  1645. Doo::loadModel ( 'role' );
  1646. $role = new role ();
  1647. $rolename = $role->getOne ( array (
  1648. 'where' => 'rid=' . $roleId,
  1649. 'asArray' => true
  1650. ) );
  1651. }
  1652. if (! empty ( $verifyStaff ))
  1653. $endStaffArray = end ( $verifyStaff );
  1654. $KOP = false;
  1655. foreach ( $roleArrayCopy as $P => $A ) {
  1656. foreach ( $A as $MKI => $AVL ) {
  1657. if (! empty ( $verifyStaff )) {
  1658. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1659. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1660. $button = 4;
  1661. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1662. }
  1663. foreach ( $verifyStaff as $m => $u ) {
  1664. $AVLFK = $AVL [0] . '_R';
  1665. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1666. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1667. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1668. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1669. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1670. break;
  1671. }
  1672. }
  1673. } else {
  1674. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1675. $button = 4;
  1676. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1677. }
  1678. }
  1679. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1680. $KOP = true;
  1681. }
  1682. }
  1683. foreach ( $roleArrayCopy as $k => $v ) {
  1684. foreach ( $verifyList as $m => $n ) {
  1685. if ($n [0] == $k) {
  1686. array_splice ( $verifyList, $m, 1, $v );
  1687. }
  1688. }
  1689. }
  1690. $receiptList [$key] ['verifyList'] = $verifyList;
  1691. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1692. 'where' => 'sid=' . $value ['staff'],
  1693. 'asArray' => true
  1694. ) );
  1695. $receiptList [$key] ['button'] = $button;
  1696. //
  1697. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1698. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1699. }
  1700. $data ['receiptList'] = $receiptList;
  1701. $acItem = $accountItem->find ( array (
  1702. 'asArray' => true
  1703. ) );
  1704. $veList = $verify->find ( array (
  1705. 'asArray' => true
  1706. ) );
  1707. foreach ( $veList as $key => $value ) {
  1708. $v = json_decode ( $value ['staff'] );
  1709. $list = array ();
  1710. foreach ( $v as $n => $m ) {
  1711. if ($m ['1'] == 'ROLE') {
  1712. $roleInfo = $role->getOne ( array (
  1713. 'where' => 'rid=' . $m [0],
  1714. 'asArray' => true
  1715. ) );
  1716. $v [$n] [1] = $roleInfo ['name'];
  1717. array_push ( $list, $roleInfo ['name'] );
  1718. } else {
  1719. array_push ( $list, $v [$n] [1] );
  1720. }
  1721. }
  1722. $veList [$key] ['staff'] = implode ( '>', $list );
  1723. }
  1724. // 配置编辑信息
  1725. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1726. foreach ( $acItem as $key => $value ) {
  1727. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1728. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1729. $acItem [$key] ['price'] = $v ['price'];
  1730. }
  1731. }
  1732. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1733. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1734. $acItem [$key] ['price'] = $v ['price'];
  1735. }
  1736. }
  1737. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1738. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1739. $acItem [$key] ['price'] = $v ['price'];
  1740. }
  1741. }
  1742. //内训
  1743. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1744. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1745. $acItem [$key] ['price'] = $v ['price'];
  1746. }
  1747. }
  1748. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1749. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1750. $acItem [$key] ['price'] = $v ['price'];
  1751. }
  1752. }
  1753. }
  1754. $data ['category'] = $Lcategory->find ( array (
  1755. 'asArray' => true
  1756. ) );
  1757. $data ['ridKey'] = $ridKey;
  1758. $data ['cSum'] = $accountItemList ['cSum'];
  1759. $data ['sum'] = $receiptDetail ['sum'];
  1760. $data ['receiptDetail'] = $receiptDetail;
  1761. $data ['veList'] = $veList;
  1762. $data ['acItem'] = $acItem;
  1763. $data ['memu'] = "receipt";
  1764. $data ['staff'] = $this->staff;
  1765. $data ['receiptMemu'] = 'saeaBorad';
  1766. $data ['verify'] = $receiptDetail ['verify'];
  1767. $data ['verifyId'] = $this->verifyId;
  1768. $data ['executeId'] = $this->executeId;
  1769. $data ['rid'] = $rid;
  1770. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1771. }
  1772. /**
  1773. * 培训班结算
  1774. */
  1775. function receiptTrainAdd() {
  1776. Doo::loadModel ( 'accountItem' );
  1777. $accountItem = new accountItem ();
  1778. $acItem = $accountItem->find ( array (
  1779. 'asArray' => true
  1780. ) );
  1781. // 审批组
  1782. Doo::loadModel ( 'verify' );
  1783. $verify = new verify ();
  1784. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1785. // 办事处
  1786. Doo::loadModel ( 'L_category' );
  1787. $lCategory = new L_category ();
  1788. $data ['category'] = $lCategory->getCategory ();
  1789. $data ['veList'] = $veList;
  1790. $data ['memu'] = "receipt";
  1791. $data ['staff'] = $this->staff;
  1792. $data ['acItem'] = $acItem;
  1793. $data ['receiptMemu'] = 'saeaBorad';
  1794. $data ['verifyId'] = $this->verifyId;
  1795. $data ['executeId'] = $this->executeId;
  1796. $this->render ( "/receipt/receiptTrainAdd", $data );
  1797. }
  1798. /**
  1799. * 添加培训班结算
  1800. */
  1801. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1802. // 培训班信息
  1803. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1804. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1805. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1806. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1807. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1808. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1809. // 发票信息
  1810. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1811. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1812. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1813. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1814. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1815. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1816. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1817. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1818. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1819. header ( 'Content-Type:text/html;charset=utf-8' );
  1820. die ( '请填写联行号' );
  1821. }
  1822. Doo::loadModel ( 'execute' );
  1823. $execute = new execute ();
  1824. $executeDetail = $execute->getOne ( array (
  1825. 'where' => 'mold="培训班结算"',
  1826. 'asArray' => true
  1827. ) );
  1828. if (empty ( $executeDetail )) {
  1829. header ( 'Content-Type:text/html;charset=utf-8' );
  1830. die ( '未设置执行人' );
  1831. }
  1832. Doo::loadClass ( 'XDeode' );
  1833. $XDeode = new XDeode ( 5 );
  1834. $cid = $XDeode->decode ( $cid );
  1835. Doo::loadModel ( 'receipt' );
  1836. $receipt = new receipt ();
  1837. Doo::loadModel ( 'receiptTraining' );
  1838. $receiptTraining = new receiptTraining ();
  1839. // 创建费用培训班
  1840. $item = array (
  1841. 'cid' => $this->staff [0] ['cid'],
  1842. 'categoryName' => $this->staff [0] ['category'],
  1843. 'trainName' => $trainName,
  1844. 'trainStartDate' => $trainStartDate,
  1845. 'trainEndDate' => $trainEndDate,
  1846. 'participants' => $participants,
  1847. 'trainAddress' => $trainAddress,
  1848. 'trainRemarks' => $trainRemarks,
  1849. 'creator' => $this->staff [0] ['sid'],
  1850. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1851. );
  1852. $irid = $receiptTraining->addReceiptTraining ( $item );
  1853. // 报销单
  1854. $receipt->status = 5;
  1855. $receipt->trainId = $irid;
  1856. $receipt->Rtype = 3;
  1857. $receipt->staff = $this->staff [0] ['sid'];
  1858. $receipt->cid = $cid;
  1859. $receipt->verify = $verify;
  1860. $receipt->date = date ( "Y-m-d" );
  1861. $receipt->executeCopy = $executeDetail ['staff'];
  1862. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1863. $receipt->remittanceName = $remittanceName;
  1864. $receipt->bankName = $bankName;
  1865. $receipt->bankNumber = $bankNumber;
  1866. $receipt->remittanceBankType = $remittanceBankType;
  1867. if ($remittanceBankType == 1)
  1868. $receipt->coupletNumber = $coupletNumber;
  1869. $rid = $receipt->insert ();
  1870. $XDeode = new XDeode ( 7 );
  1871. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1872. } else
  1873. die ( 'illegal request' );
  1874. }
  1875. /**
  1876. * 培训班编辑
  1877. */
  1878. function receiptTrainEdi() {
  1879. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1880. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1881. Doo::loadClass ( 'XDeode' );
  1882. $XDeode = new XDeode ( 7 );
  1883. $rid = $XDeode->decode ( $ridKey );
  1884. if (! is_numeric ( $rid ))
  1885. die ( 'illegal request' );
  1886. Doo::loadModel ( 'receipt' );
  1887. $receipt = new receipt ();
  1888. Doo::loadModel ( 'receiptTraining' );
  1889. $receiptTraining = new receiptTraining ();
  1890. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1891. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1892. die ('illegal request--status');
  1893. }
  1894. //如有已入账已收款的发票,自动取消办事处已收款
  1895. // Doo::loadModel ( 'RIExtend' );
  1896. // $RIExtend = new RIExtend ();
  1897. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1898. // if (!empty($RIExtendList)){
  1899. // foreach ($RIExtendList as $key=>$value){
  1900. // $RIExtend = new RIExtend ();
  1901. // $RIExtend->delete(array (
  1902. // 'where' => 'iid=' . $value['iid'],
  1903. // 'limit' => 1
  1904. // ));
  1905. // }
  1906. // }
  1907. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1908. // 汇总表合计
  1909. // 收入合计--加入开票合计
  1910. Doo::loadModel ( 'invoiceTraining' );
  1911. $invoiceTraining = new invoiceTraining ();
  1912. $invoiceTrainingDetail = array (
  1913. 'invoiceArriveAmount' => 0,
  1914. 'RIAmount' => 0,
  1915. 'invoiceTotalAmount' => 0,
  1916. 'invoiceCompanyAmount'=>0
  1917. );
  1918. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1919. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1920. }
  1921. // print_r($invoiceTrainingDetail);
  1922. $invoiceArriveAmount = $RIAmount = 0;
  1923. if (! empty ( $invoiceTrainingDetail )) {
  1924. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1925. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1926. }
  1927. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1928. //print_r($invoiceTrainingDetail);
  1929. // 支出项目
  1930. Doo::loadModel ( 'accountItem' );
  1931. $accountItem = new accountItem ();
  1932. // 项目金额合计
  1933. Doo::loadModel ( 'RItem' );
  1934. $RItem = new RItem ();
  1935. // 讲师获得
  1936. Doo::loadModel ( 'RILecturer' );
  1937. $RILecturer = new RILecturer ();
  1938. $RItemList = $RItem->getRItemByRid ( $rid );
  1939. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1940. // 支出项金额详情
  1941. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1942. // print_r($aiData);
  1943. // 利润
  1944. $profit=$invoiceArriveAmount - $aiData ['total'];
  1945. $companyProfit=$profit * 0.6;
  1946. $categoryProfit=$profit * 0.4;
  1947. $data ['profit'] = sprintf("%.2f",$profit);
  1948. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1949. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1950. //发票利润
  1951. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1952. //发票公司利润
  1953. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1954. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1955. //办事处利润
  1956. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1957. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1958. // print_r($aiData['dataList']);
  1959. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1960. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1961. // 备用金
  1962. $sum = 0;
  1963. $data ['receiptLoanDetail'] = array (
  1964. 'sum' => '0.00'
  1965. );
  1966. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1967. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1968. $sum = $data ['receiptLoanDetail'] ['sum'];
  1969. }
  1970. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1971. $data ['payment'] = sprintf("%.2f",$payment);
  1972. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1973. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1974. $data ['aiList'] = $aiData ['dataList'];
  1975. // 占比计算
  1976. if ($invoiceArriveAmount != 0) {
  1977. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1978. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1979. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1980. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1981. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1982. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1983. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1984. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1985. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1986. } else {
  1987. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1988. }
  1989. //发票金额占比计算
  1990. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1991. //支出
  1992. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1993. //利润
  1994. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1995. //公司利润
  1996. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //办事处利润
  1998. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //公司收款
  2000. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //备用金
  2002. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //办事处收款
  2004. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //办事处实际支出
  2006. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //付总部款
  2008. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. }else{
  2010. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2011. }
  2012. //讲师人数
  2013. Doo::loadModel ( 'RILecturer' );
  2014. $RILecturer = new RILecturer ();
  2015. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2016. $data['lectureCount']=count($RILecturerList);
  2017. // 审批组
  2018. Doo::loadModel ( 'verify' );
  2019. $verify = new verify ();
  2020. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2021. // 办事处
  2022. Doo::loadModel ( 'L_category' );
  2023. $lCategory = new L_category ();
  2024. $data ['category'] = $lCategory->getCategory ();
  2025. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2026. $data ['receiptDetail'] = $receiptDetail;
  2027. $data ['veList'] = $veList;
  2028. $data ['trainEdiType'] = $trainEdiType;
  2029. $data ['ridKey'] = $ridKey;
  2030. $data ['memu'] = "receipt";
  2031. $data ['staff'] = $this->staff;
  2032. $data ['receiptMemu'] = 'saeaBorad';
  2033. $data ['verifyId'] = $this->verifyId;
  2034. $data ['executeId'] = $this->executeId;
  2035. $this->render ( "/receipt/receiptTrainEdi", $data );
  2036. }
  2037. /**
  2038. * 培训班借款编辑
  2039. */
  2040. function receiptTrainLoanEdi() {
  2041. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2042. Doo::loadClass ( 'XDeode' );
  2043. $XDeode = new XDeode ( 7 );
  2044. $rid = $XDeode->decode ( $ridKey );
  2045. if (! is_numeric ( $rid ))
  2046. die ( 'illegal request' );
  2047. Doo::loadModel ( 'receipt' );
  2048. $receipt = new receipt ();
  2049. Doo::loadModel ( 'receiptTraining' );
  2050. $receiptTraining = new receiptTraining ();
  2051. Doo::loadModel ( 'verify' );
  2052. $verify = new verify ();
  2053. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2054. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2055. die ();
  2056. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2057. // 借款详情HTML
  2058. // 获得借款信息
  2059. $receiptLoanHtml = '';
  2060. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2061. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2062. // 获得某费用单审批信息
  2063. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2064. Doo::loadClass ( 'receipt.func' );
  2065. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2066. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2067. }
  2068. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2069. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2070. $data ['receiptDetail'] = $receiptDetail;
  2071. $data ['trainEdiType'] = "LOAN";
  2072. $data ['ridKey'] = $ridKey;
  2073. $data ['memu'] = "receipt";
  2074. $data ['staff'] = $this->staff;
  2075. $data ['receiptMemu'] = 'saeaBorad';
  2076. $data ['verifyId'] = $this->verifyId;
  2077. $data ['executeId'] = $this->executeId;
  2078. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2079. }
  2080. /**
  2081. * 更新培训班结算基本信息
  2082. */
  2083. function receiptTrainInfoEdiDo() {
  2084. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2085. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2086. // 培训班信息
  2087. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2088. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2089. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2090. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2091. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2092. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2093. // 发票信息
  2094. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2095. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2096. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2097. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2098. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2099. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2100. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2101. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2102. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2103. header ( 'Content-Type:text/html;charset=utf-8' );
  2104. die ( '请填写联行号' );
  2105. }
  2106. Doo::loadClass ( 'XDeode' );
  2107. $XDeode = new XDeode ( 5 );
  2108. $cid = $XDeode->decode ( $cid );
  2109. $rtid = $XDeode->decode ( $rtid );
  2110. $rid = $XDeode->decode ( $rid );
  2111. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2112. die ( 'illegal request-IdError' );
  2113. }
  2114. Doo::loadModel ( 'receipt' );
  2115. $receipt = new receipt ();
  2116. Doo::loadModel ( 'receiptTraining' );
  2117. $receiptTraining = new receiptTraining ();
  2118. // 更新费用培训班
  2119. $item = array (
  2120. 'rtid' => $rtid,
  2121. 'trainName' => $trainName,
  2122. 'trainStartDate' => $trainStartDate,
  2123. 'trainEndDate' => $trainEndDate,
  2124. 'participants' => $participants,
  2125. 'trainAddress' => $trainAddress,
  2126. 'trainRemarks' => $trainRemarks
  2127. );
  2128. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2129. // 报销单
  2130. $receipt->rid = $rid;
  2131. $receipt->cid = $cid;
  2132. $receipt->verify = $verify;
  2133. $receipt->remittanceName = $remittanceName;
  2134. $receipt->bankName = $bankName;
  2135. $receipt->bankNumber = $bankNumber;
  2136. $receipt->remittanceBankType = $remittanceBankType;
  2137. if ($remittanceBankType == 1)
  2138. $receipt->coupletNumber = $coupletNumber;
  2139. $receipt->update ();
  2140. $XDeode = new XDeode ( 7 );
  2141. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2142. } else
  2143. die ( 'illegal request' );
  2144. }
  2145. /**
  2146. * 编辑培训班结算---更新借款
  2147. */
  2148. function receiptTrainLoanEdiDo() {
  2149. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2150. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2151. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2152. Doo::loadModel ( 'receipt' );
  2153. $receipt = new receipt ();
  2154. Doo::loadClass ( 'XDeode' );
  2155. $XDeode = new XDeode ( 5 );
  2156. $rid = $XDeode->decode ( $ridKey );
  2157. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2158. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2159. die ( 'illegal request-ridError' );
  2160. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2161. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2162. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2163. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2164. die ( 'illegal request-receiptError' );
  2165. }
  2166. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2167. die ( 'illegal request-receipLoantError' );
  2168. }
  2169. // 培训班结算挂钩借款
  2170. $receipt = new receipt ();
  2171. $item = array (
  2172. 'rid' => $rid,
  2173. 'trainLoanRid' => $ridLoan
  2174. );
  2175. $receipt->setReceiptByCondition ( $item );
  2176. // 更新借款状态变成已挂钩
  2177. $receipt = new receipt ();
  2178. $item = array (
  2179. 'rid' => $ridLoan,
  2180. 'status' => 10,
  2181. 'statusTrain' => 1
  2182. );
  2183. $receipt->setReceiptByCondition ( $item );
  2184. $XDeode = new XDeode ( 7 );
  2185. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2186. } else
  2187. die ( 'illegal request' );
  2188. }
  2189. /**
  2190. * 编辑培训班结算--移除借款
  2191. */
  2192. function receiptTrainLoanRemoveDo() {
  2193. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2194. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2195. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2196. Doo::loadModel ( 'receipt' );
  2197. $receipt = new receipt ();
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $rid = $XDeode->decode ( $ridKey );
  2201. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2202. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2203. die ( 'illegal request-ridError' );
  2204. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2205. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2206. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2207. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2208. die ( 'illegal request-receiptError' );
  2209. }
  2210. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2211. die ( 'illegal request-receipLoantError' );
  2212. }
  2213. // 培训班结算挂钩借款
  2214. $receipt = new receipt ();
  2215. $item = array (
  2216. 'rid' => $rid,
  2217. 'trainLoanRid' => 0
  2218. );
  2219. $receipt->setReceiptByCondition ( $item );
  2220. // 更新借款状态变成已挂钩
  2221. $receipt = new receipt ();
  2222. $item = array (
  2223. 'rid' => $ridLoan,
  2224. 'status' => 8,
  2225. 'statusTrain' => 0
  2226. );
  2227. $receipt->setReceiptByCondition ( $item );
  2228. $XDeode = new XDeode ( 7 );
  2229. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2230. } else
  2231. die ( 'illegal request' );
  2232. }
  2233. /**
  2234. * 编辑培训班结算 ---开票
  2235. */
  2236. function receiptTrainInvoiceEdi() {
  2237. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2238. Doo::loadClass ( 'XDeode' );
  2239. $XDeode = new XDeode ( 7 );
  2240. $rid = $XDeode->decode ( $ridKey );
  2241. if (! is_numeric ( $rid ))
  2242. die ( 'illegal request' );
  2243. Doo::loadModel ( 'receipt' );
  2244. $receipt = new receipt ();
  2245. Doo::loadModel ( 'receiptTraining' );
  2246. $receiptTraining = new receiptTraining ();
  2247. Doo::loadModel ( 'invoice' );
  2248. $invoice = new invoice ();
  2249. Doo::loadModel ( 'invoiceTraining' );
  2250. $invoiceTraining = new invoiceTraining ();
  2251. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2252. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2253. die ();
  2254. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2255. $invoiceList = $invoiceTrainingDetail = array ();
  2256. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2257. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2258. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2259. }
  2260. //print_r($invoiceList);
  2261. $data ['invoiceList'] = $invoiceList;
  2262. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2263. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2264. $data ['receiptDetail'] = $receiptDetail;
  2265. $data ['trainEdiType'] = "INVOICE";
  2266. $data ['ridKey'] = $ridKey;
  2267. $data ['memu'] = "receipt";
  2268. $data ['staff'] = $this->staff;
  2269. $data ['receiptMemu'] = 'saeaBorad';
  2270. $data ['verifyId'] = $this->verifyId;
  2271. $data ['executeId'] = $this->executeId;
  2272. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2273. }
  2274. /**
  2275. * 编辑培训班结算---更新开票
  2276. */
  2277. function receiptTrainInvoiceEdiDo() {
  2278. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2279. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2280. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2281. Doo::loadModel ( 'receipt' );
  2282. $receipt = new receipt ();
  2283. Doo::loadModel ( 'invoiceTraining' );
  2284. $invoiceTraining = new invoiceTraining ();
  2285. Doo::loadClass ( 'XDeode' );
  2286. $XDeode = new XDeode ( 5 );
  2287. $rid = $XDeode->decode ( $ridKey );
  2288. $itid = $XDeode->decode ( $itidKey );
  2289. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2290. die ( 'illegal request-idError' );
  2291. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2292. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2293. // 不合法的数据
  2294. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2295. die ( 'illegal request-receiptError' );
  2296. }
  2297. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2298. die ( 'illegal request-receipLoantError' );
  2299. }
  2300. // 培训班结算挂钩借款
  2301. $receipt = new receipt ();
  2302. $item = array (
  2303. 'rid' => $rid,
  2304. 'invoiceTrainId' => $itid
  2305. );
  2306. $receipt->setReceiptByCondition ( $item );
  2307. $invoiceTraining = new invoiceTraining ();
  2308. $item = array (
  2309. 'bindReceipt' => 1,
  2310. 'itid' => $itid
  2311. );
  2312. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2313. $XDeode = new XDeode ( 7 );
  2314. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2315. } else
  2316. die ( 'illegal request' );
  2317. }
  2318. /**
  2319. * 更新培训班结算 收款和取消收款
  2320. */
  2321. function receiptTrainReceivables() {
  2322. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2323. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2324. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2325. Doo::loadClass ( 'XDeode' );
  2326. $XDeode = new XDeode ( 5 );
  2327. $rid = $XDeode->decode ( $ridKey );
  2328. $iid = $XDeode->decode ( $iidKey );
  2329. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2330. die ( 'illegal request-iid' );
  2331. Doo::loadModel ( 'RIExtend' );
  2332. $RIExtend = new RIExtend ();
  2333. if ($doType == 'CONFIRM') {
  2334. $RIExtend->rid = $rid;
  2335. $RIExtend->iid = $iid;
  2336. $RIExtend->RIstatus = 1;
  2337. $RIExtend->insert ();
  2338. echo json_encode ( array (
  2339. 'status' => 1,
  2340. ) );
  2341. die ( );
  2342. } elseif ($doType == 'CANCEL') {
  2343. $RIExtend->delete ( array (
  2344. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2345. 'limit' => 1
  2346. ) );
  2347. echo json_encode ( array (
  2348. 'status' => 1,
  2349. ) );
  2350. die ( );
  2351. } else {
  2352. echo json_encode ( array (
  2353. 'status' => 2,
  2354. ) );
  2355. die ( );
  2356. }
  2357. }
  2358. /**
  2359. * 移除挂钩的培训班发票
  2360. */
  2361. function receiptTrainReceivablesDelDo() {
  2362. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2363. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2364. Doo::loadModel ( 'receipt' );
  2365. $receipt = new receipt ();
  2366. Doo::loadModel ( 'RIExtend' );
  2367. $RIExtend = new RIExtend ();
  2368. Doo::loadClass ( 'XDeode' );
  2369. $XDeode = new XDeode ( 5 );
  2370. $rid = $XDeode->decode ( $ridKey );
  2371. $itid = $XDeode->decode ( $itidKey );
  2372. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2373. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2374. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2375. die ( 'illegal request-status' );
  2376. }
  2377. $receipt = new receipt ();
  2378. $receipt->rid = $rid;
  2379. $receipt->invoiceTrainId = 0;
  2380. $receipt->update ();
  2381. Doo::loadModel ( 'invoiceTraining' );
  2382. $invoiceTraining = new invoiceTraining ();
  2383. $item = array (
  2384. 'bindReceipt' => 0,
  2385. 'itid' => $itid
  2386. );
  2387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2388. $RIExtend->delete ( array (
  2389. 'where' => 'rid=' . $rid
  2390. ) );
  2391. $XDeode = new XDeode ( 7 );
  2392. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2393. } else
  2394. die ( 'illegal request-iid' );
  2395. }
  2396. /**
  2397. * 编辑培训班结算
  2398. */
  2399. function receiptTrainItemEdi() {
  2400. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2401. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2402. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2403. Doo::loadClass ( 'XDeode' );
  2404. $XDeode = new XDeode ( 7 );
  2405. $rid = $XDeode->decode ( $ridKey );
  2406. if (! is_numeric ( $rid ))
  2407. die ( 'illegal request' );
  2408. Doo::loadModel ( 'receipt' );
  2409. $receipt = new receipt ();
  2410. Doo::loadModel ( 'receiptTraining' );
  2411. $receiptTraining = new receiptTraining ();
  2412. Doo::loadModel ( 'RItem' );
  2413. $RItem = new RItem ();
  2414. Doo::loadModel ( 'accountItem' );
  2415. $accountItem = new accountItem ();
  2416. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2417. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2418. die ();
  2419. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2420. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2421. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2422. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2423. // if($value['name']=='税款'){
  2424. // unset($aiList[$key]);break;
  2425. // }
  2426. // }
  2427. //print_r($RItemList);
  2428. $data ['name'] = $name;
  2429. $data ['RItemList'] = $RItemList;
  2430. $data ['aiList'] = $aiList;
  2431. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2432. $data ['receiptDetail'] = $receiptDetail;
  2433. $data ['trainEdiType'] = "ITEM";
  2434. $data ['ridKey'] = $ridKey;
  2435. $data ['memu'] = "receipt";
  2436. $data ['staff'] = $this->staff;
  2437. $data ['receiptMemu'] = 'saeaBorad';
  2438. $data ['verifyId'] = $this->verifyId;
  2439. $data ['executeId'] = $this->executeId;
  2440. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2441. }
  2442. /**
  2443. * 添加支出项 需要修改 费用金额合计
  2444. */
  2445. function receiptTrainItemAddDo() {
  2446. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2447. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2448. // 支出项信息
  2449. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2450. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2451. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2452. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2453. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2454. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2455. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2456. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2457. Doo::loadClass ( 'XDeode' );
  2458. $XDeode = new XDeode ( 5 );
  2459. Doo::loadModel ( 'RItem' );
  2460. $RItem = new RItem ();
  2461. $rid = $XDeode->decode ( $ridKey );
  2462. $rtid= $XDeode->decode ( $rtidKey );
  2463. if (! is_numeric ( $rid )){
  2464. die ( 'illegal request' );
  2465. }
  2466. Doo::loadModel ( 'receiptDetail' );
  2467. $receiptDetail = new receiptDetail ();
  2468. Doo::loadModel ( 'receipt' );
  2469. $receipt = new receipt ();
  2470. Doo::loadModel ( 'receiptTraining' );
  2471. $receiptTraining = new receiptTraining ();
  2472. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2473. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2474. $order = array (
  2475. "\r\n",
  2476. "\n",
  2477. "\r"
  2478. );
  2479. $replace = '<br/>';
  2480. $describe = str_replace ( $order, $replace, $describe );
  2481. $itemData = array (
  2482. 'rid' => $rid,
  2483. 'item' => $item,
  2484. 'price' => $price,
  2485. 'date' => $date,
  2486. 'inputer' => $inputer,
  2487. 'describe' => $describe,
  2488. 'creater' => $this->staff['0']['username'],
  2489. 'createrId' => $this->staff['0']['sid'],
  2490. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2491. 'identifying'=>$identifyingTotal
  2492. );
  2493. if($payType=='company'){
  2494. $itemData += array (
  2495. 'payType' => 1
  2496. );
  2497. }
  2498. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2499. //更新支出项标识总数
  2500. $itemData = array (
  2501. 'rtid'=>$rtid,
  2502. 'identifyingTotal'=>$identifyingTotal
  2503. );
  2504. $receiptTraining->setReceiptTrainByCondition($itemData);
  2505. $XDeode = new XDeode ( 7 );
  2506. if($payType=='company'){
  2507. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2508. }else{
  2509. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2510. }
  2511. } else
  2512. die ( 'illegal request-dataError' );
  2513. }
  2514. /**
  2515. * 培训班结算-讲师
  2516. */
  2517. function receiptTrainLecturerEdi() {
  2518. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2519. Doo::loadClass ( 'XDeode' );
  2520. $XDeode = new XDeode ( 7 );
  2521. $rid = $XDeode->decode ( $ridKey );
  2522. if (! is_numeric ( $rid ))
  2523. die ( 'illegal request' );
  2524. Doo::loadModel ( 'receipt' );
  2525. $receipt = new receipt ();
  2526. Doo::loadModel ( 'receiptTraining' );
  2527. $receiptTraining = new receiptTraining ();
  2528. Doo::loadModel ( 'RILecturer' );
  2529. $RILecturer = new RILecturer ();
  2530. Doo::loadModel ( 'lecturer' );
  2531. $lecturer = new lecturer ();
  2532. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2533. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2534. die ();
  2535. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2536. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2537. $lecturerList = $lecturer->getLecturerAll ();
  2538. $INSIDEhtml = $OUTSIDEhtml = '';
  2539. foreach ( $lecturerList as $key => $value ) {
  2540. if ($value ['ltype'] == 'INSIDE') {
  2541. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2542. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2543. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2544. }
  2545. }
  2546. $data ['INSIDEhtml'] = $INSIDEhtml;
  2547. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2548. // print_r($RItemList);
  2549. $data ['RILecturerList'] = $RILecturerList;
  2550. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2551. $data ['receiptDetail'] = $receiptDetail;
  2552. $data ['trainEdiType'] = "LECTURER";
  2553. $data ['ridKey'] = $ridKey;
  2554. $data ['memu'] = "receipt";
  2555. $data ['staff'] = $this->staff;
  2556. $data ['receiptMemu'] = 'saeaBorad';
  2557. $data ['verifyId'] = $this->verifyId;
  2558. $data ['executeId'] = $this->executeId;
  2559. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2560. }
  2561. /**
  2562. * 添加讲师
  2563. */
  2564. function receiptTrainLecturerAddDo() {
  2565. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2566. // 支出项信息
  2567. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2568. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2569. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2570. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2571. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2572. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2573. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2574. Doo::loadClass ( 'XDeode' );
  2575. $XDeode = new XDeode ( 5 );
  2576. Doo::loadModel ( 'RILecturer' );
  2577. $RILecturer = new RILecturer ();
  2578. $rid = $XDeode->decode ( $ridKey );
  2579. if (! is_numeric ( $rid ))
  2580. die ( 'illegal request' );
  2581. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2582. die ( 'illegal request-taxationError' );
  2583. $RILecturer->rid = $rid;
  2584. $RILecturer->ltype = $ltype;
  2585. if ($ltype == 'OUTSIDE') {
  2586. if ($taxation == 'TAXATION') {
  2587. $RILecturer->taxation = 1;
  2588. } elseif ($taxation == 'NOTAXATION') {
  2589. $RILecturer->taxation = 0;
  2590. }
  2591. }
  2592. $RILecturer->lecturerName = $lecturerName;
  2593. $RILecturer->schoolDay = $schoolDay;
  2594. $RILecturer->price = $price;
  2595. $RILecturer->fees=$fees;
  2596. $RILecturer->insert ();
  2597. // 添加公司汇总
  2598. // 报销详情
  2599. Doo::loadModel ( 'receiptDetail' );
  2600. $receiptDetail = new receiptDetail ();
  2601. Doo::loadModel ( 'receipt' );
  2602. $receipt = new receipt ();
  2603. // 金额总计
  2604. $price = $price * $schoolDay;
  2605. $rInfo = $receipt->getReceiptByRid ( $rid );
  2606. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2607. if (empty ( $rdInfo )) {
  2608. $receiptDetail = new receiptDetail ();
  2609. $receiptDetail->staff = $rInfo ['staff'];
  2610. $receiptDetail->item = '讲课费';
  2611. $receiptDetail->itemCategory = '培训班费用';
  2612. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2613. $receiptDetail->date = date ( "Y-m-d" );
  2614. $receiptDetail->cid = $rInfo ['cid'];
  2615. $receiptDetail->rid = $rid;
  2616. $receiptDetail->status = 4;
  2617. $receiptDetail->insert ();
  2618. } else {
  2619. $receiptDetail = new receiptDetail ();
  2620. $rdInfo ['price'] += $fees;
  2621. $receiptDetail->price = $rdInfo ['price'];
  2622. $receiptDetail->update ( array (
  2623. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2624. ) );
  2625. }
  2626. $receipt = new receipt ();
  2627. $receipt->sum=$rInfo['sum']+$fees;
  2628. $receipt->update ( array (
  2629. 'where' => 'rid=' . $rid
  2630. ) );
  2631. $XDeode = new XDeode ( 7 );
  2632. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2633. } else
  2634. die ( 'illegal request' );
  2635. }
  2636. /**
  2637. * 移除讲师
  2638. */
  2639. function receiptTrainLecturerDelDo() {
  2640. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2641. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2642. Doo::loadModel ( 'receipt' );
  2643. $receipt = new receipt ();
  2644. Doo::loadModel ( 'RILecturer' );
  2645. $RILecturer = new RILecturer ();
  2646. Doo::loadClass ( 'XDeode' );
  2647. $XDeode = new XDeode ( 5 );
  2648. $rid = $XDeode->decode ( $ridKey );
  2649. $rlid = $XDeode->decode ( $rlidKey );
  2650. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2651. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2652. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2653. die ( 'illegal request-status' );
  2654. }
  2655. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2656. if (empty($detail)){
  2657. die ( 'illegal request-data' );
  2658. }
  2659. $RILecturer->delete ( array (
  2660. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2661. ) );
  2662. //更新费用合计金额
  2663. $rInfo = $receipt->getReceiptByRid ( $rid );
  2664. $receipt = new receipt ();
  2665. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2666. $receipt->update ( array (
  2667. 'where' => 'rid=' . $rid
  2668. ) );
  2669. Doo::loadModel ( 'receiptDetail' );
  2670. $receiptDetail = new receiptDetail ();
  2671. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2672. $receiptDetail = new receiptDetail ();
  2673. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2674. $receiptDetail->price = $rdInfo ['price'];
  2675. $receiptDetail->update ( array (
  2676. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2677. ) );
  2678. $XDeode = new XDeode ( 7 );
  2679. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2680. } else
  2681. die ( 'illegal request-iid' );
  2682. }
  2683. /**
  2684. * 培训班提交审批
  2685. */
  2686. function receiptTrainDo() {
  2687. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2688. Doo::loadClass ( 'XDeode' );
  2689. $XDeode = new XDeode ( 7 );
  2690. $rid = $XDeode->decode ( $ridKey );
  2691. Doo::loadModel ( 'receipt' );
  2692. $receipt = new receipt ();
  2693. Doo::loadModel ( 'receiptDetail' );
  2694. $receiptDetail = new receiptDetail ();
  2695. Doo::loadModel ( 'statistics' );
  2696. $statistics = new statistics ();
  2697. Doo::loadModel ( "verify" );
  2698. $verify = new verify ();
  2699. // 审批状态的判定
  2700. $receiptDetailList = $receipt->getOne ( array (
  2701. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2702. 'asArray' => true
  2703. ) );
  2704. if (empty ( $receiptDetailList ))
  2705. return "/saeaBorad";
  2706. $verifyDetail = $verify->getOne ( array (
  2707. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2708. 'asArray' => true
  2709. ) );
  2710. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2711. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2712. $nowStaff = "";
  2713. $nowStaffList = array ();
  2714. if ($verifyDetail [0] [1] == 'ROLE') {
  2715. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2716. foreach ( $vStaffString as $key => $value ) {
  2717. $staffK = explode ( "_", $value );
  2718. array_push ( $nowStaffList, $staffK [0] );
  2719. }
  2720. $nowStaff = implode ( ',', $nowStaffList );
  2721. } else {
  2722. $nowStaff = $verifyDetail [0] [0];
  2723. }
  2724. $receipt->nowStaff = $nowStaff;
  2725. }
  2726. // echo $nowStaff;
  2727. // print_r($verifyDetail);die;
  2728. $receipt->rid = $receiptDetailList ['rid'];
  2729. $receipt->date = date ( "Y-m-d" );
  2730. $receipt->status = 2;
  2731. $receipt->update ();
  2732. $receiptDetail->status = 2;
  2733. $receiptDetail->update ( array (
  2734. 'where' => 'rid=' . $receiptDetailList ['rid']
  2735. ) );
  2736. Doo::loadModel ( "receiptLog" );
  2737. $receiptLog = new receiptLog ();
  2738. Doo::loadModel ( "verify" );
  2739. $verify = new verify ();
  2740. $vr = $verify->getOne ( array (
  2741. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2742. 'asArray' => true
  2743. ) );
  2744. $jd = json_decode ( $vr ['staff'] );
  2745. $roleId = 0;
  2746. foreach ( $jd as $key => $value ) {
  2747. if ($value [1] == 'ROLE') {
  2748. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2749. if ($pos !== false) {
  2750. $roleId = $value [0];
  2751. }
  2752. }
  2753. }
  2754. // 审批日志
  2755. // echo $roleId;die;
  2756. if (! empty ( $roleId )) {
  2757. Doo::loadModel ( "role" );
  2758. $role = new role ();
  2759. $roleInfo = $role->getOne ( array (
  2760. 'where' => 'rid=' . $roleId,
  2761. 'asArray' => true
  2762. ) );
  2763. // $receiptLog->rolename = $roleInfo ['name'];
  2764. }
  2765. $receiptLog->username = $this->staff [0] ['username'];
  2766. $receiptLog->uid = $this->staff [0] ['sid'];
  2767. $receiptLog->date = date ( "Y-m-d" );
  2768. $receiptLog->opinion = '提交审批';
  2769. $receiptLog->img = $this->staff [0] ['avatar'];
  2770. $receiptLog->status = 2;
  2771. $receiptLog->rid = $rid;
  2772. $receiptLog->insert ();
  2773. // 写入列表项
  2774. Doo::loadModel ( 'accountItem' );
  2775. $accountItem = new accountItem ();
  2776. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2777. // 项目金额合计
  2778. Doo::loadModel ( 'RItem' );
  2779. $RItem = new RItem ();
  2780. // 讲师获得
  2781. Doo::loadModel ( 'RILecturer' );
  2782. $RILecturer = new RILecturer ();
  2783. $RItemList = $RItem->getRItemByRid ( $rid );
  2784. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2785. // 支出项金额详情
  2786. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2787. // print_r($aItem);
  2788. // print_r($aiData);
  2789. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2790. $ag = $tr = $ta = $ot = 0;
  2791. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2792. foreach ( $aItem as $key => $value ) {
  2793. if ($value ['category'] == $this->TRAIN) {
  2794. foreach ( $aiData ['dataList'] as $k => $v ) {
  2795. if ($value ['name'] == $v ['name']) {
  2796. array_push ( $accountJson [$this->TRAIN], array (
  2797. 'aid' => $value ['aid'],
  2798. 'name' => $value ['name'],
  2799. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2800. ) );
  2801. $sum += $v ['price'];
  2802. $trainSum += $v ['price'];
  2803. unset ( $aiData ['dataList'] [$k] );
  2804. break;
  2805. }
  2806. }
  2807. }
  2808. }
  2809. $accountJson ['cSum'] = array (
  2810. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2811. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2812. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2813. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2814. );
  2815. // 报销单
  2816. $receipt = new receipt ();
  2817. $receipt->accountItem = json_encode ( $accountJson );
  2818. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2819. $receipt->update ( array (
  2820. 'where' => 'rid=' . $rid
  2821. ) );
  2822. // print_r($accountJson);
  2823. // statistics item 统计写入
  2824. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2825. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2826. $accountItem = $accountJson;
  2827. $stat = $statistics->getOne ( array (
  2828. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2829. 'asArray' => true
  2830. ) );
  2831. if (empty ( $stat )) {
  2832. $statistics->date = date ( "Y-m-d" );
  2833. $statistics->cid = $this->staff [0] ['cid'];
  2834. $statistics->staff = $this->staff [0] ['sid'];
  2835. $statistics->agPrice = 0;
  2836. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2837. $statistics->insert ();
  2838. } else {
  2839. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2840. $statistics->update ( array (
  2841. 'where' => 'sid=' . $stat ['sid']
  2842. ) );
  2843. }
  2844. return "/saeaBorad";
  2845. }
  2846. function confirmation() {
  2847. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2848. Doo::loadModel ( 'receipt' );
  2849. Doo::loadModel ( 'receiptDetail' );
  2850. $receipt = new receipt ();
  2851. $receiptDetail = new receiptDetail ();
  2852. Doo::loadModel ( 'statistics' );
  2853. Doo::loadModel ( 'itemStatistics' );
  2854. $statistics = new statistics ();
  2855. $itemStatistics = new itemStatistics ();
  2856. Doo::loadModel ( "verify" );
  2857. $verify = new verify ();
  2858. $receiptDetailList = $receipt->getOne ( array (
  2859. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2860. 'asArray' => true
  2861. ) );
  2862. if (empty ( $receiptDetailList ))
  2863. return "/saeaBorad";
  2864. $verifyDetail = $verify->getOne ( array (
  2865. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2866. 'asArray' => true
  2867. ) );
  2868. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2869. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2870. $nowStaff = "";
  2871. $nowStaffList = array ();
  2872. if ($verifyDetail [0] [1] == 'ROLE') {
  2873. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2874. foreach ( $vStaffString as $key => $value ) {
  2875. $staffK = explode ( "_", $value );
  2876. array_push ( $nowStaffList, $staffK [0] );
  2877. }
  2878. $nowStaff = implode ( ',', $nowStaffList );
  2879. } else {
  2880. $nowStaff = $verifyDetail [0] [0];
  2881. }
  2882. $receipt->nowStaff = $nowStaff;
  2883. }
  2884. // echo $nowStaff;
  2885. // print_r($verifyDetail);die;
  2886. $receipt->rid = $receiptDetailList ['rid'];
  2887. $receipt->status = 2;
  2888. $receipt->update ();
  2889. // 操作日志
  2890. Doo::loadModel ( "receiptLog" );
  2891. $receiptLog = new receiptLog ();
  2892. $verify = new verify ();
  2893. $receiptInfo = $receipt->getOne ( array (
  2894. 'where' => 'rid=' . $rid,
  2895. 'asArray' => true
  2896. ) );
  2897. $vr = $verify->getOne ( array (
  2898. 'where' => 'vid=' . $receiptInfo ['verify'],
  2899. 'asArray' => true
  2900. ) );
  2901. $jd = json_decode ( $vr ['staff'] );
  2902. $roleId = 0;
  2903. foreach ( $jd as $key => $value ) {
  2904. if ($value [1] == 'ROLE') {
  2905. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2906. if ($pos !== false) {
  2907. $roleId = $value [0];
  2908. }
  2909. }
  2910. }
  2911. // 审批日志
  2912. // echo $roleId;die;
  2913. if (! empty ( $roleId )) {
  2914. Doo::loadModel ( "role" );
  2915. $role = new role ();
  2916. $roleInfo = $role->getOne ( array (
  2917. 'where' => 'rid=' . $roleId,
  2918. 'asArray' => true
  2919. ) );
  2920. // $receiptLog->rolename = $roleInfo ['name'];
  2921. }
  2922. $receiptLog->username = $this->staff [0] ['username'];
  2923. $receiptLog->uid = $this->staff [0] ['sid'];
  2924. $receiptLog->date = date ( "Y-m-d" );
  2925. $receiptLog->opinion = '提交审批';
  2926. $receiptLog->img = $this->staff [0] ['avatar'];
  2927. $receiptLog->status = 2;
  2928. $receiptLog->rid = $rid;
  2929. $receiptLog->insert ();
  2930. return "/expenses";
  2931. }
  2932. function expenses() {
  2933. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2934. if (empty ( $item ))
  2935. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2936. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2937. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2938. Doo::loadClass ( 'XDeode' );
  2939. $XDeode = new XDeode ( 7 );
  2940. Doo::loadModel ( 'receipt' );
  2941. $receipt = new receipt ();
  2942. Doo::loadModel ( 'L_category' );
  2943. $Lcategory = new L_category ();
  2944. Doo::loadModel ( 'verify' );
  2945. Doo::loadModel ( 'statistics' );
  2946. $statistics = new statistics ();
  2947. $verify = new verify ();
  2948. Doo::loadModel ( 'staff' );
  2949. $staff = new staff ();
  2950. $condition = "";
  2951. if ($item == "expenses")
  2952. $condition = " and Rtype=1 ";
  2953. elseif ($item == "receipts")
  2954. $condition = " and Rtype=0 ";
  2955. elseif ($item == "remits")
  2956. $condition = " and Rtype=2 ";
  2957. elseif ($item == "train")
  2958. $condition = " and Rtype=3 ";
  2959. $dateCondition = " and Year(date) =" . $year;
  2960. if (! empty ( $moth )) {
  2961. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2962. $stList = $statistics->getOne ( array (
  2963. 'select' => 'rePrice ,agPrice',
  2964. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2965. 'asArray' => true
  2966. ) );
  2967. } else
  2968. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2969. if (empty ( $stList ))
  2970. $stList = array (
  2971. 'rePrice' => 0,
  2972. 'agPrice' => 0
  2973. );
  2974. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2975. if (! isset ( $noPassSum ['sum'] ))
  2976. $noPassSum ['sum'] = 0;
  2977. $data ['stList'] = array (
  2978. 'rePrice' => $stList ['rePrice'],
  2979. 'agPrice' => $stList ['agPrice'],
  2980. 'skPrice' => ($noPassSum ['sum'])
  2981. );
  2982. $receiptList = $receipt->find ( array (
  2983. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2984. 'desc' => 'rid',
  2985. 'asArray' => true
  2986. ) );
  2987. $Locate = 0;
  2988. $roleId = 0;
  2989. $button = 0;
  2990. foreach ( $receiptList as $key => $value ) {
  2991. $receiptList [$key] ['Locate'] = $Locate;
  2992. $Locate ++;
  2993. $receiptList [$key] ['reviseDetail'] = array ();
  2994. if (! empty ( $value ['reviseDetail'] ))
  2995. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2996. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2997. $categoryDetil = $Lcategory->getOne ( array (
  2998. 'where' => 'cid=' . $value ['cid'],
  2999. 'asArray' => true
  3000. ) );
  3001. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3002. // 检测编辑状态
  3003. $verifyList = $verify->getOne ( array (
  3004. 'where' => 'vid=' . $value ['verify'],
  3005. 'asArray' => true
  3006. ) );
  3007. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3008. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3009. Doo::loadModel ( 'role' );
  3010. $role = new role ();
  3011. $flag = true;
  3012. $roleKey = 0;
  3013. $endStaffArray = array ();
  3014. $roleArrayCopy = array ();
  3015. foreach ( $verifyList as $k => $v ) {
  3016. // init verifyStaff
  3017. if ($v [1] == 'ROLE') {
  3018. if (! empty ( $verifyStaff )) {
  3019. $endStaffArray = end ( $verifyStaff );
  3020. // if ($v[0]==$endStaffArray['nextStaff']){
  3021. // $roleId=$v[0];
  3022. // }
  3023. }
  3024. $roleVerify = json_decode ( $v [3], true );
  3025. $roleKey = $k;
  3026. $roleArray = array ();
  3027. $rolename = $role->getOne ( array (
  3028. 'where' => 'rid=' . $v [0],
  3029. 'asArray' => true
  3030. ) );
  3031. foreach ( $roleVerify as $o => $p ) {
  3032. $staffID = explode ( '_', $p );
  3033. $staffInfo = $staff->getOne ( array (
  3034. 'where' => 'sid=' . $staffID [0],
  3035. 'asArray' => true
  3036. ) );
  3037. // print_r($staffID);
  3038. $exp = array (
  3039. 0 => $staffInfo ['sid'],
  3040. 1 => $staffID [1],
  3041. 2 => $staffInfo ['avatar'],
  3042. 'date' => '',
  3043. 'date' => '',
  3044. 'opinion' => '',
  3045. 'status' => '',
  3046. 'rolename' => $rolename ['name']
  3047. );
  3048. array_push ( $roleArray, $exp );
  3049. }
  3050. $roleArrayCopy [$v [0]] = $roleArray;
  3051. // $verifyList[$k]['roleArray']=$roleArray;
  3052. }
  3053. $verifyList [$k] ['date'] = "";
  3054. $verifyList [$k] ['opinion'] = "";
  3055. $verifyList [$k] ['status'] = "";
  3056. if (empty ( $verifyStaff )) {
  3057. $verifyList [$k] ['date'] = "";
  3058. $verifyList [$k] ['opinion'] = "";
  3059. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3060. $verifyList [$k] ['status'] = 4;
  3061. $flag = false;
  3062. }
  3063. } else {
  3064. foreach ( $verifyStaff as $m => $u ) {
  3065. if ($v [0] == $m) {
  3066. $verifyList [$k] ['date'] = $u ['date'];
  3067. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3068. $verifyList [$k] ['status'] = $u ['status'];
  3069. $flag = false;
  3070. break;
  3071. }
  3072. }
  3073. $endStaffArray = end ( $verifyStaff );
  3074. if (isset ( $endStaffArray ['ROLE'] )) {
  3075. } else {
  3076. // $endKey=key($verifyStaff);
  3077. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3078. // $button=4;
  3079. // $verifyList[$k]['status']=4;
  3080. // }
  3081. }
  3082. }
  3083. }
  3084. $rolename ['name'] = '';
  3085. if (! empty ( $roleId )) {
  3086. Doo::loadModel ( 'role' );
  3087. $role = new role ();
  3088. $rolename = $role->getOne ( array (
  3089. 'where' => 'rid=' . $roleId,
  3090. 'asArray' => true
  3091. ) );
  3092. }
  3093. if (! empty ( $verifyStaff ))
  3094. $endStaffArray = end ( $verifyStaff );
  3095. $KOP = false;
  3096. foreach ( $roleArrayCopy as $P => $A ) {
  3097. foreach ( $A as $MKI => $AVL ) {
  3098. if (! empty ( $verifyStaff )) {
  3099. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3100. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3101. $button = 4;
  3102. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3103. }
  3104. foreach ( $verifyStaff as $m => $u ) {
  3105. $AVLFK = $AVL [0] . '_R';
  3106. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3107. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3108. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3109. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3110. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3111. break;
  3112. }
  3113. }
  3114. } else {
  3115. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3116. $button = 4;
  3117. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3118. }
  3119. }
  3120. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3121. $KOP = true;
  3122. }
  3123. }
  3124. foreach ( $roleArrayCopy as $k => $v ) {
  3125. foreach ( $verifyList as $m => $n ) {
  3126. if ($n [0] == $k) {
  3127. array_splice ( $verifyList, $m, 1, $v );
  3128. }
  3129. }
  3130. }
  3131. $receiptList [$key] ['verifyList'] = $verifyList;
  3132. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3133. 'where' => 'sid=' . $value ['staff'],
  3134. 'asArray' => true
  3135. ) );
  3136. $receiptList [$key] ['button'] = $button;
  3137. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3138. }
  3139. // print_r($receiptList);die;
  3140. $mothHtml = "";
  3141. for($i = 1; $i <= 12; $i ++) {
  3142. if ($moth == $i)
  3143. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3144. else
  3145. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3146. }
  3147. $dateHtml = "";
  3148. $now = date ( "Y" );
  3149. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3150. if ($YEARD <= $now) {
  3151. $dateHtml .= '<option ';
  3152. if ($year == $YEARD) {
  3153. $dateHtml .= 'selected ';
  3154. }
  3155. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3156. }
  3157. }
  3158. $data ['dateHtml'] = $dateHtml;
  3159. $data ['mothHtml'] = $mothHtml;
  3160. $data ['receiptList'] = $receiptList;
  3161. $data ['memu'] = "receipt";
  3162. $data ['staff'] = $this->staff;
  3163. $data ['receiptMemu'] = 'expenses';
  3164. $data ['verifyId'] = $this->verifyId;
  3165. $data ['executeId'] = $this->executeId;
  3166. $data ['item'] = $item;
  3167. $data ['year'] = $year;
  3168. $this->render ( "/admin/expenses", $data );
  3169. }
  3170. function expensesCollect() {
  3171. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3172. Doo::loadModel ( 'receipt' );
  3173. $receipt = new receipt ();
  3174. Doo::loadModel ( 'L_category' );
  3175. $Lcategory = new L_category ();
  3176. Doo::loadModel ( 'verify' );
  3177. Doo::loadModel ( 'statistics' );
  3178. $statistics = new statistics ();
  3179. $verify = new verify ();
  3180. Doo::loadModel ( 'staff' );
  3181. $staff = new staff ();
  3182. Doo::loadModel ( 'loanReceipt' );
  3183. $loanReceipt = new loanReceipt ();
  3184. $receiptList = $receipt->find ( array (//去掉
  3185. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3186. 'desc' => 'rid',
  3187. 'asArray' => true
  3188. ) );
  3189. $loanList = $loanReceipt->find ( array (
  3190. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3191. 'desc' => 'rid',
  3192. 'asArray' => true
  3193. ) );
  3194. /*
  3195. * $Locate=0;$roleId=0;$button=0; foreach ($loanList as $key=>$value){ $loanList[$key]['Locate']=$Locate;$Locate++; $loanList[$key]['reviseDetail']=array(); if (!empty($value['reviseDetail'])) $loanList[$key]['reviseDetail']=json_decode($value['reviseDetail'],true); $loanList[$key]['accountItem']=json_decode($value['accountItem'],true); $loanList[$key]['loanItem']=json_decode($value['loanItem'],true); $categoryDetil=$Lcategory->getOne(array('where'=>'cid='.$value['cid'],'asArray'=>true)); $loanList[$key]['category']=$categoryDetil['title']; //检测编辑状态 if ($value['status']==3||$value['status']==1||$value['status']==8||$value['status']==9) $verifyList['staff']=$value['verifyBreakup']; else $verifyList=$verify->getOne(array('where'=>'vid='.$value['verify'],'asArray'=>true)); $verifyList=json_decode($verifyList['staff'],true);//status opinion $verifyStaff=json_decode($value['verifyStaff'],true); Doo::loadModel('role'); $role=new role(); $flag=true;$roleKey=0;$endStaffArray=array();$roleArrayCopy=array(); foreach ($verifyList as $k=>$v){ //init verifyStaff if ($v[1]=='ROLE'){ if (!empty($verifyStaff)){ $endStaffArray=end($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']){ // $roleId=$v[0]; // } } $roleVerify=json_decode($v[3],true); $roleKey=$k;$roleArray=array(); $rolename=$role->getOne(array('where'=>'rid='.$v[0],'asArray'=>true)); foreach ($roleVerify as $o=>$p){ $staffID=explode ('_',$p); $staffInfo=$staff->getOne(array('where'=>'sid='.$staffID[0],'asArray'=>true)); //print_r($staffID); $exp=array(0=>$staffInfo['sid'],1=>$staffID[1],2=>$staffInfo['avatar'],'date'=>'','date'=>'','opinion'=>'','status'=>'','rolename'=>$rolename['name']); array_push($roleArray, $exp); } $roleArrayCopy[$v[0]]=$roleArray; //$verifyList[$k]['roleArray']=$roleArray; } $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; $verifyList[$k]['status']=""; if (empty($verifyStaff)){ $verifyList[$k]['date']=""; $verifyList[$k]['opinion']=""; if (($verifyList[0][0]==$this->staff[0]['sid'])&&$flag){ $verifyList[$k]['status']=4; $flag=false; } }else{ foreach ($verifyStaff as $m=>$u){ if ($v[0]==$m){ $verifyList[$k]['date']=$u['date']; $verifyList[$k]['opinion']=$u['opinion']; $verifyList[$k]['status']=$u['status']; $flag=false; break; } } $endStaffArray=end($verifyStaff); if (isset($endStaffArray['ROLE'])){ }else{ // $endKey=key($verifyStaff); // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){ // $button=4; // $verifyList[$k]['status']=4; // } } } } $rolename['name']=''; if (!empty($roleId)){ Doo::loadModel('role'); $role=new role(); $rolename=$role->getOne(array('where'=>'rid='.$roleId,'asArray'=>true)); } if (!empty($verifyStaff)) $endStaffArray=end($verifyStaff); $KOP=false; foreach ($roleArrayCopy as $P=>$A){ foreach ( $A as $MKI=>$AVL){ if (!empty($verifyStaff)){ //&&$rolename['rid']==$endStaffArray['nextStaff'] if ($this->staff[0]['sid']==$AVL[0]&&isset($endStaffArray['ROLE'])&&$rolename['rid']==$endStaffArray['nextStaff']){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } foreach ($verifyStaff as $m=>$u){ $AVLFK=$AVL[0].'_R'; //echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>'; if (strcmp($AVLFK,$m)==0){//&&isset($u['ROLE'])&&$u['ROLE']==1 $roleArrayCopy[$P][$MKI]['date']=$u['date']; $roleArrayCopy[$P][$MKI]['opinion']=$u['opinion']; $roleArrayCopy[$P][$MKI]['status']=$u['status']; break; } } }else{ if ($this->staff[0]['sid']==$AVL[0]&&$verifyList[0][1]=='ROLE'){ $button=4; $roleArrayCopy[$P][$MKI]['status']=4; } } //$roleArray[$MKI]['rolename']=$rolename['name']; $KOP=true; } } foreach ($roleArrayCopy as $k=>$v){ foreach ($verifyList as $m=>$n){ if ($n[0]==$k){ array_splice($verifyList,$m,1,$v); } } } $loanList[$key]['verifyList']=$verifyList; $loanList[$key]['staffDetail']=$staff->getOne(array('where'=>'sid='.$value['staff'],'asArray'=>true)); $loanList[$key]['button']=$button; //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']); } $data['loanList']=$loanList;
  3196. */
  3197. $data ['explanation'] = '';
  3198. if (! empty ( $loanList ))
  3199. $data ['explanation'] = $loanList [0] ['explanation'];
  3200. $Locate = 0;
  3201. $roleId = 0;
  3202. $button = 0;
  3203. foreach ( $receiptList as $key => $value ) {
  3204. $receiptList [$key] ['Locate'] = $Locate;
  3205. $Locate ++;
  3206. $receiptList [$key] ['reviseDetail'] = array ();
  3207. if (! empty ( $value ['reviseDetail'] ))
  3208. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3209. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3210. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3211. $categoryDetil = $Lcategory->getOne ( array (
  3212. 'where' => 'cid=' . $value ['cid'],
  3213. 'asArray' => true
  3214. ) );
  3215. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3216. // 检测编辑状态
  3217. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3218. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3219. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3220. else
  3221. $verifyList ['staff'] = $value ['verifyBreakup'];
  3222. } else
  3223. $verifyList = $verify->getOne ( array (
  3224. 'where' => 'vid=' . $value ['verify'],
  3225. 'asArray' => true
  3226. ) );
  3227. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3228. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3229. Doo::loadModel ( 'role' );
  3230. $role = new role ();
  3231. $flag = true;
  3232. $roleKey = 0;
  3233. $endStaffArray = array ();
  3234. $roleArrayCopy = array ();
  3235. foreach ( $verifyList as $k => $v ) {
  3236. // init verifyStaff
  3237. if ($v [1] == 'ROLE') {
  3238. if (! empty ( $verifyStaff )) {
  3239. $endStaffArray = end ( $verifyStaff );
  3240. // if ($v[0]==$endStaffArray['nextStaff']){
  3241. // $roleId=$v[0];
  3242. // }
  3243. }
  3244. $roleVerify = json_decode ( $v [3], true );
  3245. $roleKey = $k;
  3246. $roleArray = array ();
  3247. $rolename = $role->getOne ( array (
  3248. 'where' => 'rid=' . $v [0],
  3249. 'asArray' => true
  3250. ) );
  3251. foreach ( $roleVerify as $o => $p ) {
  3252. $staffID = explode ( '_', $p );
  3253. $staffInfo = $staff->getOne ( array (
  3254. 'where' => 'sid=' . $staffID [0],
  3255. 'asArray' => true
  3256. ) );
  3257. // print_r($staffID);
  3258. $exp = array (
  3259. 0 => $staffInfo ['sid'],
  3260. 1 => $staffID [1],
  3261. 2 => $staffInfo ['avatar'],
  3262. 'date' => '',
  3263. 'date' => '',
  3264. 'opinion' => '',
  3265. 'status' => '',
  3266. 'rolename' => $rolename ['name']
  3267. );
  3268. array_push ( $roleArray, $exp );
  3269. }
  3270. $roleArrayCopy [$v [0]] = $roleArray;
  3271. // $verifyList[$k]['roleArray']=$roleArray;
  3272. }
  3273. $verifyList [$k] ['date'] = "";
  3274. $verifyList [$k] ['opinion'] = "";
  3275. $verifyList [$k] ['status'] = "";
  3276. if (empty ( $verifyStaff )) {
  3277. $verifyList [$k] ['date'] = "";
  3278. $verifyList [$k] ['opinion'] = "";
  3279. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3280. $verifyList [$k] ['status'] = 4;
  3281. $flag = false;
  3282. }
  3283. } else {
  3284. foreach ( $verifyStaff as $m => $u ) {
  3285. if ($v [0] == $m) {
  3286. $verifyList [$k] ['date'] = $u ['date'];
  3287. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3288. $verifyList [$k] ['status'] = $u ['status'];
  3289. $flag = false;
  3290. break;
  3291. }
  3292. }
  3293. $endStaffArray = end ( $verifyStaff );
  3294. if (isset ( $endStaffArray ['ROLE'] )) {
  3295. } else {
  3296. // $endKey=key($verifyStaff);
  3297. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3298. // $button=4;
  3299. // $verifyList[$k]['status']=4;
  3300. // }
  3301. }
  3302. }
  3303. }
  3304. $rolename ['name'] = '';
  3305. if (! empty ( $roleId )) {
  3306. Doo::loadModel ( 'role' );
  3307. $role = new role ();
  3308. $rolename = $role->getOne ( array (
  3309. 'where' => 'rid=' . $roleId,
  3310. 'asArray' => true
  3311. ) );
  3312. }
  3313. if (! empty ( $verifyStaff ))
  3314. $endStaffArray = end ( $verifyStaff );
  3315. $KOP = false;
  3316. foreach ( $roleArrayCopy as $P => $A ) {
  3317. foreach ( $A as $MKI => $AVL ) {
  3318. if (! empty ( $verifyStaff )) {
  3319. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3320. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3321. $button = 4;
  3322. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3323. }
  3324. foreach ( $verifyStaff as $m => $u ) {
  3325. $AVLFK = $AVL [0] . '_R';
  3326. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3327. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3328. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3329. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3330. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3331. break;
  3332. }
  3333. }
  3334. } else {
  3335. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3336. $button = 4;
  3337. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3338. }
  3339. }
  3340. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3341. $KOP = true;
  3342. }
  3343. }
  3344. foreach ( $roleArrayCopy as $k => $v ) {
  3345. foreach ( $verifyList as $m => $n ) {
  3346. if ($n [0] == $k) {
  3347. array_splice ( $verifyList, $m, 1, $v );
  3348. }
  3349. }
  3350. }
  3351. // 费用执行人相关数据
  3352. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3353. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3354. foreach ( $executeCopy as $k => $v ) {
  3355. $executeCopy [$k] ['date'] = '';
  3356. $executeCopy [$k] ['opinion'] = '';
  3357. $executeCopy [$k] ['status'] = '';
  3358. if (! empty ( $executeStaff ))
  3359. foreach ( $executeStaff as $m => $u ) {
  3360. if ($v [0] == $m) {
  3361. $executeCopy [$k] ['date'] = $u ['date'];
  3362. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3363. $executeCopy [$k] ['status'] = $u ['status'];
  3364. break;
  3365. }
  3366. }
  3367. }
  3368. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3369. $receiptList [$key] ['verifyList'] = $verifyList;
  3370. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3371. 'where' => 'sid=' . $value ['staff'],
  3372. 'asArray' => true
  3373. ) );
  3374. $receiptList [$key] ['button'] = $button;
  3375. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3376. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3377. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3378. $receiptList [$key] ['relust'] = $relust;
  3379. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3380. }
  3381. Doo::loadModel ( 'enclosur' );
  3382. $enclosur = new enclosur ();
  3383. $enclosurList = $enclosur->find ( array (
  3384. 'where' => 'rid=' . $rid,
  3385. 'asArray' => true
  3386. ) );
  3387. $enclosurHtml = '';
  3388. foreach ( $enclosurList as $value ) {
  3389. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3390. }
  3391. $data ['enclosurHtml'] = $enclosurHtml;
  3392. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3393. $data ['receiptList'] = $receiptList;
  3394. $data ['memu'] = "receipt";
  3395. $data ['staff'] = $this->staff;
  3396. $data ['receiptMemu'] = 'expenses';
  3397. $data ['verifyId'] = $this->verifyId;
  3398. $data ['executeId'] = $this->executeId;
  3399. $this->render ( "/admin/expensesCollect", $data );
  3400. }
  3401. function approvalExpenses() {
  3402. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3403. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3404. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3405. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3406. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3407. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3408. // echo $rdate;
  3409. if (empty ( $status ))
  3410. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3411. $page_size = 8;
  3412. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3413. $vidList = array ();
  3414. $button = 0;
  3415. Doo::loadModel ( 'verify' );
  3416. $verify = new verify ();
  3417. Doo::loadModel ( 'receipt' );
  3418. $receipt = new receipt ();
  3419. Doo::loadModel ( 'staff' );
  3420. $staff = new staff ();
  3421. Doo::loadModel ( 'L_category' );
  3422. $Lcategory = new L_category ();
  3423. // user verify ID
  3424. $verifyDetail = $verify->find ( array (
  3425. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3426. 'asArray' => true
  3427. ) );
  3428. foreach ( $verifyDetail as $key => $value ) {
  3429. array_push ( $vidList, $value ['vid'] );
  3430. }
  3431. $vid = implode ( ",", $vidList );
  3432. if (empty ( $verifyDetail ))
  3433. $vid = 0;
  3434. // if ($status==0)
  3435. // $dateCondition="";
  3436. // else
  3437. $dateCondition = " ";
  3438. // if (! empty ( $month ))
  3439. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3440. if ($status == 'done' || $status == 'termination') {
  3441. if (! empty ( $year )) {
  3442. $dateCondition = " and Year(pastDate) =" . $year;
  3443. if (! empty ( $month ))
  3444. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3445. }
  3446. } elseif ($status == 'finish') {
  3447. if (! empty ( $year )) {
  3448. $dateCondition = " and Year(pastDate) =" . $year;
  3449. if (! empty ( $month ))
  3450. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3451. }
  3452. }
  3453. // date ( 'Y-m' )
  3454. // if (! empty ( $rdate ) && $status == 'done')
  3455. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3456. // elseif (! empty ( $rdate ))
  3457. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3458. $categoryList = $Lcategory->find ( array (
  3459. 'asArray' => true
  3460. ) );
  3461. $staffList = $staff->find ( array (
  3462. 'where' => 'cid=' . $cid,
  3463. 'asArray' => true
  3464. ) );
  3465. $cateCondition = "";
  3466. $staffCondition = "";
  3467. $approvalCondition = "";
  3468. if (! empty ( $cid )) {
  3469. $cateCondition = ' and cid=' . $cid;
  3470. }
  3471. if (! empty ( $sid )) {
  3472. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3473. $cateCondition = "";
  3474. }
  3475. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3476. if ($status == 'pendApproval') {
  3477. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3478. }
  3479. if ($status == 'ongoing') {
  3480. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3481. }
  3482. if ($status == 'done') {
  3483. $approvalCondition = ' and (status=8 or status=9 ) ';
  3484. }
  3485. if ($status == 'termination') {
  3486. $approvalCondition = " and status=3";
  3487. }
  3488. if ($status == 'finish') {
  3489. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3490. }
  3491. $pageinfo ['page'] = array (
  3492. 'previous' => ''
  3493. );
  3494. if(!empty($receiptOrder)){
  3495. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3496. $receiptList = $receipt->find ( array ( // $dateCondition
  3497. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3498. 'desc' => 'rid',
  3499. 'asArray' => true
  3500. ) );
  3501. }else{
  3502. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3503. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3504. $receiptList = $receipt->find ( array ( // $dateCondition.
  3505. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3506. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3507. 'desc' => 'rid',
  3508. 'asArray' => true
  3509. ) );
  3510. } else {
  3511. $receiptList = $receipt->find ( array ( // $dateCondition
  3512. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3513. 'desc' => 'rid',
  3514. 'asArray' => true
  3515. ) );
  3516. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3517. }
  3518. }
  3519. $rLRes = $receipt->find ( array (
  3520. 'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )' . $cateCondition . $staffCondition . ' and verify in (' . $vid . ')',
  3521. 'desc' => 'rid',
  3522. 'asArray' => true
  3523. ) );
  3524. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3525. // print_r($receiptList);
  3526. Doo::loadClass ( 'XDeode' );
  3527. $XDeode = new XDeode ( 7 );
  3528. $Locate = 0;
  3529. $reportList = $reportCateList = array ();
  3530. foreach ( $receiptList as $key => $value ) {
  3531. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3532. $receiptList [$key] ['Locate'] = $Locate;
  3533. $Locate ++;
  3534. $receiptList [$key] ['reviseDetail'] = array ();
  3535. if (! empty ( $value ['reviseDetail'] ))
  3536. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3537. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3538. $categoryDetil = $Lcategory->getOne ( array (
  3539. 'where' => 'cid=' . $value ['cid'],
  3540. 'asArray' => true
  3541. ) );
  3542. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3543. $verifyList = $verify->getOne ( array (
  3544. 'where' => 'vid=' . $value ['verify'],
  3545. 'asArray' => true
  3546. ) );
  3547. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3548. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3549. foreach ( $verifyList as $k => $v ) {
  3550. // init verifyStaff
  3551. $verifyList [$k] ['date'] = "";
  3552. $verifyList [$k] ['opinion'] = "";
  3553. $verifyList [$k] ['status'] = "";
  3554. if (empty ( $verifyStaff )) {
  3555. $verifyList [$k] ['date'] = "";
  3556. $verifyList [$k] ['opinion'] = "";
  3557. if ($v [0] == $this->staff [0] ['sid']) {
  3558. $verifyList [$k] ['status'] = 4;
  3559. $button = 4;
  3560. }
  3561. } else {
  3562. $flag = true;
  3563. foreach ( $verifyStaff as $m => $u ) {
  3564. if ($v [0] == $m) {
  3565. $verifyList [$k] ['date'] = $u ['date'];
  3566. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3567. $verifyList [$k] ['status'] = $u ['status'];
  3568. $flag = false;
  3569. break;
  3570. }
  3571. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3572. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3573. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3574. }
  3575. if ($flag) { // 检测可编辑
  3576. if ($v [0] == $this->staff [0] ['sid']) {
  3577. $verifyList [$k] ['status'] = 4;
  3578. $button = 4;
  3579. }
  3580. }
  3581. }
  3582. }
  3583. $receiptList [$key] ['verifyList'] = $verifyList;
  3584. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3585. 'where' => 'sid=' . $value ['staff'],
  3586. 'asArray' => true
  3587. ) );
  3588. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3589. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3590. $receiptList [$key] ['button'] = $button;
  3591. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3592. }
  3593. $reportList = array_unique ( $reportList );
  3594. $reportHtml = '';
  3595. foreach ( $reportList as $key => $value ) {
  3596. $v = explode ( "-", $value );
  3597. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3598. }
  3599. // print_r($reportList)
  3600. $data ['reportHtml'] = $reportHtml;
  3601. $reportCateList = array_unique ( $reportCateList );
  3602. $reportCateHtml = '';
  3603. foreach ( $reportCateList as $key => $value ) {
  3604. $v = explode ( "-", $value );
  3605. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3606. }
  3607. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3608. $data ['reportCateHtml'] = $reportCateHtml;
  3609. // print_r($receiptList);die;
  3610. // $data['verifyDetail']=$verifyDetail;
  3611. $mothHtml = "";
  3612. for($i = 1; $i <= 12; $i ++) {
  3613. if ($month == $i)
  3614. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3615. else
  3616. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3617. }
  3618. $data ['mothHtml'] = $mothHtml;
  3619. $dateHtml = "";
  3620. $now = date ( "Y" );
  3621. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3622. if ($YEARD <= $now) {
  3623. $dateHtml .= '<option ';
  3624. if ($year == $YEARD) {
  3625. $dateHtml .= 'selected ';
  3626. }
  3627. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3628. }
  3629. }
  3630. $data ['dateHtml'] = $dateHtml;
  3631. $data ['page'] = $pageinfo;
  3632. $data ['receiptList'] = $receiptList;
  3633. $data ['receiptApprovalCount'] = count ( $rLRes );
  3634. $data ['status'] = $status;
  3635. $data ['year'] = $year;
  3636. $data ['month'] = $month;
  3637. $data ['categoryList'] = $categoryList;
  3638. $data ['staffList'] = $staffList;
  3639. $data ['cid'] = $cid;
  3640. $data ['sid'] = $sid;
  3641. // print_r($receiptList);
  3642. $data['receiptOrder']=$receiptOrder;
  3643. $data ['memu'] = "receipt";
  3644. $data ['staff'] = $this->staff;
  3645. $data ['receiptMemu'] = 'approvalExpenses';
  3646. $data ['verifyId'] = $this->verifyId;
  3647. $data ['executeId'] = $this->executeId;
  3648. $this->render ( "/admin/approvalExpenses", $data );
  3649. }
  3650. function expensesDoc() {
  3651. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3652. Doo::loadClass ( 'XDeode' );
  3653. $XDeode = new XDeode ( 5 );
  3654. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3655. $rid = $XDeode->decode ( $rid );
  3656. if (! is_numeric ( $rid ))
  3657. die ( 'illegal request' );
  3658. Doo::loadModel ( 'receipt' );
  3659. $receipt = new receipt ();
  3660. Doo::loadModel ( 'L_category' );
  3661. $Lcategory = new L_category ();
  3662. Doo::loadModel ( 'verify' );
  3663. Doo::loadModel ( 'statistics' );
  3664. $statistics = new statistics ();
  3665. $verify = new verify ();
  3666. Doo::loadModel ( 'staff' );
  3667. $staff = new staff ();
  3668. Doo::loadModel ( 'loanReceipt' );
  3669. $loanReceipt = new loanReceipt ();
  3670. $receiptList = $receipt->find ( array (
  3671. 'where' => ' rid=' . $rid,
  3672. 'desc' => 'rid',
  3673. 'asArray' => true
  3674. ) );
  3675. $loanList = array ();
  3676. if (! empty ( $receiptList ))
  3677. $loanList = $loanReceipt->find ( array (
  3678. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3679. 'desc' => 'rid',
  3680. 'asArray' => true
  3681. ) );
  3682. $Locate = 0;
  3683. $roleId = 0;
  3684. $button = 0;
  3685. foreach ( $loanList as $key => $value ) {
  3686. $loanList [$key] ['Locate'] = $Locate;
  3687. $Locate ++;
  3688. $loanList [$key] ['reviseDetail'] = array ();
  3689. if (! empty ( $value ['reviseDetail'] ))
  3690. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3691. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3692. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3693. $categoryDetil = $Lcategory->getOne ( array (
  3694. 'where' => 'cid=' . $value ['cid'],
  3695. 'asArray' => true
  3696. ) );
  3697. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3698. // 检测编辑状态
  3699. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3700. $verifyList ['staff'] = $value ['verifyBreakup'];
  3701. else
  3702. $verifyList = $verify->getOne ( array (
  3703. 'where' => 'vid=' . $value ['verify'],
  3704. 'asArray' => true
  3705. ) );
  3706. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3707. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3708. Doo::loadModel ( 'role' );
  3709. $role = new role ();
  3710. $flag = true;
  3711. $roleKey = 0;
  3712. $endStaffArray = array ();
  3713. $roleArrayCopy = array ();
  3714. foreach ( $verifyList as $k => $v ) {
  3715. // init verifyStaff
  3716. if ($v [1] == 'ROLE') {
  3717. if (! empty ( $verifyStaff )) {
  3718. $endStaffArray = end ( $verifyStaff );
  3719. // if ($v[0]==$endStaffArray['nextStaff']){
  3720. // $roleId=$v[0];
  3721. // }
  3722. }
  3723. $roleVerify = json_decode ( $v [3], true );
  3724. $roleKey = $k;
  3725. $roleArray = array ();
  3726. $rolename = $role->getOne ( array (
  3727. 'where' => 'rid=' . $v [0],
  3728. 'asArray' => true
  3729. ) );
  3730. foreach ( $roleVerify as $o => $p ) {
  3731. $staffID = explode ( '_', $p );
  3732. $staffInfo = $staff->getOne ( array (
  3733. 'where' => 'sid=' . $staffID [0],
  3734. 'asArray' => true
  3735. ) );
  3736. // print_r($staffID);
  3737. $exp = array (
  3738. 0 => $staffInfo ['sid'],
  3739. 1 => $staffID [1],
  3740. 2 => $staffInfo ['avatar'],
  3741. 'date' => '',
  3742. 'date' => '',
  3743. 'opinion' => '',
  3744. 'status' => '',
  3745. 'rolename' => $rolename ['name']
  3746. );
  3747. array_push ( $roleArray, $exp );
  3748. }
  3749. $roleArrayCopy [$v [0]] = $roleArray;
  3750. // $verifyList[$k]['roleArray']=$roleArray;
  3751. }
  3752. $verifyList [$k] ['date'] = "";
  3753. $verifyList [$k] ['opinion'] = "";
  3754. $verifyList [$k] ['status'] = "";
  3755. if (empty ( $verifyStaff )) {
  3756. $verifyList [$k] ['date'] = "";
  3757. $verifyList [$k] ['opinion'] = "";
  3758. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3759. $verifyList [$k] ['status'] = 4;
  3760. $flag = false;
  3761. }
  3762. } else {
  3763. foreach ( $verifyStaff as $m => $u ) {
  3764. if ($v [0] == $m) {
  3765. $verifyList [$k] ['date'] = $u ['date'];
  3766. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3767. $verifyList [$k] ['status'] = $u ['status'];
  3768. $flag = false;
  3769. break;
  3770. }
  3771. }
  3772. $endStaffArray = end ( $verifyStaff );
  3773. if (isset ( $endStaffArray ['ROLE'] )) {
  3774. } else {
  3775. // $endKey=key($verifyStaff);
  3776. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3777. // $button=4;
  3778. // $verifyList[$k]['status']=4;
  3779. // }
  3780. }
  3781. }
  3782. }
  3783. $rolename ['name'] = '';
  3784. if (! empty ( $roleId )) {
  3785. Doo::loadModel ( 'role' );
  3786. $role = new role ();
  3787. $rolename = $role->getOne ( array (
  3788. 'where' => 'rid=' . $roleId,
  3789. 'asArray' => true
  3790. ) );
  3791. }
  3792. if (! empty ( $verifyStaff ))
  3793. $endStaffArray = end ( $verifyStaff );
  3794. $KOP = false;
  3795. foreach ( $roleArrayCopy as $P => $A ) {
  3796. foreach ( $A as $MKI => $AVL ) {
  3797. if (! empty ( $verifyStaff )) {
  3798. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3799. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3800. $button = 4;
  3801. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3802. }
  3803. foreach ( $verifyStaff as $m => $u ) {
  3804. $AVLFK = $AVL [0] . '_R';
  3805. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3806. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3807. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3808. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3809. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3810. break;
  3811. }
  3812. }
  3813. } else {
  3814. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3815. $button = 4;
  3816. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3817. }
  3818. }
  3819. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3820. $KOP = true;
  3821. }
  3822. }
  3823. foreach ( $roleArrayCopy as $k => $v ) {
  3824. foreach ( $verifyList as $m => $n ) {
  3825. if ($n [0] == $k) {
  3826. array_splice ( $verifyList, $m, 1, $v );
  3827. }
  3828. }
  3829. }
  3830. $loanList [$key] ['verifyList'] = $verifyList;
  3831. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3832. 'where' => 'sid=' . $value ['staff'],
  3833. 'asArray' => true
  3834. ) );
  3835. $loanList [$key] ['button'] = $button;
  3836. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3837. }
  3838. $data ['loanList'] = $loanList;
  3839. //print_r($loanList);
  3840. $Locate = 0;
  3841. $roleId = 0;
  3842. $button = 0;
  3843. foreach ( $receiptList as $key => $value ) {
  3844. $receiptList [$key] ['Locate'] = $Locate;
  3845. $Locate ++;
  3846. $receiptList [$key] ['reviseDetail'] = array ();
  3847. if (! empty ( $value ['reviseDetail'] ))
  3848. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3849. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3850. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3851. $categoryDetil = $Lcategory->getOne ( array (
  3852. 'where' => 'cid=' . $value ['cid'],
  3853. 'asArray' => true
  3854. ) );
  3855. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3856. // 检测编辑状态
  3857. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3858. $verifyList ['staff'] = $value ['verifyBreakup'];
  3859. } else
  3860. $verifyList = $verify->getOne ( array (
  3861. 'where' => 'vid=' . $value ['verify'],
  3862. 'asArray' => true
  3863. ) );
  3864. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3865. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3866. Doo::loadModel ( 'role' );
  3867. $role = new role ();
  3868. if ($verifyList == NULL)
  3869. $verifyList = array ();
  3870. $flag = true;
  3871. $roleKey = 0;
  3872. $endStaffArray = array ();
  3873. $roleArrayCopy = array ();
  3874. foreach ( $verifyList as $k => $v ) {
  3875. // init verifyStaff
  3876. if ($v [1] == 'ROLE') {
  3877. if (! empty ( $verifyStaff )) {
  3878. $endStaffArray = end ( $verifyStaff );
  3879. // if ($v[0]==$endStaffArray['nextStaff']){
  3880. // $roleId=$v[0];
  3881. // }
  3882. }
  3883. $roleVerify = json_decode ( $v [3], true );
  3884. $roleKey = $k;
  3885. $roleArray = array ();
  3886. $rolename = $role->getOne ( array (
  3887. 'where' => 'rid=' . $v [0],
  3888. 'asArray' => true
  3889. ) );
  3890. foreach ( $roleVerify as $o => $p ) {
  3891. $staffID = explode ( '_', $p );
  3892. $staffInfo = $staff->getOne ( array (
  3893. 'where' => 'sid=' . $staffID [0],
  3894. 'asArray' => true
  3895. ) );
  3896. // print_r($staffID);
  3897. $exp = array (
  3898. 0 => $staffInfo ['sid'],
  3899. 1 => $staffID [1],
  3900. 2 => $staffInfo ['avatar'],
  3901. 'date' => '',
  3902. 'date' => '',
  3903. 'opinion' => '',
  3904. 'status' => '',
  3905. 'rolename' => $rolename ['name']
  3906. );
  3907. array_push ( $roleArray, $exp );
  3908. }
  3909. $roleArrayCopy [$v [0]] = $roleArray;
  3910. // $verifyList[$k]['roleArray']=$roleArray;
  3911. }
  3912. $verifyList [$k] ['date'] = "";
  3913. $verifyList [$k] ['opinion'] = "";
  3914. $verifyList [$k] ['status'] = "";
  3915. if (empty ( $verifyStaff )) {
  3916. $verifyList [$k] ['date'] = "";
  3917. $verifyList [$k] ['opinion'] = "";
  3918. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3919. $verifyList [$k] ['status'] = 4;
  3920. $flag = false;
  3921. }
  3922. } else {
  3923. foreach ( $verifyStaff as $m => $u ) {
  3924. if ($v [0] == $m) {
  3925. $verifyList [$k] ['date'] = $u ['date'];
  3926. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3927. $verifyList [$k] ['status'] = $u ['status'];
  3928. $flag = false;
  3929. break;
  3930. }
  3931. }
  3932. $endStaffArray = end ( $verifyStaff );
  3933. if (isset ( $endStaffArray ['ROLE'] )) {
  3934. } else {
  3935. // $endKey=key($verifyStaff);
  3936. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3937. // $button=4;
  3938. // $verifyList[$k]['status']=4;
  3939. // }
  3940. }
  3941. }
  3942. }
  3943. $FC = @$rolename ['name'];
  3944. $rolename ['name'] = '';
  3945. if (! empty ( $roleId )) {
  3946. Doo::loadModel ( 'role' );
  3947. $role = new role ();
  3948. $rolename = $role->getOne ( array (
  3949. 'where' => 'rid=' . $roleId,
  3950. 'asArray' => true
  3951. ) );
  3952. }
  3953. if (! empty ( $verifyStaff ))
  3954. $endStaffArray = end ( $verifyStaff );
  3955. $KOP = false;
  3956. foreach ( $roleArrayCopy as $P => $A ) {
  3957. foreach ( $A as $MKI => $AVL ) {
  3958. if (! empty ( $verifyStaff )) {
  3959. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3960. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3961. $button = 4;
  3962. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3963. }
  3964. foreach ( $verifyStaff as $m => $u ) {
  3965. $AVLFK = $AVL [0] . '_R';
  3966. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3967. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3968. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3969. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3970. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3971. break;
  3972. }
  3973. }
  3974. } else {
  3975. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3976. $button = 4;
  3977. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3978. }
  3979. }
  3980. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3981. $KOP = true;
  3982. }
  3983. }
  3984. foreach ( $roleArrayCopy as $k => $v ) {
  3985. foreach ( $verifyList as $m => $n ) {
  3986. if ($n [0] == $k) {
  3987. array_splice ( $verifyList, $m, 1, $v );
  3988. }
  3989. }
  3990. }
  3991. // 费用执行人相关数据
  3992. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3993. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3994. foreach ( $executeCopy as $k => $v ) {
  3995. $executeCopy [$k] ['date'] = '';
  3996. $executeCopy [$k] ['opinion'] = '';
  3997. $executeCopy [$k] ['status'] = '';
  3998. if (! empty ( $executeStaff ))
  3999. foreach ( $executeStaff as $m => $u ) {
  4000. if ($v [0] == $m) {
  4001. $executeCopy [$k] ['date'] = $u ['date'];
  4002. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4003. $executeCopy [$k] ['status'] = $u ['status'];
  4004. break;
  4005. }
  4006. }
  4007. }
  4008. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4009. // print_r($verifyList);
  4010. $receiptList [$key] ['verifyList'] = $verifyList;
  4011. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4012. 'where' => 'sid=' . $value ['staff'],
  4013. 'asArray' => true
  4014. ) );
  4015. $receiptList [$key] ['button'] = $button;
  4016. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4017. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4018. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4019. $receiptList [$key] ['relust'] = $relust;
  4020. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4021. }
  4022. // print_r($receiptList);
  4023. // 获取审批日志
  4024. Doo::loadModel ( 'receiptLog' );
  4025. $receiptLog = new receiptLog ();
  4026. $rlList = array ();
  4027. $rlInfo = $receiptLog->getOne ( array (
  4028. 'where' => 'rid=' . $rid . ' and status=4',
  4029. 'asArray' => true
  4030. ) );
  4031. // $tijdate = $receiptLog->getOne ( array (
  4032. // 'where' => 'rid=' . $rid . ' and status=2',
  4033. // 'asc' => 'rlid',
  4034. // 'asArray' => true
  4035. // ) );
  4036. if (! empty ( $rlInfo )) {
  4037. $rlList = $receiptLog->find ( array (
  4038. 'where' => 'rid=' . $rid,
  4039. 'asc' => 'rlid',
  4040. 'asArray' => true
  4041. ) );
  4042. }
  4043. $RN=array();
  4044. if (!empty( $rolename ['staff'])){
  4045. $RN = @json_decode ( $rolename ['staff'] );
  4046. }
  4047. //
  4048. foreach ( $rlList as $key => $value ) {
  4049. $rlList [$key] ['rolename'] = '';
  4050. foreach ( $RN as $k => $v ) {
  4051. $id = explode ( "_", $v );
  4052. if ($id [0] == $value ['uid']) {
  4053. $rlList [$key] ['rolename'] = $FC;
  4054. break;
  4055. }
  4056. }
  4057. }
  4058. Doo::loadModel ( 'enclosur' );
  4059. $enclosur = new enclosur ();
  4060. $enclosurList = $enclosur->find ( array (
  4061. 'where' => 'rid=' . $rid,
  4062. 'asArray' => true
  4063. ) );
  4064. $enclosurHtml = '';
  4065. foreach ( $enclosurList as $value ) {
  4066. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4067. }
  4068. $data ['enclosurHtml'] = $enclosurHtml;
  4069. $receiptList [0] ['rlList'] = $rlList;
  4070. $data ['receiptList'] = $receiptList;
  4071. // print_r($receiptList);
  4072. $data ['memu'] = "receipt";
  4073. $data ['staff'] = $this->staff;
  4074. $data ['receiptMemu'] = 'approvalExpenses';
  4075. $data ['verifyId'] = $this->verifyId;
  4076. $data ['executeId'] = $this->executeId;
  4077. $this->render ( "/admin/expensesDoc", $data );
  4078. }
  4079. function expensesEdi() {
  4080. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4081. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4082. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4083. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4084. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4085. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4086. if (empty ( $status ))
  4087. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4088. $vidList = array ();
  4089. $button = 0;
  4090. Doo::loadModel ( 'verify' );
  4091. Doo::loadModel ( 'receipt' );
  4092. Doo::loadModel ( 'staff' );
  4093. $staff = new staff ();
  4094. $receipt = new receipt ();
  4095. $verify = new verify ();
  4096. Doo::loadModel ( 'L_category' );
  4097. $Lcategory = new L_category ();
  4098. Doo::loadModel ( 'enclosur' );
  4099. $enclosur = new enclosur ();
  4100. // user verify ID
  4101. $verifyDetail = $verify->find ( array (
  4102. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4103. 'asArray' => true
  4104. ) );
  4105. foreach ( $verifyDetail as $key => $value ) {
  4106. array_push ( $vidList, $value ['vid'] );
  4107. }
  4108. $vid = implode ( ",", $vidList );
  4109. if (empty ( $verifyDetail ))
  4110. $vid = 0;
  4111. $categoryList = $Lcategory->find ( array (
  4112. 'asArray' => true
  4113. ) );
  4114. $staffList = $staff->find ( array (
  4115. 'where' => 'cid=' . $cid,
  4116. 'asArray' => true
  4117. ) );
  4118. $ap = "";
  4119. if ($status == 4) {
  4120. $ap = 4;
  4121. $status = 2;
  4122. }
  4123. // get Receipt By verifyID status 2
  4124. $receiptList = $receipt->find ( array (
  4125. 'where' => 'rid =' . $rid . ' and status=2',
  4126. 'desc' => 'rid',
  4127. 'asArray' => true
  4128. ) );
  4129. if (empty ( $receiptList )) {
  4130. die ( 'illegal request' );
  4131. }
  4132. $Locate = 0;
  4133. $roleId = 0;
  4134. if ($ap == 4)
  4135. $status = 4;
  4136. foreach ( $receiptList as $key => $value ) {
  4137. $receiptList [$key] ['Locate'] = $Locate;
  4138. $Locate ++;
  4139. $receiptList [$key] ['reviseDetail'] = array ();
  4140. if (! empty ( $value ['reviseDetail'] ))
  4141. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4142. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4143. $categoryDetil = $Lcategory->getOne ( array (
  4144. 'where' => 'cid=' . $value ['cid'],
  4145. 'asArray' => true
  4146. ) );
  4147. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4148. // 检测编辑状态
  4149. $verifyList = $verify->getOne ( array (
  4150. 'where' => 'vid=' . $value ['verify'],
  4151. 'asArray' => true
  4152. ) );
  4153. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4154. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4155. Doo::loadModel ( 'role' );
  4156. $role = new role ();
  4157. // print_r($verifyList);
  4158. $flag = true;
  4159. $roleKey = 0;
  4160. $endStaffArray = array ();
  4161. $roleArrayCopy = array ();
  4162. foreach ( $verifyList as $k => $v ) {
  4163. // init verifyStaff
  4164. if ($v [1] == 'ROLE') {
  4165. if (! empty ( $verifyStaff )) {
  4166. $endStaffArray = end ( $verifyStaff );
  4167. if ($v [0] == $endStaffArray ['nextStaff']) {
  4168. $roleId = $v [0];
  4169. }
  4170. }
  4171. $roleVerify = json_decode ( $v [3], true );
  4172. $roleKey = $k;
  4173. $roleArray = array ();
  4174. $rolename = $role->getOne ( array (
  4175. 'where' => 'rid=' . $v [0],
  4176. 'asArray' => true
  4177. ) );
  4178. foreach ( $roleVerify as $o => $p ) {
  4179. $staffID = explode ( '_', $p );
  4180. $staffInfo = $staff->getOne ( array (
  4181. 'where' => 'sid=' . $staffID [0],
  4182. 'asArray' => true
  4183. ) );
  4184. // print_r($staffID);
  4185. $exp = array (
  4186. 0 => $staffInfo ['sid'],
  4187. 1 => $staffID [1],
  4188. 2 => $staffInfo ['avatar'],
  4189. 'date' => '',
  4190. 'date' => '',
  4191. 'opinion' => '',
  4192. 'status' => '',
  4193. 'rolename' => $rolename ['name']
  4194. );
  4195. array_push ( $roleArray, $exp );
  4196. }
  4197. $roleArrayCopy [$v [0]] = $roleArray;
  4198. // $verifyList[$k]['roleArray']=$roleArray;
  4199. }
  4200. // print_r($roleArray);
  4201. $verifyList [$k] ['date'] = "";
  4202. $verifyList [$k] ['opinion'] = "";
  4203. $verifyList [$k] ['status'] = "";
  4204. if (empty ( $verifyStaff )) {
  4205. $verifyList [$k] ['date'] = "";
  4206. $verifyList [$k] ['opinion'] = "";
  4207. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4208. $verifyList [$k] ['status'] = 4;
  4209. $button = 4;
  4210. $flag = false;
  4211. }
  4212. } else {
  4213. foreach ( $verifyStaff as $m => $u ) {
  4214. if ($v [0] == $m) {
  4215. $verifyList [$k] ['date'] = $u ['date'];
  4216. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4217. $verifyList [$k] ['status'] = $u ['status'];
  4218. $flag = false;
  4219. break;
  4220. }
  4221. }
  4222. $endStaffArray = end ( $verifyStaff );
  4223. if (isset ( $endStaffArray ['ROLE'] )) {
  4224. } else {
  4225. $endKey = key ( $verifyStaff );
  4226. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4227. $button = 4;
  4228. $verifyList [$k] ['status'] = 4;
  4229. }
  4230. }
  4231. }
  4232. }
  4233. $rolename ['name'] = '';
  4234. if (! empty ( $roleId )) {
  4235. Doo::loadModel ( 'role' );
  4236. $role = new role ();
  4237. $rolename = $role->getOne ( array (
  4238. 'where' => 'rid=' . $roleId,
  4239. 'asArray' => true
  4240. ) );
  4241. }
  4242. if (! empty ( $verifyStaff ))
  4243. $endStaffArray = end ( $verifyStaff );
  4244. $KOP = false;
  4245. foreach ( $roleArrayCopy as $P => $A ) {
  4246. foreach ( $A as $MKI => $AVL ) {
  4247. if (! empty ( $verifyStaff )) {
  4248. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4249. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4250. $button = 4;
  4251. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4252. }
  4253. foreach ( $verifyStaff as $m => $u ) {
  4254. $AVLFK = $AVL [0] . '_R';
  4255. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4256. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4257. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4258. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4259. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4260. break;
  4261. }
  4262. }
  4263. } else {
  4264. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4265. $button = 4;
  4266. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4267. }
  4268. }
  4269. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4270. $KOP = true;
  4271. }
  4272. }
  4273. // print_r($roleArrayCopy);
  4274. // echo $roleKey;
  4275. foreach ( $roleArrayCopy as $k => $v ) {
  4276. foreach ( $verifyList as $m => $n ) {
  4277. if ($n [0] == $k) {
  4278. array_splice ( $verifyList, $m, 1, $v );
  4279. }
  4280. }
  4281. }
  4282. $receiptList [$key] ['verifyList'] = $verifyList;
  4283. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4284. 'where' => 'sid=' . $value ['staff'],
  4285. 'asArray' => true
  4286. ) );
  4287. $receiptList [$key] ['button'] = $button;
  4288. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4289. }
  4290. // $data['verifyDetail']=$verifyDetail;
  4291. $mothHtml = "";
  4292. for($i = 1; $i <= 12; $i ++) {
  4293. if ($month == $i)
  4294. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4295. else
  4296. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4297. }
  4298. // 获取审批日志
  4299. Doo::loadModel ( 'receiptLog' );
  4300. $receiptLog = new receiptLog ();
  4301. $rlList = array ();
  4302. $rlInfo = $receiptLog->getOne ( array (
  4303. 'where' => 'rid=' . $rid . ' and status=4',
  4304. 'asArray' => true
  4305. ) );
  4306. $tijdate = $receiptLog->getOne ( array (
  4307. 'where' => 'rid=' . $rid . ' and status=2',
  4308. 'asc' => 'rlid',
  4309. 'asArray' => true
  4310. ) );
  4311. if (! empty ( $rlInfo )) {
  4312. $rlList = $receiptLog->find ( array (
  4313. 'where' => 'rid=' . $rid,
  4314. 'asc' => 'rlid',
  4315. 'asArray' => true
  4316. ) );
  4317. }
  4318. $receiptList [0] ['rlList'] = $rlList;
  4319. $enclosurList = $enclosur->find ( array (
  4320. 'where' => 'rid=' . $rid,
  4321. 'asArray' => true
  4322. ) );
  4323. $enclosurHtml = '';
  4324. foreach ( $enclosurList as $value ) {
  4325. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4326. }
  4327. // print_r($receiptList);
  4328. $data ['rid'] = $rid;
  4329. $data ['enclosurHtml'] = $enclosurHtml;
  4330. $data ['rolename'] = $rolename ['name'];
  4331. $data ['datetij'] = $tijdate ['date'];
  4332. $data ['mothHtml'] = $mothHtml;
  4333. $data ['receiptList'] = $receiptList;
  4334. $data ['receiptApprovalCount'] = count ( $receiptList );
  4335. $data ['status'] = $status;
  4336. $data ['year'] = $year;
  4337. $data ['categoryList'] = $categoryList;
  4338. $data ['staffList'] = $staffList;
  4339. $data ['cid'] = $cid;
  4340. $data ['sid'] = $sid;
  4341. $data ['ap'] = $ap;
  4342. $data ['memu'] = "receipt";
  4343. $data ['staff'] = $this->staff;
  4344. $data ['receiptMemu'] = 'approvalExpenses';
  4345. $data ['verifyId'] = $this->verifyId;
  4346. $data ['executeId'] = $this->executeId;
  4347. $this->render ( "/admin/expensesEdi", $data );
  4348. }
  4349. function expensesDefray() {
  4350. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4351. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4352. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4353. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4354. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4355. if (! empty ( $rid )) {
  4356. Doo::loadModel ( "verify" );
  4357. $verify = new verify ();
  4358. Doo::loadModel ( "receiptDetail" );
  4359. $receiptDetailObj = new receiptDetail ();
  4360. Doo::loadModel ( "itemStatistics" );
  4361. Doo::loadModel ( "statistics" );
  4362. $statistics = new statistics ();
  4363. $itemStatistics = new itemStatistics ();
  4364. Doo::loadModel ( "receipt" );
  4365. $receipt = new receipt ();
  4366. Doo::loadModel ( "loanReceipt" );
  4367. $loanReceipt = new loanReceipt ();
  4368. $receiptDetail = $receipt->getOne ( array (
  4369. 'where' => 'rid=' . $rid . ' and status=2 ',
  4370. 'asArray' => true
  4371. ) );
  4372. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4373. $nsflag = true;
  4374. foreach ( $nslist as $value ) {
  4375. if ($value == $this->staff ['0'] ['sid']) {
  4376. $nsflag = false;
  4377. break;
  4378. }
  4379. }
  4380. // print_r($nslist);die;
  4381. if (empty ( $receiptDetail ) || $nsflag)
  4382. return "/approvalExpenses/pendApproval";
  4383. $verifyDetail = $verify->getOne ( array (
  4384. 'where' => ' vid =' . $receiptDetail ['verify'],
  4385. 'asArray' => true
  4386. ) );
  4387. $verifyString = $verifyDetail ['staff'];
  4388. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4389. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4390. if (empty ( $opinion )) {
  4391. if ($status == 3)
  4392. $opinion = "终止";
  4393. else
  4394. $opinion = "同意支付";
  4395. }
  4396. $nowStaff = 0;
  4397. $nowStaffList = array ();
  4398. if (empty ( $verifyStaff )) {
  4399. // 还需加入是否已经进入角色审批
  4400. if ($verifyDetail [0] [1] == 'ROLE') {
  4401. // print_r($verifyDetail);echo "ddd";
  4402. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4403. foreach ( $vStaffString as $key => $value ) {
  4404. $staffK = explode ( "_", $value );
  4405. if ($staffK [0] != $this->staff [0] ['sid'])
  4406. array_push ( $nowStaffList, $staffK [0] );
  4407. }
  4408. // print_r($verifyDetail);
  4409. // die;
  4410. if (! empty ( $nowStaffList )) {
  4411. $nowStaff = implode ( ',', $nowStaffList );
  4412. $verifyStaff = array (
  4413. $this->staff [0] ['sid'] . "_R" => array (
  4414. 'date' => date ( 'Y-m-d' ),
  4415. 'opinion' => $opinion,
  4416. 'status' => $status,
  4417. 'nextStaff' => $verifyDetail [0] [0],
  4418. 'ROLE' => 1
  4419. )
  4420. );
  4421. } else {
  4422. $nowStaff = $verifyDetail [1] [0];
  4423. $verifyStaff = array (
  4424. $this->staff [0] ['sid'] . "_R" => array (
  4425. 'date' => date ( 'Y-m-d' ),
  4426. 'opinion' => $opinion,
  4427. 'status' => $status,
  4428. 'nextStaff' => $verifyDetail [1] [0]
  4429. )
  4430. );
  4431. }
  4432. } else {
  4433. if ($verifyDetail [1] [1] == 'ROLE') {
  4434. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4435. // echo "dd";
  4436. foreach ( $vStaffString as $key => $value ) {
  4437. $staffK = explode ( "_", $value );
  4438. array_push ( $nowStaffList, $staffK [0] );
  4439. }
  4440. $nowStaff = implode ( ',', $nowStaffList );
  4441. $verifyStaff = array (
  4442. $this->staff [0] ['sid'] => array (
  4443. 'date' => date ( 'Y-m-d' ),
  4444. 'opinion' => $opinion,
  4445. 'status' => $status,
  4446. 'nextStaff' => $verifyDetail [1] [0],
  4447. 'ROLE' => 1
  4448. )
  4449. );
  4450. } else {
  4451. $nowStaff = $verifyDetail [1] [0];
  4452. $verifyStaff = array (
  4453. $this->staff [0] ['sid'] => array (
  4454. 'date' => date ( 'Y-m-d' ),
  4455. 'opinion' => $opinion,
  4456. 'status' => $status,
  4457. 'nextStaff' => $verifyDetail [1] [0]
  4458. )
  4459. );
  4460. }
  4461. }
  4462. if ($status == 3)
  4463. $verifyStaff = array (
  4464. 'final' => $status,
  4465. $this->staff [0] ['sid'] => array (
  4466. 'date' => date ( 'Y-m-d' ),
  4467. 'opinion' => $opinion,
  4468. 'status' => $status
  4469. )
  4470. );
  4471. $vStaffString = json_encode ( $verifyStaff );
  4472. $receipt->nowStaff = $nowStaff;
  4473. $receipt->verifyStaff = $vStaffString;
  4474. $loanReceipt->nowStaff = $nowStaff;
  4475. $loanReceipt->verifyStaff = $vStaffString;
  4476. } else {
  4477. $VS = end ( $verifyStaff );
  4478. // 非角色审批
  4479. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4480. $nextStaff = 0;
  4481. $roleSTF = false;
  4482. foreach ( $verifyDetail as $key => $value ) {
  4483. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4484. if (isset ( $verifyDetail [$key + 1] )) {
  4485. $nextStaff = $verifyDetail [$key + 1] [0];
  4486. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4487. $roleSTF = true;
  4488. }
  4489. break;
  4490. }
  4491. }
  4492. if (! $roleSTF) {
  4493. $nowStaff = $nextStaff;
  4494. $verifyStaff [$this->staff [0] ['sid']] = array (
  4495. 'date' => date ( 'Y-m-d' ),
  4496. 'opinion' => $opinion,
  4497. 'status' => $status,
  4498. 'nextStaff' => $nextStaff
  4499. );
  4500. } else {
  4501. // 获取角色下的所有用户ID
  4502. $nowStaffList = array ();
  4503. foreach ( $verifyDetail as $vfk ) {
  4504. if ($vfk [1] == 'ROLE') {
  4505. $vStaffString = json_decode ( $vfk [3] );
  4506. foreach ( $vStaffString as $key => $value ) {
  4507. $staffK = explode ( "_", $value );
  4508. array_push ( $nowStaffList, $staffK [0] );
  4509. }
  4510. }
  4511. }
  4512. $nowStaff = implode ( ',', $nowStaffList );
  4513. $verifyStaff [$this->staff [0] ['sid']] = array (
  4514. 'date' => date ( 'Y-m-d' ),
  4515. 'opinion' => $opinion,
  4516. 'status' => $status,
  4517. 'nextStaff' => $nextStaff,
  4518. 'ROLE' => 0
  4519. );
  4520. }
  4521. if ($status == 3) {
  4522. $verifyStaff ['final'] = $status;
  4523. $verifyStaff [$this->staff [0] ['sid']] = array (
  4524. 'date' => date ( 'Y-m-d' ),
  4525. 'opinion' => $opinion,
  4526. 'status' => $status
  4527. );
  4528. }
  4529. $vStaffString = json_encode ( $verifyStaff );
  4530. $receipt->nowStaff = $nowStaff;
  4531. $receipt->verifyStaff = $vStaffString;
  4532. $loanReceipt->nowStaff = $nowStaff;
  4533. $loanReceipt->verifyStaff = $vStaffString;
  4534. }
  4535. // 角色审批
  4536. if (isset ( $VS ['ROLE'] )) {
  4537. // 找出角色人 当前审批角色组
  4538. $verifyJSStaff = array ();
  4539. $nowStaffList2 = array ();
  4540. foreach ( $verifyDetail as $key => $value ) {
  4541. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4542. $verifyJSStaff = json_decode ( $value [3] );
  4543. foreach ( $verifyJSStaff as $m ) {
  4544. $staffK = explode ( "_", $m );
  4545. array_push ( $nowStaffList2, $staffK [0] );
  4546. }
  4547. // print_r($nowStaffList2);
  4548. }
  4549. }
  4550. $RoleVerifyStaff = array ();
  4551. foreach ( $verifyStaff as $key => $value ) {
  4552. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4553. foreach ( $nowStaffList2 as $m ) {
  4554. if ($key == $m . "_R")
  4555. $RoleVerifyStaff [$key] = $value;
  4556. }
  4557. }
  4558. }
  4559. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4560. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4561. // 下一个审批人ID
  4562. $nextStaff = 0;
  4563. $falg = false;
  4564. foreach ( $verifyDetail as $key => $value ) {
  4565. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4566. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4567. $falg = true;
  4568. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4569. $nowStaffList = array ();
  4570. foreach ( $vStaffString as $v ) {
  4571. $staffK = explode ( "_", $v );
  4572. array_push ( $nowStaffList, $staffK [0] );
  4573. }
  4574. $nowStaff = implode ( ',', $nowStaffList );
  4575. $nextStaff = $verifyDetail [$key + 1] [0];
  4576. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4577. $nextStaff = $verifyDetail [$key + 1] [0];
  4578. $nowStaff = $nextStaff;
  4579. } else
  4580. $nowStaff = '';
  4581. break;
  4582. }
  4583. }
  4584. if ($falg)
  4585. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4586. 'date' => date ( 'Y-m-d' ),
  4587. 'opinion' => $opinion,
  4588. 'status' => $status,
  4589. 'nextStaff' => $nextStaff,
  4590. 'ROLE' => 1
  4591. );
  4592. else
  4593. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4594. 'date' => date ( 'Y-m-d' ),
  4595. 'opinion' => $opinion,
  4596. 'status' => $status,
  4597. 'nextStaff' => $nextStaff
  4598. );
  4599. // print_r($verifyStaff);
  4600. // echo $nowStaff;die;
  4601. } else { // 进入下一个角色或者审批人
  4602. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  4603. //
  4604. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4605. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4606. 'date' => date ( 'Y-m-d' ),
  4607. 'opinion' => $opinion,
  4608. 'status' => $status,
  4609. 'nextStaff' => $VS ['nextStaff'],
  4610. 'ROLE' => 1
  4611. );
  4612. // print_r($verifyStaff);
  4613. // die;
  4614. }
  4615. if ($status == 3) {
  4616. $verifyStaff ['final'] = $status;
  4617. $verifyStaff [$this->staff [0] ['sid']] = array (
  4618. 'date' => date ( 'Y-m-d' ),
  4619. 'opinion' => $opinion,
  4620. 'status' => $status
  4621. );
  4622. }
  4623. $vStaffString = json_encode ( $verifyStaff );
  4624. $receipt->verifyStaff = $vStaffString;
  4625. $receipt->nowStaff = $nowStaff;
  4626. $loanReceipt->nowStaff = $nowStaff;
  4627. $loanReceipt->verifyStaff = $vStaffString;
  4628. // die;
  4629. // }
  4630. // print_r($verifyStaff);
  4631. // die;
  4632. }
  4633. // print_r($verifyStaff);die;
  4634. }
  4635. // print_r($verifyDetail);
  4636. $roleKey = 0;
  4637. $roleId = 0;
  4638. $verifyDetailCopy = array ();
  4639. foreach ( $verifyDetail as $k => $v ) {
  4640. if ($v [1] == 'ROLE') {
  4641. $roleId = $v [0];
  4642. $roleVerify = json_decode ( $v [3], true );
  4643. $roleKey = $k;
  4644. $roleArray = array ();
  4645. foreach ( $roleVerify as $o => $p ) {
  4646. $staffID = explode ( '_', $p );
  4647. $exp = array (
  4648. 0 => $staffID [0],
  4649. 1 => $staffID [1]
  4650. );
  4651. array_push ( $roleArray, $exp );
  4652. }
  4653. $verifyDetailCopy [$v [0]] = $roleArray;
  4654. }
  4655. }
  4656. // print_r($verifyDetail);
  4657. foreach ( $verifyDetailCopy as $k => $v ) {
  4658. foreach ( $verifyDetail as $m => $n ) {
  4659. if ($n [0] == $k) {
  4660. array_splice ( $verifyDetail, $m, 1, $v );
  4661. }
  4662. }
  4663. }
  4664. // 审批日志
  4665. if (! isset ( $verifyStaff ['final'] )) {
  4666. Doo::loadModel ( "receiptLog" );
  4667. $receiptLog = new receiptLog ();
  4668. if (! empty ( $roleId )) {
  4669. Doo::loadModel ( "role" );
  4670. $role = new role ();
  4671. $roleInfo = $role->getOne ( array (
  4672. 'where' => 'rid=' . $roleId,
  4673. 'asArray' => true
  4674. ) );
  4675. $receiptLog->rolename = $roleInfo ['name'];
  4676. }
  4677. $receiptLog->username = $this->staff [0] ['username'];
  4678. $receiptLog->uid = $this->staff [0] ['sid'];
  4679. $receiptLog->date = date ( "Y-m-d" );
  4680. $receiptLog->opinion = $opinion;
  4681. $receiptLog->img = $this->staff [0] ['avatar'];
  4682. $receiptLog->status = 1;
  4683. $receiptLog->rid = $rid;
  4684. $receiptLog->insert ();
  4685. }
  4686. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4687. $receipt->status = 3;
  4688. $receipt->verifyBreakup = $verifyString;
  4689. $receiptDetailObj->status = 3;
  4690. $receiptDetailObj->update ( array (
  4691. 'where' => 'rid=' . $rid
  4692. ) );
  4693. // 微信企业号通知
  4694. $this->setWXMsg ( $rid, 3 );
  4695. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4696. $receipt->status = 6;
  4697. $receipt->pastDate = date ( "Y-m-d" );
  4698. $receipt->isBK = 1;
  4699. $loanReceipt->verifyBreakup = $verifyString;
  4700. $loanReceipt->status = 1;
  4701. $loanReceipt->pastDate = date ( "Y-m-d" );
  4702. //生成流水后 不更新汇款金额
  4703. Doo::loadModel ( 'wasteBook' );
  4704. $wasteBook = new wasteBook ();
  4705. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4706. if (empty($wbDetail)){
  4707. $loanReceipt->amount = $receiptDetail ['amount'];
  4708. }
  4709. $loanReceipt->update ( array (
  4710. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4711. ) );
  4712. // 微信企业号通知
  4713. $this->setWXMsg ( $rid, 1 );
  4714. }
  4715. $receipt->amount = $amount;
  4716. $receipt->update ( array (
  4717. 'where' => ' rid = ' . $rid
  4718. ) );
  4719. // 进入下一条审批费用新加需求
  4720. $vidList = array ();
  4721. $verifyDetail = $verify->find ( array (
  4722. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4723. 'asArray' => true
  4724. ) );
  4725. foreach ( $verifyDetail as $key => $value ) {
  4726. array_push ( $vidList, $value ['vid'] );
  4727. }
  4728. $vid = implode ( ",", $vidList );
  4729. if (empty ( $verifyDetail ))
  4730. $vid = 0;
  4731. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4732. $receipt = new receipt ();
  4733. $rd = $receipt->getOne ( array (
  4734. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4735. 'asc' => 'rid',
  4736. 'asArray' => true
  4737. ) );
  4738. if (empty ( $rd )) {
  4739. return '/approvalExpenses/pendApproval';
  4740. }
  4741. if ($rd ['Rtype'] == 1) {
  4742. if ($rd ['isBK'] == 1) {
  4743. return '/receiptburEdi/' . $rd ['rid'];
  4744. } else {
  4745. return '/expensesEdi/' . $rd ['rid'];
  4746. }
  4747. } elseif ($rd ['Rtype'] == 2) {
  4748. return '/remitApproval/' . $rd ['rid'];
  4749. } else {
  4750. return '/receiptburEdi/' . $rd ['rid'];
  4751. }
  4752. // return "/approvalExpenses/pendApproval";
  4753. }
  4754. }
  4755. function ajaxExamineExe() {
  4756. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4757. Doo::loadModel ( 'receipt' );
  4758. $receipt = new receipt ();
  4759. Doo::loadClass ( 'XDeode' );
  4760. $XDeode = new XDeode ( 5 );
  4761. if (! empty ( $rid )) {
  4762. $rLRes = $receipt->find ( array (
  4763. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4764. 'asArray' => true
  4765. ) );
  4766. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4767. echo json_encode ( array (
  4768. 'status' => 1,
  4769. 'receipt' => $rLRes [0]
  4770. ) );
  4771. die ();
  4772. }
  4773. echo json_encode ( array (
  4774. 'status' => 0,
  4775. 'receipt' => array ()
  4776. ) );
  4777. die ();
  4778. }
  4779. function implement() {
  4780. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4781. Doo::loadClass ( 'XDeode' );
  4782. $XDeode = new XDeode ( 5 );
  4783. Doo::loadModel ( 'receipt' );
  4784. $receipt = new receipt ();
  4785. Doo::loadModel ( 'L_category' );
  4786. $Lcategory = new L_category ();
  4787. Doo::loadModel ( 'verify' );
  4788. $verify = new verify ();
  4789. Doo::loadModel ( 'staff' );
  4790. $staff = new staff ();
  4791. Doo::loadModel ( "execute" );
  4792. $execute = new execute ();
  4793. $rid = $XDeode->decode ( $rid );
  4794. $receiptList = $receipt->find ( array (
  4795. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4796. 'desc' => 'rid',
  4797. 'asArray' => true
  4798. ) );
  4799. Doo::loadModel ( 'loanReceipt' );
  4800. $loanReceipt = new loanReceipt ();
  4801. // print_r($receiptList);
  4802. $loanList = array ();
  4803. if (! isset ( $receiptList ))
  4804. $loanList = $loanReceipt->find ( array (
  4805. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4806. 'desc' => 'rid',
  4807. 'asArray' => true
  4808. ) );
  4809. $Locate = 0;
  4810. $roleId = 0;
  4811. $button = 0;
  4812. foreach ( $loanList as $key => $value ) {
  4813. $loanList [$key] ['Locate'] = $Locate;
  4814. $Locate ++;
  4815. $loanList [$key] ['reviseDetail'] = array ();
  4816. if (! empty ( $value ['reviseDetail'] ))
  4817. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4818. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4819. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4820. $categoryDetil = $Lcategory->getOne ( array (
  4821. 'where' => 'cid=' . $value ['cid'],
  4822. 'asArray' => true
  4823. ) );
  4824. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4825. // 检测编辑状态
  4826. $verifyList = $verify->getOne ( array (
  4827. 'where' => 'vid=' . $value ['verify'],
  4828. 'asArray' => true
  4829. ) );
  4830. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4831. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4832. Doo::loadModel ( 'role' );
  4833. $role = new role ();
  4834. $flag = true;
  4835. $roleKey = 0;
  4836. $endStaffArray = array ();
  4837. $roleArrayCopy = array ();
  4838. foreach ( $verifyList as $k => $v ) {
  4839. // init verifyStaff
  4840. if ($v [1] == 'ROLE') {
  4841. if (! empty ( $verifyStaff )) {
  4842. $endStaffArray = end ( $verifyStaff );
  4843. // if ($v[0]==$endStaffArray['nextStaff']){
  4844. // $roleId=$v[0];
  4845. // }
  4846. }
  4847. $roleVerify = json_decode ( $v [3], true );
  4848. $roleKey = $k;
  4849. $roleArray = array ();
  4850. $rolename = $role->getOne ( array (
  4851. 'where' => 'rid=' . $v [0],
  4852. 'asArray' => true
  4853. ) );
  4854. foreach ( $roleVerify as $o => $p ) {
  4855. $staffID = explode ( '_', $p );
  4856. $staffInfo = $staff->getOne ( array (
  4857. 'where' => 'sid=' . $staffID [0],
  4858. 'asArray' => true
  4859. ) );
  4860. // print_r($staffID);
  4861. $exp = array (
  4862. 0 => $staffInfo ['sid'],
  4863. 1 => $staffID [1],
  4864. 2 => $staffInfo ['avatar'],
  4865. 'date' => '',
  4866. 'date' => '',
  4867. 'opinion' => '',
  4868. 'status' => '',
  4869. 'rolename' => $rolename ['name']
  4870. );
  4871. array_push ( $roleArray, $exp );
  4872. }
  4873. $roleArrayCopy [$v [0]] = $roleArray;
  4874. // $verifyList[$k]['roleArray']=$roleArray;
  4875. }
  4876. $verifyList [$k] ['date'] = "";
  4877. $verifyList [$k] ['opinion'] = "";
  4878. $verifyList [$k] ['status'] = "";
  4879. if (empty ( $verifyStaff )) {
  4880. $verifyList [$k] ['date'] = "";
  4881. $verifyList [$k] ['opinion'] = "";
  4882. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4883. $verifyList [$k] ['status'] = 4;
  4884. $flag = false;
  4885. }
  4886. } else {
  4887. foreach ( $verifyStaff as $m => $u ) {
  4888. if ($v [0] == $m) {
  4889. $verifyList [$k] ['date'] = $u ['date'];
  4890. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4891. $verifyList [$k] ['status'] = $u ['status'];
  4892. $flag = false;
  4893. break;
  4894. }
  4895. }
  4896. $endStaffArray = end ( $verifyStaff );
  4897. if (isset ( $endStaffArray ['ROLE'] )) {
  4898. } else {
  4899. // $endKey=key($verifyStaff);
  4900. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4901. // $button=4;
  4902. // $verifyList[$k]['status']=4;
  4903. // }
  4904. }
  4905. }
  4906. }
  4907. $rolename ['name'] = '';
  4908. if (! empty ( $roleId )) {
  4909. Doo::loadModel ( 'role' );
  4910. $role = new role ();
  4911. $rolename = $role->getOne ( array (
  4912. 'where' => 'rid=' . $roleId,
  4913. 'asArray' => true
  4914. ) );
  4915. }
  4916. if (! empty ( $verifyStaff ))
  4917. $endStaffArray = end ( $verifyStaff );
  4918. $KOP = false;
  4919. foreach ( $roleArrayCopy as $P => $A ) {
  4920. foreach ( $A as $MKI => $AVL ) {
  4921. if (! empty ( $verifyStaff )) {
  4922. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4923. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4924. $button = 4;
  4925. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4926. }
  4927. foreach ( $verifyStaff as $m => $u ) {
  4928. $AVLFK = $AVL [0] . '_R';
  4929. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4930. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4931. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4932. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4933. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4934. break;
  4935. }
  4936. }
  4937. } else {
  4938. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4939. $button = 4;
  4940. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4941. }
  4942. }
  4943. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4944. $KOP = true;
  4945. }
  4946. }
  4947. foreach ( $roleArrayCopy as $k => $v ) {
  4948. foreach ( $verifyList as $m => $n ) {
  4949. if ($n [0] == $k) {
  4950. array_splice ( $verifyList, $m, 1, $v );
  4951. }
  4952. }
  4953. }
  4954. $loanList [$key] ['verifyList'] = $verifyList;
  4955. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4956. 'where' => 'sid=' . $value ['staff'],
  4957. 'asArray' => true
  4958. ) );
  4959. }
  4960. $data ['loanList'] = $loanList;
  4961. $Locate = 0;
  4962. $roleId = 0;
  4963. $button = 0;
  4964. Doo::loadClass ( 'XDeode' );
  4965. $XDeode = new XDeode ( 5 );
  4966. foreach ( $receiptList as $key => $value ) {
  4967. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4968. $button2 = 0;
  4969. $receiptList [$key] ['Locate'] = $Locate;
  4970. $Locate ++;
  4971. $receiptList [$key] ['reviseDetail'] = array ();
  4972. if (! empty ( $value ['reviseDetail'] ))
  4973. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4974. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4975. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4976. $categoryDetil = $Lcategory->getOne ( array (
  4977. 'where' => 'cid=' . $value ['cid'],
  4978. 'asArray' => true
  4979. ) );
  4980. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4981. $executeList = json_decode ( $value ['executeCopy'], true );
  4982. $executeStaff = array ();
  4983. if (! empty ( $value ['executeStaff'] ))
  4984. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4985. if (isset ( $executeList )) {
  4986. foreach ( $executeList as $op => $lo ) {
  4987. $executeList [$op] ['date'] = "";
  4988. $executeList [$op] ['opinion'] = "";
  4989. $executeList [$op] ['status'] = "";
  4990. foreach ( $executeStaff as $m => $u ) {
  4991. if ($lo [0] == $m) {
  4992. $executeList [$op] ['date'] = $u ['date'];
  4993. $executeList [$op] ['opinion'] = $u ['opinion'];
  4994. $executeList [$op] ['status'] = $u ['status'];
  4995. break;
  4996. }
  4997. }
  4998. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  4999. $button2 = 1;
  5000. $executeList [$op] ['status'] = 4;
  5001. }
  5002. }
  5003. }
  5004. // 检测编辑状态
  5005. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5006. $verifyList ['staff'] = $value ['verifyBreakup'];
  5007. } else
  5008. $verifyList = $verify->getOne ( array (
  5009. 'where' => 'vid=' . $value ['verify'],
  5010. 'asArray' => true
  5011. ) );
  5012. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5013. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5014. Doo::loadModel ( 'role' );
  5015. $role = new role ();
  5016. if ($verifyList == NULL)
  5017. $verifyList = array ();
  5018. $flag = true;
  5019. $roleKey = 0;
  5020. $endStaffArray = array ();
  5021. $roleArrayCopy = array ();
  5022. foreach ( $verifyList as $k => $v ) {
  5023. // init verifyStaff
  5024. if ($v [1] == 'ROLE') {
  5025. if (! empty ( $verifyStaff )) {
  5026. $endStaffArray = end ( $verifyStaff );
  5027. // if ($v[0]==$endStaffArray['nextStaff']){
  5028. // $roleId=$v[0];
  5029. // }
  5030. }
  5031. $roleVerify = json_decode ( $v [3], true );
  5032. $roleKey = $k;
  5033. $roleArray = array ();
  5034. $rolename = $role->getOne ( array (
  5035. 'where' => 'rid=' . $v [0],
  5036. 'asArray' => true
  5037. ) );
  5038. foreach ( $roleVerify as $o => $p ) {
  5039. $staffID = explode ( '_', $p );
  5040. $staffInfo = $staff->getOne ( array (
  5041. 'where' => 'sid=' . $staffID [0],
  5042. 'asArray' => true
  5043. ) );
  5044. // print_r($staffID);
  5045. $exp = array (
  5046. 0 => $staffInfo ['sid'],
  5047. 1 => $staffID [1],
  5048. 2 => $staffInfo ['avatar'],
  5049. 'date' => '',
  5050. 'date' => '',
  5051. 'opinion' => '',
  5052. 'status' => '',
  5053. 'rolename' => $rolename ['name']
  5054. );
  5055. array_push ( $roleArray, $exp );
  5056. }
  5057. $roleArrayCopy [$v [0]] = $roleArray;
  5058. // $verifyList[$k]['roleArray']=$roleArray;
  5059. }
  5060. $verifyList [$k] ['date'] = "";
  5061. $verifyList [$k] ['opinion'] = "";
  5062. $verifyList [$k] ['status'] = "";
  5063. if (empty ( $verifyStaff )) {
  5064. $verifyList [$k] ['date'] = "";
  5065. $verifyList [$k] ['opinion'] = "";
  5066. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5067. $verifyList [$k] ['status'] = 4;
  5068. $flag = false;
  5069. }
  5070. } else {
  5071. foreach ( $verifyStaff as $m => $u ) {
  5072. if ($v [0] == $m) {
  5073. $verifyList [$k] ['date'] = $u ['date'];
  5074. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5075. $verifyList [$k] ['status'] = $u ['status'];
  5076. $flag = false;
  5077. break;
  5078. }
  5079. }
  5080. $endStaffArray = end ( $verifyStaff );
  5081. if (isset ( $endStaffArray ['ROLE'] )) {
  5082. } else {
  5083. // $endKey=key($verifyStaff);
  5084. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5085. // $button=4;
  5086. // $verifyList[$k]['status']=4;
  5087. // }
  5088. }
  5089. }
  5090. }
  5091. $rolename ['name'] = '';
  5092. if (! empty ( $roleId )) {
  5093. Doo::loadModel ( 'role' );
  5094. $role = new role ();
  5095. $rolename = $role->getOne ( array (
  5096. 'where' => 'rid=' . $roleId,
  5097. 'asArray' => true
  5098. ) );
  5099. }
  5100. if (! empty ( $verifyStaff ))
  5101. $endStaffArray = end ( $verifyStaff );
  5102. $KOP = false;
  5103. foreach ( $roleArrayCopy as $P => $A ) {
  5104. foreach ( $A as $MKI => $AVL ) {
  5105. if (! empty ( $verifyStaff )) {
  5106. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5107. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5108. $button = 4;
  5109. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5110. }
  5111. foreach ( $verifyStaff as $m => $u ) {
  5112. $AVLFK = $AVL [0] . '_R';
  5113. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5114. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5115. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5116. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5117. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5118. break;
  5119. }
  5120. }
  5121. } else {
  5122. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5123. $button = 4;
  5124. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5125. }
  5126. }
  5127. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5128. $KOP = true;
  5129. }
  5130. }
  5131. foreach ( $roleArrayCopy as $k => $v ) {
  5132. foreach ( $verifyList as $m => $n ) {
  5133. if ($n [0] == $k) {
  5134. array_splice ( $verifyList, $m, 1, $v );
  5135. }
  5136. }
  5137. }
  5138. $receiptList [$key] ['verifyList'] = $verifyList;
  5139. $receiptList [$key] ['executeList'] = $executeList;
  5140. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5141. 'where' => 'sid=' . $value ['staff'],
  5142. 'asArray' => true
  5143. ) );
  5144. $receiptList [$key] ['button2'] = $button2;
  5145. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5146. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5147. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5148. $receiptList [$key] ['relust'] = $relust;
  5149. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5150. }
  5151. // 是否写入过流水
  5152. $accountType = 0;
  5153. if ($receiptList [0] ['Rtype'] == 0) {
  5154. $accountType = 3;
  5155. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5156. if (!empty($receiptList [0]['accountItem']) )
  5157. $accountType = 2;
  5158. else
  5159. $accountType = 1;
  5160. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5161. $accountType = 4;
  5162. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5163. $accountType = 12;
  5164. }
  5165. Doo::loadModel ( 'wasteBook' );
  5166. $wasteBook = new wasteBook ();
  5167. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5168. $data ['wbDetail'] = $wbDetail;
  5169. $wbDetailLoan=array();
  5170. if ($accountType==2){
  5171. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5172. }
  5173. $data ['wbDetailLoan'] = $wbDetailLoan;
  5174. //print_r($receiptList);
  5175. $data ['receiptList'] = $receiptList;
  5176. $data ['memu'] = "receipt";
  5177. $data ['staff'] = $this->staff;
  5178. $data ['receiptMemu'] = 'implement';
  5179. $data ['verifyId'] = $this->verifyId;
  5180. $data ['executeId'] = $this->executeId;
  5181. $this->render ( "/admin/implement", $data );
  5182. }
  5183. function implementDo() {
  5184. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5185. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5186. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5187. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5188. // $ab = '';
  5189. // if ($accountBank == 'CGBDeposit')
  5190. // $ab = '纵横广发';
  5191. // elseif ($accountBank == 'ICBCDeposit')
  5192. // $ab = '纵横工行';
  5193. // elseif ($accountBank == 'HUADeposit')
  5194. // $ab = '华润银行';
  5195. // elseif ($accountBank == 'PersonalDeposit')
  5196. // $ab = '个人广发';
  5197. // if (empty ( $ab ))
  5198. // die ( 'illegal request--22' );
  5199. if (! empty ( $rid )) {
  5200. Doo::loadModel ( 'receipt' );
  5201. $receipt = new receipt ();
  5202. // Doo::loadClass ( 'XDeode' );
  5203. // $XDeode = new XDeode ( 5 );
  5204. // $rinfo = $receipt->getOne ( array (
  5205. // 'where' => 'rid=' . $rid,
  5206. // 'asArray' => true
  5207. // ) );
  5208. $rinfo = $receipt->getReceiptByRid ( $rid );
  5209. // $accountType = '';
  5210. // if ($rinfo ['Rtype'] == 1) {
  5211. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5212. // $accountType = 2;
  5213. // else
  5214. // $accountType = 1;
  5215. // } elseif ($rinfo ['Rtype'] == 2) {
  5216. // $accountType = 4;
  5217. // } elseif ($rinfo ['Rtype'] == 0)
  5218. // $accountType = 3;
  5219. // if (empty ( $accountType ))
  5220. // die ( 'illegal request' );
  5221. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5222. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5223. if (empty ( $executeStaff )) {
  5224. $executeStaff = array (
  5225. $this->staff [0] ['sid'] => array (
  5226. 'date' => date ( 'Y-m-d' ),
  5227. 'opinion' => $implementOpinions,
  5228. 'status' => 1
  5229. )
  5230. );
  5231. } else {
  5232. $executeStaff [$this->staff [0] ['sid']] = array (
  5233. 'date' => date ( 'Y-m-d' ),
  5234. 'opinion' => $implementOpinions,
  5235. 'status' => 1
  5236. );
  5237. }
  5238. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5239. $receipt->executeStaff = json_encode ( $executeStaff );
  5240. $receipt->status = 8;
  5241. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5242. $receipt->status = 9;
  5243. if ($rinfo ['status'] == 6) {
  5244. $receipt->loanDate = date ( "Y-m-d" );
  5245. }
  5246. $receipt->executeDate = date ( "Y-m-d" );
  5247. } else {
  5248. $receipt->executeStaff = json_encode ( $executeStaff );
  5249. }
  5250. //$receipt->amount = $amount;
  5251. $receipt->update ( array (
  5252. 'where' => 'rid=' . $rid
  5253. ) );
  5254. // 公司流水记录
  5255. // Doo::loadModel ( 'wasteBook' );
  5256. // $wasteBook = new wasteBook ();
  5257. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5258. // // 银行
  5259. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5260. // $item = array (
  5261. // 'dataID' => $rid,
  5262. // 'expensesType' => 2,
  5263. // 'accountType' => $accountType,
  5264. // 'accountPriceShow' => $amount,
  5265. // 'accountPrice' => - $amount,
  5266. // 'accountBank' => $accountBank,
  5267. // 'category' => $rinfo ['category'] [0] ['title'],
  5268. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5269. // 'name' => $rinfo ['staffDetail'] ['username'],
  5270. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5271. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5272. // );
  5273. // $wasteBook->setAccountBookStatistics ( $item );
  5274. // }
  5275. }
  5276. //$ridKey = $XDeode->encode ( $rid );
  5277. return "/hisImplement";
  5278. // return "/implement/" . $ridKey . ".html";
  5279. }
  5280. function receiptburEdi() {
  5281. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5282. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5283. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5284. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5285. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5286. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5287. if (empty ( $status ))
  5288. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5289. $vidList = array ();
  5290. $button = 0;
  5291. Doo::loadModel ( 'verify' );
  5292. Doo::loadModel ( 'receipt' );
  5293. Doo::loadModel ( 'staff' );
  5294. $staff = new staff ();
  5295. $receipt = new receipt ();
  5296. $verify = new verify ();
  5297. Doo::loadModel ( 'L_category' );
  5298. $Lcategory = new L_category ();
  5299. Doo::loadModel ( 'enclosur' );
  5300. $enclosur = new enclosur ();
  5301. Doo::loadModel ( 'loanReceipt' );
  5302. $loanReceipt = new loanReceipt ();
  5303. // user verify ID
  5304. $verifyDetail = $verify->find ( array (
  5305. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5306. 'asArray' => true
  5307. ) );
  5308. foreach ( $verifyDetail as $key => $value ) {
  5309. array_push ( $vidList, $value ['vid'] );
  5310. }
  5311. $vid = implode ( ",", $vidList );
  5312. if (empty ( $verifyDetail ))
  5313. $vid = 0;
  5314. $categoryList = $Lcategory->find ( array (
  5315. 'asArray' => true
  5316. ) );
  5317. $staffList = $staff->find ( array (
  5318. 'where' => 'cid=' . $cid,
  5319. 'asArray' => true
  5320. ) );
  5321. $ap = "";
  5322. if ($status == 4) {
  5323. $ap = 4;
  5324. $status = 2;
  5325. }
  5326. // get Receipt By verifyID status 2
  5327. $receiptList = $receipt->find ( array (
  5328. 'where' => 'rid =' . $rid . ' and status=2',
  5329. 'desc' => 'rid',
  5330. 'asArray' => true
  5331. ) );
  5332. if (empty ( $receiptList )) {
  5333. die ( 'illegal request' );
  5334. }
  5335. $loanList = $loanReceipt->find ( array (
  5336. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5337. 'desc' => 'rid',
  5338. 'asArray' => true
  5339. ) );
  5340. $data ['explanation'] = '';
  5341. if (! empty ( $loanList ))
  5342. $data ['explanation'] = $loanList [0] ['explanation'];
  5343. $Locate = 0;
  5344. $roleId = 0;
  5345. $button = 0;
  5346. foreach ( $loanList as $key => $value ) {
  5347. $loanList [$key] ['Locate'] = $Locate;
  5348. $Locate ++;
  5349. $loanList [$key] ['reviseDetail'] = array ();
  5350. if (! empty ( $value ['reviseDetail'] ))
  5351. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5352. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5353. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5354. $categoryDetil = $Lcategory->getOne ( array (
  5355. 'where' => 'cid=' . $value ['cid'],
  5356. 'asArray' => true
  5357. ) );
  5358. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5359. // 检测编辑状态
  5360. $verifyList = $verify->getOne ( array (
  5361. 'where' => 'vid=' . $value ['verify'],
  5362. 'asArray' => true
  5363. ) );
  5364. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5365. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5366. Doo::loadModel ( 'role' );
  5367. $role = new role ();
  5368. $flag = true;
  5369. $roleKey = 0;
  5370. $endStaffArray = array ();
  5371. $roleArrayCopy = array ();
  5372. foreach ( $verifyList as $k => $v ) {
  5373. // init verifyStaff
  5374. if ($v [1] == 'ROLE') {
  5375. if (! empty ( $verifyStaff )) {
  5376. $endStaffArray = end ( $verifyStaff );
  5377. }
  5378. $roleVerify = json_decode ( $v [3], true );
  5379. $roleKey = $k;
  5380. $roleArray = array ();
  5381. $rolename = $role->getOne ( array (
  5382. 'where' => 'rid=' . $v [0],
  5383. 'asArray' => true
  5384. ) );
  5385. foreach ( $roleVerify as $o => $p ) {
  5386. $staffID = explode ( '_', $p );
  5387. $staffInfo = $staff->getOne ( array (
  5388. 'where' => 'sid=' . $staffID [0],
  5389. 'asArray' => true
  5390. ) );
  5391. // print_r($staffID);
  5392. $exp = array (
  5393. 0 => $staffInfo ['sid'],
  5394. 1 => $staffID [1],
  5395. 2 => $staffInfo ['avatar'],
  5396. 'date' => '',
  5397. 'date' => '',
  5398. 'opinion' => '',
  5399. 'status' => '',
  5400. 'rolename' => $rolename ['name']
  5401. );
  5402. array_push ( $roleArray, $exp );
  5403. }
  5404. $roleArrayCopy [$v [0]] = $roleArray;
  5405. // $verifyList[$k]['roleArray']=$roleArray;
  5406. }
  5407. $verifyList [$k] ['date'] = "";
  5408. $verifyList [$k] ['opinion'] = "";
  5409. $verifyList [$k] ['status'] = "";
  5410. if (empty ( $verifyStaff )) {
  5411. $verifyList [$k] ['date'] = "";
  5412. $verifyList [$k] ['opinion'] = "";
  5413. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5414. $verifyList [$k] ['status'] = 4;
  5415. $flag = false;
  5416. }
  5417. } else {
  5418. foreach ( $verifyStaff as $m => $u ) {
  5419. if ($v [0] == $m) {
  5420. $verifyList [$k] ['date'] = $u ['date'];
  5421. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5422. $verifyList [$k] ['status'] = $u ['status'];
  5423. $flag = false;
  5424. break;
  5425. }
  5426. }
  5427. $endStaffArray = end ( $verifyStaff );
  5428. if (isset ( $endStaffArray ['ROLE'] )) {
  5429. } else {
  5430. }
  5431. }
  5432. }
  5433. $rolename ['name'] = '';
  5434. if (! empty ( $roleId )) {
  5435. Doo::loadModel ( 'role' );
  5436. $role = new role ();
  5437. $rolename = $role->getOne ( array (
  5438. 'where' => 'rid=' . $roleId,
  5439. 'asArray' => true
  5440. ) );
  5441. }
  5442. if (! empty ( $verifyStaff ))
  5443. $endStaffArray = end ( $verifyStaff );
  5444. $KOP = false;
  5445. foreach ( $roleArrayCopy as $P => $A ) {
  5446. foreach ( $A as $MKI => $AVL ) {
  5447. if (! empty ( $verifyStaff )) {
  5448. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5449. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5450. $button = 4;
  5451. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5452. }
  5453. foreach ( $verifyStaff as $m => $u ) {
  5454. $AVLFK = $AVL [0] . '_R';
  5455. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5456. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5457. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5458. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5459. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5460. break;
  5461. }
  5462. }
  5463. } else {
  5464. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5465. $button = 4;
  5466. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5467. }
  5468. }
  5469. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5470. $KOP = true;
  5471. }
  5472. }
  5473. foreach ( $roleArrayCopy as $k => $v ) {
  5474. foreach ( $verifyList as $m => $n ) {
  5475. if ($n [0] == $k) {
  5476. array_splice ( $verifyList, $m, 1, $v );
  5477. }
  5478. }
  5479. }
  5480. $loanList [$key] ['verifyList'] = $verifyList;
  5481. }
  5482. $htmlLoan = '';
  5483. $data ['loanReceiptDate'] = '';
  5484. if (isset ( $loanList [0] )) {
  5485. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5486. if ($value ['status'] == 1)
  5487. $htmlLoan .= '<li class="done" >';
  5488. elseif ($value ['status'] == 3)
  5489. $htmlLoan .= '<li class="undone" >';
  5490. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5491. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5492. if (isset ( $value ['rolename'] ))
  5493. $htmlLoan .= $value ['rolename'];
  5494. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5495. }
  5496. $data ['loanDate'] = $loanList [0] ['date'];
  5497. } else {
  5498. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5499. }
  5500. $data ['htmlLoan'] = $htmlLoan;
  5501. // $data ['LoanReceipt']=$loanList[0];
  5502. // print_r($loanList);
  5503. $Locate = 0;
  5504. $roleId = 0;
  5505. $button = 0;
  5506. if ($ap == 4)
  5507. $status = 4;
  5508. Doo::loadClass ( 'XDeode' );
  5509. $XDeode = new XDeode ( 5 );
  5510. foreach ( $receiptList as $key => $value ) {
  5511. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5512. $receiptList [$key] ['Locate'] = $Locate;
  5513. $Locate ++;
  5514. $receiptList [$key] ['reviseDetail'] = array ();
  5515. // 调整金额 代码调整
  5516. if (! empty ( $value ['reviseDetail'] )) {
  5517. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5518. foreach ( $reviseDetail as $ry => $re ) {
  5519. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5520. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5521. }
  5522. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5523. // print_r($reviseDetail);
  5524. }
  5525. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5526. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5527. $categoryDetil = $Lcategory->getOne ( array (
  5528. 'where' => 'cid=' . $value ['cid'],
  5529. 'asArray' => true
  5530. ) );
  5531. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5532. // 检测编辑状态
  5533. $verifyList = $verify->getOne ( array (
  5534. 'where' => 'vid=' . $value ['verify'],
  5535. 'asArray' => true
  5536. ) );
  5537. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5538. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5539. Doo::loadModel ( 'role' );
  5540. $role = new role ();
  5541. // print_r($verifyList);
  5542. $flag = true;
  5543. $roleKey = 0;
  5544. $endStaffArray = array ();
  5545. $roleArrayCopy = array ();
  5546. foreach ( $verifyList as $k => $v ) {
  5547. // init verifyStaff
  5548. if ($v [1] == 'ROLE') {
  5549. if (! empty ( $verifyStaff )) {
  5550. $endStaffArray = end ( $verifyStaff );
  5551. if ($v [0] == $endStaffArray ['nextStaff']) {
  5552. $roleId = $v [0];
  5553. }
  5554. }
  5555. $roleVerify = json_decode ( $v [3], true );
  5556. $roleKey = $k;
  5557. $roleArray = array ();
  5558. $rolename = $role->getOne ( array (
  5559. 'where' => 'rid=' . $v [0],
  5560. 'asArray' => true
  5561. ) );
  5562. foreach ( $roleVerify as $o => $p ) {
  5563. $staffID = explode ( '_', $p );
  5564. $staffInfo = $staff->getOne ( array (
  5565. 'where' => 'sid=' . $staffID [0],
  5566. 'asArray' => true
  5567. ) );
  5568. // print_r($staffID);
  5569. $exp = array (
  5570. 0 => $staffInfo ['sid'],
  5571. 1 => $staffID [1],
  5572. 2 => $staffInfo ['avatar'],
  5573. 'date' => '',
  5574. 'date' => '',
  5575. 'opinion' => '',
  5576. 'status' => '',
  5577. 'rolename' => $rolename ['name']
  5578. );
  5579. array_push ( $roleArray, $exp );
  5580. }
  5581. $roleArrayCopy [$v [0]] = $roleArray;
  5582. // $verifyList[$k]['roleArray']=$roleArray;
  5583. }
  5584. // print_r($roleArray);
  5585. $verifyList [$k] ['date'] = "";
  5586. $verifyList [$k] ['opinion'] = "";
  5587. $verifyList [$k] ['status'] = "";
  5588. if (empty ( $verifyStaff )) {
  5589. $verifyList [$k] ['date'] = "";
  5590. $verifyList [$k] ['opinion'] = "";
  5591. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5592. $verifyList [$k] ['status'] = 4;
  5593. $button = 4;
  5594. $flag = false;
  5595. }
  5596. } else {
  5597. foreach ( $verifyStaff as $m => $u ) {
  5598. if ($v [0] == $m) {
  5599. $verifyList [$k] ['date'] = $u ['date'];
  5600. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5601. $verifyList [$k] ['status'] = $u ['status'];
  5602. $flag = false;
  5603. break;
  5604. }
  5605. }
  5606. $endStaffArray = end ( $verifyStaff );
  5607. if (isset ( $endStaffArray ['ROLE'] )) {
  5608. } else {
  5609. $endKey = key ( $verifyStaff );
  5610. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5611. $button = 4;
  5612. $verifyList [$k] ['status'] = 4;
  5613. }
  5614. }
  5615. }
  5616. }
  5617. $rolename ['name'] = '';
  5618. if (! empty ( $roleId )) {
  5619. Doo::loadModel ( 'role' );
  5620. $role = new role ();
  5621. $rolename = $role->getOne ( array (
  5622. 'where' => 'rid=' . $roleId,
  5623. 'asArray' => true
  5624. ) );
  5625. }
  5626. if (! empty ( $verifyStaff ))
  5627. $endStaffArray = end ( $verifyStaff );
  5628. $KOP = false;
  5629. foreach ( $roleArrayCopy as $P => $A ) {
  5630. foreach ( $A as $MKI => $AVL ) {
  5631. if (! empty ( $verifyStaff )) {
  5632. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5633. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5634. $button = 4;
  5635. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5636. }
  5637. foreach ( $verifyStaff as $m => $u ) {
  5638. $AVLFK = $AVL [0] . '_R';
  5639. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5640. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5641. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5642. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5643. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5644. break;
  5645. }
  5646. }
  5647. } else {
  5648. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5649. $button = 4;
  5650. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5651. }
  5652. }
  5653. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5654. $KOP = true;
  5655. }
  5656. }
  5657. foreach ( $roleArrayCopy as $k => $v ) {
  5658. foreach ( $verifyList as $m => $n ) {
  5659. if ($n [0] == $k) {
  5660. array_splice ( $verifyList, $m, 1, $v );
  5661. }
  5662. }
  5663. }
  5664. // print_r($verifyList);
  5665. $receiptList [$key] ['verifyList'] = $verifyList;
  5666. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5667. 'where' => 'sid=' . $value ['staff'],
  5668. 'asArray' => true
  5669. ) );
  5670. $receiptList [$key] ['button'] = $button;
  5671. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5672. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5673. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5674. $receiptList [$key] ['relust'] = $relust;
  5675. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5676. }
  5677. //print_r($receiptList);die;
  5678. // $data['verifyDetail']=$verifyDetail;
  5679. $mothHtml = "";
  5680. for($i = 1; $i <= 12; $i ++) {
  5681. if ($month == $i)
  5682. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5683. else
  5684. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5685. }
  5686. // 获取审批日志
  5687. Doo::loadModel ( 'receiptLog' );
  5688. $receiptLog = new receiptLog ();
  5689. $rlList = array ();
  5690. $rlInfo = $receiptLog->getOne ( array (
  5691. 'where' => 'rid=' . $rid . ' and status=4',
  5692. 'asArray' => true
  5693. ) );
  5694. $tijdate = $receiptLog->getOne ( array (
  5695. 'where' => 'rid=' . $rid . ' and status=2',
  5696. 'asc' => 'rlid',
  5697. 'asArray' => true
  5698. ) );
  5699. if (! empty ( $rlInfo )) {
  5700. $rlList = $receiptLog->find ( array (
  5701. 'where' => 'rid=' . $rid,
  5702. 'asc' => 'rlid',
  5703. 'asArray' => true
  5704. ) );
  5705. }
  5706. // echo $rid;
  5707. // print_r($receiptList);
  5708. $receiptList [0] ['rlList'] = $rlList;
  5709. // print_r($receiptList);
  5710. $enclosurList = $enclosur->find ( array (
  5711. 'where' => 'rid=' . $rid,
  5712. 'asArray' => true
  5713. ) );
  5714. $enclosurHtml = '';
  5715. foreach ( $enclosurList as $value ) {
  5716. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5717. }
  5718. $data ['enclosurHtml'] = $enclosurHtml;
  5719. $data ['rolename'] = $rolename ['name'];
  5720. $data ['mothHtml'] = $mothHtml;
  5721. // print_r($receiptList);
  5722. $data ['rid'] = $rid;
  5723. $data ['tijdate'] = $tijdate ['date'];
  5724. $data ['receiptList'] = $receiptList;
  5725. $data ['receiptApprovalCount'] = count ( $receiptList );
  5726. $data ['status'] = $status;
  5727. $data ['year'] = $year;
  5728. $data ['categoryList'] = $categoryList;
  5729. $data ['staffList'] = $staffList;
  5730. $data ['cid'] = $cid;
  5731. $data ['sid'] = $sid;
  5732. $data ['ap'] = $ap;
  5733. $data ['memu'] = "receipt";
  5734. $data ['staff'] = $this->staff;
  5735. $data ['receiptMemu'] = 'approvalExpenses';
  5736. $data ['verifyId'] = $this->verifyId;
  5737. $data ['executeId'] = $this->executeId;
  5738. $this->render ( "/admin/receiptburEdi", $data );
  5739. }
  5740. function hisImplement() {
  5741. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5742. if (empty ( $item ))
  5743. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5744. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5745. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5746. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5747. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5748. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5749. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5750. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5751. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5752. Doo::loadClass ( 'XDeode' );
  5753. $XDeode = new XDeode ( 5 );
  5754. Doo::loadModel ( 'receipt' );
  5755. $receipt = new receipt ();
  5756. Doo::loadModel ( 'L_category' );
  5757. $Lcategory = new L_category ();
  5758. Doo::loadModel ( 'verify' );
  5759. Doo::loadModel ( 'statistics' );
  5760. $statistics = new statistics ();
  5761. $verify = new verify ();
  5762. Doo::loadModel ( 'staff' );
  5763. $staff = new staff ();
  5764. Doo::loadClass ( 'XDeode' );
  5765. $XDeode = new XDeode ( 5 );
  5766. $XDeode7 = new XDeode ( 7 );
  5767. $cid = $XDeode->decode ( $cidKey );
  5768. $condition = "";
  5769. if ($item == "expenses")
  5770. $condition = " and Rtype=1 ";
  5771. elseif ($item == "receipts")
  5772. $condition = " and Rtype=0 ";
  5773. elseif ($item == "remits")
  5774. $condition = " and Rtype=2 ";
  5775. elseif($item == "train")
  5776. $condition = " and Rtype=3 ";
  5777. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5778. $sopString = $cidString = "";
  5779. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5780. if (empty ( $rdate ))
  5781. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5782. else
  5783. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5784. if ($status == 'pendImplement') {
  5785. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5786. } elseif ($status == 'alerpts') {
  5787. $statusCon = '(status=8 or status=9 )';
  5788. if (empty ( $rdate ))
  5789. $dateCondition .= " and Year(date) =" . $year;
  5790. else
  5791. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5792. }
  5793. if ($sop != 'SOP')
  5794. $sopString = " and staff=" . $sop;
  5795. if ($cidKey != 'ALL')
  5796. $cidString = " and cid=" . $cid;
  5797. if(!empty($receiptOrder)){
  5798. $receiptList = $receipt->find ( array (
  5799. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5800. 'desc' => 'rid',
  5801. 'asArray' => true
  5802. ) );
  5803. // 员工筛选
  5804. $receiptList2 = $receipt->find ( array (
  5805. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5806. 'desc' => 'rid',
  5807. 'asArray' => true
  5808. ) );
  5809. }else{
  5810. $receiptList = $receipt->find ( array (
  5811. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5812. 'desc' => 'rid',
  5813. 'asArray' => true
  5814. ) );
  5815. // 员工筛选
  5816. $receiptList2 = $receipt->find ( array (
  5817. 'where' => $statusCon . $condition . $dateCondition,
  5818. 'desc' => 'rid',
  5819. 'asArray' => true
  5820. ) );
  5821. }
  5822. $sopStaff = array ();
  5823. foreach ( $receiptList2 as $key => $value ) {
  5824. $staffDetail = $staff->getOne ( array (
  5825. 'select' => 'username',
  5826. 'where' => 'sid=' . $value ['staff'],
  5827. 'asArray' => true
  5828. ) );
  5829. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5830. }
  5831. // 办事处筛选
  5832. $categoryScreen = array ();
  5833. $categorList = $Lcategory->getCategory ();
  5834. foreach ( $receiptList2 as $key => $value ) {
  5835. foreach ( $categorList as $k => $v ) {
  5836. if ($value ['cid'] == $v ['cid']) {
  5837. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5838. break;
  5839. }
  5840. }
  5841. }
  5842. $categoryScreenHtml = "";
  5843. foreach ( $categoryScreen as $key => $value ) {
  5844. if ($cidKey == $key)
  5845. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5846. else
  5847. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5848. }
  5849. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5850. $data ['cidKey'] = $cidKey;
  5851. $Locate = 0;
  5852. $roleId = 0;
  5853. $button = 0;
  5854. $staffBatchNumber = 100001;
  5855. $remittanceList = array ();
  5856. foreach ( $receiptList as $key => $value ) {
  5857. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5858. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5859. $receiptList [$key] ['Texe'] = 'false';
  5860. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5861. $receiptList [$key] ['Texe'] = 'true';
  5862. }
  5863. $receiptList [$key] ['TRexe'] = 'true';
  5864. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5865. $receiptList [$key] ['TRexe'] = 'false';
  5866. }
  5867. $receiptList [$key] ['Locate'] = $Locate;
  5868. $Locate ++;
  5869. $receiptList [$key] ['reviseDetail'] = array ();
  5870. if (! empty ( $value ['reviseDetail'] ))
  5871. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5872. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5873. $categoryDetil = $Lcategory->getOne ( array (
  5874. 'where' => 'cid=' . $value ['cid'],
  5875. 'asArray' => true
  5876. ) );
  5877. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5878. // 检测编辑状态
  5879. $verifyList = $verify->getOne ( array (
  5880. 'where' => 'vid=' . $value ['verify'],
  5881. 'asArray' => true
  5882. ) );
  5883. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5884. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5885. Doo::loadModel ( 'role' );
  5886. $role = new role ();
  5887. $flag = true;
  5888. $roleKey = 0;
  5889. $endStaffArray = array ();
  5890. $roleArrayCopy = array ();
  5891. foreach ( $verifyList as $k => $v ) {
  5892. // init verifyStaff
  5893. if ($v [1] == 'ROLE') {
  5894. if (! empty ( $verifyStaff )) {
  5895. $endStaffArray = end ( $verifyStaff );
  5896. }
  5897. $roleVerify = json_decode ( $v [3], true );
  5898. $roleKey = $k;
  5899. $roleArray = array ();
  5900. $rolename = $role->getOne ( array (
  5901. 'where' => 'rid=' . $v [0],
  5902. 'asArray' => true
  5903. ) );
  5904. foreach ( $roleVerify as $o => $p ) {
  5905. $staffID = explode ( '_', $p );
  5906. $staffInfo = $staff->getOne ( array (
  5907. 'where' => 'sid=' . $staffID [0],
  5908. 'asArray' => true
  5909. ) );
  5910. $exp = array (
  5911. 0 => $staffInfo ['sid'],
  5912. 1 => $staffID [1],
  5913. 2 => $staffInfo ['avatar'],
  5914. 'date' => '',
  5915. 'date' => '',
  5916. 'opinion' => '',
  5917. 'status' => '',
  5918. 'rolename' => $rolename ['name']
  5919. );
  5920. array_push ( $roleArray, $exp );
  5921. }
  5922. $roleArrayCopy [$v [0]] = $roleArray;
  5923. }
  5924. $verifyList [$k] ['date'] = "";
  5925. $verifyList [$k] ['opinion'] = "";
  5926. $verifyList [$k] ['status'] = "";
  5927. if (empty ( $verifyStaff )) {
  5928. $verifyList [$k] ['date'] = "";
  5929. $verifyList [$k] ['opinion'] = "";
  5930. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5931. $verifyList [$k] ['status'] = 4;
  5932. $flag = false;
  5933. }
  5934. } else {
  5935. foreach ( $verifyStaff as $m => $u ) {
  5936. if ($v [0] == $m) {
  5937. $verifyList [$k] ['date'] = $u ['date'];
  5938. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5939. $verifyList [$k] ['status'] = $u ['status'];
  5940. $flag = false;
  5941. break;
  5942. }
  5943. }
  5944. $endStaffArray = end ( $verifyStaff );
  5945. }
  5946. }
  5947. $rolename ['name'] = '';
  5948. if (! empty ( $roleId )) {
  5949. Doo::loadModel ( 'role' );
  5950. $role = new role ();
  5951. $rolename = $role->getOne ( array (
  5952. 'where' => 'rid=' . $roleId,
  5953. 'asArray' => true
  5954. ) );
  5955. }
  5956. if (! empty ( $verifyStaff ))
  5957. $endStaffArray = end ( $verifyStaff );
  5958. $KOP = false;
  5959. foreach ( $roleArrayCopy as $P => $A ) {
  5960. foreach ( $A as $MKI => $AVL ) {
  5961. if (! empty ( $verifyStaff )) {
  5962. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5963. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5964. $button = 4;
  5965. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5966. }
  5967. foreach ( $verifyStaff as $m => $u ) {
  5968. $AVLFK = $AVL [0] . '_R';
  5969. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5970. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5971. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5972. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5973. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5974. break;
  5975. }
  5976. }
  5977. } else {
  5978. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5979. $button = 4;
  5980. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5981. }
  5982. }
  5983. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5984. $KOP = true;
  5985. }
  5986. }
  5987. foreach ( $roleArrayCopy as $k => $v ) {
  5988. foreach ( $verifyList as $m => $n ) {
  5989. if ($n [0] == $k) {
  5990. array_splice ( $verifyList, $m, 1, $v );
  5991. }
  5992. }
  5993. }
  5994. $receiptList [$key] ['verifyList'] = $verifyList;
  5995. $staffDetail = $staff->getOne ( array (
  5996. 'where' => 'sid=' . $value ['staff'],
  5997. 'asArray' => true
  5998. ) );
  5999. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6000. $receiptList [$key] ['button'] = $button;
  6001. // 设置导出汇款execl
  6002. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6003. $remittanceDetail = array (
  6004. $staffBatchNumber,
  6005. $value ['remittanceName'],
  6006. $value ['bankNumber'],
  6007. $value ['bankName'],
  6008. $value ['remittanceBankType'],
  6009. $value ['coupletNumber'],
  6010. $value ['sum']
  6011. );
  6012. array_push ( $remittanceList, $remittanceDetail );
  6013. $staffBatchNumber ++;
  6014. }
  6015. }
  6016. $data ['remittanceList'] = json_encode ( $remittanceList );
  6017. // print_r($receiptList);
  6018. $mothHtml = "";
  6019. for($i = 1; $i <= 12; $i ++) {
  6020. if ($moth == $i)
  6021. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6022. else
  6023. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6024. }
  6025. $dayHtml = "";
  6026. if ($day != "DAY" || $moth != "MONTH") {
  6027. for($i = 1; $i <= 31; $i ++) {
  6028. if ($day == $i)
  6029. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6030. else
  6031. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6032. }
  6033. }
  6034. $sopHtml = "";
  6035. foreach ( $sopStaff as $key => $value ) {
  6036. if ($sop == $key)
  6037. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6038. else
  6039. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6040. }
  6041. $data ['status'] = $status;
  6042. $data ['rdate'] = $rdate;
  6043. $data ['sopHtml'] = $sopHtml;
  6044. $data ['dayHtml'] = $dayHtml;
  6045. $data ['mothHtml'] = $mothHtml;
  6046. $data ['receiptList'] = $receiptList;
  6047. $data ['memu'] = "receipt";
  6048. $data ['staff'] = $this->staff;
  6049. $data ['receiptMemu'] = 'implement';
  6050. $data ['verifyId'] = $this->verifyId;
  6051. $data ['executeId'] = $this->executeId;
  6052. $data ['item'] = $item;
  6053. $data ['year'] = $year;
  6054. $data ['moth'] = $moth;
  6055. $data['receiptOrder']=$receiptOrder;
  6056. $data ['day'] = $day;
  6057. $data ['sop'] = $sop;
  6058. $this->render ( "/admin/hisImplement", $data );
  6059. }
  6060. /**
  6061. * 导出汇款信息的exelc
  6062. */
  6063. function exportRemittance() {
  6064. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6065. if (empty ( $remittanceInfo ))
  6066. die ( 'illegal request' );
  6067. $title = array (
  6068. '员工编号',
  6069. '姓名',
  6070. '员工账号',
  6071. '员工账户开户行',
  6072. '转账类型',
  6073. '联行号',
  6074. '金额'
  6075. );
  6076. $data = json_decode ( $remittanceInfo, true );
  6077. if (empty ( $data ))
  6078. die ( 'illegal request' );
  6079. Doo::loadClass ( 'receipt.func' );
  6080. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6081. header ( 'Content-Type:text/html;charset=utf-8' );
  6082. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6083. }
  6084. function ajaxExamine() {
  6085. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6086. Doo::loadModel ( 'receipt' );
  6087. $receipt = new receipt ();
  6088. if (! empty ( $rid )) {
  6089. $rLRes = $receipt->find ( array (
  6090. 'where' => 'status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) and rid!=' . $rid,
  6091. 'asArray' => true
  6092. ) );
  6093. echo json_encode ( array (
  6094. 'status' => 1,
  6095. 'receipt' => $rLRes [0]
  6096. ) );
  6097. die ();
  6098. }
  6099. echo json_encode ( array (
  6100. 'status' => 0,
  6101. 'receipt' => array ()
  6102. ) );
  6103. die ();
  6104. }
  6105. /*
  6106. * 废弃
  6107. */
  6108. function myReceipt() {
  6109. // all approval past withdraw
  6110. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6111. if (empty ( $item ))
  6112. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6113. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6114. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6115. Doo::loadModel ( 'receipt' );
  6116. $receipt = new receipt ();
  6117. // pre-loaded
  6118. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6119. // have cache
  6120. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6121. if (! empty ( $moth )) // yearPage
  6122. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6123. $this->showCache ( $path );
  6124. }
  6125. Doo::loadModel ( 'L_category' );
  6126. $Lcategory = new L_category ();
  6127. Doo::loadModel ( 'verify' );
  6128. Doo::loadModel ( 'statistics' );
  6129. $statistics = new statistics ();
  6130. $verify = new verify ();
  6131. Doo::loadModel ( 'staff' );
  6132. $staff = new staff ();
  6133. $condition = " and status!=0 ";
  6134. if ($item == "approval")
  6135. $condition = " and status=2 ";
  6136. elseif ($item == "withdraw")
  6137. $condition = " and status=3 ";
  6138. elseif ($item == "past")
  6139. $condition = " and status=1 ";
  6140. elseif ($item == "whdw")
  6141. $condition = " and status=4 ";
  6142. $dateCondition = " and Year(date) =" . $year;
  6143. if (! empty ( $moth )) {
  6144. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6145. $stList = $statistics->getOne ( array (
  6146. 'select' => 'rePrice ,agPrice',
  6147. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6148. 'asArray' => true
  6149. ) );
  6150. } else
  6151. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6152. if (empty ( $stList ))
  6153. $stList = array (
  6154. 'rePrice' => 0,
  6155. 'agPrice' => 0
  6156. );
  6157. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6158. $data ['stList'] = array (
  6159. 'rePrice' => $stList ['rePrice'],
  6160. 'agPrice' => $stList ['agPrice'],
  6161. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6162. );
  6163. $receiptList = $receipt->find ( array (
  6164. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6165. 'desc' => 'rid',
  6166. 'asArray' => true
  6167. ) );
  6168. $Locate = 0;
  6169. $roleId = 0;
  6170. $button = 0;
  6171. foreach ( $receiptList as $key => $value ) {
  6172. $receiptList [$key] ['Locate'] = $Locate;
  6173. $Locate ++;
  6174. $receiptList [$key] ['reviseDetail'] = array ();
  6175. if (! empty ( $value ['reviseDetail'] ))
  6176. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6177. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6178. $categoryDetil = $Lcategory->getOne ( array (
  6179. 'where' => 'cid=' . $value ['cid'],
  6180. 'asArray' => true
  6181. ) );
  6182. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6183. // 检测编辑状态
  6184. $verifyList = $verify->getOne ( array (
  6185. 'where' => 'vid=' . $value ['verify'],
  6186. 'asArray' => true
  6187. ) );
  6188. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6189. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6190. Doo::loadModel ( 'role' );
  6191. $role = new role ();
  6192. $flag = true;
  6193. $roleKey = 0;
  6194. $endStaffArray = array ();
  6195. $roleArrayCopy = array ();
  6196. foreach ( $verifyList as $k => $v ) {
  6197. // init verifyStaff
  6198. if ($v [1] == 'ROLE') {
  6199. if (! empty ( $verifyStaff )) {
  6200. $endStaffArray = end ( $verifyStaff );
  6201. // if ($v[0]==$endStaffArray['nextStaff']){
  6202. // $roleId=$v[0];
  6203. // }
  6204. }
  6205. $roleVerify = json_decode ( $v [3], true );
  6206. $roleKey = $k;
  6207. $roleArray = array ();
  6208. $rolename = $role->getOne ( array (
  6209. 'where' => 'rid=' . $v [0],
  6210. 'asArray' => true
  6211. ) );
  6212. foreach ( $roleVerify as $o => $p ) {
  6213. $staffID = explode ( '_', $p );
  6214. $staffInfo = $staff->getOne ( array (
  6215. 'where' => 'sid=' . $staffID [0],
  6216. 'asArray' => true
  6217. ) );
  6218. // print_r($staffID);
  6219. $exp = array (
  6220. 0 => $staffInfo ['sid'],
  6221. 1 => $staffID [1],
  6222. 2 => $staffInfo ['avatar'],
  6223. 'date' => '',
  6224. 'date' => '',
  6225. 'opinion' => '',
  6226. 'status' => '',
  6227. 'rolename' => $rolename ['name']
  6228. );
  6229. array_push ( $roleArray, $exp );
  6230. }
  6231. $roleArrayCopy [$v [0]] = $roleArray;
  6232. // $verifyList[$k]['roleArray']=$roleArray;
  6233. }
  6234. $verifyList [$k] ['date'] = "";
  6235. $verifyList [$k] ['opinion'] = "";
  6236. $verifyList [$k] ['status'] = "";
  6237. if (empty ( $verifyStaff )) {
  6238. $verifyList [$k] ['date'] = "";
  6239. $verifyList [$k] ['opinion'] = "";
  6240. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6241. $verifyList [$k] ['status'] = 4;
  6242. $flag = false;
  6243. }
  6244. } else {
  6245. foreach ( $verifyStaff as $m => $u ) {
  6246. if ($v [0] == $m) {
  6247. $verifyList [$k] ['date'] = $u ['date'];
  6248. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6249. $verifyList [$k] ['status'] = $u ['status'];
  6250. $flag = false;
  6251. break;
  6252. }
  6253. }
  6254. $endStaffArray = end ( $verifyStaff );
  6255. if (isset ( $endStaffArray ['ROLE'] )) {
  6256. } else {
  6257. // $endKey=key($verifyStaff);
  6258. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6259. // $button=4;
  6260. // $verifyList[$k]['status']=4;
  6261. // }
  6262. }
  6263. }
  6264. }
  6265. $rolename ['name'] = '';
  6266. if (! empty ( $roleId )) {
  6267. Doo::loadModel ( 'role' );
  6268. $role = new role ();
  6269. $rolename = $role->getOne ( array (
  6270. 'where' => 'rid=' . $roleId,
  6271. 'asArray' => true
  6272. ) );
  6273. }
  6274. if (! empty ( $verifyStaff ))
  6275. $endStaffArray = end ( $verifyStaff );
  6276. $KOP = false;
  6277. foreach ( $roleArrayCopy as $P => $A ) {
  6278. foreach ( $A as $MKI => $AVL ) {
  6279. if (! empty ( $verifyStaff )) {
  6280. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6281. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6282. $button = 4;
  6283. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6284. }
  6285. foreach ( $verifyStaff as $m => $u ) {
  6286. $AVLFK = $AVL [0] . '_R';
  6287. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6288. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6289. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6290. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6291. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6292. break;
  6293. }
  6294. }
  6295. } else {
  6296. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6297. $button = 4;
  6298. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6299. }
  6300. }
  6301. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6302. $KOP = true;
  6303. }
  6304. }
  6305. foreach ( $roleArrayCopy as $k => $v ) {
  6306. foreach ( $verifyList as $m => $n ) {
  6307. if ($n [0] == $k) {
  6308. array_splice ( $verifyList, $m, 1, $v );
  6309. }
  6310. }
  6311. }
  6312. $receiptList [$key] ['verifyList'] = $verifyList;
  6313. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6314. 'where' => 'sid=' . $value ['staff'],
  6315. 'asArray' => true
  6316. ) );
  6317. $receiptList [$key] ['button'] = $button;
  6318. }
  6319. // print_r($receiptList);die;
  6320. $mothHtml = "";
  6321. for($i = 1; $i <= 12; $i ++) {
  6322. if ($moth == $i)
  6323. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6324. else
  6325. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6326. }
  6327. $data ['mothHtml'] = $mothHtml;
  6328. $data ['receiptList'] = $receiptList;
  6329. $data ['memu'] = "receipt";
  6330. $data ['staff'] = $this->staff;
  6331. $data ['receiptMemu'] = 'receipt';
  6332. $data ['verifyId'] = $this->verifyId;
  6333. $data ['executeId'] = $this->executeId;
  6334. $data ['item'] = $item;
  6335. $data ['year'] = $year;
  6336. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6337. // sufficient condition to generate cache
  6338. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6339. $receiptList = $receipt->find ( array (
  6340. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6341. 'asArray' => true
  6342. ) );
  6343. if (empty ( $receiptList )) { // generated files
  6344. ob_start ();
  6345. $this->render ( "/admin/saea_myList", $data );
  6346. $this->cacheFile ( $path );
  6347. die ();
  6348. // $content = ob_get_contents();
  6349. // $fp = fopen($path, "w");
  6350. // fwrite($fp, $content);
  6351. // fclose($fp);
  6352. }
  6353. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6354. $receiptList = $receipt->find ( array (
  6355. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6356. 'asArray' => true
  6357. ) );
  6358. if (empty ( $receiptList )) { // generated files
  6359. ob_start ();
  6360. $this->render ( "/admin/saea_myList", $data );
  6361. $this->cacheFile ( $path );
  6362. die ();
  6363. }
  6364. }
  6365. }
  6366. $this->render ( "/admin/saea_myList", $data );
  6367. }
  6368. function saeaCreate() {
  6369. Doo::loadModel ( 'accountItem' );
  6370. Doo::loadModel ( 'verify' );
  6371. Doo::loadModel ( 'receipt' );
  6372. Doo::loadModel ( 'L_category' );
  6373. $lCategory = new L_category ();
  6374. $receipt = new receipt ();
  6375. $verify = new verify ();
  6376. $accountItem = new accountItem ();
  6377. Doo::loadModel ( "role" );
  6378. $role = new role ();
  6379. $acItem = $accountItem->find ( array (
  6380. 'asArray' => true
  6381. ) );
  6382. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6383. $data ['category'] = $lCategory->find ( array (
  6384. 'asArray' => true
  6385. ) );
  6386. $data ['veList'] = $veList;
  6387. $data ['acItem'] = $acItem;
  6388. $data ['memu'] = "receipt";
  6389. $data ['staff'] = $this->staff;
  6390. $data ['receiptMemu'] = 'saeaBorad';
  6391. $data ['verifyId'] = $this->verifyId;
  6392. $data ['executeId'] = $this->executeId;
  6393. $this->render ( "/admin/saea_create", $data );
  6394. }
  6395. function addReceipt() {
  6396. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6397. $agency = $this->get_args ( 'agency' );
  6398. $travel = $this->get_args ( 'travel' );
  6399. $train = $this->get_args ( 'train' );
  6400. $other = $this->get_args ( 'other' );
  6401. $inttrain = $this->get_args ( 'inttrain' );
  6402. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6403. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6404. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6405. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6406. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6407. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6408. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6409. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6410. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6411. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6412. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6413. header ( 'Content-Type:text/html;charset=utf-8' );
  6414. die ( '请填写联行号' );
  6415. }
  6416. Doo::loadModel ( 'receipt' );
  6417. Doo::loadModel ( 'receiptDetail' );
  6418. Doo::loadModel ( 'accountItem' );
  6419. $accountItem = new accountItem ();
  6420. $receipt = new receipt ();
  6421. Doo::loadModel ( 'enclosur' );
  6422. Doo::loadModel ( 'execute' );
  6423. $execute = new execute ();
  6424. $executeDetail = $execute->getOne ( array (
  6425. 'where' => 'mold="报销单执行人"',
  6426. 'asArray' => true
  6427. ) );
  6428. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6429. // if(!empty($receiptDetail))
  6430. // return "/referReceipt/".$receiptDetail['rid'];
  6431. $aItem = $accountItem->find ( array (
  6432. 'asArray' => true
  6433. ) );
  6434. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6435. $ag = $tr = $ta = $ot= $it = 0;
  6436. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6437. foreach ( $aItem as $key => $value ) {
  6438. if ($value ['category'] == $this->AGENCY) {
  6439. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6440. array_push ( $accountJson [$this->AGENCY], array (
  6441. 'aid' => $value ['aid'],
  6442. 'name' => $value ['name'],
  6443. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6444. ) );
  6445. $sum += $agency [$ag];
  6446. $agencySum += $agency [$ag];
  6447. }
  6448. $ag ++;
  6449. }
  6450. if ($value ['category'] == $this->TRAVEL) {
  6451. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6452. array_push ( $accountJson [$this->TRAVEL], array (
  6453. 'aid' => $value ['aid'],
  6454. 'name' => $value ['name'],
  6455. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6456. ) );
  6457. $sum += $travel [$tr];
  6458. $travelSum += $travel [$tr];
  6459. }
  6460. $tr ++;
  6461. }
  6462. if ($value ['category'] == $this->TRAIN) {
  6463. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6464. array_push ( $accountJson [$this->TRAIN], array (
  6465. 'aid' => $value ['aid'],
  6466. 'name' => $value ['name'],
  6467. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6468. ) );
  6469. $sum += $train [$ta];
  6470. $trainSum += $train [$ta];
  6471. }
  6472. $ta ++;
  6473. }
  6474. if ($value ['category'] == $this->INTTRAIN) {
  6475. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6476. array_push ( $accountJson [$this->INTTRAIN], array (
  6477. 'aid' => $value ['aid'],
  6478. 'name' => $value ['name'],
  6479. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6480. ) );
  6481. $sum += $inttrain [$it];
  6482. $inttrainSum += $inttrain [$it];
  6483. }
  6484. $it ++;
  6485. }
  6486. if ($value ['category'] == $this->OTHER) {
  6487. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6488. array_push ( $accountJson [$this->OTHER], array (
  6489. 'aid' => $value ['aid'],
  6490. 'name' => $value ['name'],
  6491. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6492. ) );
  6493. $sum += $other [$ot];
  6494. $otherSum += $other [$ot];
  6495. }
  6496. $ot ++;
  6497. }
  6498. }
  6499. $accountJson ['cSum'] = array (
  6500. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6501. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6502. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6503. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6504. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6505. );
  6506. // 报销单
  6507. $receipt->accountItem = json_encode ( $accountJson );
  6508. $receipt->staff = $this->staff [0] ['sid'];
  6509. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6510. $receipt->date = date ( "Y-m-d" );
  6511. $receipt->cid = $cid;
  6512. $receipt->status = 5;
  6513. // 修改审批流程加入角色
  6514. $receipt->verify = $verify;
  6515. $receipt->executeCopy = $executeDetail ['staff'];
  6516. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6517. $order = array (
  6518. "\r\n",
  6519. "\n",
  6520. "\r"
  6521. );
  6522. $replace = '<br/>';
  6523. $explanation = str_replace ( $order, $replace, $explanation );
  6524. $receipt->explanation = $explanation;
  6525. $receipt->remittanceName = $remittanceName;
  6526. $receipt->bankName = $bankName;
  6527. $receipt->bankNumber = $bankNumber;
  6528. $receipt->remittanceBankType = $remittanceBankType;
  6529. if ($remittanceBankType == 1)
  6530. $receipt->coupletNumber = $coupletNumber;
  6531. $rid = $receipt->insert ();
  6532. // 附件
  6533. if (! empty ( $enclosurName )) {
  6534. $enclosurArray = explode ( '-', $enclosurName );
  6535. foreach ( $enclosurArray as $value ) {
  6536. $enclosur = new enclosur ();
  6537. $enclosur->name = $value;
  6538. $enclosur->rid = $rid;
  6539. $enclosur->insert ();
  6540. }
  6541. // print_r($enclosurArray);die;
  6542. }
  6543. // 报销详情
  6544. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6545. $receiptDetail = new receiptDetail ();
  6546. $receiptDetail->staff = $this->staff [0] ['sid'];
  6547. $receiptDetail->item = $value ['name'];
  6548. $receiptDetail->itemCategory = $this->AGENCY;
  6549. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6550. $receiptDetail->date = date ( "Y-m-d" );
  6551. $receiptDetail->cid = $cid;
  6552. $receiptDetail->rid = $rid;
  6553. $receiptDetail->status = 4;
  6554. $receiptDetail->insert ();
  6555. }
  6556. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6557. $receiptDetail = new receiptDetail ();
  6558. $receiptDetail->staff = $this->staff [0] ['sid'];
  6559. $receiptDetail->item = $value ['name'];
  6560. $receiptDetail->itemCategory = $this->TRAVEL;
  6561. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6562. $receiptDetail->date = date ( "Y-m-d" );
  6563. $receiptDetail->cid = $cid;
  6564. $receiptDetail->rid = $rid;
  6565. $receiptDetail->status = 4;
  6566. $receiptDetail->insert ();
  6567. }
  6568. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6569. $receiptDetail = new receiptDetail ();
  6570. $receiptDetail->staff = $this->staff [0] ['sid'];
  6571. $receiptDetail->item = $value ['name'];
  6572. $receiptDetail->itemCategory = $this->TRAIN;
  6573. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6574. $receiptDetail->date = date ( "Y-m-d" );
  6575. $receiptDetail->cid = $cid;
  6576. $receiptDetail->rid = $rid;
  6577. $receiptDetail->status = 4;
  6578. $receiptDetail->insert ();
  6579. }
  6580. //内训
  6581. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6582. $receiptDetail = new receiptDetail ();
  6583. $receiptDetail->staff = $this->staff [0] ['sid'];
  6584. $receiptDetail->item = $value ['name'];
  6585. $receiptDetail->itemCategory = $this->INTTRAIN;
  6586. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6587. $receiptDetail->date = date ( "Y-m-d" );
  6588. $receiptDetail->cid = $cid;
  6589. $receiptDetail->rid = $rid;
  6590. $receiptDetail->status = 4;
  6591. $receiptDetail->insert ();
  6592. }
  6593. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6594. $receiptDetail = new receiptDetail ();
  6595. $receiptDetail->staff = $this->staff [0] ['sid'];
  6596. $receiptDetail->item = $value ['name'];
  6597. $receiptDetail->itemCategory = $this->OTHER;
  6598. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6599. $receiptDetail->date = date ( "Y-m-d" );
  6600. $receiptDetail->cid = $cid;
  6601. $receiptDetail->rid = $rid;
  6602. $receiptDetail->status = 4;
  6603. $receiptDetail->insert ();
  6604. }
  6605. return "/saeaBorad";
  6606. } else
  6607. die ( 'illegal request' );
  6608. }
  6609. function referReceipt() {
  6610. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6611. Doo::loadModel ( 'receipt' );
  6612. Doo::loadModel ( 'verify' );
  6613. $verify = new verify ();
  6614. $receipt = new receipt ();
  6615. Doo::loadModel ( 'L_category' );
  6616. $lCategory = new L_category ();
  6617. Doo::loadModel ( "role" );
  6618. $role = new role ();
  6619. $receiptDetail = $receipt->find ( array (
  6620. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6621. 'asArray' => true
  6622. ) );
  6623. if (empty ( $receiptDetail ))
  6624. return "/addReceipt";
  6625. foreach ( $receiptDetail as $key => $value ) {
  6626. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6627. $veList = $verify->getOne ( array (
  6628. 'where' => 'vid=' . $value ['verify'],
  6629. 'asArray' => true
  6630. ) );
  6631. $v = json_decode ( $veList ['staff'] );
  6632. array_push ( $v [0], $veList ['description'] );
  6633. foreach ( $v as $n => $m ) {
  6634. if ($m ['1'] == 'ROLE') {
  6635. $roleInfo = $role->getOne ( array (
  6636. 'where' => 'rid=' . $m [0],
  6637. 'asArray' => true
  6638. ) );
  6639. $v [$n] [1] = $roleInfo ['name'];
  6640. }
  6641. }
  6642. $receiptDetail [$key] ['staff'] = $v;
  6643. $category = $lCategory->getOne ( array (
  6644. 'where' => 'cid=' . $value ['cid'],
  6645. 'asArray' => true
  6646. ) );
  6647. $receiptDetail [$key] ['category'] = $category ['title'];
  6648. }
  6649. // print_r($receiptDetail);
  6650. $data ['receiptDetail'] = $receiptDetail;
  6651. $data ['memu'] = "receipt";
  6652. $data ['staff'] = $this->staff;
  6653. $data ['receiptMemu'] = 'saeaCreate';
  6654. $data ['verifyId'] = $this->verifyId;
  6655. $data ['executeId'] = $this->executeId;
  6656. $this->render ( "/admin/saea_confirm", $data );
  6657. }
  6658. function editReceipt() {
  6659. // edit status 4
  6660. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6661. Doo::loadClass ( 'XDeode' );
  6662. $XDeode = new XDeode ( 7 );
  6663. $rid = $XDeode->decode ( $ridKey );
  6664. if (empty ( $rid ))
  6665. die ( 'illegal request' );
  6666. // echo $rid.'sd';
  6667. Doo::loadModel ( 'accountItem' );
  6668. Doo::loadModel ( 'verify' );
  6669. Doo::loadModel ( 'receipt' );
  6670. $receipt = new receipt ();
  6671. $verify = new verify ();
  6672. $accountItem = new accountItem ();
  6673. Doo::loadModel ( 'L_category' );
  6674. $lCategory = new L_category ();
  6675. Doo::loadModel ( "role" );
  6676. $role = new role ();
  6677. Doo::loadModel ( 'enclosur' );
  6678. $enclosur = new enclosur ();
  6679. $receiptDetail = $receipt->getOne ( array (
  6680. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6681. 'asArray' => true
  6682. ) );
  6683. if (empty ( $receiptDetail ))
  6684. die ( 'illegal request' );
  6685. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6686. $acItem = $accountItem->find ( array (
  6687. 'asArray' => true
  6688. ) );
  6689. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6690. // 配置编辑信息
  6691. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6692. foreach ( $acItem as $key => $value ) {
  6693. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6694. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6695. $acItem [$key] ['price'] = $v ['price'];
  6696. }
  6697. }
  6698. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6699. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6700. $acItem [$key] ['price'] = $v ['price'];
  6701. }
  6702. }
  6703. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6704. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6705. $acItem [$key] ['price'] = $v ['price'];
  6706. }
  6707. }
  6708. //内训
  6709. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6710. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6711. $acItem [$key] ['price'] = $v ['price'];
  6712. }
  6713. }
  6714. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6715. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6716. $acItem [$key] ['price'] = $v ['price'];
  6717. }
  6718. }
  6719. }
  6720. $data ['category'] = $lCategory->find ( array (
  6721. 'asArray' => true
  6722. ) );
  6723. $data ['cSum'] = $accountItemList ['cSum'];
  6724. $data ['sum'] = $receiptDetail ['sum'];
  6725. $data ['enclosurList'] = $enclosurList;
  6726. $data ['receiptDetail'] = $receiptDetail;
  6727. $data ['veList'] = $veList;
  6728. $data ['acItem'] = $acItem;
  6729. $data ['memu'] = "receipt";
  6730. $data ['staff'] = $this->staff;
  6731. $data ['receiptMemu'] = 'saeaBorad';
  6732. $data ['verify'] = $receiptDetail ['verify'];
  6733. $data ['verifyId'] = $this->verifyId;
  6734. $data ['executeId'] = $this->executeId;
  6735. $data ['rid'] = $ridKey;
  6736. $this->render ( "/admin/saea_edit", $data );
  6737. }
  6738. function updateReceipt() {
  6739. $agency = $this->get_args ( 'agency' );
  6740. $travel = $this->get_args ( 'travel' );
  6741. $train = $this->get_args ( 'train' );
  6742. $other = $this->get_args ( 'other' );
  6743. $inttrain = $this->get_args ( 'inttrain' );
  6744. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6745. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6746. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6747. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6748. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6749. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6750. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6751. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6752. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6753. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6754. Doo::loadClass ( 'XDeode' );
  6755. $XDeode = new XDeode ( 7 );
  6756. $rid = $XDeode->decode ( $ridKey );
  6757. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6758. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6759. header ( 'Content-Type:text/html;charset=utf-8' );
  6760. die ( '请填写联行号' );
  6761. }
  6762. Doo::loadModel ( 'receipt' );
  6763. Doo::loadModel ( 'receiptDetail' );
  6764. Doo::loadModel ( 'accountItem' );
  6765. $accountItem = new accountItem ();
  6766. $receipt = new receipt ();
  6767. Doo::loadModel ( 'enclosur' );
  6768. Doo::loadModel ( 'execute' );
  6769. $execute = new execute ();
  6770. $receiptDetail = $receipt->getOne ( array (
  6771. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6772. 'asArray' => true
  6773. ) );
  6774. if (empty ( $receiptDetail ))
  6775. return "/saeaBorad";
  6776. if ($receiptDetail ['Rtype'] == 1)
  6777. $executeDetail = $execute->getOne ( array (
  6778. 'where' => 'mold="借款费用执行人"',
  6779. 'asArray' => true
  6780. ) );
  6781. else
  6782. $executeDetail = $execute->getOne ( array (
  6783. 'where' => 'mold="报销单执行人"',
  6784. 'asArray' => true
  6785. ) );
  6786. $aItem = $accountItem->find ( array (
  6787. 'asArray' => true
  6788. ) );
  6789. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6790. $ag = $tr = $ta = $ot = $it = 0 ;
  6791. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6792. foreach ( $aItem as $key => $value ) {
  6793. if ($value ['category'] == $this->AGENCY) {
  6794. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6795. array_push ( $accountJson [$this->AGENCY], array (
  6796. 'aid' => $value ['aid'],
  6797. 'name' => $value ['name'],
  6798. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6799. ) );
  6800. $sum += $agency [$ag];
  6801. $agencySum += $agency [$ag];
  6802. }
  6803. $ag ++;
  6804. }
  6805. if ($value ['category'] == $this->TRAVEL) {
  6806. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6807. array_push ( $accountJson [$this->TRAVEL], array (
  6808. 'aid' => $value ['aid'],
  6809. 'name' => $value ['name'],
  6810. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6811. ) );
  6812. $sum += $travel [$tr];
  6813. $travelSum += $travel [$tr];
  6814. }
  6815. $tr ++;
  6816. }
  6817. if ($value ['category'] == $this->TRAIN) {
  6818. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6819. array_push ( $accountJson [$this->TRAIN], array (
  6820. 'aid' => $value ['aid'],
  6821. 'name' => $value ['name'],
  6822. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6823. ) );
  6824. $sum += $train [$ta];
  6825. $trainSum += $train [$ta];
  6826. }
  6827. $ta ++;
  6828. }
  6829. if ($value ['category'] == $this->INTTRAIN) {
  6830. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6831. array_push ( $accountJson [$this->INTTRAIN], array (
  6832. 'aid' => $value ['aid'],
  6833. 'name' => $value ['name'],
  6834. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6835. ) );
  6836. $sum += $inttrain [$it];
  6837. $inttrainSum += $inttrain [$it];
  6838. }
  6839. $it ++;
  6840. }
  6841. if ($value ['category'] == $this->OTHER) {
  6842. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6843. array_push ( $accountJson [$this->OTHER], array (
  6844. 'aid' => $value ['aid'],
  6845. 'name' => $value ['name'],
  6846. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6847. ) );
  6848. $sum += $other [$ot];
  6849. $otherSum += $other [$ot];
  6850. }
  6851. $ot ++;
  6852. }
  6853. }
  6854. $accountJson ['cSum'] = array (
  6855. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6856. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6857. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6858. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6859. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6860. );
  6861. // 报销单
  6862. $rid = $receipt->rid = $receiptDetail ['rid'];
  6863. $receipt->accountItem = json_encode ( $accountJson );
  6864. $receipt->staff = $this->staff [0] ['sid'];
  6865. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6866. $receipt->date = date ( "Y-m-d" );
  6867. $receipt->cid = $cid;
  6868. if (($receiptDetail ['status'] != 4)) {
  6869. if ($receiptDetail ['Rtype'] == 1)
  6870. $receipt->status = 7;
  6871. else
  6872. $receipt->status = 5;
  6873. }
  6874. if ($receiptDetail != 4 && ! empty ( $verify ))
  6875. $receipt->verify = $verify;
  6876. $receipt->executeCopy = $executeDetail ['staff'];
  6877. $order = array (
  6878. "\r\n",
  6879. "\n",
  6880. "\r"
  6881. );
  6882. $replace = '<br/>';
  6883. $explanation = str_replace ( $order, $replace, $explanation );
  6884. $receipt->explanation = $explanation;
  6885. $receipt->remittanceName = $remittanceName;
  6886. $receipt->bankName = $bankName;
  6887. $receipt->bankNumber = $bankNumber;
  6888. $receipt->remittanceBankType = $remittanceBankType;
  6889. if ($remittanceBankType == 1)
  6890. $receipt->coupletNumber = $coupletNumber;
  6891. $receipt->update ();
  6892. $receiptDetail = new receiptDetail ();
  6893. $receiptDetail->delete ( array (
  6894. 'where' => 'rid=' . $rid
  6895. ) );
  6896. // 报销详情
  6897. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6898. $receiptDetail = new receiptDetail ();
  6899. $receiptDetail->staff = $this->staff [0] ['sid'];
  6900. $receiptDetail->item = $value ['name'];
  6901. $receiptDetail->itemCategory = $this->AGENCY;
  6902. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6903. $receiptDetail->date = date ( "Y-m-d" );
  6904. $receiptDetail->cid = $cid;
  6905. $receiptDetail->rid = $rid;
  6906. $receiptDetail->status = 4;
  6907. $receiptDetail->insert ();
  6908. }
  6909. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6910. $receiptDetail = new receiptDetail ();
  6911. $receiptDetail->staff = $this->staff [0] ['sid'];
  6912. $receiptDetail->item = $value ['name'];
  6913. $receiptDetail->itemCategory = $this->TRAVEL;
  6914. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6915. $receiptDetail->date = date ( "Y-m-d" );
  6916. $receiptDetail->cid = $cid;
  6917. $receiptDetail->rid = $rid;
  6918. $receiptDetail->status = 4;
  6919. $receiptDetail->insert ();
  6920. }
  6921. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6922. $receiptDetail = new receiptDetail ();
  6923. $receiptDetail->staff = $this->staff [0] ['sid'];
  6924. $receiptDetail->item = $value ['name'];
  6925. $receiptDetail->itemCategory = $this->TRAIN;
  6926. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6927. $receiptDetail->date = date ( "Y-m-d" );
  6928. $receiptDetail->cid = $cid;
  6929. $receiptDetail->rid = $rid;
  6930. $receiptDetail->status = 4;
  6931. $receiptDetail->insert ();
  6932. }
  6933. //内训
  6934. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6935. $receiptDetail = new receiptDetail ();
  6936. $receiptDetail->staff = $this->staff [0] ['sid'];
  6937. $receiptDetail->item = $value ['name'];
  6938. $receiptDetail->itemCategory = $this->INTTRAIN;
  6939. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6940. $receiptDetail->date = date ( "Y-m-d" );
  6941. $receiptDetail->cid = $cid;
  6942. $receiptDetail->rid = $rid;
  6943. $receiptDetail->status = 4;
  6944. $receiptDetail->insert ();
  6945. }
  6946. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6947. $receiptDetail = new receiptDetail ();
  6948. $receiptDetail->staff = $this->staff [0] ['sid'];
  6949. $receiptDetail->item = $value ['name'];
  6950. $receiptDetail->itemCategory = $this->OTHER;
  6951. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6952. $receiptDetail->date = date ( "Y-m-d" );
  6953. $receiptDetail->cid = $cid;
  6954. $receiptDetail->rid = $rid;
  6955. $receiptDetail->status = 4;
  6956. $receiptDetail->insert ();
  6957. }
  6958. // 附件
  6959. if (! empty ( $enclosurName )) {
  6960. $enclosurArray = explode ( '-', $enclosurName );
  6961. foreach ( $enclosurArray as $value ) {
  6962. $enclosur = new enclosur ();
  6963. $enclosur->name = $value;
  6964. $enclosur->rid = $rid;
  6965. $enclosur->insert ();
  6966. }
  6967. }
  6968. // return "/referReceipt/".$rid;
  6969. }
  6970. return "/saeaBorad";
  6971. }
  6972. function approvedReceipt() {
  6973. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6974. Doo::loadModel ( 'receipt' );
  6975. Doo::loadModel ( 'receiptDetail' );
  6976. $receipt = new receipt ();
  6977. $receiptDetail = new receiptDetail ();
  6978. Doo::loadModel ( 'statistics' );
  6979. Doo::loadModel ( 'itemStatistics' );
  6980. $statistics = new statistics ();
  6981. $itemStatistics = new itemStatistics ();
  6982. Doo::loadModel ( "verify" );
  6983. $verify = new verify ();
  6984. // 审批状态的判定
  6985. $receiptDetailList = $receipt->getOne ( array (
  6986. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  6987. 'asArray' => true
  6988. ) );
  6989. if (empty ( $receiptDetailList ))
  6990. return "/saeaBorad";
  6991. $verifyDetail = $verify->getOne ( array (
  6992. 'where' => ' vid =' . $receiptDetailList ['verify'],
  6993. 'asArray' => true
  6994. ) );
  6995. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  6996. if (empty ( $receiptDetailList ['nowStaff'] )) {
  6997. $nowStaff = "";
  6998. $nowStaffList = array ();
  6999. if ($verifyDetail [0] [1] == 'ROLE') {
  7000. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7001. foreach ( $vStaffString as $key => $value ) {
  7002. $staffK = explode ( "_", $value );
  7003. array_push ( $nowStaffList, $staffK [0] );
  7004. }
  7005. $nowStaff = implode ( ',', $nowStaffList );
  7006. } else {
  7007. $nowStaff = $verifyDetail [0] [0];
  7008. }
  7009. $receipt->nowStaff = $nowStaff;
  7010. }
  7011. // echo $nowStaff;
  7012. // print_r($verifyDetail);die;
  7013. $receipt->rid = $receiptDetailList ['rid'];
  7014. $receipt->date = date ( "Y-m-d" );
  7015. $receipt->status = 2;
  7016. $receipt->update ();
  7017. $receiptDetail->status = 2;
  7018. $receiptDetail->update ( array (
  7019. 'where' => 'rid=' . $receiptDetailList ['rid']
  7020. ) );
  7021. Doo::loadModel ( "receiptLog" );
  7022. $receiptLog = new receiptLog ();
  7023. Doo::loadModel ( "verify" );
  7024. $verify = new verify ();
  7025. $receiptInfo = $receipt->getOne ( array (
  7026. 'where' => 'rid=' . $rid,
  7027. 'asArray' => true
  7028. ) );
  7029. $vr = $verify->getOne ( array (
  7030. 'where' => 'vid=' . $receiptInfo ['verify'],
  7031. 'asArray' => true
  7032. ) );
  7033. $jd = json_decode ( $vr ['staff'] );
  7034. $roleId = 0;
  7035. foreach ( $jd as $key => $value ) {
  7036. if ($value [1] == 'ROLE') {
  7037. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7038. if ($pos !== false) {
  7039. $roleId = $value [0];
  7040. }
  7041. }
  7042. }
  7043. // 审批日志
  7044. // echo $roleId;die;
  7045. if (! empty ( $roleId )) {
  7046. Doo::loadModel ( "role" );
  7047. $role = new role ();
  7048. $roleInfo = $role->getOne ( array (
  7049. 'where' => 'rid=' . $roleId,
  7050. 'asArray' => true
  7051. ) );
  7052. // $receiptLog->rolename = $roleInfo ['name'];
  7053. }
  7054. $receiptLog->username = $this->staff [0] ['username'];
  7055. $receiptLog->uid = $this->staff [0] ['sid'];
  7056. $receiptLog->date = date ( "Y-m-d" );
  7057. $receiptLog->opinion = '提交审批';
  7058. $receiptLog->img = $this->staff [0] ['avatar'];
  7059. $receiptLog->status = 2;
  7060. $receiptLog->rid = $rid;
  7061. $receiptLog->insert ();
  7062. // statistics item
  7063. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7064. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7065. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7066. $stat = $statistics->getOne ( array (
  7067. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7068. 'asArray' => true
  7069. ) );
  7070. if (empty ( $stat )) {
  7071. $statistics->date = date ( "Y-m-d" );
  7072. $statistics->cid = $this->staff [0] ['cid'];
  7073. $statistics->staff = $this->staff [0] ['sid'];
  7074. $statistics->agPrice = 0;
  7075. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7076. $statistics->insert ();
  7077. } else {
  7078. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7079. $statistics->update ( array (
  7080. 'where' => 'sid=' . $stat ['sid']
  7081. ) );
  7082. }
  7083. return "/expenses";
  7084. }
  7085. function approval() {
  7086. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7087. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7088. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7089. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7090. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7091. if (empty ( $status ))
  7092. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7093. $vidList = array ();
  7094. $button = 0;
  7095. Doo::loadModel ( 'verify' );
  7096. $verify = new verify ();
  7097. Doo::loadModel ( 'receipt' );
  7098. $receipt = new receipt ();
  7099. Doo::loadModel ( 'staff' );
  7100. $staff = new staff ();
  7101. Doo::loadModel ( 'L_category' );
  7102. $Lcategory = new L_category ();
  7103. // user verify ID
  7104. $verifyDetail = $verify->find ( array (
  7105. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7106. 'asArray' => true
  7107. ) );
  7108. foreach ( $verifyDetail as $key => $value ) {
  7109. array_push ( $vidList, $value ['vid'] );
  7110. }
  7111. $vid = implode ( ",", $vidList );
  7112. if (empty ( $verifyDetail ))
  7113. $vid = 0;
  7114. /*
  7115. */
  7116. $dateCondition = " and Year(date) =" . $year;
  7117. if (! empty ( $month ))
  7118. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7119. $categoryList = $Lcategory->find ( array (
  7120. 'asArray' => true
  7121. ) );
  7122. $staffList = $staff->find ( array (
  7123. 'where' => 'cid=' . $cid,
  7124. 'asArray' => true
  7125. ) );
  7126. $cateCondition = "";
  7127. $staffCondition = "";
  7128. $approvalCondition = "";
  7129. if (! empty ( $cid ))
  7130. $cateCondition = ' and cid=' . $cid;
  7131. if (! empty ( $sid )) {
  7132. $staffCondition = ' and staff=' . $sid;
  7133. $cateCondition = "";
  7134. }
  7135. // elseif($status==1){
  7136. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7137. // }
  7138. if ($status == 2) {
  7139. // 查找角色审批人
  7140. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7141. }
  7142. $ap = "";
  7143. if ($status == 4) {
  7144. $ap = 4;
  7145. $status = 2;
  7146. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7147. }
  7148. if ($status == 5) {
  7149. $status = 4;
  7150. $ap = 5;
  7151. }
  7152. // echo $vid;
  7153. // get Receipt By verifyID status 2 .$approvalCondition
  7154. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7155. $receiptList = $receipt->find ( array (
  7156. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7157. 'desc' => 'rid',
  7158. 'asArray' => true
  7159. ) );
  7160. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7161. $Locate = 0;
  7162. if ($ap == 4)
  7163. $status = 4;
  7164. elseif ($ap == 5)
  7165. $status = 5;
  7166. foreach ( $receiptList as $key => $value ) {
  7167. $receiptList [$key] ['Locate'] = $Locate;
  7168. $Locate ++;
  7169. $receiptList [$key] ['reviseDetail'] = array ();
  7170. if (! empty ( $value ['reviseDetail'] ))
  7171. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7172. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7173. $categoryDetil = $Lcategory->getOne ( array (
  7174. 'where' => 'cid=' . $value ['cid'],
  7175. 'asArray' => true
  7176. ) );
  7177. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7178. $verifyList = $verify->getOne ( array (
  7179. 'where' => 'vid=' . $value ['verify'],
  7180. 'asArray' => true
  7181. ) );
  7182. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7183. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7184. foreach ( $verifyList as $k => $v ) {
  7185. // init verifyStaff
  7186. $verifyList [$k] ['date'] = "";
  7187. $verifyList [$k] ['opinion'] = "";
  7188. $verifyList [$k] ['status'] = "";
  7189. if (empty ( $verifyStaff )) {
  7190. $verifyList [$k] ['date'] = "";
  7191. $verifyList [$k] ['opinion'] = "";
  7192. if ($v [0] == $this->staff [0] ['sid']) {
  7193. $verifyList [$k] ['status'] = 4;
  7194. $button = 4;
  7195. }
  7196. } else {
  7197. $flag = true;
  7198. foreach ( $verifyStaff as $m => $u ) {
  7199. if ($v [0] == $m) {
  7200. $verifyList [$k] ['date'] = $u ['date'];
  7201. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7202. $verifyList [$k] ['status'] = $u ['status'];
  7203. $flag = false;
  7204. break;
  7205. }
  7206. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7207. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7208. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7209. }
  7210. if ($flag) { // 检测可编辑
  7211. if ($v [0] == $this->staff [0] ['sid']) {
  7212. $verifyList [$k] ['status'] = 4;
  7213. $button = 4;
  7214. }
  7215. }
  7216. }
  7217. }
  7218. $receiptList [$key] ['verifyList'] = $verifyList;
  7219. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7220. 'where' => 'sid=' . $value ['staff'],
  7221. 'asArray' => true
  7222. ) );
  7223. $receiptList [$key] ['button'] = $button;
  7224. }
  7225. // print_r($receiptList);die;
  7226. // $data['verifyDetail']=$verifyDetail;
  7227. $mothHtml = "";
  7228. for($i = 1; $i <= 12; $i ++) {
  7229. if ($month == $i)
  7230. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7231. else
  7232. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7233. }
  7234. $data ['mothHtml'] = $mothHtml;
  7235. $data ['receiptList'] = $receiptList;
  7236. $data ['receiptApprovalCount'] = count ( $receiptList );
  7237. $data ['status'] = $status;
  7238. $data ['year'] = $year;
  7239. $data ['categoryList'] = $categoryList;
  7240. $data ['staffList'] = $staffList;
  7241. $data ['cid'] = $cid;
  7242. $data ['sid'] = $sid;
  7243. $data ['ap'] = $ap;
  7244. $data ['memu'] = "receipt";
  7245. $data ['staff'] = $this->staff;
  7246. $data ['receiptMemu'] = 'approval';
  7247. $data ['verifyId'] = $this->verifyId;
  7248. $data ['executeId'] = $this->executeId;
  7249. $this->render ( "/admin/saea_reportList", $data );
  7250. }
  7251. function approvalDetails() {
  7252. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7253. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7254. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7255. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7256. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7257. Doo::loadModel ( 'verify' );
  7258. $verify = new verify ();
  7259. Doo::loadModel ( 'receipt' );
  7260. $receipt = new receipt ();
  7261. Doo::loadModel ( 'staff' );
  7262. $staff = new staff ();
  7263. Doo::loadModel ( 'L_category' );
  7264. $Lcategory = new L_category ();
  7265. Doo::loadModel ( 'enclosur' );
  7266. $enclosur = new enclosur ();
  7267. $vidList = array ();
  7268. $verifyDetail = $verify->find ( array (
  7269. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7270. 'asArray' => true
  7271. ) );
  7272. foreach ( $verifyDetail as $key => $value ) {
  7273. array_push ( $vidList, $value ['vid'] );
  7274. }
  7275. $vid = implode ( ",", $vidList );
  7276. if (empty ( $verifyDetail ))
  7277. $vid = 0;
  7278. $categoryList = $Lcategory->find ( array (
  7279. 'asArray' => true
  7280. ) );
  7281. $staffList = $staff->find ( array (
  7282. 'where' => 'cid=' . $cid,
  7283. 'asArray' => true
  7284. ) );
  7285. $ap = 0;
  7286. $receiptList = $receipt->find ( array (
  7287. 'where' => 'rid =' . $rid,
  7288. 'desc' => 'rid',
  7289. 'asArray' => true
  7290. ) );
  7291. $Locate = 0;
  7292. $roleId = 0;
  7293. $button = 0;
  7294. foreach ( $receiptList as $key => $value ) {
  7295. $receiptList [$key] ['Locate'] = $Locate;
  7296. $Locate ++;
  7297. $receiptList [$key] ['reviseDetail'] = array ();
  7298. if (! empty ( $value ['reviseDetail'] ))
  7299. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7300. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7301. $categoryDetil = $Lcategory->getOne ( array (
  7302. 'where' => 'cid=' . $value ['cid'],
  7303. 'asArray' => true
  7304. ) );
  7305. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7306. // 检测编辑状态
  7307. $verifyList = $verify->getOne ( array (
  7308. 'where' => 'vid=' . $value ['verify'],
  7309. 'asArray' => true
  7310. ) );
  7311. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7312. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7313. Doo::loadModel ( 'role' );
  7314. $role = new role ();
  7315. // print_r($verifyList);
  7316. $flag = true;
  7317. $roleKey = 0;
  7318. $endStaffArray = array ();
  7319. $roleArrayCopy = array ();
  7320. foreach ( $verifyList as $k => $v ) {
  7321. // init verifyStaff
  7322. if ($v [1] == 'ROLE') {
  7323. if (! empty ( $verifyStaff )) {
  7324. $endStaffArray = end ( $verifyStaff );
  7325. if ($v [0] == $endStaffArray ['nextStaff']) {
  7326. $roleId = $v [0];
  7327. }
  7328. }
  7329. $roleVerify = json_decode ( $v [3], true );
  7330. $roleKey = $k;
  7331. $roleArray = array ();
  7332. $rolename = $role->getOne ( array (
  7333. 'where' => 'rid=' . $v [0],
  7334. 'asArray' => true
  7335. ) );
  7336. foreach ( $roleVerify as $o => $p ) {
  7337. $staffID = explode ( '_', $p );
  7338. $staffInfo = $staff->getOne ( array (
  7339. 'where' => 'sid=' . $staffID [0],
  7340. 'asArray' => true
  7341. ) );
  7342. // print_r($staffID);
  7343. $exp = array (
  7344. 0 => $staffInfo ['sid'],
  7345. 1 => $staffID [1],
  7346. 2 => $staffInfo ['avatar'],
  7347. 'date' => '',
  7348. 'date' => '',
  7349. 'opinion' => '',
  7350. 'status' => '',
  7351. 'rolename' => $rolename ['name']
  7352. );
  7353. array_push ( $roleArray, $exp );
  7354. }
  7355. $roleArrayCopy [$v [0]] = $roleArray;
  7356. // $verifyList[$k]['roleArray']=$roleArray;
  7357. }
  7358. // print_r($roleArray);
  7359. $verifyList [$k] ['date'] = "";
  7360. $verifyList [$k] ['opinion'] = "";
  7361. $verifyList [$k] ['status'] = "";
  7362. if (empty ( $verifyStaff )) {
  7363. $verifyList [$k] ['date'] = "";
  7364. $verifyList [$k] ['opinion'] = "";
  7365. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7366. $verifyList [$k] ['status'] = 4;
  7367. $button = 4;
  7368. $flag = false;
  7369. }
  7370. } else {
  7371. foreach ( $verifyStaff as $m => $u ) {
  7372. if ($v [0] == $m) {
  7373. $verifyList [$k] ['date'] = $u ['date'];
  7374. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7375. $verifyList [$k] ['status'] = $u ['status'];
  7376. $flag = false;
  7377. break;
  7378. }
  7379. }
  7380. $endStaffArray = end ( $verifyStaff );
  7381. if (isset ( $endStaffArray ['ROLE'] )) {
  7382. } else {
  7383. $endKey = key ( $verifyStaff );
  7384. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7385. $button = 4;
  7386. $verifyList [$k] ['status'] = 4;
  7387. }
  7388. }
  7389. }
  7390. }
  7391. $rolename ['name'] = '';
  7392. if (! empty ( $roleId )) {
  7393. Doo::loadModel ( 'role' );
  7394. $role = new role ();
  7395. $rolename = $role->getOne ( array (
  7396. 'where' => 'rid=' . $roleId,
  7397. 'asArray' => true
  7398. ) );
  7399. }
  7400. if (! empty ( $verifyStaff ))
  7401. $endStaffArray = end ( $verifyStaff );
  7402. $KOP = false;
  7403. foreach ( $roleArrayCopy as $P => $A ) {
  7404. foreach ( $A as $MKI => $AVL ) {
  7405. if (! empty ( $verifyStaff )) {
  7406. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7407. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7408. $button = 4;
  7409. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7410. }
  7411. foreach ( $verifyStaff as $m => $u ) {
  7412. $AVLFK = $AVL [0] . '_R';
  7413. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7414. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7415. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7416. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7417. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7418. break;
  7419. }
  7420. }
  7421. } else {
  7422. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7423. $button = 4;
  7424. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7425. }
  7426. }
  7427. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7428. $KOP = true;
  7429. }
  7430. }
  7431. foreach ( $roleArrayCopy as $k => $v ) {
  7432. foreach ( $verifyList as $m => $n ) {
  7433. if ($n [0] == $k) {
  7434. array_splice ( $verifyList, $m, 1, $v );
  7435. }
  7436. }
  7437. }
  7438. $receiptList [$key] ['verifyList'] = $verifyList;
  7439. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7440. 'where' => 'sid=' . $value ['staff'],
  7441. 'asArray' => true
  7442. ) );
  7443. $receiptList [$key] ['button'] = $button;
  7444. }
  7445. $mothHtml = "";
  7446. for($i = 1; $i <= 12; $i ++) {
  7447. if ($month == $i)
  7448. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7449. else
  7450. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7451. }
  7452. // 获取审批日志
  7453. Doo::loadModel ( 'receiptLog' );
  7454. $receiptLog = new receiptLog ();
  7455. $rlList = array ();
  7456. $rlInfo = $receiptLog->getOne ( array (
  7457. 'where' => 'rid=' . $rid . ' and status=4',
  7458. 'asArray' => true
  7459. ) );
  7460. $tijdate = $receiptLog->getOne ( array (
  7461. 'where' => 'rid=' . $rid . ' and status=2',
  7462. 'asc' => 'rlid',
  7463. 'asArray' => true
  7464. ) );
  7465. if (! empty ( $rlInfo )) {
  7466. $rlList = $receiptLog->find ( array (
  7467. 'where' => 'rid=' . $rid,
  7468. 'asc' => 'rlid',
  7469. 'asArray' => true
  7470. ) );
  7471. }
  7472. $receiptList [0] ['rlList'] = $rlList;
  7473. $enclosurList = $enclosur->find ( array (
  7474. 'where' => 'rid=' . $rid,
  7475. 'asArray' => true
  7476. ) );
  7477. $enclosurHtml = '';
  7478. foreach ( $enclosurList as $value ) {
  7479. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7480. }
  7481. $data ['enclosurHtml'] = $enclosurHtml;
  7482. $data ['rolename'] = $rolename ['name'];
  7483. $data ['datetij'] = $tijdate ['date'];
  7484. $data ['mothHtml'] = $mothHtml;
  7485. $data ['receiptList'] = $receiptList;
  7486. $data ['receiptApprovalCount'] = count ( $receiptList );
  7487. $data ['year'] = $year;
  7488. $data ['categoryList'] = $categoryList;
  7489. $data ['staffList'] = $staffList;
  7490. $data ['cid'] = $cid;
  7491. $data ['sid'] = $sid;
  7492. $data ['status'] = 0;
  7493. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7494. $ap = 4;
  7495. } else
  7496. $data ['status'] = $receiptList [0] ['status'];
  7497. if ($receiptList [0] ['status'] == 4) {
  7498. $data ['status'] = 5;
  7499. $ap = 0;
  7500. }
  7501. $data ['ap'] = $ap;
  7502. $data ['memu'] = "receipt";
  7503. $data ['staff'] = $this->staff;
  7504. $data ['receiptMemu'] = 'approval';
  7505. $data ['verifyId'] = $this->verifyId;
  7506. $data ['executeId'] = $this->executeId;
  7507. $this->render ( "/admin/saeaReportListReport", $data );
  7508. }
  7509. function approvalEdi() {
  7510. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7511. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7512. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7513. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7514. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7515. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7516. if (empty ( $status ))
  7517. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7518. $vidList = array ();
  7519. $button = 0;
  7520. Doo::loadModel ( 'verify' );
  7521. Doo::loadModel ( 'receipt' );
  7522. Doo::loadModel ( 'staff' );
  7523. $staff = new staff ();
  7524. $receipt = new receipt ();
  7525. $verify = new verify ();
  7526. Doo::loadModel ( 'L_category' );
  7527. $Lcategory = new L_category ();
  7528. Doo::loadModel ( 'enclosur' );
  7529. $enclosur = new enclosur ();
  7530. // user verify ID
  7531. $verifyDetail = $verify->find ( array (
  7532. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7533. 'asArray' => true
  7534. ) );
  7535. foreach ( $verifyDetail as $key => $value ) {
  7536. array_push ( $vidList, $value ['vid'] );
  7537. }
  7538. $vid = implode ( ",", $vidList );
  7539. if (empty ( $verifyDetail ))
  7540. $vid = 0;
  7541. $categoryList = $Lcategory->find ( array (
  7542. 'asArray' => true
  7543. ) );
  7544. $staffList = $staff->find ( array (
  7545. 'where' => 'cid=' . $cid,
  7546. 'asArray' => true
  7547. ) );
  7548. $ap = "";
  7549. if ($status == 4) {
  7550. $ap = 4;
  7551. $status = 2;
  7552. }
  7553. // get Receipt By verifyID status 2
  7554. $receiptList = $receipt->find ( array (
  7555. 'where' => 'rid =' . $rid,
  7556. 'desc' => 'rid',
  7557. 'asArray' => true
  7558. ) );
  7559. $Locate = 0;
  7560. $roleId = 0;
  7561. if ($ap == 4)
  7562. $status = 4;
  7563. foreach ( $receiptList as $key => $value ) {
  7564. $receiptList [$key] ['Locate'] = $Locate;
  7565. $Locate ++;
  7566. $receiptList [$key] ['reviseDetail'] = array ();
  7567. if (! empty ( $value ['reviseDetail'] ))
  7568. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7569. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7570. $categoryDetil = $Lcategory->getOne ( array (
  7571. 'where' => 'cid=' . $value ['cid'],
  7572. 'asArray' => true
  7573. ) );
  7574. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7575. // 检测编辑状态
  7576. $verifyList = $verify->getOne ( array (
  7577. 'where' => 'vid=' . $value ['verify'],
  7578. 'asArray' => true
  7579. ) );
  7580. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7581. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7582. // print_r($verifyList);
  7583. //
  7584. // if (empty($verifyStaff)){
  7585. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7586. // $verifyList[0]['status']=4;$button=4;
  7587. // }
  7588. //
  7589. // }else{
  7590. //
  7591. // }
  7592. // die;
  7593. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7594. // echo array_search("green",$a);
  7595. //
  7596. Doo::loadModel ( 'role' );
  7597. $role = new role ();
  7598. // print_r($verifyList);
  7599. $flag = true;
  7600. $roleKey = 0;
  7601. $endStaffArray = array ();
  7602. $roleArrayCopy = array ();
  7603. foreach ( $verifyList as $k => $v ) {
  7604. // init verifyStaff
  7605. if ($v [1] == 'ROLE') {
  7606. if (! empty ( $verifyStaff )) {
  7607. $endStaffArray = end ( $verifyStaff );
  7608. if ($v [0] == $endStaffArray ['nextStaff']) {
  7609. $roleId = $v [0];
  7610. }
  7611. }
  7612. $roleVerify = json_decode ( $v [3], true );
  7613. $roleKey = $k;
  7614. $roleArray = array ();
  7615. $rolename = $role->getOne ( array (
  7616. 'where' => 'rid=' . $v [0],
  7617. 'asArray' => true
  7618. ) );
  7619. foreach ( $roleVerify as $o => $p ) {
  7620. $staffID = explode ( '_', $p );
  7621. $staffInfo = $staff->getOne ( array (
  7622. 'where' => 'sid=' . $staffID [0],
  7623. 'asArray' => true
  7624. ) );
  7625. // print_r($staffID);
  7626. $exp = array (
  7627. 0 => $staffInfo ['sid'],
  7628. 1 => $staffID [1],
  7629. 2 => $staffInfo ['avatar'],
  7630. 'date' => '',
  7631. 'date' => '',
  7632. 'opinion' => '',
  7633. 'status' => '',
  7634. 'rolename' => $rolename ['name']
  7635. );
  7636. array_push ( $roleArray, $exp );
  7637. }
  7638. $roleArrayCopy [$v [0]] = $roleArray;
  7639. // $verifyList[$k]['roleArray']=$roleArray;
  7640. }
  7641. // print_r($roleArray);
  7642. $verifyList [$k] ['date'] = "";
  7643. $verifyList [$k] ['opinion'] = "";
  7644. $verifyList [$k] ['status'] = "";
  7645. if (empty ( $verifyStaff )) {
  7646. $verifyList [$k] ['date'] = "";
  7647. $verifyList [$k] ['opinion'] = "";
  7648. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7649. $verifyList [$k] ['status'] = 4;
  7650. $button = 4;
  7651. $flag = false;
  7652. }
  7653. } else {
  7654. foreach ( $verifyStaff as $m => $u ) {
  7655. if ($v [0] == $m) {
  7656. $verifyList [$k] ['date'] = $u ['date'];
  7657. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7658. $verifyList [$k] ['status'] = $u ['status'];
  7659. $flag = false;
  7660. break;
  7661. }
  7662. }
  7663. $endStaffArray = end ( $verifyStaff );
  7664. if (isset ( $endStaffArray ['ROLE'] )) {
  7665. } else {
  7666. $endKey = key ( $verifyStaff );
  7667. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7668. $button = 4;
  7669. $verifyList [$k] ['status'] = 4;
  7670. }
  7671. }
  7672. // print_r($endStaffArray);die;
  7673. // if (empty($verifyStaff)){
  7674. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7675. // $verifyList[$k]['status']=4;$button=4;
  7676. // }
  7677. //
  7678. // }else{
  7679. //
  7680. // }
  7681. // if($flag){//检测可编辑
  7682. // if($v[0]==$this->staff[0]['sid']){
  7683. // $verifyList[$k]['status']=4;$button=4;
  7684. // }
  7685. // }
  7686. }
  7687. }
  7688. $rolename ['name'] = '';
  7689. if (! empty ( $roleId )) {
  7690. Doo::loadModel ( 'role' );
  7691. $role = new role ();
  7692. $rolename = $role->getOne ( array (
  7693. 'where' => 'rid=' . $roleId,
  7694. 'asArray' => true
  7695. ) );
  7696. }
  7697. if (! empty ( $verifyStaff ))
  7698. $endStaffArray = end ( $verifyStaff );
  7699. $KOP = false;
  7700. foreach ( $roleArrayCopy as $P => $A ) {
  7701. foreach ( $A as $MKI => $AVL ) {
  7702. if (! empty ( $verifyStaff )) {
  7703. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7704. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7705. $button = 4;
  7706. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7707. }
  7708. foreach ( $verifyStaff as $m => $u ) {
  7709. $AVLFK = $AVL [0] . '_R';
  7710. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7711. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7712. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7713. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7714. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7715. break;
  7716. }
  7717. }
  7718. } else {
  7719. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7720. $button = 4;
  7721. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7722. }
  7723. }
  7724. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7725. $KOP = true;
  7726. }
  7727. }
  7728. // print_r($roleArrayCopy);
  7729. // echo $roleKey;
  7730. foreach ( $roleArrayCopy as $k => $v ) {
  7731. foreach ( $verifyList as $m => $n ) {
  7732. if ($n [0] == $k) {
  7733. array_splice ( $verifyList, $m, 1, $v );
  7734. }
  7735. }
  7736. }
  7737. // if ($KOP)
  7738. // array_splice($verifyList,$roleKey,1,$roleArray);
  7739. // print_r($verifyList);
  7740. $receiptList [$key] ['verifyList'] = $verifyList;
  7741. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7742. 'where' => 'sid=' . $value ['staff'],
  7743. 'asArray' => true
  7744. ) );
  7745. $receiptList [$key] ['button'] = $button;
  7746. }
  7747. // $data['verifyDetail']=$verifyDetail;
  7748. $mothHtml = "";
  7749. for($i = 1; $i <= 12; $i ++) {
  7750. if ($month == $i)
  7751. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7752. else
  7753. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7754. }
  7755. // 获取审批日志
  7756. Doo::loadModel ( 'receiptLog' );
  7757. $receiptLog = new receiptLog ();
  7758. $rlList = array ();
  7759. $rlInfo = $receiptLog->getOne ( array (
  7760. 'where' => 'rid=' . $rid . ' and status=4',
  7761. 'asArray' => true
  7762. ) );
  7763. $tijdate = $receiptLog->getOne ( array (
  7764. 'where' => 'rid=' . $rid . ' and status=2',
  7765. 'asc' => 'rlid',
  7766. 'asArray' => true
  7767. ) );
  7768. if (! empty ( $rlInfo )) {
  7769. $rlList = $receiptLog->find ( array (
  7770. 'where' => 'rid=' . $rid,
  7771. 'asc' => 'rlid',
  7772. 'asArray' => true
  7773. ) );
  7774. }
  7775. $receiptList [0] ['rlList'] = $rlList;
  7776. $enclosurList = $enclosur->find ( array (
  7777. 'where' => 'rid=' . $rid,
  7778. 'asArray' => true
  7779. ) );
  7780. $enclosurHtml = '';
  7781. foreach ( $enclosurList as $value ) {
  7782. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7783. }
  7784. $data ['enclosurHtml'] = $enclosurHtml;
  7785. $data ['rolename'] = $rolename ['name'];
  7786. $data ['datetij'] = $tijdate ['date'];
  7787. $data ['mothHtml'] = $mothHtml;
  7788. $data ['receiptList'] = $receiptList;
  7789. $data ['receiptApprovalCount'] = count ( $receiptList );
  7790. $data ['status'] = $status;
  7791. $data ['year'] = $year;
  7792. $data ['categoryList'] = $categoryList;
  7793. $data ['staffList'] = $staffList;
  7794. $data ['cid'] = $cid;
  7795. $data ['sid'] = $sid;
  7796. $data ['ap'] = $ap;
  7797. $data ['memu'] = "receipt";
  7798. $data ['staff'] = $this->staff;
  7799. $data ['receiptMemu'] = 'approval';
  7800. $data ['verifyId'] = $this->verifyId;
  7801. $data ['executeId'] = $this->executeId;
  7802. $this->render ( "/admin/saeaReportListReport", $data );
  7803. }
  7804. function remittanceHky() {
  7805. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7806. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7807. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7808. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7809. $page_size = 15;
  7810. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7811. Doo::loadModel ( 'receipt' );
  7812. $receipt = new receipt ();
  7813. Doo::loadModel ( 'staff' );
  7814. $staff = new staff ();
  7815. $dateCondition = " and Year(executeDate) =" . $year;
  7816. if ($moth != 'MONTH')
  7817. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7818. if ($day != 'DAY' && $moth != 'MONTH')
  7819. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7820. $sql = ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition;
  7821. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7822. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7823. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7824. $dayList = $receipt->find ( array (
  7825. 'select' => 'executeDate,sum(amount) as amount',
  7826. 'where' => $sql,
  7827. 'desc' => 'executeDate',
  7828. 'groupby' => 'executeDate',
  7829. 'limit' => $limit,
  7830. 'asArray' => true
  7831. ) );
  7832. // print_r($dayList);
  7833. foreach ( $dayList as $key => $value ) {
  7834. $remitString = "";
  7835. $receiptList = $receipt->find ( array (
  7836. 'select' => 'rid,executeDate,amount,staff,cid',
  7837. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7838. 'desc' => 'executeDate',
  7839. 'asArray' => true
  7840. ) );
  7841. foreach ( $receiptList as $k => $v ) {
  7842. $sinfo = $staff->getOne ( array (
  7843. 'select' => 'username,category',
  7844. 'where' => ' sid=' . $v ['staff'],
  7845. 'asArray' => true
  7846. ) );
  7847. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7848. }
  7849. $dayList [$key] ['staff'] = $remitString;
  7850. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7851. }
  7852. // print_r($dayList);
  7853. $mothHtml = "";
  7854. for($i = 1; $i <= 12; $i ++) {
  7855. if ($moth == $i)
  7856. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7857. else
  7858. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7859. }
  7860. $dayHtml = "";
  7861. if ($day != "DAY" || $moth != "MONTH") {
  7862. for($i = 1; $i <= 31; $i ++) {
  7863. if ($day == $i)
  7864. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7865. else
  7866. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7867. }
  7868. }
  7869. $dateHtml = "";
  7870. $now = date ( "Y" );
  7871. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7872. if ($YEARD <= $now) {
  7873. $dateHtml .= '<option ';
  7874. if ($year == $YEARD) {
  7875. $dateHtml .= 'selected ';
  7876. }
  7877. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7878. }
  7879. }
  7880. $data ['dateHtml'] = $dateHtml;
  7881. $data ['page'] = $pageinfo;
  7882. $data ['year'] = $year;
  7883. $data ['moth'] = $moth;
  7884. $data ['day'] = $day;
  7885. $data ['get'] = $get;
  7886. $data ['dayHtml'] = $dayHtml;
  7887. $data ['mothHtml'] = $mothHtml;
  7888. $data ['receiptList'] = $dayList;
  7889. $data ['memu'] = "receipt";
  7890. $data ['staff'] = $this->staff;
  7891. $data ['receiptMemu'] = 'remittanceHky';
  7892. $data ['verifyId'] = $this->verifyId;
  7893. $data ['executeId'] = $this->executeId;
  7894. $this->render ( "/admin/remittanceHky", $data );
  7895. }
  7896. function remittancep() {
  7897. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7898. Doo::loadModel ( 'receipt' );
  7899. $receipt = new receipt ();
  7900. Doo::loadModel ( 'staff' );
  7901. $staff = new staff ();
  7902. Doo::loadClass ( 'XDeode' );
  7903. $XDeode = new XDeode ( 5 );
  7904. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7905. $rplist = $receipt->find ( array (
  7906. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7907. 'asArray' => true
  7908. ) );
  7909. $dayList = $receipt->find ( array (
  7910. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7911. 'desc' => 'executeDate',
  7912. 'groupby' => 'staff',
  7913. 'asArray' => true
  7914. ) );
  7915. $html = '';
  7916. foreach ( $dayList as $key => $value ) {
  7917. $sinfo = $staff->getOne ( array (
  7918. 'select' => 'username,category',
  7919. 'where' => ' sid=' . $value ['staff'],
  7920. 'asArray' => true
  7921. ) );
  7922. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  7923. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  7924. $au = 0;
  7925. foreach ( $rplist as $k => $v ) {
  7926. if ($value ['staff'] == $v ['staff']) {
  7927. $html .= '<tr><td><a href="#saea-detail" node-invoice="INFO" data-iskey="' . $XDeode->encode ( $v ['rid'] ) . '" data-toggle="modal">' . $v ['receiptOrder'] . '</a></td><td class="taR">¥' . $v ['amount'] . '</td></tr>';
  7928. $au += $v ['amount'];
  7929. }
  7930. }
  7931. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  7932. }
  7933. $data ['html'] = $html;
  7934. $data ['memu'] = "receipt";
  7935. $data ['staff'] = $this->staff;
  7936. $data ['receiptMemu'] = 'remittanceHky';
  7937. $data ['verifyId'] = $this->verifyId;
  7938. $data ['executeId'] = $this->executeId;
  7939. $this->render ( "/admin/remittancep", $data );
  7940. }
  7941. function ajaxGetReceiptDetails() {
  7942. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  7943. Doo::loadClass ( 'XDeode' );
  7944. $XDeode = new XDeode ( 5 );
  7945. $rid = $XDeode->decode ( $rid );
  7946. if (empty ( $rid )) {
  7947. echo json_encode ( array (
  7948. 'status' => 2,
  7949. 'msg' => 'illegal request'
  7950. ) );
  7951. die ();
  7952. }
  7953. Doo::loadModel ( 'receipt' );
  7954. $receipt = new receipt ();
  7955. Doo::loadModel ( 'staff' );
  7956. $staff = new staff ();
  7957. $rinfo = $receipt->getOne ( array (
  7958. 'where' => 'rid= ' . $rid,
  7959. 'asArray' => true
  7960. ) );
  7961. $sinfo = $staff->getOne ( array (
  7962. 'select' => 'username,category',
  7963. 'where' => ' sid=' . $rinfo ['staff'],
  7964. 'asArray' => true
  7965. ) );
  7966. $rinfo ['reviseDetail'] = array ();
  7967. if (! empty ( $rinfo ['reviseDetail'] ))
  7968. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  7969. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  7970. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  7971. $rinfo ['category'] = $sinfo ['category'];
  7972. $verifyStaff = array ();
  7973. if (! empty ( $rinfo ['verifyStaff'] ))
  7974. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  7975. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  7976. $rinfo ['relust'] = $relust;
  7977. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  7978. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  7979. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  7980. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  7981. // 费用执行人相关数据
  7982. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  7983. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  7984. foreach ( $executeCopy as $k => $v ) {
  7985. $executeCopy [$k] ['date'] = '';
  7986. $executeCopy [$k] ['opinion'] = '';
  7987. $executeCopy [$k] ['status'] = '';
  7988. if (! empty ( $executeStaff ))
  7989. foreach ( $executeStaff as $m => $u ) {
  7990. if ($v [0] == $m) {
  7991. $executeCopy [$k] ['date'] = $u ['date'];
  7992. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  7993. $executeCopy [$k] ['status'] = $u ['status'];
  7994. break;
  7995. }
  7996. }
  7997. }
  7998. $rinfo ['executeCopy'] = $executeCopy;
  7999. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8000. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8001. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8002. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8003. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8004. $html .= '<tr><th>' . $value ['name'] . '</th>
  8005. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8006. }
  8007. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8008. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8009. <tr><th class="taC" colspan="2">费用说明</th>
  8010. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8011. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8012. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8013. </tbody></table>';
  8014. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8015. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8016. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8017. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8018. $html .= '<tr><th>' . $value ['name'] . '</th>
  8019. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8020. }
  8021. $html .= '<tr><th class="taR">合计</th>
  8022. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8023. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8024. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8025. $html .= '<tr><th>' . $value ['name'] . '</th>
  8026. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8027. }
  8028. $html .= '<tr><th class="taR">合计</th>
  8029. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8030. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8031. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8032. $html .= '<tr><th>' . $value ['name'] . '</th>
  8033. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8034. }
  8035. $html .= '<tr><th class="taR">合计</th>
  8036. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8037. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8038. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8039. $html .= '<tr><th>' . $value ['name'] . '</th>
  8040. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8041. }
  8042. $html .= '<tr><th class="taR">合计</th>
  8043. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8044. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8045. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8046. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8047. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8048. }
  8049. $html .= '<tr><th class="taR">合计</th>
  8050. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8051. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8052. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8053. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8054. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8055. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8056. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8057. <tr';
  8058. if ($rinfo ['relust'] >= 0) {
  8059. $html .= 'class="success"';
  8060. } else {
  8061. $html .= 'class="error"';
  8062. }
  8063. $html .= '><td class="taR"><b>借款结余</b></td>
  8064. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8065. </tbody></table>
  8066. ';
  8067. }
  8068. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8069. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8070. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8071. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8072. $html .= '<tr><th>' . $value ['name'] . '</th>
  8073. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8074. }
  8075. $html .= '<tr><th class="taR">合计</th>
  8076. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8077. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8078. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8079. <tr><th class="taC" colspan="2">费用说明</th>
  8080. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8081. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8082. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8083. </tbody></table>';
  8084. } else {
  8085. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8086. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8087. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8088. $html .= '<tr><th>' . $value ['name'] . '</th>
  8089. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8090. }
  8091. $html .= '<tr><th class="taR">合计</th>
  8092. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8093. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8094. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8095. $html .= '<tr><th>' . $value ['name'] . '</th>
  8096. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8097. }
  8098. $html .= '<tr><th class="taR">合计</th>
  8099. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8100. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8101. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8102. $html .= '<tr><th>' . $value ['name'] . '</th>
  8103. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8104. }
  8105. $html .= '<tr><th class="taR">合计</th>
  8106. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8107. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8108. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8109. $html .= '<tr><th>' . $value ['name'] . '</th>
  8110. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8111. }
  8112. $html .= '<tr><th class="taR">合计</th>
  8113. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8114. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8115. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8116. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8117. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8118. }
  8119. $html .= '<tr><th class="taR">合计</th>
  8120. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8121. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8122. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8123. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8124. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8125. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8126. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8127. $html .= '</tbody></table>';
  8128. /*
  8129. * <table class="table table-bordered table-condensed table-hover"> <tbody> <tr><th colspan="2" class="taC">日常相关费用</th></tr> <!-- loop receiptList' value.accountItem.日常相关费用 --> <tr><th>{{receiptList' value' value.name}}</th><td width="140" class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptList' value.accountItem.cSum.agencySum}}</td></tr> <tr><th colspan="2" class="taC">差旅相关费用</th></tr> <!-- loop receiptDetail' value.accountItem.差旅相关费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.travelSum}}</td></tr> <tr><th colspan="2" class="taC">培训班费用</th></tr> <!-- loop receiptDetail' value.accountItem.培训班费用 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.trainSum}}</td></tr> <tr><th colspan="2" class="taC">其他</th></tr> <!-- loop receiptDetail' value.accountItem.其他 --> <tr><th>{{receiptDetail' value' value.name}}</th><td width="140" class="taR">¥{{receiptDetail' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colGreen taR">¥{{receiptDetail' value.accountItem.cSum.otherSum}}</td></tr> <tr><th colspan="2" class="taC">报销金额调整</th></tr> <!-- loop receiptList' value.reviseDetail --> <tr><th><span class="interval">|</span>{{receiptList' value' value.name}}:{{receiptList' value' value.description}}</th><td class="taR">¥{{receiptList' value' value.price}}</td></tr> <!-- endloop --> <tr><th class="taR">合计</th><td class="colOrange taR">¥{{receiptList' value.revisePrice}}</td></tr> <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr> <tr><th style="text-align:center" colspan="2">{{receiptDetail' value.category}}</th></tr> <tr><th class="taC" colspan="2">报销说明</th></tr> <tr><td colspan="2">{{receiptDetail' value.explanation}}</td></tr> <tr class="warning"><td class="taR"><b>({{receiptDetail' value.receiptOrder}})本次报销费用合计</b></td> <td class="colGreed taR"><b style="font-size:24px">¥{{receiptDetail' value.sum}}</b><br>{{receiptDetail' value.sumCN}}</td></tr> </tbody> </table>
  8130. */
  8131. }
  8132. // print_r($verifyStaff);die;
  8133. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8134. foreach ( $verifyStaff as $key => $value ) {
  8135. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8136. $sinfo = $staff->getOne ( array (
  8137. 'select' => 'username',
  8138. 'where' => ' sid=' . $key,
  8139. 'asArray' => true
  8140. ) );
  8141. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8142. }
  8143. $html .= '</tbody></table>';
  8144. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8145. foreach ( $rinfo ['executeCopy'] as $value ) {
  8146. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8147. }
  8148. $html .= '</tbody></table>';
  8149. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8150. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8151. </tr></table>';
  8152. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8153. echo json_encode ( array (
  8154. 'status' => 1,
  8155. 'html' => $html
  8156. ) );
  8157. die ();
  8158. }
  8159. /**
  8160. * 删除附件
  8161. */
  8162. function ajaxRemEnclousur() {
  8163. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8164. if (empty ( $key ))
  8165. echo json_encode ( array (
  8166. 'status' => 2
  8167. ) );
  8168. Doo::loadModel ( 'enclosur' );
  8169. $enclosur = new enclosur ();
  8170. $enclosur->delEnclosurByEid ( $key );
  8171. echo json_encode ( array (
  8172. 'status' => 1
  8173. ) );
  8174. }
  8175. function remittance() {
  8176. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8177. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8178. Doo::loadModel ( 'receipt' );
  8179. $receipt = new receipt ();
  8180. Doo::loadModel ( 'staff' );
  8181. $staff = new staff ();
  8182. $dateCondition = " and Year(pastDate) =" . $year;
  8183. if (! empty ( $month ))
  8184. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8185. // get Receipt By verifyID status 1
  8186. $receiptList = $receipt->find ( array (
  8187. 'select' => 'sum(sum) as sum,staff,pastDate',
  8188. 'where' => ' status=1' . $dateCondition,
  8189. 'desc' => 'pastDate',
  8190. 'groupby' => 'staff,pastDate',
  8191. 'asArray' => true
  8192. ) );
  8193. $dateList = $receipt->find ( array (
  8194. 'select' => 'pastDate,verifyStaff',
  8195. 'where' => ' status=1' . $dateCondition,
  8196. 'desc' => 'pastDate',
  8197. 'groupby' => 'pastDate',
  8198. 'asArray' => true
  8199. ) );
  8200. $dataList = array ();
  8201. foreach ( $dateList as $d => $a ) {
  8202. $dataList [$a ['pastDate']] = array ();
  8203. $daySum = 0;
  8204. foreach ( $receiptList as $key => $value ) {
  8205. if ($a ['pastDate'] == $value ['pastDate']) {
  8206. $oderList = $receipt->find ( array (
  8207. 'select' => 'receiptOrder',
  8208. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8209. 'asArray' => true
  8210. ) );
  8211. $list = array ();
  8212. $html = "";
  8213. foreach ( $oderList as $v ) {
  8214. array_push ( $list, $v ['receiptOrder'] );
  8215. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8216. }
  8217. $receiptList [$key] ['receiptOrder'] = $html;
  8218. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8219. $sinfo = $staff->getOne ( array (
  8220. 'select' => 'username ',
  8221. 'where' => ' sid=' . $value ['staff'],
  8222. 'asArray' => true
  8223. ) );
  8224. $receiptList [$key] ['username'] = $sinfo ['username'];
  8225. $daySum += $value ['sum'];
  8226. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8227. }
  8228. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8229. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8230. }
  8231. }
  8232. // print_r($dataList);
  8233. $data ['dataList'] = $dataList;
  8234. $mothHtml = "";
  8235. for($i = 1; $i <= 12; $i ++) {
  8236. if ($month == $i)
  8237. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8238. else
  8239. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8240. }
  8241. $data ['year'] = $year;
  8242. $data ['mothHtml'] = $mothHtml;
  8243. $data ['memu'] = "receipt";
  8244. $data ['staff'] = $this->staff;
  8245. $data ['receiptMemu'] = 'approval';
  8246. $data ['verifyId'] = $this->verifyId;
  8247. $data ['executeId'] = $this->executeId;
  8248. $this->render ( "/admin/saeaReportListPay", $data );
  8249. }
  8250. /**
  8251. * 金额调整,提高稳定性
  8252. * @return string
  8253. */
  8254. function revocationAdjustment() {
  8255. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8256. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8257. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8258. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8259. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8260. Doo::loadClass ( 'XDeode' );
  8261. $XDeode = new XDeode ( 5 );
  8262. Doo::loadModel ( 'receipt' );
  8263. $receipt = new receipt ();
  8264. $sid = $XDeode->decode ( $sidKey );
  8265. $rid = $XDeode->decode ( $ridKey );
  8266. $reviseKey = $XDeode->decode ( $reviseKey );
  8267. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8268. die ( 'illegal request' );
  8269. $receiptDetail = $receipt->getOne ( array (
  8270. 'where' => 'rid=' . $rid,
  8271. 'asArray' => true
  8272. ) );
  8273. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8274. die ( 'illegal request' );
  8275. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8276. if (! isset ( $reviseDetail [$reviseKey] ))
  8277. die ( 'illegal request' );
  8278. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8279. unset ( $reviseDetail [$reviseKey] );
  8280. $revisePrice = 0;
  8281. foreach ( $reviseDetail as $key => $value ) {
  8282. $revisePrice += $value ['price'];
  8283. }
  8284. $reviseDetailString = json_encode ( $reviseDetail );
  8285. $receipt->reviseDetail = $reviseDetailString;
  8286. $receipt->sum = $receiptDetail ['sum'] - $price;
  8287. $receipt->revisePrice = $revisePrice;
  8288. $receipt->update ( array (
  8289. 'where' => 'rid=' . $rid
  8290. ) );
  8291. return '/receiptburEdi/' . $rid;
  8292. } else
  8293. die ( 'illegal request2' );
  8294. }
  8295. function updateApprovalReceipt() {
  8296. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8297. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8298. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8299. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8300. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8301. if (! empty ( $rid )) {
  8302. Doo::loadModel ( "verify" );
  8303. $verify = new verify ();
  8304. Doo::loadModel ( "receiptDetail" );
  8305. $receiptDetailObj = new receiptDetail ();
  8306. Doo::loadModel ( "itemStatistics" );
  8307. Doo::loadModel ( "statistics" );
  8308. $statistics = new statistics ();
  8309. $itemStatistics = new itemStatistics ();
  8310. Doo::loadModel ( "receipt" );
  8311. $receipt = new receipt ();
  8312. $receiptDetail = $receipt->getOne ( array (
  8313. 'where' => 'rid=' . $rid . ' and status=2 ',
  8314. 'asArray' => true
  8315. ) );
  8316. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8317. $nsflag = true;
  8318. foreach ( $nslist as $value ) {
  8319. if ($value == $this->staff ['0'] ['sid']) {
  8320. $nsflag = false;
  8321. break;
  8322. }
  8323. }
  8324. if (empty ( $receiptDetail ) || $nsflag)
  8325. return "/approvalExpenses/pendApproval";
  8326. $verifyDetail = $verify->getOne ( array (
  8327. 'where' => ' vid =' . $receiptDetail ['verify'],
  8328. 'asArray' => true
  8329. ) );
  8330. $verifyString = $verifyDetail ['staff'];
  8331. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8332. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8333. if (empty ( $opinion )) {
  8334. if ($status == 3)
  8335. $opinion = "终止";
  8336. else
  8337. $opinion = "同意支付";
  8338. }
  8339. $nowStaff = 0;
  8340. $nowStaffList = array ();
  8341. if (empty ( $verifyStaff )) {
  8342. // 还需加入是否已经进入角色审批
  8343. if ($verifyDetail [0] [1] == 'ROLE') {
  8344. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8345. foreach ( $vStaffString as $key => $value ) {
  8346. $staffK = explode ( "_", $value );
  8347. if ($staffK [0] != $this->staff [0] ['sid'])
  8348. array_push ( $nowStaffList, $staffK [0] );
  8349. }
  8350. // print_r($verifyDetail);
  8351. // die;
  8352. if (! empty ( $nowStaffList )) {
  8353. $nowStaff = implode ( ',', $nowStaffList );
  8354. $verifyStaff = array (
  8355. $this->staff [0] ['sid'] . "_R" => array (
  8356. 'date' => date ( 'Y-m-d' ),
  8357. 'opinion' => $opinion,
  8358. 'status' => $status,
  8359. 'nextStaff' => $verifyDetail [0] [0],
  8360. 'ROLE' => 1
  8361. )
  8362. );
  8363. } else {
  8364. $nowStaff = $verifyDetail [1] [0];
  8365. $verifyStaff = array (
  8366. $this->staff [0] ['sid'] . "_R" => array (
  8367. 'date' => date ( 'Y-m-d' ),
  8368. 'opinion' => $opinion,
  8369. 'status' => $status,
  8370. 'nextStaff' => $verifyDetail [1] [0]
  8371. )
  8372. );
  8373. }
  8374. } else {
  8375. if ($verifyDetail [1] [1] == 'ROLE') {
  8376. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8377. // echo "dd";
  8378. foreach ( $vStaffString as $key => $value ) {
  8379. $staffK = explode ( "_", $value );
  8380. array_push ( $nowStaffList, $staffK [0] );
  8381. }
  8382. $nowStaff = implode ( ',', $nowStaffList );
  8383. $verifyStaff = array (
  8384. $this->staff [0] ['sid'] => array (
  8385. 'date' => date ( 'Y-m-d' ),
  8386. 'opinion' => $opinion,
  8387. 'status' => $status,
  8388. 'nextStaff' => $verifyDetail [1] [0],
  8389. 'ROLE' => 1
  8390. )
  8391. );
  8392. } else {
  8393. $nowStaff = $verifyDetail [1] [0];
  8394. $verifyStaff = array (
  8395. $this->staff [0] ['sid'] => array (
  8396. 'date' => date ( 'Y-m-d' ),
  8397. 'opinion' => $opinion,
  8398. 'status' => $status,
  8399. 'nextStaff' => $verifyDetail [1] [0]
  8400. )
  8401. );
  8402. }
  8403. }
  8404. if ($status == 3)
  8405. $verifyStaff = array (
  8406. 'final' => $status,
  8407. $this->staff [0] ['sid'] => array (
  8408. 'date' => date ( 'Y-m-d' ),
  8409. 'opinion' => $opinion,
  8410. 'status' => $status
  8411. )
  8412. );
  8413. $vStaffString = json_encode ( $verifyStaff );
  8414. $receipt->nowStaff = $nowStaff;
  8415. $receipt->verifyStaff = $vStaffString;
  8416. } else {
  8417. $VS = end ( $verifyStaff );
  8418. // 非角色审批
  8419. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8420. $nextStaff = 0;
  8421. $roleSTF = false;
  8422. foreach ( $verifyDetail as $key => $value ) {
  8423. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8424. if (isset ( $verifyDetail [$key + 1] )) {
  8425. $nextStaff = $verifyDetail [$key + 1] [0];
  8426. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8427. $roleSTF = true;
  8428. }
  8429. break;
  8430. }
  8431. }
  8432. if (! $roleSTF) {
  8433. $nowStaff = $nextStaff;
  8434. $verifyStaff [$this->staff [0] ['sid']] = array (
  8435. 'date' => date ( 'Y-m-d' ),
  8436. 'opinion' => $opinion,
  8437. 'status' => $status,
  8438. 'nextStaff' => $nextStaff
  8439. );
  8440. } else {
  8441. // 获取角色下的所有用户ID
  8442. $nowStaffList = array ();
  8443. foreach ( $verifyDetail as $vfk ) {
  8444. if ($vfk [1] == 'ROLE') {
  8445. $vStaffString = json_decode ( $vfk [3] );
  8446. foreach ( $vStaffString as $key => $value ) {
  8447. $staffK = explode ( "_", $value );
  8448. array_push ( $nowStaffList, $staffK [0] );
  8449. }
  8450. }
  8451. }
  8452. $nowStaff = implode ( ',', $nowStaffList );
  8453. $verifyStaff [$this->staff [0] ['sid']] = array (
  8454. 'date' => date ( 'Y-m-d' ),
  8455. 'opinion' => $opinion,
  8456. 'status' => $status,
  8457. 'nextStaff' => $nextStaff,
  8458. 'ROLE' => 0
  8459. );
  8460. }
  8461. if ($status == 3) {
  8462. $verifyStaff ['final'] = $status;
  8463. $verifyStaff [$this->staff [0] ['sid']] = array (
  8464. 'date' => date ( 'Y-m-d' ),
  8465. 'opinion' => $opinion,
  8466. 'status' => $status
  8467. );
  8468. }
  8469. $vStaffString = json_encode ( $verifyStaff );
  8470. $receipt->nowStaff = $nowStaff;
  8471. $receipt->verifyStaff = $vStaffString;
  8472. }
  8473. // 角色审批
  8474. if (isset ( $VS ['ROLE'] )) {
  8475. // 找出角色人 当前审批角色组
  8476. $verifyJSStaff = array ();
  8477. $nowStaffList2 = array ();
  8478. foreach ( $verifyDetail as $key => $value ) {
  8479. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8480. $verifyJSStaff = json_decode ( $value [3] );
  8481. foreach ( $verifyJSStaff as $m ) {
  8482. $staffK = explode ( "_", $m );
  8483. array_push ( $nowStaffList2, $staffK [0] );
  8484. }
  8485. // print_r($nowStaffList2);
  8486. }
  8487. }
  8488. $RoleVerifyStaff = array ();
  8489. foreach ( $verifyStaff as $key => $value ) {
  8490. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8491. foreach ( $nowStaffList2 as $m ) {
  8492. if ($key == $m . "_R")
  8493. $RoleVerifyStaff [$key] = $value;
  8494. }
  8495. }
  8496. }
  8497. // print_r($verifyStaff);
  8498. // print_r($nowStaffList2);
  8499. // print_r($RoleVerifyStaff);
  8500. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8501. // print_r($verifyJSStaff);
  8502. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8503. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8504. // 下一个审批人ID
  8505. $nextStaff = 0;
  8506. $falg = false;
  8507. foreach ( $verifyDetail as $key => $value ) {
  8508. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8509. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8510. $falg = true;
  8511. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8512. $nowStaffList = array ();
  8513. foreach ( $vStaffString as $v ) {
  8514. $staffK = explode ( "_", $v );
  8515. array_push ( $nowStaffList, $staffK [0] );
  8516. }
  8517. $nowStaff = implode ( ',', $nowStaffList );
  8518. $nextStaff = $verifyDetail [$key + 1] [0];
  8519. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8520. $nextStaff = $verifyDetail [$key + 1] [0];
  8521. $nowStaff = $nextStaff;
  8522. } else
  8523. $nowStaff = '';
  8524. break;
  8525. }
  8526. }
  8527. if ($falg)
  8528. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8529. 'date' => date ( 'Y-m-d' ),
  8530. 'opinion' => $opinion,
  8531. 'status' => $status,
  8532. 'nextStaff' => $nextStaff,
  8533. 'ROLE' => 1
  8534. );
  8535. else
  8536. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8537. 'date' => date ( 'Y-m-d' ),
  8538. 'opinion' => $opinion,
  8539. 'status' => $status,
  8540. 'nextStaff' => $nextStaff
  8541. );
  8542. // print_r($verifyStaff);
  8543. // echo $nowStaff;die;
  8544. } else { // 进入下一个角色或者审批人
  8545. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8546. //
  8547. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8548. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8549. 'date' => date ( 'Y-m-d' ),
  8550. 'opinion' => $opinion,
  8551. 'status' => $status,
  8552. 'nextStaff' => $VS ['nextStaff'],
  8553. 'ROLE' => 1
  8554. );
  8555. // print_r($verifyStaff);
  8556. // die;
  8557. }
  8558. if ($status == 3) {
  8559. $verifyStaff ['final'] = $status;
  8560. $verifyStaff [$this->staff [0] ['sid']] = array (
  8561. 'date' => date ( 'Y-m-d' ),
  8562. 'opinion' => $opinion,
  8563. 'status' => $status
  8564. );
  8565. }
  8566. $vStaffString = json_encode ( $verifyStaff );
  8567. $receipt->verifyStaff = $vStaffString;
  8568. $receipt->nowStaff = $nowStaff;
  8569. // die;
  8570. // }
  8571. // print_r($verifyStaff);
  8572. // die;
  8573. }
  8574. // print_r($verifyStaff);die;
  8575. }
  8576. // print_r($verifyDetail);
  8577. $roleKey = 0;
  8578. $roleId = 0;
  8579. $verifyDetailCopy = array ();
  8580. foreach ( $verifyDetail as $k => $v ) {
  8581. if ($v [1] == 'ROLE') {
  8582. $roleId = $v [0];
  8583. $roleVerify = json_decode ( $v [3], true );
  8584. $roleKey = $k;
  8585. $roleArray = array ();
  8586. foreach ( $roleVerify as $o => $p ) {
  8587. $staffID = explode ( '_', $p );
  8588. $exp = array (
  8589. 0 => $staffID [0],
  8590. 1 => $staffID [1]
  8591. );
  8592. array_push ( $roleArray, $exp );
  8593. }
  8594. $verifyDetailCopy [$v [0]] = $roleArray;
  8595. }
  8596. }
  8597. // print_r($verifyDetail);
  8598. foreach ( $verifyDetailCopy as $k => $v ) {
  8599. foreach ( $verifyDetail as $m => $n ) {
  8600. if ($n [0] == $k) {
  8601. array_splice ( $verifyDetail, $m, 1, $v );
  8602. }
  8603. }
  8604. }
  8605. // die;
  8606. // if (!empty($roleArray))
  8607. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8608. // echo $roleId;
  8609. // print_r($verifyStaff);
  8610. // print_r($verifyDetail);
  8611. // die;
  8612. Doo::loadModel ( "receiptLog" );
  8613. $receiptLog = new receiptLog ();
  8614. // 审批日志
  8615. if (! isset ( $verifyStaff ['final'] )) {
  8616. if (! empty ( $roleId )) {
  8617. Doo::loadModel ( "role" );
  8618. $role = new role ();
  8619. $roleInfo = $role->getOne ( array (
  8620. 'where' => 'rid=' . $roleId,
  8621. 'asArray' => true
  8622. ) );
  8623. $receiptLog->rolename = $roleInfo ['name'];
  8624. }
  8625. $receiptLog->username = $this->staff [0] ['username'];
  8626. $receiptLog->uid = $this->staff [0] ['sid'];
  8627. $receiptLog->date = date ( "Y-m-d" );
  8628. $receiptLog->opinion = $opinion;
  8629. $receiptLog->img = $this->staff [0] ['avatar'];
  8630. $receiptLog->status = 1;
  8631. $receiptLog->rid = $rid;
  8632. $receiptLog->insert ();
  8633. }
  8634. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8635. $receipt->verifyBreakup = $verifyString;
  8636. $receipt->status = 3;
  8637. $receiptDetailObj->status = 3;
  8638. $receiptDetailObj->update ( array (
  8639. 'where' => 'rid=' . $rid
  8640. ) );
  8641. if (! empty ( $roleId )) {
  8642. Doo::loadModel ( "role" );
  8643. $role = new role ();
  8644. $roleInfo = $role->getOne ( array (
  8645. 'where' => 'rid=' . $roleId,
  8646. 'asArray' => true
  8647. ) );
  8648. $receiptLog->rolename = $roleInfo ['name'];
  8649. }
  8650. $receiptLog->username = $this->staff [0] ['username'];
  8651. $receiptLog->uid = $this->staff [0] ['sid'];
  8652. $receiptLog->date = date ( "Y-m-d" );
  8653. $receiptLog->opinion = $opinion;
  8654. $receiptLog->img = $this->staff [0] ['avatar'];
  8655. $receiptLog->status = 3;
  8656. $receiptLog->rid = $rid;
  8657. $receiptLog->insert ();
  8658. // 微信企业号通知
  8659. $this->setWXMsg ( $rid, 3 );
  8660. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8661. $receipt->status = 1;
  8662. $reviseSum = 0;
  8663. $receipt->verifyBreakup = $verifyString;
  8664. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8665. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8666. foreach ( $reviseDetail as $key => $value ) {
  8667. $receiptDetailObj = new receiptDetail ();
  8668. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8669. $receiptDetailObj->item = $value ['description'];
  8670. $receiptDetailObj->itemCategory = "报销金额调整";
  8671. $receiptDetailObj->price = $value ['price'];
  8672. $receiptDetailObj->date = $receiptDetail ['date'];
  8673. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8674. $receiptDetailObj->rid = $rid;
  8675. $receiptDetailObj->status = 1;
  8676. $receiptDetailObj->insert ();
  8677. $reviseSum += $value ['price'];
  8678. }
  8679. $itemStatistics = new itemStatistics ();
  8680. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8681. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8682. $itemStatistics->price = $reviseSum;
  8683. $itemStatistics->itemCategory = "报销金额调整";
  8684. $itemStatistics->date = $receiptDetail ['date'];
  8685. $itemStatistics->insert ();
  8686. }
  8687. $receiptDetailObj = new receiptDetail ();
  8688. $receiptDetailObj->status = 1;
  8689. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8690. $receiptDetailObj->update ( array (
  8691. 'where' => 'rid=' . $rid
  8692. ) );
  8693. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8694. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8695. $stat = $statistics->getOne ( array (
  8696. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8697. 'asArray' => true
  8698. ) );
  8699. if (empty ( $stat )) {
  8700. $statistics->date = $receiptDetail ['date'];
  8701. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8702. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8703. $statistics->agPrice = $receiptDetail ['sum'];
  8704. $statistics->rePrice = $reviseSum;
  8705. $statistics->insert ();
  8706. } else {
  8707. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8708. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8709. $statistics->update ( array (
  8710. 'where' => 'sid=' . $stat ['sid']
  8711. ) );
  8712. }
  8713. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8714. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8715. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8716. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8717. if ($key == "agencySum") {
  8718. $iStatistics = $itemStatistics->getOne ( array (
  8719. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8720. 'asArray' => true
  8721. ) );
  8722. if (empty ( $iStatistics )) {
  8723. $itemStatistics->cid = $receiptDetail ['cid'];
  8724. ;
  8725. $itemStatistics->staff = $receiptDetail ['staff'];
  8726. $itemStatistics->price = $value;
  8727. $itemStatistics->itemCategory = $this->AGENCY;
  8728. $itemStatistics->date = $receiptDetail ['date'];
  8729. $itemStatistics->insert ();
  8730. } else {
  8731. if (! empty ( $value )) {
  8732. $itemStatistics->price = $value + $iStatistics ['price'];
  8733. $itemStatistics->update ( array (
  8734. 'where' => 'sid=' . $iStatistics ['sid']
  8735. ) );
  8736. }
  8737. }
  8738. } elseif ($key == "travelSum") {
  8739. $iStatistics = $itemStatistics->getOne ( array (
  8740. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8741. 'asArray' => true
  8742. ) );
  8743. if (empty ( $iStatistics )) {
  8744. $itemStatistics->cid = $receiptDetail ['cid'];
  8745. $itemStatistics->staff = $receiptDetail ['staff'];
  8746. $itemStatistics->price = $value;
  8747. $itemStatistics->itemCategory = $this->TRAVEL;
  8748. $itemStatistics->date = $receiptDetail ['date'];
  8749. $itemStatistics->insert ();
  8750. } else {
  8751. if (! empty ( $value )) {
  8752. $itemStatistics->price = $value + $iStatistics ['price'];
  8753. $itemStatistics->update ( array (
  8754. 'where' => 'sid=' . $iStatistics ['sid']
  8755. ) );
  8756. }
  8757. }
  8758. } elseif ($key == "trainSum") {
  8759. $iStatistics = $itemStatistics->getOne ( array (
  8760. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8761. 'asArray' => true
  8762. ) );
  8763. if (empty ( $iStatistics )) {
  8764. $itemStatistics->cid = $receiptDetail ['cid'];
  8765. $itemStatistics->staff = $receiptDetail ['staff'];
  8766. $itemStatistics->price = $value;
  8767. $itemStatistics->itemCategory = $this->TRAIN;
  8768. $itemStatistics->date = $receiptDetail ['date'];
  8769. $itemStatistics->insert ();
  8770. } else {
  8771. if (! empty ( $value )) {
  8772. $itemStatistics->price = $value + $iStatistics ['price'];
  8773. $itemStatistics->update ( array (
  8774. 'where' => 'sid=' . $iStatistics ['sid']
  8775. ) );
  8776. }
  8777. }
  8778. } elseif ($key == "otherSum") {
  8779. $iStatistics = $itemStatistics->getOne ( array (
  8780. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8781. 'asArray' => true
  8782. ) );
  8783. if (empty ( $iStatistics )) {
  8784. $itemStatistics->cid = $receiptDetail ['cid'];
  8785. $itemStatistics->staff = $receiptDetail ['staff'];
  8786. $itemStatistics->price = $value;
  8787. $itemStatistics->itemCategory = $this->OTHER;
  8788. $itemStatistics->date = $receiptDetail ['date'];
  8789. $itemStatistics->insert ();
  8790. } else {
  8791. if (! empty ( $value )) {
  8792. $itemStatistics->price = $value + $iStatistics ['price'];
  8793. $itemStatistics->update ( array (
  8794. 'where' => 'sid=' . $iStatistics ['sid']
  8795. ) );
  8796. }
  8797. }
  8798. }
  8799. }
  8800. $receipt->pastDate = date ( "Y-m-d" );
  8801. // 微信企业号通知
  8802. $this->setWXMsg ( $rid, 1 );
  8803. }
  8804. //是否有流水
  8805. Doo::loadModel ( 'wasteBook' );
  8806. $wasteBook = new wasteBook ();
  8807. $accountType=3;
  8808. if ($receiptDetail['Rtype']==1){
  8809. $accountType=2;
  8810. }elseif($receiptDetail['Rtype']==2){
  8811. $accountType=4;
  8812. }
  8813. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8814. if (empty($wbDetail)){
  8815. $receipt->amount = $amount;
  8816. }
  8817. $receipt->update ( array (
  8818. 'where' => ' rid = ' . $rid
  8819. ) );
  8820. // 进入下一条审批费用新加需求
  8821. $vidList = array ();
  8822. $verifyDetail = $verify->find ( array (
  8823. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8824. 'asArray' => true
  8825. ) );
  8826. foreach ( $verifyDetail as $key => $value ) {
  8827. array_push ( $vidList, $value ['vid'] );
  8828. }
  8829. $vid = implode ( ",", $vidList );
  8830. if (empty ( $verifyDetail ))
  8831. $vid = 0;
  8832. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8833. $receipt = new receipt ();
  8834. $rd = $receipt->getOne ( array (
  8835. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8836. 'asc' => 'rid',
  8837. 'asArray' => true
  8838. ) );
  8839. if (empty ( $rd )) {
  8840. return '/approvalExpenses/pendApproval';
  8841. }
  8842. if ($rd ['Rtype'] == 1) {
  8843. if ($rd ['isBK'] == 1) {
  8844. return '/receiptburEdi/' . $rd ['rid'];
  8845. } else {
  8846. return '/expensesEdi/' . $rd ['rid'];
  8847. }
  8848. } elseif ($rd ['Rtype'] == 2) {
  8849. return '/remitApproval/' . $rd ['rid'];
  8850. } else {
  8851. return '/receiptburEdi/' . $rd ['rid'];
  8852. }
  8853. // return "/approvalExpenses/pendApproval";
  8854. }
  8855. }
  8856. function expensesRetreats() {
  8857. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8858. if (! empty ( $rid )) {
  8859. // 操作记录
  8860. Doo::loadModel ( "receipt" );
  8861. $receipt = new receipt ();
  8862. Doo::loadModel ( "receiptLog" );
  8863. $receiptLog = new receiptLog ();
  8864. Doo::loadModel ( "verify" );
  8865. $verify = new verify ();
  8866. $receiptInfo = $receipt->getOne ( array (
  8867. 'where' => 'rid=' . $rid,
  8868. 'asArray' => true
  8869. ) );
  8870. $vr = $verify->getOne ( array (
  8871. 'where' => 'vid=' . $receiptInfo ['verify'],
  8872. 'asArray' => true
  8873. ) );
  8874. $jd = json_decode ( $vr ['staff'] );
  8875. $roleId = 0;
  8876. foreach ( $jd as $key => $value ) {
  8877. if ($value [1] == 'ROLE') {
  8878. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8879. if ($pos !== false) {
  8880. $roleId = $value [0];
  8881. }
  8882. }
  8883. }
  8884. // 审批日志
  8885. // echo $roleId;die;
  8886. if (! empty ( $roleId )) {
  8887. Doo::loadModel ( "role" );
  8888. $role = new role ();
  8889. $roleInfo = $role->getOne ( array (
  8890. 'where' => 'rid=' . $roleId,
  8891. 'asArray' => true
  8892. ) );
  8893. $receiptLog->rolename = $roleInfo ['name'];
  8894. }
  8895. $receiptLog->username = $this->staff [0] ['username'];
  8896. $receiptLog->uid = $this->staff [0] ['sid'];
  8897. $receiptLog->date = date ( "Y-m-d" );
  8898. $receiptLog->opinion = '撤回';
  8899. $receiptLog->img = $this->staff [0] ['avatar'];
  8900. $receiptLog->status = 4;
  8901. $receiptLog->rid = $rid;
  8902. $receiptLog->insert ();
  8903. $receipt->status = 4;
  8904. $receipt->update ( array (
  8905. 'where' => 'rid=' . $rid
  8906. ) );
  8907. // 微信企业号通知
  8908. $this->setWXMsg ( $rid, 2 );
  8909. }
  8910. // echo "ddd";
  8911. return '/approvalExpenses/pendApproval';
  8912. }
  8913. function updateCheReceipt() {
  8914. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8915. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8916. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8917. if (! empty ( $rid )) {
  8918. // 操作记录
  8919. Doo::loadModel ( "receipt" );
  8920. $receipt = new receipt ();
  8921. Doo::loadModel ( "receiptLog" );
  8922. $receiptLog = new receiptLog ();
  8923. Doo::loadModel ( "verify" );
  8924. $verify = new verify ();
  8925. $receiptInfo = $receipt->getOne ( array (
  8926. 'where' => 'rid=' . $rid . ' and status=2',
  8927. 'asArray' => true
  8928. ) );
  8929. if (empty ( $receiptInfo )) {
  8930. echo json_encode ( array (
  8931. 'status' => 2
  8932. ) );
  8933. die ();
  8934. }
  8935. $vr = $verify->getOne ( array (
  8936. 'where' => 'vid=' . $receiptInfo ['verify'],
  8937. 'asArray' => true
  8938. ) );
  8939. $jd = json_decode ( $vr ['staff'] );
  8940. $roleId = 0;
  8941. foreach ( $jd as $key => $value ) {
  8942. if ($value [1] == 'ROLE') {
  8943. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8944. if ($pos !== false) {
  8945. $roleId = $value [0];
  8946. }
  8947. }
  8948. }
  8949. // 审批日志
  8950. // echo $roleId;die;
  8951. if (! empty ( $roleId )) {
  8952. Doo::loadModel ( "role" );
  8953. $role = new role ();
  8954. $roleInfo = $role->getOne ( array (
  8955. 'where' => 'rid=' . $roleId,
  8956. 'asArray' => true
  8957. ) );
  8958. $receiptLog->rolename = $roleInfo ['name'];
  8959. }
  8960. $receiptLog->username = $this->staff [0] ['username'];
  8961. $receiptLog->uid = $this->staff [0] ['sid'];
  8962. $receiptLog->date = date ( "Y-m-d" );
  8963. $receiptLog->opinion = $opinion;
  8964. $receiptLog->img = $this->staff [0] ['avatar'];
  8965. $receiptLog->status = 4;
  8966. $receiptLog->rid = $rid;
  8967. $receiptLog->insert ();
  8968. $receipt->status = 4;
  8969. $receipt->update ( array (
  8970. 'where' => 'rid=' . $rid
  8971. ) );
  8972. // 微信企业号通知
  8973. $this->setWXMsg ( $rid, 2 );
  8974. echo json_encode ( array (
  8975. 'status' => 1
  8976. ) );
  8977. // Header("HTTP/1.1 303 See Other");
  8978. // Header("Location: /approvalExpenses/pendApproval");
  8979. die ();
  8980. }
  8981. echo json_encode ( array (
  8982. 'status' => 2
  8983. ) );
  8984. die ();
  8985. // echo "ddd";
  8986. // return '/saeaBorad';
  8987. }
  8988. function revisePrice() {
  8989. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  8990. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  8991. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8992. // echo $price;die;
  8993. if (! empty ( $rid )) {
  8994. Doo::loadModel ( "receipt" );
  8995. $receipt = new receipt ();
  8996. $receiptDetail = $receipt->getOne ( array (
  8997. 'where' => 'rid=' . $rid . ' and status=2 ',
  8998. 'asArray' => true
  8999. ) );
  9000. if (empty ( $receiptDetail ))
  9001. die ( 'illegal request' );
  9002. $reviseDetail = array ();
  9003. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9004. array_push ( $reviseDetail, array (
  9005. 'sid' => $this->staff [0] ['sid'],
  9006. 'name' => $this->staff [0] ['username'],
  9007. 'description' => $description,
  9008. 'price' => $price
  9009. ) );
  9010. $reviseDetailString = json_encode ( $reviseDetail );
  9011. $receipt->reviseDetail = $reviseDetailString;
  9012. $receipt->revisePrice = $price;
  9013. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9014. } else {
  9015. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9016. array_push ( $reviseDetail, array (
  9017. 'sid' => $this->staff [0] ['sid'],
  9018. 'name' => $this->staff [0] ['username'],
  9019. 'description' => $description,
  9020. 'price' => $price
  9021. ) );
  9022. $reviseDetailString = json_encode ( $reviseDetail );
  9023. $receipt->reviseDetail = $reviseDetailString;
  9024. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9025. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9026. }
  9027. $receipt->update ( array (
  9028. 'where' => 'rid=' . $rid
  9029. ) );
  9030. if ($receiptDetail ['Rtype'] == 1) {
  9031. if ($receiptDetail ['isBK'] == 1) {
  9032. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9033. }
  9034. } elseif ($receiptDetail ['Rtype'] == 2) {
  9035. } else {
  9036. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9037. }
  9038. }
  9039. die ( 'illegal request' );
  9040. }
  9041. function personalCollect() {
  9042. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9043. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9044. $this->showCache ( $path );
  9045. Doo::loadModel ( "receiptDetail" );
  9046. Doo::loadModel ( "itemStatistics" );
  9047. Doo::loadModel ( 'statistics' );
  9048. $statistics = new statistics ();
  9049. $itemStatistics = new itemStatistics ();
  9050. $receiptDetail = new receiptDetail ();
  9051. $receiptCollectList = $receiptDetail->find ( array (
  9052. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9053. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9054. 'groupby' => 'itemCategory,Month(date)',
  9055. 'asArray' => true
  9056. ) );
  9057. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9058. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9059. 'asArray' => true
  9060. ) );
  9061. // create collect html
  9062. $collectArray = array (
  9063. '日常相关费用' => array (),
  9064. '差旅相关费用' => array (),
  9065. '培训班费用' => array (),
  9066. '其他' => array ()
  9067. );
  9068. $adjustment = array ();
  9069. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9070. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9071. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9072. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9073. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9074. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9075. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9076. array_push ( $collectArray ['其他'], $collectHtml );
  9077. $data ['collectArray'] = $collectArray;
  9078. // statistics html
  9079. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9080. if (empty ( $stList ))
  9081. $stList = array (
  9082. 'rePrice' => 0,
  9083. 'agPrice' => 0
  9084. );
  9085. $data ['stList'] = array (
  9086. 'rePrice' => $stList ['rePrice'],
  9087. 'agPrice' => $stList ['agPrice'],
  9088. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9089. );
  9090. // Adjustment price html
  9091. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9092. array_push ( $adjustment, $collectHtml );
  9093. $data ['adjustment'] = $adjustment;
  9094. // total price html
  9095. $collectHtml = "";
  9096. $total = 0;
  9097. for($i = 1; $i <= 12; $i ++) {
  9098. $sumPrice = 0;
  9099. foreach ( $receiptCollectList as $key => $value ) {
  9100. if ($value ['month'] == $i) {
  9101. $sumPrice += $value ['price'];
  9102. }
  9103. }
  9104. if ($sumPrice == 0)
  9105. $collectHtml .= '<td class="taR">-</td>';
  9106. else
  9107. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9108. $total += $sumPrice;
  9109. }
  9110. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9111. $data ['totalPrice'] = $collectHtml;
  9112. $dateHtml = "";
  9113. $now = date ( "Y" );
  9114. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9115. if ($YEARD <= $now) {
  9116. $dateHtml .= '<option ';
  9117. if ($year == $YEARD) {
  9118. $dateHtml .= 'selected ';
  9119. }
  9120. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9121. }
  9122. }
  9123. $data ['dateHtml'] = $dateHtml;
  9124. $data ['year'] = $year;
  9125. $data ['totalYear'] = $total;
  9126. $data ['memu'] = "receipt";
  9127. $data ['staff'] = $this->staff;
  9128. $data ['receiptMemu'] = 'personalCollect';
  9129. $data ['verifyId'] = $this->verifyId;
  9130. $data ['executeId'] = $this->executeId;
  9131. // year staff status 2,4
  9132. if ($year < date ( "Y" )) {
  9133. Doo::loadModel ( 'receipt' );
  9134. $receipt = new receipt ();
  9135. $receiptList = $receipt->find ( array (
  9136. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9137. 'asArray' => true
  9138. ) );
  9139. if (empty ( $receiptList )) {
  9140. ob_start ();
  9141. $this->render ( "/admin/saea_slist_collect", $data );
  9142. $this->cacheFile ( $path );
  9143. die ();
  9144. }
  9145. }
  9146. $this->render ( "/admin/saea_slist_collect", $data );
  9147. }
  9148. function personalCollectDetail() {
  9149. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9150. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9151. $this->showCache ( $path );
  9152. Doo::loadModel ( "receiptDetail" );
  9153. Doo::loadModel ( "itemStatistics" );
  9154. Doo::loadModel ( 'statistics' );
  9155. Doo::loadModel ( 'accountItem' );
  9156. $accountItem = new accountItem ();
  9157. $statistics = new statistics ();
  9158. $itemStatistics = new itemStatistics ();
  9159. $receiptDetail = new receiptDetail ();
  9160. $receiptCollectList = $receiptDetail->find ( array (
  9161. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9162. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9163. 'groupby' => 'item,Month(date)',
  9164. 'asArray' => true
  9165. ) );
  9166. $accountList = $accountItem->find ( array (
  9167. 'asArray' => true
  9168. ) );
  9169. // create CollectDetail HTML
  9170. $collectHtml = array ();
  9171. foreach ( $accountList as $key => $value ) {
  9172. $html = "";
  9173. $asum = 0;
  9174. for($i = 1; $i <= 12; $i ++) {
  9175. $falg = true;
  9176. foreach ( $receiptCollectList as $v ) {
  9177. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9178. $asum += $v ['price'];
  9179. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9180. $falg = false;
  9181. break;
  9182. }
  9183. }
  9184. if ($falg)
  9185. $html .= '<td class="taR">-</td>';
  9186. }
  9187. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9188. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9189. }
  9190. $data ['collectHtml'] = $collectHtml;
  9191. // create Adjustment price html
  9192. $receiptCollectList = $receiptDetail->find ( array (
  9193. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9194. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9195. 'groupby' => 'itemCategory,Month(date)',
  9196. 'asArray' => true
  9197. ) );
  9198. $adjustment = array ();
  9199. $collectArray = array (
  9200. '日常相关费用' => array (),
  9201. '差旅相关费用' => array (),
  9202. '培训班费用' => array (),
  9203. '其他' => array ()
  9204. );
  9205. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9206. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9207. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9208. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9209. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9210. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9211. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9212. array_push ( $collectArray ['其他'], $collectHtml );
  9213. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9214. array_push ( $adjustment, $collectHtml );
  9215. // total price html
  9216. $collectHtml = "";
  9217. $total = 0;
  9218. for($i = 1; $i <= 12; $i ++) {
  9219. $sumPrice = 0;
  9220. foreach ( $receiptCollectList as $key => $value ) {
  9221. if ($value ['month'] == $i) {
  9222. $sumPrice += $value ['price'];
  9223. }
  9224. }
  9225. if ($sumPrice == 0)
  9226. $collectHtml .= '<td class="taR">-</td>';
  9227. else
  9228. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9229. $total += $sumPrice;
  9230. }
  9231. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9232. // statistics html
  9233. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9234. if (empty ( $stList ))
  9235. $stList = array (
  9236. 'rePrice' => 0,
  9237. 'agPrice' => 0
  9238. );
  9239. $data ['stList'] = array (
  9240. 'rePrice' => $stList ['rePrice'],
  9241. 'agPrice' => $stList ['agPrice'],
  9242. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9243. );
  9244. $data ['collectArray'] = $collectArray;
  9245. $data ['adjustment'] = $adjustment;
  9246. $data ['totalPrice'] = $collectHtml;
  9247. $data ['totalYear'] = $total;
  9248. $data ['year'] = $year;
  9249. $dateHtml = "";
  9250. $now = date ( "Y" );
  9251. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9252. if ($YEARD <= $now) {
  9253. $dateHtml .= '<option ';
  9254. if ($year == $YEARD) {
  9255. $dateHtml .= 'selected ';
  9256. }
  9257. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9258. }
  9259. }
  9260. $data ['dateHtml'] = $dateHtml;
  9261. $data ['memu'] = "receipt";
  9262. $data ['staff'] = $this->staff;
  9263. $data ['receiptMemu'] = 'personalCollect';
  9264. $data ['verifyId'] = $this->verifyId;
  9265. $data ['executeId'] = $this->executeId;
  9266. // year staff status 2,4
  9267. if ($year < date ( "Y" )) {
  9268. Doo::loadModel ( 'receipt' );
  9269. $receipt = new receipt ();
  9270. $receiptList = $receipt->find ( array (
  9271. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9272. 'asArray' => true
  9273. ) );
  9274. if (empty ( $receiptList )) {
  9275. ob_start ();
  9276. $this->render ( "/admin/saeaCollectArticles", $data );
  9277. $this->cacheFile ( $path );
  9278. die ();
  9279. }
  9280. }
  9281. $this->render ( "/admin/saeaCollectArticles", $data );
  9282. }
  9283. function companyCategoryCollect() {
  9284. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9285. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9286. $this->showCache ( $path );
  9287. Doo::loadModel ( 'L_category' );
  9288. Doo::loadModel ( 'itemStatistics' );
  9289. Doo::loadModel ( 'statistics' );
  9290. $statistics = new statistics ();
  9291. $Lcategory = new L_category ();
  9292. $itemStatistics = new itemStatistics ();
  9293. Doo::loadModel ( "receiptAuthorityManage" );
  9294. $receiptAuthorityManage = new receiptAuthorityManage ();
  9295. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9296. $cidList = array ();
  9297. foreach ( $imcStaff as $key => $value ) {
  9298. array_push ( $cidList, $value ['cid'] );
  9299. }
  9300. $cidString = implode ( ',', $cidList );
  9301. $LcategoryList = $Lcategory->find ( array (
  9302. 'where' => ' cid in (' . $cidString . ')',
  9303. 'asArray' => true
  9304. ) ); // 'staff='.$this->staff[0]['sid']." and
  9305. $itemStatisticsList = $itemStatistics->find ( array (
  9306. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9307. 'where' => " Year(date)=" . $year,
  9308. 'groupby' => 'cid,Month(date)',
  9309. 'asArray' => true
  9310. ) );
  9311. // ceatre companyCollectHtml
  9312. foreach ( $LcategoryList as $value ) {
  9313. $html = "";
  9314. $asum = 0;
  9315. for($i = 1; $i <= 12; $i ++) {
  9316. $falg = true;
  9317. foreach ( $itemStatisticsList as $v ) {
  9318. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9319. $asum += $v ['price'];
  9320. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9321. $falg = false;
  9322. break;
  9323. }
  9324. }
  9325. if ($falg)
  9326. $html .= '<td class="taR">-</td>';
  9327. }
  9328. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9329. $collectHtml [$value ['title']] = array (
  9330. 'html' => $html,
  9331. 'cid' => $value ['cid']
  9332. );
  9333. }
  9334. $data ['companyHtml'] = $collectHtml;
  9335. // total price html
  9336. $collectHtml = "";
  9337. $total = 0;
  9338. for($i = 1; $i <= 12; $i ++) {
  9339. $sumPrice = 0;
  9340. foreach ( $itemStatisticsList as $key => $value ) {
  9341. if ($value ['month'] == $i) {
  9342. $sumPrice += $value ['price'];
  9343. }
  9344. }
  9345. if ($sumPrice == 0)
  9346. $collectHtml .= '<td class="taR">-</td>';
  9347. else
  9348. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9349. $total += $sumPrice;
  9350. }
  9351. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9352. $data ['companyTotalHtml'] = $collectHtml;
  9353. $data ['total'] = $total;
  9354. // statistics html
  9355. // echo $cidString;
  9356. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9357. if (empty ( $stList ))
  9358. $stList = array (
  9359. 'rePrice' => 0,
  9360. 'agPrice' => 0
  9361. );
  9362. $data ['stList'] = array (
  9363. 'rePrice' => $stList ['rePrice'],
  9364. 'agPrice' => $stList ['agPrice'],
  9365. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9366. );
  9367. $data ['year'] = $year;
  9368. $data ['memu'] = "receipt";
  9369. $data ['staff'] = $this->staff;
  9370. $data ['receiptMemu'] = 'companyCategoryCollect';
  9371. $data ['verifyId'] = $this->verifyId;
  9372. $data ['executeId'] = $this->executeId;
  9373. $dateHtml = "";
  9374. $now = date ( "Y" );
  9375. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9376. if ($YEARD <= $now) {
  9377. $dateHtml .= '<option ';
  9378. if ($year == $YEARD) {
  9379. $dateHtml .= 'selected ';
  9380. }
  9381. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9382. }
  9383. }
  9384. $data ['dateHtml'] = $dateHtml;
  9385. // year staff status 2,4
  9386. if ($year < date ( "Y" )) {
  9387. Doo::loadModel ( 'receipt' );
  9388. $receipt = new receipt ();
  9389. $receiptList = $receipt->find ( array (
  9390. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9391. 'asArray' => true
  9392. ) );
  9393. if (empty ( $receiptList )) {
  9394. ob_start ();
  9395. $this->render ( "/admin/saeaCompanyCollect", $data );
  9396. $this->cacheFile ( $path );
  9397. die ();
  9398. }
  9399. }
  9400. $this->render ( "/admin/saeaCompanyCollect", $data );
  9401. }
  9402. function categoryCollectDetail() {
  9403. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9404. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9405. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9406. $this->showCache ( $path );
  9407. Doo::loadModel ( 'statistics' );
  9408. $statistics = new statistics ();
  9409. Doo::loadModel ( "receiptDetail" );
  9410. $receiptDetail = new receiptDetail ();
  9411. Doo::loadModel ( 'L_category' );
  9412. $Lcategory = new L_category ();
  9413. Doo::loadModel ( 'accountItem' );
  9414. $accountItem = new accountItem ();
  9415. Doo::loadModel ( "receiptAuthorityManage" );
  9416. $receiptAuthorityManage = new receiptAuthorityManage ();
  9417. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9418. $cidList = array ();
  9419. foreach ( $imcStaff as $key => $value ) {
  9420. array_push ( $cidList, $value ['cid'] );
  9421. }
  9422. $cidString = implode ( ',', $cidList );
  9423. $LcategoryList = $Lcategory->find ( array (
  9424. 'where' => 'cid in (' . $cidString . ')',
  9425. 'asArray' => true
  9426. ) );
  9427. if ($cid == 0) {
  9428. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9429. if ($cid == 0)
  9430. $cid = $LcategoryList [0] ['cid'];
  9431. }
  9432. $data ['LcategoryList'] = $LcategoryList;
  9433. $receiptCollectList = $receiptDetail->find ( array (
  9434. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9435. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9436. 'groupby' => 'item,Month(pastDate)',
  9437. 'asArray' => true
  9438. ) );
  9439. $accountList = $accountItem->find ( array (
  9440. 'asArray' => true
  9441. ) );
  9442. // create CollectDetail HTML
  9443. $collectHtml = array ();
  9444. foreach ( $accountList as $key => $value ) {
  9445. $html = "";
  9446. $asum = 0;
  9447. for($i = 1; $i <= 12; $i ++) {
  9448. $falg = true;
  9449. foreach ( $receiptCollectList as $v ) {
  9450. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9451. $asum += $v ['price'];
  9452. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9453. $falg = false;
  9454. break;
  9455. }
  9456. }
  9457. if ($falg)
  9458. $html .= '<td class="taR">-</td>';
  9459. }
  9460. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9461. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9462. }
  9463. $data ['collectHtml'] = $collectHtml;
  9464. // create Adjustment price html
  9465. $receiptCollectList = $receiptDetail->find ( array (
  9466. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9467. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9468. 'groupby' => 'itemCategory,Month(pastDate)',
  9469. 'asArray' => true
  9470. ) );
  9471. $adjustment = array ();
  9472. $collectArray = array (
  9473. '日常相关费用' => array (),
  9474. '差旅相关费用' => array (),
  9475. '培训班费用' => array (),
  9476. '内部培训费用'=>array(),
  9477. '其他' => array ()
  9478. );
  9479. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9480. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9481. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9482. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9483. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9484. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9485. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9486. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9487. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9488. array_push ( $collectArray ['其他'], $collectHtml );
  9489. $data ['collectArray'] = $collectArray;
  9490. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9491. array_push ( $adjustment, $collectHtml );
  9492. $data ['adjustment'] = $adjustment;
  9493. // total price html
  9494. $collectHtml = "";
  9495. $total = 0;
  9496. for($i = 1; $i <= 12; $i ++) {
  9497. $sumPrice = 0;
  9498. foreach ( $receiptCollectList as $key => $value ) {
  9499. if ($value ['month'] == $i) {
  9500. $sumPrice += $value ['price'];
  9501. }
  9502. }
  9503. if ($sumPrice == 0)
  9504. $collectHtml .= '<td class="taR">-</td>';
  9505. else
  9506. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9507. $total += $sumPrice;
  9508. }
  9509. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9510. // statistics html
  9511. $stList = $statistics->statisticsByCid ( $year, $cid );
  9512. if (empty ( $stList ))
  9513. $stList = array (
  9514. 'rePrice' => 0,
  9515. 'agPrice' => 0
  9516. );
  9517. $data ['stList'] = array (
  9518. 'rePrice' => $stList ['rePrice'],
  9519. 'agPrice' => $stList ['agPrice'],
  9520. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9521. );
  9522. $data ['totalYear'] = $total;
  9523. $data ['year'] = $year;
  9524. $data ['cid'] = $cid;
  9525. $data ['memu'] = "receipt";
  9526. $data ['staff'] = $this->staff;
  9527. $data ['receiptMemu'] = 'companyCategoryCollect';
  9528. $data ['verifyId'] = $this->verifyId;
  9529. $data ['executeId'] = $this->executeId;
  9530. // year staff status 2,4
  9531. if ($year < date ( "Y" )) {
  9532. Doo::loadModel ( 'receipt' );
  9533. $receipt = new receipt ();
  9534. $receiptList = $receipt->find ( array (
  9535. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9536. 'asArray' => true
  9537. ) );
  9538. if (empty ( $receiptList )) {
  9539. ob_start ();
  9540. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9541. $this->cacheFile ( $path );
  9542. die ();
  9543. }
  9544. }
  9545. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9546. }
  9547. function staffCollect() {
  9548. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9549. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9550. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9551. // $this->showCache($path);
  9552. Doo::loadModel ( 'statistics' );
  9553. $statistics = new statistics ();
  9554. Doo::loadModel ( "receiptDetail" );
  9555. $receiptDetail = new receiptDetail ();
  9556. Doo::loadModel ( 'L_category' );
  9557. $Lcategory = new L_category ();
  9558. Doo::loadModel ( 'accountItem' );
  9559. $accountItem = new accountItem ();
  9560. Doo::loadModel ( 'staff' );
  9561. $staff = new staff ();
  9562. Doo::loadModel ( 'itemStatistics' );
  9563. $itemStatistics = new itemStatistics ();
  9564. Doo::loadModel ( "receiptAuthorityManage" );
  9565. $receiptAuthorityManage = new receiptAuthorityManage ();
  9566. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9567. $cidList = array ();
  9568. foreach ( $imcStaff as $key => $value ) {
  9569. array_push ( $cidList, $value ['cid'] );
  9570. }
  9571. $cidString = implode ( ',', $cidList );
  9572. $naturecon='';
  9573. if ($nature=='ONJOB'){
  9574. $naturecon=' and (nature!=4 )';
  9575. }elseif($nature=='LEAVEJOB'){
  9576. $naturecon=' and (nature=4 )';
  9577. }else{
  9578. die ( 'illegal request--nature' );
  9579. }
  9580. // statistics html
  9581. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9582. if (empty ( $stList ))
  9583. $stList = array (
  9584. 'rePrice' => 0,
  9585. 'agPrice' => 0
  9586. );
  9587. $data ['stList'] = array (
  9588. 'rePrice' => $stList ['rePrice'],
  9589. 'agPrice' => $stList ['agPrice'],
  9590. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9591. );
  9592. // ---
  9593. $staffList = $staff->find ( array (
  9594. 'where' => 'username !="admin" '.$naturecon,
  9595. 'asArray' => true
  9596. ) );
  9597. $LcategoryList = $Lcategory->find ( array (
  9598. 'asArray' => true
  9599. ) ); // 'staff='.$this->staff[0]['sid']." and
  9600. $itemStatisticsList = $itemStatistics->find ( array (
  9601. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9602. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9603. 'groupby' => 'staff,Month(date)',
  9604. 'asArray' => true
  9605. ) );
  9606. $categoryList = $staff->find ( array (
  9607. 'select' => 'COUNT(*) as count,cid,category',
  9608. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9609. 'groupby' => 'cid',
  9610. 'asArray' => true
  9611. ) );
  9612. // print_r($itemStatisticsList);die;
  9613. // ceatre companyCollectHtml
  9614. foreach ( $categoryList as $vlu ) {
  9615. $count = $vlu ['count'] + 1;
  9616. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9617. $m1 = 0;
  9618. $m2 = 0;
  9619. $m3 = 0;
  9620. $m4 = 0;
  9621. $m5 = 0;
  9622. $m6 = 0;
  9623. $m7 = 0;
  9624. $m8 = 0;
  9625. $m9 = 0;
  9626. $m10 = 0;
  9627. $m11 = 0;
  9628. $m12 = 0;
  9629. $m13 = 0;
  9630. foreach ( $staffList as $value ) {
  9631. if ($vlu ['cid'] == $value ['cid']) {
  9632. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9633. $asum = 0;
  9634. for($i = 1; $i <= 12; $i ++) {
  9635. $falg = true;
  9636. foreach ( $itemStatisticsList as $v ) {
  9637. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9638. if ($v ['month'] == 1)
  9639. $m1 += $v ['price'];
  9640. if ($v ['month'] == 2)
  9641. $m2 += $v ['price'];
  9642. if ($v ['month'] == 3)
  9643. $m3 += $v ['price'];
  9644. if ($v ['month'] == 4)
  9645. $m4 += $v ['price'];
  9646. if ($v ['month'] == 5)
  9647. $m5 += $v ['price'];
  9648. if ($v ['month'] == 6)
  9649. $m6 += $v ['price'];
  9650. if ($v ['month'] == 7)
  9651. $m7 += $v ['price'];
  9652. if ($v ['month'] == 8)
  9653. $m8 += $v ['price'];
  9654. if ($v ['month'] == 9)
  9655. $m9 += $v ['price'];
  9656. if ($v ['month'] == 10)
  9657. $m10 += $v ['price'];
  9658. if ($v ['month'] == 11)
  9659. $m11 += $v ['price'];
  9660. if ($v ['month'] == 12)
  9661. $m12 += $v ['price'];
  9662. $asum += $v ['price'];
  9663. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9664. $falg = false;
  9665. break;
  9666. }
  9667. }
  9668. if ($falg)
  9669. $html .= '<td class="taR">-</td>';
  9670. }
  9671. $m13 += $asum;
  9672. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9673. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9674. 'html' => $html,
  9675. 'sid' => $value ['sid']
  9676. );
  9677. $html = "";
  9678. }
  9679. }
  9680. $hl = '<th class="taR">小计</th><td class="taR">¥' . $m1 . '</td><td class="taR">¥' . $m2 . '</td><td class="taR">¥' . $m3 . '</td><td class="taR">¥' . $m4 . '</td><td class="taR">¥' . $m5 . '</td>
  9681. <td class="taR">¥' . $m6 . '</td><td class="taR">¥' . $m7 . '</td><td class="taR">¥' . $m8 . '</td><td class="taR">¥' . $m9 . '</td><td class="taR">¥' . $m10 . '</td><td class="taR">¥' . $m11 . '</td>
  9682. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9683. $collectHtml [$vlu ['cid']] = array (
  9684. 'html' => $hl,
  9685. 'sid' => ''
  9686. );
  9687. }
  9688. $data ['companyHtml'] = $collectHtml;
  9689. // total price html
  9690. $collectHtml = "";
  9691. $total = 0;
  9692. for($i = 1; $i <= 12; $i ++) {
  9693. $sumPrice = 0;
  9694. foreach ( $itemStatisticsList as $key => $value ) {
  9695. if ($value ['month'] == $i) {
  9696. $sumPrice += $value ['price'];
  9697. }
  9698. }
  9699. if ($sumPrice == 0)
  9700. $collectHtml .= '<td class="taR">-</td>';
  9701. else
  9702. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9703. $total += $sumPrice;
  9704. }
  9705. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9706. $data ['companyTotalHtml'] = $collectHtml;
  9707. $data ['total'] = $total;
  9708. $data ['nature'] =$nature;
  9709. $data ['year'] = $year;
  9710. $data ['memu'] = "receipt";
  9711. $data ['staff'] = $this->staff;
  9712. $data ['receiptMemu'] = 'companyCategoryCollect';
  9713. $data ['verifyId'] = $this->verifyId;
  9714. $data ['executeId'] = $this->executeId;
  9715. if ($year <= date ( "Y" )) {
  9716. Doo::loadModel ( 'receipt' );
  9717. $receipt = new receipt ();
  9718. $receiptList = $receipt->find ( array (
  9719. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9720. 'asArray' => true
  9721. ) );
  9722. if (empty ( $receiptList )) { // generated files
  9723. ob_start ();
  9724. $this->render ( "/admin/saeaStaffCollectB", $data );
  9725. $this->cacheFile ( $path );
  9726. die ();
  9727. }
  9728. }
  9729. $this->render ( "/admin/saeaStaffCollectB", $data );
  9730. }
  9731. function staffCollectBak() {
  9732. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9733. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9734. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9735. $this->showCache ( $path );
  9736. Doo::loadModel ( 'statistics' );
  9737. $statistics = new statistics ();
  9738. Doo::loadModel ( "receiptDetail" );
  9739. $receiptDetail = new receiptDetail ();
  9740. Doo::loadModel ( 'L_category' );
  9741. $Lcategory = new L_category ();
  9742. Doo::loadModel ( 'accountItem' );
  9743. $accountItem = new accountItem ();
  9744. Doo::loadModel ( 'staff' );
  9745. $staff = new staff ();
  9746. Doo::loadModel ( 'itemStatistics' );
  9747. $itemStatistics = new itemStatistics ();
  9748. $itemStatisticsList = $itemStatistics->find ( array (
  9749. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9750. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9751. 'groupby' => 'staff,itemCategory,Month(date)',
  9752. 'asArray' => true
  9753. ) );
  9754. $itemCategoryList = $itemStatistics->find ( array (
  9755. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9756. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9757. 'groupby' => 'cid,itemCategory,Month(date)',
  9758. 'asArray' => true
  9759. ) );
  9760. $LcategoryList = $Lcategory->find ( array (
  9761. 'asArray' => true
  9762. ) );
  9763. $staffList = $staff->find ( array (
  9764. 'asArray' => true
  9765. ) );
  9766. $htmlArray = array ();
  9767. foreach ( $LcategoryList as $value ) {
  9768. $htmlArray [$value ['title']] = array ();
  9769. foreach ( $staffList as $v ) {
  9770. if ($value ['cid'] == $v ['cid']) {
  9771. $html = "";
  9772. $falg = true;
  9773. $staffSumPrice = 0;
  9774. foreach ( $itemStatisticsList as $a ) {
  9775. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9776. if (empty ( $a ['price'] )) {
  9777. $html .= '<td class="taR">-</td>';
  9778. $falg = false;
  9779. break;
  9780. } else {
  9781. $staffSumPrice += $a ['price'];
  9782. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9783. $falg = false;
  9784. break;
  9785. }
  9786. }
  9787. }
  9788. if ($falg) {
  9789. $html .= '<td class="taR">-</td>';
  9790. $falg = true;
  9791. }
  9792. $falg = true;
  9793. foreach ( $itemStatisticsList as $a ) {
  9794. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9795. if (empty ( $a ['price'] )) {
  9796. $html .= '<td class="taR">-</td>';
  9797. $falg = false;
  9798. break;
  9799. } else {
  9800. $staffSumPrice += $a ['price'];
  9801. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9802. $falg = false;
  9803. break;
  9804. }
  9805. }
  9806. }
  9807. if ($falg) {
  9808. $html .= '<td class="taR">-</td>';
  9809. $falg = true;
  9810. }
  9811. $falg = true;
  9812. foreach ( $itemStatisticsList as $a ) {
  9813. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9814. if (empty ( $a ['price'] )) {
  9815. $html .= '<td class="taR">-</td>';
  9816. $falg = false;
  9817. break;
  9818. } else {
  9819. $staffSumPrice += $a ['price'];
  9820. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9821. $falg = false;
  9822. break;
  9823. }
  9824. }
  9825. }
  9826. if ($falg) {
  9827. $html .= '<td class="taR">-</td>';
  9828. $falg = true;
  9829. }
  9830. $falg = true;
  9831. foreach ( $itemStatisticsList as $a ) {
  9832. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9833. if (! empty ( $a ['price'] )) {
  9834. $staffSumPrice += $a ['price'];
  9835. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9836. $falg = false;
  9837. break;
  9838. } else {
  9839. $html .= '<td class="taR">-</td>';
  9840. $falg = false;
  9841. break;
  9842. }
  9843. }
  9844. }
  9845. if ($falg) {
  9846. $html .= '<td class="taR">-</td>';
  9847. $falg = true;
  9848. }
  9849. $falg = true;
  9850. foreach ( $itemStatisticsList as $a ) {
  9851. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9852. if (! empty ( $a ['price'] )) {
  9853. $staffSumPrice += $a ['price'];
  9854. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9855. $falg = false;
  9856. break;
  9857. } else {
  9858. $html .= '<td class="taR">-</td>';
  9859. $falg = false;
  9860. break;
  9861. }
  9862. }
  9863. }
  9864. if ($falg) {
  9865. $html .= '<td class="taR">-</td>';
  9866. $falg = true;
  9867. }
  9868. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9869. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9870. }
  9871. }
  9872. /* -- --- */
  9873. // 合计费用
  9874. $cateHtml = "";
  9875. $catePrice = 0;
  9876. $cateFalg = true;
  9877. foreach ( $itemCategoryList as $l ) {
  9878. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9879. if (empty ( $l ['price'] )) {
  9880. $cateHtml .= '<td class="colGreen taR">-</td>';
  9881. $cateFalg = false;
  9882. break;
  9883. } else {
  9884. $catePrice += $l ['price'];
  9885. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9886. $cateFalg = false;
  9887. break;
  9888. }
  9889. }
  9890. }
  9891. if ($cateFalg) {
  9892. $cateHtml .= '<td class="colGreen taR">-</td>';
  9893. $cateFalg = true;
  9894. }
  9895. $cateFalg = true;
  9896. foreach ( $itemCategoryList as $l ) {
  9897. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9898. if (empty ( $l ['price'] )) {
  9899. $cateHtml .= '<td class="colGreen taR">-</td>';
  9900. $cateFalg = false;
  9901. break;
  9902. } else {
  9903. $catePrice += $l ['price'];
  9904. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9905. $cateFalg = false;
  9906. break;
  9907. }
  9908. }
  9909. }
  9910. if ($cateFalg) {
  9911. $cateHtml .= '<td class="colGreen taR">-</td>';
  9912. $cateFalg = true;
  9913. }
  9914. $cateFalg = true;
  9915. foreach ( $itemCategoryList as $l ) {
  9916. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9917. if (empty ( $l ['price'] )) {
  9918. $cateHtml .= '<td class="colGreen taR">-</td>';
  9919. $cateFalg = false;
  9920. break;
  9921. } else {
  9922. $catePrice += $l ['price'];
  9923. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9924. $cateFalg = false;
  9925. break;
  9926. }
  9927. }
  9928. }
  9929. if ($cateFalg) {
  9930. $cateHtml .= '<td class="colGreen taR">-</td>';
  9931. $cateFalg = true;
  9932. }
  9933. $cateFalg = true;
  9934. foreach ( $itemCategoryList as $l ) {
  9935. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  9936. if (empty ( $l ['price'] )) {
  9937. $cateHtml .= '<td class="colGreen taR">-</td>';
  9938. $cateFalg = false;
  9939. break;
  9940. } else {
  9941. $catePrice += $l ['price'];
  9942. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9943. $cateFalg = false;
  9944. break;
  9945. }
  9946. }
  9947. }
  9948. if ($cateFalg) {
  9949. $cateHtml .= '<td class="colGreen taR">-</td>';
  9950. $cateFalg = true;
  9951. }
  9952. $cateFalg = true;
  9953. foreach ( $itemCategoryList as $l ) {
  9954. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  9955. if (empty ( $l ['price'] )) {
  9956. $cateHtml .= '<td class="colGreen taR">-</td>';
  9957. $cateFalg = false;
  9958. break;
  9959. } else {
  9960. $catePrice += $l ['price'];
  9961. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9962. $cateFalg = false;
  9963. break;
  9964. }
  9965. }
  9966. }
  9967. if ($cateFalg) {
  9968. $cateHtml .= '<td class="colGreen taR">-</td>';
  9969. $cateFalg = true;
  9970. }
  9971. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  9972. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  9973. /* -- --- */
  9974. }
  9975. // print_r($htmlArray);die;
  9976. $data ['htmlArray'] = $htmlArray;
  9977. // statistics html
  9978. $stList = $statistics->getOne ( array (
  9979. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  9980. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9981. 'groupby' => 'Month(date)',
  9982. 'asArray' => true
  9983. ) );
  9984. if (empty ( $stList ))
  9985. $stList = array (
  9986. 'rePrice' => 0,
  9987. 'agPrice' => 0
  9988. );
  9989. $data ['stList'] = array (
  9990. 'rePrice' => $stList ['rePrice'],
  9991. 'agPrice' => $stList ['agPrice'],
  9992. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9993. );
  9994. $monthHtml = "";
  9995. for($i = 1; $i <= 12; $i ++) {
  9996. if ($i == $month)
  9997. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  9998. else
  9999. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10000. }
  10001. $data ['monthHtml'] = $monthHtml;
  10002. $data ['year'] = $year;
  10003. $data ['month'] = $month;
  10004. $data ['memu'] = "receipt";
  10005. $data ['staff'] = $this->staff;
  10006. $data ['receiptMemu'] = 'companyCategoryCollect';
  10007. $data ['verifyId'] = $this->verifyId;
  10008. $data ['executeId'] = $this->executeId;
  10009. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10010. Doo::loadModel ( 'receipt' );
  10011. $receipt = new receipt ();
  10012. $receiptList = $receipt->find ( array (
  10013. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10014. 'asArray' => true
  10015. ) );
  10016. if (empty ( $receiptList )) { // generated files
  10017. ob_start ();
  10018. $this->render ( "/admin/saeaStaffCollect", $data );
  10019. $this->cacheFile ( $path );
  10020. die ();
  10021. }
  10022. }
  10023. $this->render ( "/admin/saeaStaffCollect", $data );
  10024. }
  10025. /**
  10026. * 日常收支
  10027. */
  10028. function payments() {
  10029. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10030. Doo::loadModel ( "execute" );
  10031. $execute = new execute ();
  10032. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10033. die ( 'illegal request' );
  10034. }
  10035. Doo::loadModel ( "accountBook" );
  10036. $accountBook = new accountBook ();
  10037. Doo::loadModel ( "accountBookStatistics" );
  10038. $accountBookStatistics = new accountBookStatistics ();
  10039. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10040. $list = $accountBook->getAccountBookByLimit ( 10 );
  10041. $data ['date'] = date ( "Y-m-d" );
  10042. $data ['statisticsList'] = $statisticsList;
  10043. $data ['list'] = $list;
  10044. $data ['memu'] = "receipt";
  10045. $data ['staff'] = $this->staff;
  10046. $data ['receiptMemu'] = 'payments';
  10047. $data ['verifyId'] = $this->verifyId;
  10048. $data ['executeId'] = $this->executeId;
  10049. $this->render ( "/expenses/payments", $data );
  10050. }
  10051. function paymentsIncomeDo() {
  10052. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10053. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10054. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10055. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10056. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10057. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10058. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10059. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10060. Doo::loadClass ( 'XDeode' );
  10061. $XDeode = new XDeode ( 5 );
  10062. Doo::loadModel ( "accountBook" );
  10063. Doo::loadModel ( "accountBookStatistics" );
  10064. Doo::loadModel ( 'wasteBook' );
  10065. // 记录流水时银行的转换
  10066. $accountBank = '';
  10067. if ($receivedBank == '纵横广发') {
  10068. $accountBank = 'CGBDeposit';
  10069. } elseif ($receivedBank == '纵横工行') {
  10070. $accountBank = 'ICBCDeposit';
  10071. } elseif ($receivedBank == '华润银行') {
  10072. $accountBank = 'HUADeposit';
  10073. } elseif ($receivedBank == '个人广发') {
  10074. $accountBank = 'PersonalDeposit';
  10075. }
  10076. if (empty ( $accountBank ))
  10077. die ( 'illegal request' );
  10078. // 收入为理财时特殊处理
  10079. if ($accountType == 7 || $accountType == 9) {
  10080. if ($receivedBank == '个人广发') {
  10081. die ( '个人广发 illegal request' );
  10082. }
  10083. // 添加一条收入
  10084. $accountBook = new accountBook ();
  10085. $accountBook->accountType = 10;
  10086. $accountBook->accountMsg = $accountMsg;
  10087. $accountBook->receivedPrice = $receivedPrice;
  10088. $accountBook->receivedMsg = $receivedMsg;
  10089. $accountBook->receivedBank = $receivedBank;
  10090. $accountBook->receivedDate = $receivedDate;
  10091. $accountBook->remarks = $remarks;
  10092. $accountBook->expensesType = 1;
  10093. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10094. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10095. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10096. $inComeId = $accountBook->insert ();
  10097. // 收支汇总-添加一条收入日常汇总
  10098. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10099. $accountBookStatistics = new accountBookStatistics ();
  10100. $item = array (
  10101. 'date' => date ( "Y-m-d" ),
  10102. 'accountType' => $abDetail ['accountType'],
  10103. 'accountMsg' => $abDetail ['accountMsg'],
  10104. 'aid' => $abDetail ['aid'],
  10105. 'inComePrice' => $abDetail ['receivedPrice'],
  10106. 'expensesType' => $abDetail ['expensesType']
  10107. );
  10108. $accountBookStatistics->setAccountBookStatistics ( $item );
  10109. // 添加收入流水
  10110. $wasteBook = new wasteBook ();
  10111. $itemWaste = array (
  10112. 'accountPriceShow' => $receivedPrice,
  10113. 'accountPrice' => $receivedPrice,
  10114. 'expensesType' => 1,
  10115. 'accountType' => 6, // 流水类型
  10116. 'dataID' => $inComeId,
  10117. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10118. 'accountBank' => $accountBank,
  10119. 'category' => $this->staff [0] ['category'],
  10120. 'cid' => $this->staff [0] ['cid'],
  10121. 'name' => $this->staff [0] ['username'],
  10122. 'sid' => $this->staff [0] ['sid'],
  10123. 'inputDate' => date ( "Y-m-d H:i:s" )
  10124. );
  10125. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10126. // 添加一条理财支出
  10127. $accountBank = 'CGBDeposit';
  10128. $expenditureBank = '纵横广发';
  10129. $dailyExpenditureType = 4;
  10130. if ($accountType == 9) {
  10131. $accountBank = 'ICBCDeposit';
  10132. $expenditureBank = '纵横工行';
  10133. $dailyExpenditureType = 6;
  10134. }
  10135. $accountBook = new accountBook ();
  10136. $accountBook->expensesType = 2;
  10137. $accountBook->expenditureType = $dailyExpenditureType;
  10138. $accountBook->expenditureMsg = $accountMsg;
  10139. $accountBook->expenditurePrice = $receivedPrice;
  10140. $accountBook->expenditureBank = $expenditureBank;
  10141. $accountBook->expenditureDate = $receivedDate;
  10142. $accountBook->remarks = $remarks;
  10143. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10144. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10145. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10146. $id = $accountBook->insert ();
  10147. // 收支汇总-添加一条理财支出汇总
  10148. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10149. $accountBookStatistics = new accountBookStatistics ();
  10150. $item = array (
  10151. 'date' => date ( "Y-m-d" ),
  10152. 'accountType' => $abDetail ['accountType'],
  10153. 'accountMsg' => $abDetail ['accountMsg'],
  10154. 'aid' => $abDetail ['aid'],
  10155. 'financingPrice' => - $receivedPrice,
  10156. 'expensesType' => 3
  10157. );
  10158. $accountBookStatistics->setAccountBookStatistics ( $item );
  10159. // 添加一条支出理财流水
  10160. $accountTypeWaste = 5;
  10161. if ($accountMsg == '公司固定') {
  10162. $accountTypeWaste = 9;
  10163. } elseif ($accountMsg == '公司活期') {
  10164. $accountTypeWaste = 10;
  10165. } elseif ($accountMsg == '个人(GR)') {
  10166. $accountBank = 'PersonalDeposit';
  10167. }
  10168. $itemWaste = array (
  10169. 'expensesType' => 2,
  10170. 'accountType' => $accountTypeWaste,
  10171. 'accountPriceShow' => $receivedPrice,
  10172. 'accountPrice' => - $receivedPrice,
  10173. 'dataID' => $id,
  10174. 'dailyExpenditureType' => $dailyExpenditureType,
  10175. 'accountBank' => $accountBank,
  10176. 'category' => $this->staff [0] ['category'],
  10177. 'cid' => $this->staff [0] ['cid'],
  10178. 'name' => $this->staff [0] ['username'],
  10179. 'sid' => $this->staff [0] ['sid'],
  10180. 'inputDate' => date ( "Y-m-d H:i:s" )
  10181. );
  10182. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10183. } elseif ($accountType == 1) {
  10184. if ($receivedBank == '个人广发')
  10185. die ( 'illegal request' );
  10186. // 添加一条收入
  10187. $accountBook = new accountBook ();
  10188. $accountBook->accountType = $accountType;
  10189. $accountBook->accountMsg = $accountMsg;
  10190. $accountBook->receivedPrice = $receivedPrice;
  10191. $accountBook->receivedMsg = $receivedMsg;
  10192. $accountBook->receivedBank = $receivedBank;
  10193. $accountBook->receivedDate = $receivedDate;
  10194. $accountBook->remarks = $remarks;
  10195. $accountBook->expensesType = 1;
  10196. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10197. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10198. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10199. $id = $accountBook->insert ();
  10200. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10201. // 收支汇总-添加一条收入日常汇总
  10202. $accountBookStatistics = new accountBookStatistics ();
  10203. $item = array (
  10204. 'date' => date ( "Y-m-d" ),
  10205. 'accountType' => $abDetail ['accountType'],
  10206. 'accountMsg' => $abDetail ['accountMsg'],
  10207. 'aid' => $abDetail ['aid'],
  10208. 'expensesType' => $abDetail ['expensesType']
  10209. );
  10210. if ($abDetail ['accountType'] == 8) {
  10211. $item += array (
  10212. 'inComePrice' => $abDetail ['receivedPrice']
  10213. );
  10214. } else {
  10215. $item += array (
  10216. 'inComePrice' => $abDetail ['receivedPrice']
  10217. );
  10218. }
  10219. $accountBookStatistics->setAccountBookStatistics ( $item );
  10220. // 流水存储方向
  10221. $itemWaste = array (
  10222. 'accountType' => 6
  10223. ); // 流水类型
  10224. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10225. // }else
  10226. if ($accountMsg == '活期理财收益') {
  10227. $itemWaste = array (
  10228. 'accountType' => 10
  10229. ); // 流水类型
  10230. }
  10231. // 添加收入流水
  10232. $wasteBook = new wasteBook ();
  10233. $itemWaste += array (
  10234. 'accountPrice' => $receivedPrice,
  10235. 'accountPriceShow' => $receivedPrice,
  10236. 'expensesType' => 1,
  10237. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10238. 'dataID' => $id,
  10239. 'accountBank' => $accountBank,
  10240. 'category' => $this->staff [0] ['category'],
  10241. 'cid' => $this->staff [0] ['cid'],
  10242. 'name' => $this->staff [0] ['username'],
  10243. 'sid' => $this->staff [0] ['sid'],
  10244. 'inputDate' => date ( "Y-m-d H:i:s" )
  10245. );
  10246. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10247. } else { // 普通日常收入处理
  10248. // 添加一条收入
  10249. $accountBook = new accountBook ();
  10250. $accountBook->accountType = $accountType;
  10251. $accountBook->accountMsg = $accountMsg;
  10252. $accountBook->receivedPrice = $receivedPrice;
  10253. $accountBook->receivedMsg = $receivedMsg;
  10254. $accountBook->receivedBank = $receivedBank;
  10255. $accountBook->receivedDate = $receivedDate;
  10256. $accountBook->remarks = $remarks;
  10257. $accountBook->expensesType = 1;
  10258. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10259. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10260. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10261. $id = $accountBook->insert ();
  10262. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10263. // 收支汇总-添加一条收入日常汇总
  10264. $accountBookStatistics = new accountBookStatistics ();
  10265. $item = array (
  10266. 'date' => date ( "Y-m-d" ),
  10267. 'accountType' => $abDetail ['accountType'],
  10268. 'accountMsg' => $abDetail ['accountMsg'],
  10269. 'aid' => $abDetail ['aid'],
  10270. 'expensesType' => $abDetail ['expensesType']
  10271. );
  10272. if ($abDetail ['accountType'] == 8) {
  10273. $item += array (
  10274. 'inComePrice' => $abDetail ['receivedPrice']
  10275. );
  10276. } else {
  10277. $item += array (
  10278. 'inComePrice' => $abDetail ['receivedPrice']
  10279. );
  10280. }
  10281. $accountBookStatistics->setAccountBookStatistics ( $item );
  10282. // 添加收入流水
  10283. $itemWaste = array (
  10284. 'accountPrice' => $receivedPrice
  10285. );
  10286. if ($receivedBank == '个人广发') {
  10287. $itemWaste = array (
  10288. 'accountPrice' => - $receivedPrice
  10289. );
  10290. }
  10291. $wasteBook = new wasteBook ();
  10292. $itemWaste += array (
  10293. 'accountPriceShow' => $receivedPrice,
  10294. 'expensesType' => 1,
  10295. 'accountType' => 6, // 流水类型
  10296. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10297. 'dataID' => $id,
  10298. 'accountBank' => $accountBank,
  10299. 'category' => $this->staff [0] ['category'],
  10300. 'cid' => $this->staff [0] ['cid'],
  10301. 'name' => $this->staff [0] ['username'],
  10302. 'sid' => $this->staff [0] ['sid'],
  10303. 'inputDate' => date ( "Y-m-d H:i:s" )
  10304. );
  10305. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10306. }
  10307. }
  10308. return '/payments';
  10309. }
  10310. /**
  10311. * 添加收入
  10312. * @return string
  10313. */
  10314. function paymentsIncomeDo_() {
  10315. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10316. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10317. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10318. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10319. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10320. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10321. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10322. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10323. Doo::loadClass ( 'XDeode' );
  10324. $XDeode = new XDeode ( 5 );
  10325. Doo::loadModel ( "accountBook" );
  10326. $accountBook = new accountBook ();
  10327. $accountBank = '';
  10328. $accountTypeWaste = 6;
  10329. if ($receivedBank == '纵横广发') {
  10330. $accountBank = 'CGBDeposit';
  10331. } elseif ($receivedBank == '纵横工行') {
  10332. $accountBank = 'ICBCDeposit';
  10333. } elseif ($receivedBank == '华润银行') {
  10334. $accountBank = 'HUADeposit';
  10335. } elseif ($receivedBank == '个人广发') {
  10336. $accountBank = 'PersonalDeposit';
  10337. }
  10338. if (empty ( $accountBank ))
  10339. die ( 'illegal request' );
  10340. $dailyIncomeType = '';
  10341. $itemWaste = array (
  10342. 'accountPrice' => $receivedPrice,
  10343. 'expensesType' => 1
  10344. );
  10345. if ($receivedBank == '个人广发') {
  10346. $itemWaste = array (
  10347. 'accountPrice' => - $receivedPrice,
  10348. 'expensesType' => 1
  10349. );
  10350. }
  10351. if ($accountType == 4) {
  10352. $dailyIncomeType = 4;
  10353. } elseif ($accountType == 1) {
  10354. $dailyIncomeType = 1;
  10355. } elseif ($accountType == 2) {
  10356. $dailyIncomeType = 2;
  10357. } elseif ($accountType == 3) {
  10358. $dailyIncomeType = 3;
  10359. } elseif ($accountType == 5) {
  10360. $dailyIncomeType = 5;
  10361. } elseif ($accountType == 6) {
  10362. $dailyIncomeType = 6;
  10363. } elseif ($accountType == 7 || $accountType == 9) {
  10364. $dailyIncomeType = 7;
  10365. if ($accountMsg == '公司固定') {
  10366. $accountTypeWaste = 9;
  10367. } elseif ($accountMsg == '公司活期') {
  10368. $accountTypeWaste = 10;
  10369. } elseif ($accountMsg == '个人(GR)') {
  10370. $accountBank = 'PersonalDeposit';
  10371. }
  10372. $itemWaste = array (
  10373. 'accountPrice' => - $receivedPrice,
  10374. 'expensesType' => 2
  10375. );
  10376. } elseif ($accountType == 8) {
  10377. $dailyIncomeType = 8;
  10378. }
  10379. if (empty ( $dailyIncomeType ))
  10380. die ( 'illegal request' );
  10381. $accountBook->accountType = $accountType;
  10382. $accountBook->accountMsg = $accountMsg;
  10383. $accountBook->receivedPrice = $receivedPrice;
  10384. $accountBook->receivedMsg = $receivedMsg;
  10385. $accountBook->receivedBank = $receivedBank;
  10386. $accountBook->receivedDate = $receivedDate;
  10387. $accountBook->remarks = $remarks;
  10388. $accountBook->expensesType = 1;
  10389. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10390. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10391. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10392. $id = $accountBook->insert ();
  10393. //
  10394. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10395. // 收支汇总
  10396. Doo::loadModel ( "accountBookStatistics" );
  10397. $accountBookStatistics = new accountBookStatistics ();
  10398. $item = array (
  10399. 'date' => date ( "Y-m-d" ),
  10400. 'accountType' => $abDetail ['accountType'],
  10401. 'accountMsg' => $abDetail ['accountMsg'],
  10402. 'aid' => $abDetail ['aid']
  10403. );
  10404. if ($abDetail ['expensesType'] == 1) {
  10405. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10406. $item += array (
  10407. 'financingPrice' => - $receivedPrice,
  10408. 'expensesType' => 3
  10409. );
  10410. } else if ($abDetail ['accountType'] == 8) {
  10411. $item += array (
  10412. 'inComePrice' => - $abDetail ['receivedPrice'],
  10413. 'expensesType' => $abDetail ['expensesType']
  10414. );
  10415. } else {
  10416. $item += array (
  10417. 'inComePrice' => $abDetail ['receivedPrice'],
  10418. 'expensesType' => $abDetail ['expensesType']
  10419. );
  10420. }
  10421. }
  10422. $accountBookStatistics->setAccountBookStatistics ( $item );
  10423. // 为理财时需添加一条日常支出
  10424. if ($accountType == 7 || $accountType == 9) {
  10425. }
  10426. // 公司流水记录
  10427. Doo::loadModel ( 'wasteBook' );
  10428. $wasteBook = new wasteBook ();
  10429. // 银行
  10430. // if (empty($abDetail)){
  10431. $itemWaste += array (
  10432. 'accountPriceShow' => $receivedPrice,
  10433. 'dataID' => $id,
  10434. 'accountType' => $accountTypeWaste,
  10435. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10436. 'accountBank' => $accountBank,
  10437. 'category' => $this->staff [0] ['category'],
  10438. 'cid' => $this->staff [0] ['cid'],
  10439. 'name' => $this->staff [0] ['username'],
  10440. 'sid' => $this->staff [0] ['sid'],
  10441. 'inputDate' => date ( "Y-m-d H:i:s" )
  10442. );
  10443. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10444. // }
  10445. // 类型为理财7或者9 要添加一笔理财支出
  10446. if ($accountType == 7 || $accountType == 9) {
  10447. $accountBank = 'CGBDeposit';
  10448. $expenditureBank = '纵横广发';
  10449. $dailyExpenditureType = 4;
  10450. if ($accountType == 9) {
  10451. $accountBank = 'ICBCDeposit';
  10452. $expenditureBank = '纵横工行';
  10453. $dailyExpenditureType = 6;
  10454. }
  10455. // 添加一条支出
  10456. $accountBook = new accountBook ();
  10457. $accountBook->expenditureType = $dailyExpenditureType;
  10458. $accountBook->expenditureMsg = $accountMsg;
  10459. $accountBook->expenditurePrice = $receivedPrice;
  10460. $accountBook->expenditureBank = $expenditureBank;
  10461. $accountBook->expenditureDate = $receivedDate;
  10462. $accountBook->remarks = $remarks;
  10463. $accountBook->expensesType = 2;
  10464. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10465. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10466. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10467. $id = $accountBook->insert ();
  10468. // 添加一条收入流水
  10469. $itemWaste = array (
  10470. 'accountPriceShow' => $receivedPrice,
  10471. 'accountPrice' => $receivedPrice,
  10472. 'dataID' => $id,
  10473. 'expensesType' => 2,
  10474. 'accountType' => $accountTypeWaste,
  10475. 'dailyExpenditureType' => $dailyExpenditureType,
  10476. 'accountBank' => $accountBank,
  10477. 'category' => $this->staff [0] ['category'],
  10478. 'cid' => $this->staff [0] ['cid'],
  10479. 'name' => $this->staff [0] ['username'],
  10480. 'sid' => $this->staff [0] ['sid'],
  10481. 'inputDate' => date ( "Y-m-d H:i:s" )
  10482. );
  10483. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10484. }
  10485. }
  10486. return '/payments';
  10487. }
  10488. function paymentsExpenditureDo() {
  10489. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10490. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10491. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10492. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10493. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10494. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10495. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10496. // 理财支出特殊处理
  10497. Doo::loadModel ( "accountBook" );
  10498. Doo::loadModel ( "accountBookStatistics" );
  10499. Doo::loadModel ( 'wasteBook' );
  10500. $accountBank = '';
  10501. if ($expenditureBank == '纵横广发') {
  10502. $accountBank = 'CGBDeposit';
  10503. } elseif ($expenditureBank == '纵横工行') {
  10504. $accountBank = 'ICBCDeposit';
  10505. } elseif ($expenditureBank == '华润银行') {
  10506. $accountBank = 'HUADeposit';
  10507. } elseif ($expenditureBank == '个人广发') {
  10508. $accountBank = 'PersonalDeposit';
  10509. }
  10510. if (empty ( $accountBank ))
  10511. die ( 'illegal request' );
  10512. if ($expenditureType == 4 || $expenditureType == 6) {
  10513. if ($expenditureBank == '个人广发') {
  10514. die ( '个人广发 illegal request' );
  10515. }
  10516. // 添加一笔日常支出
  10517. $accountBook = new accountBook ();
  10518. $accountBook->expensesType = 2;
  10519. $accountBook->expenditureType = 7;
  10520. $accountBook->expenditureMsg = $expenditureMsg;
  10521. $accountBook->expenditurePrice = $expenditurePrice;
  10522. $accountBook->expenditureBank = $expenditureBank;
  10523. $accountBook->expenditureDate = $expenditureDate;
  10524. $accountBook->remarks = $remarks;
  10525. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10526. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10527. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10528. $expenditureId = $accountBook->insert ();
  10529. // 添加日常支出汇总
  10530. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10531. $accountBookStatistics = new accountBookStatistics ();
  10532. $item = array (
  10533. 'date' => date ( "Y-m-d" ),
  10534. 'expenditureType' => $abDetail ['expenditureType'],
  10535. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10536. 'aid' => $abDetail ['aid'],
  10537. 'payPrice' => $abDetail ['expenditurePrice'],
  10538. 'expensesType' => $abDetail ['expensesType']
  10539. );
  10540. $accountBookStatistics->setAccountBookStatistics ( $item );
  10541. // 公司日常支出流水
  10542. $wasteBook = new wasteBook ();
  10543. $itemWaste = array (
  10544. 'accountPrice' => - $expenditurePrice
  10545. );
  10546. if ($expenditureBank == '个人广发') {
  10547. $itemWaste = array (
  10548. 'accountPrice' => $expenditurePrice
  10549. );
  10550. }
  10551. $itemWaste += array (
  10552. 'expensesType' => 2,
  10553. 'accountType' => 5,
  10554. 'dailyExpenditureType' => $expenditureType,
  10555. 'accountPriceShow' => $expenditurePrice,
  10556. 'accountPrice' => - $expenditurePrice,
  10557. 'dataID' => $expenditureId,
  10558. 'accountBank' => $accountBank,
  10559. 'category' => $this->staff [0] ['category'],
  10560. 'cid' => $this->staff [0] ['cid'],
  10561. 'name' => $this->staff [0] ['username'],
  10562. 'sid' => $this->staff [0] ['sid'],
  10563. 'inputDate' => date ( "Y-m-d H:i:s" )
  10564. );
  10565. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10566. // 添加一笔理财收入
  10567. $accountBank = 'CGBDeposit';
  10568. $dailyIncomeType = 7;
  10569. $receivedBank = '纵横广发';
  10570. if ($expenditureType == 6) {
  10571. $accountBank = 'ICBCDeposit';
  10572. $receivedBank = '纵横工行';
  10573. $dailyIncomeType = 9;
  10574. }
  10575. $accountBook = new accountBook ();
  10576. $accountBook->expensesType = 1;
  10577. $accountBook->accountType = $dailyIncomeType;
  10578. $accountBook->accountMsg = $expenditureMsg;
  10579. $accountBook->receivedPrice = $expenditurePrice;
  10580. $accountBook->receivedBank = $receivedBank;
  10581. $accountBook->receivedDate = $expenditureDate;
  10582. $accountBook->remarks = $remarks;
  10583. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10584. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10585. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10586. $id = $accountBook->insert ();
  10587. // 添加日常理财收入汇总
  10588. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10589. $accountBookStatistics = new accountBookStatistics ();
  10590. $item = array (
  10591. 'date' => date ( "Y-m-d" ),
  10592. 'expenditureType' => $abDetail ['expenditureType'],
  10593. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10594. 'aid' => $abDetail ['aid'],
  10595. 'financingPrice' => $expenditurePrice,
  10596. 'expensesType' => 3
  10597. );
  10598. $accountBookStatistics->setAccountBookStatistics ( $item );
  10599. // 添加一笔收入流水
  10600. if ($expenditureMsg == '公司固定') {
  10601. $accountTypeWaste = 9;
  10602. } elseif ($expenditureMsg == '公司活期') {
  10603. $accountTypeWaste = 10;
  10604. } elseif ($expenditureMsg == '个人(GR)') {
  10605. $accountBank = 'PersonalDeposit';
  10606. }
  10607. $itemWaste = array (
  10608. 'expensesType' => 1,
  10609. 'accountType' => $accountTypeWaste,
  10610. 'accountPriceShow' => $expenditurePrice,
  10611. 'accountPrice' => $expenditurePrice,
  10612. 'dataID' => $id,
  10613. 'dailyIncomeType' => $dailyIncomeType,
  10614. 'accountBank' => $accountBank,
  10615. 'category' => $this->staff [0] ['category'],
  10616. 'cid' => $this->staff [0] ['cid'],
  10617. 'name' => $this->staff [0] ['username'],
  10618. 'sid' => $this->staff [0] ['sid'],
  10619. 'inputDate' => date ( "Y-m-d H:i:s" )
  10620. );
  10621. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10622. } else {
  10623. // 添加一笔日常支出
  10624. $accountBook = new accountBook ();
  10625. $accountBook->expensesType = 2;
  10626. $accountBook->expenditureType = $expenditureType;
  10627. $accountBook->expenditureMsg = $expenditureMsg;
  10628. $accountBook->expenditurePrice = $expenditurePrice;
  10629. $accountBook->expenditureBank = $expenditureBank;
  10630. $accountBook->expenditureDate = $expenditureDate;
  10631. $accountBook->remarks = $remarks;
  10632. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10633. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10634. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10635. $id = $accountBook->insert ();
  10636. // 添加日常支出汇总
  10637. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10638. $accountBookStatistics = new accountBookStatistics ();
  10639. $item = array (
  10640. 'date' => date ( "Y-m-d" ),
  10641. 'expenditureType' => $abDetail ['expenditureType'],
  10642. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10643. 'aid' => $abDetail ['aid'],
  10644. 'expensesType' => $abDetail ['expensesType']
  10645. );
  10646. if ($expenditureType == 5) {
  10647. $item += array (
  10648. 'payPrice' => - $abDetail ['expenditurePrice']
  10649. );
  10650. } else {
  10651. $item += array (
  10652. 'payPrice' => $abDetail ['expenditurePrice']
  10653. );
  10654. }
  10655. $accountBookStatistics->setAccountBookStatistics ( $item );
  10656. // 公司日常支出流水
  10657. $wasteBook = new wasteBook ();
  10658. $itemWaste = array (
  10659. 'accountPrice' => - $expenditurePrice
  10660. );
  10661. if ($expenditureBank == '个人广发') {
  10662. $itemWaste = array (
  10663. 'accountPrice' => $expenditurePrice
  10664. );
  10665. }
  10666. $itemWaste += array (
  10667. 'expensesType' => 2,
  10668. 'accountType' => 5,
  10669. 'accountPriceShow' => $expenditurePrice,
  10670. 'dataID' => $id,
  10671. 'dailyExpenditureType' => $expenditureType,
  10672. 'accountBank' => $accountBank,
  10673. 'category' => $this->staff [0] ['category'],
  10674. 'cid' => $this->staff [0] ['cid'],
  10675. 'name' => $this->staff [0] ['username'],
  10676. 'sid' => $this->staff [0] ['sid'],
  10677. 'inputDate' => date ( "Y-m-d H:i:s" )
  10678. );
  10679. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10680. }
  10681. }
  10682. return '/payments';
  10683. }
  10684. /**
  10685. * 添加支出
  10686. */
  10687. function paymentsExpenditureDo_() {
  10688. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10689. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10690. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10691. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10692. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10693. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10694. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10695. $dailyExpenditureType = '';
  10696. $accountTypeWaste = 5;
  10697. $accountBank = '';
  10698. if ($expenditureBank == '纵横广发') {
  10699. $accountBank = 'CGBDeposit';
  10700. } elseif ($expenditureBank == '纵横工行') {
  10701. $accountBank = 'ICBCDeposit';
  10702. } elseif ($expenditureBank == '华润银行') {
  10703. $accountBank = 'HUADeposit';
  10704. } elseif ($expenditureBank == '个人广发') {
  10705. $accountBank = 'PersonalDeposit';
  10706. }
  10707. if (empty ( $accountBank ))
  10708. die ( 'illegal request' );
  10709. $itemWaste = array (
  10710. 'accountPrice' => - $expenditurePrice
  10711. );
  10712. if ($expenditureBank == '个人广发') {
  10713. $itemWaste = array (
  10714. 'accountPrice' => $expenditurePrice
  10715. );
  10716. }
  10717. if ($expenditureType == 4 || $expenditureType == 6) {
  10718. $dailyExpenditureType = 4;
  10719. if ($expenditureMsg == '公司固定') {
  10720. $accountTypeWaste = 9;
  10721. } elseif ($expenditureMsg == '公司活期') {
  10722. $accountTypeWaste = 10;
  10723. } elseif ($expenditureMsg == '个人(GR)') {
  10724. $accountBank = 'PersonalDeposit';
  10725. }
  10726. $itemWaste = array (
  10727. 'accountPrice' => $expenditurePrice
  10728. );
  10729. } elseif ($expenditureType == 1) {
  10730. $dailyExpenditureType = 1;
  10731. } elseif ($expenditureType == 2) {
  10732. $dailyExpenditureType = 2;
  10733. } elseif ($expenditureType == 3) {
  10734. $dailyExpenditureType = 3;
  10735. } elseif ($expenditureType == 5) {
  10736. $dailyExpenditureType = 5;
  10737. }
  10738. if (empty ( $dailyExpenditureType ))
  10739. die ( 'illegal request' );
  10740. Doo::loadModel ( "accountBook" );
  10741. $accountBook = new accountBook ();
  10742. $accountBook->expenditureType = $expenditureType;
  10743. $accountBook->expenditureMsg = $expenditureMsg;
  10744. $accountBook->expenditurePrice = $expenditurePrice;
  10745. $accountBook->expenditureBank = $expenditureBank;
  10746. $accountBook->expenditureDate = $expenditureDate;
  10747. $accountBook->remarks = $remarks;
  10748. $accountBook->expensesType = 2;
  10749. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10750. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10751. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10752. $id = $accountBook->insert ();
  10753. //
  10754. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10755. Doo::loadModel ( "accountBookStatistics" );
  10756. $accountBookStatistics = new accountBookStatistics ();
  10757. $item = array (
  10758. 'date' => date ( "Y-m-d" ),
  10759. 'expenditureType' => $abDetail ['expenditureType'],
  10760. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10761. 'aid' => $abDetail ['aid']
  10762. );
  10763. if ($abDetail ['expensesType'] == 2) {
  10764. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10765. $item += array (
  10766. 'financingPrice' => $expenditurePrice,
  10767. 'expensesType' => 3
  10768. );
  10769. } elseif ($abDetail ['expenditureType'] == 5) {
  10770. $item += array (
  10771. 'payPrice' => $abDetail ['expenditurePrice'],
  10772. 'expensesType' => $abDetail ['expensesType']
  10773. );
  10774. } else {
  10775. $item += array (
  10776. 'payPrice' => $abDetail ['expenditurePrice'],
  10777. 'expensesType' => $abDetail ['expensesType']
  10778. );
  10779. }
  10780. }
  10781. $accountBookStatistics->setAccountBookStatistics ( $item );
  10782. // 公司流水记录
  10783. Doo::loadModel ( 'wasteBook' );
  10784. $wasteBook = new wasteBook ();
  10785. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10786. // 银行
  10787. if (empty ( $abDetail )) {
  10788. $itemWaste += array (
  10789. 'accountPriceShow' => $expenditurePrice,
  10790. 'dataID' => $id,
  10791. 'expensesType' => 2,
  10792. 'accountType' => $accountTypeWaste,
  10793. 'dailyExpenditureType' => $expenditureType,
  10794. 'accountBank' => $accountBank,
  10795. 'category' => $this->staff [0] ['category'],
  10796. 'cid' => $this->staff [0] ['cid'],
  10797. 'name' => $this->staff [0] ['username'],
  10798. 'sid' => $this->staff [0] ['sid'],
  10799. 'inputDate' => date ( "Y-m-d H:i:s" )
  10800. );
  10801. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10802. }
  10803. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10804. if ($expenditureType == 4 || $expenditureType == 6) {
  10805. $accountBank = 'CGBDeposit';
  10806. $dailyIncomeType = 7;
  10807. $receivedBank = '纵横广发';
  10808. if ($expenditureType == 6) {
  10809. $accountBank = 'ICBCDeposit';
  10810. $receivedBank = '纵横工行';
  10811. $dailyIncomeType = 9;
  10812. }
  10813. // 添加一笔收入
  10814. $accountBook = new accountBook ();
  10815. $accountBook->accountType = $dailyIncomeType;
  10816. $accountBook->accountMsg = $expenditureMsg;
  10817. $accountBook->receivedPrice = $expenditurePrice;
  10818. $accountBook->receivedBank = $receivedBank;
  10819. $accountBook->receivedDate = $expenditureDate;
  10820. $accountBook->remarks = $remarks;
  10821. $accountBook->expensesType = 1;
  10822. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10823. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10824. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10825. $id = $accountBook->insert ();
  10826. // 添加一笔收入流水
  10827. $itemWaste = array (
  10828. 'accountPriceShow' => $expenditurePrice,
  10829. 'accountPrice' => - $expenditurePrice,
  10830. 'dataID' => $id,
  10831. 'expensesType' => 1,
  10832. 'accountType' => $accountTypeWaste,
  10833. 'dailyIncomeType' => $dailyIncomeType,
  10834. 'accountBank' => $accountBank,
  10835. 'category' => $this->staff [0] ['category'],
  10836. 'cid' => $this->staff [0] ['cid'],
  10837. 'name' => $this->staff [0] ['username'],
  10838. 'sid' => $this->staff [0] ['sid'],
  10839. 'inputDate' => date ( "Y-m-d H:i:s" )
  10840. );
  10841. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10842. }
  10843. }
  10844. return '/payments';
  10845. }
  10846. /**
  10847. * 所有收支
  10848. */
  10849. function paymentsAchieve() {
  10850. $page_size = 12;
  10851. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10852. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10853. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10854. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10855. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10856. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10857. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10858. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10859. Doo::loadModel ( "accountBookStatistics" );
  10860. $accountBookStatistics = new accountBookStatistics ();
  10861. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10862. $data ['statisticsList'] = $statisticsList;
  10863. Doo::loadModel ( "accountBook" );
  10864. $accountBook = new accountBook ();
  10865. $con = '';
  10866. if ($expensesType == 'INCOME')
  10867. $con = ' and expensesType=1 ';
  10868. elseif ($expensesType == 'PAY')
  10869. $con = ' and expensesType=2 ';
  10870. $dateArr = explode ( ':', $date );
  10871. $D1 = $dateString = '';
  10872. $D2 = '';
  10873. if (! empty ( $date )) {
  10874. $D1 = $dateArr [0];
  10875. if (isset ( $dateArr [1] ))
  10876. $D2 = $dateArr [1];
  10877. else
  10878. $D2 = '';
  10879. $dateString = $D1 . " : " . $D2;
  10880. }
  10881. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10882. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10883. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10884. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10885. if (! empty ( $price ))
  10886. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10887. if ($submitType == 1) {
  10888. if ($accountType != '') {
  10889. $expenditureType = '';
  10890. $con .= ' and accountType=' . $accountType;
  10891. if (! empty ( $accountMsg ))
  10892. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10893. }
  10894. } elseif ($submitType == 2) {
  10895. if ($expenditureType != '') {
  10896. $accountType = $accountMsg = '';
  10897. $con .= ' and expenditureType=' . $expenditureType;
  10898. }
  10899. } else {
  10900. $accountType = $accountMsg = $expenditureType = '';
  10901. }
  10902. $sql = "" . $con;
  10903. $action = "paymentsAchieve";
  10904. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10905. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10906. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10907. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10908. $data ['expenditureType'] = $expenditureType;
  10909. $data ['accountMsg'] = $accountMsg;
  10910. $data ['accountType'] = $accountType;
  10911. $data ['inputDate'] = $date;
  10912. $data ['price'] = $price;
  10913. $data ['expensesType'] = $expensesType;
  10914. $data ['page'] = $pageinfo;
  10915. $data ['list'] = $list;
  10916. $data ['memu'] = "receipt";
  10917. $data ['staff'] = $this->staff;
  10918. $data ['receiptMemu'] = 'payments';
  10919. $data ['verifyId'] = $this->verifyId;
  10920. $data ['executeId'] = $this->executeId;
  10921. $this->render ( "/expenses/paymentsAchieve", $data );
  10922. }
  10923. function paymentsIncomeUpdateDo() {
  10924. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10925. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10926. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10927. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10928. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10929. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10930. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10931. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10932. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10933. Doo::loadClass ( 'XDeode' );
  10934. $XDeode = new XDeode ( 5 );
  10935. $aid = $XDeode->decode ( $aidKey );
  10936. Doo::loadModel ( "accountBook" );
  10937. $accountBook = new accountBook ();
  10938. //
  10939. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10940. $price = $receivedPrice - $abDetail [inComePrice];
  10941. Doo::loadModel ( "accountBookStatistics" );
  10942. $accountBookStatistics = new accountBookStatistics ();
  10943. if ($abDetail ['accountType'] == 7) {
  10944. $item += array (
  10945. 'date' => date ( "Y-m-d" ),
  10946. 'financingPrice' => - $price,
  10947. 'expensesType' => 3,
  10948. 'aid' => $abDetail ['aid']
  10949. );
  10950. } elseif ($abDetail ['accountType'] == 8) {
  10951. $item += array (
  10952. 'date' => date ( "Y-m-d" ),
  10953. 'expensesType' => $abDetail ['expensesType'],
  10954. 'inComePrice' => - $price,
  10955. 'aid' => $abDetail ['aid']
  10956. );
  10957. } else {
  10958. $item = array (
  10959. 'date' => date ( "Y-m-d" ),
  10960. 'expensesType' => $abDetail ['expensesType'],
  10961. 'inComePrice' => $price,
  10962. 'aid' => $abDetail ['aid']
  10963. );
  10964. }
  10965. $accountBookStatistics->setAccountBookStatistics ( $item );
  10966. $accountBook->accountType = $accountType;
  10967. $accountBook->accountMsg = $accountMsg;
  10968. $accountBook->receivedPrice = $receivedPrice;
  10969. $accountBook->receivedMsg = $receivedMsg;
  10970. $accountBook->receivedBank = $receivedBank;
  10971. $accountBook->receivedDate = $receivedDate;
  10972. $accountBook->remarks = $remarks;
  10973. $accountBook->aid = $aid;
  10974. $accountBook->update ();
  10975. }
  10976. return '/paymentsAchieve';
  10977. }
  10978. function paymentsExpenditureEdiDo() {
  10979. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10980. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10981. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10982. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10983. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10984. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10985. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10986. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10987. Doo::loadClass ( 'XDeode' );
  10988. $XDeode = new XDeode ( 5 );
  10989. $aid = $XDeode->decode ( $aidKey );
  10990. Doo::loadModel ( "accountBook" );
  10991. $accountBook = new accountBook ();
  10992. // 汇总信息
  10993. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10994. $price = $expenditurePrice - $abDetail [expenditurePrice];
  10995. Doo::loadModel ( "accountBookStatistics" );
  10996. $accountBookStatistics = new accountBookStatistics ();
  10997. if ($abDetail ['expenditureType'] == 4) {
  10998. $item += array (
  10999. 'date' => date ( "Y-m-d" ),
  11000. 'financingPrice' => $price,
  11001. 'expensesType' => 3,
  11002. 'aid' => $abDetail ['aid']
  11003. );
  11004. } elseif ($abDetail ['expenditureType'] == 5) {
  11005. $item += array (
  11006. 'date' => date ( "Y-m-d" ),
  11007. 'expensesType' => $abDetail ['expensesType'],
  11008. 'payPrice' => $price,
  11009. 'aid' => $abDetail ['aid']
  11010. );
  11011. } else {
  11012. $item = array (
  11013. 'date' => date ( "Y-m-d" ),
  11014. 'expensesType' => $abDetail ['expensesType'],
  11015. 'payPrice' => $price,
  11016. 'aid' => $abDetail ['aid']
  11017. );
  11018. }
  11019. $accountBookStatistics->setAccountBookStatistics ( $item );
  11020. //
  11021. $accountBook->expenditureType = $expenditureType;
  11022. $accountBook->expenditureMsg = $expenditureMsg;
  11023. $accountBook->expenditurePrice = $expenditurePrice;
  11024. $accountBook->expenditureBank = $expenditureBank;
  11025. $accountBook->remarks = $remarks;
  11026. $accountBook->expenditureDate = $expenditureDate;
  11027. $accountBook->aid = $aid;
  11028. $id = $accountBook->update ();
  11029. }
  11030. return '/paymentsAchieve';
  11031. }
  11032. function paymentsDelDo() {
  11033. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11034. if (! empty ( $aidKey )) {
  11035. Doo::loadClass ( 'XDeode' );
  11036. $XDeode = new XDeode ( 5 );
  11037. $aid = $XDeode->decode ( $aidKey );
  11038. Doo::loadModel ( "accountBook" );
  11039. $accountBook = new accountBook ();
  11040. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11041. if (empty ( $abDetail ))
  11042. die ( 'illegal request' );
  11043. // 删除收支
  11044. Doo::loadModel ( "accountBookStatistics" );
  11045. $accountBookStatistics = new accountBookStatistics ();
  11046. $item = array (
  11047. 'date' => date ( "Y-m-d" ),
  11048. 'aid' => $abDetail ['aid']
  11049. );
  11050. $accountType = '';
  11051. if ($abDetail ['expensesType'] == 1) {
  11052. $accountType = 6;
  11053. if ($abDetail ['accountType'] != 7) {
  11054. $item += array (
  11055. 'expensesType' => $abDetail ['expensesType'],
  11056. 'inComePrice' => - $abDetail ['receivedPrice']
  11057. );
  11058. } else {
  11059. $item += array (
  11060. 'financingPrice' => $abDetail ['receivedPrice'],
  11061. 'expensesType' => 3
  11062. );
  11063. }
  11064. } elseif ($abDetail ['expensesType'] == 2) {
  11065. $accountType = 5;
  11066. if ($abDetail ['accountType'] != 7) {
  11067. $item += array (
  11068. 'expensesType' => $abDetail ['expensesType'],
  11069. 'payPrice' => - $abDetail ['expenditurePrice']
  11070. );
  11071. } else {
  11072. $item += array (
  11073. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11074. 'expensesType' => 3
  11075. );
  11076. }
  11077. }
  11078. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11079. if ($abDetail ['expenditureMsg'] == '公司固定')
  11080. $accountType = 9;
  11081. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11082. $accountType = 10;
  11083. }
  11084. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11085. if ($abDetail ['accountMsg'] == '公司固定')
  11086. $accountType = 9;
  11087. elseif ($abDetail ['accountMsg'] == '公司活期')
  11088. $accountType = 10;
  11089. }
  11090. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11091. $accountType = 10;
  11092. }
  11093. $accountBookStatistics->setAccountBookStatistics ( $item );
  11094. $accountBook->delete ( array (
  11095. 'where' => 'aid=' . $aid,
  11096. 'limit' => 1
  11097. ) );
  11098. // 删除收入流水
  11099. if (! empty ( $accountType )) {
  11100. Doo::loadModel ( 'wasteBook' );
  11101. $wasteBook = new wasteBook ();
  11102. $wasteBook->delete ( array (
  11103. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11104. 'limit' => 1
  11105. ) );
  11106. }
  11107. }
  11108. return '/paymentsAchieve';
  11109. }
  11110. function paymentsCollect() {
  11111. Doo::loadModel ( "execute" );
  11112. $execute = new execute ();
  11113. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11114. die ( 'illegal request' );
  11115. }
  11116. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11117. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11118. Doo::loadModel ( "accountBookStatistics" );
  11119. $accountBookStatistics = new accountBookStatistics ();
  11120. Doo::loadClass ( 'receipt.func' );
  11121. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11122. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11123. $data ['html'] = $html ['html'];
  11124. $data ['inSum'] = $html ['sum'];
  11125. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11126. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11127. $data ['payHtml'] = $html ['html'];
  11128. $data ['paySum'] = $html ['sum'];
  11129. // 余额统计
  11130. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11131. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11132. include './protected/config/wasteBook.conf.php';
  11133. Doo::loadModel ( 'wasteBook' );
  11134. $wasteBook = new wasteBook ();
  11135. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11136. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11137. // 获得年份之前所有金额
  11138. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11139. // print_r($detail);
  11140. // $waste['total'];
  11141. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11142. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11143. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11144. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11145. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11146. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11147. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11148. if (date ( 'Y' ) > $year) {
  11149. $limitMonth = 12;
  11150. }
  11151. for($i = 1; $i <= 12; $i ++) {
  11152. $inComeA = $payB = 0;
  11153. $falg = true;
  11154. foreach ( $inComePay as $key => $value ) {
  11155. if ($value ['month'] == $i) {
  11156. $falg = false;
  11157. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11158. $inSum += $value ['accountPrice'];
  11159. $showInSum += $value ['accountPriceShow'];
  11160. $inComeA = $value ['accountPrice'];
  11161. break;
  11162. }
  11163. }
  11164. if ($falg)
  11165. $inComeHtml .= '<td class="taR">-</td>';
  11166. $payFalg = true;
  11167. foreach ( $pay as $key => $value ) {
  11168. if ($value ['month'] == $i) {
  11169. $payFalg = false;
  11170. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11171. $paySum += $value ['accountPrice'];
  11172. $showPaySum += $value ['accountPriceShow'];
  11173. $payB = $value ['accountPrice'];
  11174. break;
  11175. }
  11176. }
  11177. if ($payFalg)
  11178. $payHtml .= '<td class="taR">-</td>';
  11179. if (empty ( $balanceC ) || $limitMonth < $i)
  11180. $lastBalanceHtml .= '<td class="taR">-</td>';
  11181. else
  11182. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11183. $balanceC = $balanceC + $inComeA + $payB;
  11184. $balanceSum += $balanceC;
  11185. if (empty ( $balanceC ) || $limitMonth < $i)
  11186. $BalanceHtml .= '<td class="taR">-</td>';
  11187. else
  11188. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11189. // 余额统计
  11190. }
  11191. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11192. $data ['inComeHtml'] = $inComeHtml;
  11193. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11194. $data ['payBalanceHtml'] = $payHtml;
  11195. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11196. $data ['BalanceHtml'] = $BalanceHtml;
  11197. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11198. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11199. $mothHtml = "";
  11200. for($i = 1; $i <= 12; $i ++) {
  11201. if ($moth == $i)
  11202. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11203. else
  11204. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11205. }
  11206. $data ['mothHtml'] = $mothHtml;
  11207. $dateHtml = "";
  11208. $now = date ( "Y" );
  11209. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11210. if ($YEARD <= $now) {
  11211. $dateHtml .= '<option ';
  11212. if ($year == $YEARD) {
  11213. $dateHtml .= 'selected ';
  11214. }
  11215. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11216. }
  11217. }
  11218. $data ['dateHtml'] = $dateHtml;
  11219. $data ['year'] = $year;
  11220. $data ['memu'] = "receipt";
  11221. $data ['staff'] = $this->staff;
  11222. $data ['receiptMemu'] = 'paymentsCollect';
  11223. $data ['verifyId'] = $this->verifyId;
  11224. $data ['executeId'] = $this->executeId;
  11225. $this->render ( "/expenses/paymentsCollect", $data );
  11226. }
  11227. function paymentsCollectDay() {
  11228. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11229. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11230. if (empty ( $moth ))
  11231. return 'paymentsCollect';
  11232. Doo::loadModel ( "accountBookStatistics" );
  11233. $accountBookStatistics = new accountBookStatistics ();
  11234. $i = 2;
  11235. $y = 2013;
  11236. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11237. Doo::loadClass ( 'receipt.func' );
  11238. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11239. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11240. $data ['html'] = $html ['html'];
  11241. $data ['inSum'] = $html ['sum'];
  11242. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11243. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11244. $data ['payHtml'] = $html ['html'];
  11245. $data ['paySum'] = $html ['sum'];
  11246. $mothHtml = "";
  11247. for($i = 1; $i <= 12; $i ++) {
  11248. if ($moth == $i)
  11249. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11250. else
  11251. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11252. }
  11253. $data ['mothHtml'] = $mothHtml;
  11254. $data ['year'] = $year;
  11255. // 余额
  11256. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11257. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11258. include './protected/config/wasteBook.conf.php';
  11259. Doo::loadModel ( 'wasteBook' );
  11260. $wasteBook = new wasteBook ();
  11261. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11262. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11263. // 获得年份之前所有金额
  11264. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11265. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11266. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11267. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11268. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11269. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11270. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11271. // $balanceC = 0;
  11272. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11273. $limitDay = date ( 'd' );
  11274. $monthLK = ( int ) date ( 'm' );
  11275. if (date ( 'Y' ) > $year) {
  11276. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11277. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11278. $limitDay = 0;
  11279. }
  11280. for($i = 1; $i <= $day; $i ++) {
  11281. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11282. $inComeA = $payB = 0;
  11283. $falg = true;
  11284. foreach ( $inComePay as $key => $value ) {
  11285. if ($value ['day'] == $i) {
  11286. $falg = false;
  11287. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11288. $inSum += $value ['accountPrice'];
  11289. $showInSum += $value ['accountPriceShow'];
  11290. $inComeA = $value ['accountPrice'];
  11291. break;
  11292. }
  11293. }
  11294. if ($falg)
  11295. $inComeHtml .= '<td class="taR">-</td>';
  11296. $payFalg = true;
  11297. foreach ( $pay as $key => $value ) {
  11298. if ($value ['day'] == $i) {
  11299. $payFalg = false;
  11300. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11301. $paySum += $value ['accountPrice'];
  11302. $showPaySum += $value ['accountPriceShow'];
  11303. $payB = $value ['accountPrice'];
  11304. break;
  11305. }
  11306. }
  11307. if ($payFalg)
  11308. $payHtml .= '<td class="taR">-</td>';
  11309. if (empty ( $balanceC ) || $limitDay < $i)
  11310. $lastBalanceHtml .= '<td class="taR">-</td>';
  11311. else
  11312. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11313. $balanceC = $balanceC + $inComeA + $payB;
  11314. $balanceSum += $balanceC;
  11315. if (empty ( $balanceC ) || $limitDay < $i)
  11316. $BalanceHtml .= '<td class="taR">-</td>';
  11317. else
  11318. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11319. }
  11320. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11321. $data ['inComeHtml'] = $inComeHtml;
  11322. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11323. $data ['payBalanceHtml'] = $payHtml;
  11324. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11325. $data ['BalanceHtml'] = $BalanceHtml;
  11326. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11327. $data ['dayHtml'] = $dayHtml;
  11328. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11329. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11330. $dateHtml = "";
  11331. $now = date ( "Y" );
  11332. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11333. if ($YEARD <= $now) {
  11334. $dateHtml .= '<option ';
  11335. if ($year == $YEARD) {
  11336. $dateHtml .= 'selected ';
  11337. }
  11338. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11339. }
  11340. }
  11341. $data ['dateHtml'] = $dateHtml;
  11342. $data ['memu'] = "receipt";
  11343. $data ['staff'] = $this->staff;
  11344. $data ['receiptMemu'] = 'paymentsCollect';
  11345. $data ['verifyId'] = $this->verifyId;
  11346. $data ['executeId'] = $this->executeId;
  11347. $this->render ( "/expenses/paymentsCollectDay", $data );
  11348. }
  11349. // 公司流水
  11350. function wasteBook() {
  11351. Doo::loadModel ( "execute" );
  11352. $execute = new execute ();
  11353. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11354. die ( 'illegal request' );
  11355. }
  11356. include './protected/config/wasteBook.conf.php';
  11357. Doo::loadModel ( 'wasteBook' );
  11358. $wasteBook = new wasteBook ();
  11359. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11360. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11361. $total = $waste ['bank'] ['CGBDeposit'] + $waste ['bank'] ['ICBCDeposit'] + $waste ['bank'] ['HUADeposit'] + $waste ['bank'] ['PersonalDeposit'] + $waste ['financial'] ['current'] ['CGBDeposit'] + $waste ['financial'] ['current'] ['ICBCDeposit'] + $waste ['financial'] ['fixed'] ['CGBDeposit'] + $waste ['financial'] ['fixed'] ['ICBCDeposit'];
  11362. // print_r($waste);
  11363. $data ['waste'] = $waste;
  11364. $data ['total'] = $total;
  11365. // 月流水数据结构
  11366. $monthStatistics = array ();
  11367. $incomeMothStatistics = array ();
  11368. $expenditureMothStatistics = array ();
  11369. for($i = 1; $i <= 12; $i ++) {
  11370. $month = date ( 'Y' ) . '-' . $i;
  11371. if ($i < 10)
  11372. $month = date ( 'Y' ) . '-0' . $i;
  11373. array_push ( $monthStatistics, $month );
  11374. }
  11375. foreach ( $monthStatistics as $value ) {
  11376. $falg = true;
  11377. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11378. if ($value == $v ['inputDate']) {
  11379. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11380. $falg = false;
  11381. }
  11382. }
  11383. if ($falg) {
  11384. array_push ( $incomeMothStatistics, '' );
  11385. }
  11386. $falgEx = true;
  11387. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11388. if ($value == $v ['inputDate']) {
  11389. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11390. $falg = false;
  11391. }
  11392. }
  11393. if ($falgEx) {
  11394. array_push ( $expenditureMothStatistics, '' );
  11395. }
  11396. }
  11397. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11398. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11399. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11400. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11401. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11402. // print_r($incomeList);
  11403. $data ['expenditureList'] = $expenditureList;
  11404. $data ['incomeList'] = $incomeList;
  11405. $data ['memu'] = "receipt";
  11406. $data ['staff'] = $this->staff;
  11407. $data ['receiptMemu'] = 'wasteBook';
  11408. $data ['verifyId'] = $this->verifyId;
  11409. $data ['executeId'] = $this->executeId;
  11410. $this->render ( "/expenses/wasteBook", $data );
  11411. }
  11412. function wasteBookIncome() {
  11413. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11414. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11415. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11416. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11417. $data ['dailyIncomeType'] = $dailyIncomeType;
  11418. Doo::loadModel ( 'wasteBook' );
  11419. $wasteBook = new wasteBook ();
  11420. Doo::loadModel ( 'L_category' );
  11421. $L_category = new L_category ();
  11422. Doo::loadClass ( 'XDeode' );
  11423. $XDeode = new XDeode ( 5 );
  11424. // echo $XDeode->encode(1).'<br>';
  11425. // echo $XDeode->encode(2).'<br>';
  11426. // echo $XDeode->encode(3).'<br>';
  11427. // echo $XDeode->encode(4).'<br>';
  11428. // echo $XDeode->encode(5).'<br>';
  11429. // echo $XDeode->encode(6).'<br>';
  11430. // echo $XDeode->encode(7).'<br>';
  11431. // echo $XDeode->encode(8).'<br>';
  11432. // echo $XDeode->encode(9).'<br>';
  11433. // echo $XDeode->encode(10).'<br>';
  11434. $dateArr = explode ( ':', $date );
  11435. $D1 = '';
  11436. $D2 = '';
  11437. $con = '';
  11438. if (! empty ( $date )) {
  11439. $D1 = $dateArr [0];
  11440. $D2 = $dateArr [1];
  11441. }
  11442. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11443. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11444. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11445. $con = ' and inputDate = "' . $D1 . '"';
  11446. if ($cid != 'ALL') {
  11447. $cid = $XDeode->decode ( $cid );
  11448. $con .= ' and cid = "' . $cid . '"';
  11449. }
  11450. if ($accountType != 'ALL') {
  11451. if ($accountType == 'INVOICE') {
  11452. $con .= ' and (accountType = 7 or accountType = 8)';
  11453. } elseif ($accountType == 'PAYMENTS') {
  11454. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11455. if ($dailyIncomeType != 'ALL') {
  11456. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11457. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11458. }
  11459. }
  11460. }
  11461. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11462. $sum = 0;
  11463. foreach ( $incomeList as $key => $value ) {
  11464. $sum += $value ['accountPrice'];
  11465. }
  11466. // print_r($incomeList);
  11467. // 获得办事和部门
  11468. $categoryList = $L_category->getCategory ();
  11469. $data ['accountType'] = $accountType;
  11470. $data ['cid'] = $cid;
  11471. $data ['categoryList'] = $categoryList;
  11472. $data ['sum'] = $sum;
  11473. $data ['incomeList'] = $incomeList;
  11474. $data ['inputDate'] = $date;
  11475. $data ['memu'] = "receipt";
  11476. $data ['staff'] = $this->staff;
  11477. $data ['receiptMemu'] = 'wasteBook';
  11478. $data ['verifyId'] = $this->verifyId;
  11479. $data ['executeId'] = $this->executeId;
  11480. $this->render ( "/expenses/wasteBookIncome", $data );
  11481. }
  11482. /**
  11483. * 所有支出
  11484. */
  11485. function wasteBookExpenditure() {
  11486. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11487. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11488. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11489. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11490. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11491. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11492. $data ['receiptType'] = $receiptType;
  11493. Doo::loadModel ( 'wasteBook' );
  11494. $wasteBook = new wasteBook ();
  11495. Doo::loadModel ( 'L_category' );
  11496. $L_category = new L_category ();
  11497. Doo::loadClass ( 'XDeode' );
  11498. $XDeode = new XDeode ( 5 );
  11499. $dateArr = explode ( ':', $date );
  11500. $D1 = '';
  11501. $D2 = '';
  11502. $con = '';
  11503. if (! empty ( $date )) {
  11504. $D1 = $dateArr [0];
  11505. $D2 = $dateArr [1];
  11506. }
  11507. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11508. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11509. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11510. $con = ' and inputDate = "' . $D1 . '"';
  11511. if ($cid != 'ALL') {
  11512. $cid = $XDeode->decode ( $cid );
  11513. $con .= ' and cid = "' . $cid . '"';
  11514. }
  11515. if ($accountType != 'ALL') {
  11516. if ($accountType == 'INVOICE') {
  11517. $con .= ' and accountType = 11';
  11518. } elseif ($accountType == 'PAYMENTS') {
  11519. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11520. if ($dailyExpenditureType != 'ALL') {
  11521. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11522. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11523. }
  11524. } elseif ($accountType == 'RECEIPT') {
  11525. if ($receiptType == 'ALL') {
  11526. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11527. } else {
  11528. $receiptType = $XDeode->decode ( $receiptType );
  11529. echo $receiptType;
  11530. if ($receiptType == 1) {
  11531. $con .= ' and (accountType = 1 or accountType=2)';
  11532. } else {
  11533. $con .= ' and accountType = ' . $receiptType;
  11534. }
  11535. }
  11536. }
  11537. }
  11538. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11539. $sum = 0;
  11540. foreach ( $incomeList as $key => $value ) {
  11541. $sum += $value ['accountPriceShow'];
  11542. }
  11543. // print_r($incomeList);
  11544. // 获得办事和部门
  11545. $categoryList = $L_category->getCategory ();
  11546. $data ['accountType'] = $accountType;
  11547. $data ['cid'] = $cid;
  11548. $data ['categoryList'] = $categoryList;
  11549. $data ['sum'] = $sum;
  11550. $data ['incomeList'] = $incomeList;
  11551. $data ['inputDate'] = $date;
  11552. $data ['memu'] = "receipt";
  11553. $data ['staff'] = $this->staff;
  11554. $data ['receiptMemu'] = 'wasteBook';
  11555. $data ['verifyId'] = $this->verifyId;
  11556. $data ['executeId'] = $this->executeId;
  11557. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11558. }
  11559. function ajaxGetWasteinvoiceReceivables() {
  11560. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11561. Doo::loadClass ( 'XDeode' );
  11562. $XDeode = new XDeode ( 5 );
  11563. $irid = $XDeode->decode ( $serial );
  11564. Doo::loadModel ( 'invoiceReceivables' );
  11565. $invoiceReceivables = new invoiceReceivables ();
  11566. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11567. echo json_encode ( array (
  11568. 'status' => 1,
  11569. 'detail' => $detail
  11570. ) );
  11571. }
  11572. function ajaxGetPaymentsByAid() {
  11573. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11574. Doo::loadModel ( "accountBook" );
  11575. $accountBook = new accountBook ();
  11576. $detail = $accountBook->getAccountBookByAid ( $serial );
  11577. echo json_encode ( array (
  11578. 'status' => 1,
  11579. 'detail' => $detail
  11580. ) );
  11581. }
  11582. function ajaxGetWasteInvoice() {
  11583. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11584. Doo::loadModel ( 'invoice' );
  11585. $invoice = new invoice ();
  11586. Doo::loadModel ( 'invoiceReceivables' );
  11587. $invoiceReceivables = new invoiceReceivables ();
  11588. $detail = $invoice->getInvoiceByIid ( $serial );
  11589. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11590. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11591. echo json_encode ( array (
  11592. 'status' => 1,
  11593. 'detail' => $detail
  11594. ) );
  11595. }
  11596. /**
  11597. */
  11598. function ajaxGetWasteReceipt() {
  11599. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11600. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11601. Doo::loadModel ( 'receipt' );
  11602. $receipt = new receipt ();
  11603. Doo::loadClass ( 'XDeode' );
  11604. $XDeode = new XDeode ( 5 );
  11605. $rid = $XDeode->decode ( $serial );
  11606. $accountType= $XDeode->decode ( $accountTypeKey );
  11607. // 获得个数据
  11608. $detail = $receipt->getReceiptByRid ( $rid );
  11609. // 初始化
  11610. $detail ['reviseDetail'] = array ();
  11611. if (! empty ( $value ['reviseDetail'] ))
  11612. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11613. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11614. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11615. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11616. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11617. // 获得费用html
  11618. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11619. // 获得费用审批人数据
  11620. $detail = $this->getReceiptApproverHtml ( $detail );
  11621. // 审批执行
  11622. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11623. <th class="taC" width="90">审批人</th>
  11624. <th class="taC">审批意见</th></tr>';
  11625. foreach ( $detail ['verifyList'] as $key => $value ) {
  11626. $html .= '<tr>
  11627. <td>' . $value [1] . '</td>
  11628. <td>' . $value ['opinion'] . '</td>
  11629. </tr>
  11630. ';
  11631. }
  11632. $html .= ' </tbody></table>';
  11633. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11634. <th class="taC" width="90">执行人</th>
  11635. <th class="taC">执行意见</th></tr>';
  11636. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11637. $html .= '<tr>
  11638. <td>' . $value [1] . '</td>
  11639. <td>' . $value ['opinion'] . '</td>
  11640. </tr>
  11641. ';
  11642. }
  11643. $html .= ' </tbody></table>';
  11644. if($accountType==1){
  11645. Doo::loadModel ( 'loanReceipt' );
  11646. $loanReceipt = new loanReceipt ();
  11647. $loanList = $loanReceipt->getOne ( array (
  11648. 'where' => 'rid=' . $detail ['loanRid'],
  11649. 'desc' => 'rid',
  11650. 'asArray' => true
  11651. ) );
  11652. $html .= '<table class="table table-bordered table-condensed">
  11653. <tr class="warning">
  11654. <td class="taR"><b>汇款金额</b></td>
  11655. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11656. </tr>
  11657. </table>';
  11658. }else{
  11659. $html .= '<table class="table table-bordered table-condensed">
  11660. <tr class="warning">
  11661. <td class="taR"><b>汇款金额</b></td>
  11662. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11663. </tr>
  11664. </table>';
  11665. }
  11666. // print_r($detail['verifyList']);
  11667. // header ( 'Content-Type:text/html;charset=utf-8' );
  11668. // echo $html;
  11669. echo json_encode ( array (
  11670. 'status' => 1,
  11671. 'html' => $html,
  11672. 'detail' => $detail
  11673. ) );
  11674. }
  11675. function getReceiptApproverHtml($detail = array()) {
  11676. Doo::loadModel ( 'loanReceipt' );
  11677. $loanReceipt = new loanReceipt ();
  11678. Doo::loadModel ( 'verify' );
  11679. $verify = new verify ();
  11680. Doo::loadModel ( 'staff' );
  11681. $staff = new staff ();
  11682. if (empty ( $detail ))
  11683. return array ();
  11684. $loanList = $loanReceipt->getOne ( array (
  11685. 'where' => 'rid=' . $detail ['loanRid'],
  11686. 'desc' => 'rid',
  11687. 'asArray' => true
  11688. ) );
  11689. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11690. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11691. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11692. else
  11693. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11694. } else
  11695. $verifyList = $verify->getOne ( array (
  11696. 'where' => 'vid=' . $detail ['verify'],
  11697. 'asArray' => true
  11698. ) );
  11699. $verifyList = json_decode ( $verifyList ['staff'], true );
  11700. Doo::loadModel ( 'role' );
  11701. $role = new role ();
  11702. $roleId = 0;
  11703. $flag = true;
  11704. $roleKey = 0;
  11705. $endStaffArray = array ();
  11706. $roleArrayCopy = array ();
  11707. foreach ( $verifyList as $k => $v ) {
  11708. // init verifyStaff
  11709. if ($v [1] == 'ROLE') {
  11710. if (! empty ( $verifyStaff )) {
  11711. $endStaffArray = end ( $verifyStaff );
  11712. }
  11713. $roleVerify = json_decode ( $v [3], true );
  11714. $roleKey = $k;
  11715. $roleArray = array ();
  11716. $rolename = $role->getOne ( array (
  11717. 'where' => 'rid=' . $v [0],
  11718. 'asArray' => true
  11719. ) );
  11720. foreach ( $roleVerify as $o => $p ) {
  11721. $staffID = explode ( '_', $p );
  11722. $staffInfo = $staff->getOne ( array (
  11723. 'where' => 'sid=' . $staffID [0],
  11724. 'asArray' => true
  11725. ) );
  11726. // print_r($staffID);
  11727. $exp = array (
  11728. 0 => $staffInfo ['sid'],
  11729. 1 => $staffID [1],
  11730. 2 => $staffInfo ['avatar'],
  11731. 'date' => '',
  11732. 'date' => '',
  11733. 'opinion' => '',
  11734. 'status' => '',
  11735. 'rolename' => $rolename ['name']
  11736. );
  11737. array_push ( $roleArray, $exp );
  11738. }
  11739. $roleArrayCopy [$v [0]] = $roleArray;
  11740. // $verifyList[$k]['roleArray']=$roleArray;
  11741. }
  11742. $verifyList [$k] ['date'] = "";
  11743. $verifyList [$k] ['opinion'] = "";
  11744. $verifyList [$k] ['status'] = "";
  11745. if (empty ( $verifyStaff )) {
  11746. $verifyList [$k] ['date'] = "";
  11747. $verifyList [$k] ['opinion'] = "";
  11748. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11749. $verifyList [$k] ['status'] = 4;
  11750. $flag = false;
  11751. }
  11752. } else {
  11753. foreach ( $verifyStaff as $m => $u ) {
  11754. if ($v [0] == $m) {
  11755. $verifyList [$k] ['date'] = $u ['date'];
  11756. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11757. $verifyList [$k] ['status'] = $u ['status'];
  11758. $flag = false;
  11759. break;
  11760. }
  11761. }
  11762. $endStaffArray = end ( $verifyStaff );
  11763. }
  11764. }
  11765. $rolename ['name'] = '';
  11766. if (! empty ( $roleId )) {
  11767. Doo::loadModel ( 'role' );
  11768. $role = new role ();
  11769. $rolename = $role->getOne ( array (
  11770. 'where' => 'rid=' . $roleId,
  11771. 'asArray' => true
  11772. ) );
  11773. }
  11774. if (! empty ( $verifyStaff ))
  11775. $endStaffArray = end ( $verifyStaff );
  11776. $KOP = false;
  11777. foreach ( $roleArrayCopy as $P => $A ) {
  11778. foreach ( $A as $MKI => $AVL ) {
  11779. if (! empty ( $verifyStaff )) {
  11780. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11781. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11782. $button = 4;
  11783. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11784. }
  11785. foreach ( $verifyStaff as $m => $u ) {
  11786. $AVLFK = $AVL [0] . '_R';
  11787. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11788. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11789. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11790. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11791. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11792. break;
  11793. }
  11794. }
  11795. } else {
  11796. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11797. $button = 4;
  11798. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11799. }
  11800. }
  11801. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11802. $KOP = true;
  11803. }
  11804. }
  11805. foreach ( $roleArrayCopy as $k => $v ) {
  11806. foreach ( $verifyList as $m => $n ) {
  11807. if ($n [0] == $k) {
  11808. array_splice ( $verifyList, $m, 1, $v );
  11809. }
  11810. }
  11811. }
  11812. // 费用执行人相关数据
  11813. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11814. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11815. foreach ( $executeCopy as $k => $v ) {
  11816. $executeCopy [$k] ['date'] = '';
  11817. $executeCopy [$k] ['opinion'] = '';
  11818. $executeCopy [$k] ['status'] = '';
  11819. if (! empty ( $executeStaff ))
  11820. foreach ( $executeStaff as $m => $u ) {
  11821. if ($v [0] == $m) {
  11822. $executeCopy [$k] ['date'] = $u ['date'];
  11823. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11824. $executeCopy [$k] ['status'] = $u ['status'];
  11825. break;
  11826. }
  11827. }
  11828. }
  11829. $detail ['executeCopy'] = $executeCopy;
  11830. $detail ['verifyList'] = $verifyList;
  11831. return $detail;
  11832. }
  11833. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11834. if (empty ( $detail ))
  11835. return '';
  11836. $html = '';
  11837. if ($detail ['Rtype'] == 0) { // 报销单
  11838. $html .= '<table class="table table-bordered table-condensed">
  11839. <tbody>
  11840. <tr>
  11841. <th colspan="2" class="taC">日常相关费用</th>
  11842. </tr>';
  11843. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11844. $html .= '
  11845. <tr>
  11846. <th>' . $value ['name'] . '</th>
  11847. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11848. </tr>';
  11849. }
  11850. $html .= '
  11851. <tr>
  11852. <th class="taR">合计</th>
  11853. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11854. </tr>';
  11855. $html .= '<tr>
  11856. <th colspan="2" class="taC">差旅相关费用</th>
  11857. </tr>';
  11858. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11859. $html .= '
  11860. <tr>
  11861. <th>' . $value ['name'] . '</th>
  11862. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11863. </tr>';
  11864. }
  11865. $html .= '
  11866. <tr>
  11867. <th class="taR">合计</th>
  11868. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11869. </tr>';
  11870. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11871. $html .= '<tr>
  11872. <th colspan="2" class="taC">内部培训费用</th>
  11873. </tr>';
  11874. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11875. $html .= '
  11876. <tr>
  11877. <th>' . $value ['name'] . '</th>
  11878. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11879. </tr>';
  11880. }
  11881. $html .= '
  11882. <tr>
  11883. <th class="taR">合计</th>
  11884. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11885. </tr>';
  11886. }
  11887. $html .= '<tr>
  11888. <th colspan="2" class="taC">其他</th>
  11889. </tr>';
  11890. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11891. $html .= '
  11892. <tr>
  11893. <th>' . $value ['name'] . '</th>
  11894. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11895. </tr>';
  11896. }
  11897. $html .= '
  11898. <tr>
  11899. <th class="taR">合计</th>
  11900. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11901. </tr>';
  11902. $html .= '<tr>
  11903. <th colspan="2" class="taC">报销金额调整</th>
  11904. </tr>';
  11905. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11906. $html .= '
  11907. <tr>
  11908. <th>' . $value ['name'] . '</th>
  11909. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11910. </tr>';
  11911. }
  11912. $html .= '
  11913. <tr>
  11914. <th class="taR">合计</th>
  11915. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11916. </tr>';
  11917. $html .= '
  11918. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11919. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11920. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11921. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11922. <tr class="warning">
  11923. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11924. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11925. </tr>
  11926. </tbody>
  11927. </table>';
  11928. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  11929. $html .= '
  11930. <table class="table table-bordered table-condensed">
  11931. <tbody>
  11932. <tr>
  11933. <th colspan="2" class="taC">办事处相关费用</th>
  11934. </tr>';
  11935. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11936. $html .= '
  11937. <tr>
  11938. <th>' . $value ['name'] . '</th>
  11939. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11940. </tr>';
  11941. }
  11942. $html .= '
  11943. <tr>
  11944. <th class="taR">合计</th>
  11945. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11946. </tr>';
  11947. $html .= '
  11948. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11949. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11950. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11951. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11952. <tr class="warning">
  11953. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11954. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11955. </tr>
  11956. </tbody>
  11957. </table>';
  11958. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  11959. Doo::loadModel ( 'loanReceipt' );
  11960. $loanReceipt = new loanReceipt ();
  11961. $loanList = $loanReceipt->getOne ( array (
  11962. 'where' => 'rid=' . $detail ['loanRid'],
  11963. 'desc' => 'rid',
  11964. 'asArray' => true
  11965. ) );
  11966. // print_r($loanList);
  11967. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  11968. $html .= '<table class="table table-bordered table-condensed">
  11969. <tbody>
  11970. <tr>
  11971. <th colspan="2" class="taC">借款费用</th>
  11972. </tr>';
  11973. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  11974. $html .= '<tr>
  11975. <th>' . $value ['name'] . '</th>
  11976. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11977. </tr>';
  11978. }
  11979. $html .= '<tr>
  11980. <th class="taC" colspan="2">产生费用所在办事处</th>
  11981. </tr>
  11982. <tr>
  11983. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  11984. </tr>
  11985. <tr>
  11986. <th class="taC" colspan="2">费用说明</th>
  11987. </tr>
  11988. <tr>
  11989. <td colspan="2">' . $loanList ['explanation'] . '</td>
  11990. </tr>
  11991. <tr class="warning">
  11992. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  11993. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  11994. </tr>
  11995. </tbody>
  11996. </table>
  11997. ';
  11998. if ( $accountType==2) {
  11999. $balance=$detail ['sum']-$loanList ['sum'];
  12000. $balanceCN=$this->num_to_rmb($balance);
  12001. $html .= '<table class="table table-bordered table-condensed">
  12002. <tbody>
  12003. <tr>
  12004. <th colspan="2" class="taC">日常相关费用</th>
  12005. </tr>';
  12006. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12007. $html .= '
  12008. <tr>
  12009. <th>' . $value ['name'] . '</th>
  12010. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12011. </tr>';
  12012. }
  12013. $html .= '
  12014. <tr>
  12015. <th class="taR">合计</th>
  12016. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12017. </tr>';
  12018. $html .= '<tr>
  12019. <th colspan="2" class="taC">差旅相关费用</th>
  12020. </tr>';
  12021. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12022. $html .= '
  12023. <tr>
  12024. <th>' . $value ['name'] . '</th>
  12025. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12026. </tr>';
  12027. }
  12028. $html .= '
  12029. <tr>
  12030. <th class="taR">合计</th>
  12031. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12032. </tr>';
  12033. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12034. $html .= '<tr>
  12035. <th colspan="2" class="taC">内部培训费用</th>
  12036. </tr>';
  12037. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12038. $html .= '
  12039. <tr>
  12040. <th>' . $value ['name'] . '</th>
  12041. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12042. </tr>';
  12043. }
  12044. $html .= '
  12045. <tr>
  12046. <th class="taR">合计</th>
  12047. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12048. </tr>';
  12049. }
  12050. $html .= '<tr>
  12051. <th colspan="2" class="taC">其他</th>
  12052. </tr>';
  12053. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12054. $html .= '
  12055. <tr>
  12056. <th>' . $value ['name'] . '</th>
  12057. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12058. </tr>';
  12059. }
  12060. $html .= '
  12061. <tr>
  12062. <th class="taR">合计</th>
  12063. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12064. </tr>';
  12065. $html .= '<tr>
  12066. <th colspan="2" class="taC">报销金额调整</th>
  12067. </tr>';
  12068. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12069. $html .= '
  12070. <tr>
  12071. <th>' . $value ['name'] . '</th>
  12072. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12073. </tr>';
  12074. }
  12075. $html .= '
  12076. <tr>
  12077. <th class="taR">合计</th>
  12078. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12079. </tr>';
  12080. $html .= '
  12081. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12082. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12083. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12084. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12085. <tr class="warning">
  12086. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12087. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12088. </tr>
  12089. <tr class="success">
  12090. <td class="taR"><b>借款结余</b></td>
  12091. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12092. </tr>
  12093. </tbody>
  12094. </table>';
  12095. }
  12096. }
  12097. return $html;
  12098. }
  12099. /**
  12100. * 计算流水
  12101. */
  12102. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12103. $bakWaste ['bank'] = array (
  12104. 'CGBDeposit' => 0,
  12105. 'ICBCDeposit' => 0,
  12106. 'HUADeposit' => 0,
  12107. 'PersonalDeposit' => 0
  12108. );
  12109. $bakWaste ['financial'] = array (
  12110. 'current' => array (
  12111. 'CGBDeposit' => 0,
  12112. 'ICBCDeposit' => 0
  12113. ),
  12114. 'fixed' => array (
  12115. 'CGBDeposit' => 0,
  12116. 'ICBCDeposit' => 0
  12117. )
  12118. );
  12119. // 存款
  12120. foreach ( $waste ['bank'] as $key => $value ) {
  12121. // 收入
  12122. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12123. // 广发
  12124. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12125. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12126. }
  12127. // 工商
  12128. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12129. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12130. }
  12131. // 华润
  12132. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12133. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12134. }
  12135. // 个人
  12136. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12137. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12138. }
  12139. }
  12140. }
  12141. foreach ( $waste ['bank'] as $key => $value ) {
  12142. // 支出
  12143. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12144. // 广发
  12145. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12146. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12147. }
  12148. // 工商
  12149. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12150. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12151. }
  12152. // 华润
  12153. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12154. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12155. }
  12156. // 个人
  12157. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12158. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12159. }
  12160. }
  12161. }
  12162. // 活期
  12163. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12164. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12165. // 广发
  12166. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12167. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12168. }
  12169. // 工商
  12170. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12171. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12172. }
  12173. // 个人
  12174. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12175. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12176. }
  12177. }
  12178. }
  12179. // print_r($inComeStatistics ['fixedStatistics']);
  12180. // 固期
  12181. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12182. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12183. // 广发
  12184. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12185. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12186. }
  12187. // 工商
  12188. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12189. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12190. }
  12191. // 个人
  12192. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12193. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12194. }
  12195. }
  12196. }
  12197. return $waste;
  12198. }
  12199. function lyt() {
  12200. Doo::loadModel ( "receiptDetail" );
  12201. $receiptDetail = new receiptDetail ();
  12202. $receiptCollectList = $receiptDetail->find ( array (
  12203. 'where' => 'status=1 ',
  12204. 'asArray' => true
  12205. ) );
  12206. foreach ( $receiptCollectList as $key => $value ) {
  12207. $receiptDetail = new receiptDetail ();
  12208. $receiptDetail->pastDate = $value ['date'];
  12209. $receiptDetail->update ( array (
  12210. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12211. ) );
  12212. }
  12213. }
  12214. function staffCollectMonthDetail() {
  12215. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12216. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12217. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12218. if (! $year)
  12219. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12220. if (! $month)
  12221. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12222. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12223. if (! $nature){
  12224. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12225. }
  12226. Doo::loadModel ( 'staff' );
  12227. $staff = new staff ();
  12228. Doo::loadModel ( "receiptDetail" );
  12229. $receiptDetail = new receiptDetail ();
  12230. Doo::loadModel ( 'accountItem' );
  12231. $accountItem = new accountItem ();
  12232. Doo::loadModel ( 'statistics' );
  12233. $statistics = new statistics ();
  12234. Doo::loadModel ( "receiptAuthorityManage" );
  12235. $receiptAuthorityManage = new receiptAuthorityManage ();
  12236. $aiList=$accountItem->getAccountItem();
  12237. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12238. $cidList = array ();
  12239. foreach ( $imcStaff as $key => $value ) {
  12240. array_push ( $cidList, $value ['cid'] );
  12241. }
  12242. $cidString = implode ( ',', $cidList );
  12243. $naturecon='';
  12244. if ($nature=='ONJOB'){
  12245. $naturecon=' and (nature!=4 )';
  12246. }elseif($nature=='LEAVEJOB'){
  12247. $naturecon=' and (nature=4 )';
  12248. }else{
  12249. die ( 'illegal request--nature' );
  12250. }
  12251. $staffList = $staff->find ( array (
  12252. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12253. 'asArray' => true
  12254. ) );
  12255. $categoryList = $staff->find ( array (
  12256. 'select' => 'COUNT(*) as count,cid,category',
  12257. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12258. 'groupby' => 'cid',
  12259. 'asArray' => true
  12260. ) );
  12261. $list = array ();
  12262. foreach($aiList as $key=>$value){
  12263. foreach ($value as $v){
  12264. $subtotal[$key][$v['name']]=0;
  12265. }
  12266. }
  12267. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12268. foreach ( $categoryList as $vlu ) {
  12269. $s1 = 0;
  12270. $m1 = 0;
  12271. foreach ( $staffList as $value ) {
  12272. if ($vlu ['cid'] == $value ['cid']) {
  12273. // pastDate
  12274. $receiptCollectList = $receiptDetail->find ( array (
  12275. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12276. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12277. 'groupby' => 'item,Month(pastDate),itemCategory',
  12278. 'asArray' => true
  12279. ) );
  12280. if (! empty ( $receiptCollectList )) {
  12281. $receiptL = array (
  12282. '日常相关费用' => array (),
  12283. '差旅相关费用' => array (),
  12284. '内部培训费用' => array (),
  12285. '培训班费用' => array (),
  12286. '其他' => array ()
  12287. );
  12288. $html = "";
  12289. $psum = 0;
  12290. foreach ( $aiList[$this->AGENCY] as $va ) {
  12291. $falg = true;
  12292. foreach ( $receiptCollectList as $v ) {
  12293. if ($v ['itemCategory'] == '日常相关费用') {
  12294. if ($v ['item'] == $va['name']) {
  12295. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12296. $psum += $v ['price'];
  12297. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12298. $falg = false;
  12299. break;
  12300. }
  12301. }
  12302. }
  12303. if ($falg)
  12304. $html .= '<td class="taR">-</td>';
  12305. }
  12306. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12307. if (! empty ( $psum ))
  12308. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12309. else
  12310. $psum = '<td class="colGreen taR">-</td>';
  12311. $receiptL ['日常相关费用'] = $psum . $html;
  12312. /* ----------------------------------- */
  12313. $html = "";
  12314. $psum = 0;
  12315. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12316. $falg = true;
  12317. foreach ( $receiptCollectList as $v ) {
  12318. if ($v ['itemCategory'] == '差旅相关费用') {
  12319. if ($v ['item'] == $va['name']) {
  12320. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12321. $psum += $v ['price'];
  12322. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12323. $falg = false;
  12324. break;
  12325. }
  12326. }
  12327. }
  12328. if ($falg)
  12329. $html .= '<td class="taR">-</td>';
  12330. }
  12331. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12332. if (! empty ( $psum ))
  12333. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12334. else
  12335. $psum = '<td class="colGreen taR">-</td>';
  12336. $receiptL ['差旅相关费用'] = $psum . $html;
  12337. /* ------------------------------------- */
  12338. $html = "";
  12339. $psum = 0;
  12340. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12341. $falg = true;
  12342. foreach ( $receiptCollectList as $v ) {
  12343. if ($v ['itemCategory'] == '内部培训费用') {
  12344. if ($v ['item'] == $va['name']) {
  12345. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12346. $psum += $v ['price'];
  12347. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12348. $falg = false;
  12349. break;
  12350. }
  12351. }
  12352. }
  12353. if ($falg)
  12354. $html .= '<td class="taR">-</td>';
  12355. }
  12356. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12357. if (! empty ( $psum ))
  12358. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12359. else
  12360. $psum = '<td class="colGreen taR">-</td>';
  12361. $receiptL ['内部培训费用'] = $psum . $html;
  12362. /* ----------------------------------- */
  12363. $html = "";
  12364. $psum = 0;
  12365. foreach ( $aiList[$this->TRAIN] as $va ) {
  12366. $falg = true;
  12367. foreach ( $receiptCollectList as $v ) {
  12368. if ($v ['itemCategory'] == '培训班费用') {
  12369. if ($v ['item'] == $va['name']) {
  12370. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12371. $psum += $v ['price'];
  12372. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12373. $falg = false;
  12374. break;
  12375. }
  12376. }
  12377. }
  12378. if ($falg)
  12379. $html .= '<td class="taR">-</td>';
  12380. }
  12381. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12382. if (! empty ( $psum ))
  12383. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12384. else
  12385. $psum = '<td class="colGreen taR">-</td>';
  12386. $receiptL ['培训班费用'] = $psum . $html;
  12387. /* ------------------------------------- */
  12388. $html = "";
  12389. $psum = 0;
  12390. foreach ( $aiList[$this->OTHER] as $va ) {
  12391. $falg = true;
  12392. foreach ( $receiptCollectList as $v ) {
  12393. if ($v ['itemCategory'] == '其他') {
  12394. if (trim ( $v ['item'] ) == $va['name']) {
  12395. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12396. $psum += $v ['price'];
  12397. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12398. $falg = false;
  12399. break;
  12400. }
  12401. }
  12402. }
  12403. if ($falg)
  12404. $html .= '<td class="taR">-</td>';
  12405. }
  12406. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12407. if (! empty ( $psum ))
  12408. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12409. else
  12410. $psum = '<td class="colGreen taR">-</td>';
  12411. $receiptL ['其他'] = $psum . $html;
  12412. /* ------------------------------------- */
  12413. $html = "";
  12414. $psum = 0;
  12415. foreach ( $receiptCollectList as $v ) {
  12416. if ($v ['itemCategory'] == '报销金额调整') {
  12417. if (! empty ( $v ['price'] )) {
  12418. $psum += $v ['price'];
  12419. }
  12420. }
  12421. }
  12422. $s1 += $psum;
  12423. if (! empty ( $psum ))
  12424. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12425. else
  12426. $psum = '<td class="taR colOrange">-</td>';
  12427. $receiptL ['报销金额调整'] = $psum . $html;
  12428. } else {
  12429. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12430. foreach ( $aiList[$this->AGENCY] as $va ) {
  12431. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12432. }
  12433. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12434. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12435. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12436. }
  12437. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12438. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12439. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12440. }
  12441. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12442. foreach ( $aiList[$this->TRAIN] as $va ) {
  12443. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12444. }
  12445. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12446. foreach ( $aiList[$this->OTHER] as $va ) {
  12447. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12448. }
  12449. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12450. }
  12451. $monthStaffPrice = $receiptDetail->find ( array (
  12452. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12453. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12454. 'groupby' => 'Month(pastDate)',
  12455. 'asArray' => true
  12456. ) );
  12457. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12458. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12459. $m1 += $monthStaffPrice [0] ['price'];
  12460. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12461. } else
  12462. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12463. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12464. $list [$value ['username']] = $receiptL;
  12465. }
  12466. }
  12467. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12468. foreach ( $aiList[$this->AGENCY] as $va ) {
  12469. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12470. }
  12471. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12472. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12473. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12474. }
  12475. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12476. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12477. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12478. }
  12479. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12480. foreach ( $aiList[$this->TRAIN] as $va ) {
  12481. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12482. }
  12483. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12484. foreach ( $aiList[$this->OTHER] as $va ) {
  12485. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12486. }
  12487. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12488. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12489. $receiptL ['usernameEn'] =false;
  12490. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12491. }
  12492. $data ['list'] = $list;
  12493. // print_r($list);
  12494. $receiptCollectList = $receiptDetail->find ( array (
  12495. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12496. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12497. 'groupby' => 'item,Month(pastDate),itemCategory',
  12498. 'asArray' => true
  12499. ) );
  12500. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12501. // statistics html
  12502. $stList = $statistics->getOne ( array (
  12503. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12504. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12505. 'groupby' => 'Month(date)',
  12506. 'asArray' => true
  12507. ) );
  12508. if (empty ( $stList ))
  12509. $stList = array (
  12510. 'rePrice' => 0,
  12511. 'agPrice' => 0
  12512. );
  12513. $data ['stList'] = array (
  12514. 'rePrice' => $stList ['rePrice'],
  12515. 'agPrice' => $stList ['agPrice'],
  12516. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12517. );
  12518. $monthHtml = "";
  12519. for($i = 1; $i <= 12; $i ++) {
  12520. if ($i == $month)
  12521. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12522. else
  12523. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12524. }
  12525. $data ['monthHtml'] = $monthHtml;
  12526. $data ['year'] = $year;
  12527. $data ['month'] = $month;
  12528. $data ['nature'] = $nature;
  12529. $data ['aiList'] = $aiList;
  12530. $data ['memu'] = "receipt";
  12531. $data ['staff'] = $this->staff;
  12532. $data ['receiptMemu'] = 'companyCategoryCollect';
  12533. $data ['verifyId'] = $this->verifyId;
  12534. $data ['executeId'] = $this->executeId;
  12535. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12536. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12537. }
  12538. function staffCollectMonthDetail2() {
  12539. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12540. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12541. if (! $year)
  12542. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12543. if (! $month)
  12544. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12545. Doo::loadModel ( 'staff' );
  12546. $staff = new staff ();
  12547. Doo::loadModel ( "receiptDetail" );
  12548. $receiptDetail = new receiptDetail ();
  12549. Doo::loadModel ( 'accountItem' );
  12550. $accountItem = new accountItem ();
  12551. Doo::loadModel ( 'statistics' );
  12552. $statistics = new statistics ();
  12553. Doo::loadModel ( 'L_category' );
  12554. $lCategory = new L_category ();
  12555. $staffList = $staff->find ( array (
  12556. 'where' => 'username!="admin"',
  12557. 'asArray' => true
  12558. ) );
  12559. $categoryList = $staff->find ( array (
  12560. 'select' => 'COUNT(*) as count,cid,category',
  12561. 'where' => 'username !="admin"',
  12562. 'groupby' => 'cid',
  12563. 'asArray' => true
  12564. ) );
  12565. $list = array ();
  12566. foreach ( $categoryList as $vlu ) {
  12567. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12568. $r1 = 0;
  12569. $r2 = 0;
  12570. $r3 = 0;
  12571. $r4 = 0;
  12572. $r5 = 0;
  12573. $r6 = 0;
  12574. $r7 = 0;
  12575. $r8 = 0;
  12576. $r9 = 0;
  12577. $r10 = 0;
  12578. $r11 = 0;
  12579. $r12 = 0;
  12580. $r13 = 0;
  12581. $r14 = 0;
  12582. $r15 = 0;
  12583. $c1 = 0;
  12584. $c2 = 0;
  12585. $c3 = 0;
  12586. $c4 = 0;
  12587. $c5 = 0;
  12588. $c6 = 0;
  12589. $p1 = 0;
  12590. $p2 = 0;
  12591. $p3 = 0;
  12592. $p4 = 0;
  12593. $p5 = 0;
  12594. $p6 = 0;
  12595. $p7 = 0;
  12596. $p8 = 0;
  12597. $p9 = 0;
  12598. $t1 = 0;
  12599. $t2 = 0;
  12600. $t3 = 0;
  12601. $t4 = 0;
  12602. $t5 = 0;
  12603. $s1 = 0;
  12604. $m1 = 0;
  12605. foreach ( $staffList as $value ) {
  12606. if ($vlu ['cid'] == $value ['cid']) {
  12607. $receiptCollectList = $receiptDetail->find ( array (
  12608. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12609. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12610. 'groupby' => 'item,Month(date),itemCategory',
  12611. 'asArray' => true
  12612. ) );
  12613. if (! empty ( $receiptCollectList )) {
  12614. $receiptL = array (
  12615. '日常相关费用' => array (),
  12616. '差旅相关费用' => array (),
  12617. '培训班费用' => array (),
  12618. '其他' => array ()
  12619. );
  12620. $html = "";
  12621. $psum = 0;
  12622. $item = array (
  12623. '市内交通费',
  12624. '市内出租费',
  12625. '办事处房租',
  12626. '电话费',
  12627. '水费',
  12628. '电费',
  12629. '办公费用',
  12630. '邮寄费',
  12631. '其他费用',
  12632. '车辆费用',
  12633. '广告费',
  12634. '团队建设费',
  12635. '物业管理费',
  12636. '宽带费'
  12637. );
  12638. foreach ( $item as $va ) {
  12639. $falg = true;
  12640. foreach ( $receiptCollectList as $v ) {
  12641. if ($v ['itemCategory'] == '日常相关费用') {
  12642. if ($v ['item'] == $va) {
  12643. if ($va == '市内交通费')
  12644. $r1 += $v ['price'];
  12645. if ($va == '市内出租费')
  12646. $r2 += $v ['price'];
  12647. if ($va == '办事处房租')
  12648. $r3 += $v ['price'];
  12649. if ($va == '电话费')
  12650. $r4 += $v ['price'];
  12651. if ($va == '水费')
  12652. $r5 += $v ['price'];
  12653. if ($va == '电费')
  12654. $r6 += $v ['price'];
  12655. if ($va == '办公费用')
  12656. $r7 += $v ['price'];
  12657. if ($va == '邮寄费')
  12658. $r8 += $v ['price'];
  12659. if ($va == '其他费用')
  12660. $r9 += $v ['price'];
  12661. if ($va == '车辆费用')
  12662. $r10 += $v ['price'];
  12663. if ($va == '广告费')
  12664. $r11 += $v ['price'];
  12665. if ($va == '团队建设费')
  12666. $r13 += $v ['price'];
  12667. if ($va == '物业管理费')
  12668. $r14 += $v ['price'];
  12669. if ($va == '宽带费')
  12670. $r15 += $v ['price'];
  12671. $psum += $v ['price'];
  12672. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12673. $falg = false;
  12674. break;
  12675. }
  12676. }
  12677. }
  12678. if ($falg)
  12679. $html .= '<td class="taR">-</td>';
  12680. }
  12681. $r12 += $psum;
  12682. if (! empty ( $psum ))
  12683. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12684. else
  12685. $psum = '<td class="colGreen taR">-</td>';
  12686. $receiptL ['日常相关费用'] = $psum . $html;
  12687. /* ----------------------------------- */
  12688. $html = "";
  12689. $psum = 0;
  12690. $item = array (
  12691. '往来交通费',
  12692. '市内交通费',
  12693. '出差住宿费',
  12694. '出差补助',
  12695. '其他费用'
  12696. );
  12697. foreach ( $item as $va ) {
  12698. $falg = true;
  12699. foreach ( $receiptCollectList as $v ) {
  12700. if ($v ['itemCategory'] == '差旅相关费用') {
  12701. if ($v ['item'] == $va) {
  12702. if ($va == '往来交通费')
  12703. $c1 += $v ['price'];
  12704. if ($va == '市内交通费')
  12705. $c2 += $v ['price'];
  12706. if ($va == '出差住宿费')
  12707. $c3 += $v ['price'];
  12708. if ($va == '出差补助')
  12709. $c4 += $v ['price'];
  12710. if ($va == '其他费用')
  12711. $c5 += $v ['price'];
  12712. $psum += $v ['price'];
  12713. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12714. $falg = false;
  12715. break;
  12716. }
  12717. }
  12718. }
  12719. if ($falg)
  12720. $html .= '<td class="taR">-</td>';
  12721. }
  12722. $c6 += $psum;
  12723. if (! empty ( $psum ))
  12724. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12725. else
  12726. $psum = '<td class="colGreen taR">-</td>';
  12727. $receiptL ['差旅相关费用'] = $psum . $html;
  12728. /* ------------------------------------- */
  12729. $html = "";
  12730. $psum = 0;
  12731. $item = array (
  12732. '场租费',
  12733. '薪酬',
  12734. '住宿费',
  12735. '交通费',
  12736. '餐饮费',
  12737. '办公费',
  12738. '公关费',
  12739. '其他'
  12740. );
  12741. foreach ( $item as $va ) {
  12742. $falg = true;
  12743. foreach ( $receiptCollectList as $v ) {
  12744. if ($v ['itemCategory'] == '培训班费用') {
  12745. if ($v ['item'] == $va) {
  12746. if ($va == '场租费')
  12747. $p1 += $v ['price'];
  12748. if ($va == '薪酬')
  12749. $p2 += $v ['price'];
  12750. if ($va == '住宿费')
  12751. $p3 += $v ['price'];
  12752. if ($va == '交通费')
  12753. $p4 += $v ['price'];
  12754. if ($va == '餐饮费')
  12755. $p5 += $v ['price'];
  12756. if ($va == '办公费')
  12757. $p6 += $v ['price'];
  12758. if ($va == '公关费')
  12759. $p7 += $v ['price'];
  12760. if ($va == '其他')
  12761. $p8 += $v ['price'];
  12762. $psum += $v ['price'];
  12763. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12764. $falg = false;
  12765. break;
  12766. }
  12767. }
  12768. }
  12769. if ($falg)
  12770. $html .= '<td class="taR">-</td>';
  12771. }
  12772. $p9 += $psum;
  12773. if (! empty ( $psum ))
  12774. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12775. else
  12776. $psum = '<td class="colGreen taR">-</td>';
  12777. $receiptL ['培训班费用'] = $psum . $html;
  12778. /* ------------------------------------- */
  12779. $html = "";
  12780. $psum = 0;
  12781. $item = array (
  12782. '公关费',
  12783. '广告费',
  12784. '借款',
  12785. '可自加费用'
  12786. );
  12787. foreach ( $item as $va ) {
  12788. $falg = true;
  12789. foreach ( $receiptCollectList as $v ) {
  12790. if ($v ['itemCategory'] == '其他') {
  12791. if ($v ['item'] == $va) {
  12792. if ($va == '公关费')
  12793. $t1 += $v ['price'];
  12794. if ($va == '广告费')
  12795. $t2 += $v ['price'];
  12796. if ($va == '借款')
  12797. $t3 += $v ['price'];
  12798. if ($va == '可自加费用')
  12799. $t4 += $v ['price'];
  12800. $psum += $v ['price'];
  12801. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12802. $falg = false;
  12803. break;
  12804. }
  12805. }
  12806. }
  12807. if ($falg)
  12808. $html .= '<td class="taR">-</td>';
  12809. }
  12810. $t5 += $psum;
  12811. if (! empty ( $psum ))
  12812. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12813. else
  12814. $psum = '<td class="colGreen taR">-</td>';
  12815. $receiptL ['其他'] = $psum . $html;
  12816. /* ------------------------------------- */
  12817. $html = "";
  12818. $psum = 0;
  12819. foreach ( $receiptCollectList as $v ) {
  12820. if ($v ['itemCategory'] == '报销金额调整') {
  12821. if (! empty ( $v ['price'] )) {
  12822. $psum += $v ['price'];
  12823. }
  12824. }
  12825. }
  12826. $s1 += $psum;
  12827. if (! empty ( $psum ))
  12828. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12829. else
  12830. $psum = '<td class="taR colOrange">-</td>';
  12831. $receiptL ['报销金额调整'] = $psum . $html;
  12832. } else {
  12833. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12834. <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>';
  12835. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12836. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12837. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12838. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12839. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12840. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12841. }
  12842. $monthStaffPrice = $receiptDetail->find ( array (
  12843. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12844. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12845. 'asArray' => true
  12846. ) );
  12847. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12848. $m1 += $monthStaffPrice [0] ['price'];
  12849. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12850. } else
  12851. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12852. $list [$value ['username']] = $receiptL;
  12853. }
  12854. }
  12855. $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>
  12856. <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>
  12857. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12858. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12859. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12860. $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>
  12861. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12862. $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>';
  12863. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12864. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12865. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12866. }
  12867. $data ['list'] = $list;
  12868. $receiptCollectList = $receiptDetail->find ( array (
  12869. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12870. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12871. 'groupby' => 'item,Month(date),itemCategory',
  12872. 'asArray' => true
  12873. ) );
  12874. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12875. // statistics html
  12876. $stList = $statistics->getOne ( array (
  12877. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12878. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12879. 'groupby' => 'Month(date)',
  12880. 'asArray' => true
  12881. ) );
  12882. if (empty ( $stList ))
  12883. $stList = array (
  12884. 'rePrice' => 0,
  12885. 'agPrice' => 0
  12886. );
  12887. $data ['stList'] = array (
  12888. 'rePrice' => $stList ['rePrice'],
  12889. 'agPrice' => $stList ['agPrice'],
  12890. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12891. );
  12892. $monthHtml = "";
  12893. for($i = 1; $i <= 12; $i ++) {
  12894. if ($i == $month)
  12895. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12896. else
  12897. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12898. }
  12899. $data ['monthHtml'] = $monthHtml;
  12900. $data ['year'] = $year;
  12901. $data ['month'] = $month;
  12902. $data ['memu'] = "receipt";
  12903. $data ['staff'] = $this->staff;
  12904. $data ['receiptMemu'] = 'companyCategoryCollect';
  12905. $data ['verifyId'] = $this->verifyId;
  12906. $data ['executeId'] = $this->executeId;
  12907. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12908. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12909. }
  12910. /**
  12911. * 用户报销单列表
  12912. */
  12913. function receiptStatisticsStaffDetail() {
  12914. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12915. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12916. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  12917. Doo::loadModel ( "receipt" );
  12918. $receipt = new receipt ();
  12919. Doo::loadModel ( "receiptDetail" );
  12920. $receiptDetail = new receiptDetail ();
  12921. Doo::loadModel ( 'staff' );
  12922. $staff = new staff ();
  12923. Doo::loadModel ( 'accountItem' );
  12924. $accountItem = new accountItem ();
  12925. Doo::loadModel ( 'statistics' );
  12926. $statistics = new statistics ();
  12927. if (! empty ( $username )) {
  12928. $username = addslashes ( urldecode ( $username ) );
  12929. $staffDetail = $staff->getStaffByName ( $username );
  12930. if (empty ( $staffDetail ))
  12931. die ( 'illegal request' );
  12932. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  12933. $itemList = $accountItem->getAccountItem ();
  12934. $itemHtml = '';
  12935. $categoryHtml = '';
  12936. $itemKeyList = array_keys ( $itemList );
  12937. $revisePrice = 0;
  12938. // 报销单内容详情
  12939. foreach ( $list as $key => $value ) {
  12940. $accountItemList = json_decode ( $value ['accountItem'], true );
  12941. $list [$key] ['accountItemList'] = $accountItemList;
  12942. $receiptItemHtml = '';
  12943. foreach ( $itemKeyList as $v ) {
  12944. if ($v == '日常相关费用')
  12945. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  12946. elseif ($v == '差旅相关费用')
  12947. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  12948. elseif ($v == '培训班费用')
  12949. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  12950. elseif ($v == '内部培训费用'){
  12951. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  12952. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  12953. }else{
  12954. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  12955. }
  12956. }elseif ($v == '其他')
  12957. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  12958. foreach ( $itemList [$v] as $ke => $va ) {
  12959. $falg = true;
  12960. if (! empty ( $accountItemList [$v] )) {
  12961. foreach ( $accountItemList [$v] as $ve ) {
  12962. if ($va ['name'] == $ve ['name']) {
  12963. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  12964. $falg = false;
  12965. break;
  12966. }
  12967. }
  12968. }
  12969. if ($falg)
  12970. $receiptItemHtml .= '<td class="taR"></td>';
  12971. }
  12972. }
  12973. // 金额调整和费用查看
  12974. $revisePrice += $value ['revisePrice'];
  12975. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  12976. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  12977. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  12978. }
  12979. // 报销单合计
  12980. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  12981. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  12982. $receiptTotalHtml = '';
  12983. // 报销单项目抬头
  12984. foreach ( $itemKeyList as $value ) {
  12985. $count = count ( $itemList [$value] ) + 1;
  12986. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  12987. $categoryHtml .= '<th class="taC">合计</th>';
  12988. $sumfalg=true;
  12989. foreach ( $rtl as $rtlValue ) {
  12990. if ($rtlValue ['itemCategory'] == $value) {
  12991. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  12992. $sumfalg=false;
  12993. break;
  12994. }
  12995. }
  12996. if ($sumfalg)
  12997. $receiptTotalHtml .= '<th></th>';
  12998. foreach ( $itemList [$value] as $k => $v ) {
  12999. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13000. // 合计
  13001. $falg = true;
  13002. foreach ( $receiptTotalList as $ve ) {
  13003. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13004. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13005. $falg = false;
  13006. break;
  13007. }
  13008. }
  13009. if ($falg)
  13010. $receiptTotalHtml .= '<th></th>';
  13011. }
  13012. }
  13013. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13014. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13015. if (empty ( $stList ))
  13016. $stList = array (
  13017. 'rePrice' => 0,
  13018. 'agPrice' => 0
  13019. );
  13020. $data ['stList'] = array (
  13021. 'rePrice' => $stList ['rePrice'],
  13022. 'agPrice' => $stList ['agPrice'],
  13023. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13024. );
  13025. $monthHtml = "";
  13026. for($i = 1; $i <= 12; $i ++) {
  13027. if ($i == $month)
  13028. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13029. else
  13030. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13031. }
  13032. $data ['username'] = urlencode ( $username );
  13033. $data ['usernameEN'] = $username;
  13034. $data ['monthHtml'] = $monthHtml;
  13035. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13036. $data ['list'] = $list;
  13037. $data ['categoryHtml'] = $categoryHtml;
  13038. $data ['itemHtml'] = $itemHtml;
  13039. $data ['itemList'] = $itemList;
  13040. $data ['year'] = $year;
  13041. $data ['month'] = $month;
  13042. $data ['memu'] = "receipt";
  13043. $data ['staff'] = $this->staff;
  13044. $data ['receiptMemu'] = 'companyCategoryCollect';
  13045. $data ['verifyId'] = $this->verifyId;
  13046. $data ['executeId'] = $this->executeId;
  13047. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13048. }
  13049. die ( 'illegal request' );
  13050. }
  13051. function companyMonthCollectDetail() {
  13052. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13053. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13054. if (! $year)
  13055. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13056. if (! $month)
  13057. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13058. Doo::loadModel ( 'staff' );
  13059. $staff = new staff ();
  13060. Doo::loadModel ( "receiptDetail" );
  13061. $receiptDetail = new receiptDetail ();
  13062. Doo::loadModel ( 'accountItem' );
  13063. $accountItem = new accountItem ();
  13064. Doo::loadModel ( 'statistics' );
  13065. $statistics = new statistics ();
  13066. Doo::loadModel ( 'L_category' );
  13067. $lCategory = new L_category ();
  13068. $staffList = $staff->find ( array (
  13069. 'where' => 'username!="admin"',
  13070. 'asArray' => true
  13071. ) );
  13072. $categoryList = $lCategory->find ( array (
  13073. 'asArray' => true
  13074. ) );
  13075. $aiList=$accountItem->getAccountItem();
  13076. $list = array ();
  13077. foreach ( $categoryList as $value ) {
  13078. $receiptCollectList = $receiptDetail->find ( array (
  13079. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13080. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13081. 'groupby' => 'item,Month(pastDate),itemCategory',
  13082. 'asArray' => true
  13083. ) );
  13084. if (! empty ( $receiptCollectList )) {
  13085. $receiptL = array (
  13086. '日常相关费用' => array (),
  13087. '差旅相关费用' => array (),
  13088. '内部培训费用' => array (),
  13089. '培训班费用' => array (),
  13090. '其他' => array ()
  13091. );
  13092. $html = "";
  13093. $psum = 0;
  13094. foreach ( $aiList[$this->AGENCY] as $va ) {
  13095. $falg = true;
  13096. foreach ( $receiptCollectList as $v ) {
  13097. if ($v ['itemCategory'] == $this->AGENCY) {
  13098. if ($v ['item'] == $va['name']) {
  13099. $psum += $v ['price'];
  13100. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13101. $falg = false;
  13102. break;
  13103. }
  13104. }
  13105. }
  13106. if ($falg)
  13107. $html .= '<td class="taR">-</td>';
  13108. }
  13109. if (! empty ( $psum ))
  13110. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13111. else
  13112. $psum = '<td class="colGreen taR">-</td>';
  13113. $receiptL [$this->AGENCY] = $psum . $html;
  13114. /* ----------------------------------- */
  13115. $html = "";
  13116. $psum = 0;
  13117. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13118. $falg = true;
  13119. foreach ( $receiptCollectList as $v ) {
  13120. if ($v ['itemCategory'] == $this->TRAVEL) {
  13121. if ($v ['item'] == $va['name']) {
  13122. $psum += $v ['price'];
  13123. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13124. $falg = false;
  13125. break;
  13126. }
  13127. }
  13128. }
  13129. if ($falg)
  13130. $html .= '<td class="taR">-</td>';
  13131. }
  13132. if (! empty ( $psum ))
  13133. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13134. else
  13135. $psum = '<td class="colGreen taR">-</td>';
  13136. $receiptL [$this->TRAVEL] = $psum . $html;
  13137. /* ------------------------------------- */
  13138. $html = "";
  13139. $psum = 0;
  13140. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13141. $falg = true;
  13142. foreach ( $receiptCollectList as $v ) {
  13143. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13144. if ($v ['item'] == $va['name']) {
  13145. $psum += $v ['price'];
  13146. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13147. $falg = false;
  13148. break;
  13149. }
  13150. }
  13151. }
  13152. if ($falg)
  13153. $html .= '<td class="taR">-</td>';
  13154. }
  13155. if (! empty ( $psum ))
  13156. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13157. else
  13158. $psum = '<td class="colGreen taR">-</td>';
  13159. $receiptL [$this->INTTRAIN] = $psum . $html;
  13160. /* ------------------------------------- */
  13161. $html = "";
  13162. $psum = 0;
  13163. foreach ( $aiList[$this->TRAIN] as $va ) {
  13164. $falg = true;
  13165. foreach ( $receiptCollectList as $v ) {
  13166. if ($v ['itemCategory'] == $this->TRAIN) {
  13167. if ($v ['item'] == $va['name']) {
  13168. $psum += $v ['price'];
  13169. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13170. $falg = false;
  13171. break;
  13172. }
  13173. }
  13174. }
  13175. if ($falg)
  13176. $html .= '<td class="taR">-</td>';
  13177. }
  13178. if (! empty ( $psum ))
  13179. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13180. else
  13181. $psum = '<td class="colGreen taR">-</td>';
  13182. $receiptL [$this->TRAIN] = $psum . $html;
  13183. /* ------------------------------------- */
  13184. $html = "";
  13185. $psum = 0;
  13186. foreach ( $aiList[$this->OTHER] as $va ) {
  13187. $falg = true;
  13188. foreach ( $receiptCollectList as $v ) {
  13189. if ($v ['itemCategory'] == $this->OTHER) {
  13190. if ($v ['item'] == $va['name']) {
  13191. $psum += $v ['price'];
  13192. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13193. $falg = false;
  13194. break;
  13195. }
  13196. }
  13197. }
  13198. if ($falg)
  13199. $html .= '<td class="taR">-</td>';
  13200. }
  13201. if (! empty ( $psum ))
  13202. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13203. else
  13204. $psum = '<td class="colGreen taR">-</td>';
  13205. $receiptL [$this->OTHER] = $psum . $html;
  13206. /* ------------------------------------- */
  13207. $html = "";
  13208. $psum = 0;
  13209. foreach ( $receiptCollectList as $v ) {
  13210. if ($v ['itemCategory'] == '报销金额调整') {
  13211. if (! empty ( $v ['price'] ))
  13212. $psum += $v ['price'];
  13213. }
  13214. }
  13215. if (! empty ( $psum ))
  13216. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13217. else
  13218. $psum = '<td class="taR colOrange">-</td>';
  13219. $receiptL ['报销金额调整'] = $psum . $html;
  13220. } else {
  13221. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13222. foreach ( $aiList[$this->AGENCY] as $va ) {
  13223. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13224. }
  13225. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13226. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13227. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13228. }
  13229. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13230. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13231. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13232. }
  13233. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13234. foreach ( $aiList[$this->TRAIN] as $va ) {
  13235. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13236. }
  13237. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13238. foreach ( $aiList[$this->OTHER] as $va ) {
  13239. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13240. }
  13241. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13242. }
  13243. $monthStaffPrice = $receiptDetail->find ( array (
  13244. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13245. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13246. 'asArray' => true
  13247. ) );
  13248. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13249. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13250. else
  13251. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13252. $list [$value ['title']] = $receiptL;
  13253. }
  13254. $data ['list'] = $list;
  13255. $receiptCollectList = $receiptDetail->find ( array (
  13256. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13257. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13258. 'groupby' => 'item,Month(pastDate),itemCategory',
  13259. 'asArray' => true
  13260. ) );
  13261. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13262. //print_r($data['monthPriceHtml']);
  13263. // foreach ($data['monthPriceHtml'] as $value){
  13264. // echo $value;
  13265. // }
  13266. // die;
  13267. // statistics html
  13268. $stList = $statistics->getOne ( array (
  13269. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13270. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13271. 'groupby' => 'Month(date)',
  13272. 'asArray' => true
  13273. ) );
  13274. if (empty ( $stList ))
  13275. $stList = array (
  13276. 'rePrice' => 0,
  13277. 'agPrice' => 0
  13278. );
  13279. $data ['stList'] = array (
  13280. 'rePrice' => $stList ['rePrice'],
  13281. 'agPrice' => $stList ['agPrice'],
  13282. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13283. );
  13284. $monthHtml = "";
  13285. for($i = 1; $i <= 12; $i ++) {
  13286. if ($i == $month)
  13287. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13288. else
  13289. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13290. }
  13291. $data ['aiList'] = $aiList;
  13292. $data ['monthHtml'] = $monthHtml;
  13293. $data ['year'] = $year;
  13294. $data ['month'] = $month;
  13295. $data ['memu'] = "receipt";
  13296. $data ['staff'] = $this->staff;
  13297. $data ['receiptMemu'] = 'companyCategoryCollect';
  13298. $data ['verifyId'] = $this->verifyId;
  13299. $data ['executeId'] = $this->executeId;
  13300. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13301. }
  13302. function staffCollectDetail() {
  13303. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13304. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13305. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13306. if (! $staffname) {
  13307. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13308. $staffname = urldecode ( $staffname );
  13309. }
  13310. Doo::loadModel ( 'staff' );
  13311. $staff = new staff ();
  13312. Doo::loadModel ( "receiptDetail" );
  13313. $receiptDetail = new receiptDetail ();
  13314. Doo::loadModel ( 'accountItem' );
  13315. $accountItem = new accountItem ();
  13316. Doo::loadModel ( 'statistics' );
  13317. $statistics = new statistics ();
  13318. Doo::loadModel ( 'L_category' );
  13319. $lCategory = new L_category ();
  13320. Doo::loadModel ( "receiptAuthorityManage" );
  13321. $receiptAuthorityManage = new receiptAuthorityManage ();
  13322. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13323. $cidList = array ();
  13324. foreach ( $imcStaff as $key => $value ) {
  13325. array_push ( $cidList, $value ['cid'] );
  13326. }
  13327. $cidString = implode ( ',', $cidList );
  13328. $staffList = $staff->find ( array (
  13329. 'where' => ' cid in (' . $cidString . ')',
  13330. 'asArray' => true
  13331. ) );
  13332. $stHtml = '';
  13333. $stTitle = "";
  13334. $staffId = 0;
  13335. $cid = 0;
  13336. $ocid = 0;
  13337. foreach ( $staffList as $value ) {
  13338. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13339. $stTitle = $value ['category'] . '-' . $value ['username'];
  13340. $staffId = $value ['sid'];
  13341. $cid = $value ['cid'];
  13342. $ocid = $value ['cid'];
  13343. if (! empty ( $value ['othercid'] ))
  13344. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13345. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13346. } elseif ($value ['username'] != 'admin')
  13347. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13348. }
  13349. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13350. 'where' => 'cid in(' . $cid . ')',
  13351. 'asArray' => true
  13352. ) );
  13353. if (empty ( $pcid ))
  13354. $pcid = $ocid;
  13355. $data ['ocid'] = $pcid;
  13356. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13357. $this->showCache ( $path );
  13358. //
  13359. $receiptCollectList = $receiptDetail->find ( array (
  13360. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13361. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13362. 'groupby' => 'item,Month(pastDate),itemCategory',
  13363. 'asArray' => true
  13364. ) );
  13365. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13366. // print_r($receiptCollectList);
  13367. $accountList = $accountItem->find ( array (
  13368. 'asArray' => true
  13369. ) );
  13370. // create CollectDetail HTML
  13371. $collectHtml = array ();
  13372. foreach ( $accountList as $key => $value ) {
  13373. $html = "";
  13374. $asum = 0;
  13375. for($i = 1; $i <= 12; $i ++) {
  13376. $falg = true;
  13377. foreach ( $receiptCollectList as $v ) {
  13378. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13379. if ($v ['item'] == '可自加费用') {
  13380. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13381. }
  13382. $asum += $v ['price'];
  13383. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13384. $falg = false;
  13385. break;
  13386. }
  13387. }
  13388. if ($falg)
  13389. $html .= '<td class="taR">-</td>';
  13390. }
  13391. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13392. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13393. }
  13394. $data ['collectHtml'] = $collectHtml;
  13395. // print_r($collectHtml);
  13396. // create Adjustment price html
  13397. $receiptCollectList = $receiptDetail->find ( array (
  13398. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13399. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13400. 'groupby' => 'itemCategory,Month(pastDate)',
  13401. 'asArray' => true
  13402. ) );
  13403. $adjustment = array ();
  13404. $collectArray = array (
  13405. '日常相关费用' => array (),
  13406. '差旅相关费用' => array (),
  13407. '培训班费用' => array (),
  13408. '内部培训费用'=>array(),
  13409. '其他' => array ()
  13410. );
  13411. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13412. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13413. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13414. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13415. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13416. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13417. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13418. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13419. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13420. array_push ( $collectArray ['其他'], $collectHtml );
  13421. $data ['collectArray'] = $collectArray;
  13422. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13423. array_push ( $adjustment, $collectHtml );
  13424. $data ['adjustment'] = $adjustment;
  13425. // total price html
  13426. $collectHtml = "";
  13427. $total = 0;
  13428. for($i = 1; $i <= 12; $i ++) {
  13429. $sumPrice = 0;
  13430. foreach ( $receiptCollectList as $key => $value ) {
  13431. if ($value ['month'] == $i) {
  13432. $sumPrice += $value ['price'];
  13433. }
  13434. }
  13435. if ($sumPrice == 0)
  13436. $collectHtml .= '<td class="taR">-</td>';
  13437. else
  13438. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13439. $total += $sumPrice;
  13440. }
  13441. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13442. // statistics html
  13443. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13444. if (empty ( $stList ))
  13445. $stList = array (
  13446. 'rePrice' => 0,
  13447. 'agPrice' => 0
  13448. );
  13449. $data ['stList'] = array (
  13450. 'rePrice' => $stList ['rePrice'],
  13451. 'agPrice' => $stList ['agPrice'],
  13452. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13453. );
  13454. $data ['totalPrice'] = $collectHtml;
  13455. $data ['totalYear'] = $total;
  13456. $data ['stHtml'] = $stHtml;
  13457. $data ['year'] = $year;
  13458. $data ['stTitle'] = $stTitle;
  13459. $data ['staffname'] = urlencode ( $staffname );
  13460. $data ['memu'] = "receipt";
  13461. $data ['staff'] = $this->staff;
  13462. $data ['receiptMemu'] = 'companyCategoryCollect';
  13463. $data ['verifyId'] = $this->verifyId;
  13464. $data ['executeId'] = $this->executeId;
  13465. if ($year < date ( "Y" )) {
  13466. Doo::loadModel ( 'receipt' );
  13467. $receipt = new receipt ();
  13468. $receiptList = $receipt->find ( array (
  13469. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13470. 'asArray' => true
  13471. ) );
  13472. if (empty ( $receiptList )) { // generated files
  13473. ob_start ();
  13474. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13475. $this->cacheFile ( $path );
  13476. die ();
  13477. }
  13478. }
  13479. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13480. }
  13481. function BUGFLAG() {
  13482. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13483. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13484. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13485. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13486. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13487. if (empty ( $status ))
  13488. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13489. $page_size = 12;
  13490. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13491. $vidList = array ();
  13492. $button = 0;
  13493. Doo::loadModel ( 'verify' );
  13494. $verify = new verify ();
  13495. Doo::loadModel ( 'receipt' );
  13496. $receipt = new receipt ();
  13497. Doo::loadModel ( 'staff' );
  13498. $staff = new staff ();
  13499. Doo::loadModel ( 'L_category' );
  13500. $Lcategory = new L_category ();
  13501. $dateCondition = " and Year(date) =" . $year;
  13502. if (! empty ( $month ))
  13503. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13504. $categoryList = $Lcategory->find ( array (
  13505. 'asArray' => true
  13506. ) );
  13507. $staffList = $staff->find ( array (
  13508. 'where' => 'cid=' . $cid,
  13509. 'asArray' => true
  13510. ) );
  13511. $cateCondition = "";
  13512. $staffCondition = "";
  13513. $approvalCondition = "";
  13514. if (! empty ( $cid ))
  13515. $cateCondition = ' and cid=' . $cid;
  13516. if (! empty ( $sid )) {
  13517. $staffCondition = ' and staff=' . $sid;
  13518. $cateCondition = "";
  13519. }
  13520. $approvalCondition = " and status=" . $status;
  13521. if ($status == 2) {
  13522. // 查找角色审批人
  13523. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13524. }
  13525. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13526. $approvalCondition = ' and status=2 ';
  13527. }
  13528. if ($status == 1) {
  13529. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13530. }
  13531. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13532. $pageinfo ['page'] = array (
  13533. 'previous' => ''
  13534. );
  13535. if ($status == 0) {
  13536. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13537. $receiptList = $receipt->find ( array (
  13538. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13539. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13540. 'desc' => 'rid',
  13541. 'asArray' => true
  13542. ) );
  13543. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13544. } else
  13545. $receiptList = $receipt->find ( array (
  13546. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13547. 'desc' => 'rid',
  13548. 'asArray' => true
  13549. ) );
  13550. $rLRes = $receipt->find ( array (
  13551. '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,
  13552. 'desc' => 'rid',
  13553. 'asArray' => true
  13554. ) );
  13555. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13556. // print_r($pageinfo);
  13557. $Locate = 0;
  13558. foreach ( $receiptList as $key => $value ) {
  13559. $receiptList [$key] ['Locate'] = $Locate;
  13560. $Locate ++;
  13561. $receiptList [$key] ['reviseDetail'] = array ();
  13562. if (! empty ( $value ['reviseDetail'] ))
  13563. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13564. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13565. $categoryDetil = $Lcategory->getOne ( array (
  13566. 'where' => 'cid=' . $value ['cid'],
  13567. 'asArray' => true
  13568. ) );
  13569. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13570. $verifyList = $verify->getOne ( array (
  13571. 'where' => 'vid=' . $value ['verify'],
  13572. 'asArray' => true
  13573. ) );
  13574. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13575. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13576. foreach ( $verifyList as $k => $v ) {
  13577. // init verifyStaff
  13578. $verifyList [$k] ['date'] = "";
  13579. $verifyList [$k] ['opinion'] = "";
  13580. $verifyList [$k] ['status'] = "";
  13581. if (empty ( $verifyStaff )) {
  13582. $verifyList [$k] ['date'] = "";
  13583. $verifyList [$k] ['opinion'] = "";
  13584. if ($v [0] == $this->staff [0] ['sid']) {
  13585. $verifyList [$k] ['status'] = 4;
  13586. $button = 4;
  13587. }
  13588. } else {
  13589. $flag = true;
  13590. foreach ( $verifyStaff as $m => $u ) {
  13591. if ($v [0] == $m) {
  13592. $verifyList [$k] ['date'] = $u ['date'];
  13593. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13594. $verifyList [$k] ['status'] = $u ['status'];
  13595. $flag = false;
  13596. break;
  13597. }
  13598. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13599. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13600. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13601. }
  13602. if ($flag) { // 检测可编辑
  13603. if ($v [0] == $this->staff [0] ['sid']) {
  13604. $verifyList [$k] ['status'] = 4;
  13605. $button = 4;
  13606. }
  13607. }
  13608. }
  13609. }
  13610. $receiptList [$key] ['verifyList'] = $verifyList;
  13611. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13612. 'where' => 'sid=' . $value ['staff'],
  13613. 'asArray' => true
  13614. ) );
  13615. $receiptList [$key] ['button'] = $button;
  13616. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13617. }
  13618. // print_r($receiptList);die;
  13619. // $data['verifyDetail']=$verifyDetail;
  13620. $mothHtml = "";
  13621. for($i = 1; $i <= 12; $i ++) {
  13622. if ($month == $i)
  13623. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13624. else
  13625. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13626. }
  13627. $data ['mothHtml'] = $mothHtml;
  13628. $data ['page'] = $pageinfo;
  13629. $data ['receiptList'] = $receiptList;
  13630. $data ['receiptApprovalCount'] = count ( $rLRes );
  13631. $data ['status'] = $status;
  13632. $data ['year'] = $year;
  13633. $data ['categoryList'] = $categoryList;
  13634. $data ['staffList'] = $staffList;
  13635. $data ['cid'] = $cid;
  13636. $data ['sid'] = $sid;
  13637. // print_r($receiptList);
  13638. $data ['memu'] = "receipt";
  13639. $data ['staff'] = $this->staff;
  13640. $data ['receiptMemu'] = 'approvalExpenses';
  13641. $data ['verifyId'] = $this->verifyId;
  13642. $data ['executeId'] = $this->executeId;
  13643. $this->render ( "/admin/FALG", $data );
  13644. }
  13645. function ajaxGetReceiptOrder() {
  13646. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13647. if (! empty ( $receiptOrder )) {
  13648. Doo::loadModel ( 'receipt' );
  13649. $receipt = new receipt ();
  13650. Doo::loadModel ( 'staff' );
  13651. $staff = new staff ();
  13652. $receiptInfo = $receipt->getOne ( array (
  13653. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13654. 'asArray' => true
  13655. ) );
  13656. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13657. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13658. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13659. </tbody></table><table class="table table table-bordered"><tbody>';
  13660. foreach ( $verifyStaff as $key => $value ) {
  13661. $staffInfo = $staff->getOne ( array (
  13662. 'select' => 'username',
  13663. 'where' => ' sid="' . $key . '"',
  13664. 'asArray' => true
  13665. ) );
  13666. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13667. }
  13668. $html .= '</tbody></table></div></div>';
  13669. echo json_encode ( array (
  13670. 'status' => 1,
  13671. 'receiptHtml' => $html
  13672. ) );
  13673. die ();
  13674. }
  13675. echo json_encode ( array (
  13676. 'status' => 2,
  13677. 'receiptHtml' => ''
  13678. ) );
  13679. die ();
  13680. }
  13681. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13682. if (! empty ( $receiptCollectList )) {
  13683. $receiptL = array (
  13684. '日常相关费用' => array (),
  13685. '差旅相关费用' => array (),
  13686. '内部培训费用'=>array(),
  13687. '培训班费用' => array (),
  13688. '其他' => array ()
  13689. );
  13690. $html = "";
  13691. $psum = 0;
  13692. foreach ( $aiList[$this->AGENCY] as $value ) {
  13693. $falg = true;
  13694. foreach ( $receiptCollectList as $v ) {
  13695. if ($v ['itemCategory'] == '日常相关费用') {
  13696. if ($v ['item'] == $value['name']) {
  13697. $psum += $v ['price'];
  13698. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13699. $falg = false;
  13700. break;
  13701. }
  13702. }
  13703. }
  13704. if ($falg)
  13705. $html .= '<td class="taR">-</td>';
  13706. }
  13707. if (! empty ( $psum ))
  13708. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13709. else
  13710. $psum = '<td class="colGreen taR">-</td>';
  13711. $receiptL ['日常相关费用'] = $psum . $html;
  13712. /* ----------------------------------- */
  13713. $html = "";
  13714. $psum = 0;
  13715. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13716. $falg = true;
  13717. foreach ( $receiptCollectList as $v ) {
  13718. if ($v ['itemCategory'] == '差旅相关费用') {
  13719. if ($v ['item'] == $value['name']) {
  13720. $psum += $v ['price'];
  13721. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13722. $falg = false;
  13723. break;
  13724. }
  13725. }
  13726. }
  13727. if ($falg)
  13728. $html .= '<td class="taR">-</td>';
  13729. }
  13730. if (! empty ( $psum ))
  13731. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13732. else
  13733. $psum = '<td class="colGreen taR">-</td>';
  13734. $receiptL ['差旅相关费用'] = $psum . $html;
  13735. /* ----------------------------------- */
  13736. $html = "";
  13737. $psum = 0;
  13738. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13739. $falg = true;
  13740. foreach ( $receiptCollectList as $v ) {
  13741. if ($v ['itemCategory'] == '内部培训费用') {
  13742. if ($v ['item'] == $value['name']) {
  13743. $psum += $v ['price'];
  13744. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13745. $falg = false;
  13746. break;
  13747. }
  13748. }
  13749. }
  13750. if ($falg)
  13751. $html .= '<td class="taR">-</td>';
  13752. }
  13753. if (! empty ( $psum ))
  13754. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13755. else
  13756. $psum = '<td class="colGreen taR">-</td>';
  13757. $receiptL ['内部培训费用'] = $psum . $html;
  13758. /* ------------------------------------- */
  13759. $html = "";
  13760. $psum = 0;
  13761. foreach ( $aiList[$this->TRAIN] as $value ) {
  13762. $falg = true;
  13763. foreach ( $receiptCollectList as $v ) {
  13764. if ($v ['itemCategory'] == '培训班费用') {
  13765. if ($v ['item'] == $value['name']) {
  13766. $psum += $v ['price'];
  13767. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13768. $falg = false;
  13769. break;
  13770. }
  13771. }
  13772. }
  13773. if ($falg)
  13774. $html .= '<td class="taR">-</td>';
  13775. }
  13776. if (! empty ( $psum ))
  13777. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13778. else
  13779. $psum = '<td class="colGreen taR">-</td>';
  13780. $receiptL ['培训班费用'] = $psum . $html;
  13781. /* ------------------------------------- */
  13782. $html = "";
  13783. $psum = 0;
  13784. foreach ( $aiList[$this->OTHER] as $value ) {
  13785. $falg = true;
  13786. foreach ( $receiptCollectList as $v ) {
  13787. if ($v ['itemCategory'] == '其他') {
  13788. if ($v ['item'] == $value['name']) {
  13789. $psum += $v ['price'];
  13790. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13791. $falg = false;
  13792. break;
  13793. }
  13794. }
  13795. }
  13796. if ($falg)
  13797. $html .= '<td class="taR">-</td>';
  13798. }
  13799. if (! empty ( $psum ))
  13800. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13801. else
  13802. $psum = '<td class="colGreen taR">-</td>';
  13803. $receiptL ['其他'] = $psum . $html;
  13804. /* ------------------------------------- */
  13805. $html = "";
  13806. $psum = 0;
  13807. foreach ( $receiptCollectList as $v ) {
  13808. if ($v ['itemCategory'] == '报销金额调整') {
  13809. if (! empty ( $v ['price'] ))
  13810. $psum += $v ['price'];
  13811. }
  13812. }
  13813. if (! empty ( $psum ))
  13814. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13815. else
  13816. $psum = '<td class="taR colOrange">-</td>';
  13817. $receiptL ['报销金额调整'] = $psum . $html;
  13818. } else {
  13819. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13820. foreach ( $aiList[$this->AGENCY] as $va ) {
  13821. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13822. }
  13823. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13824. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13825. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13826. }
  13827. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13828. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13829. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13830. }
  13831. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13832. foreach ( $aiList[$this->TRAIN] as $va ) {
  13833. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13834. }
  13835. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13836. foreach ( $aiList[$this->OTHER] as $va ) {
  13837. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13838. }
  13839. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13840. }
  13841. return $receiptL;
  13842. }
  13843. function eMail() {
  13844. Doo::loadModel ( 'staff' );
  13845. $staff = new staff ();
  13846. Doo::loadModel ( 'receipt' );
  13847. $receipt = new receipt ();
  13848. Doo::loadModel ( 'L_category' );
  13849. $Lcategory = new L_category ();
  13850. Doo::loadModel ( "verify" );
  13851. $verify = new verify ();
  13852. $staffList = $staff->find ( array (
  13853. 'asArray' => true
  13854. ) );
  13855. foreach ( $staffList as $key => $value ) {
  13856. if ($value ['username'] != 'admin') {
  13857. // 提交人
  13858. $receiptList = $receipt->find ( array (
  13859. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13860. 'asArray' => true
  13861. ) );
  13862. if (! empty ( $receiptList )) {
  13863. $html = '<br><div><style></style>
  13864. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13865. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13866. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13867. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13868. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13869. <tbody><tr>
  13870. <td style="padding: 0 40px;" align="left">
  13871. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13872. </td></tr><tr>
  13873. <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>
  13874. </tr>
  13875. </tbody> </table></td> </tr> <tr><td>
  13876. <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">
  13877. <tbody> <tr><td>
  13878. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13879. 以下报销单完成了审批,等着收款吧:</p>
  13880. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13881. foreach ( $receiptList as $k => $v ) {
  13882. $category = $Lcategory->getOne ( array (
  13883. 'where' => 'cid=' . $v ['cid'],
  13884. 'asArray' => true
  13885. ) );
  13886. $html .= '
  13887. <tr>
  13888. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13889. <td align="left">
  13890. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13891. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13892. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13893. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13894. </tr>';
  13895. }
  13896. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13897. <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>
  13898. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13899. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13900. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13901. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13902. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13903. $receipt = new receipt ();
  13904. $receipt->notice = 1;
  13905. $receipt->update ( array (
  13906. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13907. ) );
  13908. }
  13909. }
  13910. // 审批人
  13911. $verifyList = $verify->find ( array (
  13912. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13913. 'asArray' => true
  13914. ) );
  13915. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  13916. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  13917. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13918. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  13919. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13920. <tbody><tr><td style="padding: 0 40px;" align="left">
  13921. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13922. </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>
  13923. </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">
  13924. <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>
  13925. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  13926. foreach ( $verifyList as $k => $v ) {
  13927. $receiptList = $receipt->find ( array (
  13928. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  13929. 'asArray' => true
  13930. ) );
  13931. foreach ( $receiptList as $r => $l ) {
  13932. $category = $Lcategory->getOne ( array (
  13933. 'where' => 'cid=' . $l ['cid'],
  13934. 'asArray' => true
  13935. ) );
  13936. $staffDetile = $staff->getOne ( array (
  13937. 'where' => 'sid=' . $l ['staff'],
  13938. 'asArray' => true
  13939. ) );
  13940. $html .= '
  13941. <tr>
  13942. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13943. <td align="left">
  13944. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  13945. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  13946. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  13947. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  13948. </tr>';
  13949. }
  13950. }
  13951. $html .= '
  13952. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  13953. <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>
  13954. </tr></tbody></table></td></tr></tbody></table></div><br>';
  13955. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  13956. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  13957. // $receipt=new receipt();
  13958. // $receipt->notice=1;
  13959. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  13960. }
  13961. }
  13962. }
  13963. }
  13964. function setWXMsg($rid, $type) {
  13965. Doo::loadModel ( "receipt" );
  13966. $receipt = new receipt ();
  13967. $receiptDetail = $receipt->getOne ( array (
  13968. 'where' => 'rid=' . $rid,
  13969. 'asArray' => true
  13970. ) );
  13971. if (! empty ( $receiptDetail )) {
  13972. Doo::loadModel ( 'staff' );
  13973. $staff = new staff ();
  13974. $staffmsg = $staff->getOne ( array (
  13975. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  13976. 'asArray' => TRUE
  13977. ) );
  13978. if (! empty ( $staffmsg ['wxid'] )) {
  13979. require_once (SITE_PATH . '/protected/class/client.php');
  13980. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  13981. $user = $staffmsg ['wxid'];
  13982. $receiptName = '';
  13983. $msg = '';
  13984. switch ($receiptDetail ['Rtype']) {
  13985. case 0 :
  13986. $receiptName = '报销';
  13987. break;
  13988. case 1 :
  13989. $receiptName = '借款';
  13990. break;
  13991. case 2 :
  13992. $receiptName = '对公汇款';
  13993. break;
  13994. }
  13995. switch ($type) {
  13996. case 1 :
  13997. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  13998. break;
  13999. case 2 :
  14000. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14001. break;
  14002. case 3 :
  14003. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14004. break;
  14005. }
  14006. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14007. }
  14008. }
  14009. }
  14010. // Email发送函数
  14011. function SMail($toemail, $subject, $contents) {
  14012. Doo::loadClass ( 'class.phpmailer' );
  14013. $mail = new PHPMailer ();
  14014. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14015. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14016. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14017. $mail->Password = "cDO1GjtY1seH"; // 密码
  14018. $mail->CharSet = "UTF8";
  14019. $mail->SMTPAuth = true;
  14020. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14021. $mail->Mailer = "smtp";
  14022. $mail->Port = 25;
  14023. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14024. $mail->MsgHTML ( $contents );
  14025. $mail->AddAddress ( $toemail );
  14026. $mail->CharSet = "UTF-8";
  14027. return $mail->Send ();
  14028. }
  14029. function h5Upload() {
  14030. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14031. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14032. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14033. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14034. header ( "HTTP/1.1 500 Internal Server Error" );
  14035. echo "POST exceeded maximum allowed size.";
  14036. exit ( 0 );
  14037. }
  14038. // Settings
  14039. $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)
  14040. $upload_name = "Filedata";
  14041. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14042. $extension_whitelist = array (
  14043. "doc",
  14044. "txt",
  14045. "jpg",
  14046. "gif",
  14047. "png"
  14048. ); // Allowed file extensions
  14049. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14050. // Other variables
  14051. $MAX_FILENAME_LENGTH = 260;
  14052. $file_name = "";
  14053. $file_extension = "";
  14054. $uploadErrors = array (
  14055. 0 => "文件上传成功",
  14056. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14057. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14058. 3 => "上传的文件仅为部分文件",
  14059. 4 => "没有文件上传",
  14060. 6 => "缺少临时文件夹"
  14061. );
  14062. $nk = time ();
  14063. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14064. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14065. echo "文件无法保存.";
  14066. exit ( 0 );
  14067. }
  14068. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14069. echo json_encode ( array (
  14070. 'filename' => $file_name,
  14071. 'id' => $nk
  14072. ) );
  14073. exit ( 0 );
  14074. }
  14075. function swfupload() {
  14076. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14077. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14078. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14079. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14080. header ( "HTTP/1.1 500 Internal Server Error" );
  14081. echo "POST exceeded maximum allowed size.";
  14082. exit ( 0 );
  14083. }
  14084. // Settings
  14085. $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)
  14086. $upload_name = "Filedata";
  14087. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14088. $extension_whitelist = array (
  14089. "doc",
  14090. "txt",
  14091. "jpg",
  14092. "gif",
  14093. "png"
  14094. ); // Allowed file extensions
  14095. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14096. // Other variables
  14097. $MAX_FILENAME_LENGTH = 260;
  14098. $file_name = "";
  14099. $file_extension = "";
  14100. $uploadErrors = array (
  14101. 0 => "文件上传成功",
  14102. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14103. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14104. 3 => "上传的文件仅为部分文件",
  14105. 4 => "没有文件上传",
  14106. 6 => "缺少临时文件夹"
  14107. );
  14108. $nk = time ();
  14109. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14110. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14111. echo "文件无法保存.";
  14112. exit ( 0 );
  14113. }
  14114. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14115. echo json_encode ( array (
  14116. 'filename' => $file_name,
  14117. 'id' => $nk
  14118. ) );
  14119. exit ( 0 );
  14120. }
  14121. function _GetFileEXT($filename) {
  14122. $pics = explode ( '.', $filename );
  14123. $num = count ( $pics );
  14124. return $pics [$num - 1];
  14125. }
  14126. /**
  14127. * 获取get或者POST值
  14128. * @param string $name 属性名称
  14129. * @return fixed 值
  14130. */
  14131. function get_args($name) {
  14132. if (isset ( $_GET [$name] )) {
  14133. if (is_array ( $_GET [$name] ))
  14134. return $_GET [$name];
  14135. else
  14136. return addslashes ( $_GET [$name] );
  14137. } elseif (isset ( $_POST [$name] )) {
  14138. if (is_array ( $_POST [$name] ))
  14139. return $_POST [$name];
  14140. else
  14141. return addslashes ( $_POST [$name] );
  14142. } else
  14143. return false;
  14144. }
  14145. function num_to_rmb($num) {
  14146. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14147. $c2 = "分角元拾佰仟万拾佰仟亿";
  14148. // 精确到分后面就不要了,所以只留两个小数位
  14149. $num = round ( $num, 2 );
  14150. // 将数字转化为整数
  14151. $num = $num * 100;
  14152. if (strlen ( $num ) > 10) {
  14153. return "金额太大,请检查";
  14154. }
  14155. $i = 0;
  14156. $c = "";
  14157. while ( 1 ) {
  14158. if ($i == 0) {
  14159. // 获取最后一位数字
  14160. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14161. } else {
  14162. $n = $num % 10;
  14163. }
  14164. // 每次将最后一位数字转化为中文
  14165. $p1 = substr ( $c1, 3 * $n, 3 );
  14166. $p2 = substr ( $c2, 3 * $i, 3 );
  14167. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14168. $c = $p1 . $p2 . $c;
  14169. } else {
  14170. $c = $p1 . $c;
  14171. }
  14172. $i = $i + 1;
  14173. // 去掉数字最后一位了
  14174. $num = $num / 10;
  14175. // echo $num.'</br>';
  14176. $num = ( int ) $num;
  14177. // $num =floor($num);
  14178. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14179. // echo $num.'</br>';
  14180. // 结束循环
  14181. if ($num == 0) {
  14182. break;
  14183. }
  14184. }
  14185. // echo $c.'</br>';
  14186. $j = 0;
  14187. $slen = strlen ( $c );
  14188. while ( $j < $slen ) {
  14189. // utf8一个汉字相当3个字符
  14190. $m = substr ( $c, $j, 6 );
  14191. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14192. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14193. $left = substr ( $c, 0, $j );
  14194. $right = substr ( $c, $j + 3 );
  14195. $c = $left . $right;
  14196. $j = $j - 3;
  14197. $slen = $slen - 3;
  14198. }
  14199. $j = $j + 3;
  14200. }
  14201. // 这个是为了去掉类似23.0中最后一个“零”字
  14202. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14203. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14204. }
  14205. // 将处理的汉字加上“整”
  14206. if (empty ( $c )) {
  14207. return "零元整";
  14208. } else {
  14209. return $c . "整";
  14210. }
  14211. }
  14212. /**
  14213. * 获得分页数据
  14214. * @param unknown_type $table
  14215. * @param unknown_type $condition
  14216. * @param unknown_type $on_page
  14217. * @param unknown_type $page_size
  14218. */
  14219. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14220. $page_c = "";
  14221. $page ['previous'] = $this->get_previous ( $on_page );
  14222. $page ['on_page'] = $on_page;
  14223. $total_count = $this->get_table_count ( $table, $condition );
  14224. $total = intval ( $total_count / $page_size );
  14225. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14226. $page ['total_data'] = $total_count;
  14227. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14228. $i = 1;
  14229. $page_max = 1;
  14230. $page_width = 3;
  14231. if ($on_page >= $page_width) {
  14232. $page_max = intval ( $on_page / $page_width ) + 1;
  14233. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14234. }
  14235. for(; $i <= $page ['total_page']; $i ++) {
  14236. if ($i == $on_page)
  14237. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14238. else
  14239. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14240. if ($i == ($page_width * $page_max))
  14241. break;
  14242. }
  14243. $page ['page'] = $page_c;
  14244. $page ['lower'] = (-- $on_page) * $page_size;
  14245. return $page;
  14246. }
  14247. /**
  14248. * 获取总页数
  14249. * @param unknown_type $table
  14250. * @param unknown_type $condition
  14251. */
  14252. public function get_table_count($table = "", $condition = "") {
  14253. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14254. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14255. // echo $sql;die;
  14256. $query = Doo::db ()->query ( $sql );
  14257. $result = $query->fetch ();
  14258. return $result ['count'];
  14259. }
  14260. /**
  14261. * 获取上一页
  14262. * @param unknown_type $on_page
  14263. */
  14264. function get_previous($on_page = 1) {
  14265. return $on_page != 0 ? $on_page - 1 : $on_page;
  14266. }
  14267. }
  14268. ?>