ReceiptController.php 535 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. public function beforeRun($resource, $action) {
  58. Doo::loadClass ( 'XDeode' );
  59. $XDeode = new XDeode ( 5 );
  60. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  61. // 单独判断公司汇总的访问权限
  62. if ($action == 'companyCategoryCollect') {
  63. Doo::loadModel ( "receiptAuthorityManage" );
  64. $invoiceCompanyManage = new receiptAuthorityManage ();
  65. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  66. if (empty ( $icm ))
  67. die ( 'illegal request' );
  68. }
  69. Doo::loadModel ( 'staff' );
  70. $staff = new staff ();
  71. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  72. $accessModular = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'where'=>'mold !="日常收支"',
  121. 'select' => 'staff',
  122. 'asArray' => true
  123. ) );
  124. $list2 = array ();
  125. foreach ( $executeList as $key => $value ) {
  126. $ver = json_decode ( $value ['staff'] );
  127. foreach ( $ver as $k => $v ) {
  128. array_push ( $list2, $v [0] );
  129. }
  130. }
  131. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  132. $eidList = array_filter ( explode ( ",", $eidList ) );
  133. $this->executeId = array_merge ( $list2, $eidList );
  134. $this->verifyId = $list;
  135. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  136. // 检测用户信息完成
  137. $this->data ['isStaffCompleteMsg'] = false;
  138. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  139. if (! empty ( $detail ))
  140. $this->data ['isStaffCompleteMsg'] = true;
  141. return "/";
  142. }
  143. }
  144. Doo::loadCore ( 'uri/DooUriRouter' );
  145. $router = new DooUriRouter ();
  146. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  147. if ($routeRs ['1'] != "login") {
  148. header ( 'Content-Type:text/html;charset=utf-8' );
  149. @header ( "Location: /login" );
  150. }
  151. }
  152. function saeaBorad() {
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'verify' );
  156. $verify = new verify ();
  157. Doo::loadModel ( 'L_category' );
  158. $lCategory = new L_category ();
  159. Doo::loadModel ( "role" );
  160. $role = new role ();
  161. Doo::loadModel ( "receiptLog" );
  162. $receiptLog = new receiptLog ();
  163. Doo::loadClass ( 'XDeode' );
  164. $XDeode = new XDeode ( 7 );
  165. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  166. $receiptDetail = $receipt->find ( array (
  167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  168. 'desc' => 'rid',
  169. 'asArray' => true
  170. ) );
  171. foreach ( $receiptDetail as $key => $value ) {
  172. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  173. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  174. $veList = $verify->getOne ( array (
  175. 'where' => 'vid=' . $value ['verify'],
  176. 'asArray' => true
  177. ) );
  178. $v = json_decode ( $veList ['staff'] );
  179. array_push ( $v [0], $veList ['description'] );
  180. foreach ( $v as $n => $m ) {
  181. if ($m ['1'] == 'ROLE') {
  182. $roleInfo = $role->getOne ( array (
  183. 'where' => 'rid=' . $m [0],
  184. 'asArray' => true
  185. ) );
  186. $v [$n] [1] = $roleInfo ['name'];
  187. }
  188. }
  189. $receiptDetail [$key] ['staff'] = $v;
  190. $category = $lCategory->getOne ( array (
  191. 'where' => 'cid=' . $value ['cid'],
  192. 'asArray' => true
  193. ) );
  194. $receiptDetail [$key] ['category'] = $category ['title'];
  195. }
  196. // print_r($receiptLogList);
  197. Doo::loadModel ( 'RAssist' );
  198. $RAssist = new RAssist ();
  199. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  200. $data ['receiptExtendList'] = $receiptExtendList;
  201. $data ['receiptLogList'] = $receiptLogList;
  202. $data ['receiptDetail'] = $receiptDetail;
  203. $data ['memu'] = "receipt";
  204. $data ['staff'] = $this->staff;
  205. $data ['receiptMemu'] = 'saeaBorad';
  206. $data ['verifyId'] = $this->verifyId;
  207. $data ['executeId'] = $this->executeId;
  208. $this->render ( "/admin/saeaBorad", $data );
  209. }
  210. function remitAdd() {
  211. Doo::loadModel ( 'accountItem' );
  212. Doo::loadModel ( 'verify' );
  213. Doo::loadModel ( 'receipt' );
  214. Doo::loadModel ( 'L_category' );
  215. $lCategory = new L_category ();
  216. $receipt = new receipt ();
  217. $verify = new verify ();
  218. $accountItem = new accountItem ();
  219. Doo::loadModel ( "role" );
  220. $role = new role ();
  221. $acItem = $accountItem->find ( array (
  222. 'asArray' => true
  223. ) );
  224. $veList = $verify->getVerifyBySubordinate('REMIT');
  225. $data ['category'] = $lCategory->find ( array (
  226. 'asArray' => true
  227. ) );
  228. $data ['veList'] = $veList;
  229. $data ['acItem'] = $acItem;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/admin/remitAdd", $data );
  236. }
  237. function remitAddDo() {
  238. $agency = $this->get_args ( 'agency' );
  239. $travel = $this->get_args ( 'travel' );
  240. $train = $this->get_args ( 'train' );
  241. $other = $this->get_args ( 'other' );
  242. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  243. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  244. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  245. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  246. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  247. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  248. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  249. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  250. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  251. // print_r($agency);die;
  252. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  253. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  254. header ( 'Content-Type:text/html;charset=utf-8' );
  255. die ( '请填写联行号' );
  256. }
  257. Doo::loadModel ( 'receipt' );
  258. Doo::loadModel ( 'receiptDetail' );
  259. Doo::loadModel ( 'accountItem' );
  260. $accountItem = new accountItem ();
  261. $receipt = new receipt ();
  262. Doo::loadModel ( 'enclosur' );
  263. Doo::loadModel ( 'execute' );
  264. $execute = new execute ();
  265. $executeDetail = $execute->getOne ( array (
  266. 'where' => 'mold="对公汇款执行人"',
  267. 'asArray' => true
  268. ) );
  269. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  270. $aItem = $accountItem->find ( array (
  271. 'where' => '(name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  272. 'asArray' => true
  273. ) );
  274. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  275. $ag = $tr = $ta = $ot = 0;
  276. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  277. print_r($aItem);
  278. foreach ( $aItem as $key => $value ) {
  279. if ($value ['category'] == $this->AGENCY) {
  280. if (isset ( $agency [$ag] )) {
  281. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  282. array_push ( $accountJson [$this->AGENCY], array (
  283. 'aid' => $value ['aid'],
  284. 'name' => $value ['name'],
  285. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  286. ) );
  287. $sum += $agency [$ag];
  288. $agencySum += $agency [$ag];
  289. }
  290. }
  291. $ag ++;
  292. }
  293. }
  294. $accountJson ['cSum'] = array (
  295. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  296. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  297. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  298. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  299. );
  300. //die;
  301. // 报销单
  302. $receipt->accountItem = json_encode ( $accountJson );
  303. $receipt->staff = $this->staff [0] ['sid'];
  304. $receipt->sum = number_format ( $sum, 2, '.', '' );
  305. $receipt->date = date ( "Y-m-d" );
  306. $receipt->cid = $cid;
  307. $receipt->status = 5;
  308. $receipt->Rtype = 2;
  309. // 修改审批流程加入角色
  310. $receipt->verify = $verify;
  311. $receipt->executeCopy = $executeDetail ['staff'];
  312. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  313. $order = array (
  314. "\r\n",
  315. "\n",
  316. "\r"
  317. );
  318. $replace = '<br/>';
  319. $explanation = str_replace ( $order, $replace, $explanation );
  320. $receipt->explanation = $explanation;
  321. $receipt->remittanceName = $remittanceName;
  322. $receipt->bankName = $bankName;
  323. $receipt->bankNumber = $bankNumber;
  324. $receipt->remittanceBankType = $remittanceBankType;
  325. if ($remittanceBankType == 1)
  326. $receipt->coupletNumber = $coupletNumber;
  327. $rid = $receipt->insert ();
  328. // 附件
  329. if (! empty ( $enclosurName )) {
  330. $enclosurArray = explode ( '-', $enclosurName );
  331. foreach ( $enclosurArray as $value ) {
  332. $enclosur = new enclosur ();
  333. $enclosur->name = $value;
  334. $enclosur->rid = $rid;
  335. $enclosur->insert ();
  336. }
  337. // print_r($enclosurArray);die;
  338. }
  339. // 报销详情
  340. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  341. $receiptDetail = new receiptDetail ();
  342. $receiptDetail->staff = $this->staff [0] ['sid'];
  343. $receiptDetail->item = $value ['name'];
  344. $receiptDetail->itemCategory = $this->AGENCY;
  345. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  346. $receiptDetail->date = date ( "Y-m-d" );
  347. $receiptDetail->cid = $cid;
  348. $receiptDetail->rid = $rid;
  349. $receiptDetail->status = 4;
  350. $receiptDetail->insert ();
  351. }
  352. return "/saeaBorad";
  353. } else
  354. die ( 'illegal request' );
  355. }
  356. function remitEdit() {
  357. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  358. Doo::loadClass ( 'XDeode' );
  359. $XDeode = new XDeode ( 7 );
  360. $rid = $XDeode->decode ( $ridKey );
  361. if (! is_numeric ( $rid ))
  362. die ( 'illegal request' );
  363. Doo::loadModel ( 'accountItem' );
  364. Doo::loadModel ( 'verify' );
  365. Doo::loadModel ( 'receipt' );
  366. $receipt = new receipt ();
  367. $verify = new verify ();
  368. $accountItem = new accountItem ();
  369. Doo::loadModel ( 'L_category' );
  370. $lCategory = new L_category ();
  371. Doo::loadModel ( "role" );
  372. $role = new role ();
  373. Doo::loadModel ( 'enclosur' );
  374. $enclosur = new enclosur ();
  375. $receiptDetail = $receipt->getOne ( array (
  376. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  377. 'asArray' => true
  378. ) );
  379. if (empty ( $receiptDetail ))
  380. return "/saeaCreate";
  381. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  382. $acItem = $accountItem->find ( array (
  383. 'asArray' => true
  384. ) );
  385. $veList = $verify->getVerifyBySubordinate('REMIT');
  386. // 配置编辑信息
  387. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  388. foreach ( $acItem as $key => $value ) {
  389. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  390. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  391. $acItem [$key] ['price'] = $v ['price'];
  392. }
  393. }
  394. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  395. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  396. $acItem [$key] ['price'] = $v ['price'];
  397. }
  398. }
  399. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  400. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  401. $acItem [$key] ['price'] = $v ['price'];
  402. }
  403. }
  404. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  405. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  406. $acItem [$key] ['price'] = $v ['price'];
  407. }
  408. }
  409. }
  410. $data ['category'] = $lCategory->find ( array (
  411. 'asArray' => true
  412. ) );
  413. $data ['enclosurList'] = $enclosurList;
  414. $data ['cSum'] = $accountItemList ['cSum'];
  415. $data ['sum'] = $receiptDetail ['sum'];
  416. $data ['receiptDetail'] = $receiptDetail;
  417. $data ['veList'] = $veList;
  418. $data ['acItem'] = $acItem;
  419. $data ['memu'] = "receipt";
  420. $data ['staff'] = $this->staff;
  421. $data ['receiptMemu'] = 'saeaBorad';
  422. $data ['verify'] = $receiptDetail ['verify'];
  423. $data ['verifyId'] = $this->verifyId;
  424. $data ['executeId'] = $this->executeId;
  425. $data ['rid'] = $rid;
  426. $data ['ridKey'] = $ridKey;
  427. $this->render ( "/admin/remitEdit", $data );
  428. }
  429. function remitEdiDo() {
  430. $agency = $this->get_args ( 'agency' );
  431. $travel = $this->get_args ( 'travel' );
  432. $train = $this->get_args ( 'train' );
  433. $other = $this->get_args ( 'other' );
  434. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  435. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  436. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  437. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  438. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  439. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  440. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  441. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  442. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  443. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  444. Doo::loadClass ( 'XDeode' );
  445. $XDeode = new XDeode ( 7 );
  446. $rid = $XDeode->decode ( $ridKey );
  447. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  448. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  449. header ( 'Content-Type:text/html;charset=utf-8' );
  450. die ( '请填写联行号' );
  451. }
  452. Doo::loadModel ( 'receipt' );
  453. Doo::loadModel ( 'receiptDetail' );
  454. Doo::loadModel ( 'accountItem' );
  455. $accountItem = new accountItem ();
  456. $receipt = new receipt ();
  457. Doo::loadModel ( 'enclosur' );
  458. $enclosur = new enclosur ();
  459. Doo::loadModel ( 'execute' );
  460. $execute = new execute ();
  461. $executeDetail = $execute->getOne ( array (
  462. 'where' => 'mold="对公汇款执行人"',
  463. 'asArray' => true
  464. ) );
  465. $receiptDetail = $receipt->getOne ( array (
  466. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  467. 'asArray' => true
  468. ) );
  469. if (empty ( $receiptDetail ))
  470. return "/saeaBorad";
  471. $aItem = $accountItem->find ( array (
  472. 'where' => '(name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  473. 'asArray' => true
  474. ) );
  475. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  476. $ag = $tr = $ta = $ot = 0;
  477. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  478. foreach ( $aItem as $key => $value ) {
  479. if ($value ['category'] == $this->AGENCY) {
  480. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  481. array_push ( $accountJson [$this->AGENCY], array (
  482. 'aid' => $value ['aid'],
  483. 'name' => $value ['name'],
  484. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  485. ) );
  486. $sum += $agency [$ag];
  487. $agencySum += $agency [$ag];
  488. }
  489. $ag ++;
  490. }
  491. }
  492. $accountJson ['cSum'] = array (
  493. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  494. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  495. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  496. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  497. );
  498. // 报销单
  499. $rid = $receipt->rid = $receiptDetail ['rid'];
  500. $receipt->accountItem = json_encode ( $accountJson );
  501. $receipt->staff = $this->staff [0] ['sid'];
  502. $receipt->sum = number_format ( $sum, 2, '.', '' );
  503. $receipt->date = date ( "Y-m-d" );
  504. $receipt->cid = $cid;
  505. if ($receiptDetail ['Rtype'] == 1)
  506. $receipt->status = 7;
  507. else
  508. $receipt->status = 5;
  509. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  510. $receipt->verify = $verify;
  511. $receipt->executeCopy = $executeDetail ['staff'];
  512. $order = array (
  513. "\r\n",
  514. "\n",
  515. "\r"
  516. );
  517. $replace = '<br/>';
  518. $explanation = str_replace ( $order, $replace, $explanation );
  519. $receipt->explanation = $explanation;
  520. $receipt->remittanceName = $remittanceName;
  521. $receipt->bankName = $bankName;
  522. $receipt->bankNumber = $bankNumber;
  523. $receipt->remittanceBankType = $remittanceBankType;
  524. if ($remittanceBankType == 1)
  525. $receipt->coupletNumber = $coupletNumber;
  526. $receipt->update ();
  527. $receiptDetail = new receiptDetail ();
  528. $receiptDetail->delete ( array (
  529. 'where' => 'rid=' . $rid
  530. ) );
  531. // 报销详情
  532. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  533. $receiptDetail = new receiptDetail ();
  534. $receiptDetail->staff = $this->staff [0] ['sid'];
  535. $receiptDetail->item = $value ['name'];
  536. $receiptDetail->itemCategory = $this->AGENCY;
  537. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  538. $receiptDetail->date = date ( "Y-m-d" );
  539. $receiptDetail->cid = $cid;
  540. $receiptDetail->rid = $rid;
  541. $receiptDetail->status = 4;
  542. $receiptDetail->insert ();
  543. }
  544. // 附件
  545. if (! empty ( $enclosurName )) {
  546. $enclosurArray = explode ( '-', $enclosurName );
  547. foreach ( $enclosurArray as $value ) {
  548. $enclosur = new enclosur ();
  549. $enclosur->name = $value;
  550. $enclosur->rid = $rid;
  551. $enclosur->insert ();
  552. }
  553. }
  554. }
  555. return "/saeaBorad";
  556. }
  557. function remitApproval() {
  558. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  559. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  561. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  562. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  563. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  564. if (empty ( $status ))
  565. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  566. $vidList = array ();
  567. $button = 0;
  568. Doo::loadModel ( 'verify' );
  569. Doo::loadModel ( 'receipt' );
  570. Doo::loadModel ( 'staff' );
  571. $staff = new staff ();
  572. $receipt = new receipt ();
  573. $verify = new verify ();
  574. Doo::loadModel ( 'L_category' );
  575. $Lcategory = new L_category ();
  576. Doo::loadModel ( 'enclosur' );
  577. $enclosur = new enclosur ();
  578. // user verify ID
  579. $verifyDetail = $verify->find ( array (
  580. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  581. 'asArray' => true
  582. ) );
  583. foreach ( $verifyDetail as $key => $value ) {
  584. array_push ( $vidList, $value ['vid'] );
  585. }
  586. $vid = implode ( ",", $vidList );
  587. if (empty ( $verifyDetail ))
  588. $vid = 0;
  589. $categoryList = $Lcategory->find ( array (
  590. 'asArray' => true
  591. ) );
  592. $staffList = $staff->find ( array (
  593. 'where' => 'cid=' . $cid,
  594. 'asArray' => true
  595. ) );
  596. $ap = "";
  597. if ($status == 4) {
  598. $ap = 4;
  599. $status = 2;
  600. }
  601. // get Receipt By verifyID status 2
  602. $receiptList = $receipt->find ( array (
  603. 'where' => 'rid =' . $rid . ' and status=2',
  604. 'desc' => 'rid',
  605. 'asArray' => true
  606. ) );
  607. if (empty ( $receiptList )) {
  608. die ( 'illegal request' );
  609. }
  610. $Locate = 0;
  611. $roleId = 0;
  612. if ($ap == 4)
  613. $status = 4;
  614. foreach ( $receiptList as $key => $value ) {
  615. $receiptList [$key] ['Locate'] = $Locate;
  616. $Locate ++;
  617. $receiptList [$key] ['reviseDetail'] = array ();
  618. if (! empty ( $value ['reviseDetail'] ))
  619. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  620. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  621. $categoryDetil = $Lcategory->getOne ( array (
  622. 'where' => 'cid=' . $value ['cid'],
  623. 'asArray' => true
  624. ) );
  625. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  626. // 检测编辑状态
  627. $verifyList = $verify->getOne ( array (
  628. 'where' => 'vid=' . $value ['verify'],
  629. 'asArray' => true
  630. ) );
  631. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  632. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  633. Doo::loadModel ( 'role' );
  634. $role = new role ();
  635. // print_r($verifyList);
  636. $flag = true;
  637. $roleKey = 0;
  638. $endStaffArray = array ();
  639. $roleArrayCopy = array ();
  640. foreach ( $verifyList as $k => $v ) {
  641. // init verifyStaff
  642. if ($v [1] == 'ROLE') {
  643. if (! empty ( $verifyStaff )) {
  644. $endStaffArray = end ( $verifyStaff );
  645. if ($v [0] == $endStaffArray ['nextStaff']) {
  646. $roleId = $v [0];
  647. }
  648. }
  649. $roleVerify = json_decode ( $v [3], true );
  650. $roleKey = $k;
  651. $roleArray = array ();
  652. $rolename = $role->getOne ( array (
  653. 'where' => 'rid=' . $v [0],
  654. 'asArray' => true
  655. ) );
  656. foreach ( $roleVerify as $o => $p ) {
  657. $staffID = explode ( '_', $p );
  658. $staffInfo = $staff->getOne ( array (
  659. 'where' => 'sid=' . $staffID [0],
  660. 'asArray' => true
  661. ) );
  662. // print_r($staffID);
  663. $exp = array (
  664. 0 => $staffInfo ['sid'],
  665. 1 => $staffID [1],
  666. 2 => $staffInfo ['avatar'],
  667. 'date' => '',
  668. 'date' => '',
  669. 'opinion' => '',
  670. 'status' => '',
  671. 'rolename' => $rolename ['name']
  672. );
  673. array_push ( $roleArray, $exp );
  674. }
  675. $roleArrayCopy [$v [0]] = $roleArray;
  676. // $verifyList[$k]['roleArray']=$roleArray;
  677. }
  678. // print_r($roleArray);
  679. $verifyList [$k] ['date'] = "";
  680. $verifyList [$k] ['opinion'] = "";
  681. $verifyList [$k] ['status'] = "";
  682. if (empty ( $verifyStaff )) {
  683. $verifyList [$k] ['date'] = "";
  684. $verifyList [$k] ['opinion'] = "";
  685. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  686. $verifyList [$k] ['status'] = 4;
  687. $button = 4;
  688. $flag = false;
  689. }
  690. } else {
  691. foreach ( $verifyStaff as $m => $u ) {
  692. if ($v [0] == $m) {
  693. $verifyList [$k] ['date'] = $u ['date'];
  694. $verifyList [$k] ['opinion'] = $u ['opinion'];
  695. $verifyList [$k] ['status'] = $u ['status'];
  696. $flag = false;
  697. break;
  698. }
  699. }
  700. $endStaffArray = end ( $verifyStaff );
  701. if (isset ( $endStaffArray ['ROLE'] )) {
  702. } else {
  703. $endKey = key ( $verifyStaff );
  704. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  705. $button = 4;
  706. $verifyList [$k] ['status'] = 4;
  707. }
  708. }
  709. }
  710. }
  711. $rolename ['name'] = '';
  712. if (! empty ( $roleId )) {
  713. Doo::loadModel ( 'role' );
  714. $role = new role ();
  715. $rolename = $role->getOne ( array (
  716. 'where' => 'rid=' . $roleId,
  717. 'asArray' => true
  718. ) );
  719. }
  720. if (! empty ( $verifyStaff ))
  721. $endStaffArray = end ( $verifyStaff );
  722. $KOP = false;
  723. foreach ( $roleArrayCopy as $P => $A ) {
  724. foreach ( $A as $MKI => $AVL ) {
  725. if (! empty ( $verifyStaff )) {
  726. // &&$rolename['rid']==$endStaffArray['nextStaff']
  727. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  728. $button = 4;
  729. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  730. }
  731. foreach ( $verifyStaff as $m => $u ) {
  732. $AVLFK = $AVL [0] . '_R';
  733. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  734. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  735. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  736. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  737. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  738. break;
  739. }
  740. }
  741. } else {
  742. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  743. $button = 4;
  744. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  745. }
  746. }
  747. // $roleArray[$MKI]['rolename']=$rolename['name'];
  748. $KOP = true;
  749. }
  750. }
  751. foreach ( $roleArrayCopy as $k => $v ) {
  752. foreach ( $verifyList as $m => $n ) {
  753. if ($n [0] == $k) {
  754. array_splice ( $verifyList, $m, 1, $v );
  755. }
  756. }
  757. }
  758. $receiptList [$key] ['verifyList'] = $verifyList;
  759. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  760. 'where' => 'sid=' . $value ['staff'],
  761. 'asArray' => true
  762. ) );
  763. $receiptList [$key] ['button'] = $button;
  764. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  765. }
  766. $mothHtml = "";
  767. for($i = 1; $i <= 12; $i ++) {
  768. if ($month == $i)
  769. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  770. else
  771. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  772. }
  773. // 获取审批日志
  774. Doo::loadModel ( 'receiptLog' );
  775. $receiptLog = new receiptLog ();
  776. $rlList = array ();
  777. $rlInfo = $receiptLog->getOne ( array (
  778. 'where' => 'rid=' . $rid . ' and status=4',
  779. 'asArray' => true
  780. ) );
  781. $tijdate = $receiptLog->getOne ( array (
  782. 'where' => 'rid=' . $rid . ' and status=2',
  783. 'asc' => 'rlid',
  784. 'asArray' => true
  785. ) );
  786. if (! empty ( $rlInfo )) {
  787. $rlList = $receiptLog->find ( array (
  788. 'where' => 'rid=' . $rid,
  789. 'asc' => 'rlid',
  790. 'asArray' => true
  791. ) );
  792. }
  793. $receiptList [0] ['rlList'] = $rlList;
  794. $enclosurList = $enclosur->find ( array (
  795. 'where' => 'rid=' . $rid,
  796. 'asArray' => true
  797. ) );
  798. $enclosurHtml = '';
  799. foreach ( $enclosurList as $value ) {
  800. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  801. }
  802. // print_r($receiptList);
  803. $data ['enclosurHtml'] = $enclosurHtml;
  804. $data ['rolename'] = $rolename ['name'];
  805. $data ['datetij'] = $tijdate ['date'];
  806. $data ['mothHtml'] = $mothHtml;
  807. $data ['rid'] = $rid;
  808. $data ['receiptList'] = $receiptList;
  809. $data ['receiptApprovalCount'] = count ( $receiptList );
  810. $data ['status'] = $status;
  811. $data ['year'] = $year;
  812. $data ['categoryList'] = $categoryList;
  813. $data ['staffList'] = $staffList;
  814. $data ['cid'] = $cid;
  815. $data ['sid'] = $sid;
  816. $data ['ap'] = $ap;
  817. $data ['memu'] = "receipt";
  818. $data ['staff'] = $this->staff;
  819. $data ['receiptMemu'] = 'approvalExpenses';
  820. $data ['verifyId'] = $this->verifyId;
  821. $data ['executeId'] = $this->executeId;
  822. $this->render ( "/admin/remitApproval", $data );
  823. }
  824. function saeaLoanAdd() {
  825. Doo::loadModel ( 'verify' );
  826. $verify = new verify ();
  827. Doo::loadModel ( "role" );
  828. $role = new role ();
  829. Doo::loadModel ( 'L_category' );
  830. $lCategory = new L_category ();
  831. $veList = $verify->getVerifyBySubordinate('LOAN');
  832. $data ['category'] = $lCategory->find ( array (
  833. 'asArray' => true
  834. ) );
  835. $data ['veList'] = $veList;
  836. $data ['memu'] = "receipt";
  837. $data ['staff'] = $this->staff;
  838. $data ['receiptMemu'] = 'saeaBorad';
  839. $data ['verifyId'] = $this->verifyId;
  840. $data ['executeId'] = $this->executeId;
  841. $this->render ( "/admin/saeaLoanAdd", $data );
  842. }
  843. function saeaLoanAddDo() {
  844. $agency = $this->get_args ( 'agency' );
  845. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  846. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  847. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  848. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  849. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  850. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  851. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  852. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  853. // die;
  854. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  855. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  856. header ( 'Content-Type:text/html;charset=utf-8' );
  857. die ( '请填写联行号' );
  858. }
  859. Doo::loadModel ( 'receipt' );
  860. Doo::loadModel ( 'receiptDetail' );
  861. Doo::loadModel ( 'accountItem' );
  862. $accountItem = new accountItem ();
  863. $receipt = new receipt ();
  864. Doo::loadModel ( 'loanReceipt' );
  865. $loanReceipt = new loanReceipt ();
  866. Doo::loadModel ( 'execute' );
  867. $execute = new execute ();
  868. Doo::loadModel ( 'enclosur' );
  869. $executeDetail = $execute->getOne ( array (
  870. 'where' => 'mold="借款执行人"',
  871. 'asArray' => true
  872. ) );
  873. $aItem = $accountItem->find ( array (
  874. 'asArray' => true
  875. ) );
  876. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  877. $ag = $tr = $ta = $ot = 0;
  878. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  879. array_push ( $accountJson ['借款费用'], array (
  880. 'aid' => 0,
  881. 'name' => '申请金额',
  882. 'price' => number_format ( $agency, 2, '.', '' )
  883. ) );
  884. $sum += $agency;
  885. $agencySum += $agency;
  886. $accountJson ['cSum'] = array (
  887. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  888. 'agencySum' => number_format ( 0, 2, '.', '' ),
  889. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  890. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  891. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  892. );
  893. // 借款数据备份
  894. $loanReceipt->loanItem = json_encode ( $accountJson );
  895. $loanReceipt->staff = $this->staff [0] ['sid'];
  896. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  897. $loanReceipt->date = date ( "Y-m-d" );
  898. $loanReceipt->cid = $cid;
  899. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  900. $loanReceipt->status = 5;
  901. $loanReceipt->Rtype = 1;
  902. $loanReceipt->verify = $verify;
  903. $receipt->receiptOrder = $receipt->receiptOrder;
  904. // 添加HTML换行符
  905. // var_dump($explanation);
  906. $order = array (
  907. "\r\n",
  908. "\n",
  909. "\r"
  910. );
  911. $replace = '<br/>';
  912. $explanation = str_replace ( $order, $replace, $explanation );
  913. // $explanation=str_replace('\r',"<br/>",$explanation);
  914. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  915. $loanReceipt->explanation = $explanation;
  916. $loanRid = $loanReceipt->insert ();
  917. // 报销单
  918. $receipt->loanItem = json_encode ( $accountJson );
  919. $receipt->staff = $this->staff [0] ['sid'];
  920. $receipt->sum = number_format ( $sum, 2, '.', '' );
  921. $receipt->date = date ( "Y-m-d" );
  922. $receipt->cid = $cid;
  923. // 特殊状态
  924. $receipt->status = 5;
  925. $receipt->Rtype = 1;
  926. $receipt->loanRid = $loanRid;
  927. // 修改审批流程加入角色
  928. $receipt->verify = $verify;
  929. $receipt->executeCopy = $executeDetail ['staff'];
  930. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  931. $receipt->explanation = $explanation;
  932. $receipt->remittanceName = $remittanceName;
  933. $receipt->bankName = $bankName;
  934. $receipt->bankNumber = $bankNumber;
  935. $receipt->remittanceBankType = $remittanceBankType;
  936. if ($remittanceBankType == 1)
  937. $receipt->coupletNumber = $coupletNumber;
  938. $rid = $receipt->insert ();
  939. return "/saeaBorad";
  940. } else
  941. die ( 'illegal request' );
  942. }
  943. function saeaLoanEdi() {
  944. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  945. Doo::loadClass ( 'XDeode' );
  946. $XDeode = new XDeode ( 7 );
  947. $rid = $XDeode->decode ( $ridKey );
  948. if (! is_numeric ( $rid ))
  949. die ( 'illegal request' );
  950. Doo::loadModel ( 'verify' );
  951. $verify = new verify ();
  952. Doo::loadModel ( "role" );
  953. $role = new role ();
  954. Doo::loadModel ( 'L_category' );
  955. $lCategory = new L_category ();
  956. Doo::loadModel ( 'receipt' );
  957. $receipt = new receipt ();
  958. $receiptInfo = $receipt->getOne ( array (
  959. 'where' => 'rid=' . $rid,
  960. 'asArray' => true
  961. ) );
  962. $veList = $verify->find ( array (
  963. 'where'=>'subordinate like "%LOAN%"',
  964. 'asArray' => true
  965. ) );
  966. foreach ( $veList as $key => $value ) {
  967. $v = json_decode ( $value ['staff'] );
  968. $list = array ();
  969. foreach ( $v as $n => $m ) {
  970. if ($m ['1'] == 'ROLE') {
  971. $roleInfo = $role->getOne ( array (
  972. 'where' => 'rid=' . $m [0],
  973. 'asArray' => true
  974. ) );
  975. $v [$n] [1] = $roleInfo ['name'];
  976. array_push ( $list, $roleInfo ['name'] );
  977. } else {
  978. array_push ( $list, $v [$n] [1] );
  979. }
  980. }
  981. $veList [$key] ['staff'] = implode ( '>', $list );
  982. }
  983. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  984. // print_r($receiptInfo);
  985. $data ['receiptInfo'] = $receiptInfo;
  986. $data ['category'] = $lCategory->find ( array (
  987. 'asArray' => true
  988. ) );
  989. $data ['veList'] = $veList;
  990. $data ['ridKey'] = $ridKey;
  991. $data ['memu'] = "receipt";
  992. $data ['staff'] = $this->staff;
  993. $data ['receiptMemu'] = 'saeaBorad';
  994. $data ['verifyId'] = $this->verifyId;
  995. $data ['executeId'] = $this->executeId;
  996. $this->render ( "/admin/saeaLoanEdi", $data );
  997. }
  998. function saeaLoanEdiDo() {
  999. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1000. $agency = $this->get_args ( 'agency' );
  1001. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1002. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1003. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1004. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1005. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1006. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1007. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1008. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1009. // die;
  1010. Doo::loadClass ( 'XDeode' );
  1011. $XDeode = new XDeode ( 7 );
  1012. $rid = $XDeode->decode ( $ridKey );
  1013. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1014. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1015. header ( 'Content-Type:text/html;charset=utf-8' );
  1016. die ( '请填写联行号' );
  1017. }
  1018. Doo::loadModel ( 'receipt' );
  1019. Doo::loadModel ( 'receiptDetail' );
  1020. Doo::loadModel ( 'accountItem' );
  1021. $accountItem = new accountItem ();
  1022. $receipt = new receipt ();
  1023. Doo::loadModel ( 'loanReceipt' );
  1024. $loanReceipt = new loanReceipt ();
  1025. Doo::loadModel ( 'enclosur' );
  1026. Doo::loadModel ( 'execute' );
  1027. $execute = new execute ();
  1028. $executeDetail = $execute->getOne ( array (
  1029. 'where' => 'mold="借款执行人"',
  1030. 'asArray' => true
  1031. ) );
  1032. $receiptDetail = $receipt->getOne ( array (
  1033. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1034. 'asArray' => true
  1035. ) );
  1036. if (empty ( $receiptDetail ))
  1037. die ( '参数错误' );
  1038. $aItem = $accountItem->find ( array (
  1039. 'asArray' => true
  1040. ) );
  1041. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1042. $ag = $tr = $ta = $ot = 0;
  1043. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1044. array_push ( $accountJson ['借款费用'], array (
  1045. 'aid' => 0,
  1046. 'name' => '申请金额',
  1047. 'price' => number_format ( $agency, 2, '.', '' )
  1048. ) );
  1049. $sum += $agency;
  1050. $agencySum += $agency;
  1051. $accountJson ['cSum'] = array (
  1052. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1053. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1054. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1055. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1056. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1057. );
  1058. // 报销单
  1059. $receipt->loanItem = json_encode ( $accountJson );
  1060. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1061. $receipt->cid = $cid;
  1062. // 特殊状态
  1063. // 修改审批流程加入角色
  1064. if ($receiptDetail ['status'] != 4)
  1065. $receipt->verify = $verify;
  1066. $order = array (
  1067. "\r\n",
  1068. "\n",
  1069. "\r"
  1070. );
  1071. $replace = '<br/>';
  1072. $explanation = str_replace ( $order, $replace, $explanation );
  1073. $receipt->explanation = $explanation;
  1074. $receipt->remittanceName = $remittanceName;
  1075. $receipt->bankName = $bankName;
  1076. $receipt->bankNumber = $bankNumber;
  1077. $receipt->remittanceBankType = $remittanceBankType;
  1078. if ($remittanceBankType == 1)
  1079. $receipt->coupletNumber = $coupletNumber;
  1080. $receipt->update ( array (
  1081. 'where' => 'rid=' . $rid
  1082. ) );
  1083. // 借款数据更新
  1084. $loanReceipt->loanItem = json_encode ( $accountJson );
  1085. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1086. $loanReceipt->cid = $cid;
  1087. if ($receiptDetail ['status'] != 4)
  1088. $loanReceipt->verify = $verify;
  1089. $loanReceipt->explanation = $explanation;
  1090. $receipt->executeCopy = $executeDetail ['staff'];
  1091. $loanReceipt->update ( array (
  1092. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1093. ) );
  1094. }
  1095. return "/saeaBorad";
  1096. }
  1097. function saeaLoanReceiptAdd() {
  1098. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. Doo::loadModel ( 'loanReceipt' );
  1102. $loanReceipt = new loanReceipt ();
  1103. Doo::loadModel ( 'L_category' );
  1104. $Lcategory = new L_category ();
  1105. Doo::loadModel ( 'verify' );
  1106. Doo::loadModel ( 'statistics' );
  1107. $statistics = new statistics ();
  1108. $verify = new verify ();
  1109. Doo::loadModel ( 'staff' );
  1110. $staff = new staff ();
  1111. $receiptDetail = $receipt->getOne ( array (
  1112. 'where' => 'rid=' . $rid,
  1113. 'desc' => 'rid',
  1114. 'asArray' => true
  1115. ) );
  1116. $receiptList = $loanReceipt->find ( array (
  1117. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1118. 'desc' => 'rid',
  1119. 'asArray' => true
  1120. ) );
  1121. $Locate = 0;
  1122. $roleId = 0;
  1123. $button = 0;
  1124. foreach ( $receiptList as $key => $value ) {
  1125. $receiptList [$key] ['Locate'] = $Locate;
  1126. $Locate ++;
  1127. $receiptList [$key] ['reviseDetail'] = array ();
  1128. if (! empty ( $value ['reviseDetail'] ))
  1129. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1130. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1131. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1132. $categoryDetil = $Lcategory->getOne ( array (
  1133. 'where' => 'cid=' . $value ['cid'],
  1134. 'asArray' => true
  1135. ) );
  1136. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1137. // 检测编辑状态
  1138. $verifyList = $verify->getOne ( array (
  1139. 'where' => 'vid=' . $value ['verify'],
  1140. 'asArray' => true
  1141. ) );
  1142. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1143. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1144. Doo::loadModel ( 'role' );
  1145. $role = new role ();
  1146. $flag = true;
  1147. $roleKey = 0;
  1148. $endStaffArray = array ();
  1149. $roleArrayCopy = array ();
  1150. foreach ( $verifyList as $k => $v ) {
  1151. // init verifyStaff
  1152. if ($v [1] == 'ROLE') {
  1153. if (! empty ( $verifyStaff )) {
  1154. $endStaffArray = end ( $verifyStaff );
  1155. // if ($v[0]==$endStaffArray['nextStaff']){
  1156. // $roleId=$v[0];
  1157. // }
  1158. }
  1159. $roleVerify = json_decode ( $v [3], true );
  1160. $roleKey = $k;
  1161. $roleArray = array ();
  1162. $rolename = $role->getOne ( array (
  1163. 'where' => 'rid=' . $v [0],
  1164. 'asArray' => true
  1165. ) );
  1166. foreach ( $roleVerify as $o => $p ) {
  1167. $staffID = explode ( '_', $p );
  1168. $staffInfo = $staff->getOne ( array (
  1169. 'where' => 'sid=' . $staffID [0],
  1170. 'asArray' => true
  1171. ) );
  1172. // print_r($staffID);
  1173. $exp = array (
  1174. 0 => $staffInfo ['sid'],
  1175. 1 => $staffID [1],
  1176. 2 => $staffInfo ['avatar'],
  1177. 'date' => '',
  1178. 'date' => '',
  1179. 'opinion' => '',
  1180. 'status' => '',
  1181. 'rolename' => $rolename ['name']
  1182. );
  1183. array_push ( $roleArray, $exp );
  1184. }
  1185. $roleArrayCopy [$v [0]] = $roleArray;
  1186. // $verifyList[$k]['roleArray']=$roleArray;
  1187. }
  1188. $verifyList [$k] ['date'] = "";
  1189. $verifyList [$k] ['opinion'] = "";
  1190. $verifyList [$k] ['status'] = "";
  1191. if (empty ( $verifyStaff )) {
  1192. $verifyList [$k] ['date'] = "";
  1193. $verifyList [$k] ['opinion'] = "";
  1194. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1195. $verifyList [$k] ['status'] = 4;
  1196. $flag = false;
  1197. }
  1198. } else {
  1199. foreach ( $verifyStaff as $m => $u ) {
  1200. if ($v [0] == $m) {
  1201. $verifyList [$k] ['date'] = $u ['date'];
  1202. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1203. $verifyList [$k] ['status'] = $u ['status'];
  1204. $flag = false;
  1205. break;
  1206. }
  1207. }
  1208. $endStaffArray = end ( $verifyStaff );
  1209. if (isset ( $endStaffArray ['ROLE'] )) {
  1210. } else {
  1211. // $endKey=key($verifyStaff);
  1212. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1213. // $button=4;
  1214. // $verifyList[$k]['status']=4;
  1215. // }
  1216. }
  1217. }
  1218. }
  1219. $rolename ['name'] = '';
  1220. if (! empty ( $roleId )) {
  1221. Doo::loadModel ( 'role' );
  1222. $role = new role ();
  1223. $rolename = $role->getOne ( array (
  1224. 'where' => 'rid=' . $roleId,
  1225. 'asArray' => true
  1226. ) );
  1227. }
  1228. if (! empty ( $verifyStaff ))
  1229. $endStaffArray = end ( $verifyStaff );
  1230. $KOP = false;
  1231. foreach ( $roleArrayCopy as $P => $A ) {
  1232. foreach ( $A as $MKI => $AVL ) {
  1233. if (! empty ( $verifyStaff )) {
  1234. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1235. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1236. $button = 4;
  1237. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1238. }
  1239. foreach ( $verifyStaff as $m => $u ) {
  1240. $AVLFK = $AVL [0] . '_R';
  1241. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1242. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1243. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1244. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1245. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1246. break;
  1247. }
  1248. }
  1249. } else {
  1250. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1251. $button = 4;
  1252. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1253. }
  1254. }
  1255. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1256. $KOP = true;
  1257. }
  1258. }
  1259. foreach ( $roleArrayCopy as $k => $v ) {
  1260. foreach ( $verifyList as $m => $n ) {
  1261. if ($n [0] == $k) {
  1262. array_splice ( $verifyList, $m, 1, $v );
  1263. }
  1264. }
  1265. }
  1266. $receiptList [$key] ['verifyList'] = $verifyList;
  1267. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1268. 'where' => 'sid=' . $value ['staff'],
  1269. 'asArray' => true
  1270. ) );
  1271. $receiptList [$key] ['button'] = $button;
  1272. //
  1273. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1274. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1275. }
  1276. $data ['receiptList'] = $receiptList;
  1277. $data ['receiptDetail'] = $receiptDetail;
  1278. Doo::loadModel ( 'L_category' );
  1279. $lCategory = new L_category ();
  1280. Doo::loadModel ( 'accountItem' );
  1281. $accountItem = new accountItem ();
  1282. $acItem = $accountItem->find ( array (
  1283. 'asArray' => true
  1284. ) );
  1285. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1286. $data ['rid'] = $rid;
  1287. $data ['category'] = $lCategory->find ( array (
  1288. 'asArray' => true
  1289. ) );
  1290. $data ['veList'] = $veList;
  1291. $data ['acItem'] = $acItem;
  1292. $data ['memu'] = "receipt";
  1293. $data ['staff'] = $this->staff;
  1294. $data ['receiptMemu'] = 'saeaBorad';
  1295. $data ['verifyId'] = $this->verifyId;
  1296. $data ['executeId'] = $this->executeId;
  1297. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1298. }
  1299. function saeaLoanReceiptAddDo() {
  1300. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1301. $agency = $this->get_args ( 'agency' );
  1302. $travel = $this->get_args ( 'travel' );
  1303. $train = $this->get_args ( 'train' );
  1304. $other = $this->get_args ( 'other' );
  1305. $inttrain = $this->get_args ( 'inttrain' );
  1306. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1307. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1308. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1309. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1310. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1311. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1312. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1313. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1314. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1315. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1316. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1317. header ( 'Content-Type:text/html;charset=utf-8' );
  1318. die ( '请填写联行号' );
  1319. }
  1320. Doo::loadModel ( 'receipt' );
  1321. Doo::loadModel ( 'receiptDetail' );
  1322. Doo::loadModel ( 'accountItem' );
  1323. $accountItem = new accountItem ();
  1324. $receipt = new receipt ();
  1325. Doo::loadModel ( 'enclosur' );
  1326. Doo::loadModel ( 'execute' );
  1327. $execute = new execute ();
  1328. $executeDetail = $execute->getOne ( array (
  1329. 'where' => 'mold="借款费用执行人"',
  1330. 'asArray' => true
  1331. ) );
  1332. $receiptDet = $receipt->getOne ( array (
  1333. 'where' => 'rid=' . $rid,
  1334. 'asArray' => true
  1335. ) );
  1336. // if(!empty($receiptDetail))
  1337. // return "/referReceipt/".$receiptDetail['rid'];
  1338. $aItem = $accountItem->find ( array (
  1339. 'asArray' => true
  1340. ) );
  1341. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1342. $ag = $tr = $ta = $ot =$it = 0;
  1343. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1344. foreach ( $aItem as $key => $value ) {
  1345. if ($value ['category'] == $this->AGENCY) {
  1346. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1347. array_push ( $accountJson [$this->AGENCY], array (
  1348. 'aid' => $value ['aid'],
  1349. 'name' => $value ['name'],
  1350. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1351. ) );
  1352. $sum += $agency [$ag];
  1353. $agencySum += $agency [$ag];
  1354. }
  1355. $ag ++;
  1356. }
  1357. if ($value ['category'] == $this->TRAVEL) {
  1358. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1359. array_push ( $accountJson [$this->TRAVEL], array (
  1360. 'aid' => $value ['aid'],
  1361. 'name' => $value ['name'],
  1362. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1363. ) );
  1364. $sum += $travel [$tr];
  1365. $travelSum += $travel [$tr];
  1366. }
  1367. $tr ++;
  1368. }
  1369. if ($value ['category'] == $this->INTTRAIN) {
  1370. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1371. array_push ( $accountJson [$this->INTTRAIN], array (
  1372. 'aid' => $value ['aid'],
  1373. 'name' => $value ['name'],
  1374. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1375. ) );
  1376. $sum += $inttrain [$it];
  1377. $inttrainSum += $inttrain [$it];
  1378. }
  1379. $it ++;
  1380. }
  1381. if ($value ['category'] == $this->TRAIN) {
  1382. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1383. array_push ( $accountJson [$this->TRAIN], array (
  1384. 'aid' => $value ['aid'],
  1385. 'name' => $value ['name'],
  1386. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1387. ) );
  1388. $sum += $train [$ta];
  1389. $trainSum += $train [$ta];
  1390. }
  1391. $ta ++;
  1392. }
  1393. if ($value ['category'] == $this->OTHER) {
  1394. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1395. array_push ( $accountJson [$this->OTHER], array (
  1396. 'aid' => $value ['aid'],
  1397. 'name' => $value ['name'],
  1398. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1399. ) );
  1400. $sum += $other [$ot];
  1401. $otherSum += $other [$ot];
  1402. }
  1403. $ot ++;
  1404. }
  1405. }
  1406. $accountJson ['cSum'] = array (
  1407. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1408. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1409. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1410. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1411. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1412. );
  1413. // 报销单
  1414. $receipt->accountItem = json_encode ( $accountJson );
  1415. $receipt->staff = $this->staff [0] ['sid'];
  1416. $receipt->loanSum = $receiptDet ['sum'];
  1417. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1418. $receipt->date = date ( "Y-m-d" );
  1419. $receipt->pastDate = '';
  1420. $receipt->cid = $cid;
  1421. $receipt->status = 7;
  1422. // 修改审批流程加入角色
  1423. $receipt->verify = $verify;
  1424. $receipt->verifyStaff = '';
  1425. $receipt->executeStaff = '';
  1426. $receipt->executeCopy = $executeDetail ['staff'];
  1427. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1428. $receipt->explanation = $explanation;
  1429. $receipt->remittanceName = $remittanceName;
  1430. $receipt->bankName = $bankName;
  1431. $receipt->bankNumber = $bankNumber;
  1432. $receipt->remittanceBankType = $remittanceBankType;
  1433. if ($remittanceBankType == 1)
  1434. $receipt->coupletNumber = $coupletNumber;
  1435. $receipt->update ( array (
  1436. 'where' => 'rid=' . $rid
  1437. ) );
  1438. // 附件
  1439. if (! empty ( $enclosurName )) {
  1440. $enclosurArray = explode ( '-', $enclosurName );
  1441. foreach ( $enclosurArray as $value ) {
  1442. $enclosur = new enclosur ();
  1443. $enclosur->name = $value;
  1444. $enclosur->rid = $rid;
  1445. $enclosur->insert ();
  1446. }
  1447. // print_r($enclosurArray);die;
  1448. }
  1449. // 报销详情
  1450. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1451. $receiptDetail = new receiptDetail ();
  1452. $receiptDetail->staff = $this->staff [0] ['sid'];
  1453. $receiptDetail->item = $value ['name'];
  1454. $receiptDetail->itemCategory = $this->AGENCY;
  1455. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1456. $receiptDetail->date = date ( "Y-m-d" );
  1457. $receiptDetail->cid = $cid;
  1458. $receiptDetail->rid = $rid;
  1459. $receiptDetail->status = 4;
  1460. $receiptDetail->insert ();
  1461. }
  1462. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1463. $receiptDetail = new receiptDetail ();
  1464. $receiptDetail->staff = $this->staff [0] ['sid'];
  1465. $receiptDetail->item = $value ['name'];
  1466. $receiptDetail->itemCategory = $this->TRAVEL;
  1467. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1468. $receiptDetail->date = date ( "Y-m-d" );
  1469. $receiptDetail->cid = $cid;
  1470. $receiptDetail->rid = $rid;
  1471. $receiptDetail->status = 4;
  1472. $receiptDetail->insert ();
  1473. }
  1474. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1475. $receiptDetail = new receiptDetail ();
  1476. $receiptDetail->staff = $this->staff [0] ['sid'];
  1477. $receiptDetail->item = $value ['name'];
  1478. $receiptDetail->itemCategory = $this->TRAIN;
  1479. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1480. $receiptDetail->date = date ( "Y-m-d" );
  1481. $receiptDetail->cid = $cid;
  1482. $receiptDetail->rid = $rid;
  1483. $receiptDetail->status = 4;
  1484. $receiptDetail->insert ();
  1485. }
  1486. //内训
  1487. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1488. $receiptDetail = new receiptDetail ();
  1489. $receiptDetail->staff = $this->staff [0] ['sid'];
  1490. $receiptDetail->item = $value ['name'];
  1491. $receiptDetail->itemCategory = $this->INTTRAIN;
  1492. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1493. $receiptDetail->date = date ( "Y-m-d" );
  1494. $receiptDetail->cid = $cid;
  1495. $receiptDetail->rid = $rid;
  1496. $receiptDetail->status = 4;
  1497. $receiptDetail->insert ();
  1498. }
  1499. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1500. $receiptDetail = new receiptDetail ();
  1501. $receiptDetail->staff = $this->staff [0] ['sid'];
  1502. $receiptDetail->item = $value ['name'];
  1503. $receiptDetail->itemCategory = $this->OTHER;
  1504. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1505. $receiptDetail->date = date ( "Y-m-d" );
  1506. $receiptDetail->cid = $cid;
  1507. $receiptDetail->rid = $rid;
  1508. $receiptDetail->status = 4;
  1509. $receiptDetail->insert ();
  1510. }
  1511. return "/saeaBorad";
  1512. }
  1513. return "/saeaLoanReceiptAdd/" . $rid;
  1514. }
  1515. function saeaLoanReceiptEdi() {
  1516. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1517. Doo::loadClass ( 'XDeode' );
  1518. $XDeode = new XDeode ( 7 );
  1519. $rid = $XDeode->decode ( $ridKey );
  1520. if (! is_numeric ( $rid ))
  1521. die ( 'illegal request' );
  1522. Doo::loadModel ( 'accountItem' );
  1523. Doo::loadModel ( 'verify' );
  1524. Doo::loadModel ( 'receipt' );
  1525. $receipt = new receipt ();
  1526. $verify = new verify ();
  1527. $accountItem = new accountItem ();
  1528. Doo::loadModel ( 'L_category' );
  1529. $Lcategory = new L_category ();
  1530. Doo::loadModel ( "role" );
  1531. $role = new role ();
  1532. Doo::loadModel ( 'loanReceipt' );
  1533. $loanReceipt = new loanReceipt ();
  1534. Doo::loadModel ( 'staff' );
  1535. $staff = new staff ();
  1536. $receiptDetail = $receipt->getOne ( array (
  1537. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1538. 'asArray' => true
  1539. ) );
  1540. if (empty ( $receiptDetail ))
  1541. return "/saeaBorad";
  1542. $receiptList = $loanReceipt->find ( array (
  1543. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1544. 'desc' => 'rid',
  1545. 'asArray' => true
  1546. ) );
  1547. $Locate = 0;
  1548. $roleId = 0;
  1549. $button = 0;
  1550. foreach ( $receiptList as $key => $value ) {
  1551. $receiptList [$key] ['Locate'] = $Locate;
  1552. $Locate ++;
  1553. $receiptList [$key] ['reviseDetail'] = array ();
  1554. if (! empty ( $value ['reviseDetail'] ))
  1555. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1556. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1557. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1558. $categoryDetil = $Lcategory->getOne ( array (
  1559. 'where' => 'cid=' . $value ['cid'],
  1560. 'asArray' => true
  1561. ) );
  1562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1563. // 检测编辑状态
  1564. $verifyList = $verify->getOne ( array (
  1565. 'where' => 'vid=' . $value ['verify'],
  1566. 'asArray' => true
  1567. ) );
  1568. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1569. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1570. Doo::loadModel ( 'role' );
  1571. $role = new role ();
  1572. $flag = true;
  1573. $roleKey = 0;
  1574. $endStaffArray = array ();
  1575. $roleArrayCopy = array ();
  1576. foreach ( $verifyList as $k => $v ) {
  1577. // init verifyStaff
  1578. if ($v [1] == 'ROLE') {
  1579. if (! empty ( $verifyStaff )) {
  1580. $endStaffArray = end ( $verifyStaff );
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify = json_decode ( $v [3], true );
  1586. $roleKey = $k;
  1587. $roleArray = array ();
  1588. $rolename = $role->getOne ( array (
  1589. 'where' => 'rid=' . $v [0],
  1590. 'asArray' => true
  1591. ) );
  1592. foreach ( $roleVerify as $o => $p ) {
  1593. $staffID = explode ( '_', $p );
  1594. $staffInfo = $staff->getOne ( array (
  1595. 'where' => 'sid=' . $staffID [0],
  1596. 'asArray' => true
  1597. ) );
  1598. // print_r($staffID);
  1599. $exp = array (
  1600. 0 => $staffInfo ['sid'],
  1601. 1 => $staffID [1],
  1602. 2 => $staffInfo ['avatar'],
  1603. 'date' => '',
  1604. 'date' => '',
  1605. 'opinion' => '',
  1606. 'status' => '',
  1607. 'rolename' => $rolename ['name']
  1608. );
  1609. array_push ( $roleArray, $exp );
  1610. }
  1611. $roleArrayCopy [$v [0]] = $roleArray;
  1612. // $verifyList[$k]['roleArray']=$roleArray;
  1613. }
  1614. $verifyList [$k] ['date'] = "";
  1615. $verifyList [$k] ['opinion'] = "";
  1616. $verifyList [$k] ['status'] = "";
  1617. if (empty ( $verifyStaff )) {
  1618. $verifyList [$k] ['date'] = "";
  1619. $verifyList [$k] ['opinion'] = "";
  1620. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1621. $verifyList [$k] ['status'] = 4;
  1622. $flag = false;
  1623. }
  1624. } else {
  1625. foreach ( $verifyStaff as $m => $u ) {
  1626. if ($v [0] == $m) {
  1627. $verifyList [$k] ['date'] = $u ['date'];
  1628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1629. $verifyList [$k] ['status'] = $u ['status'];
  1630. $flag = false;
  1631. break;
  1632. }
  1633. }
  1634. $endStaffArray = end ( $verifyStaff );
  1635. if (isset ( $endStaffArray ['ROLE'] )) {
  1636. } else {
  1637. // $endKey=key($verifyStaff);
  1638. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1639. // $button=4;
  1640. // $verifyList[$k]['status']=4;
  1641. // }
  1642. }
  1643. }
  1644. }
  1645. $rolename ['name'] = '';
  1646. if (! empty ( $roleId )) {
  1647. Doo::loadModel ( 'role' );
  1648. $role = new role ();
  1649. $rolename = $role->getOne ( array (
  1650. 'where' => 'rid=' . $roleId,
  1651. 'asArray' => true
  1652. ) );
  1653. }
  1654. if (! empty ( $verifyStaff ))
  1655. $endStaffArray = end ( $verifyStaff );
  1656. $KOP = false;
  1657. foreach ( $roleArrayCopy as $P => $A ) {
  1658. foreach ( $A as $MKI => $AVL ) {
  1659. if (! empty ( $verifyStaff )) {
  1660. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. foreach ( $verifyStaff as $m => $u ) {
  1666. $AVLFK = $AVL [0] . '_R';
  1667. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1668. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1669. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1670. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1671. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1672. break;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1677. $button = 4;
  1678. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1679. }
  1680. }
  1681. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1682. $KOP = true;
  1683. }
  1684. }
  1685. foreach ( $roleArrayCopy as $k => $v ) {
  1686. foreach ( $verifyList as $m => $n ) {
  1687. if ($n [0] == $k) {
  1688. array_splice ( $verifyList, $m, 1, $v );
  1689. }
  1690. }
  1691. }
  1692. $receiptList [$key] ['verifyList'] = $verifyList;
  1693. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1694. 'where' => 'sid=' . $value ['staff'],
  1695. 'asArray' => true
  1696. ) );
  1697. $receiptList [$key] ['button'] = $button;
  1698. //
  1699. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1700. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1701. }
  1702. $data ['receiptList'] = $receiptList;
  1703. $acItem = $accountItem->find ( array (
  1704. 'asArray' => true
  1705. ) );
  1706. $veList = $verify->find ( array (
  1707. 'asArray' => true
  1708. ) );
  1709. foreach ( $veList as $key => $value ) {
  1710. $v = json_decode ( $value ['staff'] );
  1711. $list = array ();
  1712. foreach ( $v as $n => $m ) {
  1713. if ($m ['1'] == 'ROLE') {
  1714. $roleInfo = $role->getOne ( array (
  1715. 'where' => 'rid=' . $m [0],
  1716. 'asArray' => true
  1717. ) );
  1718. $v [$n] [1] = $roleInfo ['name'];
  1719. array_push ( $list, $roleInfo ['name'] );
  1720. } else {
  1721. array_push ( $list, $v [$n] [1] );
  1722. }
  1723. }
  1724. $veList [$key] ['staff'] = implode ( '>', $list );
  1725. }
  1726. // 配置编辑信息
  1727. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1728. foreach ( $acItem as $key => $value ) {
  1729. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1730. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1731. $acItem [$key] ['price'] = $v ['price'];
  1732. }
  1733. }
  1734. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1735. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1736. $acItem [$key] ['price'] = $v ['price'];
  1737. }
  1738. }
  1739. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1740. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1741. $acItem [$key] ['price'] = $v ['price'];
  1742. }
  1743. }
  1744. //内训
  1745. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1746. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1747. $acItem [$key] ['price'] = $v ['price'];
  1748. }
  1749. }
  1750. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1751. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1752. $acItem [$key] ['price'] = $v ['price'];
  1753. }
  1754. }
  1755. }
  1756. $data ['category'] = $Lcategory->find ( array (
  1757. 'asArray' => true
  1758. ) );
  1759. $data ['ridKey'] = $ridKey;
  1760. $data ['cSum'] = $accountItemList ['cSum'];
  1761. $data ['sum'] = $receiptDetail ['sum'];
  1762. $data ['receiptDetail'] = $receiptDetail;
  1763. $data ['veList'] = $veList;
  1764. $data ['acItem'] = $acItem;
  1765. $data ['memu'] = "receipt";
  1766. $data ['staff'] = $this->staff;
  1767. $data ['receiptMemu'] = 'saeaBorad';
  1768. $data ['verify'] = $receiptDetail ['verify'];
  1769. $data ['verifyId'] = $this->verifyId;
  1770. $data ['executeId'] = $this->executeId;
  1771. $data ['rid'] = $rid;
  1772. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1773. }
  1774. /**
  1775. * 培训班结算
  1776. */
  1777. function receiptTrainAdd() {
  1778. Doo::loadModel ( 'accountItem' );
  1779. $accountItem = new accountItem ();
  1780. $acItem = $accountItem->find ( array (
  1781. 'asArray' => true
  1782. ) );
  1783. // 审批组
  1784. Doo::loadModel ( 'verify' );
  1785. $verify = new verify ();
  1786. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1787. // 办事处
  1788. Doo::loadModel ( 'L_category' );
  1789. $lCategory = new L_category ();
  1790. $data ['category'] = $lCategory->getCategory ();
  1791. $data ['veList'] = $veList;
  1792. $data ['memu'] = "receipt";
  1793. $data ['staff'] = $this->staff;
  1794. $data ['acItem'] = $acItem;
  1795. $data ['receiptMemu'] = 'saeaBorad';
  1796. $data ['verifyId'] = $this->verifyId;
  1797. $data ['executeId'] = $this->executeId;
  1798. $this->render ( "/receipt/receiptTrainAdd", $data );
  1799. }
  1800. /**
  1801. * 添加培训班结算
  1802. */
  1803. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1804. // 培训班信息
  1805. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1806. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1807. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1808. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1809. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1810. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1811. // 发票信息
  1812. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1813. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1814. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1815. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1816. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1817. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1818. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1819. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1820. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1821. header ( 'Content-Type:text/html;charset=utf-8' );
  1822. die ( '请填写联行号' );
  1823. }
  1824. Doo::loadModel ( 'execute' );
  1825. $execute = new execute ();
  1826. $executeDetail = $execute->getOne ( array (
  1827. 'where' => 'mold="培训班结算"',
  1828. 'asArray' => true
  1829. ) );
  1830. if (empty ( $executeDetail )) {
  1831. header ( 'Content-Type:text/html;charset=utf-8' );
  1832. die ( '未设置执行人' );
  1833. }
  1834. Doo::loadClass ( 'XDeode' );
  1835. $XDeode = new XDeode ( 5 );
  1836. $cid = $XDeode->decode ( $cid );
  1837. Doo::loadModel ( 'receipt' );
  1838. $receipt = new receipt ();
  1839. Doo::loadModel ( 'receiptTraining' );
  1840. $receiptTraining = new receiptTraining ();
  1841. // 创建费用培训班
  1842. $item = array (
  1843. 'cid' => $this->staff [0] ['cid'],
  1844. 'categoryName' => $this->staff [0] ['category'],
  1845. 'trainName' => $trainName,
  1846. 'trainStartDate' => $trainStartDate,
  1847. 'trainEndDate' => $trainEndDate,
  1848. 'participants' => $participants,
  1849. 'trainAddress' => $trainAddress,
  1850. 'trainRemarks' => $trainRemarks,
  1851. 'creator' => $this->staff [0] ['sid'],
  1852. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1853. );
  1854. $irid = $receiptTraining->addReceiptTraining ( $item );
  1855. // 报销单
  1856. $receipt->status = 5;
  1857. $receipt->trainId = $irid;
  1858. $receipt->Rtype = 3;
  1859. $receipt->staff = $this->staff [0] ['sid'];
  1860. $receipt->cid = $cid;
  1861. $receipt->verify = $verify;
  1862. $receipt->date = date ( "Y-m-d" );
  1863. $receipt->executeCopy = $executeDetail ['staff'];
  1864. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1865. $receipt->remittanceName = $remittanceName;
  1866. $receipt->bankName = $bankName;
  1867. $receipt->bankNumber = $bankNumber;
  1868. $receipt->remittanceBankType = $remittanceBankType;
  1869. if ($remittanceBankType == 1)
  1870. $receipt->coupletNumber = $coupletNumber;
  1871. $rid = $receipt->insert ();
  1872. $XDeode = new XDeode ( 7 );
  1873. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1874. } else
  1875. die ( 'illegal request' );
  1876. }
  1877. /**
  1878. * 培训班编辑
  1879. */
  1880. function receiptTrainEdi() {
  1881. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1882. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1883. Doo::loadClass ( 'XDeode' );
  1884. $XDeode = new XDeode ( 7 );
  1885. $rid = $XDeode->decode ( $ridKey );
  1886. if (! is_numeric ( $rid ))
  1887. die ( 'illegal request' );
  1888. Doo::loadModel ( 'receipt' );
  1889. $receipt = new receipt ();
  1890. Doo::loadModel ( 'receiptTraining' );
  1891. $receiptTraining = new receiptTraining ();
  1892. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1893. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1894. die ('illegal request--status');
  1895. }
  1896. //如有已入账已收款的发票,自动取消办事处已收款
  1897. // Doo::loadModel ( 'RIExtend' );
  1898. // $RIExtend = new RIExtend ();
  1899. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1900. // if (!empty($RIExtendList)){
  1901. // foreach ($RIExtendList as $key=>$value){
  1902. // $RIExtend = new RIExtend ();
  1903. // $RIExtend->delete(array (
  1904. // 'where' => 'iid=' . $value['iid'],
  1905. // 'limit' => 1
  1906. // ));
  1907. // }
  1908. // }
  1909. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1910. // 汇总表合计
  1911. // 收入合计--加入开票合计
  1912. Doo::loadModel ( 'invoiceTraining' );
  1913. $invoiceTraining = new invoiceTraining ();
  1914. $invoiceTrainingDetail = array (
  1915. 'invoiceArriveAmount' => 0,
  1916. 'RIAmount' => 0,
  1917. 'invoiceTotalAmount' => 0,
  1918. 'invoiceCompanyAmount'=>0
  1919. );
  1920. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1921. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1922. }
  1923. // print_r($invoiceTrainingDetail);
  1924. $invoiceArriveAmount = $RIAmount = 0;
  1925. if (! empty ( $invoiceTrainingDetail )) {
  1926. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1927. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1928. }
  1929. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1930. //print_r($invoiceTrainingDetail);
  1931. // 支出项目
  1932. Doo::loadModel ( 'accountItem' );
  1933. $accountItem = new accountItem ();
  1934. // 项目金额合计
  1935. Doo::loadModel ( 'RItem' );
  1936. $RItem = new RItem ();
  1937. // 讲师获得
  1938. Doo::loadModel ( 'RILecturer' );
  1939. $RILecturer = new RILecturer ();
  1940. $RItemList = $RItem->getRItemByRid ( $rid );
  1941. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1942. // 支出项金额详情
  1943. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1944. // print_r($aiData);
  1945. // 利润
  1946. $profit=$invoiceArriveAmount - $aiData ['total'];
  1947. $companyProfit=$profit * 0.6;
  1948. $categoryProfit=$profit * 0.4;
  1949. $data ['profit'] = sprintf("%.2f",$profit);
  1950. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1951. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1952. //发票利润
  1953. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1954. //发票公司利润
  1955. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1956. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1957. //办事处利润
  1958. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1959. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1960. // print_r($aiData['dataList']);
  1961. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1962. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1963. // 备用金
  1964. $sum = 0;
  1965. $data ['receiptLoanDetail'] = array (
  1966. 'sum' => '0.00'
  1967. );
  1968. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1969. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1970. $sum = $data ['receiptLoanDetail'] ['sum'];
  1971. }
  1972. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1973. $data ['payment'] = sprintf("%.2f",$payment);
  1974. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1975. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1976. $data ['aiList'] = $aiData ['dataList'];
  1977. // 占比计算
  1978. if ($invoiceArriveAmount != 0) {
  1979. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1980. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1981. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1982. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1983. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1984. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1985. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1986. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1987. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1988. } else {
  1989. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1990. }
  1991. //发票金额占比计算
  1992. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1993. //支出
  1994. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1995. //利润
  1996. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //公司利润
  1998. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //办事处利润
  2000. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //公司收款
  2002. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //备用金
  2004. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //办事处收款
  2006. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //办事处实际支出
  2008. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. //付总部款
  2010. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2011. }else{
  2012. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2013. }
  2014. //讲师人数
  2015. Doo::loadModel ( 'RILecturer' );
  2016. $RILecturer = new RILecturer ();
  2017. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2018. $data['lectureCount']=count($RILecturerList);
  2019. // 审批组
  2020. Doo::loadModel ( 'verify' );
  2021. $verify = new verify ();
  2022. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2023. // 办事处
  2024. Doo::loadModel ( 'L_category' );
  2025. $lCategory = new L_category ();
  2026. $data ['category'] = $lCategory->getCategory ();
  2027. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2028. $data ['receiptDetail'] = $receiptDetail;
  2029. $data ['veList'] = $veList;
  2030. $data ['trainEdiType'] = $trainEdiType;
  2031. $data ['ridKey'] = $ridKey;
  2032. $data ['memu'] = "receipt";
  2033. $data ['staff'] = $this->staff;
  2034. $data ['receiptMemu'] = 'saeaBorad';
  2035. $data ['verifyId'] = $this->verifyId;
  2036. $data ['executeId'] = $this->executeId;
  2037. $this->render ( "/receipt/receiptTrainEdi", $data );
  2038. }
  2039. /**
  2040. * 培训班借款编辑
  2041. */
  2042. function receiptTrainLoanEdi() {
  2043. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2044. Doo::loadClass ( 'XDeode' );
  2045. $XDeode = new XDeode ( 7 );
  2046. $rid = $XDeode->decode ( $ridKey );
  2047. if (! is_numeric ( $rid ))
  2048. die ( 'illegal request' );
  2049. Doo::loadModel ( 'receipt' );
  2050. $receipt = new receipt ();
  2051. Doo::loadModel ( 'receiptTraining' );
  2052. $receiptTraining = new receiptTraining ();
  2053. Doo::loadModel ( 'verify' );
  2054. $verify = new verify ();
  2055. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2056. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2057. die ();
  2058. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2059. // 借款详情HTML
  2060. // 获得借款信息
  2061. $receiptLoanHtml = '';
  2062. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2063. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2064. // 获得某费用单审批信息
  2065. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2066. Doo::loadClass ( 'receipt.func' );
  2067. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2068. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2069. }
  2070. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2071. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2072. $data ['receiptDetail'] = $receiptDetail;
  2073. $data ['trainEdiType'] = "LOAN";
  2074. $data ['ridKey'] = $ridKey;
  2075. $data ['memu'] = "receipt";
  2076. $data ['staff'] = $this->staff;
  2077. $data ['receiptMemu'] = 'saeaBorad';
  2078. $data ['verifyId'] = $this->verifyId;
  2079. $data ['executeId'] = $this->executeId;
  2080. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2081. }
  2082. /**
  2083. * 更新培训班结算基本信息
  2084. */
  2085. function receiptTrainInfoEdiDo() {
  2086. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2087. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2088. // 培训班信息
  2089. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2090. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2091. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2092. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2093. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2094. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2095. // 发票信息
  2096. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2097. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2098. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2099. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2100. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2101. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2102. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2103. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2104. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2105. header ( 'Content-Type:text/html;charset=utf-8' );
  2106. die ( '请填写联行号' );
  2107. }
  2108. Doo::loadClass ( 'XDeode' );
  2109. $XDeode = new XDeode ( 5 );
  2110. $cid = $XDeode->decode ( $cid );
  2111. $rtid = $XDeode->decode ( $rtid );
  2112. $rid = $XDeode->decode ( $rid );
  2113. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2114. die ( 'illegal request-IdError' );
  2115. }
  2116. Doo::loadModel ( 'receipt' );
  2117. $receipt = new receipt ();
  2118. Doo::loadModel ( 'receiptTraining' );
  2119. $receiptTraining = new receiptTraining ();
  2120. // 更新费用培训班
  2121. $item = array (
  2122. 'rtid' => $rtid,
  2123. 'trainName' => $trainName,
  2124. 'trainStartDate' => $trainStartDate,
  2125. 'trainEndDate' => $trainEndDate,
  2126. 'participants' => $participants,
  2127. 'trainAddress' => $trainAddress,
  2128. 'trainRemarks' => $trainRemarks
  2129. );
  2130. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2131. // 报销单
  2132. $receipt->rid = $rid;
  2133. $receipt->cid = $cid;
  2134. $receipt->verify = $verify;
  2135. $receipt->remittanceName = $remittanceName;
  2136. $receipt->bankName = $bankName;
  2137. $receipt->bankNumber = $bankNumber;
  2138. $receipt->remittanceBankType = $remittanceBankType;
  2139. if ($remittanceBankType == 1)
  2140. $receipt->coupletNumber = $coupletNumber;
  2141. $receipt->update ();
  2142. $XDeode = new XDeode ( 7 );
  2143. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2144. } else
  2145. die ( 'illegal request' );
  2146. }
  2147. /**
  2148. * 编辑培训班结算---更新借款
  2149. */
  2150. function receiptTrainLoanEdiDo() {
  2151. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2152. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2153. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2154. Doo::loadModel ( 'receipt' );
  2155. $receipt = new receipt ();
  2156. Doo::loadClass ( 'XDeode' );
  2157. $XDeode = new XDeode ( 5 );
  2158. $rid = $XDeode->decode ( $ridKey );
  2159. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2160. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2161. die ( 'illegal request-ridError' );
  2162. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2163. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2164. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2165. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2166. die ( 'illegal request-receiptError' );
  2167. }
  2168. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2169. die ( 'illegal request-receipLoantError' );
  2170. }
  2171. // 培训班结算挂钩借款
  2172. $receipt = new receipt ();
  2173. $item = array (
  2174. 'rid' => $rid,
  2175. 'trainLoanRid' => $ridLoan
  2176. );
  2177. $receipt->setReceiptByCondition ( $item );
  2178. // 更新借款状态变成已挂钩
  2179. $receipt = new receipt ();
  2180. $item = array (
  2181. 'rid' => $ridLoan,
  2182. 'status' => 10,
  2183. 'statusTrain' => 1
  2184. );
  2185. $receipt->setReceiptByCondition ( $item );
  2186. $XDeode = new XDeode ( 7 );
  2187. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2188. } else
  2189. die ( 'illegal request' );
  2190. }
  2191. /**
  2192. * 编辑培训班结算--移除借款
  2193. */
  2194. function receiptTrainLoanRemoveDo() {
  2195. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2196. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2197. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2198. Doo::loadModel ( 'receipt' );
  2199. $receipt = new receipt ();
  2200. Doo::loadClass ( 'XDeode' );
  2201. $XDeode = new XDeode ( 5 );
  2202. $rid = $XDeode->decode ( $ridKey );
  2203. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2204. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2205. die ( 'illegal request-ridError' );
  2206. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2207. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2208. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2209. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2210. die ( 'illegal request-receiptError' );
  2211. }
  2212. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2213. die ( 'illegal request-receipLoantError' );
  2214. }
  2215. // 培训班结算挂钩借款
  2216. $receipt = new receipt ();
  2217. $item = array (
  2218. 'rid' => $rid,
  2219. 'trainLoanRid' => 0
  2220. );
  2221. $receipt->setReceiptByCondition ( $item );
  2222. // 更新借款状态变成已挂钩
  2223. $receipt = new receipt ();
  2224. $item = array (
  2225. 'rid' => $ridLoan,
  2226. 'status' => 8,
  2227. 'statusTrain' => 0
  2228. );
  2229. $receipt->setReceiptByCondition ( $item );
  2230. $XDeode = new XDeode ( 7 );
  2231. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2232. } else
  2233. die ( 'illegal request' );
  2234. }
  2235. /**
  2236. * 编辑培训班结算 ---开票
  2237. */
  2238. function receiptTrainInvoiceEdi() {
  2239. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2240. Doo::loadClass ( 'XDeode' );
  2241. $XDeode = new XDeode ( 7 );
  2242. $rid = $XDeode->decode ( $ridKey );
  2243. if (! is_numeric ( $rid ))
  2244. die ( 'illegal request' );
  2245. Doo::loadModel ( 'receipt' );
  2246. $receipt = new receipt ();
  2247. Doo::loadModel ( 'receiptTraining' );
  2248. $receiptTraining = new receiptTraining ();
  2249. Doo::loadModel ( 'invoice' );
  2250. $invoice = new invoice ();
  2251. Doo::loadModel ( 'invoiceTraining' );
  2252. $invoiceTraining = new invoiceTraining ();
  2253. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2254. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2255. die ();
  2256. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2257. $invoiceList = $invoiceTrainingDetail = array ();
  2258. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2259. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2260. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2261. }
  2262. //print_r($invoiceList);
  2263. $data ['invoiceList'] = $invoiceList;
  2264. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2265. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2266. $data ['receiptDetail'] = $receiptDetail;
  2267. $data ['trainEdiType'] = "INVOICE";
  2268. $data ['ridKey'] = $ridKey;
  2269. $data ['memu'] = "receipt";
  2270. $data ['staff'] = $this->staff;
  2271. $data ['receiptMemu'] = 'saeaBorad';
  2272. $data ['verifyId'] = $this->verifyId;
  2273. $data ['executeId'] = $this->executeId;
  2274. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2275. }
  2276. /**
  2277. * 编辑培训班结算---更新开票
  2278. */
  2279. function receiptTrainInvoiceEdiDo() {
  2280. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2281. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2282. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2283. Doo::loadModel ( 'receipt' );
  2284. $receipt = new receipt ();
  2285. Doo::loadModel ( 'invoiceTraining' );
  2286. $invoiceTraining = new invoiceTraining ();
  2287. Doo::loadClass ( 'XDeode' );
  2288. $XDeode = new XDeode ( 5 );
  2289. $rid = $XDeode->decode ( $ridKey );
  2290. $itid = $XDeode->decode ( $itidKey );
  2291. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2292. die ( 'illegal request-idError' );
  2293. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2294. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2295. // 不合法的数据
  2296. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2297. die ( 'illegal request-receiptError' );
  2298. }
  2299. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2300. die ( 'illegal request-receipLoantError' );
  2301. }
  2302. // 培训班结算挂钩借款
  2303. $receipt = new receipt ();
  2304. $item = array (
  2305. 'rid' => $rid,
  2306. 'invoiceTrainId' => $itid
  2307. );
  2308. $receipt->setReceiptByCondition ( $item );
  2309. $invoiceTraining = new invoiceTraining ();
  2310. $item = array (
  2311. 'bindReceipt' => 1,
  2312. 'itid' => $itid
  2313. );
  2314. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2315. $XDeode = new XDeode ( 7 );
  2316. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2317. } else
  2318. die ( 'illegal request' );
  2319. }
  2320. /**
  2321. * 更新培训班结算 收款和取消收款
  2322. */
  2323. function receiptTrainReceivables() {
  2324. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2325. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2326. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2327. Doo::loadClass ( 'XDeode' );
  2328. $XDeode = new XDeode ( 5 );
  2329. $rid = $XDeode->decode ( $ridKey );
  2330. $iid = $XDeode->decode ( $iidKey );
  2331. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2332. die ( 'illegal request-iid' );
  2333. Doo::loadModel ( 'RIExtend' );
  2334. $RIExtend = new RIExtend ();
  2335. if ($doType == 'CONFIRM') {
  2336. $RIExtend->rid = $rid;
  2337. $RIExtend->iid = $iid;
  2338. $RIExtend->RIstatus = 1;
  2339. $RIExtend->insert ();
  2340. echo json_encode ( array (
  2341. 'status' => 1,
  2342. ) );
  2343. die ( );
  2344. } elseif ($doType == 'CANCEL') {
  2345. $RIExtend->delete ( array (
  2346. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2347. 'limit' => 1
  2348. ) );
  2349. echo json_encode ( array (
  2350. 'status' => 1,
  2351. ) );
  2352. die ( );
  2353. } else {
  2354. echo json_encode ( array (
  2355. 'status' => 2,
  2356. ) );
  2357. die ( );
  2358. }
  2359. }
  2360. /**
  2361. * 移除挂钩的培训班发票
  2362. */
  2363. function receiptTrainReceivablesDelDo() {
  2364. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2365. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2366. Doo::loadModel ( 'receipt' );
  2367. $receipt = new receipt ();
  2368. Doo::loadModel ( 'RIExtend' );
  2369. $RIExtend = new RIExtend ();
  2370. Doo::loadClass ( 'XDeode' );
  2371. $XDeode = new XDeode ( 5 );
  2372. $rid = $XDeode->decode ( $ridKey );
  2373. $itid = $XDeode->decode ( $itidKey );
  2374. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2375. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2376. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2377. die ( 'illegal request-status' );
  2378. }
  2379. $receipt = new receipt ();
  2380. $receipt->rid = $rid;
  2381. $receipt->invoiceTrainId = 0;
  2382. $receipt->update ();
  2383. Doo::loadModel ( 'invoiceTraining' );
  2384. $invoiceTraining = new invoiceTraining ();
  2385. $item = array (
  2386. 'bindReceipt' => 0,
  2387. 'itid' => $itid
  2388. );
  2389. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2390. $RIExtend->delete ( array (
  2391. 'where' => 'rid=' . $rid
  2392. ) );
  2393. $XDeode = new XDeode ( 7 );
  2394. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2395. } else
  2396. die ( 'illegal request-iid' );
  2397. }
  2398. /**
  2399. * 编辑培训班结算
  2400. */
  2401. function receiptTrainItemEdi() {
  2402. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2403. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2404. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2405. Doo::loadClass ( 'XDeode' );
  2406. $XDeode = new XDeode ( 7 );
  2407. $rid = $XDeode->decode ( $ridKey );
  2408. if (! is_numeric ( $rid ))
  2409. die ( 'illegal request' );
  2410. Doo::loadModel ( 'receipt' );
  2411. $receipt = new receipt ();
  2412. Doo::loadModel ( 'receiptTraining' );
  2413. $receiptTraining = new receiptTraining ();
  2414. Doo::loadModel ( 'RItem' );
  2415. $RItem = new RItem ();
  2416. Doo::loadModel ( 'accountItem' );
  2417. $accountItem = new accountItem ();
  2418. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2419. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2420. die ();
  2421. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2422. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2423. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2424. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2425. // if($value['name']=='税款'){
  2426. // unset($aiList[$key]);break;
  2427. // }
  2428. // }
  2429. //print_r($RItemList);
  2430. $data ['name'] = $name;
  2431. $data ['RItemList'] = $RItemList;
  2432. $data ['aiList'] = $aiList;
  2433. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2434. $data ['receiptDetail'] = $receiptDetail;
  2435. $data ['trainEdiType'] = "ITEM";
  2436. $data ['ridKey'] = $ridKey;
  2437. $data ['memu'] = "receipt";
  2438. $data ['staff'] = $this->staff;
  2439. $data ['receiptMemu'] = 'saeaBorad';
  2440. $data ['verifyId'] = $this->verifyId;
  2441. $data ['executeId'] = $this->executeId;
  2442. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2443. }
  2444. /**
  2445. * 添加支出项 需要修改 费用金额合计
  2446. */
  2447. function receiptTrainItemAddDo() {
  2448. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2449. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2450. // 支出项信息
  2451. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2452. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2453. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2454. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2455. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2456. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2457. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2458. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2459. Doo::loadClass ( 'XDeode' );
  2460. $XDeode = new XDeode ( 5 );
  2461. Doo::loadModel ( 'RItem' );
  2462. $RItem = new RItem ();
  2463. $rid = $XDeode->decode ( $ridKey );
  2464. $rtid= $XDeode->decode ( $rtidKey );
  2465. if (! is_numeric ( $rid )){
  2466. die ( 'illegal request' );
  2467. }
  2468. Doo::loadModel ( 'receiptDetail' );
  2469. $receiptDetail = new receiptDetail ();
  2470. Doo::loadModel ( 'receipt' );
  2471. $receipt = new receipt ();
  2472. Doo::loadModel ( 'receiptTraining' );
  2473. $receiptTraining = new receiptTraining ();
  2474. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2475. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2476. $order = array (
  2477. "\r\n",
  2478. "\n",
  2479. "\r"
  2480. );
  2481. $replace = '<br/>';
  2482. $describe = str_replace ( $order, $replace, $describe );
  2483. $itemData = array (
  2484. 'rid' => $rid,
  2485. 'item' => $item,
  2486. 'price' => $price,
  2487. 'date' => $date,
  2488. 'inputer' => $inputer,
  2489. 'describe' => $describe,
  2490. 'creater' => $this->staff['0']['username'],
  2491. 'createrId' => $this->staff['0']['sid'],
  2492. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2493. 'identifying'=>$identifyingTotal
  2494. );
  2495. if($payType=='company'){
  2496. $itemData += array (
  2497. 'payType' => 1
  2498. );
  2499. }
  2500. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2501. //更新支出项标识总数
  2502. $itemData = array (
  2503. 'rtid'=>$rtid,
  2504. 'identifyingTotal'=>$identifyingTotal
  2505. );
  2506. $receiptTraining->setReceiptTrainByCondition($itemData);
  2507. $XDeode = new XDeode ( 7 );
  2508. if($payType=='company'){
  2509. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2510. }else{
  2511. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2512. }
  2513. } else
  2514. die ( 'illegal request-dataError' );
  2515. }
  2516. /**
  2517. * 培训班结算-讲师
  2518. */
  2519. function receiptTrainLecturerEdi() {
  2520. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2521. Doo::loadClass ( 'XDeode' );
  2522. $XDeode = new XDeode ( 7 );
  2523. $rid = $XDeode->decode ( $ridKey );
  2524. if (! is_numeric ( $rid ))
  2525. die ( 'illegal request' );
  2526. Doo::loadModel ( 'receipt' );
  2527. $receipt = new receipt ();
  2528. Doo::loadModel ( 'receiptTraining' );
  2529. $receiptTraining = new receiptTraining ();
  2530. Doo::loadModel ( 'RILecturer' );
  2531. $RILecturer = new RILecturer ();
  2532. Doo::loadModel ( 'lecturer' );
  2533. $lecturer = new lecturer ();
  2534. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2535. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2536. die ();
  2537. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2538. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2539. $lecturerList = $lecturer->getLecturerAll ();
  2540. $INSIDEhtml = $OUTSIDEhtml = '';
  2541. foreach ( $lecturerList as $key => $value ) {
  2542. if ($value ['ltype'] == 'INSIDE') {
  2543. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2544. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2545. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2546. }
  2547. }
  2548. $data ['INSIDEhtml'] = $INSIDEhtml;
  2549. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2550. // print_r($RItemList);
  2551. $data ['RILecturerList'] = $RILecturerList;
  2552. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2553. $data ['receiptDetail'] = $receiptDetail;
  2554. $data ['trainEdiType'] = "LECTURER";
  2555. $data ['ridKey'] = $ridKey;
  2556. $data ['memu'] = "receipt";
  2557. $data ['staff'] = $this->staff;
  2558. $data ['receiptMemu'] = 'saeaBorad';
  2559. $data ['verifyId'] = $this->verifyId;
  2560. $data ['executeId'] = $this->executeId;
  2561. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2562. }
  2563. /**
  2564. * 添加讲师
  2565. */
  2566. function receiptTrainLecturerAddDo() {
  2567. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2568. // 支出项信息
  2569. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2570. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2571. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2572. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2573. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2574. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2575. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2576. Doo::loadClass ( 'XDeode' );
  2577. $XDeode = new XDeode ( 5 );
  2578. Doo::loadModel ( 'RILecturer' );
  2579. $RILecturer = new RILecturer ();
  2580. $rid = $XDeode->decode ( $ridKey );
  2581. if (! is_numeric ( $rid ))
  2582. die ( 'illegal request' );
  2583. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2584. die ( 'illegal request-taxationError' );
  2585. $RILecturer->rid = $rid;
  2586. $RILecturer->ltype = $ltype;
  2587. if ($ltype == 'OUTSIDE') {
  2588. if ($taxation == 'TAXATION') {
  2589. $RILecturer->taxation = 1;
  2590. } elseif ($taxation == 'NOTAXATION') {
  2591. $RILecturer->taxation = 0;
  2592. }
  2593. }
  2594. $RILecturer->lecturerName = $lecturerName;
  2595. $RILecturer->schoolDay = $schoolDay;
  2596. $RILecturer->price = $price;
  2597. $RILecturer->fees=$fees;
  2598. $RILecturer->insert ();
  2599. // 添加公司汇总
  2600. // 报销详情
  2601. Doo::loadModel ( 'receiptDetail' );
  2602. $receiptDetail = new receiptDetail ();
  2603. Doo::loadModel ( 'receipt' );
  2604. $receipt = new receipt ();
  2605. // 金额总计
  2606. $price = $price * $schoolDay;
  2607. $rInfo = $receipt->getReceiptByRid ( $rid );
  2608. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2609. if (empty ( $rdInfo )) {
  2610. $receiptDetail = new receiptDetail ();
  2611. $receiptDetail->staff = $rInfo ['staff'];
  2612. $receiptDetail->item = '讲课费';
  2613. $receiptDetail->itemCategory = '培训班费用';
  2614. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2615. $receiptDetail->date = date ( "Y-m-d" );
  2616. $receiptDetail->cid = $rInfo ['cid'];
  2617. $receiptDetail->rid = $rid;
  2618. $receiptDetail->status = 4;
  2619. $receiptDetail->insert ();
  2620. } else {
  2621. $receiptDetail = new receiptDetail ();
  2622. $rdInfo ['price'] += $fees;
  2623. $receiptDetail->price = $rdInfo ['price'];
  2624. $receiptDetail->update ( array (
  2625. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2626. ) );
  2627. }
  2628. $receipt = new receipt ();
  2629. $receipt->sum=$rInfo['sum']+$fees;
  2630. $receipt->update ( array (
  2631. 'where' => 'rid=' . $rid
  2632. ) );
  2633. $XDeode = new XDeode ( 7 );
  2634. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2635. } else
  2636. die ( 'illegal request' );
  2637. }
  2638. /**
  2639. * 移除讲师
  2640. */
  2641. function receiptTrainLecturerDelDo() {
  2642. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2643. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2644. Doo::loadModel ( 'receipt' );
  2645. $receipt = new receipt ();
  2646. Doo::loadModel ( 'RILecturer' );
  2647. $RILecturer = new RILecturer ();
  2648. Doo::loadClass ( 'XDeode' );
  2649. $XDeode = new XDeode ( 5 );
  2650. $rid = $XDeode->decode ( $ridKey );
  2651. $rlid = $XDeode->decode ( $rlidKey );
  2652. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2653. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2654. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2655. die ( 'illegal request-status' );
  2656. }
  2657. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2658. if (empty($detail)){
  2659. die ( 'illegal request-data' );
  2660. }
  2661. $RILecturer->delete ( array (
  2662. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2663. ) );
  2664. //更新费用合计金额
  2665. $rInfo = $receipt->getReceiptByRid ( $rid );
  2666. $receipt = new receipt ();
  2667. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2668. $receipt->update ( array (
  2669. 'where' => 'rid=' . $rid
  2670. ) );
  2671. Doo::loadModel ( 'receiptDetail' );
  2672. $receiptDetail = new receiptDetail ();
  2673. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2674. $receiptDetail = new receiptDetail ();
  2675. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2676. $receiptDetail->price = $rdInfo ['price'];
  2677. $receiptDetail->update ( array (
  2678. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2679. ) );
  2680. $XDeode = new XDeode ( 7 );
  2681. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2682. } else
  2683. die ( 'illegal request-iid' );
  2684. }
  2685. /**
  2686. * 培训班提交审批
  2687. */
  2688. function receiptTrainDo() {
  2689. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2690. Doo::loadClass ( 'XDeode' );
  2691. $XDeode = new XDeode ( 7 );
  2692. $rid = $XDeode->decode ( $ridKey );
  2693. Doo::loadModel ( 'receipt' );
  2694. $receipt = new receipt ();
  2695. Doo::loadModel ( 'receiptDetail' );
  2696. $receiptDetail = new receiptDetail ();
  2697. Doo::loadModel ( 'statistics' );
  2698. $statistics = new statistics ();
  2699. Doo::loadModel ( "verify" );
  2700. $verify = new verify ();
  2701. // 审批状态的判定
  2702. $receiptDetailList = $receipt->getOne ( array (
  2703. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2704. 'asArray' => true
  2705. ) );
  2706. if (empty ( $receiptDetailList ))
  2707. return "/saeaBorad";
  2708. $verifyDetail = $verify->getOne ( array (
  2709. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2710. 'asArray' => true
  2711. ) );
  2712. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2713. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2714. $nowStaff = "";
  2715. $nowStaffList = array ();
  2716. if ($verifyDetail [0] [1] == 'ROLE') {
  2717. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2718. foreach ( $vStaffString as $key => $value ) {
  2719. $staffK = explode ( "_", $value );
  2720. array_push ( $nowStaffList, $staffK [0] );
  2721. }
  2722. $nowStaff = implode ( ',', $nowStaffList );
  2723. } else {
  2724. $nowStaff = $verifyDetail [0] [0];
  2725. }
  2726. $receipt->nowStaff = $nowStaff;
  2727. }
  2728. // echo $nowStaff;
  2729. // print_r($verifyDetail);die;
  2730. $receipt->rid = $receiptDetailList ['rid'];
  2731. $receipt->date = date ( "Y-m-d" );
  2732. $receipt->status = 2;
  2733. $receipt->update ();
  2734. $receiptDetail->status = 2;
  2735. $receiptDetail->update ( array (
  2736. 'where' => 'rid=' . $receiptDetailList ['rid']
  2737. ) );
  2738. Doo::loadModel ( "receiptLog" );
  2739. $receiptLog = new receiptLog ();
  2740. Doo::loadModel ( "verify" );
  2741. $verify = new verify ();
  2742. $vr = $verify->getOne ( array (
  2743. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2744. 'asArray' => true
  2745. ) );
  2746. $jd = json_decode ( $vr ['staff'] );
  2747. $roleId = 0;
  2748. foreach ( $jd as $key => $value ) {
  2749. if ($value [1] == 'ROLE') {
  2750. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2751. if ($pos !== false) {
  2752. $roleId = $value [0];
  2753. }
  2754. }
  2755. }
  2756. // 审批日志
  2757. // echo $roleId;die;
  2758. if (! empty ( $roleId )) {
  2759. Doo::loadModel ( "role" );
  2760. $role = new role ();
  2761. $roleInfo = $role->getOne ( array (
  2762. 'where' => 'rid=' . $roleId,
  2763. 'asArray' => true
  2764. ) );
  2765. // $receiptLog->rolename = $roleInfo ['name'];
  2766. }
  2767. $receiptLog->username = $this->staff [0] ['username'];
  2768. $receiptLog->uid = $this->staff [0] ['sid'];
  2769. $receiptLog->date = date ( "Y-m-d" );
  2770. $receiptLog->opinion = '提交审批';
  2771. $receiptLog->img = $this->staff [0] ['avatar'];
  2772. $receiptLog->status = 2;
  2773. $receiptLog->rid = $rid;
  2774. $receiptLog->insert ();
  2775. // 写入列表项
  2776. Doo::loadModel ( 'accountItem' );
  2777. $accountItem = new accountItem ();
  2778. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2779. // 项目金额合计
  2780. Doo::loadModel ( 'RItem' );
  2781. $RItem = new RItem ();
  2782. // 讲师获得
  2783. Doo::loadModel ( 'RILecturer' );
  2784. $RILecturer = new RILecturer ();
  2785. $RItemList = $RItem->getRItemByRid ( $rid );
  2786. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2787. // 支出项金额详情
  2788. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2789. // print_r($aItem);
  2790. // print_r($aiData);
  2791. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2792. $ag = $tr = $ta = $ot = 0;
  2793. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2794. foreach ( $aItem as $key => $value ) {
  2795. if ($value ['category'] == $this->TRAIN) {
  2796. foreach ( $aiData ['dataList'] as $k => $v ) {
  2797. if ($value ['name'] == $v ['name']) {
  2798. array_push ( $accountJson [$this->TRAIN], array (
  2799. 'aid' => $value ['aid'],
  2800. 'name' => $value ['name'],
  2801. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2802. ) );
  2803. $sum += $v ['price'];
  2804. $trainSum += $v ['price'];
  2805. unset ( $aiData ['dataList'] [$k] );
  2806. break;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. $accountJson ['cSum'] = array (
  2812. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2813. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2814. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2815. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2816. );
  2817. // 报销单
  2818. $receipt = new receipt ();
  2819. $receipt->accountItem = json_encode ( $accountJson );
  2820. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2821. $receipt->update ( array (
  2822. 'where' => 'rid=' . $rid
  2823. ) );
  2824. // print_r($accountJson);
  2825. // statistics item 统计写入
  2826. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2827. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2828. $accountItem = $accountJson;
  2829. $stat = $statistics->getOne ( array (
  2830. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2831. 'asArray' => true
  2832. ) );
  2833. if (empty ( $stat )) {
  2834. $statistics->date = date ( "Y-m-d" );
  2835. $statistics->cid = $this->staff [0] ['cid'];
  2836. $statistics->staff = $this->staff [0] ['sid'];
  2837. $statistics->agPrice = 0;
  2838. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2839. $statistics->insert ();
  2840. } else {
  2841. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2842. $statistics->update ( array (
  2843. 'where' => 'sid=' . $stat ['sid']
  2844. ) );
  2845. }
  2846. return "/saeaBorad";
  2847. }
  2848. function confirmation() {
  2849. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2850. Doo::loadModel ( 'receipt' );
  2851. Doo::loadModel ( 'receiptDetail' );
  2852. $receipt = new receipt ();
  2853. $receiptDetail = new receiptDetail ();
  2854. Doo::loadModel ( 'statistics' );
  2855. Doo::loadModel ( 'itemStatistics' );
  2856. $statistics = new statistics ();
  2857. $itemStatistics = new itemStatistics ();
  2858. Doo::loadModel ( "verify" );
  2859. $verify = new verify ();
  2860. $receiptDetailList = $receipt->getOne ( array (
  2861. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2862. 'asArray' => true
  2863. ) );
  2864. if (empty ( $receiptDetailList ))
  2865. return "/saeaBorad";
  2866. $verifyDetail = $verify->getOne ( array (
  2867. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2868. 'asArray' => true
  2869. ) );
  2870. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2871. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2872. $nowStaff = "";
  2873. $nowStaffList = array ();
  2874. if ($verifyDetail [0] [1] == 'ROLE') {
  2875. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2876. foreach ( $vStaffString as $key => $value ) {
  2877. $staffK = explode ( "_", $value );
  2878. array_push ( $nowStaffList, $staffK [0] );
  2879. }
  2880. $nowStaff = implode ( ',', $nowStaffList );
  2881. } else {
  2882. $nowStaff = $verifyDetail [0] [0];
  2883. }
  2884. $receipt->nowStaff = $nowStaff;
  2885. }
  2886. // echo $nowStaff;
  2887. // print_r($verifyDetail);die;
  2888. $receipt->rid = $receiptDetailList ['rid'];
  2889. $receipt->status = 2;
  2890. $receipt->update ();
  2891. // 操作日志
  2892. Doo::loadModel ( "receiptLog" );
  2893. $receiptLog = new receiptLog ();
  2894. $verify = new verify ();
  2895. $receiptInfo = $receipt->getOne ( array (
  2896. 'where' => 'rid=' . $rid,
  2897. 'asArray' => true
  2898. ) );
  2899. $vr = $verify->getOne ( array (
  2900. 'where' => 'vid=' . $receiptInfo ['verify'],
  2901. 'asArray' => true
  2902. ) );
  2903. $jd = json_decode ( $vr ['staff'] );
  2904. $roleId = 0;
  2905. foreach ( $jd as $key => $value ) {
  2906. if ($value [1] == 'ROLE') {
  2907. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2908. if ($pos !== false) {
  2909. $roleId = $value [0];
  2910. }
  2911. }
  2912. }
  2913. // 审批日志
  2914. // echo $roleId;die;
  2915. if (! empty ( $roleId )) {
  2916. Doo::loadModel ( "role" );
  2917. $role = new role ();
  2918. $roleInfo = $role->getOne ( array (
  2919. 'where' => 'rid=' . $roleId,
  2920. 'asArray' => true
  2921. ) );
  2922. // $receiptLog->rolename = $roleInfo ['name'];
  2923. }
  2924. $receiptLog->username = $this->staff [0] ['username'];
  2925. $receiptLog->uid = $this->staff [0] ['sid'];
  2926. $receiptLog->date = date ( "Y-m-d" );
  2927. $receiptLog->opinion = '提交审批';
  2928. $receiptLog->img = $this->staff [0] ['avatar'];
  2929. $receiptLog->status = 2;
  2930. $receiptLog->rid = $rid;
  2931. $receiptLog->insert ();
  2932. return "/expenses";
  2933. }
  2934. function expenses() {
  2935. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2936. if (empty ( $item ))
  2937. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2938. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2939. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2940. Doo::loadClass ( 'XDeode' );
  2941. $XDeode = new XDeode ( 7 );
  2942. Doo::loadModel ( 'receipt' );
  2943. $receipt = new receipt ();
  2944. Doo::loadModel ( 'L_category' );
  2945. $Lcategory = new L_category ();
  2946. Doo::loadModel ( 'verify' );
  2947. Doo::loadModel ( 'statistics' );
  2948. $statistics = new statistics ();
  2949. $verify = new verify ();
  2950. Doo::loadModel ( 'staff' );
  2951. $staff = new staff ();
  2952. $condition = "";
  2953. if ($item == "expenses")
  2954. $condition = " and Rtype=1 ";
  2955. elseif ($item == "receipts")
  2956. $condition = " and Rtype=0 ";
  2957. elseif ($item == "remits")
  2958. $condition = " and Rtype=2 ";
  2959. elseif ($item == "train")
  2960. $condition = " and Rtype=3 ";
  2961. $dateCondition = " and Year(date) =" . $year;
  2962. if (! empty ( $moth )) {
  2963. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2964. $stList = $statistics->getOne ( array (
  2965. 'select' => 'rePrice ,agPrice',
  2966. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2967. 'asArray' => true
  2968. ) );
  2969. } else
  2970. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2971. if (empty ( $stList ))
  2972. $stList = array (
  2973. 'rePrice' => 0,
  2974. 'agPrice' => 0
  2975. );
  2976. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2977. if (! isset ( $noPassSum ['sum'] ))
  2978. $noPassSum ['sum'] = 0;
  2979. $data ['stList'] = array (
  2980. 'rePrice' => $stList ['rePrice'],
  2981. 'agPrice' => $stList ['agPrice'],
  2982. 'skPrice' => ($noPassSum ['sum'])
  2983. );
  2984. $receiptList = $receipt->find ( array (
  2985. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2986. 'desc' => 'rid',
  2987. 'asArray' => true
  2988. ) );
  2989. $Locate = 0;
  2990. $roleId = 0;
  2991. $button = 0;
  2992. foreach ( $receiptList as $key => $value ) {
  2993. $receiptList [$key] ['Locate'] = $Locate;
  2994. $Locate ++;
  2995. $receiptList [$key] ['reviseDetail'] = array ();
  2996. if (! empty ( $value ['reviseDetail'] ))
  2997. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2998. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2999. $categoryDetil = $Lcategory->getOne ( array (
  3000. 'where' => 'cid=' . $value ['cid'],
  3001. 'asArray' => true
  3002. ) );
  3003. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3004. // 检测编辑状态
  3005. $verifyList = $verify->getOne ( array (
  3006. 'where' => 'vid=' . $value ['verify'],
  3007. 'asArray' => true
  3008. ) );
  3009. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3010. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3011. Doo::loadModel ( 'role' );
  3012. $role = new role ();
  3013. $flag = true;
  3014. $roleKey = 0;
  3015. $endStaffArray = array ();
  3016. $roleArrayCopy = array ();
  3017. foreach ( $verifyList as $k => $v ) {
  3018. // init verifyStaff
  3019. if ($v [1] == 'ROLE') {
  3020. if (! empty ( $verifyStaff )) {
  3021. $endStaffArray = end ( $verifyStaff );
  3022. // if ($v[0]==$endStaffArray['nextStaff']){
  3023. // $roleId=$v[0];
  3024. // }
  3025. }
  3026. $roleVerify = json_decode ( $v [3], true );
  3027. $roleKey = $k;
  3028. $roleArray = array ();
  3029. $rolename = $role->getOne ( array (
  3030. 'where' => 'rid=' . $v [0],
  3031. 'asArray' => true
  3032. ) );
  3033. foreach ( $roleVerify as $o => $p ) {
  3034. $staffID = explode ( '_', $p );
  3035. $staffInfo = $staff->getOne ( array (
  3036. 'where' => 'sid=' . $staffID [0],
  3037. 'asArray' => true
  3038. ) );
  3039. // print_r($staffID);
  3040. $exp = array (
  3041. 0 => $staffInfo ['sid'],
  3042. 1 => $staffID [1],
  3043. 2 => $staffInfo ['avatar'],
  3044. 'date' => '',
  3045. 'date' => '',
  3046. 'opinion' => '',
  3047. 'status' => '',
  3048. 'rolename' => $rolename ['name']
  3049. );
  3050. array_push ( $roleArray, $exp );
  3051. }
  3052. $roleArrayCopy [$v [0]] = $roleArray;
  3053. // $verifyList[$k]['roleArray']=$roleArray;
  3054. }
  3055. $verifyList [$k] ['date'] = "";
  3056. $verifyList [$k] ['opinion'] = "";
  3057. $verifyList [$k] ['status'] = "";
  3058. if (empty ( $verifyStaff )) {
  3059. $verifyList [$k] ['date'] = "";
  3060. $verifyList [$k] ['opinion'] = "";
  3061. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3062. $verifyList [$k] ['status'] = 4;
  3063. $flag = false;
  3064. }
  3065. } else {
  3066. foreach ( $verifyStaff as $m => $u ) {
  3067. if ($v [0] == $m) {
  3068. $verifyList [$k] ['date'] = $u ['date'];
  3069. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3070. $verifyList [$k] ['status'] = $u ['status'];
  3071. $flag = false;
  3072. break;
  3073. }
  3074. }
  3075. $endStaffArray = end ( $verifyStaff );
  3076. if (isset ( $endStaffArray ['ROLE'] )) {
  3077. } else {
  3078. // $endKey=key($verifyStaff);
  3079. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3080. // $button=4;
  3081. // $verifyList[$k]['status']=4;
  3082. // }
  3083. }
  3084. }
  3085. }
  3086. $rolename ['name'] = '';
  3087. if (! empty ( $roleId )) {
  3088. Doo::loadModel ( 'role' );
  3089. $role = new role ();
  3090. $rolename = $role->getOne ( array (
  3091. 'where' => 'rid=' . $roleId,
  3092. 'asArray' => true
  3093. ) );
  3094. }
  3095. if (! empty ( $verifyStaff ))
  3096. $endStaffArray = end ( $verifyStaff );
  3097. $KOP = false;
  3098. foreach ( $roleArrayCopy as $P => $A ) {
  3099. foreach ( $A as $MKI => $AVL ) {
  3100. if (! empty ( $verifyStaff )) {
  3101. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3102. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3103. $button = 4;
  3104. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3105. }
  3106. foreach ( $verifyStaff as $m => $u ) {
  3107. $AVLFK = $AVL [0] . '_R';
  3108. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3109. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3110. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3111. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3112. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3113. break;
  3114. }
  3115. }
  3116. } else {
  3117. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3118. $button = 4;
  3119. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3120. }
  3121. }
  3122. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3123. $KOP = true;
  3124. }
  3125. }
  3126. foreach ( $roleArrayCopy as $k => $v ) {
  3127. foreach ( $verifyList as $m => $n ) {
  3128. if ($n [0] == $k) {
  3129. array_splice ( $verifyList, $m, 1, $v );
  3130. }
  3131. }
  3132. }
  3133. $receiptList [$key] ['verifyList'] = $verifyList;
  3134. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3135. 'where' => 'sid=' . $value ['staff'],
  3136. 'asArray' => true
  3137. ) );
  3138. $receiptList [$key] ['button'] = $button;
  3139. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3140. }
  3141. // print_r($receiptList);die;
  3142. $mothHtml = "";
  3143. for($i = 1; $i <= 12; $i ++) {
  3144. if ($moth == $i)
  3145. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3146. else
  3147. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3148. }
  3149. $dateHtml = "";
  3150. $now = date ( "Y" );
  3151. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3152. if ($YEARD <= $now) {
  3153. $dateHtml .= '<option ';
  3154. if ($year == $YEARD) {
  3155. $dateHtml .= 'selected ';
  3156. }
  3157. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3158. }
  3159. }
  3160. $data ['dateHtml'] = $dateHtml;
  3161. $data ['mothHtml'] = $mothHtml;
  3162. $data ['receiptList'] = $receiptList;
  3163. $data ['memu'] = "receipt";
  3164. $data ['staff'] = $this->staff;
  3165. $data ['receiptMemu'] = 'expenses';
  3166. $data ['verifyId'] = $this->verifyId;
  3167. $data ['executeId'] = $this->executeId;
  3168. $data ['item'] = $item;
  3169. $data ['year'] = $year;
  3170. $this->render ( "/admin/expenses", $data );
  3171. }
  3172. function expensesCollect() {
  3173. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3174. Doo::loadModel ( 'receipt' );
  3175. $receipt = new receipt ();
  3176. Doo::loadModel ( 'L_category' );
  3177. $Lcategory = new L_category ();
  3178. Doo::loadModel ( 'verify' );
  3179. Doo::loadModel ( 'statistics' );
  3180. $statistics = new statistics ();
  3181. $verify = new verify ();
  3182. Doo::loadModel ( 'staff' );
  3183. $staff = new staff ();
  3184. Doo::loadModel ( 'loanReceipt' );
  3185. $loanReceipt = new loanReceipt ();
  3186. $receiptList = $receipt->find ( array (//去掉
  3187. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3188. 'desc' => 'rid',
  3189. 'asArray' => true
  3190. ) );
  3191. $loanList = $loanReceipt->find ( array (
  3192. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3193. 'desc' => 'rid',
  3194. 'asArray' => true
  3195. ) );
  3196. /*
  3197. * $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;
  3198. */
  3199. $data ['explanation'] = '';
  3200. if (! empty ( $loanList ))
  3201. $data ['explanation'] = $loanList [0] ['explanation'];
  3202. $Locate = 0;
  3203. $roleId = 0;
  3204. $button = 0;
  3205. foreach ( $receiptList as $key => $value ) {
  3206. $receiptList [$key] ['Locate'] = $Locate;
  3207. $Locate ++;
  3208. $receiptList [$key] ['reviseDetail'] = array ();
  3209. if (! empty ( $value ['reviseDetail'] ))
  3210. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3211. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3212. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3213. $categoryDetil = $Lcategory->getOne ( array (
  3214. 'where' => 'cid=' . $value ['cid'],
  3215. 'asArray' => true
  3216. ) );
  3217. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3218. // 检测编辑状态
  3219. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3220. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3221. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3222. else
  3223. $verifyList ['staff'] = $value ['verifyBreakup'];
  3224. } else
  3225. $verifyList = $verify->getOne ( array (
  3226. 'where' => 'vid=' . $value ['verify'],
  3227. 'asArray' => true
  3228. ) );
  3229. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3230. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3231. Doo::loadModel ( 'role' );
  3232. $role = new role ();
  3233. $flag = true;
  3234. $roleKey = 0;
  3235. $endStaffArray = array ();
  3236. $roleArrayCopy = array ();
  3237. foreach ( $verifyList as $k => $v ) {
  3238. // init verifyStaff
  3239. if ($v [1] == 'ROLE') {
  3240. if (! empty ( $verifyStaff )) {
  3241. $endStaffArray = end ( $verifyStaff );
  3242. // if ($v[0]==$endStaffArray['nextStaff']){
  3243. // $roleId=$v[0];
  3244. // }
  3245. }
  3246. $roleVerify = json_decode ( $v [3], true );
  3247. $roleKey = $k;
  3248. $roleArray = array ();
  3249. $rolename = $role->getOne ( array (
  3250. 'where' => 'rid=' . $v [0],
  3251. 'asArray' => true
  3252. ) );
  3253. foreach ( $roleVerify as $o => $p ) {
  3254. $staffID = explode ( '_', $p );
  3255. $staffInfo = $staff->getOne ( array (
  3256. 'where' => 'sid=' . $staffID [0],
  3257. 'asArray' => true
  3258. ) );
  3259. // print_r($staffID);
  3260. $exp = array (
  3261. 0 => $staffInfo ['sid'],
  3262. 1 => $staffID [1],
  3263. 2 => $staffInfo ['avatar'],
  3264. 'date' => '',
  3265. 'date' => '',
  3266. 'opinion' => '',
  3267. 'status' => '',
  3268. 'rolename' => $rolename ['name']
  3269. );
  3270. array_push ( $roleArray, $exp );
  3271. }
  3272. $roleArrayCopy [$v [0]] = $roleArray;
  3273. // $verifyList[$k]['roleArray']=$roleArray;
  3274. }
  3275. $verifyList [$k] ['date'] = "";
  3276. $verifyList [$k] ['opinion'] = "";
  3277. $verifyList [$k] ['status'] = "";
  3278. if (empty ( $verifyStaff )) {
  3279. $verifyList [$k] ['date'] = "";
  3280. $verifyList [$k] ['opinion'] = "";
  3281. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3282. $verifyList [$k] ['status'] = 4;
  3283. $flag = false;
  3284. }
  3285. } else {
  3286. foreach ( $verifyStaff as $m => $u ) {
  3287. if ($v [0] == $m) {
  3288. $verifyList [$k] ['date'] = $u ['date'];
  3289. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3290. $verifyList [$k] ['status'] = $u ['status'];
  3291. $flag = false;
  3292. break;
  3293. }
  3294. }
  3295. $endStaffArray = end ( $verifyStaff );
  3296. if (isset ( $endStaffArray ['ROLE'] )) {
  3297. } else {
  3298. // $endKey=key($verifyStaff);
  3299. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3300. // $button=4;
  3301. // $verifyList[$k]['status']=4;
  3302. // }
  3303. }
  3304. }
  3305. }
  3306. $rolename ['name'] = '';
  3307. if (! empty ( $roleId )) {
  3308. Doo::loadModel ( 'role' );
  3309. $role = new role ();
  3310. $rolename = $role->getOne ( array (
  3311. 'where' => 'rid=' . $roleId,
  3312. 'asArray' => true
  3313. ) );
  3314. }
  3315. if (! empty ( $verifyStaff ))
  3316. $endStaffArray = end ( $verifyStaff );
  3317. $KOP = false;
  3318. foreach ( $roleArrayCopy as $P => $A ) {
  3319. foreach ( $A as $MKI => $AVL ) {
  3320. if (! empty ( $verifyStaff )) {
  3321. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3322. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3323. $button = 4;
  3324. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3325. }
  3326. foreach ( $verifyStaff as $m => $u ) {
  3327. $AVLFK = $AVL [0] . '_R';
  3328. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3329. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3330. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3331. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3332. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3333. break;
  3334. }
  3335. }
  3336. } else {
  3337. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3338. $button = 4;
  3339. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3340. }
  3341. }
  3342. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3343. $KOP = true;
  3344. }
  3345. }
  3346. foreach ( $roleArrayCopy as $k => $v ) {
  3347. foreach ( $verifyList as $m => $n ) {
  3348. if ($n [0] == $k) {
  3349. array_splice ( $verifyList, $m, 1, $v );
  3350. }
  3351. }
  3352. }
  3353. // 费用执行人相关数据
  3354. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3355. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3356. foreach ( $executeCopy as $k => $v ) {
  3357. $executeCopy [$k] ['date'] = '';
  3358. $executeCopy [$k] ['opinion'] = '';
  3359. $executeCopy [$k] ['status'] = '';
  3360. if (! empty ( $executeStaff ))
  3361. foreach ( $executeStaff as $m => $u ) {
  3362. if ($v [0] == $m) {
  3363. $executeCopy [$k] ['date'] = $u ['date'];
  3364. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3365. $executeCopy [$k] ['status'] = $u ['status'];
  3366. break;
  3367. }
  3368. }
  3369. }
  3370. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3371. $receiptList [$key] ['verifyList'] = $verifyList;
  3372. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3373. 'where' => 'sid=' . $value ['staff'],
  3374. 'asArray' => true
  3375. ) );
  3376. $receiptList [$key] ['button'] = $button;
  3377. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3378. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3379. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3380. $receiptList [$key] ['relust'] = $relust;
  3381. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3382. }
  3383. Doo::loadModel ( 'enclosur' );
  3384. $enclosur = new enclosur ();
  3385. $enclosurList = $enclosur->find ( array (
  3386. 'where' => 'rid=' . $rid,
  3387. 'asArray' => true
  3388. ) );
  3389. $enclosurHtml = '';
  3390. foreach ( $enclosurList as $value ) {
  3391. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3392. }
  3393. $data ['enclosurHtml'] = $enclosurHtml;
  3394. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3395. $data ['receiptList'] = $receiptList;
  3396. $data ['memu'] = "receipt";
  3397. $data ['staff'] = $this->staff;
  3398. $data ['receiptMemu'] = 'expenses';
  3399. $data ['verifyId'] = $this->verifyId;
  3400. $data ['executeId'] = $this->executeId;
  3401. $this->render ( "/admin/expensesCollect", $data );
  3402. }
  3403. function approvalExpenses() {
  3404. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3405. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3406. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3407. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3408. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3409. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3410. // echo $rdate;
  3411. if (empty ( $status ))
  3412. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3413. $page_size = 8;
  3414. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3415. $vidList = array ();
  3416. $button = 0;
  3417. Doo::loadModel ( 'verify' );
  3418. $verify = new verify ();
  3419. Doo::loadModel ( 'receipt' );
  3420. $receipt = new receipt ();
  3421. Doo::loadModel ( 'staff' );
  3422. $staff = new staff ();
  3423. Doo::loadModel ( 'L_category' );
  3424. $Lcategory = new L_category ();
  3425. // user verify ID
  3426. $verifyDetail = $verify->find ( array (
  3427. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3428. 'asArray' => true
  3429. ) );
  3430. foreach ( $verifyDetail as $key => $value ) {
  3431. array_push ( $vidList, $value ['vid'] );
  3432. }
  3433. $vid = implode ( ",", $vidList );
  3434. if (empty ( $verifyDetail ))
  3435. $vid = 0;
  3436. // if ($status==0)
  3437. // $dateCondition="";
  3438. // else
  3439. $dateCondition = " ";
  3440. // if (! empty ( $month ))
  3441. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3442. if ($status == 'done' || $status == 'termination') {
  3443. if (! empty ( $year )) {
  3444. $dateCondition = " and Year(pastDate) =" . $year;
  3445. if (! empty ( $month ))
  3446. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3447. }
  3448. } elseif ($status == 'finish') {
  3449. if (! empty ( $year )) {
  3450. $dateCondition = " and Year(pastDate) =" . $year;
  3451. if (! empty ( $month ))
  3452. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3453. }
  3454. }
  3455. // date ( 'Y-m' )
  3456. // if (! empty ( $rdate ) && $status == 'done')
  3457. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3458. // elseif (! empty ( $rdate ))
  3459. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3460. $categoryList = $Lcategory->find ( array (
  3461. 'asArray' => true
  3462. ) );
  3463. $staffList = $staff->find ( array (
  3464. 'where' => 'cid=' . $cid,
  3465. 'asArray' => true
  3466. ) );
  3467. $cateCondition = "";
  3468. $staffCondition = "";
  3469. $approvalCondition = "";
  3470. if (! empty ( $cid )) {
  3471. $cateCondition = ' and cid=' . $cid;
  3472. }
  3473. if (! empty ( $sid )) {
  3474. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3475. $cateCondition = "";
  3476. }
  3477. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3478. if ($status == 'pendApproval') {
  3479. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3480. }
  3481. if ($status == 'ongoing') {
  3482. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3483. }
  3484. if ($status == 'done') {
  3485. $approvalCondition = ' and (status=8 or status=9 ) ';
  3486. }
  3487. if ($status == 'termination') {
  3488. $approvalCondition = " and status=3";
  3489. }
  3490. if ($status == 'finish') {
  3491. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3492. }
  3493. $pageinfo ['page'] = array (
  3494. 'previous' => ''
  3495. );
  3496. if(!empty($receiptOrder)){
  3497. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3498. $receiptList = $receipt->find ( array ( // $dateCondition
  3499. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3500. 'desc' => 'rid',
  3501. 'asArray' => true
  3502. ) );
  3503. }else{
  3504. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3505. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3506. $receiptList = $receipt->find ( array ( // $dateCondition.
  3507. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3508. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3509. 'desc' => 'rid',
  3510. 'asArray' => true
  3511. ) );
  3512. } else {
  3513. $receiptList = $receipt->find ( array ( // $dateCondition
  3514. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3515. 'desc' => 'rid',
  3516. 'asArray' => true
  3517. ) );
  3518. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3519. }
  3520. }
  3521. $rLRes = $receipt->find ( array (
  3522. '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 . ')',
  3523. 'desc' => 'rid',
  3524. 'asArray' => true
  3525. ) );
  3526. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3527. // print_r($receiptList);
  3528. Doo::loadClass ( 'XDeode' );
  3529. $XDeode = new XDeode ( 7 );
  3530. $Locate = 0;
  3531. $reportList = $reportCateList = array ();
  3532. foreach ( $receiptList as $key => $value ) {
  3533. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3534. $receiptList [$key] ['Locate'] = $Locate;
  3535. $Locate ++;
  3536. $receiptList [$key] ['reviseDetail'] = array ();
  3537. if (! empty ( $value ['reviseDetail'] ))
  3538. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3539. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3540. $categoryDetil = $Lcategory->getOne ( array (
  3541. 'where' => 'cid=' . $value ['cid'],
  3542. 'asArray' => true
  3543. ) );
  3544. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3545. $verifyList = $verify->getOne ( array (
  3546. 'where' => 'vid=' . $value ['verify'],
  3547. 'asArray' => true
  3548. ) );
  3549. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3550. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3551. foreach ( $verifyList as $k => $v ) {
  3552. // init verifyStaff
  3553. $verifyList [$k] ['date'] = "";
  3554. $verifyList [$k] ['opinion'] = "";
  3555. $verifyList [$k] ['status'] = "";
  3556. if (empty ( $verifyStaff )) {
  3557. $verifyList [$k] ['date'] = "";
  3558. $verifyList [$k] ['opinion'] = "";
  3559. if ($v [0] == $this->staff [0] ['sid']) {
  3560. $verifyList [$k] ['status'] = 4;
  3561. $button = 4;
  3562. }
  3563. } else {
  3564. $flag = true;
  3565. foreach ( $verifyStaff as $m => $u ) {
  3566. if ($v [0] == $m) {
  3567. $verifyList [$k] ['date'] = $u ['date'];
  3568. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3569. $verifyList [$k] ['status'] = $u ['status'];
  3570. $flag = false;
  3571. break;
  3572. }
  3573. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3574. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3575. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3576. }
  3577. if ($flag) { // 检测可编辑
  3578. if ($v [0] == $this->staff [0] ['sid']) {
  3579. $verifyList [$k] ['status'] = 4;
  3580. $button = 4;
  3581. }
  3582. }
  3583. }
  3584. }
  3585. $receiptList [$key] ['verifyList'] = $verifyList;
  3586. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3587. 'where' => 'sid=' . $value ['staff'],
  3588. 'asArray' => true
  3589. ) );
  3590. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3591. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3592. $receiptList [$key] ['button'] = $button;
  3593. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3594. //获得培训班结算RID 借款费用--已经锁定
  3595. if($value['status']==10){
  3596. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  3597. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  3598. }
  3599. }
  3600. $reportList = array_unique ( $reportList );
  3601. $reportHtml = '';
  3602. foreach ( $reportList as $key => $value ) {
  3603. $v = explode ( "-", $value );
  3604. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3605. }
  3606. // print_r($reportList)
  3607. $data ['reportHtml'] = $reportHtml;
  3608. $reportCateList = array_unique ( $reportCateList );
  3609. $reportCateHtml = '';
  3610. foreach ( $reportCateList as $key => $value ) {
  3611. $v = explode ( "-", $value );
  3612. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3613. }
  3614. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3615. $data ['reportCateHtml'] = $reportCateHtml;
  3616. // print_r($receiptList);die;
  3617. // $data['verifyDetail']=$verifyDetail;
  3618. $mothHtml = "";
  3619. for($i = 1; $i <= 12; $i ++) {
  3620. if ($month == $i)
  3621. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3622. else
  3623. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3624. }
  3625. $data ['mothHtml'] = $mothHtml;
  3626. $dateHtml = "";
  3627. $now = date ( "Y" );
  3628. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3629. if ($YEARD <= $now) {
  3630. $dateHtml .= '<option ';
  3631. if ($year == $YEARD) {
  3632. $dateHtml .= 'selected ';
  3633. }
  3634. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3635. }
  3636. }
  3637. $data ['dateHtml'] = $dateHtml;
  3638. $data ['page'] = $pageinfo;
  3639. $data ['receiptList'] = $receiptList;
  3640. $data ['receiptApprovalCount'] = count ( $rLRes );
  3641. $data ['status'] = $status;
  3642. $data ['year'] = $year;
  3643. $data ['month'] = $month;
  3644. $data ['categoryList'] = $categoryList;
  3645. $data ['staffList'] = $staffList;
  3646. $data ['cid'] = $cid;
  3647. $data ['sid'] = $sid;
  3648. // print_r($receiptList);
  3649. $data['receiptOrder']=$receiptOrder;
  3650. $data ['memu'] = "receipt";
  3651. $data ['staff'] = $this->staff;
  3652. $data ['receiptMemu'] = 'approvalExpenses';
  3653. $data ['verifyId'] = $this->verifyId;
  3654. $data ['executeId'] = $this->executeId;
  3655. $this->render ( "/admin/approvalExpenses", $data );
  3656. }
  3657. function expensesDoc() {
  3658. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3659. Doo::loadClass ( 'XDeode' );
  3660. $XDeode = new XDeode ( 5 );
  3661. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3662. $rid = $XDeode->decode ( $rid );
  3663. if (! is_numeric ( $rid ))
  3664. die ( 'illegal request' );
  3665. Doo::loadModel ( 'receipt' );
  3666. $receipt = new receipt ();
  3667. Doo::loadModel ( 'L_category' );
  3668. $Lcategory = new L_category ();
  3669. Doo::loadModel ( 'verify' );
  3670. Doo::loadModel ( 'statistics' );
  3671. $statistics = new statistics ();
  3672. $verify = new verify ();
  3673. Doo::loadModel ( 'staff' );
  3674. $staff = new staff ();
  3675. Doo::loadModel ( 'loanReceipt' );
  3676. $loanReceipt = new loanReceipt ();
  3677. $receiptList = $receipt->find ( array (
  3678. 'where' => ' rid=' . $rid,
  3679. 'desc' => 'rid',
  3680. 'asArray' => true
  3681. ) );
  3682. $loanList = array ();
  3683. if (! empty ( $receiptList ))
  3684. $loanList = $loanReceipt->find ( array (
  3685. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3686. 'desc' => 'rid',
  3687. 'asArray' => true
  3688. ) );
  3689. $Locate = 0;
  3690. $roleId = 0;
  3691. $button = 0;
  3692. foreach ( $loanList as $key => $value ) {
  3693. $loanList [$key] ['Locate'] = $Locate;
  3694. $Locate ++;
  3695. $loanList [$key] ['reviseDetail'] = array ();
  3696. if (! empty ( $value ['reviseDetail'] ))
  3697. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3698. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3699. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3700. $categoryDetil = $Lcategory->getOne ( array (
  3701. 'where' => 'cid=' . $value ['cid'],
  3702. 'asArray' => true
  3703. ) );
  3704. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3705. // 检测编辑状态
  3706. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3707. $verifyList ['staff'] = $value ['verifyBreakup'];
  3708. else
  3709. $verifyList = $verify->getOne ( array (
  3710. 'where' => 'vid=' . $value ['verify'],
  3711. 'asArray' => true
  3712. ) );
  3713. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3714. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3715. Doo::loadModel ( 'role' );
  3716. $role = new role ();
  3717. $flag = true;
  3718. $roleKey = 0;
  3719. $endStaffArray = array ();
  3720. $roleArrayCopy = array ();
  3721. foreach ( $verifyList as $k => $v ) {
  3722. // init verifyStaff
  3723. if ($v [1] == 'ROLE') {
  3724. if (! empty ( $verifyStaff )) {
  3725. $endStaffArray = end ( $verifyStaff );
  3726. // if ($v[0]==$endStaffArray['nextStaff']){
  3727. // $roleId=$v[0];
  3728. // }
  3729. }
  3730. $roleVerify = json_decode ( $v [3], true );
  3731. $roleKey = $k;
  3732. $roleArray = array ();
  3733. $rolename = $role->getOne ( array (
  3734. 'where' => 'rid=' . $v [0],
  3735. 'asArray' => true
  3736. ) );
  3737. foreach ( $roleVerify as $o => $p ) {
  3738. $staffID = explode ( '_', $p );
  3739. $staffInfo = $staff->getOne ( array (
  3740. 'where' => 'sid=' . $staffID [0],
  3741. 'asArray' => true
  3742. ) );
  3743. // print_r($staffID);
  3744. $exp = array (
  3745. 0 => $staffInfo ['sid'],
  3746. 1 => $staffID [1],
  3747. 2 => $staffInfo ['avatar'],
  3748. 'date' => '',
  3749. 'date' => '',
  3750. 'opinion' => '',
  3751. 'status' => '',
  3752. 'rolename' => $rolename ['name']
  3753. );
  3754. array_push ( $roleArray, $exp );
  3755. }
  3756. $roleArrayCopy [$v [0]] = $roleArray;
  3757. // $verifyList[$k]['roleArray']=$roleArray;
  3758. }
  3759. $verifyList [$k] ['date'] = "";
  3760. $verifyList [$k] ['opinion'] = "";
  3761. $verifyList [$k] ['status'] = "";
  3762. if (empty ( $verifyStaff )) {
  3763. $verifyList [$k] ['date'] = "";
  3764. $verifyList [$k] ['opinion'] = "";
  3765. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3766. $verifyList [$k] ['status'] = 4;
  3767. $flag = false;
  3768. }
  3769. } else {
  3770. foreach ( $verifyStaff as $m => $u ) {
  3771. if ($v [0] == $m) {
  3772. $verifyList [$k] ['date'] = $u ['date'];
  3773. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3774. $verifyList [$k] ['status'] = $u ['status'];
  3775. $flag = false;
  3776. break;
  3777. }
  3778. }
  3779. $endStaffArray = end ( $verifyStaff );
  3780. if (isset ( $endStaffArray ['ROLE'] )) {
  3781. } else {
  3782. // $endKey=key($verifyStaff);
  3783. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3784. // $button=4;
  3785. // $verifyList[$k]['status']=4;
  3786. // }
  3787. }
  3788. }
  3789. }
  3790. $rolename ['name'] = '';
  3791. if (! empty ( $roleId )) {
  3792. Doo::loadModel ( 'role' );
  3793. $role = new role ();
  3794. $rolename = $role->getOne ( array (
  3795. 'where' => 'rid=' . $roleId,
  3796. 'asArray' => true
  3797. ) );
  3798. }
  3799. if (! empty ( $verifyStaff ))
  3800. $endStaffArray = end ( $verifyStaff );
  3801. $KOP = false;
  3802. foreach ( $roleArrayCopy as $P => $A ) {
  3803. foreach ( $A as $MKI => $AVL ) {
  3804. if (! empty ( $verifyStaff )) {
  3805. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3806. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3807. $button = 4;
  3808. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3809. }
  3810. foreach ( $verifyStaff as $m => $u ) {
  3811. $AVLFK = $AVL [0] . '_R';
  3812. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3813. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3814. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3815. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3816. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3817. break;
  3818. }
  3819. }
  3820. } else {
  3821. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3822. $button = 4;
  3823. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3824. }
  3825. }
  3826. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3827. $KOP = true;
  3828. }
  3829. }
  3830. foreach ( $roleArrayCopy as $k => $v ) {
  3831. foreach ( $verifyList as $m => $n ) {
  3832. if ($n [0] == $k) {
  3833. array_splice ( $verifyList, $m, 1, $v );
  3834. }
  3835. }
  3836. }
  3837. $loanList [$key] ['verifyList'] = $verifyList;
  3838. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3839. 'where' => 'sid=' . $value ['staff'],
  3840. 'asArray' => true
  3841. ) );
  3842. $loanList [$key] ['button'] = $button;
  3843. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3844. }
  3845. $data ['loanList'] = $loanList;
  3846. //print_r($loanList);
  3847. $Locate = 0;
  3848. $roleId = 0;
  3849. $button = 0;
  3850. foreach ( $receiptList as $key => $value ) {
  3851. $receiptList [$key] ['Locate'] = $Locate;
  3852. $Locate ++;
  3853. $receiptList [$key] ['reviseDetail'] = array ();
  3854. if (! empty ( $value ['reviseDetail'] ))
  3855. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3856. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3857. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3858. $categoryDetil = $Lcategory->getOne ( array (
  3859. 'where' => 'cid=' . $value ['cid'],
  3860. 'asArray' => true
  3861. ) );
  3862. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3863. // 检测编辑状态
  3864. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3865. $verifyList ['staff'] = $value ['verifyBreakup'];
  3866. } else
  3867. $verifyList = $verify->getOne ( array (
  3868. 'where' => 'vid=' . $value ['verify'],
  3869. 'asArray' => true
  3870. ) );
  3871. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3872. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3873. Doo::loadModel ( 'role' );
  3874. $role = new role ();
  3875. if ($verifyList == NULL)
  3876. $verifyList = array ();
  3877. $flag = true;
  3878. $roleKey = 0;
  3879. $endStaffArray = array ();
  3880. $roleArrayCopy = array ();
  3881. foreach ( $verifyList as $k => $v ) {
  3882. // init verifyStaff
  3883. if ($v [1] == 'ROLE') {
  3884. if (! empty ( $verifyStaff )) {
  3885. $endStaffArray = end ( $verifyStaff );
  3886. // if ($v[0]==$endStaffArray['nextStaff']){
  3887. // $roleId=$v[0];
  3888. // }
  3889. }
  3890. $roleVerify = json_decode ( $v [3], true );
  3891. $roleKey = $k;
  3892. $roleArray = array ();
  3893. $rolename = $role->getOne ( array (
  3894. 'where' => 'rid=' . $v [0],
  3895. 'asArray' => true
  3896. ) );
  3897. foreach ( $roleVerify as $o => $p ) {
  3898. $staffID = explode ( '_', $p );
  3899. $staffInfo = $staff->getOne ( array (
  3900. 'where' => 'sid=' . $staffID [0],
  3901. 'asArray' => true
  3902. ) );
  3903. // print_r($staffID);
  3904. $exp = array (
  3905. 0 => $staffInfo ['sid'],
  3906. 1 => $staffID [1],
  3907. 2 => $staffInfo ['avatar'],
  3908. 'date' => '',
  3909. 'date' => '',
  3910. 'opinion' => '',
  3911. 'status' => '',
  3912. 'rolename' => $rolename ['name']
  3913. );
  3914. array_push ( $roleArray, $exp );
  3915. }
  3916. $roleArrayCopy [$v [0]] = $roleArray;
  3917. // $verifyList[$k]['roleArray']=$roleArray;
  3918. }
  3919. $verifyList [$k] ['date'] = "";
  3920. $verifyList [$k] ['opinion'] = "";
  3921. $verifyList [$k] ['status'] = "";
  3922. if (empty ( $verifyStaff )) {
  3923. $verifyList [$k] ['date'] = "";
  3924. $verifyList [$k] ['opinion'] = "";
  3925. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3926. $verifyList [$k] ['status'] = 4;
  3927. $flag = false;
  3928. }
  3929. } else {
  3930. foreach ( $verifyStaff as $m => $u ) {
  3931. if ($v [0] == $m) {
  3932. $verifyList [$k] ['date'] = $u ['date'];
  3933. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3934. $verifyList [$k] ['status'] = $u ['status'];
  3935. $flag = false;
  3936. break;
  3937. }
  3938. }
  3939. $endStaffArray = end ( $verifyStaff );
  3940. if (isset ( $endStaffArray ['ROLE'] )) {
  3941. } else {
  3942. // $endKey=key($verifyStaff);
  3943. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3944. // $button=4;
  3945. // $verifyList[$k]['status']=4;
  3946. // }
  3947. }
  3948. }
  3949. }
  3950. $FC = @$rolename ['name'];
  3951. $rolename ['name'] = '';
  3952. if (! empty ( $roleId )) {
  3953. Doo::loadModel ( 'role' );
  3954. $role = new role ();
  3955. $rolename = $role->getOne ( array (
  3956. 'where' => 'rid=' . $roleId,
  3957. 'asArray' => true
  3958. ) );
  3959. }
  3960. if (! empty ( $verifyStaff ))
  3961. $endStaffArray = end ( $verifyStaff );
  3962. $KOP = false;
  3963. foreach ( $roleArrayCopy as $P => $A ) {
  3964. foreach ( $A as $MKI => $AVL ) {
  3965. if (! empty ( $verifyStaff )) {
  3966. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3967. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3968. $button = 4;
  3969. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3970. }
  3971. foreach ( $verifyStaff as $m => $u ) {
  3972. $AVLFK = $AVL [0] . '_R';
  3973. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3974. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3975. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3976. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3977. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3978. break;
  3979. }
  3980. }
  3981. } else {
  3982. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3983. $button = 4;
  3984. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3985. }
  3986. }
  3987. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3988. $KOP = true;
  3989. }
  3990. }
  3991. foreach ( $roleArrayCopy as $k => $v ) {
  3992. foreach ( $verifyList as $m => $n ) {
  3993. if ($n [0] == $k) {
  3994. array_splice ( $verifyList, $m, 1, $v );
  3995. }
  3996. }
  3997. }
  3998. // 费用执行人相关数据
  3999. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4000. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4001. foreach ( $executeCopy as $k => $v ) {
  4002. $executeCopy [$k] ['date'] = '';
  4003. $executeCopy [$k] ['opinion'] = '';
  4004. $executeCopy [$k] ['status'] = '';
  4005. if (! empty ( $executeStaff ))
  4006. foreach ( $executeStaff as $m => $u ) {
  4007. if ($v [0] == $m) {
  4008. $executeCopy [$k] ['date'] = $u ['date'];
  4009. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4010. $executeCopy [$k] ['status'] = $u ['status'];
  4011. break;
  4012. }
  4013. }
  4014. }
  4015. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4016. // print_r($verifyList);
  4017. $receiptList [$key] ['verifyList'] = $verifyList;
  4018. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4019. 'where' => 'sid=' . $value ['staff'],
  4020. 'asArray' => true
  4021. ) );
  4022. $receiptList [$key] ['button'] = $button;
  4023. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4024. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4025. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4026. $receiptList [$key] ['relust'] = $relust;
  4027. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4028. }
  4029. // print_r($receiptList);
  4030. // 获取审批日志
  4031. Doo::loadModel ( 'receiptLog' );
  4032. $receiptLog = new receiptLog ();
  4033. $rlList = array ();
  4034. $rlInfo = $receiptLog->getOne ( array (
  4035. 'where' => 'rid=' . $rid . ' and status=4',
  4036. 'asArray' => true
  4037. ) );
  4038. // $tijdate = $receiptLog->getOne ( array (
  4039. // 'where' => 'rid=' . $rid . ' and status=2',
  4040. // 'asc' => 'rlid',
  4041. // 'asArray' => true
  4042. // ) );
  4043. if (! empty ( $rlInfo )) {
  4044. $rlList = $receiptLog->find ( array (
  4045. 'where' => 'rid=' . $rid,
  4046. 'asc' => 'rlid',
  4047. 'asArray' => true
  4048. ) );
  4049. }
  4050. $RN=array();
  4051. if (!empty( $rolename ['staff'])){
  4052. $RN = @json_decode ( $rolename ['staff'] );
  4053. }
  4054. //
  4055. foreach ( $rlList as $key => $value ) {
  4056. $rlList [$key] ['rolename'] = '';
  4057. foreach ( $RN as $k => $v ) {
  4058. $id = explode ( "_", $v );
  4059. if ($id [0] == $value ['uid']) {
  4060. $rlList [$key] ['rolename'] = $FC;
  4061. break;
  4062. }
  4063. }
  4064. }
  4065. Doo::loadModel ( 'enclosur' );
  4066. $enclosur = new enclosur ();
  4067. $enclosurList = $enclosur->find ( array (
  4068. 'where' => 'rid=' . $rid,
  4069. 'asArray' => true
  4070. ) );
  4071. $enclosurHtml = '';
  4072. foreach ( $enclosurList as $value ) {
  4073. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4074. }
  4075. $data ['enclosurHtml'] = $enclosurHtml;
  4076. $receiptList [0] ['rlList'] = $rlList;
  4077. $data ['receiptList'] = $receiptList;
  4078. // print_r($receiptList);
  4079. $data ['memu'] = "receipt";
  4080. $data ['staff'] = $this->staff;
  4081. $data ['receiptMemu'] = 'approvalExpenses';
  4082. $data ['verifyId'] = $this->verifyId;
  4083. $data ['executeId'] = $this->executeId;
  4084. $this->render ( "/admin/expensesDoc", $data );
  4085. }
  4086. function expensesEdi() {
  4087. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4088. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4089. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4090. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4091. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4092. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4093. if (empty ( $status ))
  4094. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4095. $vidList = array ();
  4096. $button = 0;
  4097. Doo::loadModel ( 'verify' );
  4098. Doo::loadModel ( 'receipt' );
  4099. Doo::loadModel ( 'staff' );
  4100. $staff = new staff ();
  4101. $receipt = new receipt ();
  4102. $verify = new verify ();
  4103. Doo::loadModel ( 'L_category' );
  4104. $Lcategory = new L_category ();
  4105. Doo::loadModel ( 'enclosur' );
  4106. $enclosur = new enclosur ();
  4107. // user verify ID
  4108. $verifyDetail = $verify->find ( array (
  4109. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4110. 'asArray' => true
  4111. ) );
  4112. foreach ( $verifyDetail as $key => $value ) {
  4113. array_push ( $vidList, $value ['vid'] );
  4114. }
  4115. $vid = implode ( ",", $vidList );
  4116. if (empty ( $verifyDetail ))
  4117. $vid = 0;
  4118. $categoryList = $Lcategory->find ( array (
  4119. 'asArray' => true
  4120. ) );
  4121. $staffList = $staff->find ( array (
  4122. 'where' => 'cid=' . $cid,
  4123. 'asArray' => true
  4124. ) );
  4125. $ap = "";
  4126. if ($status == 4) {
  4127. $ap = 4;
  4128. $status = 2;
  4129. }
  4130. // get Receipt By verifyID status 2
  4131. $receiptList = $receipt->find ( array (
  4132. 'where' => 'rid =' . $rid . ' and status=2',
  4133. 'desc' => 'rid',
  4134. 'asArray' => true
  4135. ) );
  4136. if (empty ( $receiptList )) {
  4137. die ( 'illegal request' );
  4138. }
  4139. $Locate = 0;
  4140. $roleId = 0;
  4141. if ($ap == 4)
  4142. $status = 4;
  4143. foreach ( $receiptList as $key => $value ) {
  4144. $receiptList [$key] ['Locate'] = $Locate;
  4145. $Locate ++;
  4146. $receiptList [$key] ['reviseDetail'] = array ();
  4147. if (! empty ( $value ['reviseDetail'] ))
  4148. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4149. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4150. $categoryDetil = $Lcategory->getOne ( array (
  4151. 'where' => 'cid=' . $value ['cid'],
  4152. 'asArray' => true
  4153. ) );
  4154. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4155. // 检测编辑状态
  4156. $verifyList = $verify->getOne ( array (
  4157. 'where' => 'vid=' . $value ['verify'],
  4158. 'asArray' => true
  4159. ) );
  4160. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4161. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4162. Doo::loadModel ( 'role' );
  4163. $role = new role ();
  4164. // print_r($verifyList);
  4165. $flag = true;
  4166. $roleKey = 0;
  4167. $endStaffArray = array ();
  4168. $roleArrayCopy = array ();
  4169. foreach ( $verifyList as $k => $v ) {
  4170. // init verifyStaff
  4171. if ($v [1] == 'ROLE') {
  4172. if (! empty ( $verifyStaff )) {
  4173. $endStaffArray = end ( $verifyStaff );
  4174. if ($v [0] == $endStaffArray ['nextStaff']) {
  4175. $roleId = $v [0];
  4176. }
  4177. }
  4178. $roleVerify = json_decode ( $v [3], true );
  4179. $roleKey = $k;
  4180. $roleArray = array ();
  4181. $rolename = $role->getOne ( array (
  4182. 'where' => 'rid=' . $v [0],
  4183. 'asArray' => true
  4184. ) );
  4185. foreach ( $roleVerify as $o => $p ) {
  4186. $staffID = explode ( '_', $p );
  4187. $staffInfo = $staff->getOne ( array (
  4188. 'where' => 'sid=' . $staffID [0],
  4189. 'asArray' => true
  4190. ) );
  4191. // print_r($staffID);
  4192. $exp = array (
  4193. 0 => $staffInfo ['sid'],
  4194. 1 => $staffID [1],
  4195. 2 => $staffInfo ['avatar'],
  4196. 'date' => '',
  4197. 'date' => '',
  4198. 'opinion' => '',
  4199. 'status' => '',
  4200. 'rolename' => $rolename ['name']
  4201. );
  4202. array_push ( $roleArray, $exp );
  4203. }
  4204. $roleArrayCopy [$v [0]] = $roleArray;
  4205. // $verifyList[$k]['roleArray']=$roleArray;
  4206. }
  4207. // print_r($roleArray);
  4208. $verifyList [$k] ['date'] = "";
  4209. $verifyList [$k] ['opinion'] = "";
  4210. $verifyList [$k] ['status'] = "";
  4211. if (empty ( $verifyStaff )) {
  4212. $verifyList [$k] ['date'] = "";
  4213. $verifyList [$k] ['opinion'] = "";
  4214. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4215. $verifyList [$k] ['status'] = 4;
  4216. $button = 4;
  4217. $flag = false;
  4218. }
  4219. } else {
  4220. foreach ( $verifyStaff as $m => $u ) {
  4221. if ($v [0] == $m) {
  4222. $verifyList [$k] ['date'] = $u ['date'];
  4223. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4224. $verifyList [$k] ['status'] = $u ['status'];
  4225. $flag = false;
  4226. break;
  4227. }
  4228. }
  4229. $endStaffArray = end ( $verifyStaff );
  4230. if (isset ( $endStaffArray ['ROLE'] )) {
  4231. } else {
  4232. $endKey = key ( $verifyStaff );
  4233. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4234. $button = 4;
  4235. $verifyList [$k] ['status'] = 4;
  4236. }
  4237. }
  4238. }
  4239. }
  4240. $rolename ['name'] = '';
  4241. if (! empty ( $roleId )) {
  4242. Doo::loadModel ( 'role' );
  4243. $role = new role ();
  4244. $rolename = $role->getOne ( array (
  4245. 'where' => 'rid=' . $roleId,
  4246. 'asArray' => true
  4247. ) );
  4248. }
  4249. if (! empty ( $verifyStaff ))
  4250. $endStaffArray = end ( $verifyStaff );
  4251. $KOP = false;
  4252. foreach ( $roleArrayCopy as $P => $A ) {
  4253. foreach ( $A as $MKI => $AVL ) {
  4254. if (! empty ( $verifyStaff )) {
  4255. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4256. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4257. $button = 4;
  4258. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4259. }
  4260. foreach ( $verifyStaff as $m => $u ) {
  4261. $AVLFK = $AVL [0] . '_R';
  4262. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4263. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4264. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4265. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4266. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4267. break;
  4268. }
  4269. }
  4270. } else {
  4271. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4272. $button = 4;
  4273. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4274. }
  4275. }
  4276. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4277. $KOP = true;
  4278. }
  4279. }
  4280. // print_r($roleArrayCopy);
  4281. // echo $roleKey;
  4282. foreach ( $roleArrayCopy as $k => $v ) {
  4283. foreach ( $verifyList as $m => $n ) {
  4284. if ($n [0] == $k) {
  4285. array_splice ( $verifyList, $m, 1, $v );
  4286. }
  4287. }
  4288. }
  4289. $receiptList [$key] ['verifyList'] = $verifyList;
  4290. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4291. 'where' => 'sid=' . $value ['staff'],
  4292. 'asArray' => true
  4293. ) );
  4294. $receiptList [$key] ['button'] = $button;
  4295. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4296. }
  4297. // $data['verifyDetail']=$verifyDetail;
  4298. $mothHtml = "";
  4299. for($i = 1; $i <= 12; $i ++) {
  4300. if ($month == $i)
  4301. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4302. else
  4303. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4304. }
  4305. // 获取审批日志
  4306. Doo::loadModel ( 'receiptLog' );
  4307. $receiptLog = new receiptLog ();
  4308. $rlList = array ();
  4309. $rlInfo = $receiptLog->getOne ( array (
  4310. 'where' => 'rid=' . $rid . ' and status=4',
  4311. 'asArray' => true
  4312. ) );
  4313. $tijdate = $receiptLog->getOne ( array (
  4314. 'where' => 'rid=' . $rid . ' and status=2',
  4315. 'asc' => 'rlid',
  4316. 'asArray' => true
  4317. ) );
  4318. if (! empty ( $rlInfo )) {
  4319. $rlList = $receiptLog->find ( array (
  4320. 'where' => 'rid=' . $rid,
  4321. 'asc' => 'rlid',
  4322. 'asArray' => true
  4323. ) );
  4324. }
  4325. $receiptList [0] ['rlList'] = $rlList;
  4326. $enclosurList = $enclosur->find ( array (
  4327. 'where' => 'rid=' . $rid,
  4328. 'asArray' => true
  4329. ) );
  4330. $enclosurHtml = '';
  4331. foreach ( $enclosurList as $value ) {
  4332. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4333. }
  4334. // print_r($receiptList);
  4335. $data ['rid'] = $rid;
  4336. $data ['enclosurHtml'] = $enclosurHtml;
  4337. $data ['rolename'] = $rolename ['name'];
  4338. $data ['datetij'] = $tijdate ['date'];
  4339. $data ['mothHtml'] = $mothHtml;
  4340. $data ['receiptList'] = $receiptList;
  4341. $data ['receiptApprovalCount'] = count ( $receiptList );
  4342. $data ['status'] = $status;
  4343. $data ['year'] = $year;
  4344. $data ['categoryList'] = $categoryList;
  4345. $data ['staffList'] = $staffList;
  4346. $data ['cid'] = $cid;
  4347. $data ['sid'] = $sid;
  4348. $data ['ap'] = $ap;
  4349. $data ['memu'] = "receipt";
  4350. $data ['staff'] = $this->staff;
  4351. $data ['receiptMemu'] = 'approvalExpenses';
  4352. $data ['verifyId'] = $this->verifyId;
  4353. $data ['executeId'] = $this->executeId;
  4354. $this->render ( "/admin/expensesEdi", $data );
  4355. }
  4356. function expensesDefray() {
  4357. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4358. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4359. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4360. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4361. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4362. if (! empty ( $rid )) {
  4363. Doo::loadModel ( "verify" );
  4364. $verify = new verify ();
  4365. Doo::loadModel ( "receiptDetail" );
  4366. $receiptDetailObj = new receiptDetail ();
  4367. Doo::loadModel ( "itemStatistics" );
  4368. Doo::loadModel ( "statistics" );
  4369. $statistics = new statistics ();
  4370. $itemStatistics = new itemStatistics ();
  4371. Doo::loadModel ( "receipt" );
  4372. $receipt = new receipt ();
  4373. Doo::loadModel ( "loanReceipt" );
  4374. $loanReceipt = new loanReceipt ();
  4375. $receiptDetail = $receipt->getOne ( array (
  4376. 'where' => 'rid=' . $rid . ' and status=2 ',
  4377. 'asArray' => true
  4378. ) );
  4379. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4380. $nsflag = true;
  4381. foreach ( $nslist as $value ) {
  4382. if ($value == $this->staff ['0'] ['sid']) {
  4383. $nsflag = false;
  4384. break;
  4385. }
  4386. }
  4387. // print_r($nslist);die;
  4388. if (empty ( $receiptDetail ) || $nsflag)
  4389. return "/approvalExpenses/pendApproval";
  4390. $verifyDetail = $verify->getOne ( array (
  4391. 'where' => ' vid =' . $receiptDetail ['verify'],
  4392. 'asArray' => true
  4393. ) );
  4394. $verifyString = $verifyDetail ['staff'];
  4395. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4396. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4397. if (empty ( $opinion )) {
  4398. if ($status == 3)
  4399. $opinion = "终止";
  4400. else
  4401. $opinion = "同意支付";
  4402. }
  4403. $nowStaff = 0;
  4404. $nowStaffList = array ();
  4405. if (empty ( $verifyStaff )) {
  4406. // 还需加入是否已经进入角色审批
  4407. if ($verifyDetail [0] [1] == 'ROLE') {
  4408. // print_r($verifyDetail);echo "ddd";
  4409. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4410. foreach ( $vStaffString as $key => $value ) {
  4411. $staffK = explode ( "_", $value );
  4412. if ($staffK [0] != $this->staff [0] ['sid'])
  4413. array_push ( $nowStaffList, $staffK [0] );
  4414. }
  4415. // print_r($verifyDetail);
  4416. // die;
  4417. if (! empty ( $nowStaffList )) {
  4418. $nowStaff = implode ( ',', $nowStaffList );
  4419. $verifyStaff = array (
  4420. $this->staff [0] ['sid'] . "_R" => array (
  4421. 'date' => date ( 'Y-m-d' ),
  4422. 'opinion' => $opinion,
  4423. 'status' => $status,
  4424. 'nextStaff' => $verifyDetail [0] [0],
  4425. 'ROLE' => 1
  4426. )
  4427. );
  4428. } else {
  4429. $nowStaff = $verifyDetail [1] [0];
  4430. $verifyStaff = array (
  4431. $this->staff [0] ['sid'] . "_R" => array (
  4432. 'date' => date ( 'Y-m-d' ),
  4433. 'opinion' => $opinion,
  4434. 'status' => $status,
  4435. 'nextStaff' => $verifyDetail [1] [0]
  4436. )
  4437. );
  4438. }
  4439. } else {
  4440. if ($verifyDetail [1] [1] == 'ROLE') {
  4441. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4442. // echo "dd";
  4443. foreach ( $vStaffString as $key => $value ) {
  4444. $staffK = explode ( "_", $value );
  4445. array_push ( $nowStaffList, $staffK [0] );
  4446. }
  4447. $nowStaff = implode ( ',', $nowStaffList );
  4448. $verifyStaff = array (
  4449. $this->staff [0] ['sid'] => array (
  4450. 'date' => date ( 'Y-m-d' ),
  4451. 'opinion' => $opinion,
  4452. 'status' => $status,
  4453. 'nextStaff' => $verifyDetail [1] [0],
  4454. 'ROLE' => 1
  4455. )
  4456. );
  4457. } else {
  4458. $nowStaff = $verifyDetail [1] [0];
  4459. $verifyStaff = array (
  4460. $this->staff [0] ['sid'] => array (
  4461. 'date' => date ( 'Y-m-d' ),
  4462. 'opinion' => $opinion,
  4463. 'status' => $status,
  4464. 'nextStaff' => $verifyDetail [1] [0]
  4465. )
  4466. );
  4467. }
  4468. }
  4469. if ($status == 3)
  4470. $verifyStaff = array (
  4471. 'final' => $status,
  4472. $this->staff [0] ['sid'] => array (
  4473. 'date' => date ( 'Y-m-d' ),
  4474. 'opinion' => $opinion,
  4475. 'status' => $status
  4476. )
  4477. );
  4478. $vStaffString = json_encode ( $verifyStaff );
  4479. $receipt->nowStaff = $nowStaff;
  4480. $receipt->verifyStaff = $vStaffString;
  4481. $loanReceipt->nowStaff = $nowStaff;
  4482. $loanReceipt->verifyStaff = $vStaffString;
  4483. } else {
  4484. $VS = end ( $verifyStaff );
  4485. // 非角色审批
  4486. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4487. $nextStaff = 0;
  4488. $roleSTF = false;
  4489. foreach ( $verifyDetail as $key => $value ) {
  4490. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4491. if (isset ( $verifyDetail [$key + 1] )) {
  4492. $nextStaff = $verifyDetail [$key + 1] [0];
  4493. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4494. $roleSTF = true;
  4495. }
  4496. break;
  4497. }
  4498. }
  4499. if (! $roleSTF) {
  4500. $nowStaff = $nextStaff;
  4501. $verifyStaff [$this->staff [0] ['sid']] = array (
  4502. 'date' => date ( 'Y-m-d' ),
  4503. 'opinion' => $opinion,
  4504. 'status' => $status,
  4505. 'nextStaff' => $nextStaff
  4506. );
  4507. } else {
  4508. // 获取角色下的所有用户ID
  4509. $nowStaffList = array ();
  4510. foreach ( $verifyDetail as $vfk ) {
  4511. if ($vfk [1] == 'ROLE') {
  4512. $vStaffString = json_decode ( $vfk [3] );
  4513. foreach ( $vStaffString as $key => $value ) {
  4514. $staffK = explode ( "_", $value );
  4515. array_push ( $nowStaffList, $staffK [0] );
  4516. }
  4517. }
  4518. }
  4519. $nowStaff = implode ( ',', $nowStaffList );
  4520. $verifyStaff [$this->staff [0] ['sid']] = array (
  4521. 'date' => date ( 'Y-m-d' ),
  4522. 'opinion' => $opinion,
  4523. 'status' => $status,
  4524. 'nextStaff' => $nextStaff,
  4525. 'ROLE' => 0
  4526. );
  4527. }
  4528. if ($status == 3) {
  4529. $verifyStaff ['final'] = $status;
  4530. $verifyStaff [$this->staff [0] ['sid']] = array (
  4531. 'date' => date ( 'Y-m-d' ),
  4532. 'opinion' => $opinion,
  4533. 'status' => $status
  4534. );
  4535. }
  4536. $vStaffString = json_encode ( $verifyStaff );
  4537. $receipt->nowStaff = $nowStaff;
  4538. $receipt->verifyStaff = $vStaffString;
  4539. $loanReceipt->nowStaff = $nowStaff;
  4540. $loanReceipt->verifyStaff = $vStaffString;
  4541. }
  4542. // 角色审批
  4543. if (isset ( $VS ['ROLE'] )) {
  4544. // 找出角色人 当前审批角色组
  4545. $verifyJSStaff = array ();
  4546. $nowStaffList2 = array ();
  4547. foreach ( $verifyDetail as $key => $value ) {
  4548. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4549. $verifyJSStaff = json_decode ( $value [3] );
  4550. foreach ( $verifyJSStaff as $m ) {
  4551. $staffK = explode ( "_", $m );
  4552. array_push ( $nowStaffList2, $staffK [0] );
  4553. }
  4554. // print_r($nowStaffList2);
  4555. }
  4556. }
  4557. $RoleVerifyStaff = array ();
  4558. foreach ( $verifyStaff as $key => $value ) {
  4559. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4560. foreach ( $nowStaffList2 as $m ) {
  4561. if ($key == $m . "_R")
  4562. $RoleVerifyStaff [$key] = $value;
  4563. }
  4564. }
  4565. }
  4566. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4567. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4568. // 下一个审批人ID
  4569. $nextStaff = 0;
  4570. $falg = false;
  4571. foreach ( $verifyDetail as $key => $value ) {
  4572. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4573. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4574. $falg = true;
  4575. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4576. $nowStaffList = array ();
  4577. foreach ( $vStaffString as $v ) {
  4578. $staffK = explode ( "_", $v );
  4579. array_push ( $nowStaffList, $staffK [0] );
  4580. }
  4581. $nowStaff = implode ( ',', $nowStaffList );
  4582. $nextStaff = $verifyDetail [$key + 1] [0];
  4583. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4584. $nextStaff = $verifyDetail [$key + 1] [0];
  4585. $nowStaff = $nextStaff;
  4586. } else
  4587. $nowStaff = '';
  4588. break;
  4589. }
  4590. }
  4591. if ($falg)
  4592. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4593. 'date' => date ( 'Y-m-d' ),
  4594. 'opinion' => $opinion,
  4595. 'status' => $status,
  4596. 'nextStaff' => $nextStaff,
  4597. 'ROLE' => 1
  4598. );
  4599. else
  4600. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4601. 'date' => date ( 'Y-m-d' ),
  4602. 'opinion' => $opinion,
  4603. 'status' => $status,
  4604. 'nextStaff' => $nextStaff
  4605. );
  4606. // print_r($verifyStaff);
  4607. // echo $nowStaff;die;
  4608. } else { // 进入下一个角色或者审批人
  4609. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4610. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4611. 'date' => date ( 'Y-m-d' ),
  4612. 'opinion' => $opinion,
  4613. 'status' => $status,
  4614. 'nextStaff' => $VS ['nextStaff'],
  4615. 'ROLE' => 1
  4616. );
  4617. }
  4618. if ($status == 3) {
  4619. $verifyStaff ['final'] = $status;
  4620. $verifyStaff [$this->staff [0] ['sid']] = array (
  4621. 'date' => date ( 'Y-m-d' ),
  4622. 'opinion' => $opinion,
  4623. 'status' => $status
  4624. );
  4625. }
  4626. $vStaffString = json_encode ( $verifyStaff );
  4627. $receipt->verifyStaff = $vStaffString;
  4628. $receipt->nowStaff = $nowStaff;
  4629. $loanReceipt->nowStaff = $nowStaff;
  4630. $loanReceipt->verifyStaff = $vStaffString;
  4631. }
  4632. // print_r($verifyStaff);die;
  4633. }
  4634. $roleKey = 0;
  4635. $roleId = 0;
  4636. $verifyDetailCopy = array ();
  4637. foreach ( $verifyDetail as $k => $v ) {
  4638. if ($v [1] == 'ROLE') {
  4639. $roleId = $v [0];
  4640. $roleVerify = json_decode ( $v [3], true );
  4641. $roleKey = $k;
  4642. $roleArray = array ();
  4643. foreach ( $roleVerify as $o => $p ) {
  4644. $staffID = explode ( '_', $p );
  4645. $exp = array (
  4646. 0 => $staffID [0],
  4647. 1 => $staffID [1]
  4648. );
  4649. array_push ( $roleArray, $exp );
  4650. }
  4651. $verifyDetailCopy [$v [0]] = $roleArray;
  4652. }
  4653. }
  4654. // print_r($verifyDetail);
  4655. foreach ( $verifyDetailCopy as $k => $v ) {
  4656. foreach ( $verifyDetail as $m => $n ) {
  4657. if ($n [0] == $k) {
  4658. array_splice ( $verifyDetail, $m, 1, $v );
  4659. }
  4660. }
  4661. }
  4662. // 审批日志
  4663. if (! isset ( $verifyStaff ['final'] )) {
  4664. Doo::loadModel ( "receiptLog" );
  4665. $receiptLog = new receiptLog ();
  4666. if (! empty ( $roleId )) {
  4667. Doo::loadModel ( "role" );
  4668. $role = new role ();
  4669. $roleInfo = $role->getOne ( array (
  4670. 'where' => 'rid=' . $roleId,
  4671. 'asArray' => true
  4672. ) );
  4673. $receiptLog->rolename = $roleInfo ['name'];
  4674. }
  4675. $receiptLog->username = $this->staff [0] ['username'];
  4676. $receiptLog->uid = $this->staff [0] ['sid'];
  4677. $receiptLog->date = date ( "Y-m-d" );
  4678. $receiptLog->opinion = $opinion;
  4679. $receiptLog->img = $this->staff [0] ['avatar'];
  4680. $receiptLog->status = 1;
  4681. $receiptLog->rid = $rid;
  4682. $receiptLog->insert ();
  4683. }
  4684. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4685. $receipt->status = 3;
  4686. $receipt->verifyBreakup = $verifyString;
  4687. $receiptDetailObj->status = 3;
  4688. $receiptDetailObj->update ( array (
  4689. 'where' => 'rid=' . $rid
  4690. ) );
  4691. // 微信企业号通知
  4692. $this->setWXMsg ( $rid, 3 );
  4693. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4694. $receipt->status = 6;
  4695. $receipt->pastDate = date ( "Y-m-d" );
  4696. $receipt->isBK = 1;
  4697. $loanReceipt->verifyBreakup = $verifyString;
  4698. $loanReceipt->status = 1;
  4699. $loanReceipt->pastDate = date ( "Y-m-d" );
  4700. //生成流水后 不更新汇款金额
  4701. Doo::loadModel ( 'wasteBook' );
  4702. $wasteBook = new wasteBook ();
  4703. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4704. if (empty($wbDetail)){
  4705. $loanReceipt->amount = $receiptDetail ['amount'];
  4706. }
  4707. $loanReceipt->update ( array (
  4708. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4709. ) );
  4710. // 微信企业号通知
  4711. $this->setWXMsg ( $rid, 1 );
  4712. }
  4713. $receipt->amount = $receiptDetail['sum'];
  4714. $receipt->update ( array (
  4715. 'where' => ' rid = ' . $rid
  4716. ) );
  4717. // 进入下一条审批费用新加需求
  4718. $vidList = array ();
  4719. $verifyDetail = $verify->find ( array (
  4720. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4721. 'asArray' => true
  4722. ) );
  4723. foreach ( $verifyDetail as $key => $value ) {
  4724. array_push ( $vidList, $value ['vid'] );
  4725. }
  4726. $vid = implode ( ",", $vidList );
  4727. if (empty ( $verifyDetail ))
  4728. $vid = 0;
  4729. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4730. $receipt = new receipt ();
  4731. $rd = $receipt->getOne ( array (
  4732. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4733. 'asc' => 'rid',
  4734. 'asArray' => true
  4735. ) );
  4736. if (empty ( $rd )) {
  4737. return '/approvalExpenses/pendApproval';
  4738. }
  4739. if ($rd ['Rtype'] == 1) {
  4740. if ($rd ['isBK'] == 1) {
  4741. return '/receiptburEdi/' . $rd ['rid'];
  4742. } else {
  4743. return '/expensesEdi/' . $rd ['rid'];
  4744. }
  4745. } elseif ($rd ['Rtype'] == 2) {
  4746. return '/remitApproval/' . $rd ['rid'];
  4747. } else {
  4748. return '/receiptburEdi/' . $rd ['rid'];
  4749. }
  4750. // return "/approvalExpenses/pendApproval";
  4751. }
  4752. }
  4753. function ajaxExamineExe() {
  4754. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4755. Doo::loadModel ( 'receipt' );
  4756. $receipt = new receipt ();
  4757. Doo::loadClass ( 'XDeode' );
  4758. $XDeode = new XDeode ( 5 );
  4759. if (! empty ( $rid )) {
  4760. $rLRes = $receipt->find ( array (
  4761. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4762. 'asArray' => true
  4763. ) );
  4764. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4765. echo json_encode ( array (
  4766. 'status' => 1,
  4767. 'receipt' => $rLRes [0]
  4768. ) );
  4769. die ();
  4770. }
  4771. echo json_encode ( array (
  4772. 'status' => 0,
  4773. 'receipt' => array ()
  4774. ) );
  4775. die ();
  4776. }
  4777. function implement() {
  4778. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4779. Doo::loadClass ( 'XDeode' );
  4780. $XDeode = new XDeode ( 5 );
  4781. Doo::loadModel ( 'receipt' );
  4782. $receipt = new receipt ();
  4783. Doo::loadModel ( 'L_category' );
  4784. $Lcategory = new L_category ();
  4785. Doo::loadModel ( 'verify' );
  4786. $verify = new verify ();
  4787. Doo::loadModel ( 'staff' );
  4788. $staff = new staff ();
  4789. Doo::loadModel ( "execute" );
  4790. $execute = new execute ();
  4791. $rid = $XDeode->decode ( $rid );
  4792. $receiptList = $receipt->find ( array (
  4793. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4794. 'desc' => 'rid',
  4795. 'asArray' => true
  4796. ) );
  4797. Doo::loadModel ( 'loanReceipt' );
  4798. $loanReceipt = new loanReceipt ();
  4799. // print_r($receiptList);
  4800. $loanList = array ();
  4801. if (! isset ( $receiptList ))
  4802. $loanList = $loanReceipt->find ( array (
  4803. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4804. 'desc' => 'rid',
  4805. 'asArray' => true
  4806. ) );
  4807. $Locate = 0;
  4808. $roleId = 0;
  4809. $button = 0;
  4810. foreach ( $loanList as $key => $value ) {
  4811. $loanList [$key] ['Locate'] = $Locate;
  4812. $Locate ++;
  4813. $loanList [$key] ['reviseDetail'] = array ();
  4814. if (! empty ( $value ['reviseDetail'] ))
  4815. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4816. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4817. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4818. $categoryDetil = $Lcategory->getOne ( array (
  4819. 'where' => 'cid=' . $value ['cid'],
  4820. 'asArray' => true
  4821. ) );
  4822. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4823. // 检测编辑状态
  4824. $verifyList = $verify->getOne ( array (
  4825. 'where' => 'vid=' . $value ['verify'],
  4826. 'asArray' => true
  4827. ) );
  4828. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4829. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4830. Doo::loadModel ( 'role' );
  4831. $role = new role ();
  4832. $flag = true;
  4833. $roleKey = 0;
  4834. $endStaffArray = array ();
  4835. $roleArrayCopy = array ();
  4836. foreach ( $verifyList as $k => $v ) {
  4837. // init verifyStaff
  4838. if ($v [1] == 'ROLE') {
  4839. if (! empty ( $verifyStaff )) {
  4840. $endStaffArray = end ( $verifyStaff );
  4841. // if ($v[0]==$endStaffArray['nextStaff']){
  4842. // $roleId=$v[0];
  4843. // }
  4844. }
  4845. $roleVerify = json_decode ( $v [3], true );
  4846. $roleKey = $k;
  4847. $roleArray = array ();
  4848. $rolename = $role->getOne ( array (
  4849. 'where' => 'rid=' . $v [0],
  4850. 'asArray' => true
  4851. ) );
  4852. foreach ( $roleVerify as $o => $p ) {
  4853. $staffID = explode ( '_', $p );
  4854. $staffInfo = $staff->getOne ( array (
  4855. 'where' => 'sid=' . $staffID [0],
  4856. 'asArray' => true
  4857. ) );
  4858. // print_r($staffID);
  4859. $exp = array (
  4860. 0 => $staffInfo ['sid'],
  4861. 1 => $staffID [1],
  4862. 2 => $staffInfo ['avatar'],
  4863. 'date' => '',
  4864. 'date' => '',
  4865. 'opinion' => '',
  4866. 'status' => '',
  4867. 'rolename' => $rolename ['name']
  4868. );
  4869. array_push ( $roleArray, $exp );
  4870. }
  4871. $roleArrayCopy [$v [0]] = $roleArray;
  4872. // $verifyList[$k]['roleArray']=$roleArray;
  4873. }
  4874. $verifyList [$k] ['date'] = "";
  4875. $verifyList [$k] ['opinion'] = "";
  4876. $verifyList [$k] ['status'] = "";
  4877. if (empty ( $verifyStaff )) {
  4878. $verifyList [$k] ['date'] = "";
  4879. $verifyList [$k] ['opinion'] = "";
  4880. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4881. $verifyList [$k] ['status'] = 4;
  4882. $flag = false;
  4883. }
  4884. } else {
  4885. foreach ( $verifyStaff as $m => $u ) {
  4886. if ($v [0] == $m) {
  4887. $verifyList [$k] ['date'] = $u ['date'];
  4888. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4889. $verifyList [$k] ['status'] = $u ['status'];
  4890. $flag = false;
  4891. break;
  4892. }
  4893. }
  4894. $endStaffArray = end ( $verifyStaff );
  4895. if (isset ( $endStaffArray ['ROLE'] )) {
  4896. } else {
  4897. // $endKey=key($verifyStaff);
  4898. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4899. // $button=4;
  4900. // $verifyList[$k]['status']=4;
  4901. // }
  4902. }
  4903. }
  4904. }
  4905. $rolename ['name'] = '';
  4906. if (! empty ( $roleId )) {
  4907. Doo::loadModel ( 'role' );
  4908. $role = new role ();
  4909. $rolename = $role->getOne ( array (
  4910. 'where' => 'rid=' . $roleId,
  4911. 'asArray' => true
  4912. ) );
  4913. }
  4914. if (! empty ( $verifyStaff ))
  4915. $endStaffArray = end ( $verifyStaff );
  4916. $KOP = false;
  4917. foreach ( $roleArrayCopy as $P => $A ) {
  4918. foreach ( $A as $MKI => $AVL ) {
  4919. if (! empty ( $verifyStaff )) {
  4920. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4921. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4922. $button = 4;
  4923. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4924. }
  4925. foreach ( $verifyStaff as $m => $u ) {
  4926. $AVLFK = $AVL [0] . '_R';
  4927. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4928. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4929. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4930. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4931. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4932. break;
  4933. }
  4934. }
  4935. } else {
  4936. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4937. $button = 4;
  4938. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4939. }
  4940. }
  4941. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4942. $KOP = true;
  4943. }
  4944. }
  4945. foreach ( $roleArrayCopy as $k => $v ) {
  4946. foreach ( $verifyList as $m => $n ) {
  4947. if ($n [0] == $k) {
  4948. array_splice ( $verifyList, $m, 1, $v );
  4949. }
  4950. }
  4951. }
  4952. $loanList [$key] ['verifyList'] = $verifyList;
  4953. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4954. 'where' => 'sid=' . $value ['staff'],
  4955. 'asArray' => true
  4956. ) );
  4957. }
  4958. $data ['loanList'] = $loanList;
  4959. $Locate = 0;
  4960. $roleId = 0;
  4961. $button = 0;
  4962. Doo::loadClass ( 'XDeode' );
  4963. $XDeode = new XDeode ( 5 );
  4964. foreach ( $receiptList as $key => $value ) {
  4965. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4966. $button2 = 0;
  4967. $receiptList [$key] ['Locate'] = $Locate;
  4968. $Locate ++;
  4969. $receiptList [$key] ['reviseDetail'] = array ();
  4970. if (! empty ( $value ['reviseDetail'] ))
  4971. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4972. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4973. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4974. $categoryDetil = $Lcategory->getOne ( array (
  4975. 'where' => 'cid=' . $value ['cid'],
  4976. 'asArray' => true
  4977. ) );
  4978. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4979. $executeList = json_decode ( $value ['executeCopy'], true );
  4980. $executeStaff = array ();
  4981. if (! empty ( $value ['executeStaff'] ))
  4982. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4983. if (isset ( $executeList )) {
  4984. foreach ( $executeList as $op => $lo ) {
  4985. $executeList [$op] ['date'] = "";
  4986. $executeList [$op] ['opinion'] = "";
  4987. $executeList [$op] ['status'] = "";
  4988. foreach ( $executeStaff as $m => $u ) {
  4989. if ($lo [0] == $m) {
  4990. $executeList [$op] ['date'] = $u ['date'];
  4991. $executeList [$op] ['opinion'] = $u ['opinion'];
  4992. $executeList [$op] ['status'] = $u ['status'];
  4993. break;
  4994. }
  4995. }
  4996. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  4997. $button2 = 1;
  4998. $executeList [$op] ['status'] = 4;
  4999. }
  5000. }
  5001. }
  5002. // 检测编辑状态
  5003. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5004. $verifyList ['staff'] = $value ['verifyBreakup'];
  5005. } else
  5006. $verifyList = $verify->getOne ( array (
  5007. 'where' => 'vid=' . $value ['verify'],
  5008. 'asArray' => true
  5009. ) );
  5010. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5011. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5012. Doo::loadModel ( 'role' );
  5013. $role = new role ();
  5014. if ($verifyList == NULL)
  5015. $verifyList = array ();
  5016. $flag = true;
  5017. $roleKey = 0;
  5018. $endStaffArray = array ();
  5019. $roleArrayCopy = array ();
  5020. foreach ( $verifyList as $k => $v ) {
  5021. // init verifyStaff
  5022. if ($v [1] == 'ROLE') {
  5023. if (! empty ( $verifyStaff )) {
  5024. $endStaffArray = end ( $verifyStaff );
  5025. // if ($v[0]==$endStaffArray['nextStaff']){
  5026. // $roleId=$v[0];
  5027. // }
  5028. }
  5029. $roleVerify = json_decode ( $v [3], true );
  5030. $roleKey = $k;
  5031. $roleArray = array ();
  5032. $rolename = $role->getOne ( array (
  5033. 'where' => 'rid=' . $v [0],
  5034. 'asArray' => true
  5035. ) );
  5036. foreach ( $roleVerify as $o => $p ) {
  5037. $staffID = explode ( '_', $p );
  5038. $staffInfo = $staff->getOne ( array (
  5039. 'where' => 'sid=' . $staffID [0],
  5040. 'asArray' => true
  5041. ) );
  5042. // print_r($staffID);
  5043. $exp = array (
  5044. 0 => $staffInfo ['sid'],
  5045. 1 => $staffID [1],
  5046. 2 => $staffInfo ['avatar'],
  5047. 'date' => '',
  5048. 'date' => '',
  5049. 'opinion' => '',
  5050. 'status' => '',
  5051. 'rolename' => $rolename ['name']
  5052. );
  5053. array_push ( $roleArray, $exp );
  5054. }
  5055. $roleArrayCopy [$v [0]] = $roleArray;
  5056. // $verifyList[$k]['roleArray']=$roleArray;
  5057. }
  5058. $verifyList [$k] ['date'] = "";
  5059. $verifyList [$k] ['opinion'] = "";
  5060. $verifyList [$k] ['status'] = "";
  5061. if (empty ( $verifyStaff )) {
  5062. $verifyList [$k] ['date'] = "";
  5063. $verifyList [$k] ['opinion'] = "";
  5064. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5065. $verifyList [$k] ['status'] = 4;
  5066. $flag = false;
  5067. }
  5068. } else {
  5069. foreach ( $verifyStaff as $m => $u ) {
  5070. if ($v [0] == $m) {
  5071. $verifyList [$k] ['date'] = $u ['date'];
  5072. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5073. $verifyList [$k] ['status'] = $u ['status'];
  5074. $flag = false;
  5075. break;
  5076. }
  5077. }
  5078. $endStaffArray = end ( $verifyStaff );
  5079. if (isset ( $endStaffArray ['ROLE'] )) {
  5080. } else {
  5081. // $endKey=key($verifyStaff);
  5082. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5083. // $button=4;
  5084. // $verifyList[$k]['status']=4;
  5085. // }
  5086. }
  5087. }
  5088. }
  5089. $rolename ['name'] = '';
  5090. if (! empty ( $roleId )) {
  5091. Doo::loadModel ( 'role' );
  5092. $role = new role ();
  5093. $rolename = $role->getOne ( array (
  5094. 'where' => 'rid=' . $roleId,
  5095. 'asArray' => true
  5096. ) );
  5097. }
  5098. if (! empty ( $verifyStaff ))
  5099. $endStaffArray = end ( $verifyStaff );
  5100. $KOP = false;
  5101. foreach ( $roleArrayCopy as $P => $A ) {
  5102. foreach ( $A as $MKI => $AVL ) {
  5103. if (! empty ( $verifyStaff )) {
  5104. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5105. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5106. $button = 4;
  5107. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5108. }
  5109. foreach ( $verifyStaff as $m => $u ) {
  5110. $AVLFK = $AVL [0] . '_R';
  5111. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5112. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5113. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5114. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5115. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5116. break;
  5117. }
  5118. }
  5119. } else {
  5120. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5121. $button = 4;
  5122. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5123. }
  5124. }
  5125. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5126. $KOP = true;
  5127. }
  5128. }
  5129. foreach ( $roleArrayCopy as $k => $v ) {
  5130. foreach ( $verifyList as $m => $n ) {
  5131. if ($n [0] == $k) {
  5132. array_splice ( $verifyList, $m, 1, $v );
  5133. }
  5134. }
  5135. }
  5136. $receiptList [$key] ['verifyList'] = $verifyList;
  5137. $receiptList [$key] ['executeList'] = $executeList;
  5138. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5139. 'where' => 'sid=' . $value ['staff'],
  5140. 'asArray' => true
  5141. ) );
  5142. $receiptList [$key] ['button2'] = $button2;
  5143. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5144. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5145. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5146. $receiptList [$key] ['relust'] = $relust;
  5147. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5148. }
  5149. // 是否写入过流水
  5150. $accountType = 0;
  5151. if ($receiptList [0] ['Rtype'] == 0) {
  5152. $accountType = 3;
  5153. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5154. if (!empty($receiptList [0]['accountItem']) )
  5155. $accountType = 2;
  5156. else
  5157. $accountType = 1;
  5158. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5159. $accountType = 4;
  5160. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5161. $accountType = 12;
  5162. }
  5163. Doo::loadModel ( 'wasteBook' );
  5164. $wasteBook = new wasteBook ();
  5165. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5166. $data ['wbDetail'] = $wbDetail;
  5167. $wbDetailLoan=array();
  5168. if ($accountType==2){
  5169. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5170. }
  5171. $data ['wbDetailLoan'] = $wbDetailLoan;
  5172. //print_r($wbDetail);
  5173. $data ['receiptList'] = $receiptList;
  5174. $data ['memu'] = "receipt";
  5175. $data ['staff'] = $this->staff;
  5176. $data ['receiptMemu'] = 'implement';
  5177. $data ['verifyId'] = $this->verifyId;
  5178. $data ['executeId'] = $this->executeId;
  5179. $this->render ( "/admin/implement", $data );
  5180. }
  5181. function implementDo() {
  5182. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5183. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5184. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5185. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5186. // $ab = '';
  5187. // if ($accountBank == 'CGBDeposit')
  5188. // $ab = '纵横广发';
  5189. // elseif ($accountBank == 'ICBCDeposit')
  5190. // $ab = '纵横工行';
  5191. // elseif ($accountBank == 'HUADeposit')
  5192. // $ab = '华润银行';
  5193. // elseif ($accountBank == 'PersonalDeposit')
  5194. // $ab = '个人广发';
  5195. // if (empty ( $ab ))
  5196. // die ( 'illegal request--22' );
  5197. if (! empty ( $rid )) {
  5198. Doo::loadModel ( 'receipt' );
  5199. $receipt = new receipt ();
  5200. // Doo::loadClass ( 'XDeode' );
  5201. // $XDeode = new XDeode ( 5 );
  5202. // $rinfo = $receipt->getOne ( array (
  5203. // 'where' => 'rid=' . $rid,
  5204. // 'asArray' => true
  5205. // ) );
  5206. $rinfo = $receipt->getReceiptByRid ( $rid );
  5207. // $accountType = '';
  5208. // if ($rinfo ['Rtype'] == 1) {
  5209. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5210. // $accountType = 2;
  5211. // else
  5212. // $accountType = 1;
  5213. // } elseif ($rinfo ['Rtype'] == 2) {
  5214. // $accountType = 4;
  5215. // } elseif ($rinfo ['Rtype'] == 0)
  5216. // $accountType = 3;
  5217. // if (empty ( $accountType ))
  5218. // die ( 'illegal request' );
  5219. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5220. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5221. if (empty ( $executeStaff )) {
  5222. $executeStaff = array (
  5223. $this->staff [0] ['sid'] => array (
  5224. 'date' => date ( 'Y-m-d' ),
  5225. 'opinion' => $implementOpinions,
  5226. 'status' => 1
  5227. )
  5228. );
  5229. } else {
  5230. $executeStaff [$this->staff [0] ['sid']] = array (
  5231. 'date' => date ( 'Y-m-d' ),
  5232. 'opinion' => $implementOpinions,
  5233. 'status' => 1
  5234. );
  5235. }
  5236. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5237. $receipt->executeStaff = json_encode ( $executeStaff );
  5238. $receipt->status = 8;
  5239. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5240. $receipt->status = 9;
  5241. if ($rinfo ['status'] == 6) {
  5242. $receipt->loanDate = date ( "Y-m-d" );
  5243. }
  5244. $receipt->executeDate = date ( "Y-m-d" );
  5245. } else {
  5246. $receipt->executeStaff = json_encode ( $executeStaff );
  5247. }
  5248. //$receipt->amount = $amount;
  5249. $receipt->update ( array (
  5250. 'where' => 'rid=' . $rid
  5251. ) );
  5252. // 公司流水记录
  5253. // Doo::loadModel ( 'wasteBook' );
  5254. // $wasteBook = new wasteBook ();
  5255. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5256. // // 银行
  5257. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5258. // $item = array (
  5259. // 'dataID' => $rid,
  5260. // 'expensesType' => 2,
  5261. // 'accountType' => $accountType,
  5262. // 'accountPriceShow' => $amount,
  5263. // 'accountPrice' => - $amount,
  5264. // 'accountBank' => $accountBank,
  5265. // 'category' => $rinfo ['category'] [0] ['title'],
  5266. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5267. // 'name' => $rinfo ['staffDetail'] ['username'],
  5268. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5269. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5270. // );
  5271. // $wasteBook->setAccountBookStatistics ( $item );
  5272. // }
  5273. }
  5274. //$ridKey = $XDeode->encode ( $rid );
  5275. return "/hisImplement";
  5276. // return "/implement/" . $ridKey . ".html";
  5277. }
  5278. function receiptburEdi() {
  5279. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5280. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5281. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5282. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5283. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5284. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5285. if (empty ( $status ))
  5286. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5287. $vidList = array ();
  5288. $button = 0;
  5289. Doo::loadModel ( 'verify' );
  5290. Doo::loadModel ( 'receipt' );
  5291. Doo::loadModel ( 'staff' );
  5292. $staff = new staff ();
  5293. $receipt = new receipt ();
  5294. $verify = new verify ();
  5295. Doo::loadModel ( 'L_category' );
  5296. $Lcategory = new L_category ();
  5297. Doo::loadModel ( 'enclosur' );
  5298. $enclosur = new enclosur ();
  5299. Doo::loadModel ( 'loanReceipt' );
  5300. $loanReceipt = new loanReceipt ();
  5301. // user verify ID
  5302. $verifyDetail = $verify->find ( array (
  5303. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5304. 'asArray' => true
  5305. ) );
  5306. foreach ( $verifyDetail as $key => $value ) {
  5307. array_push ( $vidList, $value ['vid'] );
  5308. }
  5309. $vid = implode ( ",", $vidList );
  5310. if (empty ( $verifyDetail ))
  5311. $vid = 0;
  5312. $categoryList = $Lcategory->find ( array (
  5313. 'asArray' => true
  5314. ) );
  5315. $staffList = $staff->find ( array (
  5316. 'where' => 'cid=' . $cid,
  5317. 'asArray' => true
  5318. ) );
  5319. $ap = "";
  5320. if ($status == 4) {
  5321. $ap = 4;
  5322. $status = 2;
  5323. }
  5324. // get Receipt By verifyID status 2
  5325. $receiptList = $receipt->find ( array (
  5326. 'where' => 'rid =' . $rid . ' and status=2',
  5327. 'desc' => 'rid',
  5328. 'asArray' => true
  5329. ) );
  5330. if (empty ( $receiptList )) {
  5331. die ( 'illegal request' );
  5332. }
  5333. $loanList = $loanReceipt->find ( array (
  5334. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5335. 'desc' => 'rid',
  5336. 'asArray' => true
  5337. ) );
  5338. $data ['explanation'] = '';
  5339. if (! empty ( $loanList ))
  5340. $data ['explanation'] = $loanList [0] ['explanation'];
  5341. $Locate = 0;
  5342. $roleId = 0;
  5343. $button = 0;
  5344. foreach ( $loanList as $key => $value ) {
  5345. $loanList [$key] ['Locate'] = $Locate;
  5346. $Locate ++;
  5347. $loanList [$key] ['reviseDetail'] = array ();
  5348. if (! empty ( $value ['reviseDetail'] ))
  5349. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5350. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5351. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5352. $categoryDetil = $Lcategory->getOne ( array (
  5353. 'where' => 'cid=' . $value ['cid'],
  5354. 'asArray' => true
  5355. ) );
  5356. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5357. // 检测编辑状态
  5358. $verifyList = $verify->getOne ( array (
  5359. 'where' => 'vid=' . $value ['verify'],
  5360. 'asArray' => true
  5361. ) );
  5362. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5363. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5364. Doo::loadModel ( 'role' );
  5365. $role = new role ();
  5366. $flag = true;
  5367. $roleKey = 0;
  5368. $endStaffArray = array ();
  5369. $roleArrayCopy = array ();
  5370. foreach ( $verifyList as $k => $v ) {
  5371. // init verifyStaff
  5372. if ($v [1] == 'ROLE') {
  5373. if (! empty ( $verifyStaff )) {
  5374. $endStaffArray = end ( $verifyStaff );
  5375. }
  5376. $roleVerify = json_decode ( $v [3], true );
  5377. $roleKey = $k;
  5378. $roleArray = array ();
  5379. $rolename = $role->getOne ( array (
  5380. 'where' => 'rid=' . $v [0],
  5381. 'asArray' => true
  5382. ) );
  5383. foreach ( $roleVerify as $o => $p ) {
  5384. $staffID = explode ( '_', $p );
  5385. $staffInfo = $staff->getOne ( array (
  5386. 'where' => 'sid=' . $staffID [0],
  5387. 'asArray' => true
  5388. ) );
  5389. // print_r($staffID);
  5390. $exp = array (
  5391. 0 => $staffInfo ['sid'],
  5392. 1 => $staffID [1],
  5393. 2 => $staffInfo ['avatar'],
  5394. 'date' => '',
  5395. 'date' => '',
  5396. 'opinion' => '',
  5397. 'status' => '',
  5398. 'rolename' => $rolename ['name']
  5399. );
  5400. array_push ( $roleArray, $exp );
  5401. }
  5402. $roleArrayCopy [$v [0]] = $roleArray;
  5403. // $verifyList[$k]['roleArray']=$roleArray;
  5404. }
  5405. $verifyList [$k] ['date'] = "";
  5406. $verifyList [$k] ['opinion'] = "";
  5407. $verifyList [$k] ['status'] = "";
  5408. if (empty ( $verifyStaff )) {
  5409. $verifyList [$k] ['date'] = "";
  5410. $verifyList [$k] ['opinion'] = "";
  5411. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5412. $verifyList [$k] ['status'] = 4;
  5413. $flag = false;
  5414. }
  5415. } else {
  5416. foreach ( $verifyStaff as $m => $u ) {
  5417. if ($v [0] == $m) {
  5418. $verifyList [$k] ['date'] = $u ['date'];
  5419. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5420. $verifyList [$k] ['status'] = $u ['status'];
  5421. $flag = false;
  5422. break;
  5423. }
  5424. }
  5425. $endStaffArray = end ( $verifyStaff );
  5426. if (isset ( $endStaffArray ['ROLE'] )) {
  5427. } else {
  5428. }
  5429. }
  5430. }
  5431. $rolename ['name'] = '';
  5432. if (! empty ( $roleId )) {
  5433. Doo::loadModel ( 'role' );
  5434. $role = new role ();
  5435. $rolename = $role->getOne ( array (
  5436. 'where' => 'rid=' . $roleId,
  5437. 'asArray' => true
  5438. ) );
  5439. }
  5440. if (! empty ( $verifyStaff ))
  5441. $endStaffArray = end ( $verifyStaff );
  5442. $KOP = false;
  5443. foreach ( $roleArrayCopy as $P => $A ) {
  5444. foreach ( $A as $MKI => $AVL ) {
  5445. if (! empty ( $verifyStaff )) {
  5446. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5447. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5448. $button = 4;
  5449. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5450. }
  5451. foreach ( $verifyStaff as $m => $u ) {
  5452. $AVLFK = $AVL [0] . '_R';
  5453. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5454. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5455. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5456. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5457. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5458. break;
  5459. }
  5460. }
  5461. } else {
  5462. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5463. $button = 4;
  5464. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5465. }
  5466. }
  5467. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5468. $KOP = true;
  5469. }
  5470. }
  5471. foreach ( $roleArrayCopy as $k => $v ) {
  5472. foreach ( $verifyList as $m => $n ) {
  5473. if ($n [0] == $k) {
  5474. array_splice ( $verifyList, $m, 1, $v );
  5475. }
  5476. }
  5477. }
  5478. $loanList [$key] ['verifyList'] = $verifyList;
  5479. }
  5480. $htmlLoan = '';
  5481. $data ['loanReceiptDate'] = '';
  5482. if (isset ( $loanList [0] )) {
  5483. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5484. if ($value ['status'] == 1)
  5485. $htmlLoan .= '<li class="done" >';
  5486. elseif ($value ['status'] == 3)
  5487. $htmlLoan .= '<li class="undone" >';
  5488. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5489. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5490. if (isset ( $value ['rolename'] ))
  5491. $htmlLoan .= $value ['rolename'];
  5492. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5493. }
  5494. $data ['loanDate'] = $loanList [0] ['date'];
  5495. } else {
  5496. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5497. }
  5498. $data ['htmlLoan'] = $htmlLoan;
  5499. // $data ['LoanReceipt']=$loanList[0];
  5500. // print_r($loanList);
  5501. $Locate = 0;
  5502. $roleId = 0;
  5503. $button = 0;
  5504. if ($ap == 4)
  5505. $status = 4;
  5506. Doo::loadClass ( 'XDeode' );
  5507. $XDeode = new XDeode ( 5 );
  5508. foreach ( $receiptList as $key => $value ) {
  5509. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5510. $receiptList [$key] ['Locate'] = $Locate;
  5511. $Locate ++;
  5512. $receiptList [$key] ['reviseDetail'] = array ();
  5513. // 调整金额 代码调整
  5514. if (! empty ( $value ['reviseDetail'] )) {
  5515. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5516. foreach ( $reviseDetail as $ry => $re ) {
  5517. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5518. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5519. }
  5520. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5521. // print_r($reviseDetail);
  5522. }
  5523. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5524. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5525. $categoryDetil = $Lcategory->getOne ( array (
  5526. 'where' => 'cid=' . $value ['cid'],
  5527. 'asArray' => true
  5528. ) );
  5529. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5530. // 检测编辑状态
  5531. $verifyList = $verify->getOne ( array (
  5532. 'where' => 'vid=' . $value ['verify'],
  5533. 'asArray' => true
  5534. ) );
  5535. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5536. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5537. Doo::loadModel ( 'role' );
  5538. $role = new role ();
  5539. // print_r($verifyList);
  5540. $flag = true;
  5541. $roleKey = 0;
  5542. $endStaffArray = array ();
  5543. $roleArrayCopy = array ();
  5544. foreach ( $verifyList as $k => $v ) {
  5545. // init verifyStaff
  5546. if ($v [1] == 'ROLE') {
  5547. if (! empty ( $verifyStaff )) {
  5548. $endStaffArray = end ( $verifyStaff );
  5549. if ($v [0] == $endStaffArray ['nextStaff']) {
  5550. $roleId = $v [0];
  5551. }
  5552. }
  5553. $roleVerify = json_decode ( $v [3], true );
  5554. $roleKey = $k;
  5555. $roleArray = array ();
  5556. $rolename = $role->getOne ( array (
  5557. 'where' => 'rid=' . $v [0],
  5558. 'asArray' => true
  5559. ) );
  5560. foreach ( $roleVerify as $o => $p ) {
  5561. $staffID = explode ( '_', $p );
  5562. $staffInfo = $staff->getOne ( array (
  5563. 'where' => 'sid=' . $staffID [0],
  5564. 'asArray' => true
  5565. ) );
  5566. // print_r($staffID);
  5567. $exp = array (
  5568. 0 => $staffInfo ['sid'],
  5569. 1 => $staffID [1],
  5570. 2 => $staffInfo ['avatar'],
  5571. 'date' => '',
  5572. 'date' => '',
  5573. 'opinion' => '',
  5574. 'status' => '',
  5575. 'rolename' => $rolename ['name']
  5576. );
  5577. array_push ( $roleArray, $exp );
  5578. }
  5579. $roleArrayCopy [$v [0]] = $roleArray;
  5580. // $verifyList[$k]['roleArray']=$roleArray;
  5581. }
  5582. // print_r($roleArray);
  5583. $verifyList [$k] ['date'] = "";
  5584. $verifyList [$k] ['opinion'] = "";
  5585. $verifyList [$k] ['status'] = "";
  5586. if (empty ( $verifyStaff )) {
  5587. $verifyList [$k] ['date'] = "";
  5588. $verifyList [$k] ['opinion'] = "";
  5589. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5590. $verifyList [$k] ['status'] = 4;
  5591. $button = 4;
  5592. $flag = false;
  5593. }
  5594. } else {
  5595. foreach ( $verifyStaff as $m => $u ) {
  5596. if ($v [0] == $m) {
  5597. $verifyList [$k] ['date'] = $u ['date'];
  5598. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5599. $verifyList [$k] ['status'] = $u ['status'];
  5600. $flag = false;
  5601. break;
  5602. }
  5603. }
  5604. $endStaffArray = end ( $verifyStaff );
  5605. if (isset ( $endStaffArray ['ROLE'] )) {
  5606. } else {
  5607. $endKey = key ( $verifyStaff );
  5608. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5609. $button = 4;
  5610. $verifyList [$k] ['status'] = 4;
  5611. }
  5612. }
  5613. }
  5614. }
  5615. $rolename ['name'] = '';
  5616. if (! empty ( $roleId )) {
  5617. Doo::loadModel ( 'role' );
  5618. $role = new role ();
  5619. $rolename = $role->getOne ( array (
  5620. 'where' => 'rid=' . $roleId,
  5621. 'asArray' => true
  5622. ) );
  5623. }
  5624. if (! empty ( $verifyStaff ))
  5625. $endStaffArray = end ( $verifyStaff );
  5626. $KOP = false;
  5627. foreach ( $roleArrayCopy as $P => $A ) {
  5628. foreach ( $A as $MKI => $AVL ) {
  5629. if (! empty ( $verifyStaff )) {
  5630. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5631. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5632. $button = 4;
  5633. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5634. }
  5635. foreach ( $verifyStaff as $m => $u ) {
  5636. $AVLFK = $AVL [0] . '_R';
  5637. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5638. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5639. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5640. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5641. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5642. break;
  5643. }
  5644. }
  5645. } else {
  5646. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5647. $button = 4;
  5648. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5649. }
  5650. }
  5651. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5652. $KOP = true;
  5653. }
  5654. }
  5655. foreach ( $roleArrayCopy as $k => $v ) {
  5656. foreach ( $verifyList as $m => $n ) {
  5657. if ($n [0] == $k) {
  5658. array_splice ( $verifyList, $m, 1, $v );
  5659. }
  5660. }
  5661. }
  5662. // print_r($verifyList);
  5663. $receiptList [$key] ['verifyList'] = $verifyList;
  5664. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5665. 'where' => 'sid=' . $value ['staff'],
  5666. 'asArray' => true
  5667. ) );
  5668. $receiptList [$key] ['button'] = $button;
  5669. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5670. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5671. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5672. $receiptList [$key] ['relust'] = $relust;
  5673. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5674. }
  5675. //print_r($receiptList);die;
  5676. // $data['verifyDetail']=$verifyDetail;
  5677. $mothHtml = "";
  5678. for($i = 1; $i <= 12; $i ++) {
  5679. if ($month == $i)
  5680. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5681. else
  5682. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5683. }
  5684. // 获取审批日志
  5685. Doo::loadModel ( 'receiptLog' );
  5686. $receiptLog = new receiptLog ();
  5687. $rlList = array ();
  5688. $rlInfo = $receiptLog->getOne ( array (
  5689. 'where' => 'rid=' . $rid . ' and status=4',
  5690. 'asArray' => true
  5691. ) );
  5692. $tijdate = $receiptLog->getOne ( array (
  5693. 'where' => 'rid=' . $rid . ' and status=2',
  5694. 'asc' => 'rlid',
  5695. 'asArray' => true
  5696. ) );
  5697. if (! empty ( $rlInfo )) {
  5698. $rlList = $receiptLog->find ( array (
  5699. 'where' => 'rid=' . $rid,
  5700. 'asc' => 'rlid',
  5701. 'asArray' => true
  5702. ) );
  5703. }
  5704. // echo $rid;
  5705. // print_r($receiptList);
  5706. $receiptList [0] ['rlList'] = $rlList;
  5707. // print_r($receiptList);
  5708. $enclosurList = $enclosur->find ( array (
  5709. 'where' => 'rid=' . $rid,
  5710. 'asArray' => true
  5711. ) );
  5712. $enclosurHtml = '';
  5713. foreach ( $enclosurList as $value ) {
  5714. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5715. }
  5716. $data ['enclosurHtml'] = $enclosurHtml;
  5717. $data ['rolename'] = $rolename ['name'];
  5718. $data ['mothHtml'] = $mothHtml;
  5719. // print_r($receiptList);
  5720. $data ['rid'] = $rid;
  5721. $data ['tijdate'] = $tijdate ['date'];
  5722. $data ['receiptList'] = $receiptList;
  5723. $data ['receiptApprovalCount'] = count ( $receiptList );
  5724. $data ['status'] = $status;
  5725. $data ['year'] = $year;
  5726. $data ['categoryList'] = $categoryList;
  5727. $data ['staffList'] = $staffList;
  5728. $data ['cid'] = $cid;
  5729. $data ['sid'] = $sid;
  5730. $data ['ap'] = $ap;
  5731. $data ['memu'] = "receipt";
  5732. $data ['staff'] = $this->staff;
  5733. $data ['receiptMemu'] = 'approvalExpenses';
  5734. $data ['verifyId'] = $this->verifyId;
  5735. $data ['executeId'] = $this->executeId;
  5736. $this->render ( "/admin/receiptburEdi", $data );
  5737. }
  5738. function hisImplement() {
  5739. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5740. if (empty ( $item ))
  5741. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5742. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5743. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5744. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5745. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5746. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5747. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5748. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5749. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5750. Doo::loadClass ( 'XDeode' );
  5751. $XDeode = new XDeode ( 5 );
  5752. Doo::loadModel ( 'receipt' );
  5753. $receipt = new receipt ();
  5754. Doo::loadModel ( 'L_category' );
  5755. $Lcategory = new L_category ();
  5756. Doo::loadModel ( 'verify' );
  5757. Doo::loadModel ( 'statistics' );
  5758. $statistics = new statistics ();
  5759. $verify = new verify ();
  5760. Doo::loadModel ( 'staff' );
  5761. $staff = new staff ();
  5762. Doo::loadClass ( 'XDeode' );
  5763. $XDeode = new XDeode ( 5 );
  5764. $XDeode7 = new XDeode ( 7 );
  5765. $cid = $XDeode->decode ( $cidKey );
  5766. $condition = "";
  5767. if ($item == "expenses")
  5768. $condition = " and Rtype=1 ";
  5769. elseif ($item == "receipts")
  5770. $condition = " and Rtype=0 ";
  5771. elseif ($item == "remits")
  5772. $condition = " and Rtype=2 ";
  5773. elseif($item == "train")
  5774. $condition = " and Rtype=3 ";
  5775. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5776. $sopString = $cidString = "";
  5777. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5778. if (empty ( $rdate ))
  5779. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5780. else
  5781. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5782. if ($status == 'pendImplement') {
  5783. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5784. } elseif ($status == 'alerpts') {
  5785. $statusCon = '(status=8 or status=9 )';
  5786. if (empty ( $rdate ))
  5787. $dateCondition .= " and Year(date) =" . $year;
  5788. else
  5789. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5790. }
  5791. if ($sop != 'SOP')
  5792. $sopString = " and staff=" . $sop;
  5793. if ($cidKey != 'ALL')
  5794. $cidString = " and cid=" . $cid;
  5795. if(!empty($receiptOrder)){
  5796. $receiptList = $receipt->find ( array (
  5797. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5798. 'desc' => 'rid',
  5799. 'asArray' => true
  5800. ) );
  5801. // 员工筛选
  5802. $receiptList2 = $receipt->find ( array (
  5803. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5804. 'desc' => 'rid',
  5805. 'asArray' => true
  5806. ) );
  5807. }else{
  5808. $receiptList = $receipt->find ( array (
  5809. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5810. 'desc' => 'rid',
  5811. 'asArray' => true
  5812. ) );
  5813. // 员工筛选
  5814. $receiptList2 = $receipt->find ( array (
  5815. 'where' => $statusCon . $condition . $dateCondition,
  5816. 'desc' => 'rid',
  5817. 'asArray' => true
  5818. ) );
  5819. }
  5820. $sopStaff = array ();
  5821. foreach ( $receiptList2 as $key => $value ) {
  5822. $staffDetail = $staff->getOne ( array (
  5823. 'select' => 'username',
  5824. 'where' => 'sid=' . $value ['staff'],
  5825. 'asArray' => true
  5826. ) );
  5827. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5828. }
  5829. // 办事处筛选
  5830. $categoryScreen = array ();
  5831. $categorList = $Lcategory->getCategory ();
  5832. foreach ( $receiptList2 as $key => $value ) {
  5833. foreach ( $categorList as $k => $v ) {
  5834. if ($value ['cid'] == $v ['cid']) {
  5835. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5836. break;
  5837. }
  5838. }
  5839. }
  5840. $categoryScreenHtml = "";
  5841. foreach ( $categoryScreen as $key => $value ) {
  5842. if ($cidKey == $key)
  5843. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5844. else
  5845. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5846. }
  5847. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5848. $data ['cidKey'] = $cidKey;
  5849. $Locate = 0;
  5850. $roleId = 0;
  5851. $button = 0;
  5852. $staffBatchNumber = 100001;
  5853. $remittanceList = array ();
  5854. foreach ( $receiptList as $key => $value ) {
  5855. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5856. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5857. $receiptList [$key] ['Texe'] = 'false';
  5858. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5859. $receiptList [$key] ['Texe'] = 'true';
  5860. }
  5861. $receiptList [$key] ['TRexe'] = 'true';
  5862. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5863. $receiptList [$key] ['TRexe'] = 'false';
  5864. }
  5865. $receiptList [$key] ['Locate'] = $Locate;
  5866. $Locate ++;
  5867. $receiptList [$key] ['reviseDetail'] = array ();
  5868. if (! empty ( $value ['reviseDetail'] ))
  5869. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5870. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5871. $categoryDetil = $Lcategory->getOne ( array (
  5872. 'where' => 'cid=' . $value ['cid'],
  5873. 'asArray' => true
  5874. ) );
  5875. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5876. // 检测编辑状态
  5877. $verifyList = $verify->getOne ( array (
  5878. 'where' => 'vid=' . $value ['verify'],
  5879. 'asArray' => true
  5880. ) );
  5881. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5882. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5883. Doo::loadModel ( 'role' );
  5884. $role = new role ();
  5885. $flag = true;
  5886. $roleKey = 0;
  5887. $endStaffArray = array ();
  5888. $roleArrayCopy = array ();
  5889. foreach ( $verifyList as $k => $v ) {
  5890. // init verifyStaff
  5891. if ($v [1] == 'ROLE') {
  5892. if (! empty ( $verifyStaff )) {
  5893. $endStaffArray = end ( $verifyStaff );
  5894. }
  5895. $roleVerify = json_decode ( $v [3], true );
  5896. $roleKey = $k;
  5897. $roleArray = array ();
  5898. $rolename = $role->getOne ( array (
  5899. 'where' => 'rid=' . $v [0],
  5900. 'asArray' => true
  5901. ) );
  5902. foreach ( $roleVerify as $o => $p ) {
  5903. $staffID = explode ( '_', $p );
  5904. $staffInfo = $staff->getOne ( array (
  5905. 'where' => 'sid=' . $staffID [0],
  5906. 'asArray' => true
  5907. ) );
  5908. $exp = array (
  5909. 0 => $staffInfo ['sid'],
  5910. 1 => $staffID [1],
  5911. 2 => $staffInfo ['avatar'],
  5912. 'date' => '',
  5913. 'date' => '',
  5914. 'opinion' => '',
  5915. 'status' => '',
  5916. 'rolename' => $rolename ['name']
  5917. );
  5918. array_push ( $roleArray, $exp );
  5919. }
  5920. $roleArrayCopy [$v [0]] = $roleArray;
  5921. }
  5922. $verifyList [$k] ['date'] = "";
  5923. $verifyList [$k] ['opinion'] = "";
  5924. $verifyList [$k] ['status'] = "";
  5925. if (empty ( $verifyStaff )) {
  5926. $verifyList [$k] ['date'] = "";
  5927. $verifyList [$k] ['opinion'] = "";
  5928. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5929. $verifyList [$k] ['status'] = 4;
  5930. $flag = false;
  5931. }
  5932. } else {
  5933. foreach ( $verifyStaff as $m => $u ) {
  5934. if ($v [0] == $m) {
  5935. $verifyList [$k] ['date'] = $u ['date'];
  5936. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5937. $verifyList [$k] ['status'] = $u ['status'];
  5938. $flag = false;
  5939. break;
  5940. }
  5941. }
  5942. $endStaffArray = end ( $verifyStaff );
  5943. }
  5944. }
  5945. $rolename ['name'] = '';
  5946. if (! empty ( $roleId )) {
  5947. Doo::loadModel ( 'role' );
  5948. $role = new role ();
  5949. $rolename = $role->getOne ( array (
  5950. 'where' => 'rid=' . $roleId,
  5951. 'asArray' => true
  5952. ) );
  5953. }
  5954. if (! empty ( $verifyStaff ))
  5955. $endStaffArray = end ( $verifyStaff );
  5956. $KOP = false;
  5957. foreach ( $roleArrayCopy as $P => $A ) {
  5958. foreach ( $A as $MKI => $AVL ) {
  5959. if (! empty ( $verifyStaff )) {
  5960. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5961. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5962. $button = 4;
  5963. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5964. }
  5965. foreach ( $verifyStaff as $m => $u ) {
  5966. $AVLFK = $AVL [0] . '_R';
  5967. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5968. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5969. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5970. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5971. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5972. break;
  5973. }
  5974. }
  5975. } else {
  5976. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5977. $button = 4;
  5978. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5979. }
  5980. }
  5981. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5982. $KOP = true;
  5983. }
  5984. }
  5985. foreach ( $roleArrayCopy as $k => $v ) {
  5986. foreach ( $verifyList as $m => $n ) {
  5987. if ($n [0] == $k) {
  5988. array_splice ( $verifyList, $m, 1, $v );
  5989. }
  5990. }
  5991. }
  5992. $receiptList [$key] ['verifyList'] = $verifyList;
  5993. $staffDetail = $staff->getOne ( array (
  5994. 'where' => 'sid=' . $value ['staff'],
  5995. 'asArray' => true
  5996. ) );
  5997. $receiptList [$key] ['staffDetail'] = $staffDetail;
  5998. $receiptList [$key] ['button'] = $button;
  5999. // 设置导出汇款execl
  6000. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6001. $remittanceDetail = array (
  6002. $staffBatchNumber,
  6003. $value ['remittanceName'],
  6004. $value ['bankNumber'],
  6005. $value ['bankName'],
  6006. $value ['remittanceBankType'],
  6007. $value ['coupletNumber'],
  6008. $value ['sum']
  6009. );
  6010. array_push ( $remittanceList, $remittanceDetail );
  6011. $staffBatchNumber ++;
  6012. }
  6013. }
  6014. $data ['remittanceList'] = json_encode ( $remittanceList );
  6015. // print_r($receiptList);
  6016. $mothHtml = "";
  6017. for($i = 1; $i <= 12; $i ++) {
  6018. if ($moth == $i)
  6019. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6020. else
  6021. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6022. }
  6023. $dayHtml = "";
  6024. if ($day != "DAY" || $moth != "MONTH") {
  6025. for($i = 1; $i <= 31; $i ++) {
  6026. if ($day == $i)
  6027. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6028. else
  6029. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6030. }
  6031. }
  6032. $sopHtml = "";
  6033. foreach ( $sopStaff as $key => $value ) {
  6034. if ($sop == $key)
  6035. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6036. else
  6037. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6038. }
  6039. $data ['status'] = $status;
  6040. $data ['rdate'] = $rdate;
  6041. $data ['sopHtml'] = $sopHtml;
  6042. $data ['dayHtml'] = $dayHtml;
  6043. $data ['mothHtml'] = $mothHtml;
  6044. $data ['receiptList'] = $receiptList;
  6045. $data ['memu'] = "receipt";
  6046. $data ['staff'] = $this->staff;
  6047. $data ['receiptMemu'] = 'implement';
  6048. $data ['verifyId'] = $this->verifyId;
  6049. $data ['executeId'] = $this->executeId;
  6050. $data ['item'] = $item;
  6051. $data ['year'] = $year;
  6052. $data ['moth'] = $moth;
  6053. $data['receiptOrder']=$receiptOrder;
  6054. $data ['day'] = $day;
  6055. $data ['sop'] = $sop;
  6056. $this->render ( "/admin/hisImplement", $data );
  6057. }
  6058. /**
  6059. * 导出汇款信息的exelc
  6060. */
  6061. function exportRemittance() {
  6062. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6063. if (empty ( $remittanceInfo ))
  6064. die ( 'illegal request' );
  6065. $title = array (
  6066. '员工编号',
  6067. '姓名',
  6068. '员工账号',
  6069. '员工账户开户行',
  6070. '转账类型',
  6071. '联行号',
  6072. '金额'
  6073. );
  6074. $data = json_decode ( $remittanceInfo, true );
  6075. if (empty ( $data ))
  6076. die ( 'illegal request' );
  6077. Doo::loadClass ( 'receipt.func' );
  6078. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6079. header ( 'Content-Type:text/html;charset=utf-8' );
  6080. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6081. }
  6082. function ajaxExamine() {
  6083. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6084. Doo::loadModel ( 'receipt' );
  6085. $receipt = new receipt ();
  6086. if (! empty ( $rid )) {
  6087. $rLRes = $receipt->find ( array (
  6088. '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,
  6089. 'asArray' => true
  6090. ) );
  6091. echo json_encode ( array (
  6092. 'status' => 1,
  6093. 'receipt' => $rLRes [0]
  6094. ) );
  6095. die ();
  6096. }
  6097. echo json_encode ( array (
  6098. 'status' => 0,
  6099. 'receipt' => array ()
  6100. ) );
  6101. die ();
  6102. }
  6103. /*
  6104. * 废弃
  6105. */
  6106. function myReceipt() {
  6107. // all approval past withdraw
  6108. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6109. if (empty ( $item ))
  6110. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6111. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6112. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6113. Doo::loadModel ( 'receipt' );
  6114. $receipt = new receipt ();
  6115. // pre-loaded
  6116. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6117. // have cache
  6118. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6119. if (! empty ( $moth )) // yearPage
  6120. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6121. $this->showCache ( $path );
  6122. }
  6123. Doo::loadModel ( 'L_category' );
  6124. $Lcategory = new L_category ();
  6125. Doo::loadModel ( 'verify' );
  6126. Doo::loadModel ( 'statistics' );
  6127. $statistics = new statistics ();
  6128. $verify = new verify ();
  6129. Doo::loadModel ( 'staff' );
  6130. $staff = new staff ();
  6131. $condition = " and status!=0 ";
  6132. if ($item == "approval")
  6133. $condition = " and status=2 ";
  6134. elseif ($item == "withdraw")
  6135. $condition = " and status=3 ";
  6136. elseif ($item == "past")
  6137. $condition = " and status=1 ";
  6138. elseif ($item == "whdw")
  6139. $condition = " and status=4 ";
  6140. $dateCondition = " and Year(date) =" . $year;
  6141. if (! empty ( $moth )) {
  6142. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6143. $stList = $statistics->getOne ( array (
  6144. 'select' => 'rePrice ,agPrice',
  6145. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6146. 'asArray' => true
  6147. ) );
  6148. } else
  6149. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6150. if (empty ( $stList ))
  6151. $stList = array (
  6152. 'rePrice' => 0,
  6153. 'agPrice' => 0
  6154. );
  6155. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6156. $data ['stList'] = array (
  6157. 'rePrice' => $stList ['rePrice'],
  6158. 'agPrice' => $stList ['agPrice'],
  6159. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6160. );
  6161. $receiptList = $receipt->find ( array (
  6162. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6163. 'desc' => 'rid',
  6164. 'asArray' => true
  6165. ) );
  6166. $Locate = 0;
  6167. $roleId = 0;
  6168. $button = 0;
  6169. foreach ( $receiptList as $key => $value ) {
  6170. $receiptList [$key] ['Locate'] = $Locate;
  6171. $Locate ++;
  6172. $receiptList [$key] ['reviseDetail'] = array ();
  6173. if (! empty ( $value ['reviseDetail'] ))
  6174. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6175. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6176. $categoryDetil = $Lcategory->getOne ( array (
  6177. 'where' => 'cid=' . $value ['cid'],
  6178. 'asArray' => true
  6179. ) );
  6180. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6181. // 检测编辑状态
  6182. $verifyList = $verify->getOne ( array (
  6183. 'where' => 'vid=' . $value ['verify'],
  6184. 'asArray' => true
  6185. ) );
  6186. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6187. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6188. Doo::loadModel ( 'role' );
  6189. $role = new role ();
  6190. $flag = true;
  6191. $roleKey = 0;
  6192. $endStaffArray = array ();
  6193. $roleArrayCopy = array ();
  6194. foreach ( $verifyList as $k => $v ) {
  6195. // init verifyStaff
  6196. if ($v [1] == 'ROLE') {
  6197. if (! empty ( $verifyStaff )) {
  6198. $endStaffArray = end ( $verifyStaff );
  6199. // if ($v[0]==$endStaffArray['nextStaff']){
  6200. // $roleId=$v[0];
  6201. // }
  6202. }
  6203. $roleVerify = json_decode ( $v [3], true );
  6204. $roleKey = $k;
  6205. $roleArray = array ();
  6206. $rolename = $role->getOne ( array (
  6207. 'where' => 'rid=' . $v [0],
  6208. 'asArray' => true
  6209. ) );
  6210. foreach ( $roleVerify as $o => $p ) {
  6211. $staffID = explode ( '_', $p );
  6212. $staffInfo = $staff->getOne ( array (
  6213. 'where' => 'sid=' . $staffID [0],
  6214. 'asArray' => true
  6215. ) );
  6216. // print_r($staffID);
  6217. $exp = array (
  6218. 0 => $staffInfo ['sid'],
  6219. 1 => $staffID [1],
  6220. 2 => $staffInfo ['avatar'],
  6221. 'date' => '',
  6222. 'date' => '',
  6223. 'opinion' => '',
  6224. 'status' => '',
  6225. 'rolename' => $rolename ['name']
  6226. );
  6227. array_push ( $roleArray, $exp );
  6228. }
  6229. $roleArrayCopy [$v [0]] = $roleArray;
  6230. // $verifyList[$k]['roleArray']=$roleArray;
  6231. }
  6232. $verifyList [$k] ['date'] = "";
  6233. $verifyList [$k] ['opinion'] = "";
  6234. $verifyList [$k] ['status'] = "";
  6235. if (empty ( $verifyStaff )) {
  6236. $verifyList [$k] ['date'] = "";
  6237. $verifyList [$k] ['opinion'] = "";
  6238. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6239. $verifyList [$k] ['status'] = 4;
  6240. $flag = false;
  6241. }
  6242. } else {
  6243. foreach ( $verifyStaff as $m => $u ) {
  6244. if ($v [0] == $m) {
  6245. $verifyList [$k] ['date'] = $u ['date'];
  6246. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6247. $verifyList [$k] ['status'] = $u ['status'];
  6248. $flag = false;
  6249. break;
  6250. }
  6251. }
  6252. $endStaffArray = end ( $verifyStaff );
  6253. if (isset ( $endStaffArray ['ROLE'] )) {
  6254. } else {
  6255. // $endKey=key($verifyStaff);
  6256. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6257. // $button=4;
  6258. // $verifyList[$k]['status']=4;
  6259. // }
  6260. }
  6261. }
  6262. }
  6263. $rolename ['name'] = '';
  6264. if (! empty ( $roleId )) {
  6265. Doo::loadModel ( 'role' );
  6266. $role = new role ();
  6267. $rolename = $role->getOne ( array (
  6268. 'where' => 'rid=' . $roleId,
  6269. 'asArray' => true
  6270. ) );
  6271. }
  6272. if (! empty ( $verifyStaff ))
  6273. $endStaffArray = end ( $verifyStaff );
  6274. $KOP = false;
  6275. foreach ( $roleArrayCopy as $P => $A ) {
  6276. foreach ( $A as $MKI => $AVL ) {
  6277. if (! empty ( $verifyStaff )) {
  6278. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6279. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6280. $button = 4;
  6281. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6282. }
  6283. foreach ( $verifyStaff as $m => $u ) {
  6284. $AVLFK = $AVL [0] . '_R';
  6285. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6286. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6287. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6288. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6289. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6290. break;
  6291. }
  6292. }
  6293. } else {
  6294. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6295. $button = 4;
  6296. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6297. }
  6298. }
  6299. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6300. $KOP = true;
  6301. }
  6302. }
  6303. foreach ( $roleArrayCopy as $k => $v ) {
  6304. foreach ( $verifyList as $m => $n ) {
  6305. if ($n [0] == $k) {
  6306. array_splice ( $verifyList, $m, 1, $v );
  6307. }
  6308. }
  6309. }
  6310. $receiptList [$key] ['verifyList'] = $verifyList;
  6311. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6312. 'where' => 'sid=' . $value ['staff'],
  6313. 'asArray' => true
  6314. ) );
  6315. $receiptList [$key] ['button'] = $button;
  6316. }
  6317. // print_r($receiptList);die;
  6318. $mothHtml = "";
  6319. for($i = 1; $i <= 12; $i ++) {
  6320. if ($moth == $i)
  6321. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6322. else
  6323. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6324. }
  6325. $data ['mothHtml'] = $mothHtml;
  6326. $data ['receiptList'] = $receiptList;
  6327. $data ['memu'] = "receipt";
  6328. $data ['staff'] = $this->staff;
  6329. $data ['receiptMemu'] = 'receipt';
  6330. $data ['verifyId'] = $this->verifyId;
  6331. $data ['executeId'] = $this->executeId;
  6332. $data ['item'] = $item;
  6333. $data ['year'] = $year;
  6334. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6335. // sufficient condition to generate cache
  6336. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6337. $receiptList = $receipt->find ( array (
  6338. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6339. 'asArray' => true
  6340. ) );
  6341. if (empty ( $receiptList )) { // generated files
  6342. ob_start ();
  6343. $this->render ( "/admin/saea_myList", $data );
  6344. $this->cacheFile ( $path );
  6345. die ();
  6346. // $content = ob_get_contents();
  6347. // $fp = fopen($path, "w");
  6348. // fwrite($fp, $content);
  6349. // fclose($fp);
  6350. }
  6351. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6352. $receiptList = $receipt->find ( array (
  6353. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6354. 'asArray' => true
  6355. ) );
  6356. if (empty ( $receiptList )) { // generated files
  6357. ob_start ();
  6358. $this->render ( "/admin/saea_myList", $data );
  6359. $this->cacheFile ( $path );
  6360. die ();
  6361. }
  6362. }
  6363. }
  6364. $this->render ( "/admin/saea_myList", $data );
  6365. }
  6366. function saeaCreate() {
  6367. Doo::loadModel ( 'accountItem' );
  6368. Doo::loadModel ( 'verify' );
  6369. Doo::loadModel ( 'receipt' );
  6370. Doo::loadModel ( 'L_category' );
  6371. $lCategory = new L_category ();
  6372. $receipt = new receipt ();
  6373. $verify = new verify ();
  6374. $accountItem = new accountItem ();
  6375. Doo::loadModel ( "role" );
  6376. $role = new role ();
  6377. $acItem = $accountItem->find ( array (
  6378. 'asArray' => true
  6379. ) );
  6380. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6381. $data ['category'] = $lCategory->find ( array (
  6382. 'asArray' => true
  6383. ) );
  6384. $data ['veList'] = $veList;
  6385. $data ['acItem'] = $acItem;
  6386. $data ['memu'] = "receipt";
  6387. $data ['staff'] = $this->staff;
  6388. $data ['receiptMemu'] = 'saeaBorad';
  6389. $data ['verifyId'] = $this->verifyId;
  6390. $data ['executeId'] = $this->executeId;
  6391. $this->render ( "/admin/saea_create", $data );
  6392. }
  6393. function addReceipt() {
  6394. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6395. $agency = $this->get_args ( 'agency' );
  6396. $travel = $this->get_args ( 'travel' );
  6397. $train = $this->get_args ( 'train' );
  6398. $other = $this->get_args ( 'other' );
  6399. $inttrain = $this->get_args ( 'inttrain' );
  6400. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6401. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6402. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6403. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6404. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6405. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6406. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6407. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6408. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6409. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6410. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6411. header ( 'Content-Type:text/html;charset=utf-8' );
  6412. die ( '请填写联行号' );
  6413. }
  6414. Doo::loadModel ( 'receipt' );
  6415. Doo::loadModel ( 'receiptDetail' );
  6416. Doo::loadModel ( 'accountItem' );
  6417. $accountItem = new accountItem ();
  6418. $receipt = new receipt ();
  6419. Doo::loadModel ( 'enclosur' );
  6420. Doo::loadModel ( 'execute' );
  6421. $execute = new execute ();
  6422. $executeDetail = $execute->getOne ( array (
  6423. 'where' => 'mold="报销单执行人"',
  6424. 'asArray' => true
  6425. ) );
  6426. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6427. // if(!empty($receiptDetail))
  6428. // return "/referReceipt/".$receiptDetail['rid'];
  6429. $aItem = $accountItem->find ( array (
  6430. 'asArray' => true
  6431. ) );
  6432. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6433. $ag = $tr = $ta = $ot= $it = 0;
  6434. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6435. foreach ( $aItem as $key => $value ) {
  6436. if ($value ['category'] == $this->AGENCY) {
  6437. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6438. array_push ( $accountJson [$this->AGENCY], array (
  6439. 'aid' => $value ['aid'],
  6440. 'name' => $value ['name'],
  6441. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6442. ) );
  6443. $sum += $agency [$ag];
  6444. $agencySum += $agency [$ag];
  6445. }
  6446. $ag ++;
  6447. }
  6448. if ($value ['category'] == $this->TRAVEL) {
  6449. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6450. array_push ( $accountJson [$this->TRAVEL], array (
  6451. 'aid' => $value ['aid'],
  6452. 'name' => $value ['name'],
  6453. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6454. ) );
  6455. $sum += $travel [$tr];
  6456. $travelSum += $travel [$tr];
  6457. }
  6458. $tr ++;
  6459. }
  6460. if ($value ['category'] == $this->TRAIN) {
  6461. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6462. array_push ( $accountJson [$this->TRAIN], array (
  6463. 'aid' => $value ['aid'],
  6464. 'name' => $value ['name'],
  6465. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6466. ) );
  6467. $sum += $train [$ta];
  6468. $trainSum += $train [$ta];
  6469. }
  6470. $ta ++;
  6471. }
  6472. if ($value ['category'] == $this->INTTRAIN) {
  6473. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6474. array_push ( $accountJson [$this->INTTRAIN], array (
  6475. 'aid' => $value ['aid'],
  6476. 'name' => $value ['name'],
  6477. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6478. ) );
  6479. $sum += $inttrain [$it];
  6480. $inttrainSum += $inttrain [$it];
  6481. }
  6482. $it ++;
  6483. }
  6484. if ($value ['category'] == $this->OTHER) {
  6485. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6486. array_push ( $accountJson [$this->OTHER], array (
  6487. 'aid' => $value ['aid'],
  6488. 'name' => $value ['name'],
  6489. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6490. ) );
  6491. $sum += $other [$ot];
  6492. $otherSum += $other [$ot];
  6493. }
  6494. $ot ++;
  6495. }
  6496. }
  6497. $accountJson ['cSum'] = array (
  6498. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6499. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6500. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6501. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6502. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6503. );
  6504. // 报销单
  6505. $receipt->accountItem = json_encode ( $accountJson );
  6506. $receipt->staff = $this->staff [0] ['sid'];
  6507. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6508. $receipt->date = date ( "Y-m-d" );
  6509. $receipt->cid = $cid;
  6510. $receipt->status = 5;
  6511. // 修改审批流程加入角色
  6512. $receipt->verify = $verify;
  6513. $receipt->executeCopy = $executeDetail ['staff'];
  6514. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6515. $order = array (
  6516. "\r\n",
  6517. "\n",
  6518. "\r"
  6519. );
  6520. $replace = '<br/>';
  6521. $explanation = str_replace ( $order, $replace, $explanation );
  6522. $receipt->explanation = $explanation;
  6523. $receipt->remittanceName = $remittanceName;
  6524. $receipt->bankName = $bankName;
  6525. $receipt->bankNumber = $bankNumber;
  6526. $receipt->remittanceBankType = $remittanceBankType;
  6527. if ($remittanceBankType == 1)
  6528. $receipt->coupletNumber = $coupletNumber;
  6529. $rid = $receipt->insert ();
  6530. // 附件
  6531. if (! empty ( $enclosurName )) {
  6532. $enclosurArray = explode ( '-', $enclosurName );
  6533. foreach ( $enclosurArray as $value ) {
  6534. $enclosur = new enclosur ();
  6535. $enclosur->name = $value;
  6536. $enclosur->rid = $rid;
  6537. $enclosur->insert ();
  6538. }
  6539. // print_r($enclosurArray);die;
  6540. }
  6541. // 报销详情
  6542. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6543. $receiptDetail = new receiptDetail ();
  6544. $receiptDetail->staff = $this->staff [0] ['sid'];
  6545. $receiptDetail->item = $value ['name'];
  6546. $receiptDetail->itemCategory = $this->AGENCY;
  6547. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6548. $receiptDetail->date = date ( "Y-m-d" );
  6549. $receiptDetail->cid = $cid;
  6550. $receiptDetail->rid = $rid;
  6551. $receiptDetail->status = 4;
  6552. $receiptDetail->insert ();
  6553. }
  6554. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6555. $receiptDetail = new receiptDetail ();
  6556. $receiptDetail->staff = $this->staff [0] ['sid'];
  6557. $receiptDetail->item = $value ['name'];
  6558. $receiptDetail->itemCategory = $this->TRAVEL;
  6559. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6560. $receiptDetail->date = date ( "Y-m-d" );
  6561. $receiptDetail->cid = $cid;
  6562. $receiptDetail->rid = $rid;
  6563. $receiptDetail->status = 4;
  6564. $receiptDetail->insert ();
  6565. }
  6566. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6567. $receiptDetail = new receiptDetail ();
  6568. $receiptDetail->staff = $this->staff [0] ['sid'];
  6569. $receiptDetail->item = $value ['name'];
  6570. $receiptDetail->itemCategory = $this->TRAIN;
  6571. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6572. $receiptDetail->date = date ( "Y-m-d" );
  6573. $receiptDetail->cid = $cid;
  6574. $receiptDetail->rid = $rid;
  6575. $receiptDetail->status = 4;
  6576. $receiptDetail->insert ();
  6577. }
  6578. //内训
  6579. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6580. $receiptDetail = new receiptDetail ();
  6581. $receiptDetail->staff = $this->staff [0] ['sid'];
  6582. $receiptDetail->item = $value ['name'];
  6583. $receiptDetail->itemCategory = $this->INTTRAIN;
  6584. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6585. $receiptDetail->date = date ( "Y-m-d" );
  6586. $receiptDetail->cid = $cid;
  6587. $receiptDetail->rid = $rid;
  6588. $receiptDetail->status = 4;
  6589. $receiptDetail->insert ();
  6590. }
  6591. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6592. $receiptDetail = new receiptDetail ();
  6593. $receiptDetail->staff = $this->staff [0] ['sid'];
  6594. $receiptDetail->item = $value ['name'];
  6595. $receiptDetail->itemCategory = $this->OTHER;
  6596. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6597. $receiptDetail->date = date ( "Y-m-d" );
  6598. $receiptDetail->cid = $cid;
  6599. $receiptDetail->rid = $rid;
  6600. $receiptDetail->status = 4;
  6601. $receiptDetail->insert ();
  6602. }
  6603. return "/saeaBorad";
  6604. } else
  6605. die ( 'illegal request' );
  6606. }
  6607. function referReceipt() {
  6608. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6609. Doo::loadModel ( 'receipt' );
  6610. Doo::loadModel ( 'verify' );
  6611. $verify = new verify ();
  6612. $receipt = new receipt ();
  6613. Doo::loadModel ( 'L_category' );
  6614. $lCategory = new L_category ();
  6615. Doo::loadModel ( "role" );
  6616. $role = new role ();
  6617. $receiptDetail = $receipt->find ( array (
  6618. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6619. 'asArray' => true
  6620. ) );
  6621. if (empty ( $receiptDetail ))
  6622. return "/addReceipt";
  6623. foreach ( $receiptDetail as $key => $value ) {
  6624. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6625. $veList = $verify->getOne ( array (
  6626. 'where' => 'vid=' . $value ['verify'],
  6627. 'asArray' => true
  6628. ) );
  6629. $v = json_decode ( $veList ['staff'] );
  6630. array_push ( $v [0], $veList ['description'] );
  6631. foreach ( $v as $n => $m ) {
  6632. if ($m ['1'] == 'ROLE') {
  6633. $roleInfo = $role->getOne ( array (
  6634. 'where' => 'rid=' . $m [0],
  6635. 'asArray' => true
  6636. ) );
  6637. $v [$n] [1] = $roleInfo ['name'];
  6638. }
  6639. }
  6640. $receiptDetail [$key] ['staff'] = $v;
  6641. $category = $lCategory->getOne ( array (
  6642. 'where' => 'cid=' . $value ['cid'],
  6643. 'asArray' => true
  6644. ) );
  6645. $receiptDetail [$key] ['category'] = $category ['title'];
  6646. }
  6647. // print_r($receiptDetail);
  6648. $data ['receiptDetail'] = $receiptDetail;
  6649. $data ['memu'] = "receipt";
  6650. $data ['staff'] = $this->staff;
  6651. $data ['receiptMemu'] = 'saeaCreate';
  6652. $data ['verifyId'] = $this->verifyId;
  6653. $data ['executeId'] = $this->executeId;
  6654. $this->render ( "/admin/saea_confirm", $data );
  6655. }
  6656. function editReceipt() {
  6657. // edit status 4
  6658. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6659. Doo::loadClass ( 'XDeode' );
  6660. $XDeode = new XDeode ( 7 );
  6661. $rid = $XDeode->decode ( $ridKey );
  6662. if (empty ( $rid ))
  6663. die ( 'illegal request' );
  6664. // echo $rid.'sd';
  6665. Doo::loadModel ( 'accountItem' );
  6666. Doo::loadModel ( 'verify' );
  6667. Doo::loadModel ( 'receipt' );
  6668. $receipt = new receipt ();
  6669. $verify = new verify ();
  6670. $accountItem = new accountItem ();
  6671. Doo::loadModel ( 'L_category' );
  6672. $lCategory = new L_category ();
  6673. Doo::loadModel ( "role" );
  6674. $role = new role ();
  6675. Doo::loadModel ( 'enclosur' );
  6676. $enclosur = new enclosur ();
  6677. $receiptDetail = $receipt->getOne ( array (
  6678. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6679. 'asArray' => true
  6680. ) );
  6681. if (empty ( $receiptDetail ))
  6682. die ( 'illegal request' );
  6683. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6684. $acItem = $accountItem->find ( array (
  6685. 'asArray' => true
  6686. ) );
  6687. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6688. // 配置编辑信息
  6689. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6690. foreach ( $acItem as $key => $value ) {
  6691. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6692. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6693. $acItem [$key] ['price'] = $v ['price'];
  6694. }
  6695. }
  6696. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6697. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6698. $acItem [$key] ['price'] = $v ['price'];
  6699. }
  6700. }
  6701. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6702. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6703. $acItem [$key] ['price'] = $v ['price'];
  6704. }
  6705. }
  6706. //内训
  6707. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6708. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6709. $acItem [$key] ['price'] = $v ['price'];
  6710. }
  6711. }
  6712. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6713. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6714. $acItem [$key] ['price'] = $v ['price'];
  6715. }
  6716. }
  6717. }
  6718. $data ['category'] = $lCategory->find ( array (
  6719. 'asArray' => true
  6720. ) );
  6721. $data ['cSum'] = $accountItemList ['cSum'];
  6722. $data ['sum'] = $receiptDetail ['sum'];
  6723. $data ['enclosurList'] = $enclosurList;
  6724. $data ['receiptDetail'] = $receiptDetail;
  6725. $data ['veList'] = $veList;
  6726. $data ['acItem'] = $acItem;
  6727. $data ['memu'] = "receipt";
  6728. $data ['staff'] = $this->staff;
  6729. $data ['receiptMemu'] = 'saeaBorad';
  6730. $data ['verify'] = $receiptDetail ['verify'];
  6731. $data ['verifyId'] = $this->verifyId;
  6732. $data ['executeId'] = $this->executeId;
  6733. $data ['rid'] = $ridKey;
  6734. $this->render ( "/admin/saea_edit", $data );
  6735. }
  6736. function updateReceipt() {
  6737. $agency = $this->get_args ( 'agency' );
  6738. $travel = $this->get_args ( 'travel' );
  6739. $train = $this->get_args ( 'train' );
  6740. $other = $this->get_args ( 'other' );
  6741. $inttrain = $this->get_args ( 'inttrain' );
  6742. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6743. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6744. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6745. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6746. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6747. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6748. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6749. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6750. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6751. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6752. Doo::loadClass ( 'XDeode' );
  6753. $XDeode = new XDeode ( 7 );
  6754. $rid = $XDeode->decode ( $ridKey );
  6755. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6756. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6757. header ( 'Content-Type:text/html;charset=utf-8' );
  6758. die ( '请填写联行号' );
  6759. }
  6760. Doo::loadModel ( 'receipt' );
  6761. Doo::loadModel ( 'receiptDetail' );
  6762. Doo::loadModel ( 'accountItem' );
  6763. $accountItem = new accountItem ();
  6764. $receipt = new receipt ();
  6765. Doo::loadModel ( 'enclosur' );
  6766. Doo::loadModel ( 'execute' );
  6767. $execute = new execute ();
  6768. $receiptDetail = $receipt->getOne ( array (
  6769. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6770. 'asArray' => true
  6771. ) );
  6772. if (empty ( $receiptDetail ))
  6773. return "/saeaBorad";
  6774. if ($receiptDetail ['Rtype'] == 1)
  6775. $executeDetail = $execute->getOne ( array (
  6776. 'where' => 'mold="借款费用执行人"',
  6777. 'asArray' => true
  6778. ) );
  6779. else
  6780. $executeDetail = $execute->getOne ( array (
  6781. 'where' => 'mold="报销单执行人"',
  6782. 'asArray' => true
  6783. ) );
  6784. $aItem = $accountItem->find ( array (
  6785. 'asArray' => true
  6786. ) );
  6787. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6788. $ag = $tr = $ta = $ot = $it = 0 ;
  6789. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6790. foreach ( $aItem as $key => $value ) {
  6791. if ($value ['category'] == $this->AGENCY) {
  6792. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6793. array_push ( $accountJson [$this->AGENCY], array (
  6794. 'aid' => $value ['aid'],
  6795. 'name' => $value ['name'],
  6796. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6797. ) );
  6798. $sum += $agency [$ag];
  6799. $agencySum += $agency [$ag];
  6800. }
  6801. $ag ++;
  6802. }
  6803. if ($value ['category'] == $this->TRAVEL) {
  6804. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6805. array_push ( $accountJson [$this->TRAVEL], array (
  6806. 'aid' => $value ['aid'],
  6807. 'name' => $value ['name'],
  6808. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6809. ) );
  6810. $sum += $travel [$tr];
  6811. $travelSum += $travel [$tr];
  6812. }
  6813. $tr ++;
  6814. }
  6815. if ($value ['category'] == $this->TRAIN) {
  6816. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6817. array_push ( $accountJson [$this->TRAIN], array (
  6818. 'aid' => $value ['aid'],
  6819. 'name' => $value ['name'],
  6820. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6821. ) );
  6822. $sum += $train [$ta];
  6823. $trainSum += $train [$ta];
  6824. }
  6825. $ta ++;
  6826. }
  6827. if ($value ['category'] == $this->INTTRAIN) {
  6828. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6829. array_push ( $accountJson [$this->INTTRAIN], array (
  6830. 'aid' => $value ['aid'],
  6831. 'name' => $value ['name'],
  6832. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6833. ) );
  6834. $sum += $inttrain [$it];
  6835. $inttrainSum += $inttrain [$it];
  6836. }
  6837. $it ++;
  6838. }
  6839. if ($value ['category'] == $this->OTHER) {
  6840. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6841. array_push ( $accountJson [$this->OTHER], array (
  6842. 'aid' => $value ['aid'],
  6843. 'name' => $value ['name'],
  6844. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6845. ) );
  6846. $sum += $other [$ot];
  6847. $otherSum += $other [$ot];
  6848. }
  6849. $ot ++;
  6850. }
  6851. }
  6852. $accountJson ['cSum'] = array (
  6853. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6854. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6855. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6856. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6857. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6858. );
  6859. // 报销单
  6860. $rid = $receipt->rid = $receiptDetail ['rid'];
  6861. $receipt->accountItem = json_encode ( $accountJson );
  6862. $receipt->staff = $this->staff [0] ['sid'];
  6863. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6864. $receipt->date = date ( "Y-m-d" );
  6865. $receipt->cid = $cid;
  6866. if (($receiptDetail ['status'] != 4)) {
  6867. if ($receiptDetail ['Rtype'] == 1)
  6868. $receipt->status = 7;
  6869. else
  6870. $receipt->status = 5;
  6871. }
  6872. if ($receiptDetail != 4 && ! empty ( $verify ))
  6873. $receipt->verify = $verify;
  6874. $receipt->executeCopy = $executeDetail ['staff'];
  6875. $order = array (
  6876. "\r\n",
  6877. "\n",
  6878. "\r"
  6879. );
  6880. $replace = '<br/>';
  6881. $explanation = str_replace ( $order, $replace, $explanation );
  6882. $receipt->explanation = $explanation;
  6883. $receipt->remittanceName = $remittanceName;
  6884. $receipt->bankName = $bankName;
  6885. $receipt->bankNumber = $bankNumber;
  6886. $receipt->remittanceBankType = $remittanceBankType;
  6887. if ($remittanceBankType == 1)
  6888. $receipt->coupletNumber = $coupletNumber;
  6889. $receipt->update ();
  6890. $receiptDetail = new receiptDetail ();
  6891. $receiptDetail->delete ( array (
  6892. 'where' => 'rid=' . $rid
  6893. ) );
  6894. // 报销详情
  6895. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6896. $receiptDetail = new receiptDetail ();
  6897. $receiptDetail->staff = $this->staff [0] ['sid'];
  6898. $receiptDetail->item = $value ['name'];
  6899. $receiptDetail->itemCategory = $this->AGENCY;
  6900. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6901. $receiptDetail->date = date ( "Y-m-d" );
  6902. $receiptDetail->cid = $cid;
  6903. $receiptDetail->rid = $rid;
  6904. $receiptDetail->status = 4;
  6905. $receiptDetail->insert ();
  6906. }
  6907. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6908. $receiptDetail = new receiptDetail ();
  6909. $receiptDetail->staff = $this->staff [0] ['sid'];
  6910. $receiptDetail->item = $value ['name'];
  6911. $receiptDetail->itemCategory = $this->TRAVEL;
  6912. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6913. $receiptDetail->date = date ( "Y-m-d" );
  6914. $receiptDetail->cid = $cid;
  6915. $receiptDetail->rid = $rid;
  6916. $receiptDetail->status = 4;
  6917. $receiptDetail->insert ();
  6918. }
  6919. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6920. $receiptDetail = new receiptDetail ();
  6921. $receiptDetail->staff = $this->staff [0] ['sid'];
  6922. $receiptDetail->item = $value ['name'];
  6923. $receiptDetail->itemCategory = $this->TRAIN;
  6924. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6925. $receiptDetail->date = date ( "Y-m-d" );
  6926. $receiptDetail->cid = $cid;
  6927. $receiptDetail->rid = $rid;
  6928. $receiptDetail->status = 4;
  6929. $receiptDetail->insert ();
  6930. }
  6931. //内训
  6932. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6933. $receiptDetail = new receiptDetail ();
  6934. $receiptDetail->staff = $this->staff [0] ['sid'];
  6935. $receiptDetail->item = $value ['name'];
  6936. $receiptDetail->itemCategory = $this->INTTRAIN;
  6937. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6938. $receiptDetail->date = date ( "Y-m-d" );
  6939. $receiptDetail->cid = $cid;
  6940. $receiptDetail->rid = $rid;
  6941. $receiptDetail->status = 4;
  6942. $receiptDetail->insert ();
  6943. }
  6944. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6945. $receiptDetail = new receiptDetail ();
  6946. $receiptDetail->staff = $this->staff [0] ['sid'];
  6947. $receiptDetail->item = $value ['name'];
  6948. $receiptDetail->itemCategory = $this->OTHER;
  6949. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6950. $receiptDetail->date = date ( "Y-m-d" );
  6951. $receiptDetail->cid = $cid;
  6952. $receiptDetail->rid = $rid;
  6953. $receiptDetail->status = 4;
  6954. $receiptDetail->insert ();
  6955. }
  6956. // 附件
  6957. if (! empty ( $enclosurName )) {
  6958. $enclosurArray = explode ( '-', $enclosurName );
  6959. foreach ( $enclosurArray as $value ) {
  6960. $enclosur = new enclosur ();
  6961. $enclosur->name = $value;
  6962. $enclosur->rid = $rid;
  6963. $enclosur->insert ();
  6964. }
  6965. }
  6966. // return "/referReceipt/".$rid;
  6967. }
  6968. return "/saeaBorad";
  6969. }
  6970. function approvedReceipt() {
  6971. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6972. Doo::loadModel ( 'receipt' );
  6973. Doo::loadModel ( 'receiptDetail' );
  6974. $receipt = new receipt ();
  6975. $receiptDetail = new receiptDetail ();
  6976. Doo::loadModel ( 'statistics' );
  6977. Doo::loadModel ( 'itemStatistics' );
  6978. $statistics = new statistics ();
  6979. $itemStatistics = new itemStatistics ();
  6980. Doo::loadModel ( "verify" );
  6981. $verify = new verify ();
  6982. // 审批状态的判定
  6983. $receiptDetailList = $receipt->getOne ( array (
  6984. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  6985. 'asArray' => true
  6986. ) );
  6987. if (empty ( $receiptDetailList ))
  6988. return "/saeaBorad";
  6989. $verifyDetail = $verify->getOne ( array (
  6990. 'where' => ' vid =' . $receiptDetailList ['verify'],
  6991. 'asArray' => true
  6992. ) );
  6993. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  6994. if (empty ( $receiptDetailList ['nowStaff'] )) {
  6995. $nowStaff = "";
  6996. $nowStaffList = array ();
  6997. if ($verifyDetail [0] [1] == 'ROLE') {
  6998. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  6999. foreach ( $vStaffString as $key => $value ) {
  7000. $staffK = explode ( "_", $value );
  7001. array_push ( $nowStaffList, $staffK [0] );
  7002. }
  7003. $nowStaff = implode ( ',', $nowStaffList );
  7004. } else {
  7005. $nowStaff = $verifyDetail [0] [0];
  7006. }
  7007. $receipt->nowStaff = $nowStaff;
  7008. }
  7009. // echo $nowStaff;
  7010. // print_r($verifyDetail);die;
  7011. $receipt->rid = $receiptDetailList ['rid'];
  7012. $receipt->date = date ( "Y-m-d" );
  7013. $receipt->status = 2;
  7014. $receipt->update ();
  7015. $receiptDetail->status = 2;
  7016. $receiptDetail->update ( array (
  7017. 'where' => 'rid=' . $receiptDetailList ['rid']
  7018. ) );
  7019. Doo::loadModel ( "receiptLog" );
  7020. $receiptLog = new receiptLog ();
  7021. Doo::loadModel ( "verify" );
  7022. $verify = new verify ();
  7023. $receiptInfo = $receipt->getOne ( array (
  7024. 'where' => 'rid=' . $rid,
  7025. 'asArray' => true
  7026. ) );
  7027. $vr = $verify->getOne ( array (
  7028. 'where' => 'vid=' . $receiptInfo ['verify'],
  7029. 'asArray' => true
  7030. ) );
  7031. $jd = json_decode ( $vr ['staff'] );
  7032. $roleId = 0;
  7033. foreach ( $jd as $key => $value ) {
  7034. if ($value [1] == 'ROLE') {
  7035. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7036. if ($pos !== false) {
  7037. $roleId = $value [0];
  7038. }
  7039. }
  7040. }
  7041. // 审批日志
  7042. // echo $roleId;die;
  7043. if (! empty ( $roleId )) {
  7044. Doo::loadModel ( "role" );
  7045. $role = new role ();
  7046. $roleInfo = $role->getOne ( array (
  7047. 'where' => 'rid=' . $roleId,
  7048. 'asArray' => true
  7049. ) );
  7050. // $receiptLog->rolename = $roleInfo ['name'];
  7051. }
  7052. $receiptLog->username = $this->staff [0] ['username'];
  7053. $receiptLog->uid = $this->staff [0] ['sid'];
  7054. $receiptLog->date = date ( "Y-m-d" );
  7055. $receiptLog->opinion = '提交审批';
  7056. $receiptLog->img = $this->staff [0] ['avatar'];
  7057. $receiptLog->status = 2;
  7058. $receiptLog->rid = $rid;
  7059. $receiptLog->insert ();
  7060. // statistics item
  7061. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7062. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7063. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7064. $stat = $statistics->getOne ( array (
  7065. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7066. 'asArray' => true
  7067. ) );
  7068. if (empty ( $stat )) {
  7069. $statistics->date = date ( "Y-m-d" );
  7070. $statistics->cid = $this->staff [0] ['cid'];
  7071. $statistics->staff = $this->staff [0] ['sid'];
  7072. $statistics->agPrice = 0;
  7073. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7074. $statistics->insert ();
  7075. } else {
  7076. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7077. $statistics->update ( array (
  7078. 'where' => 'sid=' . $stat ['sid']
  7079. ) );
  7080. }
  7081. return "/expenses";
  7082. }
  7083. function approval() {
  7084. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7085. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7086. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7087. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7088. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7089. if (empty ( $status ))
  7090. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7091. $vidList = array ();
  7092. $button = 0;
  7093. Doo::loadModel ( 'verify' );
  7094. $verify = new verify ();
  7095. Doo::loadModel ( 'receipt' );
  7096. $receipt = new receipt ();
  7097. Doo::loadModel ( 'staff' );
  7098. $staff = new staff ();
  7099. Doo::loadModel ( 'L_category' );
  7100. $Lcategory = new L_category ();
  7101. // user verify ID
  7102. $verifyDetail = $verify->find ( array (
  7103. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7104. 'asArray' => true
  7105. ) );
  7106. foreach ( $verifyDetail as $key => $value ) {
  7107. array_push ( $vidList, $value ['vid'] );
  7108. }
  7109. $vid = implode ( ",", $vidList );
  7110. if (empty ( $verifyDetail ))
  7111. $vid = 0;
  7112. /*
  7113. */
  7114. $dateCondition = " and Year(date) =" . $year;
  7115. if (! empty ( $month ))
  7116. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7117. $categoryList = $Lcategory->find ( array (
  7118. 'asArray' => true
  7119. ) );
  7120. $staffList = $staff->find ( array (
  7121. 'where' => 'cid=' . $cid,
  7122. 'asArray' => true
  7123. ) );
  7124. $cateCondition = "";
  7125. $staffCondition = "";
  7126. $approvalCondition = "";
  7127. if (! empty ( $cid ))
  7128. $cateCondition = ' and cid=' . $cid;
  7129. if (! empty ( $sid )) {
  7130. $staffCondition = ' and staff=' . $sid;
  7131. $cateCondition = "";
  7132. }
  7133. // elseif($status==1){
  7134. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7135. // }
  7136. if ($status == 2) {
  7137. // 查找角色审批人
  7138. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7139. }
  7140. $ap = "";
  7141. if ($status == 4) {
  7142. $ap = 4;
  7143. $status = 2;
  7144. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7145. }
  7146. if ($status == 5) {
  7147. $status = 4;
  7148. $ap = 5;
  7149. }
  7150. // echo $vid;
  7151. // get Receipt By verifyID status 2 .$approvalCondition
  7152. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7153. $receiptList = $receipt->find ( array (
  7154. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7155. 'desc' => 'rid',
  7156. 'asArray' => true
  7157. ) );
  7158. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7159. $Locate = 0;
  7160. if ($ap == 4)
  7161. $status = 4;
  7162. elseif ($ap == 5)
  7163. $status = 5;
  7164. foreach ( $receiptList as $key => $value ) {
  7165. $receiptList [$key] ['Locate'] = $Locate;
  7166. $Locate ++;
  7167. $receiptList [$key] ['reviseDetail'] = array ();
  7168. if (! empty ( $value ['reviseDetail'] ))
  7169. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7170. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7171. $categoryDetil = $Lcategory->getOne ( array (
  7172. 'where' => 'cid=' . $value ['cid'],
  7173. 'asArray' => true
  7174. ) );
  7175. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7176. $verifyList = $verify->getOne ( array (
  7177. 'where' => 'vid=' . $value ['verify'],
  7178. 'asArray' => true
  7179. ) );
  7180. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7181. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7182. foreach ( $verifyList as $k => $v ) {
  7183. // init verifyStaff
  7184. $verifyList [$k] ['date'] = "";
  7185. $verifyList [$k] ['opinion'] = "";
  7186. $verifyList [$k] ['status'] = "";
  7187. if (empty ( $verifyStaff )) {
  7188. $verifyList [$k] ['date'] = "";
  7189. $verifyList [$k] ['opinion'] = "";
  7190. if ($v [0] == $this->staff [0] ['sid']) {
  7191. $verifyList [$k] ['status'] = 4;
  7192. $button = 4;
  7193. }
  7194. } else {
  7195. $flag = true;
  7196. foreach ( $verifyStaff as $m => $u ) {
  7197. if ($v [0] == $m) {
  7198. $verifyList [$k] ['date'] = $u ['date'];
  7199. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7200. $verifyList [$k] ['status'] = $u ['status'];
  7201. $flag = false;
  7202. break;
  7203. }
  7204. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7205. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7206. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7207. }
  7208. if ($flag) { // 检测可编辑
  7209. if ($v [0] == $this->staff [0] ['sid']) {
  7210. $verifyList [$k] ['status'] = 4;
  7211. $button = 4;
  7212. }
  7213. }
  7214. }
  7215. }
  7216. $receiptList [$key] ['verifyList'] = $verifyList;
  7217. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7218. 'where' => 'sid=' . $value ['staff'],
  7219. 'asArray' => true
  7220. ) );
  7221. $receiptList [$key] ['button'] = $button;
  7222. }
  7223. // print_r($receiptList);die;
  7224. // $data['verifyDetail']=$verifyDetail;
  7225. $mothHtml = "";
  7226. for($i = 1; $i <= 12; $i ++) {
  7227. if ($month == $i)
  7228. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7229. else
  7230. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7231. }
  7232. $data ['mothHtml'] = $mothHtml;
  7233. $data ['receiptList'] = $receiptList;
  7234. $data ['receiptApprovalCount'] = count ( $receiptList );
  7235. $data ['status'] = $status;
  7236. $data ['year'] = $year;
  7237. $data ['categoryList'] = $categoryList;
  7238. $data ['staffList'] = $staffList;
  7239. $data ['cid'] = $cid;
  7240. $data ['sid'] = $sid;
  7241. $data ['ap'] = $ap;
  7242. $data ['memu'] = "receipt";
  7243. $data ['staff'] = $this->staff;
  7244. $data ['receiptMemu'] = 'approval';
  7245. $data ['verifyId'] = $this->verifyId;
  7246. $data ['executeId'] = $this->executeId;
  7247. $this->render ( "/admin/saea_reportList", $data );
  7248. }
  7249. function approvalDetails() {
  7250. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7251. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7252. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7253. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7254. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7255. Doo::loadModel ( 'verify' );
  7256. $verify = new verify ();
  7257. Doo::loadModel ( 'receipt' );
  7258. $receipt = new receipt ();
  7259. Doo::loadModel ( 'staff' );
  7260. $staff = new staff ();
  7261. Doo::loadModel ( 'L_category' );
  7262. $Lcategory = new L_category ();
  7263. Doo::loadModel ( 'enclosur' );
  7264. $enclosur = new enclosur ();
  7265. $vidList = array ();
  7266. $verifyDetail = $verify->find ( array (
  7267. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7268. 'asArray' => true
  7269. ) );
  7270. foreach ( $verifyDetail as $key => $value ) {
  7271. array_push ( $vidList, $value ['vid'] );
  7272. }
  7273. $vid = implode ( ",", $vidList );
  7274. if (empty ( $verifyDetail ))
  7275. $vid = 0;
  7276. $categoryList = $Lcategory->find ( array (
  7277. 'asArray' => true
  7278. ) );
  7279. $staffList = $staff->find ( array (
  7280. 'where' => 'cid=' . $cid,
  7281. 'asArray' => true
  7282. ) );
  7283. $ap = 0;
  7284. $receiptList = $receipt->find ( array (
  7285. 'where' => 'rid =' . $rid,
  7286. 'desc' => 'rid',
  7287. 'asArray' => true
  7288. ) );
  7289. $Locate = 0;
  7290. $roleId = 0;
  7291. $button = 0;
  7292. foreach ( $receiptList as $key => $value ) {
  7293. $receiptList [$key] ['Locate'] = $Locate;
  7294. $Locate ++;
  7295. $receiptList [$key] ['reviseDetail'] = array ();
  7296. if (! empty ( $value ['reviseDetail'] ))
  7297. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7298. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7299. $categoryDetil = $Lcategory->getOne ( array (
  7300. 'where' => 'cid=' . $value ['cid'],
  7301. 'asArray' => true
  7302. ) );
  7303. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7304. // 检测编辑状态
  7305. $verifyList = $verify->getOne ( array (
  7306. 'where' => 'vid=' . $value ['verify'],
  7307. 'asArray' => true
  7308. ) );
  7309. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7310. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7311. Doo::loadModel ( 'role' );
  7312. $role = new role ();
  7313. // print_r($verifyList);
  7314. $flag = true;
  7315. $roleKey = 0;
  7316. $endStaffArray = array ();
  7317. $roleArrayCopy = array ();
  7318. foreach ( $verifyList as $k => $v ) {
  7319. // init verifyStaff
  7320. if ($v [1] == 'ROLE') {
  7321. if (! empty ( $verifyStaff )) {
  7322. $endStaffArray = end ( $verifyStaff );
  7323. if ($v [0] == $endStaffArray ['nextStaff']) {
  7324. $roleId = $v [0];
  7325. }
  7326. }
  7327. $roleVerify = json_decode ( $v [3], true );
  7328. $roleKey = $k;
  7329. $roleArray = array ();
  7330. $rolename = $role->getOne ( array (
  7331. 'where' => 'rid=' . $v [0],
  7332. 'asArray' => true
  7333. ) );
  7334. foreach ( $roleVerify as $o => $p ) {
  7335. $staffID = explode ( '_', $p );
  7336. $staffInfo = $staff->getOne ( array (
  7337. 'where' => 'sid=' . $staffID [0],
  7338. 'asArray' => true
  7339. ) );
  7340. // print_r($staffID);
  7341. $exp = array (
  7342. 0 => $staffInfo ['sid'],
  7343. 1 => $staffID [1],
  7344. 2 => $staffInfo ['avatar'],
  7345. 'date' => '',
  7346. 'date' => '',
  7347. 'opinion' => '',
  7348. 'status' => '',
  7349. 'rolename' => $rolename ['name']
  7350. );
  7351. array_push ( $roleArray, $exp );
  7352. }
  7353. $roleArrayCopy [$v [0]] = $roleArray;
  7354. // $verifyList[$k]['roleArray']=$roleArray;
  7355. }
  7356. // print_r($roleArray);
  7357. $verifyList [$k] ['date'] = "";
  7358. $verifyList [$k] ['opinion'] = "";
  7359. $verifyList [$k] ['status'] = "";
  7360. if (empty ( $verifyStaff )) {
  7361. $verifyList [$k] ['date'] = "";
  7362. $verifyList [$k] ['opinion'] = "";
  7363. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7364. $verifyList [$k] ['status'] = 4;
  7365. $button = 4;
  7366. $flag = false;
  7367. }
  7368. } else {
  7369. foreach ( $verifyStaff as $m => $u ) {
  7370. if ($v [0] == $m) {
  7371. $verifyList [$k] ['date'] = $u ['date'];
  7372. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7373. $verifyList [$k] ['status'] = $u ['status'];
  7374. $flag = false;
  7375. break;
  7376. }
  7377. }
  7378. $endStaffArray = end ( $verifyStaff );
  7379. if (isset ( $endStaffArray ['ROLE'] )) {
  7380. } else {
  7381. $endKey = key ( $verifyStaff );
  7382. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7383. $button = 4;
  7384. $verifyList [$k] ['status'] = 4;
  7385. }
  7386. }
  7387. }
  7388. }
  7389. $rolename ['name'] = '';
  7390. if (! empty ( $roleId )) {
  7391. Doo::loadModel ( 'role' );
  7392. $role = new role ();
  7393. $rolename = $role->getOne ( array (
  7394. 'where' => 'rid=' . $roleId,
  7395. 'asArray' => true
  7396. ) );
  7397. }
  7398. if (! empty ( $verifyStaff ))
  7399. $endStaffArray = end ( $verifyStaff );
  7400. $KOP = false;
  7401. foreach ( $roleArrayCopy as $P => $A ) {
  7402. foreach ( $A as $MKI => $AVL ) {
  7403. if (! empty ( $verifyStaff )) {
  7404. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7405. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7406. $button = 4;
  7407. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7408. }
  7409. foreach ( $verifyStaff as $m => $u ) {
  7410. $AVLFK = $AVL [0] . '_R';
  7411. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7412. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7413. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7414. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7415. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7416. break;
  7417. }
  7418. }
  7419. } else {
  7420. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7421. $button = 4;
  7422. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7423. }
  7424. }
  7425. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7426. $KOP = true;
  7427. }
  7428. }
  7429. foreach ( $roleArrayCopy as $k => $v ) {
  7430. foreach ( $verifyList as $m => $n ) {
  7431. if ($n [0] == $k) {
  7432. array_splice ( $verifyList, $m, 1, $v );
  7433. }
  7434. }
  7435. }
  7436. $receiptList [$key] ['verifyList'] = $verifyList;
  7437. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7438. 'where' => 'sid=' . $value ['staff'],
  7439. 'asArray' => true
  7440. ) );
  7441. $receiptList [$key] ['button'] = $button;
  7442. }
  7443. $mothHtml = "";
  7444. for($i = 1; $i <= 12; $i ++) {
  7445. if ($month == $i)
  7446. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7447. else
  7448. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7449. }
  7450. // 获取审批日志
  7451. Doo::loadModel ( 'receiptLog' );
  7452. $receiptLog = new receiptLog ();
  7453. $rlList = array ();
  7454. $rlInfo = $receiptLog->getOne ( array (
  7455. 'where' => 'rid=' . $rid . ' and status=4',
  7456. 'asArray' => true
  7457. ) );
  7458. $tijdate = $receiptLog->getOne ( array (
  7459. 'where' => 'rid=' . $rid . ' and status=2',
  7460. 'asc' => 'rlid',
  7461. 'asArray' => true
  7462. ) );
  7463. if (! empty ( $rlInfo )) {
  7464. $rlList = $receiptLog->find ( array (
  7465. 'where' => 'rid=' . $rid,
  7466. 'asc' => 'rlid',
  7467. 'asArray' => true
  7468. ) );
  7469. }
  7470. $receiptList [0] ['rlList'] = $rlList;
  7471. $enclosurList = $enclosur->find ( array (
  7472. 'where' => 'rid=' . $rid,
  7473. 'asArray' => true
  7474. ) );
  7475. $enclosurHtml = '';
  7476. foreach ( $enclosurList as $value ) {
  7477. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7478. }
  7479. $data ['enclosurHtml'] = $enclosurHtml;
  7480. $data ['rolename'] = $rolename ['name'];
  7481. $data ['datetij'] = $tijdate ['date'];
  7482. $data ['mothHtml'] = $mothHtml;
  7483. $data ['receiptList'] = $receiptList;
  7484. $data ['receiptApprovalCount'] = count ( $receiptList );
  7485. $data ['year'] = $year;
  7486. $data ['categoryList'] = $categoryList;
  7487. $data ['staffList'] = $staffList;
  7488. $data ['cid'] = $cid;
  7489. $data ['sid'] = $sid;
  7490. $data ['status'] = 0;
  7491. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7492. $ap = 4;
  7493. } else
  7494. $data ['status'] = $receiptList [0] ['status'];
  7495. if ($receiptList [0] ['status'] == 4) {
  7496. $data ['status'] = 5;
  7497. $ap = 0;
  7498. }
  7499. $data ['ap'] = $ap;
  7500. $data ['memu'] = "receipt";
  7501. $data ['staff'] = $this->staff;
  7502. $data ['receiptMemu'] = 'approval';
  7503. $data ['verifyId'] = $this->verifyId;
  7504. $data ['executeId'] = $this->executeId;
  7505. $this->render ( "/admin/saeaReportListReport", $data );
  7506. }
  7507. function approvalEdi() {
  7508. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7509. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7510. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7511. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7512. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7513. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7514. if (empty ( $status ))
  7515. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7516. $vidList = array ();
  7517. $button = 0;
  7518. Doo::loadModel ( 'verify' );
  7519. Doo::loadModel ( 'receipt' );
  7520. Doo::loadModel ( 'staff' );
  7521. $staff = new staff ();
  7522. $receipt = new receipt ();
  7523. $verify = new verify ();
  7524. Doo::loadModel ( 'L_category' );
  7525. $Lcategory = new L_category ();
  7526. Doo::loadModel ( 'enclosur' );
  7527. $enclosur = new enclosur ();
  7528. // user verify ID
  7529. $verifyDetail = $verify->find ( array (
  7530. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7531. 'asArray' => true
  7532. ) );
  7533. foreach ( $verifyDetail as $key => $value ) {
  7534. array_push ( $vidList, $value ['vid'] );
  7535. }
  7536. $vid = implode ( ",", $vidList );
  7537. if (empty ( $verifyDetail ))
  7538. $vid = 0;
  7539. $categoryList = $Lcategory->find ( array (
  7540. 'asArray' => true
  7541. ) );
  7542. $staffList = $staff->find ( array (
  7543. 'where' => 'cid=' . $cid,
  7544. 'asArray' => true
  7545. ) );
  7546. $ap = "";
  7547. if ($status == 4) {
  7548. $ap = 4;
  7549. $status = 2;
  7550. }
  7551. // get Receipt By verifyID status 2
  7552. $receiptList = $receipt->find ( array (
  7553. 'where' => 'rid =' . $rid,
  7554. 'desc' => 'rid',
  7555. 'asArray' => true
  7556. ) );
  7557. $Locate = 0;
  7558. $roleId = 0;
  7559. if ($ap == 4)
  7560. $status = 4;
  7561. foreach ( $receiptList as $key => $value ) {
  7562. $receiptList [$key] ['Locate'] = $Locate;
  7563. $Locate ++;
  7564. $receiptList [$key] ['reviseDetail'] = array ();
  7565. if (! empty ( $value ['reviseDetail'] ))
  7566. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7567. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7568. $categoryDetil = $Lcategory->getOne ( array (
  7569. 'where' => 'cid=' . $value ['cid'],
  7570. 'asArray' => true
  7571. ) );
  7572. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7573. // 检测编辑状态
  7574. $verifyList = $verify->getOne ( array (
  7575. 'where' => 'vid=' . $value ['verify'],
  7576. 'asArray' => true
  7577. ) );
  7578. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7579. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7580. // print_r($verifyList);
  7581. //
  7582. // if (empty($verifyStaff)){
  7583. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7584. // $verifyList[0]['status']=4;$button=4;
  7585. // }
  7586. //
  7587. // }else{
  7588. //
  7589. // }
  7590. // die;
  7591. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7592. // echo array_search("green",$a);
  7593. //
  7594. Doo::loadModel ( 'role' );
  7595. $role = new role ();
  7596. // print_r($verifyList);
  7597. $flag = true;
  7598. $roleKey = 0;
  7599. $endStaffArray = array ();
  7600. $roleArrayCopy = array ();
  7601. foreach ( $verifyList as $k => $v ) {
  7602. // init verifyStaff
  7603. if ($v [1] == 'ROLE') {
  7604. if (! empty ( $verifyStaff )) {
  7605. $endStaffArray = end ( $verifyStaff );
  7606. if ($v [0] == $endStaffArray ['nextStaff']) {
  7607. $roleId = $v [0];
  7608. }
  7609. }
  7610. $roleVerify = json_decode ( $v [3], true );
  7611. $roleKey = $k;
  7612. $roleArray = array ();
  7613. $rolename = $role->getOne ( array (
  7614. 'where' => 'rid=' . $v [0],
  7615. 'asArray' => true
  7616. ) );
  7617. foreach ( $roleVerify as $o => $p ) {
  7618. $staffID = explode ( '_', $p );
  7619. $staffInfo = $staff->getOne ( array (
  7620. 'where' => 'sid=' . $staffID [0],
  7621. 'asArray' => true
  7622. ) );
  7623. // print_r($staffID);
  7624. $exp = array (
  7625. 0 => $staffInfo ['sid'],
  7626. 1 => $staffID [1],
  7627. 2 => $staffInfo ['avatar'],
  7628. 'date' => '',
  7629. 'date' => '',
  7630. 'opinion' => '',
  7631. 'status' => '',
  7632. 'rolename' => $rolename ['name']
  7633. );
  7634. array_push ( $roleArray, $exp );
  7635. }
  7636. $roleArrayCopy [$v [0]] = $roleArray;
  7637. // $verifyList[$k]['roleArray']=$roleArray;
  7638. }
  7639. // print_r($roleArray);
  7640. $verifyList [$k] ['date'] = "";
  7641. $verifyList [$k] ['opinion'] = "";
  7642. $verifyList [$k] ['status'] = "";
  7643. if (empty ( $verifyStaff )) {
  7644. $verifyList [$k] ['date'] = "";
  7645. $verifyList [$k] ['opinion'] = "";
  7646. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7647. $verifyList [$k] ['status'] = 4;
  7648. $button = 4;
  7649. $flag = false;
  7650. }
  7651. } else {
  7652. foreach ( $verifyStaff as $m => $u ) {
  7653. if ($v [0] == $m) {
  7654. $verifyList [$k] ['date'] = $u ['date'];
  7655. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7656. $verifyList [$k] ['status'] = $u ['status'];
  7657. $flag = false;
  7658. break;
  7659. }
  7660. }
  7661. $endStaffArray = end ( $verifyStaff );
  7662. if (isset ( $endStaffArray ['ROLE'] )) {
  7663. } else {
  7664. $endKey = key ( $verifyStaff );
  7665. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7666. $button = 4;
  7667. $verifyList [$k] ['status'] = 4;
  7668. }
  7669. }
  7670. // print_r($endStaffArray);die;
  7671. // if (empty($verifyStaff)){
  7672. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7673. // $verifyList[$k]['status']=4;$button=4;
  7674. // }
  7675. //
  7676. // }else{
  7677. //
  7678. // }
  7679. // if($flag){//检测可编辑
  7680. // if($v[0]==$this->staff[0]['sid']){
  7681. // $verifyList[$k]['status']=4;$button=4;
  7682. // }
  7683. // }
  7684. }
  7685. }
  7686. $rolename ['name'] = '';
  7687. if (! empty ( $roleId )) {
  7688. Doo::loadModel ( 'role' );
  7689. $role = new role ();
  7690. $rolename = $role->getOne ( array (
  7691. 'where' => 'rid=' . $roleId,
  7692. 'asArray' => true
  7693. ) );
  7694. }
  7695. if (! empty ( $verifyStaff ))
  7696. $endStaffArray = end ( $verifyStaff );
  7697. $KOP = false;
  7698. foreach ( $roleArrayCopy as $P => $A ) {
  7699. foreach ( $A as $MKI => $AVL ) {
  7700. if (! empty ( $verifyStaff )) {
  7701. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7702. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7703. $button = 4;
  7704. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7705. }
  7706. foreach ( $verifyStaff as $m => $u ) {
  7707. $AVLFK = $AVL [0] . '_R';
  7708. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7709. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7710. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7711. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7712. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7713. break;
  7714. }
  7715. }
  7716. } else {
  7717. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7718. $button = 4;
  7719. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7720. }
  7721. }
  7722. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7723. $KOP = true;
  7724. }
  7725. }
  7726. // print_r($roleArrayCopy);
  7727. // echo $roleKey;
  7728. foreach ( $roleArrayCopy as $k => $v ) {
  7729. foreach ( $verifyList as $m => $n ) {
  7730. if ($n [0] == $k) {
  7731. array_splice ( $verifyList, $m, 1, $v );
  7732. }
  7733. }
  7734. }
  7735. // if ($KOP)
  7736. // array_splice($verifyList,$roleKey,1,$roleArray);
  7737. // print_r($verifyList);
  7738. $receiptList [$key] ['verifyList'] = $verifyList;
  7739. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7740. 'where' => 'sid=' . $value ['staff'],
  7741. 'asArray' => true
  7742. ) );
  7743. $receiptList [$key] ['button'] = $button;
  7744. }
  7745. // $data['verifyDetail']=$verifyDetail;
  7746. $mothHtml = "";
  7747. for($i = 1; $i <= 12; $i ++) {
  7748. if ($month == $i)
  7749. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7750. else
  7751. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7752. }
  7753. // 获取审批日志
  7754. Doo::loadModel ( 'receiptLog' );
  7755. $receiptLog = new receiptLog ();
  7756. $rlList = array ();
  7757. $rlInfo = $receiptLog->getOne ( array (
  7758. 'where' => 'rid=' . $rid . ' and status=4',
  7759. 'asArray' => true
  7760. ) );
  7761. $tijdate = $receiptLog->getOne ( array (
  7762. 'where' => 'rid=' . $rid . ' and status=2',
  7763. 'asc' => 'rlid',
  7764. 'asArray' => true
  7765. ) );
  7766. if (! empty ( $rlInfo )) {
  7767. $rlList = $receiptLog->find ( array (
  7768. 'where' => 'rid=' . $rid,
  7769. 'asc' => 'rlid',
  7770. 'asArray' => true
  7771. ) );
  7772. }
  7773. $receiptList [0] ['rlList'] = $rlList;
  7774. $enclosurList = $enclosur->find ( array (
  7775. 'where' => 'rid=' . $rid,
  7776. 'asArray' => true
  7777. ) );
  7778. $enclosurHtml = '';
  7779. foreach ( $enclosurList as $value ) {
  7780. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7781. }
  7782. $data ['enclosurHtml'] = $enclosurHtml;
  7783. $data ['rolename'] = $rolename ['name'];
  7784. $data ['datetij'] = $tijdate ['date'];
  7785. $data ['mothHtml'] = $mothHtml;
  7786. $data ['receiptList'] = $receiptList;
  7787. $data ['receiptApprovalCount'] = count ( $receiptList );
  7788. $data ['status'] = $status;
  7789. $data ['year'] = $year;
  7790. $data ['categoryList'] = $categoryList;
  7791. $data ['staffList'] = $staffList;
  7792. $data ['cid'] = $cid;
  7793. $data ['sid'] = $sid;
  7794. $data ['ap'] = $ap;
  7795. $data ['memu'] = "receipt";
  7796. $data ['staff'] = $this->staff;
  7797. $data ['receiptMemu'] = 'approval';
  7798. $data ['verifyId'] = $this->verifyId;
  7799. $data ['executeId'] = $this->executeId;
  7800. $this->render ( "/admin/saeaReportListReport", $data );
  7801. }
  7802. function remittanceHky() {
  7803. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7804. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7805. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7806. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7807. $page_size = 15;
  7808. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7809. Doo::loadModel ( 'receipt' );
  7810. $receipt = new receipt ();
  7811. Doo::loadModel ( 'staff' );
  7812. $staff = new staff ();
  7813. $dateCondition = " and Year(executeDate) =" . $year;
  7814. if ($moth != 'MONTH')
  7815. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7816. if ($day != 'DAY' && $moth != 'MONTH')
  7817. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7818. $sql = ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition;
  7819. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7820. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7821. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7822. $dayList = $receipt->find ( array (
  7823. 'select' => 'executeDate,sum(amount) as amount',
  7824. 'where' => $sql,
  7825. 'desc' => 'executeDate',
  7826. 'groupby' => 'executeDate',
  7827. 'limit' => $limit,
  7828. 'asArray' => true
  7829. ) );
  7830. // print_r($dayList);
  7831. foreach ( $dayList as $key => $value ) {
  7832. $remitString = "";
  7833. $receiptList = $receipt->find ( array (
  7834. 'select' => 'rid,executeDate,amount,staff,cid',
  7835. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7836. 'desc' => 'executeDate',
  7837. 'asArray' => true
  7838. ) );
  7839. foreach ( $receiptList as $k => $v ) {
  7840. $sinfo = $staff->getOne ( array (
  7841. 'select' => 'username,category',
  7842. 'where' => ' sid=' . $v ['staff'],
  7843. 'asArray' => true
  7844. ) );
  7845. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7846. }
  7847. $dayList [$key] ['staff'] = $remitString;
  7848. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7849. }
  7850. // print_r($dayList);
  7851. $mothHtml = "";
  7852. for($i = 1; $i <= 12; $i ++) {
  7853. if ($moth == $i)
  7854. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7855. else
  7856. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7857. }
  7858. $dayHtml = "";
  7859. if ($day != "DAY" || $moth != "MONTH") {
  7860. for($i = 1; $i <= 31; $i ++) {
  7861. if ($day == $i)
  7862. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7863. else
  7864. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7865. }
  7866. }
  7867. $dateHtml = "";
  7868. $now = date ( "Y" );
  7869. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7870. if ($YEARD <= $now) {
  7871. $dateHtml .= '<option ';
  7872. if ($year == $YEARD) {
  7873. $dateHtml .= 'selected ';
  7874. }
  7875. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7876. }
  7877. }
  7878. $data ['dateHtml'] = $dateHtml;
  7879. $data ['page'] = $pageinfo;
  7880. $data ['year'] = $year;
  7881. $data ['moth'] = $moth;
  7882. $data ['day'] = $day;
  7883. $data ['get'] = $get;
  7884. $data ['dayHtml'] = $dayHtml;
  7885. $data ['mothHtml'] = $mothHtml;
  7886. $data ['receiptList'] = $dayList;
  7887. $data ['memu'] = "receipt";
  7888. $data ['staff'] = $this->staff;
  7889. $data ['receiptMemu'] = 'remittanceHky';
  7890. $data ['verifyId'] = $this->verifyId;
  7891. $data ['executeId'] = $this->executeId;
  7892. $this->render ( "/admin/remittanceHky", $data );
  7893. }
  7894. function remittancep() {
  7895. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7896. Doo::loadModel ( 'receipt' );
  7897. $receipt = new receipt ();
  7898. Doo::loadModel ( 'staff' );
  7899. $staff = new staff ();
  7900. Doo::loadClass ( 'XDeode' );
  7901. $XDeode = new XDeode ( 5 );
  7902. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7903. $rplist = $receipt->find ( array (
  7904. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7905. 'asArray' => true
  7906. ) );
  7907. $dayList = $receipt->find ( array (
  7908. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7909. 'desc' => 'executeDate',
  7910. 'groupby' => 'staff',
  7911. 'asArray' => true
  7912. ) );
  7913. $html = '';
  7914. foreach ( $dayList as $key => $value ) {
  7915. $sinfo = $staff->getOne ( array (
  7916. 'select' => 'username,category',
  7917. 'where' => ' sid=' . $value ['staff'],
  7918. 'asArray' => true
  7919. ) );
  7920. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  7921. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  7922. $au = 0;
  7923. foreach ( $rplist as $k => $v ) {
  7924. if ($value ['staff'] == $v ['staff']) {
  7925. $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>';
  7926. $au += $v ['amount'];
  7927. }
  7928. }
  7929. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  7930. }
  7931. $data ['html'] = $html;
  7932. $data ['memu'] = "receipt";
  7933. $data ['staff'] = $this->staff;
  7934. $data ['receiptMemu'] = 'remittanceHky';
  7935. $data ['verifyId'] = $this->verifyId;
  7936. $data ['executeId'] = $this->executeId;
  7937. $this->render ( "/admin/remittancep", $data );
  7938. }
  7939. function ajaxGetReceiptDetails() {
  7940. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  7941. Doo::loadClass ( 'XDeode' );
  7942. $XDeode = new XDeode ( 5 );
  7943. $rid = $XDeode->decode ( $rid );
  7944. if (empty ( $rid )) {
  7945. echo json_encode ( array (
  7946. 'status' => 2,
  7947. 'msg' => 'illegal request'
  7948. ) );
  7949. die ();
  7950. }
  7951. Doo::loadModel ( 'receipt' );
  7952. $receipt = new receipt ();
  7953. Doo::loadModel ( 'staff' );
  7954. $staff = new staff ();
  7955. $rinfo = $receipt->getOne ( array (
  7956. 'where' => 'rid= ' . $rid,
  7957. 'asArray' => true
  7958. ) );
  7959. $sinfo = $staff->getOne ( array (
  7960. 'select' => 'username,category',
  7961. 'where' => ' sid=' . $rinfo ['staff'],
  7962. 'asArray' => true
  7963. ) );
  7964. $rinfo ['reviseDetail'] = array ();
  7965. if (! empty ( $rinfo ['reviseDetail'] ))
  7966. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  7967. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  7968. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  7969. $rinfo ['category'] = $sinfo ['category'];
  7970. $verifyStaff = array ();
  7971. if (! empty ( $rinfo ['verifyStaff'] ))
  7972. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  7973. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  7974. $rinfo ['relust'] = $relust;
  7975. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  7976. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  7977. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  7978. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  7979. // 费用执行人相关数据
  7980. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  7981. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  7982. foreach ( $executeCopy as $k => $v ) {
  7983. $executeCopy [$k] ['date'] = '';
  7984. $executeCopy [$k] ['opinion'] = '';
  7985. $executeCopy [$k] ['status'] = '';
  7986. if (! empty ( $executeStaff ))
  7987. foreach ( $executeStaff as $m => $u ) {
  7988. if ($v [0] == $m) {
  7989. $executeCopy [$k] ['date'] = $u ['date'];
  7990. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  7991. $executeCopy [$k] ['status'] = $u ['status'];
  7992. break;
  7993. }
  7994. }
  7995. }
  7996. $rinfo ['executeCopy'] = $executeCopy;
  7997. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  7998. if ($rinfo ['Rtype'] == 1) { // 借款费用
  7999. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8000. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8001. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8002. $html .= '<tr><th>' . $value ['name'] . '</th>
  8003. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8004. }
  8005. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8006. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8007. <tr><th class="taC" colspan="2">费用说明</th>
  8008. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8009. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8010. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8011. </tbody></table>';
  8012. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8013. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8014. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8015. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8016. $html .= '<tr><th>' . $value ['name'] . '</th>
  8017. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8018. }
  8019. $html .= '<tr><th class="taR">合计</th>
  8020. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8021. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8022. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8023. $html .= '<tr><th>' . $value ['name'] . '</th>
  8024. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8025. }
  8026. $html .= '<tr><th class="taR">合计</th>
  8027. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8028. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8029. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8030. $html .= '<tr><th>' . $value ['name'] . '</th>
  8031. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8032. }
  8033. $html .= '<tr><th class="taR">合计</th>
  8034. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8035. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8036. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8037. $html .= '<tr><th>' . $value ['name'] . '</th>
  8038. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8039. }
  8040. $html .= '<tr><th class="taR">合计</th>
  8041. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8042. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8043. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8044. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8045. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8046. }
  8047. $html .= '<tr><th class="taR">合计</th>
  8048. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8049. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8050. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8051. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8052. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8053. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8054. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8055. <tr';
  8056. if ($rinfo ['relust'] >= 0) {
  8057. $html .= 'class="success"';
  8058. } else {
  8059. $html .= 'class="error"';
  8060. }
  8061. $html .= '><td class="taR"><b>借款结余</b></td>
  8062. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8063. </tbody></table>
  8064. ';
  8065. }
  8066. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8067. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8068. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8069. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8070. $html .= '<tr><th>' . $value ['name'] . '</th>
  8071. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8072. }
  8073. $html .= '<tr><th class="taR">合计</th>
  8074. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8075. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8076. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8077. <tr><th class="taC" colspan="2">费用说明</th>
  8078. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8079. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8080. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8081. </tbody></table>';
  8082. } else {
  8083. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8084. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8085. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8086. $html .= '<tr><th>' . $value ['name'] . '</th>
  8087. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8088. }
  8089. $html .= '<tr><th class="taR">合计</th>
  8090. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8091. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8092. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8093. $html .= '<tr><th>' . $value ['name'] . '</th>
  8094. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8095. }
  8096. $html .= '<tr><th class="taR">合计</th>
  8097. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8098. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8099. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8100. $html .= '<tr><th>' . $value ['name'] . '</th>
  8101. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8102. }
  8103. $html .= '<tr><th class="taR">合计</th>
  8104. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8105. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8106. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8107. $html .= '<tr><th>' . $value ['name'] . '</th>
  8108. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8109. }
  8110. $html .= '<tr><th class="taR">合计</th>
  8111. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8112. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8113. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8114. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8115. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8116. }
  8117. $html .= '<tr><th class="taR">合计</th>
  8118. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8119. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8120. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8121. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8122. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8123. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8124. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8125. $html .= '</tbody></table>';
  8126. /*
  8127. * <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>
  8128. */
  8129. }
  8130. // print_r($verifyStaff);die;
  8131. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8132. foreach ( $verifyStaff as $key => $value ) {
  8133. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8134. $sinfo = $staff->getOne ( array (
  8135. 'select' => 'username',
  8136. 'where' => ' sid=' . $key,
  8137. 'asArray' => true
  8138. ) );
  8139. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8140. }
  8141. $html .= '</tbody></table>';
  8142. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8143. foreach ( $rinfo ['executeCopy'] as $value ) {
  8144. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8145. }
  8146. $html .= '</tbody></table>';
  8147. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8148. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8149. </tr></table>';
  8150. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8151. echo json_encode ( array (
  8152. 'status' => 1,
  8153. 'html' => $html
  8154. ) );
  8155. die ();
  8156. }
  8157. /**
  8158. * 删除附件
  8159. */
  8160. function ajaxRemEnclousur() {
  8161. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8162. if (empty ( $key ))
  8163. echo json_encode ( array (
  8164. 'status' => 2
  8165. ) );
  8166. Doo::loadModel ( 'enclosur' );
  8167. $enclosur = new enclosur ();
  8168. $enclosur->delEnclosurByEid ( $key );
  8169. echo json_encode ( array (
  8170. 'status' => 1
  8171. ) );
  8172. }
  8173. function remittance() {
  8174. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8175. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8176. Doo::loadModel ( 'receipt' );
  8177. $receipt = new receipt ();
  8178. Doo::loadModel ( 'staff' );
  8179. $staff = new staff ();
  8180. $dateCondition = " and Year(pastDate) =" . $year;
  8181. if (! empty ( $month ))
  8182. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8183. // get Receipt By verifyID status 1
  8184. $receiptList = $receipt->find ( array (
  8185. 'select' => 'sum(sum) as sum,staff,pastDate',
  8186. 'where' => ' status=1' . $dateCondition,
  8187. 'desc' => 'pastDate',
  8188. 'groupby' => 'staff,pastDate',
  8189. 'asArray' => true
  8190. ) );
  8191. $dateList = $receipt->find ( array (
  8192. 'select' => 'pastDate,verifyStaff',
  8193. 'where' => ' status=1' . $dateCondition,
  8194. 'desc' => 'pastDate',
  8195. 'groupby' => 'pastDate',
  8196. 'asArray' => true
  8197. ) );
  8198. $dataList = array ();
  8199. foreach ( $dateList as $d => $a ) {
  8200. $dataList [$a ['pastDate']] = array ();
  8201. $daySum = 0;
  8202. foreach ( $receiptList as $key => $value ) {
  8203. if ($a ['pastDate'] == $value ['pastDate']) {
  8204. $oderList = $receipt->find ( array (
  8205. 'select' => 'receiptOrder',
  8206. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8207. 'asArray' => true
  8208. ) );
  8209. $list = array ();
  8210. $html = "";
  8211. foreach ( $oderList as $v ) {
  8212. array_push ( $list, $v ['receiptOrder'] );
  8213. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8214. }
  8215. $receiptList [$key] ['receiptOrder'] = $html;
  8216. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8217. $sinfo = $staff->getOne ( array (
  8218. 'select' => 'username ',
  8219. 'where' => ' sid=' . $value ['staff'],
  8220. 'asArray' => true
  8221. ) );
  8222. $receiptList [$key] ['username'] = $sinfo ['username'];
  8223. $daySum += $value ['sum'];
  8224. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8225. }
  8226. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8227. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8228. }
  8229. }
  8230. // print_r($dataList);
  8231. $data ['dataList'] = $dataList;
  8232. $mothHtml = "";
  8233. for($i = 1; $i <= 12; $i ++) {
  8234. if ($month == $i)
  8235. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8236. else
  8237. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8238. }
  8239. $data ['year'] = $year;
  8240. $data ['mothHtml'] = $mothHtml;
  8241. $data ['memu'] = "receipt";
  8242. $data ['staff'] = $this->staff;
  8243. $data ['receiptMemu'] = 'approval';
  8244. $data ['verifyId'] = $this->verifyId;
  8245. $data ['executeId'] = $this->executeId;
  8246. $this->render ( "/admin/saeaReportListPay", $data );
  8247. }
  8248. /**
  8249. * 金额调整,提高稳定性
  8250. * @return string
  8251. */
  8252. function revocationAdjustment() {
  8253. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8254. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8255. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8256. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8257. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8258. Doo::loadClass ( 'XDeode' );
  8259. $XDeode = new XDeode ( 5 );
  8260. Doo::loadModel ( 'receipt' );
  8261. $receipt = new receipt ();
  8262. $sid = $XDeode->decode ( $sidKey );
  8263. $rid = $XDeode->decode ( $ridKey );
  8264. $reviseKey = $XDeode->decode ( $reviseKey );
  8265. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8266. die ( 'illegal request' );
  8267. $receiptDetail = $receipt->getOne ( array (
  8268. 'where' => 'rid=' . $rid,
  8269. 'asArray' => true
  8270. ) );
  8271. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8272. die ( 'illegal request' );
  8273. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8274. if (! isset ( $reviseDetail [$reviseKey] ))
  8275. die ( 'illegal request' );
  8276. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8277. unset ( $reviseDetail [$reviseKey] );
  8278. $revisePrice = 0;
  8279. foreach ( $reviseDetail as $key => $value ) {
  8280. $revisePrice += $value ['price'];
  8281. }
  8282. $reviseDetailString = json_encode ( $reviseDetail );
  8283. $receipt->reviseDetail = $reviseDetailString;
  8284. $receipt->sum = $receiptDetail ['sum'] - $price;
  8285. $receipt->revisePrice = $revisePrice;
  8286. $receipt->update ( array (
  8287. 'where' => 'rid=' . $rid
  8288. ) );
  8289. return '/receiptburEdi/' . $rid;
  8290. } else
  8291. die ( 'illegal request2' );
  8292. }
  8293. function updateApprovalReceipt() {
  8294. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8295. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8296. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8297. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8298. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8299. if (! empty ( $rid )) {
  8300. Doo::loadModel ( "verify" );
  8301. $verify = new verify ();
  8302. Doo::loadModel ( "receiptDetail" );
  8303. $receiptDetailObj = new receiptDetail ();
  8304. Doo::loadModel ( "itemStatistics" );
  8305. Doo::loadModel ( "statistics" );
  8306. $statistics = new statistics ();
  8307. $itemStatistics = new itemStatistics ();
  8308. Doo::loadModel ( "receipt" );
  8309. $receipt = new receipt ();
  8310. $receiptDetail = $receipt->getOne ( array (
  8311. 'where' => 'rid=' . $rid . ' and status=2 ',
  8312. 'asArray' => true
  8313. ) );
  8314. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8315. $nsflag = true;
  8316. foreach ( $nslist as $value ) {
  8317. if ($value == $this->staff ['0'] ['sid']) {
  8318. $nsflag = false;
  8319. break;
  8320. }
  8321. }
  8322. if (empty ( $receiptDetail ) || $nsflag)
  8323. return "/approvalExpenses/pendApproval";
  8324. $verifyDetail = $verify->getOne ( array (
  8325. 'where' => ' vid =' . $receiptDetail ['verify'],
  8326. 'asArray' => true
  8327. ) );
  8328. $verifyString = $verifyDetail ['staff'];
  8329. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8330. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8331. if (empty ( $opinion )) {
  8332. if ($status == 3)
  8333. $opinion = "终止";
  8334. else
  8335. $opinion = "同意支付";
  8336. }
  8337. $nowStaff = 0;
  8338. $nowStaffList = array ();
  8339. if (empty ( $verifyStaff )) {
  8340. // 还需加入是否已经进入角色审批
  8341. if ($verifyDetail [0] [1] == 'ROLE') {
  8342. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8343. foreach ( $vStaffString as $key => $value ) {
  8344. $staffK = explode ( "_", $value );
  8345. if ($staffK [0] != $this->staff [0] ['sid'])
  8346. array_push ( $nowStaffList, $staffK [0] );
  8347. }
  8348. // print_r($verifyDetail);
  8349. // die;
  8350. if (! empty ( $nowStaffList )) {
  8351. $nowStaff = implode ( ',', $nowStaffList );
  8352. $verifyStaff = array (
  8353. $this->staff [0] ['sid'] . "_R" => array (
  8354. 'date' => date ( 'Y-m-d' ),
  8355. 'opinion' => $opinion,
  8356. 'status' => $status,
  8357. 'nextStaff' => $verifyDetail [0] [0],
  8358. 'ROLE' => 1
  8359. )
  8360. );
  8361. } else {
  8362. $nowStaff = $verifyDetail [1] [0];
  8363. $verifyStaff = array (
  8364. $this->staff [0] ['sid'] . "_R" => array (
  8365. 'date' => date ( 'Y-m-d' ),
  8366. 'opinion' => $opinion,
  8367. 'status' => $status,
  8368. 'nextStaff' => $verifyDetail [1] [0]
  8369. )
  8370. );
  8371. }
  8372. } else {
  8373. if ($verifyDetail [1] [1] == 'ROLE') {
  8374. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8375. // echo "dd";
  8376. foreach ( $vStaffString as $key => $value ) {
  8377. $staffK = explode ( "_", $value );
  8378. array_push ( $nowStaffList, $staffK [0] );
  8379. }
  8380. $nowStaff = implode ( ',', $nowStaffList );
  8381. $verifyStaff = array (
  8382. $this->staff [0] ['sid'] => array (
  8383. 'date' => date ( 'Y-m-d' ),
  8384. 'opinion' => $opinion,
  8385. 'status' => $status,
  8386. 'nextStaff' => $verifyDetail [1] [0],
  8387. 'ROLE' => 1
  8388. )
  8389. );
  8390. } else {
  8391. $nowStaff = $verifyDetail [1] [0];
  8392. $verifyStaff = array (
  8393. $this->staff [0] ['sid'] => array (
  8394. 'date' => date ( 'Y-m-d' ),
  8395. 'opinion' => $opinion,
  8396. 'status' => $status,
  8397. 'nextStaff' => $verifyDetail [1] [0]
  8398. )
  8399. );
  8400. }
  8401. }
  8402. if ($status == 3)
  8403. $verifyStaff = array (
  8404. 'final' => $status,
  8405. $this->staff [0] ['sid'] => array (
  8406. 'date' => date ( 'Y-m-d' ),
  8407. 'opinion' => $opinion,
  8408. 'status' => $status
  8409. )
  8410. );
  8411. $vStaffString = json_encode ( $verifyStaff );
  8412. $receipt->nowStaff = $nowStaff;
  8413. $receipt->verifyStaff = $vStaffString;
  8414. } else {
  8415. $VS = end ( $verifyStaff );
  8416. // 非角色审批
  8417. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8418. $nextStaff = 0;
  8419. $roleSTF = false;
  8420. foreach ( $verifyDetail as $key => $value ) {
  8421. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8422. if (isset ( $verifyDetail [$key + 1] )) {
  8423. $nextStaff = $verifyDetail [$key + 1] [0];
  8424. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8425. $roleSTF = true;
  8426. }
  8427. break;
  8428. }
  8429. }
  8430. if (! $roleSTF) {
  8431. $nowStaff = $nextStaff;
  8432. $verifyStaff [$this->staff [0] ['sid']] = array (
  8433. 'date' => date ( 'Y-m-d' ),
  8434. 'opinion' => $opinion,
  8435. 'status' => $status,
  8436. 'nextStaff' => $nextStaff
  8437. );
  8438. } else {
  8439. // 获取角色下的所有用户ID
  8440. $nowStaffList = array ();
  8441. foreach ( $verifyDetail as $vfk ) {
  8442. if ($vfk [1] == 'ROLE') {
  8443. $vStaffString = json_decode ( $vfk [3] );
  8444. foreach ( $vStaffString as $key => $value ) {
  8445. $staffK = explode ( "_", $value );
  8446. array_push ( $nowStaffList, $staffK [0] );
  8447. }
  8448. }
  8449. }
  8450. $nowStaff = implode ( ',', $nowStaffList );
  8451. $verifyStaff [$this->staff [0] ['sid']] = array (
  8452. 'date' => date ( 'Y-m-d' ),
  8453. 'opinion' => $opinion,
  8454. 'status' => $status,
  8455. 'nextStaff' => $nextStaff,
  8456. 'ROLE' => 0
  8457. );
  8458. }
  8459. if ($status == 3) {
  8460. $verifyStaff ['final'] = $status;
  8461. $verifyStaff [$this->staff [0] ['sid']] = array (
  8462. 'date' => date ( 'Y-m-d' ),
  8463. 'opinion' => $opinion,
  8464. 'status' => $status
  8465. );
  8466. }
  8467. $vStaffString = json_encode ( $verifyStaff );
  8468. $receipt->nowStaff = $nowStaff;
  8469. $receipt->verifyStaff = $vStaffString;
  8470. }
  8471. // 角色审批
  8472. if (isset ( $VS ['ROLE'] )) {
  8473. // 找出角色人 当前审批角色组
  8474. $verifyJSStaff = array ();
  8475. $nowStaffList2 = array ();
  8476. foreach ( $verifyDetail as $key => $value ) {
  8477. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8478. $verifyJSStaff = json_decode ( $value [3] );
  8479. foreach ( $verifyJSStaff as $m ) {
  8480. $staffK = explode ( "_", $m );
  8481. array_push ( $nowStaffList2, $staffK [0] );
  8482. }
  8483. // print_r($nowStaffList2);
  8484. }
  8485. }
  8486. $RoleVerifyStaff = array ();
  8487. foreach ( $verifyStaff as $key => $value ) {
  8488. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8489. foreach ( $nowStaffList2 as $m ) {
  8490. if ($key == $m . "_R")
  8491. $RoleVerifyStaff [$key] = $value;
  8492. }
  8493. }
  8494. }
  8495. // print_r($verifyStaff);
  8496. // print_r($nowStaffList2);
  8497. // print_r($RoleVerifyStaff);
  8498. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8499. // print_r($verifyJSStaff);
  8500. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8501. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8502. // 下一个审批人ID
  8503. $nextStaff = 0;
  8504. $falg = false;
  8505. foreach ( $verifyDetail as $key => $value ) {
  8506. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8507. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8508. $falg = true;
  8509. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8510. $nowStaffList = array ();
  8511. foreach ( $vStaffString as $v ) {
  8512. $staffK = explode ( "_", $v );
  8513. array_push ( $nowStaffList, $staffK [0] );
  8514. }
  8515. $nowStaff = implode ( ',', $nowStaffList );
  8516. $nextStaff = $verifyDetail [$key + 1] [0];
  8517. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8518. $nextStaff = $verifyDetail [$key + 1] [0];
  8519. $nowStaff = $nextStaff;
  8520. } else
  8521. $nowStaff = '';
  8522. break;
  8523. }
  8524. }
  8525. if ($falg)
  8526. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8527. 'date' => date ( 'Y-m-d' ),
  8528. 'opinion' => $opinion,
  8529. 'status' => $status,
  8530. 'nextStaff' => $nextStaff,
  8531. 'ROLE' => 1
  8532. );
  8533. else
  8534. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8535. 'date' => date ( 'Y-m-d' ),
  8536. 'opinion' => $opinion,
  8537. 'status' => $status,
  8538. 'nextStaff' => $nextStaff
  8539. );
  8540. // print_r($verifyStaff);
  8541. // echo $nowStaff;die;
  8542. } else { // 进入下一个角色或者审批人
  8543. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8544. //
  8545. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8546. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8547. 'date' => date ( 'Y-m-d' ),
  8548. 'opinion' => $opinion,
  8549. 'status' => $status,
  8550. 'nextStaff' => $VS ['nextStaff'],
  8551. 'ROLE' => 1
  8552. );
  8553. // print_r($verifyStaff);
  8554. // die;
  8555. }
  8556. if ($status == 3) {
  8557. $verifyStaff ['final'] = $status;
  8558. $verifyStaff [$this->staff [0] ['sid']] = array (
  8559. 'date' => date ( 'Y-m-d' ),
  8560. 'opinion' => $opinion,
  8561. 'status' => $status
  8562. );
  8563. }
  8564. $vStaffString = json_encode ( $verifyStaff );
  8565. $receipt->verifyStaff = $vStaffString;
  8566. $receipt->nowStaff = $nowStaff;
  8567. // die;
  8568. // }
  8569. // print_r($verifyStaff);
  8570. // die;
  8571. }
  8572. // print_r($verifyStaff);die;
  8573. }
  8574. // print_r($verifyDetail);
  8575. $roleKey = 0;
  8576. $roleId = 0;
  8577. $verifyDetailCopy = array ();
  8578. foreach ( $verifyDetail as $k => $v ) {
  8579. if ($v [1] == 'ROLE') {
  8580. $roleId = $v [0];
  8581. $roleVerify = json_decode ( $v [3], true );
  8582. $roleKey = $k;
  8583. $roleArray = array ();
  8584. foreach ( $roleVerify as $o => $p ) {
  8585. $staffID = explode ( '_', $p );
  8586. $exp = array (
  8587. 0 => $staffID [0],
  8588. 1 => $staffID [1]
  8589. );
  8590. array_push ( $roleArray, $exp );
  8591. }
  8592. $verifyDetailCopy [$v [0]] = $roleArray;
  8593. }
  8594. }
  8595. // print_r($verifyDetail);
  8596. foreach ( $verifyDetailCopy as $k => $v ) {
  8597. foreach ( $verifyDetail as $m => $n ) {
  8598. if ($n [0] == $k) {
  8599. array_splice ( $verifyDetail, $m, 1, $v );
  8600. }
  8601. }
  8602. }
  8603. // die;
  8604. // if (!empty($roleArray))
  8605. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8606. // echo $roleId;
  8607. // print_r($verifyStaff);
  8608. // print_r($verifyDetail);
  8609. // die;
  8610. Doo::loadModel ( "receiptLog" );
  8611. $receiptLog = new receiptLog ();
  8612. // 审批日志
  8613. if (! isset ( $verifyStaff ['final'] )) {
  8614. if (! empty ( $roleId )) {
  8615. Doo::loadModel ( "role" );
  8616. $role = new role ();
  8617. $roleInfo = $role->getOne ( array (
  8618. 'where' => 'rid=' . $roleId,
  8619. 'asArray' => true
  8620. ) );
  8621. $receiptLog->rolename = $roleInfo ['name'];
  8622. }
  8623. $receiptLog->username = $this->staff [0] ['username'];
  8624. $receiptLog->uid = $this->staff [0] ['sid'];
  8625. $receiptLog->date = date ( "Y-m-d" );
  8626. $receiptLog->opinion = $opinion;
  8627. $receiptLog->img = $this->staff [0] ['avatar'];
  8628. $receiptLog->status = 1;
  8629. $receiptLog->rid = $rid;
  8630. $receiptLog->insert ();
  8631. }
  8632. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8633. $receipt->verifyBreakup = $verifyString;
  8634. $receipt->status = 3;
  8635. $receiptDetailObj->status = 3;
  8636. $receiptDetailObj->update ( array (
  8637. 'where' => 'rid=' . $rid
  8638. ) );
  8639. if (! empty ( $roleId )) {
  8640. Doo::loadModel ( "role" );
  8641. $role = new role ();
  8642. $roleInfo = $role->getOne ( array (
  8643. 'where' => 'rid=' . $roleId,
  8644. 'asArray' => true
  8645. ) );
  8646. $receiptLog->rolename = $roleInfo ['name'];
  8647. }
  8648. $receiptLog->username = $this->staff [0] ['username'];
  8649. $receiptLog->uid = $this->staff [0] ['sid'];
  8650. $receiptLog->date = date ( "Y-m-d" );
  8651. $receiptLog->opinion = $opinion;
  8652. $receiptLog->img = $this->staff [0] ['avatar'];
  8653. $receiptLog->status = 3;
  8654. $receiptLog->rid = $rid;
  8655. $receiptLog->insert ();
  8656. // 微信企业号通知
  8657. $this->setWXMsg ( $rid, 3 );
  8658. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8659. $receipt->status = 1;
  8660. $reviseSum = 0;
  8661. $receipt->verifyBreakup = $verifyString;
  8662. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8663. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8664. foreach ( $reviseDetail as $key => $value ) {
  8665. $receiptDetailObj = new receiptDetail ();
  8666. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8667. $receiptDetailObj->item = $value ['description'];
  8668. $receiptDetailObj->itemCategory = "报销金额调整";
  8669. $receiptDetailObj->price = $value ['price'];
  8670. $receiptDetailObj->date = $receiptDetail ['date'];
  8671. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8672. $receiptDetailObj->rid = $rid;
  8673. $receiptDetailObj->status = 1;
  8674. $receiptDetailObj->insert ();
  8675. $reviseSum += $value ['price'];
  8676. }
  8677. $itemStatistics = new itemStatistics ();
  8678. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8679. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8680. $itemStatistics->price = $reviseSum;
  8681. $itemStatistics->itemCategory = "报销金额调整";
  8682. $itemStatistics->date = $receiptDetail ['date'];
  8683. $itemStatistics->insert ();
  8684. }
  8685. $receiptDetailObj = new receiptDetail ();
  8686. $receiptDetailObj->status = 1;
  8687. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8688. $receiptDetailObj->update ( array (
  8689. 'where' => 'rid=' . $rid
  8690. ) );
  8691. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8692. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8693. $stat = $statistics->getOne ( array (
  8694. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8695. 'asArray' => true
  8696. ) );
  8697. if (empty ( $stat )) {
  8698. $statistics->date = $receiptDetail ['date'];
  8699. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8700. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8701. $statistics->agPrice = $receiptDetail ['sum'];
  8702. $statistics->rePrice = $reviseSum;
  8703. $statistics->insert ();
  8704. } else {
  8705. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8706. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8707. $statistics->update ( array (
  8708. 'where' => 'sid=' . $stat ['sid']
  8709. ) );
  8710. }
  8711. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8712. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8713. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8714. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8715. if ($key == "agencySum") {
  8716. $iStatistics = $itemStatistics->getOne ( array (
  8717. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8718. 'asArray' => true
  8719. ) );
  8720. if (empty ( $iStatistics )) {
  8721. $itemStatistics->cid = $receiptDetail ['cid'];
  8722. ;
  8723. $itemStatistics->staff = $receiptDetail ['staff'];
  8724. $itemStatistics->price = $value;
  8725. $itemStatistics->itemCategory = $this->AGENCY;
  8726. $itemStatistics->date = $receiptDetail ['date'];
  8727. $itemStatistics->insert ();
  8728. } else {
  8729. if (! empty ( $value )) {
  8730. $itemStatistics->price = $value + $iStatistics ['price'];
  8731. $itemStatistics->update ( array (
  8732. 'where' => 'sid=' . $iStatistics ['sid']
  8733. ) );
  8734. }
  8735. }
  8736. } elseif ($key == "travelSum") {
  8737. $iStatistics = $itemStatistics->getOne ( array (
  8738. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8739. 'asArray' => true
  8740. ) );
  8741. if (empty ( $iStatistics )) {
  8742. $itemStatistics->cid = $receiptDetail ['cid'];
  8743. $itemStatistics->staff = $receiptDetail ['staff'];
  8744. $itemStatistics->price = $value;
  8745. $itemStatistics->itemCategory = $this->TRAVEL;
  8746. $itemStatistics->date = $receiptDetail ['date'];
  8747. $itemStatistics->insert ();
  8748. } else {
  8749. if (! empty ( $value )) {
  8750. $itemStatistics->price = $value + $iStatistics ['price'];
  8751. $itemStatistics->update ( array (
  8752. 'where' => 'sid=' . $iStatistics ['sid']
  8753. ) );
  8754. }
  8755. }
  8756. } elseif ($key == "trainSum") {
  8757. $iStatistics = $itemStatistics->getOne ( array (
  8758. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8759. 'asArray' => true
  8760. ) );
  8761. if (empty ( $iStatistics )) {
  8762. $itemStatistics->cid = $receiptDetail ['cid'];
  8763. $itemStatistics->staff = $receiptDetail ['staff'];
  8764. $itemStatistics->price = $value;
  8765. $itemStatistics->itemCategory = $this->TRAIN;
  8766. $itemStatistics->date = $receiptDetail ['date'];
  8767. $itemStatistics->insert ();
  8768. } else {
  8769. if (! empty ( $value )) {
  8770. $itemStatistics->price = $value + $iStatistics ['price'];
  8771. $itemStatistics->update ( array (
  8772. 'where' => 'sid=' . $iStatistics ['sid']
  8773. ) );
  8774. }
  8775. }
  8776. } elseif ($key == "otherSum") {
  8777. $iStatistics = $itemStatistics->getOne ( array (
  8778. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8779. 'asArray' => true
  8780. ) );
  8781. if (empty ( $iStatistics )) {
  8782. $itemStatistics->cid = $receiptDetail ['cid'];
  8783. $itemStatistics->staff = $receiptDetail ['staff'];
  8784. $itemStatistics->price = $value;
  8785. $itemStatistics->itemCategory = $this->OTHER;
  8786. $itemStatistics->date = $receiptDetail ['date'];
  8787. $itemStatistics->insert ();
  8788. } else {
  8789. if (! empty ( $value )) {
  8790. $itemStatistics->price = $value + $iStatistics ['price'];
  8791. $itemStatistics->update ( array (
  8792. 'where' => 'sid=' . $iStatistics ['sid']
  8793. ) );
  8794. }
  8795. }
  8796. }
  8797. }
  8798. $receipt->pastDate = date ( "Y-m-d" );
  8799. // 微信企业号通知
  8800. $this->setWXMsg ( $rid, 1 );
  8801. }
  8802. //是否有流水
  8803. Doo::loadModel ( 'wasteBook' );
  8804. $wasteBook = new wasteBook ();
  8805. $accountType=3;
  8806. if ($receiptDetail['Rtype']==1){
  8807. $accountType=2;
  8808. }elseif($receiptDetail['Rtype']==2){
  8809. $accountType=4;
  8810. }
  8811. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8812. if (empty($wbDetail)){
  8813. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  8814. $receipt->amount = $rsum;//$amount;
  8815. }
  8816. $receipt->update ( array (
  8817. 'where' => ' rid = ' . $rid
  8818. ) );
  8819. // 进入下一条审批费用新加需求
  8820. $vidList = array ();
  8821. $verifyDetail = $verify->find ( array (
  8822. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8823. 'asArray' => true
  8824. ) );
  8825. foreach ( $verifyDetail as $key => $value ) {
  8826. array_push ( $vidList, $value ['vid'] );
  8827. }
  8828. $vid = implode ( ",", $vidList );
  8829. if (empty ( $verifyDetail ))
  8830. $vid = 0;
  8831. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8832. $receipt = new receipt ();
  8833. $rd = $receipt->getOne ( array (
  8834. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8835. 'asc' => 'rid',
  8836. 'asArray' => true
  8837. ) );
  8838. if (empty ( $rd )) {
  8839. return '/approvalExpenses/pendApproval';
  8840. }
  8841. if ($rd ['Rtype'] == 1) {
  8842. if ($rd ['isBK'] == 1) {
  8843. return '/receiptburEdi/' . $rd ['rid'];
  8844. } else {
  8845. return '/expensesEdi/' . $rd ['rid'];
  8846. }
  8847. } elseif ($rd ['Rtype'] == 2) {
  8848. return '/remitApproval/' . $rd ['rid'];
  8849. } else {
  8850. return '/receiptburEdi/' . $rd ['rid'];
  8851. }
  8852. // return "/approvalExpenses/pendApproval";
  8853. }
  8854. }
  8855. function expensesRetreats() {
  8856. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8857. if (! empty ( $rid )) {
  8858. // 操作记录
  8859. Doo::loadModel ( "receipt" );
  8860. $receipt = new receipt ();
  8861. Doo::loadModel ( "receiptLog" );
  8862. $receiptLog = new receiptLog ();
  8863. Doo::loadModel ( "verify" );
  8864. $verify = new verify ();
  8865. $receiptInfo = $receipt->getOne ( array (
  8866. 'where' => 'rid=' . $rid,
  8867. 'asArray' => true
  8868. ) );
  8869. $vr = $verify->getOne ( array (
  8870. 'where' => 'vid=' . $receiptInfo ['verify'],
  8871. 'asArray' => true
  8872. ) );
  8873. $jd = json_decode ( $vr ['staff'] );
  8874. $roleId = 0;
  8875. foreach ( $jd as $key => $value ) {
  8876. if ($value [1] == 'ROLE') {
  8877. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8878. if ($pos !== false) {
  8879. $roleId = $value [0];
  8880. }
  8881. }
  8882. }
  8883. // 审批日志
  8884. // echo $roleId;die;
  8885. if (! empty ( $roleId )) {
  8886. Doo::loadModel ( "role" );
  8887. $role = new role ();
  8888. $roleInfo = $role->getOne ( array (
  8889. 'where' => 'rid=' . $roleId,
  8890. 'asArray' => true
  8891. ) );
  8892. $receiptLog->rolename = $roleInfo ['name'];
  8893. }
  8894. $receiptLog->username = $this->staff [0] ['username'];
  8895. $receiptLog->uid = $this->staff [0] ['sid'];
  8896. $receiptLog->date = date ( "Y-m-d" );
  8897. $receiptLog->opinion = '撤回';
  8898. $receiptLog->img = $this->staff [0] ['avatar'];
  8899. $receiptLog->status = 4;
  8900. $receiptLog->rid = $rid;
  8901. $receiptLog->insert ();
  8902. $receipt->status = 4;
  8903. $receipt->update ( array (
  8904. 'where' => 'rid=' . $rid
  8905. ) );
  8906. // 微信企业号通知
  8907. $this->setWXMsg ( $rid, 2 );
  8908. }
  8909. // echo "ddd";
  8910. return '/approvalExpenses/pendApproval';
  8911. }
  8912. function updateCheReceipt() {
  8913. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8914. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8915. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8916. if (! empty ( $rid )) {
  8917. // 操作记录
  8918. Doo::loadModel ( "receipt" );
  8919. $receipt = new receipt ();
  8920. Doo::loadModel ( "receiptLog" );
  8921. $receiptLog = new receiptLog ();
  8922. Doo::loadModel ( "verify" );
  8923. $verify = new verify ();
  8924. $receiptInfo = $receipt->getOne ( array (
  8925. 'where' => 'rid=' . $rid . ' and status=2',
  8926. 'asArray' => true
  8927. ) );
  8928. if (empty ( $receiptInfo )) {
  8929. echo json_encode ( array (
  8930. 'status' => 2
  8931. ) );
  8932. die ();
  8933. }
  8934. $vr = $verify->getOne ( array (
  8935. 'where' => 'vid=' . $receiptInfo ['verify'],
  8936. 'asArray' => true
  8937. ) );
  8938. $jd = json_decode ( $vr ['staff'] );
  8939. $roleId = 0;
  8940. foreach ( $jd as $key => $value ) {
  8941. if ($value [1] == 'ROLE') {
  8942. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8943. if ($pos !== false) {
  8944. $roleId = $value [0];
  8945. }
  8946. }
  8947. }
  8948. // 审批日志
  8949. // echo $roleId;die;
  8950. if (! empty ( $roleId )) {
  8951. Doo::loadModel ( "role" );
  8952. $role = new role ();
  8953. $roleInfo = $role->getOne ( array (
  8954. 'where' => 'rid=' . $roleId,
  8955. 'asArray' => true
  8956. ) );
  8957. $receiptLog->rolename = $roleInfo ['name'];
  8958. }
  8959. $receiptLog->username = $this->staff [0] ['username'];
  8960. $receiptLog->uid = $this->staff [0] ['sid'];
  8961. $receiptLog->date = date ( "Y-m-d" );
  8962. $receiptLog->opinion = $opinion;
  8963. $receiptLog->img = $this->staff [0] ['avatar'];
  8964. $receiptLog->status = 4;
  8965. $receiptLog->rid = $rid;
  8966. $receiptLog->insert ();
  8967. $receipt->status = 4;
  8968. $receipt->update ( array (
  8969. 'where' => 'rid=' . $rid
  8970. ) );
  8971. // 微信企业号通知
  8972. $this->setWXMsg ( $rid, 2 );
  8973. echo json_encode ( array (
  8974. 'status' => 1
  8975. ) );
  8976. // Header("HTTP/1.1 303 See Other");
  8977. // Header("Location: /approvalExpenses/pendApproval");
  8978. die ();
  8979. }
  8980. echo json_encode ( array (
  8981. 'status' => 2
  8982. ) );
  8983. die ();
  8984. // echo "ddd";
  8985. // return '/saeaBorad';
  8986. }
  8987. function revisePrice() {
  8988. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  8989. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  8990. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8991. // echo $price;die;
  8992. if (! empty ( $rid )) {
  8993. Doo::loadModel ( "receipt" );
  8994. $receipt = new receipt ();
  8995. $receiptDetail = $receipt->getOne ( array (
  8996. 'where' => 'rid=' . $rid . ' and status=2 ',
  8997. 'asArray' => true
  8998. ) );
  8999. if (empty ( $receiptDetail ))
  9000. die ( 'illegal request' );
  9001. $reviseDetail = array ();
  9002. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9003. array_push ( $reviseDetail, array (
  9004. 'sid' => $this->staff [0] ['sid'],
  9005. 'name' => $this->staff [0] ['username'],
  9006. 'description' => $description,
  9007. 'price' => $price
  9008. ) );
  9009. $reviseDetailString = json_encode ( $reviseDetail );
  9010. $receipt->reviseDetail = $reviseDetailString;
  9011. $receipt->revisePrice = $price;
  9012. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9013. } else {
  9014. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9015. array_push ( $reviseDetail, array (
  9016. 'sid' => $this->staff [0] ['sid'],
  9017. 'name' => $this->staff [0] ['username'],
  9018. 'description' => $description,
  9019. 'price' => $price
  9020. ) );
  9021. $reviseDetailString = json_encode ( $reviseDetail );
  9022. $receipt->reviseDetail = $reviseDetailString;
  9023. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9024. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9025. }
  9026. $receipt->update ( array (
  9027. 'where' => 'rid=' . $rid
  9028. ) );
  9029. if ($receiptDetail ['Rtype'] == 1) {
  9030. if ($receiptDetail ['isBK'] == 1) {
  9031. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9032. }
  9033. } elseif ($receiptDetail ['Rtype'] == 2) {
  9034. } else {
  9035. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9036. }
  9037. }
  9038. die ( 'illegal request' );
  9039. }
  9040. function personalCollect() {
  9041. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9042. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9043. $this->showCache ( $path );
  9044. Doo::loadModel ( "receiptDetail" );
  9045. Doo::loadModel ( "itemStatistics" );
  9046. Doo::loadModel ( 'statistics' );
  9047. $statistics = new statistics ();
  9048. $itemStatistics = new itemStatistics ();
  9049. $receiptDetail = new receiptDetail ();
  9050. $receiptCollectList = $receiptDetail->find ( array (
  9051. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9052. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9053. 'groupby' => 'itemCategory,Month(date)',
  9054. 'asArray' => true
  9055. ) );
  9056. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9057. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9058. 'asArray' => true
  9059. ) );
  9060. // create collect html
  9061. $collectArray = array (
  9062. '日常相关费用' => array (),
  9063. '差旅相关费用' => array (),
  9064. '培训班费用' => array (),
  9065. '其他' => array ()
  9066. );
  9067. $adjustment = array ();
  9068. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9069. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9070. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9071. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9072. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9073. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9074. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9075. array_push ( $collectArray ['其他'], $collectHtml );
  9076. $data ['collectArray'] = $collectArray;
  9077. // statistics html
  9078. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9079. if (empty ( $stList ))
  9080. $stList = array (
  9081. 'rePrice' => 0,
  9082. 'agPrice' => 0
  9083. );
  9084. $data ['stList'] = array (
  9085. 'rePrice' => $stList ['rePrice'],
  9086. 'agPrice' => $stList ['agPrice'],
  9087. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9088. );
  9089. // Adjustment price html
  9090. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9091. array_push ( $adjustment, $collectHtml );
  9092. $data ['adjustment'] = $adjustment;
  9093. // total price html
  9094. $collectHtml = "";
  9095. $total = 0;
  9096. for($i = 1; $i <= 12; $i ++) {
  9097. $sumPrice = 0;
  9098. foreach ( $receiptCollectList as $key => $value ) {
  9099. if ($value ['month'] == $i) {
  9100. $sumPrice += $value ['price'];
  9101. }
  9102. }
  9103. if ($sumPrice == 0)
  9104. $collectHtml .= '<td class="taR">-</td>';
  9105. else
  9106. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9107. $total += $sumPrice;
  9108. }
  9109. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9110. $data ['totalPrice'] = $collectHtml;
  9111. $dateHtml = "";
  9112. $now = date ( "Y" );
  9113. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9114. if ($YEARD <= $now) {
  9115. $dateHtml .= '<option ';
  9116. if ($year == $YEARD) {
  9117. $dateHtml .= 'selected ';
  9118. }
  9119. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9120. }
  9121. }
  9122. $data ['dateHtml'] = $dateHtml;
  9123. $data ['year'] = $year;
  9124. $data ['totalYear'] = $total;
  9125. $data ['memu'] = "receipt";
  9126. $data ['staff'] = $this->staff;
  9127. $data ['receiptMemu'] = 'personalCollect';
  9128. $data ['verifyId'] = $this->verifyId;
  9129. $data ['executeId'] = $this->executeId;
  9130. // year staff status 2,4
  9131. if ($year < date ( "Y" )) {
  9132. Doo::loadModel ( 'receipt' );
  9133. $receipt = new receipt ();
  9134. $receiptList = $receipt->find ( array (
  9135. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9136. 'asArray' => true
  9137. ) );
  9138. if (empty ( $receiptList )) {
  9139. ob_start ();
  9140. $this->render ( "/admin/saea_slist_collect", $data );
  9141. $this->cacheFile ( $path );
  9142. die ();
  9143. }
  9144. }
  9145. $this->render ( "/admin/saea_slist_collect", $data );
  9146. }
  9147. function personalCollectDetail() {
  9148. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9149. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9150. $this->showCache ( $path );
  9151. Doo::loadModel ( "receiptDetail" );
  9152. Doo::loadModel ( "itemStatistics" );
  9153. Doo::loadModel ( 'statistics' );
  9154. Doo::loadModel ( 'accountItem' );
  9155. $accountItem = new accountItem ();
  9156. $statistics = new statistics ();
  9157. $itemStatistics = new itemStatistics ();
  9158. $receiptDetail = new receiptDetail ();
  9159. $receiptCollectList = $receiptDetail->find ( array (
  9160. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9161. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9162. 'groupby' => 'item,Month(date)',
  9163. 'asArray' => true
  9164. ) );
  9165. $accountList = $accountItem->find ( array (
  9166. 'asArray' => true
  9167. ) );
  9168. // create CollectDetail HTML
  9169. $collectHtml = array ();
  9170. foreach ( $accountList as $key => $value ) {
  9171. $html = "";
  9172. $asum = 0;
  9173. for($i = 1; $i <= 12; $i ++) {
  9174. $falg = true;
  9175. foreach ( $receiptCollectList as $v ) {
  9176. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9177. $asum += $v ['price'];
  9178. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9179. $falg = false;
  9180. break;
  9181. }
  9182. }
  9183. if ($falg)
  9184. $html .= '<td class="taR">-</td>';
  9185. }
  9186. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9187. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9188. }
  9189. $data ['collectHtml'] = $collectHtml;
  9190. // create Adjustment price html
  9191. $receiptCollectList = $receiptDetail->find ( array (
  9192. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9193. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9194. 'groupby' => 'itemCategory,Month(date)',
  9195. 'asArray' => true
  9196. ) );
  9197. $adjustment = array ();
  9198. $collectArray = array (
  9199. '日常相关费用' => array (),
  9200. '差旅相关费用' => array (),
  9201. '培训班费用' => array (),
  9202. '其他' => array ()
  9203. );
  9204. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9205. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9206. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9207. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9208. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9209. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9210. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9211. array_push ( $collectArray ['其他'], $collectHtml );
  9212. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9213. array_push ( $adjustment, $collectHtml );
  9214. // total price html
  9215. $collectHtml = "";
  9216. $total = 0;
  9217. for($i = 1; $i <= 12; $i ++) {
  9218. $sumPrice = 0;
  9219. foreach ( $receiptCollectList as $key => $value ) {
  9220. if ($value ['month'] == $i) {
  9221. $sumPrice += $value ['price'];
  9222. }
  9223. }
  9224. if ($sumPrice == 0)
  9225. $collectHtml .= '<td class="taR">-</td>';
  9226. else
  9227. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9228. $total += $sumPrice;
  9229. }
  9230. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9231. // statistics html
  9232. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9233. if (empty ( $stList ))
  9234. $stList = array (
  9235. 'rePrice' => 0,
  9236. 'agPrice' => 0
  9237. );
  9238. $data ['stList'] = array (
  9239. 'rePrice' => $stList ['rePrice'],
  9240. 'agPrice' => $stList ['agPrice'],
  9241. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9242. );
  9243. $data ['collectArray'] = $collectArray;
  9244. $data ['adjustment'] = $adjustment;
  9245. $data ['totalPrice'] = $collectHtml;
  9246. $data ['totalYear'] = $total;
  9247. $data ['year'] = $year;
  9248. $dateHtml = "";
  9249. $now = date ( "Y" );
  9250. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9251. if ($YEARD <= $now) {
  9252. $dateHtml .= '<option ';
  9253. if ($year == $YEARD) {
  9254. $dateHtml .= 'selected ';
  9255. }
  9256. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9257. }
  9258. }
  9259. $data ['dateHtml'] = $dateHtml;
  9260. $data ['memu'] = "receipt";
  9261. $data ['staff'] = $this->staff;
  9262. $data ['receiptMemu'] = 'personalCollect';
  9263. $data ['verifyId'] = $this->verifyId;
  9264. $data ['executeId'] = $this->executeId;
  9265. // year staff status 2,4
  9266. if ($year < date ( "Y" )) {
  9267. Doo::loadModel ( 'receipt' );
  9268. $receipt = new receipt ();
  9269. $receiptList = $receipt->find ( array (
  9270. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9271. 'asArray' => true
  9272. ) );
  9273. if (empty ( $receiptList )) {
  9274. ob_start ();
  9275. $this->render ( "/admin/saeaCollectArticles", $data );
  9276. $this->cacheFile ( $path );
  9277. die ();
  9278. }
  9279. }
  9280. $this->render ( "/admin/saeaCollectArticles", $data );
  9281. }
  9282. function companyCategoryCollect() {
  9283. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9284. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9285. $this->showCache ( $path );
  9286. Doo::loadModel ( 'L_category' );
  9287. Doo::loadModel ( 'itemStatistics' );
  9288. Doo::loadModel ( 'statistics' );
  9289. $statistics = new statistics ();
  9290. $Lcategory = new L_category ();
  9291. $itemStatistics = new itemStatistics ();
  9292. Doo::loadModel ( "receiptAuthorityManage" );
  9293. $receiptAuthorityManage = new receiptAuthorityManage ();
  9294. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9295. $cidList = array ();
  9296. foreach ( $imcStaff as $key => $value ) {
  9297. array_push ( $cidList, $value ['cid'] );
  9298. }
  9299. $cidString = implode ( ',', $cidList );
  9300. $LcategoryList = $Lcategory->find ( array (
  9301. 'where' => ' cid in (' . $cidString . ')',
  9302. 'asArray' => true
  9303. ) ); // 'staff='.$this->staff[0]['sid']." and
  9304. $itemStatisticsList = $itemStatistics->find ( array (
  9305. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9306. 'where' => " Year(date)=" . $year,
  9307. 'groupby' => 'cid,Month(date)',
  9308. 'asArray' => true
  9309. ) );
  9310. // ceatre companyCollectHtml
  9311. foreach ( $LcategoryList as $value ) {
  9312. $html = "";
  9313. $asum = 0;
  9314. for($i = 1; $i <= 12; $i ++) {
  9315. $falg = true;
  9316. foreach ( $itemStatisticsList as $v ) {
  9317. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9318. $asum += $v ['price'];
  9319. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9320. $falg = false;
  9321. break;
  9322. }
  9323. }
  9324. if ($falg)
  9325. $html .= '<td class="taR">-</td>';
  9326. }
  9327. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9328. $collectHtml [$value ['title']] = array (
  9329. 'html' => $html,
  9330. 'cid' => $value ['cid']
  9331. );
  9332. }
  9333. $data ['companyHtml'] = $collectHtml;
  9334. // total price html
  9335. $collectHtml = "";
  9336. $total = 0;
  9337. for($i = 1; $i <= 12; $i ++) {
  9338. $sumPrice = 0;
  9339. foreach ( $itemStatisticsList as $key => $value ) {
  9340. if ($value ['month'] == $i) {
  9341. $sumPrice += $value ['price'];
  9342. }
  9343. }
  9344. if ($sumPrice == 0)
  9345. $collectHtml .= '<td class="taR">-</td>';
  9346. else
  9347. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9348. $total += $sumPrice;
  9349. }
  9350. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9351. $data ['companyTotalHtml'] = $collectHtml;
  9352. $data ['total'] = $total;
  9353. // statistics html
  9354. // echo $cidString;
  9355. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9356. if (empty ( $stList ))
  9357. $stList = array (
  9358. 'rePrice' => 0,
  9359. 'agPrice' => 0
  9360. );
  9361. $data ['stList'] = array (
  9362. 'rePrice' => $stList ['rePrice'],
  9363. 'agPrice' => $stList ['agPrice'],
  9364. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9365. );
  9366. $data ['year'] = $year;
  9367. $data ['memu'] = "receipt";
  9368. $data ['staff'] = $this->staff;
  9369. $data ['receiptMemu'] = 'companyCategoryCollect';
  9370. $data ['verifyId'] = $this->verifyId;
  9371. $data ['executeId'] = $this->executeId;
  9372. $dateHtml = "";
  9373. $now = date ( "Y" );
  9374. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9375. if ($YEARD <= $now) {
  9376. $dateHtml .= '<option ';
  9377. if ($year == $YEARD) {
  9378. $dateHtml .= 'selected ';
  9379. }
  9380. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9381. }
  9382. }
  9383. $data ['dateHtml'] = $dateHtml;
  9384. // year staff status 2,4
  9385. if ($year < date ( "Y" )) {
  9386. Doo::loadModel ( 'receipt' );
  9387. $receipt = new receipt ();
  9388. $receiptList = $receipt->find ( array (
  9389. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9390. 'asArray' => true
  9391. ) );
  9392. if (empty ( $receiptList )) {
  9393. ob_start ();
  9394. $this->render ( "/admin/saeaCompanyCollect", $data );
  9395. $this->cacheFile ( $path );
  9396. die ();
  9397. }
  9398. }
  9399. $this->render ( "/admin/saeaCompanyCollect", $data );
  9400. }
  9401. function categoryCollectDetail() {
  9402. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9403. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9404. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9405. $this->showCache ( $path );
  9406. Doo::loadModel ( 'statistics' );
  9407. $statistics = new statistics ();
  9408. Doo::loadModel ( "receiptDetail" );
  9409. $receiptDetail = new receiptDetail ();
  9410. Doo::loadModel ( 'L_category' );
  9411. $Lcategory = new L_category ();
  9412. Doo::loadModel ( 'accountItem' );
  9413. $accountItem = new accountItem ();
  9414. Doo::loadModel ( "receiptAuthorityManage" );
  9415. $receiptAuthorityManage = new receiptAuthorityManage ();
  9416. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9417. $cidList = array ();
  9418. foreach ( $imcStaff as $key => $value ) {
  9419. array_push ( $cidList, $value ['cid'] );
  9420. }
  9421. $cidString = implode ( ',', $cidList );
  9422. $LcategoryList = $Lcategory->find ( array (
  9423. 'where' => 'cid in (' . $cidString . ')',
  9424. 'asArray' => true
  9425. ) );
  9426. if ($cid == 0) {
  9427. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9428. if ($cid == 0)
  9429. $cid = $LcategoryList [0] ['cid'];
  9430. }
  9431. $data ['LcategoryList'] = $LcategoryList;
  9432. $receiptCollectList = $receiptDetail->find ( array (
  9433. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9434. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9435. 'groupby' => 'item,Month(pastDate)',
  9436. 'asArray' => true
  9437. ) );
  9438. $accountList = $accountItem->find ( array (
  9439. 'asArray' => true
  9440. ) );
  9441. // create CollectDetail HTML
  9442. $collectHtml = array ();
  9443. foreach ( $accountList as $key => $value ) {
  9444. $html = "";
  9445. $asum = 0;
  9446. for($i = 1; $i <= 12; $i ++) {
  9447. $falg = true;
  9448. foreach ( $receiptCollectList as $v ) {
  9449. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9450. $asum += $v ['price'];
  9451. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9452. $falg = false;
  9453. break;
  9454. }
  9455. }
  9456. if ($falg)
  9457. $html .= '<td class="taR">-</td>';
  9458. }
  9459. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9460. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9461. }
  9462. $data ['collectHtml'] = $collectHtml;
  9463. // create Adjustment price html
  9464. $receiptCollectList = $receiptDetail->find ( array (
  9465. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9466. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9467. 'groupby' => 'itemCategory,Month(pastDate)',
  9468. 'asArray' => true
  9469. ) );
  9470. $adjustment = array ();
  9471. $collectArray = array (
  9472. '日常相关费用' => array (),
  9473. '差旅相关费用' => array (),
  9474. '培训班费用' => array (),
  9475. '内部培训费用'=>array(),
  9476. '其他' => array ()
  9477. );
  9478. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9479. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9480. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9481. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9482. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9483. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9484. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9485. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9486. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9487. array_push ( $collectArray ['其他'], $collectHtml );
  9488. $data ['collectArray'] = $collectArray;
  9489. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9490. array_push ( $adjustment, $collectHtml );
  9491. $data ['adjustment'] = $adjustment;
  9492. // total price html
  9493. $collectHtml = "";
  9494. $total = 0;
  9495. for($i = 1; $i <= 12; $i ++) {
  9496. $sumPrice = 0;
  9497. foreach ( $receiptCollectList as $key => $value ) {
  9498. if ($value ['month'] == $i) {
  9499. $sumPrice += $value ['price'];
  9500. }
  9501. }
  9502. if ($sumPrice == 0)
  9503. $collectHtml .= '<td class="taR">-</td>';
  9504. else
  9505. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9506. $total += $sumPrice;
  9507. }
  9508. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9509. // statistics html
  9510. $stList = $statistics->statisticsByCid ( $year, $cid );
  9511. if (empty ( $stList ))
  9512. $stList = array (
  9513. 'rePrice' => 0,
  9514. 'agPrice' => 0
  9515. );
  9516. $data ['stList'] = array (
  9517. 'rePrice' => $stList ['rePrice'],
  9518. 'agPrice' => $stList ['agPrice'],
  9519. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9520. );
  9521. $data ['totalYear'] = $total;
  9522. $data ['year'] = $year;
  9523. $data ['cid'] = $cid;
  9524. $data ['memu'] = "receipt";
  9525. $data ['staff'] = $this->staff;
  9526. $data ['receiptMemu'] = 'companyCategoryCollect';
  9527. $data ['verifyId'] = $this->verifyId;
  9528. $data ['executeId'] = $this->executeId;
  9529. // year staff status 2,4
  9530. if ($year < date ( "Y" )) {
  9531. Doo::loadModel ( 'receipt' );
  9532. $receipt = new receipt ();
  9533. $receiptList = $receipt->find ( array (
  9534. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9535. 'asArray' => true
  9536. ) );
  9537. if (empty ( $receiptList )) {
  9538. ob_start ();
  9539. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9540. $this->cacheFile ( $path );
  9541. die ();
  9542. }
  9543. }
  9544. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9545. }
  9546. function staffCollect() {
  9547. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9548. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9549. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9550. // $this->showCache($path);
  9551. Doo::loadModel ( 'statistics' );
  9552. $statistics = new statistics ();
  9553. Doo::loadModel ( "receiptDetail" );
  9554. $receiptDetail = new receiptDetail ();
  9555. Doo::loadModel ( 'L_category' );
  9556. $Lcategory = new L_category ();
  9557. Doo::loadModel ( 'accountItem' );
  9558. $accountItem = new accountItem ();
  9559. Doo::loadModel ( 'staff' );
  9560. $staff = new staff ();
  9561. Doo::loadModel ( 'itemStatistics' );
  9562. $itemStatistics = new itemStatistics ();
  9563. Doo::loadModel ( "receiptAuthorityManage" );
  9564. $receiptAuthorityManage = new receiptAuthorityManage ();
  9565. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9566. $cidList = array ();
  9567. foreach ( $imcStaff as $key => $value ) {
  9568. array_push ( $cidList, $value ['cid'] );
  9569. }
  9570. $cidString = implode ( ',', $cidList );
  9571. $naturecon='';
  9572. if ($nature=='ONJOB'){
  9573. $naturecon=' and (nature!=4 )';
  9574. }elseif($nature=='LEAVEJOB'){
  9575. $naturecon=' and (nature=4 )';
  9576. }else{
  9577. die ( 'illegal request--nature' );
  9578. }
  9579. // statistics html
  9580. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9581. if (empty ( $stList ))
  9582. $stList = array (
  9583. 'rePrice' => 0,
  9584. 'agPrice' => 0
  9585. );
  9586. $data ['stList'] = array (
  9587. 'rePrice' => $stList ['rePrice'],
  9588. 'agPrice' => $stList ['agPrice'],
  9589. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9590. );
  9591. // ---
  9592. $staffList = $staff->find ( array (
  9593. 'where' => 'username !="admin" '.$naturecon,
  9594. 'asArray' => true
  9595. ) );
  9596. $LcategoryList = $Lcategory->find ( array (
  9597. 'asArray' => true
  9598. ) ); // 'staff='.$this->staff[0]['sid']." and
  9599. $itemStatisticsList = $itemStatistics->find ( array (
  9600. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9601. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9602. 'groupby' => 'staff,Month(date)',
  9603. 'asArray' => true
  9604. ) );
  9605. $categoryList = $staff->find ( array (
  9606. 'select' => 'COUNT(*) as count,cid,category',
  9607. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9608. 'groupby' => 'cid',
  9609. 'asArray' => true
  9610. ) );
  9611. // print_r($itemStatisticsList);die;
  9612. // ceatre companyCollectHtml
  9613. foreach ( $categoryList as $vlu ) {
  9614. $count = $vlu ['count'] + 1;
  9615. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9616. $m1 = 0;
  9617. $m2 = 0;
  9618. $m3 = 0;
  9619. $m4 = 0;
  9620. $m5 = 0;
  9621. $m6 = 0;
  9622. $m7 = 0;
  9623. $m8 = 0;
  9624. $m9 = 0;
  9625. $m10 = 0;
  9626. $m11 = 0;
  9627. $m12 = 0;
  9628. $m13 = 0;
  9629. foreach ( $staffList as $value ) {
  9630. if ($vlu ['cid'] == $value ['cid']) {
  9631. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9632. $asum = 0;
  9633. for($i = 1; $i <= 12; $i ++) {
  9634. $falg = true;
  9635. foreach ( $itemStatisticsList as $v ) {
  9636. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9637. if ($v ['month'] == 1)
  9638. $m1 += $v ['price'];
  9639. if ($v ['month'] == 2)
  9640. $m2 += $v ['price'];
  9641. if ($v ['month'] == 3)
  9642. $m3 += $v ['price'];
  9643. if ($v ['month'] == 4)
  9644. $m4 += $v ['price'];
  9645. if ($v ['month'] == 5)
  9646. $m5 += $v ['price'];
  9647. if ($v ['month'] == 6)
  9648. $m6 += $v ['price'];
  9649. if ($v ['month'] == 7)
  9650. $m7 += $v ['price'];
  9651. if ($v ['month'] == 8)
  9652. $m8 += $v ['price'];
  9653. if ($v ['month'] == 9)
  9654. $m9 += $v ['price'];
  9655. if ($v ['month'] == 10)
  9656. $m10 += $v ['price'];
  9657. if ($v ['month'] == 11)
  9658. $m11 += $v ['price'];
  9659. if ($v ['month'] == 12)
  9660. $m12 += $v ['price'];
  9661. $asum += $v ['price'];
  9662. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9663. $falg = false;
  9664. break;
  9665. }
  9666. }
  9667. if ($falg)
  9668. $html .= '<td class="taR">-</td>';
  9669. }
  9670. $m13 += $asum;
  9671. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9672. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9673. 'html' => $html,
  9674. 'sid' => $value ['sid']
  9675. );
  9676. $html = "";
  9677. }
  9678. }
  9679. $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>
  9680. <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>
  9681. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9682. $collectHtml [$vlu ['cid']] = array (
  9683. 'html' => $hl,
  9684. 'sid' => ''
  9685. );
  9686. }
  9687. $data ['companyHtml'] = $collectHtml;
  9688. // total price html
  9689. $collectHtml = "";
  9690. $total = 0;
  9691. for($i = 1; $i <= 12; $i ++) {
  9692. $sumPrice = 0;
  9693. foreach ( $itemStatisticsList as $key => $value ) {
  9694. if ($value ['month'] == $i) {
  9695. $sumPrice += $value ['price'];
  9696. }
  9697. }
  9698. if ($sumPrice == 0)
  9699. $collectHtml .= '<td class="taR">-</td>';
  9700. else
  9701. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9702. $total += $sumPrice;
  9703. }
  9704. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9705. $data ['companyTotalHtml'] = $collectHtml;
  9706. $data ['total'] = $total;
  9707. $data ['nature'] =$nature;
  9708. $data ['year'] = $year;
  9709. $data ['memu'] = "receipt";
  9710. $data ['staff'] = $this->staff;
  9711. $data ['receiptMemu'] = 'companyCategoryCollect';
  9712. $data ['verifyId'] = $this->verifyId;
  9713. $data ['executeId'] = $this->executeId;
  9714. if ($year <= date ( "Y" )) {
  9715. Doo::loadModel ( 'receipt' );
  9716. $receipt = new receipt ();
  9717. $receiptList = $receipt->find ( array (
  9718. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9719. 'asArray' => true
  9720. ) );
  9721. if (empty ( $receiptList )) { // generated files
  9722. ob_start ();
  9723. $this->render ( "/admin/saeaStaffCollectB", $data );
  9724. $this->cacheFile ( $path );
  9725. die ();
  9726. }
  9727. }
  9728. $this->render ( "/admin/saeaStaffCollectB", $data );
  9729. }
  9730. function staffCollectBak() {
  9731. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9732. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9733. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9734. $this->showCache ( $path );
  9735. Doo::loadModel ( 'statistics' );
  9736. $statistics = new statistics ();
  9737. Doo::loadModel ( "receiptDetail" );
  9738. $receiptDetail = new receiptDetail ();
  9739. Doo::loadModel ( 'L_category' );
  9740. $Lcategory = new L_category ();
  9741. Doo::loadModel ( 'accountItem' );
  9742. $accountItem = new accountItem ();
  9743. Doo::loadModel ( 'staff' );
  9744. $staff = new staff ();
  9745. Doo::loadModel ( 'itemStatistics' );
  9746. $itemStatistics = new itemStatistics ();
  9747. $itemStatisticsList = $itemStatistics->find ( array (
  9748. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9749. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9750. 'groupby' => 'staff,itemCategory,Month(date)',
  9751. 'asArray' => true
  9752. ) );
  9753. $itemCategoryList = $itemStatistics->find ( array (
  9754. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9755. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9756. 'groupby' => 'cid,itemCategory,Month(date)',
  9757. 'asArray' => true
  9758. ) );
  9759. $LcategoryList = $Lcategory->find ( array (
  9760. 'asArray' => true
  9761. ) );
  9762. $staffList = $staff->find ( array (
  9763. 'asArray' => true
  9764. ) );
  9765. $htmlArray = array ();
  9766. foreach ( $LcategoryList as $value ) {
  9767. $htmlArray [$value ['title']] = array ();
  9768. foreach ( $staffList as $v ) {
  9769. if ($value ['cid'] == $v ['cid']) {
  9770. $html = "";
  9771. $falg = true;
  9772. $staffSumPrice = 0;
  9773. foreach ( $itemStatisticsList as $a ) {
  9774. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9775. if (empty ( $a ['price'] )) {
  9776. $html .= '<td class="taR">-</td>';
  9777. $falg = false;
  9778. break;
  9779. } else {
  9780. $staffSumPrice += $a ['price'];
  9781. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9782. $falg = false;
  9783. break;
  9784. }
  9785. }
  9786. }
  9787. if ($falg) {
  9788. $html .= '<td class="taR">-</td>';
  9789. $falg = true;
  9790. }
  9791. $falg = true;
  9792. foreach ( $itemStatisticsList as $a ) {
  9793. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9794. if (empty ( $a ['price'] )) {
  9795. $html .= '<td class="taR">-</td>';
  9796. $falg = false;
  9797. break;
  9798. } else {
  9799. $staffSumPrice += $a ['price'];
  9800. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9801. $falg = false;
  9802. break;
  9803. }
  9804. }
  9805. }
  9806. if ($falg) {
  9807. $html .= '<td class="taR">-</td>';
  9808. $falg = true;
  9809. }
  9810. $falg = true;
  9811. foreach ( $itemStatisticsList as $a ) {
  9812. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9813. if (empty ( $a ['price'] )) {
  9814. $html .= '<td class="taR">-</td>';
  9815. $falg = false;
  9816. break;
  9817. } else {
  9818. $staffSumPrice += $a ['price'];
  9819. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9820. $falg = false;
  9821. break;
  9822. }
  9823. }
  9824. }
  9825. if ($falg) {
  9826. $html .= '<td class="taR">-</td>';
  9827. $falg = true;
  9828. }
  9829. $falg = true;
  9830. foreach ( $itemStatisticsList as $a ) {
  9831. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9832. if (! empty ( $a ['price'] )) {
  9833. $staffSumPrice += $a ['price'];
  9834. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9835. $falg = false;
  9836. break;
  9837. } else {
  9838. $html .= '<td class="taR">-</td>';
  9839. $falg = false;
  9840. break;
  9841. }
  9842. }
  9843. }
  9844. if ($falg) {
  9845. $html .= '<td class="taR">-</td>';
  9846. $falg = true;
  9847. }
  9848. $falg = true;
  9849. foreach ( $itemStatisticsList as $a ) {
  9850. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9851. if (! empty ( $a ['price'] )) {
  9852. $staffSumPrice += $a ['price'];
  9853. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9854. $falg = false;
  9855. break;
  9856. } else {
  9857. $html .= '<td class="taR">-</td>';
  9858. $falg = false;
  9859. break;
  9860. }
  9861. }
  9862. }
  9863. if ($falg) {
  9864. $html .= '<td class="taR">-</td>';
  9865. $falg = true;
  9866. }
  9867. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9868. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9869. }
  9870. }
  9871. /* -- --- */
  9872. // 合计费用
  9873. $cateHtml = "";
  9874. $catePrice = 0;
  9875. $cateFalg = true;
  9876. foreach ( $itemCategoryList as $l ) {
  9877. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9878. if (empty ( $l ['price'] )) {
  9879. $cateHtml .= '<td class="colGreen taR">-</td>';
  9880. $cateFalg = false;
  9881. break;
  9882. } else {
  9883. $catePrice += $l ['price'];
  9884. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9885. $cateFalg = false;
  9886. break;
  9887. }
  9888. }
  9889. }
  9890. if ($cateFalg) {
  9891. $cateHtml .= '<td class="colGreen taR">-</td>';
  9892. $cateFalg = true;
  9893. }
  9894. $cateFalg = true;
  9895. foreach ( $itemCategoryList as $l ) {
  9896. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9897. if (empty ( $l ['price'] )) {
  9898. $cateHtml .= '<td class="colGreen taR">-</td>';
  9899. $cateFalg = false;
  9900. break;
  9901. } else {
  9902. $catePrice += $l ['price'];
  9903. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9904. $cateFalg = false;
  9905. break;
  9906. }
  9907. }
  9908. }
  9909. if ($cateFalg) {
  9910. $cateHtml .= '<td class="colGreen taR">-</td>';
  9911. $cateFalg = true;
  9912. }
  9913. $cateFalg = true;
  9914. foreach ( $itemCategoryList as $l ) {
  9915. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9916. if (empty ( $l ['price'] )) {
  9917. $cateHtml .= '<td class="colGreen taR">-</td>';
  9918. $cateFalg = false;
  9919. break;
  9920. } else {
  9921. $catePrice += $l ['price'];
  9922. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9923. $cateFalg = false;
  9924. break;
  9925. }
  9926. }
  9927. }
  9928. if ($cateFalg) {
  9929. $cateHtml .= '<td class="colGreen taR">-</td>';
  9930. $cateFalg = true;
  9931. }
  9932. $cateFalg = true;
  9933. foreach ( $itemCategoryList as $l ) {
  9934. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  9935. if (empty ( $l ['price'] )) {
  9936. $cateHtml .= '<td class="colGreen taR">-</td>';
  9937. $cateFalg = false;
  9938. break;
  9939. } else {
  9940. $catePrice += $l ['price'];
  9941. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9942. $cateFalg = false;
  9943. break;
  9944. }
  9945. }
  9946. }
  9947. if ($cateFalg) {
  9948. $cateHtml .= '<td class="colGreen taR">-</td>';
  9949. $cateFalg = true;
  9950. }
  9951. $cateFalg = true;
  9952. foreach ( $itemCategoryList as $l ) {
  9953. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  9954. if (empty ( $l ['price'] )) {
  9955. $cateHtml .= '<td class="colGreen taR">-</td>';
  9956. $cateFalg = false;
  9957. break;
  9958. } else {
  9959. $catePrice += $l ['price'];
  9960. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9961. $cateFalg = false;
  9962. break;
  9963. }
  9964. }
  9965. }
  9966. if ($cateFalg) {
  9967. $cateHtml .= '<td class="colGreen taR">-</td>';
  9968. $cateFalg = true;
  9969. }
  9970. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  9971. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  9972. /* -- --- */
  9973. }
  9974. // print_r($htmlArray);die;
  9975. $data ['htmlArray'] = $htmlArray;
  9976. // statistics html
  9977. $stList = $statistics->getOne ( array (
  9978. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  9979. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9980. 'groupby' => 'Month(date)',
  9981. 'asArray' => true
  9982. ) );
  9983. if (empty ( $stList ))
  9984. $stList = array (
  9985. 'rePrice' => 0,
  9986. 'agPrice' => 0
  9987. );
  9988. $data ['stList'] = array (
  9989. 'rePrice' => $stList ['rePrice'],
  9990. 'agPrice' => $stList ['agPrice'],
  9991. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9992. );
  9993. $monthHtml = "";
  9994. for($i = 1; $i <= 12; $i ++) {
  9995. if ($i == $month)
  9996. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  9997. else
  9998. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  9999. }
  10000. $data ['monthHtml'] = $monthHtml;
  10001. $data ['year'] = $year;
  10002. $data ['month'] = $month;
  10003. $data ['memu'] = "receipt";
  10004. $data ['staff'] = $this->staff;
  10005. $data ['receiptMemu'] = 'companyCategoryCollect';
  10006. $data ['verifyId'] = $this->verifyId;
  10007. $data ['executeId'] = $this->executeId;
  10008. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10009. Doo::loadModel ( 'receipt' );
  10010. $receipt = new receipt ();
  10011. $receiptList = $receipt->find ( array (
  10012. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10013. 'asArray' => true
  10014. ) );
  10015. if (empty ( $receiptList )) { // generated files
  10016. ob_start ();
  10017. $this->render ( "/admin/saeaStaffCollect", $data );
  10018. $this->cacheFile ( $path );
  10019. die ();
  10020. }
  10021. }
  10022. $this->render ( "/admin/saeaStaffCollect", $data );
  10023. }
  10024. /**
  10025. * 日常收支
  10026. */
  10027. function payments() {
  10028. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10029. Doo::loadModel ( "execute" );
  10030. $execute = new execute ();
  10031. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10032. die ( 'illegal request' );
  10033. }
  10034. Doo::loadModel ( "accountBook" );
  10035. $accountBook = new accountBook ();
  10036. Doo::loadModel ( "accountBookStatistics" );
  10037. $accountBookStatistics = new accountBookStatistics ();
  10038. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10039. $list = $accountBook->getAccountBookByLimit ( 10 );
  10040. $data ['date'] = date ( "Y-m-d" );
  10041. $data ['statisticsList'] = $statisticsList;
  10042. $data ['list'] = $list;
  10043. $data ['memu'] = "receipt";
  10044. $data ['staff'] = $this->staff;
  10045. $data ['receiptMemu'] = 'payments';
  10046. $data ['verifyId'] = $this->verifyId;
  10047. $data ['executeId'] = $this->executeId;
  10048. $this->render ( "/expenses/payments", $data );
  10049. }
  10050. function paymentsIncomeDo() {
  10051. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10052. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10053. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10054. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10055. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10056. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10057. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10058. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10059. Doo::loadClass ( 'XDeode' );
  10060. $XDeode = new XDeode ( 5 );
  10061. Doo::loadModel ( "accountBook" );
  10062. Doo::loadModel ( "accountBookStatistics" );
  10063. Doo::loadModel ( 'wasteBook' );
  10064. // 记录流水时银行的转换
  10065. $accountBank = '';
  10066. if ($receivedBank == '纵横广发') {
  10067. $accountBank = 'CGBDeposit';
  10068. } elseif ($receivedBank == '纵横工行') {
  10069. $accountBank = 'ICBCDeposit';
  10070. } elseif ($receivedBank == '华润银行') {
  10071. $accountBank = 'HUADeposit';
  10072. } elseif ($receivedBank == '个人广发') {
  10073. $accountBank = 'PersonalDeposit';
  10074. }
  10075. if (empty ( $accountBank ))
  10076. die ( 'illegal request' );
  10077. // 收入为理财时特殊处理
  10078. if ($accountType == 7 || $accountType == 9) {
  10079. if ($receivedBank == '个人广发') {
  10080. die ( '个人广发 illegal request' );
  10081. }
  10082. // 添加一条收入
  10083. $accountBook = new accountBook ();
  10084. $accountBook->accountType = 10;
  10085. $accountBook->accountMsg = $accountMsg;
  10086. $accountBook->receivedPrice = $receivedPrice;
  10087. $accountBook->receivedMsg = $receivedMsg;
  10088. $accountBook->receivedBank = $receivedBank;
  10089. $accountBook->receivedDate = $receivedDate;
  10090. $accountBook->remarks = $remarks;
  10091. $accountBook->expensesType = 1;
  10092. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10093. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10094. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10095. $inComeId = $accountBook->insert ();
  10096. // 收支汇总-添加一条收入日常汇总
  10097. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10098. $accountBookStatistics = new accountBookStatistics ();
  10099. $item = array (
  10100. 'date' => date ( "Y-m-d" ),
  10101. 'accountType' => $abDetail ['accountType'],
  10102. 'accountMsg' => $abDetail ['accountMsg'],
  10103. 'aid' => $abDetail ['aid'],
  10104. 'inComePrice' => $abDetail ['receivedPrice'],
  10105. 'expensesType' => $abDetail ['expensesType']
  10106. );
  10107. $accountBookStatistics->setAccountBookStatistics ( $item );
  10108. // 添加收入流水
  10109. $wasteBook = new wasteBook ();
  10110. $itemWaste = array (
  10111. 'accountPriceShow' => $receivedPrice,
  10112. 'accountPrice' => $receivedPrice,
  10113. 'expensesType' => 1,
  10114. 'accountType' => 6, // 流水类型
  10115. 'dataID' => $inComeId,
  10116. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10117. 'accountBank' => $accountBank,
  10118. 'category' => $this->staff [0] ['category'],
  10119. 'cid' => $this->staff [0] ['cid'],
  10120. 'name' => $this->staff [0] ['username'],
  10121. 'sid' => $this->staff [0] ['sid'],
  10122. 'inputDate' => date ( "Y-m-d H:i:s" )
  10123. );
  10124. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10125. // 添加一条理财支出
  10126. $accountBank = 'CGBDeposit';
  10127. $expenditureBank = '纵横广发';
  10128. $dailyExpenditureType = 4;
  10129. if ($accountType == 9) {
  10130. $accountBank = 'ICBCDeposit';
  10131. $expenditureBank = '纵横工行';
  10132. $dailyExpenditureType = 6;
  10133. }
  10134. $accountBook = new accountBook ();
  10135. $accountBook->expensesType = 2;
  10136. $accountBook->expenditureType = $dailyExpenditureType;
  10137. $accountBook->expenditureMsg = $accountMsg;
  10138. $accountBook->expenditurePrice = $receivedPrice;
  10139. $accountBook->expenditureBank = $expenditureBank;
  10140. $accountBook->expenditureDate = $receivedDate;
  10141. $accountBook->remarks = $remarks;
  10142. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10143. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10144. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10145. $id = $accountBook->insert ();
  10146. // 收支汇总-添加一条理财支出汇总
  10147. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10148. $accountBookStatistics = new accountBookStatistics ();
  10149. $item = array (
  10150. 'date' => date ( "Y-m-d" ),
  10151. 'accountType' => $abDetail ['accountType'],
  10152. 'accountMsg' => $abDetail ['accountMsg'],
  10153. 'aid' => $abDetail ['aid'],
  10154. 'financingPrice' => - $receivedPrice,
  10155. 'expensesType' => 3
  10156. );
  10157. $accountBookStatistics->setAccountBookStatistics ( $item );
  10158. // 添加一条支出理财流水
  10159. $accountTypeWaste = 5;
  10160. if ($accountMsg == '公司固定') {
  10161. $accountTypeWaste = 9;
  10162. } elseif ($accountMsg == '公司活期') {
  10163. $accountTypeWaste = 10;
  10164. } elseif ($accountMsg == '个人(GR)') {
  10165. $accountBank = 'PersonalDeposit';
  10166. }
  10167. $itemWaste = array (
  10168. 'expensesType' => 2,
  10169. 'accountType' => $accountTypeWaste,
  10170. 'accountPriceShow' => $receivedPrice,
  10171. 'accountPrice' => - $receivedPrice,
  10172. 'dataID' => $id,
  10173. 'dailyExpenditureType' => $dailyExpenditureType,
  10174. 'accountBank' => $accountBank,
  10175. 'category' => $this->staff [0] ['category'],
  10176. 'cid' => $this->staff [0] ['cid'],
  10177. 'name' => $this->staff [0] ['username'],
  10178. 'sid' => $this->staff [0] ['sid'],
  10179. 'inputDate' => date ( "Y-m-d H:i:s" )
  10180. );
  10181. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10182. } elseif ($accountType == 1) {
  10183. if ($receivedBank == '个人广发')
  10184. die ( 'illegal request' );
  10185. // 添加一条收入
  10186. $accountBook = new accountBook ();
  10187. $accountBook->accountType = $accountType;
  10188. $accountBook->accountMsg = $accountMsg;
  10189. $accountBook->receivedPrice = $receivedPrice;
  10190. $accountBook->receivedMsg = $receivedMsg;
  10191. $accountBook->receivedBank = $receivedBank;
  10192. $accountBook->receivedDate = $receivedDate;
  10193. $accountBook->remarks = $remarks;
  10194. $accountBook->expensesType = 1;
  10195. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10196. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10197. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10198. $id = $accountBook->insert ();
  10199. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10200. // 收支汇总-添加一条收入日常汇总
  10201. $accountBookStatistics = new accountBookStatistics ();
  10202. $item = array (
  10203. 'date' => date ( "Y-m-d" ),
  10204. 'accountType' => $abDetail ['accountType'],
  10205. 'accountMsg' => $abDetail ['accountMsg'],
  10206. 'aid' => $abDetail ['aid'],
  10207. 'expensesType' => $abDetail ['expensesType']
  10208. );
  10209. if ($abDetail ['accountType'] == 8) {
  10210. $item += array (
  10211. 'inComePrice' => $abDetail ['receivedPrice']
  10212. );
  10213. } else {
  10214. $item += array (
  10215. 'inComePrice' => $abDetail ['receivedPrice']
  10216. );
  10217. }
  10218. $accountBookStatistics->setAccountBookStatistics ( $item );
  10219. // 流水存储方向
  10220. $itemWaste = array (
  10221. 'accountType' => 6
  10222. ); // 流水类型
  10223. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10224. // }else
  10225. if ($accountMsg == '活期理财收益') {
  10226. $itemWaste = array (
  10227. 'accountType' => 10
  10228. ); // 流水类型
  10229. }
  10230. // 添加收入流水
  10231. $wasteBook = new wasteBook ();
  10232. $itemWaste += array (
  10233. 'accountPrice' => $receivedPrice,
  10234. 'accountPriceShow' => $receivedPrice,
  10235. 'expensesType' => 1,
  10236. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10237. 'dataID' => $id,
  10238. 'accountBank' => $accountBank,
  10239. 'category' => $this->staff [0] ['category'],
  10240. 'cid' => $this->staff [0] ['cid'],
  10241. 'name' => $this->staff [0] ['username'],
  10242. 'sid' => $this->staff [0] ['sid'],
  10243. 'inputDate' => date ( "Y-m-d H:i:s" )
  10244. );
  10245. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10246. } else { // 普通日常收入处理
  10247. // 添加一条收入
  10248. $accountBook = new accountBook ();
  10249. $accountBook->accountType = $accountType;
  10250. $accountBook->accountMsg = $accountMsg;
  10251. $accountBook->receivedPrice = $receivedPrice;
  10252. $accountBook->receivedMsg = $receivedMsg;
  10253. $accountBook->receivedBank = $receivedBank;
  10254. $accountBook->receivedDate = $receivedDate;
  10255. $accountBook->remarks = $remarks;
  10256. $accountBook->expensesType = 1;
  10257. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10258. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10259. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10260. $id = $accountBook->insert ();
  10261. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10262. // 收支汇总-添加一条收入日常汇总
  10263. $accountBookStatistics = new accountBookStatistics ();
  10264. $item = array (
  10265. 'date' => date ( "Y-m-d" ),
  10266. 'accountType' => $abDetail ['accountType'],
  10267. 'accountMsg' => $abDetail ['accountMsg'],
  10268. 'aid' => $abDetail ['aid'],
  10269. 'expensesType' => $abDetail ['expensesType']
  10270. );
  10271. if ($abDetail ['accountType'] == 8) {
  10272. $item += array (
  10273. 'inComePrice' => $abDetail ['receivedPrice']
  10274. );
  10275. } else {
  10276. $item += array (
  10277. 'inComePrice' => $abDetail ['receivedPrice']
  10278. );
  10279. }
  10280. $accountBookStatistics->setAccountBookStatistics ( $item );
  10281. // 添加收入流水
  10282. $itemWaste = array (
  10283. 'accountPrice' => $receivedPrice
  10284. );
  10285. if ($receivedBank == '个人广发') {
  10286. $itemWaste = array (
  10287. 'accountPrice' => - $receivedPrice
  10288. );
  10289. }
  10290. $wasteBook = new wasteBook ();
  10291. $itemWaste += array (
  10292. 'accountPriceShow' => $receivedPrice,
  10293. 'expensesType' => 1,
  10294. 'accountType' => 6, // 流水类型
  10295. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10296. 'dataID' => $id,
  10297. 'accountBank' => $accountBank,
  10298. 'category' => $this->staff [0] ['category'],
  10299. 'cid' => $this->staff [0] ['cid'],
  10300. 'name' => $this->staff [0] ['username'],
  10301. 'sid' => $this->staff [0] ['sid'],
  10302. 'inputDate' => date ( "Y-m-d H:i:s" )
  10303. );
  10304. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10305. }
  10306. }
  10307. return '/payments';
  10308. }
  10309. /**
  10310. * 添加收入
  10311. * @return string
  10312. */
  10313. function paymentsIncomeDo_() {
  10314. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10315. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10316. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10317. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10318. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10319. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10320. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10321. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10322. Doo::loadClass ( 'XDeode' );
  10323. $XDeode = new XDeode ( 5 );
  10324. Doo::loadModel ( "accountBook" );
  10325. $accountBook = new accountBook ();
  10326. $accountBank = '';
  10327. $accountTypeWaste = 6;
  10328. if ($receivedBank == '纵横广发') {
  10329. $accountBank = 'CGBDeposit';
  10330. } elseif ($receivedBank == '纵横工行') {
  10331. $accountBank = 'ICBCDeposit';
  10332. } elseif ($receivedBank == '华润银行') {
  10333. $accountBank = 'HUADeposit';
  10334. } elseif ($receivedBank == '个人广发') {
  10335. $accountBank = 'PersonalDeposit';
  10336. }
  10337. if (empty ( $accountBank ))
  10338. die ( 'illegal request' );
  10339. $dailyIncomeType = '';
  10340. $itemWaste = array (
  10341. 'accountPrice' => $receivedPrice,
  10342. 'expensesType' => 1
  10343. );
  10344. if ($receivedBank == '个人广发') {
  10345. $itemWaste = array (
  10346. 'accountPrice' => - $receivedPrice,
  10347. 'expensesType' => 1
  10348. );
  10349. }
  10350. if ($accountType == 4) {
  10351. $dailyIncomeType = 4;
  10352. } elseif ($accountType == 1) {
  10353. $dailyIncomeType = 1;
  10354. } elseif ($accountType == 2) {
  10355. $dailyIncomeType = 2;
  10356. } elseif ($accountType == 3) {
  10357. $dailyIncomeType = 3;
  10358. } elseif ($accountType == 5) {
  10359. $dailyIncomeType = 5;
  10360. } elseif ($accountType == 6) {
  10361. $dailyIncomeType = 6;
  10362. } elseif ($accountType == 7 || $accountType == 9) {
  10363. $dailyIncomeType = 7;
  10364. if ($accountMsg == '公司固定') {
  10365. $accountTypeWaste = 9;
  10366. } elseif ($accountMsg == '公司活期') {
  10367. $accountTypeWaste = 10;
  10368. } elseif ($accountMsg == '个人(GR)') {
  10369. $accountBank = 'PersonalDeposit';
  10370. }
  10371. $itemWaste = array (
  10372. 'accountPrice' => - $receivedPrice,
  10373. 'expensesType' => 2
  10374. );
  10375. } elseif ($accountType == 8) {
  10376. $dailyIncomeType = 8;
  10377. }
  10378. if (empty ( $dailyIncomeType ))
  10379. die ( 'illegal request' );
  10380. $accountBook->accountType = $accountType;
  10381. $accountBook->accountMsg = $accountMsg;
  10382. $accountBook->receivedPrice = $receivedPrice;
  10383. $accountBook->receivedMsg = $receivedMsg;
  10384. $accountBook->receivedBank = $receivedBank;
  10385. $accountBook->receivedDate = $receivedDate;
  10386. $accountBook->remarks = $remarks;
  10387. $accountBook->expensesType = 1;
  10388. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10389. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10390. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10391. $id = $accountBook->insert ();
  10392. //
  10393. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10394. // 收支汇总
  10395. Doo::loadModel ( "accountBookStatistics" );
  10396. $accountBookStatistics = new accountBookStatistics ();
  10397. $item = array (
  10398. 'date' => date ( "Y-m-d" ),
  10399. 'accountType' => $abDetail ['accountType'],
  10400. 'accountMsg' => $abDetail ['accountMsg'],
  10401. 'aid' => $abDetail ['aid']
  10402. );
  10403. if ($abDetail ['expensesType'] == 1) {
  10404. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10405. $item += array (
  10406. 'financingPrice' => - $receivedPrice,
  10407. 'expensesType' => 3
  10408. );
  10409. } else if ($abDetail ['accountType'] == 8) {
  10410. $item += array (
  10411. 'inComePrice' => - $abDetail ['receivedPrice'],
  10412. 'expensesType' => $abDetail ['expensesType']
  10413. );
  10414. } else {
  10415. $item += array (
  10416. 'inComePrice' => $abDetail ['receivedPrice'],
  10417. 'expensesType' => $abDetail ['expensesType']
  10418. );
  10419. }
  10420. }
  10421. $accountBookStatistics->setAccountBookStatistics ( $item );
  10422. // 为理财时需添加一条日常支出
  10423. if ($accountType == 7 || $accountType == 9) {
  10424. }
  10425. // 公司流水记录
  10426. Doo::loadModel ( 'wasteBook' );
  10427. $wasteBook = new wasteBook ();
  10428. // 银行
  10429. // if (empty($abDetail)){
  10430. $itemWaste += array (
  10431. 'accountPriceShow' => $receivedPrice,
  10432. 'dataID' => $id,
  10433. 'accountType' => $accountTypeWaste,
  10434. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10435. 'accountBank' => $accountBank,
  10436. 'category' => $this->staff [0] ['category'],
  10437. 'cid' => $this->staff [0] ['cid'],
  10438. 'name' => $this->staff [0] ['username'],
  10439. 'sid' => $this->staff [0] ['sid'],
  10440. 'inputDate' => date ( "Y-m-d H:i:s" )
  10441. );
  10442. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10443. // }
  10444. // 类型为理财7或者9 要添加一笔理财支出
  10445. if ($accountType == 7 || $accountType == 9) {
  10446. $accountBank = 'CGBDeposit';
  10447. $expenditureBank = '纵横广发';
  10448. $dailyExpenditureType = 4;
  10449. if ($accountType == 9) {
  10450. $accountBank = 'ICBCDeposit';
  10451. $expenditureBank = '纵横工行';
  10452. $dailyExpenditureType = 6;
  10453. }
  10454. // 添加一条支出
  10455. $accountBook = new accountBook ();
  10456. $accountBook->expenditureType = $dailyExpenditureType;
  10457. $accountBook->expenditureMsg = $accountMsg;
  10458. $accountBook->expenditurePrice = $receivedPrice;
  10459. $accountBook->expenditureBank = $expenditureBank;
  10460. $accountBook->expenditureDate = $receivedDate;
  10461. $accountBook->remarks = $remarks;
  10462. $accountBook->expensesType = 2;
  10463. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10464. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10465. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10466. $id = $accountBook->insert ();
  10467. // 添加一条收入流水
  10468. $itemWaste = array (
  10469. 'accountPriceShow' => $receivedPrice,
  10470. 'accountPrice' => $receivedPrice,
  10471. 'dataID' => $id,
  10472. 'expensesType' => 2,
  10473. 'accountType' => $accountTypeWaste,
  10474. 'dailyExpenditureType' => $dailyExpenditureType,
  10475. 'accountBank' => $accountBank,
  10476. 'category' => $this->staff [0] ['category'],
  10477. 'cid' => $this->staff [0] ['cid'],
  10478. 'name' => $this->staff [0] ['username'],
  10479. 'sid' => $this->staff [0] ['sid'],
  10480. 'inputDate' => date ( "Y-m-d H:i:s" )
  10481. );
  10482. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10483. }
  10484. }
  10485. return '/payments';
  10486. }
  10487. function paymentsExpenditureDo() {
  10488. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10489. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10490. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10491. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10492. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10493. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10494. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10495. // 理财支出特殊处理
  10496. Doo::loadModel ( "accountBook" );
  10497. Doo::loadModel ( "accountBookStatistics" );
  10498. Doo::loadModel ( 'wasteBook' );
  10499. $accountBank = '';
  10500. if ($expenditureBank == '纵横广发') {
  10501. $accountBank = 'CGBDeposit';
  10502. } elseif ($expenditureBank == '纵横工行') {
  10503. $accountBank = 'ICBCDeposit';
  10504. } elseif ($expenditureBank == '华润银行') {
  10505. $accountBank = 'HUADeposit';
  10506. } elseif ($expenditureBank == '个人广发') {
  10507. $accountBank = 'PersonalDeposit';
  10508. }
  10509. if (empty ( $accountBank ))
  10510. die ( 'illegal request' );
  10511. if ($expenditureType == 4 || $expenditureType == 6) {
  10512. if ($expenditureBank == '个人广发') {
  10513. die ( '个人广发 illegal request' );
  10514. }
  10515. // 添加一笔日常支出
  10516. $accountBook = new accountBook ();
  10517. $accountBook->expensesType = 2;
  10518. $accountBook->expenditureType = 7;
  10519. $accountBook->expenditureMsg = $expenditureMsg;
  10520. $accountBook->expenditurePrice = $expenditurePrice;
  10521. $accountBook->expenditureBank = $expenditureBank;
  10522. $accountBook->expenditureDate = $expenditureDate;
  10523. $accountBook->remarks = $remarks;
  10524. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10525. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10526. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10527. $expenditureId = $accountBook->insert ();
  10528. // 添加日常支出汇总
  10529. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10530. $accountBookStatistics = new accountBookStatistics ();
  10531. $item = array (
  10532. 'date' => date ( "Y-m-d" ),
  10533. 'expenditureType' => $abDetail ['expenditureType'],
  10534. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10535. 'aid' => $abDetail ['aid'],
  10536. 'payPrice' => $abDetail ['expenditurePrice'],
  10537. 'expensesType' => $abDetail ['expensesType']
  10538. );
  10539. $accountBookStatistics->setAccountBookStatistics ( $item );
  10540. // 公司日常支出流水
  10541. $wasteBook = new wasteBook ();
  10542. $itemWaste = array (
  10543. 'accountPrice' => - $expenditurePrice
  10544. );
  10545. if ($expenditureBank == '个人广发') {
  10546. $itemWaste = array (
  10547. 'accountPrice' => $expenditurePrice
  10548. );
  10549. }
  10550. $itemWaste += array (
  10551. 'expensesType' => 2,
  10552. 'accountType' => 5,
  10553. 'dailyExpenditureType' => $expenditureType,
  10554. 'accountPriceShow' => $expenditurePrice,
  10555. 'accountPrice' => - $expenditurePrice,
  10556. 'dataID' => $expenditureId,
  10557. 'accountBank' => $accountBank,
  10558. 'category' => $this->staff [0] ['category'],
  10559. 'cid' => $this->staff [0] ['cid'],
  10560. 'name' => $this->staff [0] ['username'],
  10561. 'sid' => $this->staff [0] ['sid'],
  10562. 'inputDate' => date ( "Y-m-d H:i:s" )
  10563. );
  10564. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10565. // 添加一笔理财收入
  10566. $accountBank = 'CGBDeposit';
  10567. $dailyIncomeType = 7;
  10568. $receivedBank = '纵横广发';
  10569. if ($expenditureType == 6) {
  10570. $accountBank = 'ICBCDeposit';
  10571. $receivedBank = '纵横工行';
  10572. $dailyIncomeType = 9;
  10573. }
  10574. $accountBook = new accountBook ();
  10575. $accountBook->expensesType = 1;
  10576. $accountBook->accountType = $dailyIncomeType;
  10577. $accountBook->accountMsg = $expenditureMsg;
  10578. $accountBook->receivedPrice = $expenditurePrice;
  10579. $accountBook->receivedBank = $receivedBank;
  10580. $accountBook->receivedDate = $expenditureDate;
  10581. $accountBook->remarks = $remarks;
  10582. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10583. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10584. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10585. $id = $accountBook->insert ();
  10586. // 添加日常理财收入汇总
  10587. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10588. $accountBookStatistics = new accountBookStatistics ();
  10589. $item = array (
  10590. 'date' => date ( "Y-m-d" ),
  10591. 'expenditureType' => $abDetail ['expenditureType'],
  10592. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10593. 'aid' => $abDetail ['aid'],
  10594. 'financingPrice' => $expenditurePrice,
  10595. 'expensesType' => 3
  10596. );
  10597. $accountBookStatistics->setAccountBookStatistics ( $item );
  10598. // 添加一笔收入流水
  10599. if ($expenditureMsg == '公司固定') {
  10600. $accountTypeWaste = 9;
  10601. } elseif ($expenditureMsg == '公司活期') {
  10602. $accountTypeWaste = 10;
  10603. } elseif ($expenditureMsg == '个人(GR)') {
  10604. $accountBank = 'PersonalDeposit';
  10605. }
  10606. $itemWaste = array (
  10607. 'expensesType' => 1,
  10608. 'accountType' => $accountTypeWaste,
  10609. 'accountPriceShow' => $expenditurePrice,
  10610. 'accountPrice' => $expenditurePrice,
  10611. 'dataID' => $id,
  10612. 'dailyIncomeType' => $dailyIncomeType,
  10613. 'accountBank' => $accountBank,
  10614. 'category' => $this->staff [0] ['category'],
  10615. 'cid' => $this->staff [0] ['cid'],
  10616. 'name' => $this->staff [0] ['username'],
  10617. 'sid' => $this->staff [0] ['sid'],
  10618. 'inputDate' => date ( "Y-m-d H:i:s" )
  10619. );
  10620. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10621. } else {
  10622. // 添加一笔日常支出
  10623. $accountBook = new accountBook ();
  10624. $accountBook->expensesType = 2;
  10625. $accountBook->expenditureType = $expenditureType;
  10626. $accountBook->expenditureMsg = $expenditureMsg;
  10627. $accountBook->expenditurePrice = $expenditurePrice;
  10628. $accountBook->expenditureBank = $expenditureBank;
  10629. $accountBook->expenditureDate = $expenditureDate;
  10630. $accountBook->remarks = $remarks;
  10631. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10632. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10633. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10634. $id = $accountBook->insert ();
  10635. // 添加日常支出汇总
  10636. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10637. $accountBookStatistics = new accountBookStatistics ();
  10638. $item = array (
  10639. 'date' => date ( "Y-m-d" ),
  10640. 'expenditureType' => $abDetail ['expenditureType'],
  10641. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10642. 'aid' => $abDetail ['aid'],
  10643. 'expensesType' => $abDetail ['expensesType']
  10644. );
  10645. if ($expenditureType == 5) {
  10646. $item += array (
  10647. 'payPrice' => - $abDetail ['expenditurePrice']
  10648. );
  10649. } else {
  10650. $item += array (
  10651. 'payPrice' => $abDetail ['expenditurePrice']
  10652. );
  10653. }
  10654. $accountBookStatistics->setAccountBookStatistics ( $item );
  10655. // 公司日常支出流水
  10656. $wasteBook = new wasteBook ();
  10657. $itemWaste = array (
  10658. 'accountPrice' => - $expenditurePrice
  10659. );
  10660. if ($expenditureBank == '个人广发') {
  10661. $itemWaste = array (
  10662. 'accountPrice' => $expenditurePrice
  10663. );
  10664. }
  10665. $itemWaste += array (
  10666. 'expensesType' => 2,
  10667. 'accountType' => 5,
  10668. 'accountPriceShow' => $expenditurePrice,
  10669. 'dataID' => $id,
  10670. 'dailyExpenditureType' => $expenditureType,
  10671. 'accountBank' => $accountBank,
  10672. 'category' => $this->staff [0] ['category'],
  10673. 'cid' => $this->staff [0] ['cid'],
  10674. 'name' => $this->staff [0] ['username'],
  10675. 'sid' => $this->staff [0] ['sid'],
  10676. 'inputDate' => date ( "Y-m-d H:i:s" )
  10677. );
  10678. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10679. }
  10680. }
  10681. return '/payments';
  10682. }
  10683. /**
  10684. * 添加支出
  10685. */
  10686. function paymentsExpenditureDo_() {
  10687. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10688. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10689. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10690. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10691. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10692. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10693. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10694. $dailyExpenditureType = '';
  10695. $accountTypeWaste = 5;
  10696. $accountBank = '';
  10697. if ($expenditureBank == '纵横广发') {
  10698. $accountBank = 'CGBDeposit';
  10699. } elseif ($expenditureBank == '纵横工行') {
  10700. $accountBank = 'ICBCDeposit';
  10701. } elseif ($expenditureBank == '华润银行') {
  10702. $accountBank = 'HUADeposit';
  10703. } elseif ($expenditureBank == '个人广发') {
  10704. $accountBank = 'PersonalDeposit';
  10705. }
  10706. if (empty ( $accountBank ))
  10707. die ( 'illegal request' );
  10708. $itemWaste = array (
  10709. 'accountPrice' => - $expenditurePrice
  10710. );
  10711. if ($expenditureBank == '个人广发') {
  10712. $itemWaste = array (
  10713. 'accountPrice' => $expenditurePrice
  10714. );
  10715. }
  10716. if ($expenditureType == 4 || $expenditureType == 6) {
  10717. $dailyExpenditureType = 4;
  10718. if ($expenditureMsg == '公司固定') {
  10719. $accountTypeWaste = 9;
  10720. } elseif ($expenditureMsg == '公司活期') {
  10721. $accountTypeWaste = 10;
  10722. } elseif ($expenditureMsg == '个人(GR)') {
  10723. $accountBank = 'PersonalDeposit';
  10724. }
  10725. $itemWaste = array (
  10726. 'accountPrice' => $expenditurePrice
  10727. );
  10728. } elseif ($expenditureType == 1) {
  10729. $dailyExpenditureType = 1;
  10730. } elseif ($expenditureType == 2) {
  10731. $dailyExpenditureType = 2;
  10732. } elseif ($expenditureType == 3) {
  10733. $dailyExpenditureType = 3;
  10734. } elseif ($expenditureType == 5) {
  10735. $dailyExpenditureType = 5;
  10736. }
  10737. if (empty ( $dailyExpenditureType ))
  10738. die ( 'illegal request' );
  10739. Doo::loadModel ( "accountBook" );
  10740. $accountBook = new accountBook ();
  10741. $accountBook->expenditureType = $expenditureType;
  10742. $accountBook->expenditureMsg = $expenditureMsg;
  10743. $accountBook->expenditurePrice = $expenditurePrice;
  10744. $accountBook->expenditureBank = $expenditureBank;
  10745. $accountBook->expenditureDate = $expenditureDate;
  10746. $accountBook->remarks = $remarks;
  10747. $accountBook->expensesType = 2;
  10748. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10749. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10750. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10751. $id = $accountBook->insert ();
  10752. //
  10753. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10754. Doo::loadModel ( "accountBookStatistics" );
  10755. $accountBookStatistics = new accountBookStatistics ();
  10756. $item = array (
  10757. 'date' => date ( "Y-m-d" ),
  10758. 'expenditureType' => $abDetail ['expenditureType'],
  10759. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10760. 'aid' => $abDetail ['aid']
  10761. );
  10762. if ($abDetail ['expensesType'] == 2) {
  10763. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10764. $item += array (
  10765. 'financingPrice' => $expenditurePrice,
  10766. 'expensesType' => 3
  10767. );
  10768. } elseif ($abDetail ['expenditureType'] == 5) {
  10769. $item += array (
  10770. 'payPrice' => $abDetail ['expenditurePrice'],
  10771. 'expensesType' => $abDetail ['expensesType']
  10772. );
  10773. } else {
  10774. $item += array (
  10775. 'payPrice' => $abDetail ['expenditurePrice'],
  10776. 'expensesType' => $abDetail ['expensesType']
  10777. );
  10778. }
  10779. }
  10780. $accountBookStatistics->setAccountBookStatistics ( $item );
  10781. // 公司流水记录
  10782. Doo::loadModel ( 'wasteBook' );
  10783. $wasteBook = new wasteBook ();
  10784. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10785. // 银行
  10786. if (empty ( $abDetail )) {
  10787. $itemWaste += array (
  10788. 'accountPriceShow' => $expenditurePrice,
  10789. 'dataID' => $id,
  10790. 'expensesType' => 2,
  10791. 'accountType' => $accountTypeWaste,
  10792. 'dailyExpenditureType' => $expenditureType,
  10793. 'accountBank' => $accountBank,
  10794. 'category' => $this->staff [0] ['category'],
  10795. 'cid' => $this->staff [0] ['cid'],
  10796. 'name' => $this->staff [0] ['username'],
  10797. 'sid' => $this->staff [0] ['sid'],
  10798. 'inputDate' => date ( "Y-m-d H:i:s" )
  10799. );
  10800. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10801. }
  10802. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10803. if ($expenditureType == 4 || $expenditureType == 6) {
  10804. $accountBank = 'CGBDeposit';
  10805. $dailyIncomeType = 7;
  10806. $receivedBank = '纵横广发';
  10807. if ($expenditureType == 6) {
  10808. $accountBank = 'ICBCDeposit';
  10809. $receivedBank = '纵横工行';
  10810. $dailyIncomeType = 9;
  10811. }
  10812. // 添加一笔收入
  10813. $accountBook = new accountBook ();
  10814. $accountBook->accountType = $dailyIncomeType;
  10815. $accountBook->accountMsg = $expenditureMsg;
  10816. $accountBook->receivedPrice = $expenditurePrice;
  10817. $accountBook->receivedBank = $receivedBank;
  10818. $accountBook->receivedDate = $expenditureDate;
  10819. $accountBook->remarks = $remarks;
  10820. $accountBook->expensesType = 1;
  10821. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10822. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10823. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10824. $id = $accountBook->insert ();
  10825. // 添加一笔收入流水
  10826. $itemWaste = array (
  10827. 'accountPriceShow' => $expenditurePrice,
  10828. 'accountPrice' => - $expenditurePrice,
  10829. 'dataID' => $id,
  10830. 'expensesType' => 1,
  10831. 'accountType' => $accountTypeWaste,
  10832. 'dailyIncomeType' => $dailyIncomeType,
  10833. 'accountBank' => $accountBank,
  10834. 'category' => $this->staff [0] ['category'],
  10835. 'cid' => $this->staff [0] ['cid'],
  10836. 'name' => $this->staff [0] ['username'],
  10837. 'sid' => $this->staff [0] ['sid'],
  10838. 'inputDate' => date ( "Y-m-d H:i:s" )
  10839. );
  10840. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10841. }
  10842. }
  10843. return '/payments';
  10844. }
  10845. /**
  10846. * 所有收支
  10847. */
  10848. function paymentsAchieve() {
  10849. $page_size = 12;
  10850. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10851. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10852. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10853. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10854. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10855. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10856. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10857. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10858. Doo::loadModel ( "accountBookStatistics" );
  10859. $accountBookStatistics = new accountBookStatistics ();
  10860. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10861. $data ['statisticsList'] = $statisticsList;
  10862. Doo::loadModel ( "accountBook" );
  10863. $accountBook = new accountBook ();
  10864. $con = '';
  10865. if ($expensesType == 'INCOME')
  10866. $con = ' and expensesType=1 ';
  10867. elseif ($expensesType == 'PAY')
  10868. $con = ' and expensesType=2 ';
  10869. $dateArr = explode ( ':', $date );
  10870. $D1 = $dateString = '';
  10871. $D2 = '';
  10872. if (! empty ( $date )) {
  10873. $D1 = $dateArr [0];
  10874. if (isset ( $dateArr [1] ))
  10875. $D2 = $dateArr [1];
  10876. else
  10877. $D2 = '';
  10878. $dateString = $D1 . " : " . $D2;
  10879. }
  10880. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10881. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10882. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10883. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10884. if (! empty ( $price ))
  10885. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10886. if ($submitType == 1) {
  10887. if ($accountType != '') {
  10888. $expenditureType = '';
  10889. $con .= ' and accountType=' . $accountType;
  10890. if (! empty ( $accountMsg ))
  10891. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10892. }
  10893. } elseif ($submitType == 2) {
  10894. if ($expenditureType != '') {
  10895. $accountType = $accountMsg = '';
  10896. $con .= ' and expenditureType=' . $expenditureType;
  10897. }
  10898. } else {
  10899. $accountType = $accountMsg = $expenditureType = '';
  10900. }
  10901. $sql = "" . $con;
  10902. $action = "paymentsAchieve";
  10903. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10904. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10905. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10906. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10907. $data ['expenditureType'] = $expenditureType;
  10908. $data ['accountMsg'] = $accountMsg;
  10909. $data ['accountType'] = $accountType;
  10910. $data ['inputDate'] = $date;
  10911. $data ['price'] = $price;
  10912. $data ['expensesType'] = $expensesType;
  10913. $data ['page'] = $pageinfo;
  10914. $data ['list'] = $list;
  10915. $data ['memu'] = "receipt";
  10916. $data ['staff'] = $this->staff;
  10917. $data ['receiptMemu'] = 'payments';
  10918. $data ['verifyId'] = $this->verifyId;
  10919. $data ['executeId'] = $this->executeId;
  10920. $this->render ( "/expenses/paymentsAchieve", $data );
  10921. }
  10922. function paymentsIncomeUpdateDo() {
  10923. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10924. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10925. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10926. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10927. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10928. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10929. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10930. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10931. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10932. Doo::loadClass ( 'XDeode' );
  10933. $XDeode = new XDeode ( 5 );
  10934. $aid = $XDeode->decode ( $aidKey );
  10935. Doo::loadModel ( "accountBook" );
  10936. $accountBook = new accountBook ();
  10937. //
  10938. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10939. $price = $receivedPrice - $abDetail [inComePrice];
  10940. Doo::loadModel ( "accountBookStatistics" );
  10941. $accountBookStatistics = new accountBookStatistics ();
  10942. if ($abDetail ['accountType'] == 7) {
  10943. $item += array (
  10944. 'date' => date ( "Y-m-d" ),
  10945. 'financingPrice' => - $price,
  10946. 'expensesType' => 3,
  10947. 'aid' => $abDetail ['aid']
  10948. );
  10949. } elseif ($abDetail ['accountType'] == 8) {
  10950. $item += array (
  10951. 'date' => date ( "Y-m-d" ),
  10952. 'expensesType' => $abDetail ['expensesType'],
  10953. 'inComePrice' => - $price,
  10954. 'aid' => $abDetail ['aid']
  10955. );
  10956. } else {
  10957. $item = array (
  10958. 'date' => date ( "Y-m-d" ),
  10959. 'expensesType' => $abDetail ['expensesType'],
  10960. 'inComePrice' => $price,
  10961. 'aid' => $abDetail ['aid']
  10962. );
  10963. }
  10964. $accountBookStatistics->setAccountBookStatistics ( $item );
  10965. $accountBook->accountType = $accountType;
  10966. $accountBook->accountMsg = $accountMsg;
  10967. $accountBook->receivedPrice = $receivedPrice;
  10968. $accountBook->receivedMsg = $receivedMsg;
  10969. $accountBook->receivedBank = $receivedBank;
  10970. $accountBook->receivedDate = $receivedDate;
  10971. $accountBook->remarks = $remarks;
  10972. $accountBook->aid = $aid;
  10973. $accountBook->update ();
  10974. }
  10975. return '/paymentsAchieve';
  10976. }
  10977. function paymentsExpenditureEdiDo() {
  10978. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10979. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10980. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10981. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10982. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10983. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10984. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10985. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10986. Doo::loadClass ( 'XDeode' );
  10987. $XDeode = new XDeode ( 5 );
  10988. $aid = $XDeode->decode ( $aidKey );
  10989. Doo::loadModel ( "accountBook" );
  10990. $accountBook = new accountBook ();
  10991. // 汇总信息
  10992. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10993. $price = $expenditurePrice - $abDetail [expenditurePrice];
  10994. Doo::loadModel ( "accountBookStatistics" );
  10995. $accountBookStatistics = new accountBookStatistics ();
  10996. if ($abDetail ['expenditureType'] == 4) {
  10997. $item += array (
  10998. 'date' => date ( "Y-m-d" ),
  10999. 'financingPrice' => $price,
  11000. 'expensesType' => 3,
  11001. 'aid' => $abDetail ['aid']
  11002. );
  11003. } elseif ($abDetail ['expenditureType'] == 5) {
  11004. $item += array (
  11005. 'date' => date ( "Y-m-d" ),
  11006. 'expensesType' => $abDetail ['expensesType'],
  11007. 'payPrice' => $price,
  11008. 'aid' => $abDetail ['aid']
  11009. );
  11010. } else {
  11011. $item = array (
  11012. 'date' => date ( "Y-m-d" ),
  11013. 'expensesType' => $abDetail ['expensesType'],
  11014. 'payPrice' => $price,
  11015. 'aid' => $abDetail ['aid']
  11016. );
  11017. }
  11018. $accountBookStatistics->setAccountBookStatistics ( $item );
  11019. //
  11020. $accountBook->expenditureType = $expenditureType;
  11021. $accountBook->expenditureMsg = $expenditureMsg;
  11022. $accountBook->expenditurePrice = $expenditurePrice;
  11023. $accountBook->expenditureBank = $expenditureBank;
  11024. $accountBook->remarks = $remarks;
  11025. $accountBook->expenditureDate = $expenditureDate;
  11026. $accountBook->aid = $aid;
  11027. $id = $accountBook->update ();
  11028. }
  11029. return '/paymentsAchieve';
  11030. }
  11031. function paymentsDelDo() {
  11032. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11033. if (! empty ( $aidKey )) {
  11034. Doo::loadClass ( 'XDeode' );
  11035. $XDeode = new XDeode ( 5 );
  11036. $aid = $XDeode->decode ( $aidKey );
  11037. Doo::loadModel ( "accountBook" );
  11038. $accountBook = new accountBook ();
  11039. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11040. if (empty ( $abDetail ))
  11041. die ( 'illegal request' );
  11042. // 删除收支
  11043. Doo::loadModel ( "accountBookStatistics" );
  11044. $accountBookStatistics = new accountBookStatistics ();
  11045. $item = array (
  11046. 'date' => date ( "Y-m-d" ),
  11047. 'aid' => $abDetail ['aid']
  11048. );
  11049. $accountType = '';
  11050. if ($abDetail ['expensesType'] == 1) {
  11051. $accountType = 6;
  11052. if ($abDetail ['accountType'] != 7) {
  11053. $item += array (
  11054. 'expensesType' => $abDetail ['expensesType'],
  11055. 'inComePrice' => - $abDetail ['receivedPrice']
  11056. );
  11057. } else {
  11058. $item += array (
  11059. 'financingPrice' => $abDetail ['receivedPrice'],
  11060. 'expensesType' => 3
  11061. );
  11062. }
  11063. } elseif ($abDetail ['expensesType'] == 2) {
  11064. $accountType = 5;
  11065. if ($abDetail ['accountType'] != 7) {
  11066. $item += array (
  11067. 'expensesType' => $abDetail ['expensesType'],
  11068. 'payPrice' => - $abDetail ['expenditurePrice']
  11069. );
  11070. } else {
  11071. $item += array (
  11072. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11073. 'expensesType' => 3
  11074. );
  11075. }
  11076. }
  11077. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11078. if ($abDetail ['expenditureMsg'] == '公司固定')
  11079. $accountType = 9;
  11080. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11081. $accountType = 10;
  11082. }
  11083. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11084. if ($abDetail ['accountMsg'] == '公司固定')
  11085. $accountType = 9;
  11086. elseif ($abDetail ['accountMsg'] == '公司活期')
  11087. $accountType = 10;
  11088. }
  11089. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11090. $accountType = 10;
  11091. }
  11092. $accountBookStatistics->setAccountBookStatistics ( $item );
  11093. $accountBook->delete ( array (
  11094. 'where' => 'aid=' . $aid,
  11095. 'limit' => 1
  11096. ) );
  11097. // 删除收入流水
  11098. if (! empty ( $accountType )) {
  11099. Doo::loadModel ( 'wasteBook' );
  11100. $wasteBook = new wasteBook ();
  11101. $wasteBook->delete ( array (
  11102. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11103. 'limit' => 1
  11104. ) );
  11105. }
  11106. }
  11107. return '/paymentsAchieve';
  11108. }
  11109. function paymentsCollect() {
  11110. Doo::loadModel ( "execute" );
  11111. $execute = new execute ();
  11112. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11113. die ( 'illegal request' );
  11114. }
  11115. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11116. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11117. Doo::loadModel ( "accountBookStatistics" );
  11118. $accountBookStatistics = new accountBookStatistics ();
  11119. Doo::loadClass ( 'receipt.func' );
  11120. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11121. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11122. $data ['html'] = $html ['html'];
  11123. $data ['inSum'] = $html ['sum'];
  11124. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11125. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11126. $data ['payHtml'] = $html ['html'];
  11127. $data ['paySum'] = $html ['sum'];
  11128. // 余额统计
  11129. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11130. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11131. include './protected/config/wasteBook.conf.php';
  11132. Doo::loadModel ( 'wasteBook' );
  11133. $wasteBook = new wasteBook ();
  11134. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11135. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11136. // 获得年份之前所有金额
  11137. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11138. // print_r($detail);
  11139. // $waste['total'];
  11140. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11141. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11142. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11143. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11144. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11145. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11146. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11147. if (date ( 'Y' ) > $year) {
  11148. $limitMonth = 12;
  11149. }
  11150. for($i = 1; $i <= 12; $i ++) {
  11151. $inComeA = $payB = 0;
  11152. $falg = true;
  11153. foreach ( $inComePay as $key => $value ) {
  11154. if ($value ['month'] == $i) {
  11155. $falg = false;
  11156. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11157. $inSum += $value ['accountPrice'];
  11158. $showInSum += $value ['accountPriceShow'];
  11159. $inComeA = $value ['accountPrice'];
  11160. break;
  11161. }
  11162. }
  11163. if ($falg)
  11164. $inComeHtml .= '<td class="taR">-</td>';
  11165. $payFalg = true;
  11166. foreach ( $pay as $key => $value ) {
  11167. if ($value ['month'] == $i) {
  11168. $payFalg = false;
  11169. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11170. $paySum += $value ['accountPrice'];
  11171. $showPaySum += $value ['accountPriceShow'];
  11172. $payB = $value ['accountPrice'];
  11173. break;
  11174. }
  11175. }
  11176. if ($payFalg)
  11177. $payHtml .= '<td class="taR">-</td>';
  11178. if (empty ( $balanceC ) || $limitMonth < $i)
  11179. $lastBalanceHtml .= '<td class="taR">-</td>';
  11180. else
  11181. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11182. $balanceC = $balanceC + $inComeA + $payB;
  11183. $balanceSum += $balanceC;
  11184. if (empty ( $balanceC ) || $limitMonth < $i)
  11185. $BalanceHtml .= '<td class="taR">-</td>';
  11186. else
  11187. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11188. // 余额统计
  11189. }
  11190. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11191. $data ['inComeHtml'] = $inComeHtml;
  11192. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11193. $data ['payBalanceHtml'] = $payHtml;
  11194. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11195. $data ['BalanceHtml'] = $BalanceHtml;
  11196. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11197. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11198. $mothHtml = "";
  11199. for($i = 1; $i <= 12; $i ++) {
  11200. if ($moth == $i)
  11201. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11202. else
  11203. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11204. }
  11205. $data ['mothHtml'] = $mothHtml;
  11206. $dateHtml = "";
  11207. $now = date ( "Y" );
  11208. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11209. if ($YEARD <= $now) {
  11210. $dateHtml .= '<option ';
  11211. if ($year == $YEARD) {
  11212. $dateHtml .= 'selected ';
  11213. }
  11214. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11215. }
  11216. }
  11217. $data ['dateHtml'] = $dateHtml;
  11218. $data ['year'] = $year;
  11219. $data ['memu'] = "receipt";
  11220. $data ['staff'] = $this->staff;
  11221. $data ['receiptMemu'] = 'paymentsCollect';
  11222. $data ['verifyId'] = $this->verifyId;
  11223. $data ['executeId'] = $this->executeId;
  11224. $this->render ( "/expenses/paymentsCollect", $data );
  11225. }
  11226. function paymentsCollectDay() {
  11227. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11228. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11229. if (empty ( $moth ))
  11230. return 'paymentsCollect';
  11231. Doo::loadModel ( "accountBookStatistics" );
  11232. $accountBookStatistics = new accountBookStatistics ();
  11233. $i = 2;
  11234. $y = 2013;
  11235. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11236. Doo::loadClass ( 'receipt.func' );
  11237. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11238. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11239. $data ['html'] = $html ['html'];
  11240. $data ['inSum'] = $html ['sum'];
  11241. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11242. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11243. $data ['payHtml'] = $html ['html'];
  11244. $data ['paySum'] = $html ['sum'];
  11245. $mothHtml = "";
  11246. for($i = 1; $i <= 12; $i ++) {
  11247. if ($moth == $i)
  11248. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11249. else
  11250. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11251. }
  11252. $data ['mothHtml'] = $mothHtml;
  11253. $data ['year'] = $year;
  11254. // 余额
  11255. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11256. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11257. include './protected/config/wasteBook.conf.php';
  11258. Doo::loadModel ( 'wasteBook' );
  11259. $wasteBook = new wasteBook ();
  11260. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11261. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11262. // 获得年份之前所有金额
  11263. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11264. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11265. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11266. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11267. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11268. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11269. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11270. // $balanceC = 0;
  11271. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11272. $limitDay = date ( 'd' );
  11273. $monthLK = ( int ) date ( 'm' );
  11274. if (date ( 'Y' ) > $year) {
  11275. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11276. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11277. $limitDay = 0;
  11278. }
  11279. for($i = 1; $i <= $day; $i ++) {
  11280. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11281. $inComeA = $payB = 0;
  11282. $falg = true;
  11283. foreach ( $inComePay as $key => $value ) {
  11284. if ($value ['day'] == $i) {
  11285. $falg = false;
  11286. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11287. $inSum += $value ['accountPrice'];
  11288. $showInSum += $value ['accountPriceShow'];
  11289. $inComeA = $value ['accountPrice'];
  11290. break;
  11291. }
  11292. }
  11293. if ($falg)
  11294. $inComeHtml .= '<td class="taR">-</td>';
  11295. $payFalg = true;
  11296. foreach ( $pay as $key => $value ) {
  11297. if ($value ['day'] == $i) {
  11298. $payFalg = false;
  11299. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11300. $paySum += $value ['accountPrice'];
  11301. $showPaySum += $value ['accountPriceShow'];
  11302. $payB = $value ['accountPrice'];
  11303. break;
  11304. }
  11305. }
  11306. if ($payFalg)
  11307. $payHtml .= '<td class="taR">-</td>';
  11308. if (empty ( $balanceC ) || $limitDay < $i)
  11309. $lastBalanceHtml .= '<td class="taR">-</td>';
  11310. else
  11311. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11312. $balanceC = $balanceC + $inComeA + $payB;
  11313. $balanceSum += $balanceC;
  11314. if (empty ( $balanceC ) || $limitDay < $i)
  11315. $BalanceHtml .= '<td class="taR">-</td>';
  11316. else
  11317. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11318. }
  11319. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11320. $data ['inComeHtml'] = $inComeHtml;
  11321. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11322. $data ['payBalanceHtml'] = $payHtml;
  11323. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11324. $data ['BalanceHtml'] = $BalanceHtml;
  11325. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11326. $data ['dayHtml'] = $dayHtml;
  11327. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11328. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11329. $dateHtml = "";
  11330. $now = date ( "Y" );
  11331. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11332. if ($YEARD <= $now) {
  11333. $dateHtml .= '<option ';
  11334. if ($year == $YEARD) {
  11335. $dateHtml .= 'selected ';
  11336. }
  11337. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11338. }
  11339. }
  11340. $data ['dateHtml'] = $dateHtml;
  11341. $data ['memu'] = "receipt";
  11342. $data ['staff'] = $this->staff;
  11343. $data ['receiptMemu'] = 'paymentsCollect';
  11344. $data ['verifyId'] = $this->verifyId;
  11345. $data ['executeId'] = $this->executeId;
  11346. $this->render ( "/expenses/paymentsCollectDay", $data );
  11347. }
  11348. // 公司流水
  11349. function wasteBook() {
  11350. Doo::loadModel ( "execute" );
  11351. $execute = new execute ();
  11352. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11353. die ( 'illegal request' );
  11354. }
  11355. include './protected/config/wasteBook.conf.php';
  11356. Doo::loadModel ( 'wasteBook' );
  11357. $wasteBook = new wasteBook ();
  11358. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11359. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11360. $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'];
  11361. // print_r($waste);
  11362. $data ['waste'] = $waste;
  11363. $data ['total'] = $total;
  11364. // 月流水数据结构
  11365. $monthStatistics = array ();
  11366. $incomeMothStatistics = array ();
  11367. $expenditureMothStatistics = array ();
  11368. for($i = 1; $i <= 12; $i ++) {
  11369. $month = date ( 'Y' ) . '-' . $i;
  11370. if ($i < 10)
  11371. $month = date ( 'Y' ) . '-0' . $i;
  11372. array_push ( $monthStatistics, $month );
  11373. }
  11374. foreach ( $monthStatistics as $value ) {
  11375. $falg = true;
  11376. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11377. if ($value == $v ['inputDate']) {
  11378. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11379. $falg = false;
  11380. }
  11381. }
  11382. if ($falg) {
  11383. array_push ( $incomeMothStatistics, '' );
  11384. }
  11385. $falgEx = true;
  11386. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11387. if ($value == $v ['inputDate']) {
  11388. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11389. $falg = false;
  11390. }
  11391. }
  11392. if ($falgEx) {
  11393. array_push ( $expenditureMothStatistics, '' );
  11394. }
  11395. }
  11396. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11397. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11398. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11399. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11400. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11401. // print_r($incomeList);
  11402. $data ['expenditureList'] = $expenditureList;
  11403. $data ['incomeList'] = $incomeList;
  11404. $data ['memu'] = "receipt";
  11405. $data ['staff'] = $this->staff;
  11406. $data ['receiptMemu'] = 'wasteBook';
  11407. $data ['verifyId'] = $this->verifyId;
  11408. $data ['executeId'] = $this->executeId;
  11409. $this->render ( "/expenses/wasteBook", $data );
  11410. }
  11411. function wasteBookIncome() {
  11412. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11413. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11414. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11415. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11416. $data ['dailyIncomeType'] = $dailyIncomeType;
  11417. Doo::loadModel ( 'wasteBook' );
  11418. $wasteBook = new wasteBook ();
  11419. Doo::loadModel ( 'L_category' );
  11420. $L_category = new L_category ();
  11421. Doo::loadClass ( 'XDeode' );
  11422. $XDeode = new XDeode ( 5 );
  11423. // echo $XDeode->encode(1).'<br>';
  11424. // echo $XDeode->encode(2).'<br>';
  11425. // echo $XDeode->encode(3).'<br>';
  11426. // echo $XDeode->encode(4).'<br>';
  11427. // echo $XDeode->encode(5).'<br>';
  11428. // echo $XDeode->encode(6).'<br>';
  11429. // echo $XDeode->encode(7).'<br>';
  11430. // echo $XDeode->encode(8).'<br>';
  11431. // echo $XDeode->encode(9).'<br>';
  11432. // echo $XDeode->encode(10).'<br>';
  11433. $dateArr = explode ( ':', $date );
  11434. $D1 = '';
  11435. $D2 = '';
  11436. $con = '';
  11437. if (! empty ( $date )) {
  11438. $D1 = $dateArr [0];
  11439. $D2 = $dateArr [1];
  11440. }
  11441. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11442. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11443. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11444. $con = ' and inputDate = "' . $D1 . '"';
  11445. if ($cid != 'ALL') {
  11446. $cid = $XDeode->decode ( $cid );
  11447. $con .= ' and cid = "' . $cid . '"';
  11448. }
  11449. if ($accountType != 'ALL') {
  11450. if ($accountType == 'INVOICE') {
  11451. $con .= ' and (accountType = 7 or accountType = 8)';
  11452. } elseif ($accountType == 'PAYMENTS') {
  11453. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11454. if ($dailyIncomeType != 'ALL') {
  11455. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11456. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11457. }
  11458. }
  11459. }
  11460. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11461. $sum = 0;
  11462. foreach ( $incomeList as $key => $value ) {
  11463. $sum += $value ['accountPrice'];
  11464. }
  11465. // print_r($incomeList);
  11466. // 获得办事和部门
  11467. $categoryList = $L_category->getCategory ();
  11468. $data ['accountType'] = $accountType;
  11469. $data ['cid'] = $cid;
  11470. $data ['categoryList'] = $categoryList;
  11471. $data ['sum'] = $sum;
  11472. $data ['incomeList'] = $incomeList;
  11473. $data ['inputDate'] = $date;
  11474. $data ['memu'] = "receipt";
  11475. $data ['staff'] = $this->staff;
  11476. $data ['receiptMemu'] = 'wasteBook';
  11477. $data ['verifyId'] = $this->verifyId;
  11478. $data ['executeId'] = $this->executeId;
  11479. $this->render ( "/expenses/wasteBookIncome", $data );
  11480. }
  11481. /**
  11482. * 所有支出
  11483. */
  11484. function wasteBookExpenditure() {
  11485. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11486. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11487. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11488. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11489. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11490. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11491. $data ['receiptType'] = $receiptType;
  11492. Doo::loadModel ( 'wasteBook' );
  11493. $wasteBook = new wasteBook ();
  11494. Doo::loadModel ( 'L_category' );
  11495. $L_category = new L_category ();
  11496. Doo::loadClass ( 'XDeode' );
  11497. $XDeode = new XDeode ( 5 );
  11498. $dateArr = explode ( ':', $date );
  11499. $D1 = '';
  11500. $D2 = '';
  11501. $con = '';
  11502. if (! empty ( $date )) {
  11503. $D1 = $dateArr [0];
  11504. $D2 = $dateArr [1];
  11505. }
  11506. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11507. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11508. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11509. $con = ' and inputDate = "' . $D1 . '"';
  11510. if ($cid != 'ALL') {
  11511. $cid = $XDeode->decode ( $cid );
  11512. $con .= ' and cid = "' . $cid . '"';
  11513. }
  11514. if ($accountType != 'ALL') {
  11515. if ($accountType == 'INVOICE') {
  11516. $con .= ' and accountType = 11';
  11517. } elseif ($accountType == 'PAYMENTS') {
  11518. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11519. if ($dailyExpenditureType != 'ALL') {
  11520. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11521. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11522. }
  11523. } elseif ($accountType == 'RECEIPT') {
  11524. if ($receiptType == 'ALL') {
  11525. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11526. } else {
  11527. $receiptType = $XDeode->decode ( $receiptType );
  11528. echo $receiptType;
  11529. if ($receiptType == 1) {
  11530. $con .= ' and (accountType = 1 or accountType=2)';
  11531. } else {
  11532. $con .= ' and accountType = ' . $receiptType;
  11533. }
  11534. }
  11535. }
  11536. }
  11537. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11538. $sum = 0;
  11539. foreach ( $incomeList as $key => $value ) {
  11540. $sum += $value ['accountPriceShow'];
  11541. }
  11542. // print_r($incomeList);
  11543. // 获得办事和部门
  11544. $categoryList = $L_category->getCategory ();
  11545. $data ['accountType'] = $accountType;
  11546. $data ['cid'] = $cid;
  11547. $data ['categoryList'] = $categoryList;
  11548. $data ['sum'] = $sum;
  11549. $data ['incomeList'] = $incomeList;
  11550. $data ['inputDate'] = $date;
  11551. $data ['memu'] = "receipt";
  11552. $data ['staff'] = $this->staff;
  11553. $data ['receiptMemu'] = 'wasteBook';
  11554. $data ['verifyId'] = $this->verifyId;
  11555. $data ['executeId'] = $this->executeId;
  11556. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11557. }
  11558. function ajaxGetWasteinvoiceReceivables() {
  11559. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11560. Doo::loadClass ( 'XDeode' );
  11561. $XDeode = new XDeode ( 5 );
  11562. $irid = $XDeode->decode ( $serial );
  11563. Doo::loadModel ( 'invoiceReceivables' );
  11564. $invoiceReceivables = new invoiceReceivables ();
  11565. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11566. echo json_encode ( array (
  11567. 'status' => 1,
  11568. 'detail' => $detail
  11569. ) );
  11570. }
  11571. function ajaxGetPaymentsByAid() {
  11572. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11573. Doo::loadModel ( "accountBook" );
  11574. $accountBook = new accountBook ();
  11575. $detail = $accountBook->getAccountBookByAid ( $serial );
  11576. echo json_encode ( array (
  11577. 'status' => 1,
  11578. 'detail' => $detail
  11579. ) );
  11580. }
  11581. function ajaxGetWasteInvoice() {
  11582. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11583. Doo::loadModel ( 'invoice' );
  11584. $invoice = new invoice ();
  11585. Doo::loadModel ( 'invoiceReceivables' );
  11586. $invoiceReceivables = new invoiceReceivables ();
  11587. $detail = $invoice->getInvoiceByIid ( $serial );
  11588. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11589. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11590. echo json_encode ( array (
  11591. 'status' => 1,
  11592. 'detail' => $detail
  11593. ) );
  11594. }
  11595. /**
  11596. */
  11597. function ajaxGetWasteReceipt() {
  11598. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11599. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11600. Doo::loadModel ( 'receipt' );
  11601. $receipt = new receipt ();
  11602. Doo::loadClass ( 'XDeode' );
  11603. $XDeode = new XDeode ( 5 );
  11604. $rid = $XDeode->decode ( $serial );
  11605. $accountType= $XDeode->decode ( $accountTypeKey );
  11606. // 获得个数据
  11607. $detail = $receipt->getReceiptByRid ( $rid );
  11608. // 初始化
  11609. $detail ['reviseDetail'] = array ();
  11610. if (! empty ( $value ['reviseDetail'] ))
  11611. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11612. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11613. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11614. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11615. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11616. // 获得费用html
  11617. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11618. // 获得费用审批人数据
  11619. $detail = $this->getReceiptApproverHtml ( $detail );
  11620. // 审批执行
  11621. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11622. <th class="taC" width="90">审批人</th>
  11623. <th class="taC">审批意见</th></tr>';
  11624. foreach ( $detail ['verifyList'] as $key => $value ) {
  11625. $html .= '<tr>
  11626. <td>' . $value [1] . '</td>
  11627. <td>' . $value ['opinion'] . '</td>
  11628. </tr>
  11629. ';
  11630. }
  11631. $html .= ' </tbody></table>';
  11632. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11633. <th class="taC" width="90">执行人</th>
  11634. <th class="taC">执行意见</th></tr>';
  11635. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11636. $html .= '<tr>
  11637. <td>' . $value [1] . '</td>
  11638. <td>' . $value ['opinion'] . '</td>
  11639. </tr>
  11640. ';
  11641. }
  11642. $html .= ' </tbody></table>';
  11643. if($accountType==1){
  11644. Doo::loadModel ( 'loanReceipt' );
  11645. $loanReceipt = new loanReceipt ();
  11646. $loanList = $loanReceipt->getOne ( array (
  11647. 'where' => 'rid=' . $detail ['loanRid'],
  11648. 'desc' => 'rid',
  11649. 'asArray' => true
  11650. ) );
  11651. $html .= '<table class="table table-bordered table-condensed">
  11652. <tr class="warning">
  11653. <td class="taR"><b>汇款金额</b></td>
  11654. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11655. </tr>
  11656. </table>';
  11657. }else{
  11658. $html .= '<table class="table table-bordered table-condensed">
  11659. <tr class="warning">
  11660. <td class="taR"><b>汇款金额</b></td>
  11661. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11662. </tr>
  11663. </table>';
  11664. }
  11665. // print_r($detail['verifyList']);
  11666. // header ( 'Content-Type:text/html;charset=utf-8' );
  11667. // echo $html;
  11668. echo json_encode ( array (
  11669. 'status' => 1,
  11670. 'html' => $html,
  11671. 'detail' => $detail
  11672. ) );
  11673. }
  11674. function getReceiptApproverHtml($detail = array()) {
  11675. Doo::loadModel ( 'loanReceipt' );
  11676. $loanReceipt = new loanReceipt ();
  11677. Doo::loadModel ( 'verify' );
  11678. $verify = new verify ();
  11679. Doo::loadModel ( 'staff' );
  11680. $staff = new staff ();
  11681. if (empty ( $detail ))
  11682. return array ();
  11683. $loanList = $loanReceipt->getOne ( array (
  11684. 'where' => 'rid=' . $detail ['loanRid'],
  11685. 'desc' => 'rid',
  11686. 'asArray' => true
  11687. ) );
  11688. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11689. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11690. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11691. else
  11692. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11693. } else
  11694. $verifyList = $verify->getOne ( array (
  11695. 'where' => 'vid=' . $detail ['verify'],
  11696. 'asArray' => true
  11697. ) );
  11698. $verifyList = json_decode ( $verifyList ['staff'], true );
  11699. Doo::loadModel ( 'role' );
  11700. $role = new role ();
  11701. $roleId = 0;
  11702. $flag = true;
  11703. $roleKey = 0;
  11704. $endStaffArray = array ();
  11705. $roleArrayCopy = array ();
  11706. foreach ( $verifyList as $k => $v ) {
  11707. // init verifyStaff
  11708. if ($v [1] == 'ROLE') {
  11709. if (! empty ( $verifyStaff )) {
  11710. $endStaffArray = end ( $verifyStaff );
  11711. }
  11712. $roleVerify = json_decode ( $v [3], true );
  11713. $roleKey = $k;
  11714. $roleArray = array ();
  11715. $rolename = $role->getOne ( array (
  11716. 'where' => 'rid=' . $v [0],
  11717. 'asArray' => true
  11718. ) );
  11719. foreach ( $roleVerify as $o => $p ) {
  11720. $staffID = explode ( '_', $p );
  11721. $staffInfo = $staff->getOne ( array (
  11722. 'where' => 'sid=' . $staffID [0],
  11723. 'asArray' => true
  11724. ) );
  11725. // print_r($staffID);
  11726. $exp = array (
  11727. 0 => $staffInfo ['sid'],
  11728. 1 => $staffID [1],
  11729. 2 => $staffInfo ['avatar'],
  11730. 'date' => '',
  11731. 'date' => '',
  11732. 'opinion' => '',
  11733. 'status' => '',
  11734. 'rolename' => $rolename ['name']
  11735. );
  11736. array_push ( $roleArray, $exp );
  11737. }
  11738. $roleArrayCopy [$v [0]] = $roleArray;
  11739. // $verifyList[$k]['roleArray']=$roleArray;
  11740. }
  11741. $verifyList [$k] ['date'] = "";
  11742. $verifyList [$k] ['opinion'] = "";
  11743. $verifyList [$k] ['status'] = "";
  11744. if (empty ( $verifyStaff )) {
  11745. $verifyList [$k] ['date'] = "";
  11746. $verifyList [$k] ['opinion'] = "";
  11747. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11748. $verifyList [$k] ['status'] = 4;
  11749. $flag = false;
  11750. }
  11751. } else {
  11752. foreach ( $verifyStaff as $m => $u ) {
  11753. if ($v [0] == $m) {
  11754. $verifyList [$k] ['date'] = $u ['date'];
  11755. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11756. $verifyList [$k] ['status'] = $u ['status'];
  11757. $flag = false;
  11758. break;
  11759. }
  11760. }
  11761. $endStaffArray = end ( $verifyStaff );
  11762. }
  11763. }
  11764. $rolename ['name'] = '';
  11765. if (! empty ( $roleId )) {
  11766. Doo::loadModel ( 'role' );
  11767. $role = new role ();
  11768. $rolename = $role->getOne ( array (
  11769. 'where' => 'rid=' . $roleId,
  11770. 'asArray' => true
  11771. ) );
  11772. }
  11773. if (! empty ( $verifyStaff ))
  11774. $endStaffArray = end ( $verifyStaff );
  11775. $KOP = false;
  11776. foreach ( $roleArrayCopy as $P => $A ) {
  11777. foreach ( $A as $MKI => $AVL ) {
  11778. if (! empty ( $verifyStaff )) {
  11779. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11780. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11781. $button = 4;
  11782. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11783. }
  11784. foreach ( $verifyStaff as $m => $u ) {
  11785. $AVLFK = $AVL [0] . '_R';
  11786. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11787. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11788. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11789. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11790. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11791. break;
  11792. }
  11793. }
  11794. } else {
  11795. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11796. $button = 4;
  11797. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11798. }
  11799. }
  11800. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11801. $KOP = true;
  11802. }
  11803. }
  11804. foreach ( $roleArrayCopy as $k => $v ) {
  11805. foreach ( $verifyList as $m => $n ) {
  11806. if ($n [0] == $k) {
  11807. array_splice ( $verifyList, $m, 1, $v );
  11808. }
  11809. }
  11810. }
  11811. // 费用执行人相关数据
  11812. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11813. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11814. foreach ( $executeCopy as $k => $v ) {
  11815. $executeCopy [$k] ['date'] = '';
  11816. $executeCopy [$k] ['opinion'] = '';
  11817. $executeCopy [$k] ['status'] = '';
  11818. if (! empty ( $executeStaff ))
  11819. foreach ( $executeStaff as $m => $u ) {
  11820. if ($v [0] == $m) {
  11821. $executeCopy [$k] ['date'] = $u ['date'];
  11822. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11823. $executeCopy [$k] ['status'] = $u ['status'];
  11824. break;
  11825. }
  11826. }
  11827. }
  11828. $detail ['executeCopy'] = $executeCopy;
  11829. $detail ['verifyList'] = $verifyList;
  11830. return $detail;
  11831. }
  11832. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11833. if (empty ( $detail ))
  11834. return '';
  11835. $html = '';
  11836. if ($detail ['Rtype'] == 0) { // 报销单
  11837. $html .= '<table class="table table-bordered table-condensed">
  11838. <tbody>
  11839. <tr>
  11840. <th colspan="2" class="taC">日常相关费用</th>
  11841. </tr>';
  11842. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11843. $html .= '
  11844. <tr>
  11845. <th>' . $value ['name'] . '</th>
  11846. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11847. </tr>';
  11848. }
  11849. $html .= '
  11850. <tr>
  11851. <th class="taR">合计</th>
  11852. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11853. </tr>';
  11854. $html .= '<tr>
  11855. <th colspan="2" class="taC">差旅相关费用</th>
  11856. </tr>';
  11857. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11858. $html .= '
  11859. <tr>
  11860. <th>' . $value ['name'] . '</th>
  11861. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11862. </tr>';
  11863. }
  11864. $html .= '
  11865. <tr>
  11866. <th class="taR">合计</th>
  11867. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11868. </tr>';
  11869. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11870. $html .= '<tr>
  11871. <th colspan="2" class="taC">内部培训费用</th>
  11872. </tr>';
  11873. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11874. $html .= '
  11875. <tr>
  11876. <th>' . $value ['name'] . '</th>
  11877. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11878. </tr>';
  11879. }
  11880. $html .= '
  11881. <tr>
  11882. <th class="taR">合计</th>
  11883. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11884. </tr>';
  11885. }
  11886. $html .= '<tr>
  11887. <th colspan="2" class="taC">其他</th>
  11888. </tr>';
  11889. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11890. $html .= '
  11891. <tr>
  11892. <th>' . $value ['name'] . '</th>
  11893. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11894. </tr>';
  11895. }
  11896. $html .= '
  11897. <tr>
  11898. <th class="taR">合计</th>
  11899. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11900. </tr>';
  11901. $html .= '<tr>
  11902. <th colspan="2" class="taC">报销金额调整</th>
  11903. </tr>';
  11904. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11905. $html .= '
  11906. <tr>
  11907. <th>' . $value ['name'] . '</th>
  11908. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11909. </tr>';
  11910. }
  11911. $html .= '
  11912. <tr>
  11913. <th class="taR">合计</th>
  11914. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11915. </tr>';
  11916. $html .= '
  11917. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11918. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11919. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11920. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11921. <tr class="warning">
  11922. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11923. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11924. </tr>
  11925. </tbody>
  11926. </table>';
  11927. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  11928. $html .= '
  11929. <table class="table table-bordered table-condensed">
  11930. <tbody>
  11931. <tr>
  11932. <th colspan="2" class="taC">办事处相关费用</th>
  11933. </tr>';
  11934. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11935. $html .= '
  11936. <tr>
  11937. <th>' . $value ['name'] . '</th>
  11938. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11939. </tr>';
  11940. }
  11941. $html .= '
  11942. <tr>
  11943. <th class="taR">合计</th>
  11944. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11945. </tr>';
  11946. $html .= '
  11947. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11948. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11949. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11950. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11951. <tr class="warning">
  11952. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11953. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11954. </tr>
  11955. </tbody>
  11956. </table>';
  11957. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  11958. Doo::loadModel ( 'loanReceipt' );
  11959. $loanReceipt = new loanReceipt ();
  11960. $loanList = $loanReceipt->getOne ( array (
  11961. 'where' => 'rid=' . $detail ['loanRid'],
  11962. 'desc' => 'rid',
  11963. 'asArray' => true
  11964. ) );
  11965. // print_r($loanList);
  11966. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  11967. $html .= '<table class="table table-bordered table-condensed">
  11968. <tbody>
  11969. <tr>
  11970. <th colspan="2" class="taC">借款费用</th>
  11971. </tr>';
  11972. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  11973. $html .= '<tr>
  11974. <th>' . $value ['name'] . '</th>
  11975. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11976. </tr>';
  11977. }
  11978. $html .= '<tr>
  11979. <th class="taC" colspan="2">产生费用所在办事处</th>
  11980. </tr>
  11981. <tr>
  11982. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  11983. </tr>
  11984. <tr>
  11985. <th class="taC" colspan="2">费用说明</th>
  11986. </tr>
  11987. <tr>
  11988. <td colspan="2">' . $loanList ['explanation'] . '</td>
  11989. </tr>
  11990. <tr class="warning">
  11991. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  11992. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  11993. </tr>
  11994. </tbody>
  11995. </table>
  11996. ';
  11997. if ( $accountType==2) {
  11998. $balance=$detail ['sum']-$loanList ['sum'];
  11999. $balanceCN=$this->num_to_rmb($balance);
  12000. $html .= '<table class="table table-bordered table-condensed">
  12001. <tbody>
  12002. <tr>
  12003. <th colspan="2" class="taC">日常相关费用</th>
  12004. </tr>';
  12005. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12006. $html .= '
  12007. <tr>
  12008. <th>' . $value ['name'] . '</th>
  12009. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12010. </tr>';
  12011. }
  12012. $html .= '
  12013. <tr>
  12014. <th class="taR">合计</th>
  12015. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12016. </tr>';
  12017. $html .= '<tr>
  12018. <th colspan="2" class="taC">差旅相关费用</th>
  12019. </tr>';
  12020. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12021. $html .= '
  12022. <tr>
  12023. <th>' . $value ['name'] . '</th>
  12024. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12025. </tr>';
  12026. }
  12027. $html .= '
  12028. <tr>
  12029. <th class="taR">合计</th>
  12030. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12031. </tr>';
  12032. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12033. $html .= '<tr>
  12034. <th colspan="2" class="taC">内部培训费用</th>
  12035. </tr>';
  12036. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12037. $html .= '
  12038. <tr>
  12039. <th>' . $value ['name'] . '</th>
  12040. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12041. </tr>';
  12042. }
  12043. $html .= '
  12044. <tr>
  12045. <th class="taR">合计</th>
  12046. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12047. </tr>';
  12048. }
  12049. $html .= '<tr>
  12050. <th colspan="2" class="taC">其他</th>
  12051. </tr>';
  12052. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12053. $html .= '
  12054. <tr>
  12055. <th>' . $value ['name'] . '</th>
  12056. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12057. </tr>';
  12058. }
  12059. $html .= '
  12060. <tr>
  12061. <th class="taR">合计</th>
  12062. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12063. </tr>';
  12064. $html .= '<tr>
  12065. <th colspan="2" class="taC">报销金额调整</th>
  12066. </tr>';
  12067. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12068. $html .= '
  12069. <tr>
  12070. <th>' . $value ['name'] . '</th>
  12071. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12072. </tr>';
  12073. }
  12074. $html .= '
  12075. <tr>
  12076. <th class="taR">合计</th>
  12077. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12078. </tr>';
  12079. $html .= '
  12080. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12081. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12082. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12083. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12084. <tr class="warning">
  12085. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12086. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12087. </tr>
  12088. <tr class="success">
  12089. <td class="taR"><b>借款结余</b></td>
  12090. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12091. </tr>
  12092. </tbody>
  12093. </table>';
  12094. }
  12095. }
  12096. return $html;
  12097. }
  12098. /**
  12099. * 计算流水
  12100. */
  12101. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12102. $bakWaste ['bank'] = array (
  12103. 'CGBDeposit' => 0,
  12104. 'ICBCDeposit' => 0,
  12105. 'HUADeposit' => 0,
  12106. 'PersonalDeposit' => 0
  12107. );
  12108. $bakWaste ['financial'] = array (
  12109. 'current' => array (
  12110. 'CGBDeposit' => 0,
  12111. 'ICBCDeposit' => 0
  12112. ),
  12113. 'fixed' => array (
  12114. 'CGBDeposit' => 0,
  12115. 'ICBCDeposit' => 0
  12116. )
  12117. );
  12118. // 存款
  12119. foreach ( $waste ['bank'] as $key => $value ) {
  12120. // 收入
  12121. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12122. // 广发
  12123. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12124. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12125. }
  12126. // 工商
  12127. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12128. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12129. }
  12130. // 华润
  12131. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12132. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12133. }
  12134. // 个人
  12135. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12136. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12137. }
  12138. }
  12139. }
  12140. foreach ( $waste ['bank'] as $key => $value ) {
  12141. // 支出
  12142. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12143. // 广发
  12144. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12145. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12146. }
  12147. // 工商
  12148. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12149. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12150. }
  12151. // 华润
  12152. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12153. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12154. }
  12155. // 个人
  12156. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12157. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12158. }
  12159. }
  12160. }
  12161. // 活期
  12162. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12163. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12164. // 广发
  12165. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12166. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12167. }
  12168. // 工商
  12169. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12170. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12171. }
  12172. // 个人
  12173. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12174. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12175. }
  12176. }
  12177. }
  12178. // print_r($inComeStatistics ['fixedStatistics']);
  12179. // 固期
  12180. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12181. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12182. // 广发
  12183. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12184. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12185. }
  12186. // 工商
  12187. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12188. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12189. }
  12190. // 个人
  12191. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12192. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12193. }
  12194. }
  12195. }
  12196. return $waste;
  12197. }
  12198. function lyt() {
  12199. Doo::loadModel ( "receiptDetail" );
  12200. $receiptDetail = new receiptDetail ();
  12201. $receiptCollectList = $receiptDetail->find ( array (
  12202. 'where' => 'status=1 ',
  12203. 'asArray' => true
  12204. ) );
  12205. foreach ( $receiptCollectList as $key => $value ) {
  12206. $receiptDetail = new receiptDetail ();
  12207. $receiptDetail->pastDate = $value ['date'];
  12208. $receiptDetail->update ( array (
  12209. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12210. ) );
  12211. }
  12212. }
  12213. function staffCollectMonthDetail() {
  12214. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12215. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12216. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12217. if (! $year)
  12218. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12219. if (! $month)
  12220. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12221. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12222. if (! $nature){
  12223. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12224. }
  12225. Doo::loadModel ( 'staff' );
  12226. $staff = new staff ();
  12227. Doo::loadModel ( "receiptDetail" );
  12228. $receiptDetail = new receiptDetail ();
  12229. Doo::loadModel ( 'accountItem' );
  12230. $accountItem = new accountItem ();
  12231. Doo::loadModel ( 'statistics' );
  12232. $statistics = new statistics ();
  12233. Doo::loadModel ( "receiptAuthorityManage" );
  12234. $receiptAuthorityManage = new receiptAuthorityManage ();
  12235. $aiList=$accountItem->getAccountItem();
  12236. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12237. $cidList = array ();
  12238. foreach ( $imcStaff as $key => $value ) {
  12239. array_push ( $cidList, $value ['cid'] );
  12240. }
  12241. $cidString = implode ( ',', $cidList );
  12242. $naturecon='';
  12243. if ($nature=='ONJOB'){
  12244. $naturecon=' and (nature!=4 )';
  12245. }elseif($nature=='LEAVEJOB'){
  12246. $naturecon=' and (nature=4 )';
  12247. }else{
  12248. die ( 'illegal request--nature' );
  12249. }
  12250. $staffList = $staff->find ( array (
  12251. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12252. 'asArray' => true
  12253. ) );
  12254. $categoryList = $staff->find ( array (
  12255. 'select' => 'COUNT(*) as count,cid,category',
  12256. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12257. 'groupby' => 'cid',
  12258. 'asArray' => true
  12259. ) );
  12260. $list = array ();
  12261. foreach($aiList as $key=>$value){
  12262. foreach ($value as $v){
  12263. $subtotal[$key][$v['name']]=0;
  12264. }
  12265. }
  12266. foreach ( $categoryList as $vlu ) {
  12267. $s1 = 0;
  12268. $m1 = 0;
  12269. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12270. foreach ( $staffList as $value ) {
  12271. if ($vlu ['cid'] == $value ['cid']) {
  12272. // pastDate
  12273. $receiptCollectList = $receiptDetail->find ( array (
  12274. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12275. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12276. 'groupby' => 'item,Month(pastDate),itemCategory',
  12277. 'asArray' => true
  12278. ) );
  12279. if (! empty ( $receiptCollectList )) {
  12280. $receiptL = array (
  12281. '日常相关费用' => array (),
  12282. '差旅相关费用' => array (),
  12283. '内部培训费用' => array (),
  12284. '培训班费用' => array (),
  12285. '其他' => array ()
  12286. );
  12287. $html = "";
  12288. $psum = 0;
  12289. foreach ( $aiList[$this->AGENCY] as $va ) {
  12290. $falg = true;
  12291. foreach ( $receiptCollectList as $v ) {
  12292. if ($v ['itemCategory'] == '日常相关费用') {
  12293. if ($v ['item'] == $va['name']) {
  12294. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12295. $psum += $v ['price'];
  12296. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12297. $falg = false;
  12298. break;
  12299. }
  12300. }
  12301. }
  12302. if ($falg)
  12303. $html .= '<td class="taR">-</td>';
  12304. }
  12305. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12306. if (! empty ( $psum ))
  12307. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12308. else
  12309. $psum = '<td class="colGreen taR">-</td>';
  12310. $receiptL ['日常相关费用'] = $psum . $html;
  12311. /* ----------------------------------- */
  12312. $html = "";
  12313. $psum = 0;
  12314. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12315. $falg = true;
  12316. foreach ( $receiptCollectList as $v ) {
  12317. if ($v ['itemCategory'] == '差旅相关费用') {
  12318. if ($v ['item'] == $va['name']) {
  12319. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12320. $psum += $v ['price'];
  12321. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12322. $falg = false;
  12323. break;
  12324. }
  12325. }
  12326. }
  12327. if ($falg)
  12328. $html .= '<td class="taR">-</td>';
  12329. }
  12330. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12331. if (! empty ( $psum ))
  12332. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12333. else
  12334. $psum = '<td class="colGreen taR">-</td>';
  12335. $receiptL ['差旅相关费用'] = $psum . $html;
  12336. /* ------------------------------------- */
  12337. $html = "";
  12338. $psum = 0;
  12339. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12340. $falg = true;
  12341. foreach ( $receiptCollectList as $v ) {
  12342. if ($v ['itemCategory'] == '内部培训费用') {
  12343. if ($v ['item'] == $va['name']) {
  12344. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12345. $psum += $v ['price'];
  12346. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12347. $falg = false;
  12348. break;
  12349. }
  12350. }
  12351. }
  12352. if ($falg)
  12353. $html .= '<td class="taR">-</td>';
  12354. }
  12355. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12356. if (! empty ( $psum ))
  12357. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12358. else
  12359. $psum = '<td class="colGreen taR">-</td>';
  12360. $receiptL ['内部培训费用'] = $psum . $html;
  12361. /* ----------------------------------- */
  12362. $html = "";
  12363. $psum = 0;
  12364. foreach ( $aiList[$this->TRAIN] as $va ) {
  12365. $falg = true;
  12366. foreach ( $receiptCollectList as $v ) {
  12367. if ($v ['itemCategory'] == '培训班费用') {
  12368. if ($v ['item'] == $va['name']) {
  12369. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12370. $psum += $v ['price'];
  12371. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12372. $falg = false;
  12373. break;
  12374. }
  12375. }
  12376. }
  12377. if ($falg)
  12378. $html .= '<td class="taR">-</td>';
  12379. }
  12380. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12381. if (! empty ( $psum ))
  12382. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12383. else
  12384. $psum = '<td class="colGreen taR">-</td>';
  12385. $receiptL ['培训班费用'] = $psum . $html;
  12386. /* ------------------------------------- */
  12387. $html = "";
  12388. $psum = 0;
  12389. foreach ( $aiList[$this->OTHER] as $va ) {
  12390. $falg = true;
  12391. foreach ( $receiptCollectList as $v ) {
  12392. if ($v ['itemCategory'] == '其他') {
  12393. if (trim ( $v ['item'] ) == $va['name']) {
  12394. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12395. $psum += $v ['price'];
  12396. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12397. $falg = false;
  12398. break;
  12399. }
  12400. }
  12401. }
  12402. if ($falg)
  12403. $html .= '<td class="taR">-</td>';
  12404. }
  12405. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12406. if (! empty ( $psum ))
  12407. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12408. else
  12409. $psum = '<td class="colGreen taR">-</td>';
  12410. $receiptL ['其他'] = $psum . $html;
  12411. /* ------------------------------------- */
  12412. $html = "";
  12413. $psum = 0;
  12414. foreach ( $receiptCollectList as $v ) {
  12415. if ($v ['itemCategory'] == '报销金额调整') {
  12416. if (! empty ( $v ['price'] )) {
  12417. $psum += $v ['price'];
  12418. }
  12419. }
  12420. }
  12421. $s1 += $psum;
  12422. if (! empty ( $psum ))
  12423. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12424. else
  12425. $psum = '<td class="taR colOrange">-</td>';
  12426. $receiptL ['报销金额调整'] = $psum . $html;
  12427. } else {
  12428. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12429. foreach ( $aiList[$this->AGENCY] as $va ) {
  12430. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12431. }
  12432. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12433. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12434. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12435. }
  12436. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12437. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12438. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12439. }
  12440. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12441. foreach ( $aiList[$this->TRAIN] as $va ) {
  12442. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12443. }
  12444. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12445. foreach ( $aiList[$this->OTHER] as $va ) {
  12446. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12447. }
  12448. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12449. }
  12450. $monthStaffPrice = $receiptDetail->find ( array (
  12451. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12452. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12453. 'groupby' => 'Month(pastDate)',
  12454. 'asArray' => true
  12455. ) );
  12456. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12457. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12458. $m1 += $monthStaffPrice [0] ['price'];
  12459. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12460. } else
  12461. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12462. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12463. $list [$value ['username']] = $receiptL;
  12464. }
  12465. }
  12466. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12467. foreach ( $aiList[$this->AGENCY] as $va ) {
  12468. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12469. $subtotal[$this->AGENCY][$va['name']]=0;
  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. $subtotal[$this->TRAVEL][$va['name']]=0;
  12475. }
  12476. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12477. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12478. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12479. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12480. }
  12481. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12482. foreach ( $aiList[$this->TRAIN] as $va ) {
  12483. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12484. $subtotal[$this->TRAIN][$va['name']]=0;
  12485. }
  12486. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12487. foreach ( $aiList[$this->OTHER] as $va ) {
  12488. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12489. $subtotal[$this->OTHER][$va['name']]=0;
  12490. }
  12491. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12492. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12493. $receiptL ['usernameEn'] =false;
  12494. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12495. }
  12496. $data ['list'] = $list;
  12497. // print_r($list);
  12498. $receiptCollectList = $receiptDetail->find ( array (
  12499. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12500. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12501. 'groupby' => 'item,Month(pastDate),itemCategory',
  12502. 'asArray' => true
  12503. ) );
  12504. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12505. // statistics html
  12506. $stList = $statistics->getOne ( array (
  12507. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12508. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12509. 'groupby' => 'Month(date)',
  12510. 'asArray' => true
  12511. ) );
  12512. if (empty ( $stList ))
  12513. $stList = array (
  12514. 'rePrice' => 0,
  12515. 'agPrice' => 0
  12516. );
  12517. $data ['stList'] = array (
  12518. 'rePrice' => $stList ['rePrice'],
  12519. 'agPrice' => $stList ['agPrice'],
  12520. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12521. );
  12522. $monthHtml = "";
  12523. for($i = 1; $i <= 12; $i ++) {
  12524. if ($i == $month)
  12525. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12526. else
  12527. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12528. }
  12529. $data ['monthHtml'] = $monthHtml;
  12530. $data ['year'] = $year;
  12531. $data ['month'] = $month;
  12532. $data ['nature'] = $nature;
  12533. $data ['aiList'] = $aiList;
  12534. $data ['memu'] = "receipt";
  12535. $data ['staff'] = $this->staff;
  12536. $data ['receiptMemu'] = 'companyCategoryCollect';
  12537. $data ['verifyId'] = $this->verifyId;
  12538. $data ['executeId'] = $this->executeId;
  12539. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12540. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12541. }
  12542. function staffCollectMonthDetail2() {
  12543. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12544. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12545. if (! $year)
  12546. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12547. if (! $month)
  12548. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12549. Doo::loadModel ( 'staff' );
  12550. $staff = new staff ();
  12551. Doo::loadModel ( "receiptDetail" );
  12552. $receiptDetail = new receiptDetail ();
  12553. Doo::loadModel ( 'accountItem' );
  12554. $accountItem = new accountItem ();
  12555. Doo::loadModel ( 'statistics' );
  12556. $statistics = new statistics ();
  12557. Doo::loadModel ( 'L_category' );
  12558. $lCategory = new L_category ();
  12559. $staffList = $staff->find ( array (
  12560. 'where' => 'username!="admin"',
  12561. 'asArray' => true
  12562. ) );
  12563. $categoryList = $staff->find ( array (
  12564. 'select' => 'COUNT(*) as count,cid,category',
  12565. 'where' => 'username !="admin"',
  12566. 'groupby' => 'cid',
  12567. 'asArray' => true
  12568. ) );
  12569. $list = array ();
  12570. foreach ( $categoryList as $vlu ) {
  12571. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12572. $r1 = 0;
  12573. $r2 = 0;
  12574. $r3 = 0;
  12575. $r4 = 0;
  12576. $r5 = 0;
  12577. $r6 = 0;
  12578. $r7 = 0;
  12579. $r8 = 0;
  12580. $r9 = 0;
  12581. $r10 = 0;
  12582. $r11 = 0;
  12583. $r12 = 0;
  12584. $r13 = 0;
  12585. $r14 = 0;
  12586. $r15 = 0;
  12587. $c1 = 0;
  12588. $c2 = 0;
  12589. $c3 = 0;
  12590. $c4 = 0;
  12591. $c5 = 0;
  12592. $c6 = 0;
  12593. $p1 = 0;
  12594. $p2 = 0;
  12595. $p3 = 0;
  12596. $p4 = 0;
  12597. $p5 = 0;
  12598. $p6 = 0;
  12599. $p7 = 0;
  12600. $p8 = 0;
  12601. $p9 = 0;
  12602. $t1 = 0;
  12603. $t2 = 0;
  12604. $t3 = 0;
  12605. $t4 = 0;
  12606. $t5 = 0;
  12607. $s1 = 0;
  12608. $m1 = 0;
  12609. foreach ( $staffList as $value ) {
  12610. if ($vlu ['cid'] == $value ['cid']) {
  12611. $receiptCollectList = $receiptDetail->find ( array (
  12612. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12613. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12614. 'groupby' => 'item,Month(date),itemCategory',
  12615. 'asArray' => true
  12616. ) );
  12617. if (! empty ( $receiptCollectList )) {
  12618. $receiptL = array (
  12619. '日常相关费用' => array (),
  12620. '差旅相关费用' => array (),
  12621. '培训班费用' => array (),
  12622. '其他' => array ()
  12623. );
  12624. $html = "";
  12625. $psum = 0;
  12626. $item = array (
  12627. '市内交通费',
  12628. '市内出租费',
  12629. '办事处房租',
  12630. '电话费',
  12631. '水费',
  12632. '电费',
  12633. '办公费用',
  12634. '邮寄费',
  12635. '其他费用',
  12636. '车辆费用',
  12637. '广告费',
  12638. '团队建设费',
  12639. '物业管理费',
  12640. '宽带费'
  12641. );
  12642. foreach ( $item as $va ) {
  12643. $falg = true;
  12644. foreach ( $receiptCollectList as $v ) {
  12645. if ($v ['itemCategory'] == '日常相关费用') {
  12646. if ($v ['item'] == $va) {
  12647. if ($va == '市内交通费')
  12648. $r1 += $v ['price'];
  12649. if ($va == '市内出租费')
  12650. $r2 += $v ['price'];
  12651. if ($va == '办事处房租')
  12652. $r3 += $v ['price'];
  12653. if ($va == '电话费')
  12654. $r4 += $v ['price'];
  12655. if ($va == '水费')
  12656. $r5 += $v ['price'];
  12657. if ($va == '电费')
  12658. $r6 += $v ['price'];
  12659. if ($va == '办公费用')
  12660. $r7 += $v ['price'];
  12661. if ($va == '邮寄费')
  12662. $r8 += $v ['price'];
  12663. if ($va == '其他费用')
  12664. $r9 += $v ['price'];
  12665. if ($va == '车辆费用')
  12666. $r10 += $v ['price'];
  12667. if ($va == '广告费')
  12668. $r11 += $v ['price'];
  12669. if ($va == '团队建设费')
  12670. $r13 += $v ['price'];
  12671. if ($va == '物业管理费')
  12672. $r14 += $v ['price'];
  12673. if ($va == '宽带费')
  12674. $r15 += $v ['price'];
  12675. $psum += $v ['price'];
  12676. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12677. $falg = false;
  12678. break;
  12679. }
  12680. }
  12681. }
  12682. if ($falg)
  12683. $html .= '<td class="taR">-</td>';
  12684. }
  12685. $r12 += $psum;
  12686. if (! empty ( $psum ))
  12687. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12688. else
  12689. $psum = '<td class="colGreen taR">-</td>';
  12690. $receiptL ['日常相关费用'] = $psum . $html;
  12691. /* ----------------------------------- */
  12692. $html = "";
  12693. $psum = 0;
  12694. $item = array (
  12695. '往来交通费',
  12696. '市内交通费',
  12697. '出差住宿费',
  12698. '出差补助',
  12699. '其他费用'
  12700. );
  12701. foreach ( $item as $va ) {
  12702. $falg = true;
  12703. foreach ( $receiptCollectList as $v ) {
  12704. if ($v ['itemCategory'] == '差旅相关费用') {
  12705. if ($v ['item'] == $va) {
  12706. if ($va == '往来交通费')
  12707. $c1 += $v ['price'];
  12708. if ($va == '市内交通费')
  12709. $c2 += $v ['price'];
  12710. if ($va == '出差住宿费')
  12711. $c3 += $v ['price'];
  12712. if ($va == '出差补助')
  12713. $c4 += $v ['price'];
  12714. if ($va == '其他费用')
  12715. $c5 += $v ['price'];
  12716. $psum += $v ['price'];
  12717. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12718. $falg = false;
  12719. break;
  12720. }
  12721. }
  12722. }
  12723. if ($falg)
  12724. $html .= '<td class="taR">-</td>';
  12725. }
  12726. $c6 += $psum;
  12727. if (! empty ( $psum ))
  12728. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12729. else
  12730. $psum = '<td class="colGreen taR">-</td>';
  12731. $receiptL ['差旅相关费用'] = $psum . $html;
  12732. /* ------------------------------------- */
  12733. $html = "";
  12734. $psum = 0;
  12735. $item = array (
  12736. '场租费',
  12737. '薪酬',
  12738. '住宿费',
  12739. '交通费',
  12740. '餐饮费',
  12741. '办公费',
  12742. '公关费',
  12743. '其他'
  12744. );
  12745. foreach ( $item as $va ) {
  12746. $falg = true;
  12747. foreach ( $receiptCollectList as $v ) {
  12748. if ($v ['itemCategory'] == '培训班费用') {
  12749. if ($v ['item'] == $va) {
  12750. if ($va == '场租费')
  12751. $p1 += $v ['price'];
  12752. if ($va == '薪酬')
  12753. $p2 += $v ['price'];
  12754. if ($va == '住宿费')
  12755. $p3 += $v ['price'];
  12756. if ($va == '交通费')
  12757. $p4 += $v ['price'];
  12758. if ($va == '餐饮费')
  12759. $p5 += $v ['price'];
  12760. if ($va == '办公费')
  12761. $p6 += $v ['price'];
  12762. if ($va == '公关费')
  12763. $p7 += $v ['price'];
  12764. if ($va == '其他')
  12765. $p8 += $v ['price'];
  12766. $psum += $v ['price'];
  12767. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12768. $falg = false;
  12769. break;
  12770. }
  12771. }
  12772. }
  12773. if ($falg)
  12774. $html .= '<td class="taR">-</td>';
  12775. }
  12776. $p9 += $psum;
  12777. if (! empty ( $psum ))
  12778. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12779. else
  12780. $psum = '<td class="colGreen taR">-</td>';
  12781. $receiptL ['培训班费用'] = $psum . $html;
  12782. /* ------------------------------------- */
  12783. $html = "";
  12784. $psum = 0;
  12785. $item = array (
  12786. '公关费',
  12787. '广告费',
  12788. '借款',
  12789. '可自加费用'
  12790. );
  12791. foreach ( $item as $va ) {
  12792. $falg = true;
  12793. foreach ( $receiptCollectList as $v ) {
  12794. if ($v ['itemCategory'] == '其他') {
  12795. if ($v ['item'] == $va) {
  12796. if ($va == '公关费')
  12797. $t1 += $v ['price'];
  12798. if ($va == '广告费')
  12799. $t2 += $v ['price'];
  12800. if ($va == '借款')
  12801. $t3 += $v ['price'];
  12802. if ($va == '可自加费用')
  12803. $t4 += $v ['price'];
  12804. $psum += $v ['price'];
  12805. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12806. $falg = false;
  12807. break;
  12808. }
  12809. }
  12810. }
  12811. if ($falg)
  12812. $html .= '<td class="taR">-</td>';
  12813. }
  12814. $t5 += $psum;
  12815. if (! empty ( $psum ))
  12816. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12817. else
  12818. $psum = '<td class="colGreen taR">-</td>';
  12819. $receiptL ['其他'] = $psum . $html;
  12820. /* ------------------------------------- */
  12821. $html = "";
  12822. $psum = 0;
  12823. foreach ( $receiptCollectList as $v ) {
  12824. if ($v ['itemCategory'] == '报销金额调整') {
  12825. if (! empty ( $v ['price'] )) {
  12826. $psum += $v ['price'];
  12827. }
  12828. }
  12829. }
  12830. $s1 += $psum;
  12831. if (! empty ( $psum ))
  12832. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12833. else
  12834. $psum = '<td class="taR colOrange">-</td>';
  12835. $receiptL ['报销金额调整'] = $psum . $html;
  12836. } else {
  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><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>
  12840. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12841. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12842. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12843. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12844. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12845. }
  12846. $monthStaffPrice = $receiptDetail->find ( array (
  12847. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12848. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12849. 'asArray' => true
  12850. ) );
  12851. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12852. $m1 += $monthStaffPrice [0] ['price'];
  12853. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12854. } else
  12855. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12856. $list [$value ['username']] = $receiptL;
  12857. }
  12858. }
  12859. $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>
  12860. <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>
  12861. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12862. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12863. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12864. $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>
  12865. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12866. $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>';
  12867. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12868. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12869. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12870. }
  12871. $data ['list'] = $list;
  12872. $receiptCollectList = $receiptDetail->find ( array (
  12873. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12874. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12875. 'groupby' => 'item,Month(date),itemCategory',
  12876. 'asArray' => true
  12877. ) );
  12878. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12879. // statistics html
  12880. $stList = $statistics->getOne ( array (
  12881. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12882. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12883. 'groupby' => 'Month(date)',
  12884. 'asArray' => true
  12885. ) );
  12886. if (empty ( $stList ))
  12887. $stList = array (
  12888. 'rePrice' => 0,
  12889. 'agPrice' => 0
  12890. );
  12891. $data ['stList'] = array (
  12892. 'rePrice' => $stList ['rePrice'],
  12893. 'agPrice' => $stList ['agPrice'],
  12894. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12895. );
  12896. $monthHtml = "";
  12897. for($i = 1; $i <= 12; $i ++) {
  12898. if ($i == $month)
  12899. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12900. else
  12901. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12902. }
  12903. $data ['monthHtml'] = $monthHtml;
  12904. $data ['year'] = $year;
  12905. $data ['month'] = $month;
  12906. $data ['memu'] = "receipt";
  12907. $data ['staff'] = $this->staff;
  12908. $data ['receiptMemu'] = 'companyCategoryCollect';
  12909. $data ['verifyId'] = $this->verifyId;
  12910. $data ['executeId'] = $this->executeId;
  12911. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12912. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12913. }
  12914. /**
  12915. * 用户报销单列表
  12916. */
  12917. function receiptStatisticsStaffDetail() {
  12918. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12919. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12920. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  12921. Doo::loadModel ( "receipt" );
  12922. $receipt = new receipt ();
  12923. Doo::loadModel ( "receiptDetail" );
  12924. $receiptDetail = new receiptDetail ();
  12925. Doo::loadModel ( 'staff' );
  12926. $staff = new staff ();
  12927. Doo::loadModel ( 'accountItem' );
  12928. $accountItem = new accountItem ();
  12929. Doo::loadModel ( 'statistics' );
  12930. $statistics = new statistics ();
  12931. if (! empty ( $username )) {
  12932. $username = addslashes ( urldecode ( $username ) );
  12933. $staffDetail = $staff->getStaffByName ( $username );
  12934. if (empty ( $staffDetail ))
  12935. die ( 'illegal request' );
  12936. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  12937. $itemList = $accountItem->getAccountItem ();
  12938. $itemHtml = '';
  12939. $categoryHtml = '';
  12940. $itemKeyList = array_keys ( $itemList );
  12941. $revisePrice = 0;
  12942. // 报销单内容详情
  12943. foreach ( $list as $key => $value ) {
  12944. $accountItemList = json_decode ( $value ['accountItem'], true );
  12945. $list [$key] ['accountItemList'] = $accountItemList;
  12946. $receiptItemHtml = '';
  12947. foreach ( $itemKeyList as $v ) {
  12948. if ($v == '日常相关费用')
  12949. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  12950. elseif ($v == '差旅相关费用')
  12951. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  12952. elseif ($v == '培训班费用')
  12953. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  12954. elseif ($v == '内部培训费用'){
  12955. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  12956. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  12957. }else{
  12958. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  12959. }
  12960. }elseif ($v == '其他')
  12961. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  12962. foreach ( $itemList [$v] as $ke => $va ) {
  12963. $falg = true;
  12964. if (! empty ( $accountItemList [$v] )) {
  12965. foreach ( $accountItemList [$v] as $ve ) {
  12966. if ($va ['name'] == $ve ['name']) {
  12967. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  12968. $falg = false;
  12969. break;
  12970. }
  12971. }
  12972. }
  12973. if ($falg)
  12974. $receiptItemHtml .= '<td class="taR"></td>';
  12975. }
  12976. }
  12977. // 金额调整和费用查看
  12978. $revisePrice += $value ['revisePrice'];
  12979. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  12980. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  12981. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  12982. }
  12983. // 报销单合计
  12984. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  12985. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  12986. $receiptTotalHtml = '';
  12987. // 报销单项目抬头
  12988. foreach ( $itemKeyList as $value ) {
  12989. $count = count ( $itemList [$value] ) + 1;
  12990. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  12991. $categoryHtml .= '<th class="taC">合计</th>';
  12992. $sumfalg=true;
  12993. foreach ( $rtl as $rtlValue ) {
  12994. if ($rtlValue ['itemCategory'] == $value) {
  12995. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  12996. $sumfalg=false;
  12997. break;
  12998. }
  12999. }
  13000. if ($sumfalg)
  13001. $receiptTotalHtml .= '<th></th>';
  13002. foreach ( $itemList [$value] as $k => $v ) {
  13003. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13004. // 合计
  13005. $falg = true;
  13006. foreach ( $receiptTotalList as $ve ) {
  13007. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13008. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13009. $falg = false;
  13010. break;
  13011. }
  13012. }
  13013. if ($falg)
  13014. $receiptTotalHtml .= '<th></th>';
  13015. }
  13016. }
  13017. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13018. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13019. if (empty ( $stList ))
  13020. $stList = array (
  13021. 'rePrice' => 0,
  13022. 'agPrice' => 0
  13023. );
  13024. $data ['stList'] = array (
  13025. 'rePrice' => $stList ['rePrice'],
  13026. 'agPrice' => $stList ['agPrice'],
  13027. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13028. );
  13029. $monthHtml = "";
  13030. for($i = 1; $i <= 12; $i ++) {
  13031. if ($i == $month)
  13032. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13033. else
  13034. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13035. }
  13036. $data ['username'] = urlencode ( $username );
  13037. $data ['usernameEN'] = $username;
  13038. $data ['monthHtml'] = $monthHtml;
  13039. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13040. $data ['list'] = $list;
  13041. $data ['categoryHtml'] = $categoryHtml;
  13042. $data ['itemHtml'] = $itemHtml;
  13043. $data ['itemList'] = $itemList;
  13044. $data ['year'] = $year;
  13045. $data ['month'] = $month;
  13046. $data ['memu'] = "receipt";
  13047. $data ['staff'] = $this->staff;
  13048. $data ['receiptMemu'] = 'companyCategoryCollect';
  13049. $data ['verifyId'] = $this->verifyId;
  13050. $data ['executeId'] = $this->executeId;
  13051. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13052. }
  13053. die ( 'illegal request' );
  13054. }
  13055. function companyMonthCollectDetail() {
  13056. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13057. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13058. if (! $year)
  13059. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13060. if (! $month)
  13061. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13062. Doo::loadModel ( 'staff' );
  13063. $staff = new staff ();
  13064. Doo::loadModel ( "receiptDetail" );
  13065. $receiptDetail = new receiptDetail ();
  13066. Doo::loadModel ( 'accountItem' );
  13067. $accountItem = new accountItem ();
  13068. Doo::loadModel ( 'statistics' );
  13069. $statistics = new statistics ();
  13070. Doo::loadModel ( 'L_category' );
  13071. $lCategory = new L_category ();
  13072. $staffList = $staff->find ( array (
  13073. 'where' => 'username!="admin"',
  13074. 'asArray' => true
  13075. ) );
  13076. $categoryList = $lCategory->find ( array (
  13077. 'asArray' => true
  13078. ) );
  13079. $aiList=$accountItem->getAccountItem();
  13080. $list = array ();
  13081. foreach ( $categoryList as $value ) {
  13082. $receiptCollectList = $receiptDetail->find ( array (
  13083. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13084. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13085. 'groupby' => 'item,Month(pastDate),itemCategory',
  13086. 'asArray' => true
  13087. ) );
  13088. if (! empty ( $receiptCollectList )) {
  13089. $receiptL = array (
  13090. '日常相关费用' => array (),
  13091. '差旅相关费用' => array (),
  13092. '内部培训费用' => array (),
  13093. '培训班费用' => array (),
  13094. '其他' => array ()
  13095. );
  13096. $html = "";
  13097. $psum = 0;
  13098. foreach ( $aiList[$this->AGENCY] as $va ) {
  13099. $falg = true;
  13100. foreach ( $receiptCollectList as $v ) {
  13101. if ($v ['itemCategory'] == $this->AGENCY) {
  13102. if ($v ['item'] == $va['name']) {
  13103. $psum += $v ['price'];
  13104. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13105. $falg = false;
  13106. break;
  13107. }
  13108. }
  13109. }
  13110. if ($falg)
  13111. $html .= '<td class="taR">-</td>';
  13112. }
  13113. if (! empty ( $psum ))
  13114. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13115. else
  13116. $psum = '<td class="colGreen taR">-</td>';
  13117. $receiptL [$this->AGENCY] = $psum . $html;
  13118. /* ----------------------------------- */
  13119. $html = "";
  13120. $psum = 0;
  13121. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13122. $falg = true;
  13123. foreach ( $receiptCollectList as $v ) {
  13124. if ($v ['itemCategory'] == $this->TRAVEL) {
  13125. if ($v ['item'] == $va['name']) {
  13126. $psum += $v ['price'];
  13127. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13128. $falg = false;
  13129. break;
  13130. }
  13131. }
  13132. }
  13133. if ($falg)
  13134. $html .= '<td class="taR">-</td>';
  13135. }
  13136. if (! empty ( $psum ))
  13137. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13138. else
  13139. $psum = '<td class="colGreen taR">-</td>';
  13140. $receiptL [$this->TRAVEL] = $psum . $html;
  13141. /* ------------------------------------- */
  13142. $html = "";
  13143. $psum = 0;
  13144. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13145. $falg = true;
  13146. foreach ( $receiptCollectList as $v ) {
  13147. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13148. if ($v ['item'] == $va['name']) {
  13149. $psum += $v ['price'];
  13150. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13151. $falg = false;
  13152. break;
  13153. }
  13154. }
  13155. }
  13156. if ($falg)
  13157. $html .= '<td class="taR">-</td>';
  13158. }
  13159. if (! empty ( $psum ))
  13160. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13161. else
  13162. $psum = '<td class="colGreen taR">-</td>';
  13163. $receiptL [$this->INTTRAIN] = $psum . $html;
  13164. /* ------------------------------------- */
  13165. $html = "";
  13166. $psum = 0;
  13167. foreach ( $aiList[$this->TRAIN] as $va ) {
  13168. $falg = true;
  13169. foreach ( $receiptCollectList as $v ) {
  13170. if ($v ['itemCategory'] == $this->TRAIN) {
  13171. if ($v ['item'] == $va['name']) {
  13172. $psum += $v ['price'];
  13173. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13174. $falg = false;
  13175. break;
  13176. }
  13177. }
  13178. }
  13179. if ($falg)
  13180. $html .= '<td class="taR">-</td>';
  13181. }
  13182. if (! empty ( $psum ))
  13183. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13184. else
  13185. $psum = '<td class="colGreen taR">-</td>';
  13186. $receiptL [$this->TRAIN] = $psum . $html;
  13187. /* ------------------------------------- */
  13188. $html = "";
  13189. $psum = 0;
  13190. foreach ( $aiList[$this->OTHER] as $va ) {
  13191. $falg = true;
  13192. foreach ( $receiptCollectList as $v ) {
  13193. if ($v ['itemCategory'] == $this->OTHER) {
  13194. if ($v ['item'] == $va['name']) {
  13195. $psum += $v ['price'];
  13196. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13197. $falg = false;
  13198. break;
  13199. }
  13200. }
  13201. }
  13202. if ($falg)
  13203. $html .= '<td class="taR">-</td>';
  13204. }
  13205. if (! empty ( $psum ))
  13206. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13207. else
  13208. $psum = '<td class="colGreen taR">-</td>';
  13209. $receiptL [$this->OTHER] = $psum . $html;
  13210. /* ------------------------------------- */
  13211. $html = "";
  13212. $psum = 0;
  13213. foreach ( $receiptCollectList as $v ) {
  13214. if ($v ['itemCategory'] == '报销金额调整') {
  13215. if (! empty ( $v ['price'] ))
  13216. $psum += $v ['price'];
  13217. }
  13218. }
  13219. if (! empty ( $psum ))
  13220. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13221. else
  13222. $psum = '<td class="taR colOrange">-</td>';
  13223. $receiptL ['报销金额调整'] = $psum . $html;
  13224. } else {
  13225. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13226. foreach ( $aiList[$this->AGENCY] as $va ) {
  13227. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13228. }
  13229. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13230. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13231. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13232. }
  13233. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13234. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13235. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13236. }
  13237. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13238. foreach ( $aiList[$this->TRAIN] as $va ) {
  13239. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13240. }
  13241. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13242. foreach ( $aiList[$this->OTHER] as $va ) {
  13243. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13244. }
  13245. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13246. }
  13247. $monthStaffPrice = $receiptDetail->find ( array (
  13248. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13249. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13250. 'asArray' => true
  13251. ) );
  13252. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13253. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13254. else
  13255. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13256. $list [$value ['title']] = $receiptL;
  13257. }
  13258. $data ['list'] = $list;
  13259. $receiptCollectList = $receiptDetail->find ( array (
  13260. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13261. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13262. 'groupby' => 'item,Month(pastDate),itemCategory',
  13263. 'asArray' => true
  13264. ) );
  13265. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13266. //print_r($data['monthPriceHtml']);
  13267. // foreach ($data['monthPriceHtml'] as $value){
  13268. // echo $value;
  13269. // }
  13270. // die;
  13271. // statistics html
  13272. $stList = $statistics->getOne ( array (
  13273. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13274. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13275. 'groupby' => 'Month(date)',
  13276. 'asArray' => true
  13277. ) );
  13278. if (empty ( $stList ))
  13279. $stList = array (
  13280. 'rePrice' => 0,
  13281. 'agPrice' => 0
  13282. );
  13283. $data ['stList'] = array (
  13284. 'rePrice' => $stList ['rePrice'],
  13285. 'agPrice' => $stList ['agPrice'],
  13286. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13287. );
  13288. $monthHtml = "";
  13289. for($i = 1; $i <= 12; $i ++) {
  13290. if ($i == $month)
  13291. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13292. else
  13293. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13294. }
  13295. $data ['aiList'] = $aiList;
  13296. $data ['monthHtml'] = $monthHtml;
  13297. $data ['year'] = $year;
  13298. $data ['month'] = $month;
  13299. $data ['memu'] = "receipt";
  13300. $data ['staff'] = $this->staff;
  13301. $data ['receiptMemu'] = 'companyCategoryCollect';
  13302. $data ['verifyId'] = $this->verifyId;
  13303. $data ['executeId'] = $this->executeId;
  13304. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13305. }
  13306. function staffCollectDetail() {
  13307. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13308. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13309. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13310. if (! $staffname) {
  13311. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13312. $staffname = urldecode ( $staffname );
  13313. }
  13314. Doo::loadModel ( 'staff' );
  13315. $staff = new staff ();
  13316. Doo::loadModel ( "receiptDetail" );
  13317. $receiptDetail = new receiptDetail ();
  13318. Doo::loadModel ( 'accountItem' );
  13319. $accountItem = new accountItem ();
  13320. Doo::loadModel ( 'statistics' );
  13321. $statistics = new statistics ();
  13322. Doo::loadModel ( 'L_category' );
  13323. $lCategory = new L_category ();
  13324. Doo::loadModel ( "receiptAuthorityManage" );
  13325. $receiptAuthorityManage = new receiptAuthorityManage ();
  13326. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13327. $cidList = array ();
  13328. foreach ( $imcStaff as $key => $value ) {
  13329. array_push ( $cidList, $value ['cid'] );
  13330. }
  13331. $cidString = implode ( ',', $cidList );
  13332. $staffList = $staff->find ( array (
  13333. 'where' => ' cid in (' . $cidString . ')',
  13334. 'asArray' => true
  13335. ) );
  13336. $stHtml = '';
  13337. $stTitle = "";
  13338. $staffId = 0;
  13339. $cid = 0;
  13340. $ocid = 0;
  13341. foreach ( $staffList as $value ) {
  13342. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13343. $stTitle = $value ['category'] . '-' . $value ['username'];
  13344. $staffId = $value ['sid'];
  13345. $cid = $value ['cid'];
  13346. $ocid = $value ['cid'];
  13347. if (! empty ( $value ['othercid'] ))
  13348. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13349. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13350. } elseif ($value ['username'] != 'admin')
  13351. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13352. }
  13353. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13354. 'where' => 'cid in(' . $cid . ')',
  13355. 'asArray' => true
  13356. ) );
  13357. if (empty ( $pcid ))
  13358. $pcid = $ocid;
  13359. $data ['ocid'] = $pcid;
  13360. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13361. $this->showCache ( $path );
  13362. //
  13363. $receiptCollectList = $receiptDetail->find ( array (
  13364. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13365. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13366. 'groupby' => 'item,Month(pastDate),itemCategory',
  13367. 'asArray' => true
  13368. ) );
  13369. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13370. // print_r($receiptCollectList);
  13371. $accountList = $accountItem->find ( array (
  13372. 'asArray' => true
  13373. ) );
  13374. // create CollectDetail HTML
  13375. $collectHtml = array ();
  13376. foreach ( $accountList as $key => $value ) {
  13377. $html = "";
  13378. $asum = 0;
  13379. for($i = 1; $i <= 12; $i ++) {
  13380. $falg = true;
  13381. foreach ( $receiptCollectList as $v ) {
  13382. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13383. if ($v ['item'] == '可自加费用') {
  13384. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13385. }
  13386. $asum += $v ['price'];
  13387. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13388. $falg = false;
  13389. break;
  13390. }
  13391. }
  13392. if ($falg)
  13393. $html .= '<td class="taR">-</td>';
  13394. }
  13395. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13396. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13397. }
  13398. $data ['collectHtml'] = $collectHtml;
  13399. // print_r($collectHtml);
  13400. // create Adjustment price html
  13401. $receiptCollectList = $receiptDetail->find ( array (
  13402. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13403. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13404. 'groupby' => 'itemCategory,Month(pastDate)',
  13405. 'asArray' => true
  13406. ) );
  13407. $adjustment = array ();
  13408. $collectArray = array (
  13409. '日常相关费用' => array (),
  13410. '差旅相关费用' => array (),
  13411. '培训班费用' => array (),
  13412. '内部培训费用'=>array(),
  13413. '其他' => array ()
  13414. );
  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. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13422. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13423. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13424. array_push ( $collectArray ['其他'], $collectHtml );
  13425. $data ['collectArray'] = $collectArray;
  13426. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13427. array_push ( $adjustment, $collectHtml );
  13428. $data ['adjustment'] = $adjustment;
  13429. // total price html
  13430. $collectHtml = "";
  13431. $total = 0;
  13432. for($i = 1; $i <= 12; $i ++) {
  13433. $sumPrice = 0;
  13434. foreach ( $receiptCollectList as $key => $value ) {
  13435. if ($value ['month'] == $i) {
  13436. $sumPrice += $value ['price'];
  13437. }
  13438. }
  13439. if ($sumPrice == 0)
  13440. $collectHtml .= '<td class="taR">-</td>';
  13441. else
  13442. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13443. $total += $sumPrice;
  13444. }
  13445. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13446. // statistics html
  13447. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13448. if (empty ( $stList ))
  13449. $stList = array (
  13450. 'rePrice' => 0,
  13451. 'agPrice' => 0
  13452. );
  13453. $data ['stList'] = array (
  13454. 'rePrice' => $stList ['rePrice'],
  13455. 'agPrice' => $stList ['agPrice'],
  13456. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13457. );
  13458. $data ['totalPrice'] = $collectHtml;
  13459. $data ['totalYear'] = $total;
  13460. $data ['stHtml'] = $stHtml;
  13461. $data ['year'] = $year;
  13462. $data ['stTitle'] = $stTitle;
  13463. $data ['staffname'] = urlencode ( $staffname );
  13464. $data ['memu'] = "receipt";
  13465. $data ['staff'] = $this->staff;
  13466. $data ['receiptMemu'] = 'companyCategoryCollect';
  13467. $data ['verifyId'] = $this->verifyId;
  13468. $data ['executeId'] = $this->executeId;
  13469. if ($year < date ( "Y" )) {
  13470. Doo::loadModel ( 'receipt' );
  13471. $receipt = new receipt ();
  13472. $receiptList = $receipt->find ( array (
  13473. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13474. 'asArray' => true
  13475. ) );
  13476. if (empty ( $receiptList )) { // generated files
  13477. ob_start ();
  13478. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13479. $this->cacheFile ( $path );
  13480. die ();
  13481. }
  13482. }
  13483. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13484. }
  13485. function BUGFLAG() {
  13486. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13487. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13488. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13489. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13490. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13491. if (empty ( $status ))
  13492. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13493. $page_size = 12;
  13494. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13495. $vidList = array ();
  13496. $button = 0;
  13497. Doo::loadModel ( 'verify' );
  13498. $verify = new verify ();
  13499. Doo::loadModel ( 'receipt' );
  13500. $receipt = new receipt ();
  13501. Doo::loadModel ( 'staff' );
  13502. $staff = new staff ();
  13503. Doo::loadModel ( 'L_category' );
  13504. $Lcategory = new L_category ();
  13505. $dateCondition = " and Year(date) =" . $year;
  13506. if (! empty ( $month ))
  13507. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13508. $categoryList = $Lcategory->find ( array (
  13509. 'asArray' => true
  13510. ) );
  13511. $staffList = $staff->find ( array (
  13512. 'where' => 'cid=' . $cid,
  13513. 'asArray' => true
  13514. ) );
  13515. $cateCondition = "";
  13516. $staffCondition = "";
  13517. $approvalCondition = "";
  13518. if (! empty ( $cid ))
  13519. $cateCondition = ' and cid=' . $cid;
  13520. if (! empty ( $sid )) {
  13521. $staffCondition = ' and staff=' . $sid;
  13522. $cateCondition = "";
  13523. }
  13524. $approvalCondition = " and status=" . $status;
  13525. if ($status == 2) {
  13526. // 查找角色审批人
  13527. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13528. }
  13529. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13530. $approvalCondition = ' and status=2 ';
  13531. }
  13532. if ($status == 1) {
  13533. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13534. }
  13535. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13536. $pageinfo ['page'] = array (
  13537. 'previous' => ''
  13538. );
  13539. if ($status == 0) {
  13540. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13541. $receiptList = $receipt->find ( array (
  13542. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13543. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13544. 'desc' => 'rid',
  13545. 'asArray' => true
  13546. ) );
  13547. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13548. } else
  13549. $receiptList = $receipt->find ( array (
  13550. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13551. 'desc' => 'rid',
  13552. 'asArray' => true
  13553. ) );
  13554. $rLRes = $receipt->find ( array (
  13555. '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,
  13556. 'desc' => 'rid',
  13557. 'asArray' => true
  13558. ) );
  13559. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13560. // print_r($pageinfo);
  13561. $Locate = 0;
  13562. foreach ( $receiptList as $key => $value ) {
  13563. $receiptList [$key] ['Locate'] = $Locate;
  13564. $Locate ++;
  13565. $receiptList [$key] ['reviseDetail'] = array ();
  13566. if (! empty ( $value ['reviseDetail'] ))
  13567. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13568. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13569. $categoryDetil = $Lcategory->getOne ( array (
  13570. 'where' => 'cid=' . $value ['cid'],
  13571. 'asArray' => true
  13572. ) );
  13573. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13574. $verifyList = $verify->getOne ( array (
  13575. 'where' => 'vid=' . $value ['verify'],
  13576. 'asArray' => true
  13577. ) );
  13578. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13579. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13580. foreach ( $verifyList as $k => $v ) {
  13581. // init verifyStaff
  13582. $verifyList [$k] ['date'] = "";
  13583. $verifyList [$k] ['opinion'] = "";
  13584. $verifyList [$k] ['status'] = "";
  13585. if (empty ( $verifyStaff )) {
  13586. $verifyList [$k] ['date'] = "";
  13587. $verifyList [$k] ['opinion'] = "";
  13588. if ($v [0] == $this->staff [0] ['sid']) {
  13589. $verifyList [$k] ['status'] = 4;
  13590. $button = 4;
  13591. }
  13592. } else {
  13593. $flag = true;
  13594. foreach ( $verifyStaff as $m => $u ) {
  13595. if ($v [0] == $m) {
  13596. $verifyList [$k] ['date'] = $u ['date'];
  13597. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13598. $verifyList [$k] ['status'] = $u ['status'];
  13599. $flag = false;
  13600. break;
  13601. }
  13602. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13603. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13604. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13605. }
  13606. if ($flag) { // 检测可编辑
  13607. if ($v [0] == $this->staff [0] ['sid']) {
  13608. $verifyList [$k] ['status'] = 4;
  13609. $button = 4;
  13610. }
  13611. }
  13612. }
  13613. }
  13614. $receiptList [$key] ['verifyList'] = $verifyList;
  13615. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13616. 'where' => 'sid=' . $value ['staff'],
  13617. 'asArray' => true
  13618. ) );
  13619. $receiptList [$key] ['button'] = $button;
  13620. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13621. }
  13622. // print_r($receiptList);die;
  13623. // $data['verifyDetail']=$verifyDetail;
  13624. $mothHtml = "";
  13625. for($i = 1; $i <= 12; $i ++) {
  13626. if ($month == $i)
  13627. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13628. else
  13629. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13630. }
  13631. $data ['mothHtml'] = $mothHtml;
  13632. $data ['page'] = $pageinfo;
  13633. $data ['receiptList'] = $receiptList;
  13634. $data ['receiptApprovalCount'] = count ( $rLRes );
  13635. $data ['status'] = $status;
  13636. $data ['year'] = $year;
  13637. $data ['categoryList'] = $categoryList;
  13638. $data ['staffList'] = $staffList;
  13639. $data ['cid'] = $cid;
  13640. $data ['sid'] = $sid;
  13641. // print_r($receiptList);
  13642. $data ['memu'] = "receipt";
  13643. $data ['staff'] = $this->staff;
  13644. $data ['receiptMemu'] = 'approvalExpenses';
  13645. $data ['verifyId'] = $this->verifyId;
  13646. $data ['executeId'] = $this->executeId;
  13647. $this->render ( "/admin/FALG", $data );
  13648. }
  13649. function ajaxGetReceiptOrder() {
  13650. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13651. if (! empty ( $receiptOrder )) {
  13652. Doo::loadModel ( 'receipt' );
  13653. $receipt = new receipt ();
  13654. Doo::loadModel ( 'staff' );
  13655. $staff = new staff ();
  13656. $receiptInfo = $receipt->getOne ( array (
  13657. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13658. 'asArray' => true
  13659. ) );
  13660. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13661. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13662. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13663. </tbody></table><table class="table table table-bordered"><tbody>';
  13664. foreach ( $verifyStaff as $key => $value ) {
  13665. $staffInfo = $staff->getOne ( array (
  13666. 'select' => 'username',
  13667. 'where' => ' sid="' . $key . '"',
  13668. 'asArray' => true
  13669. ) );
  13670. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13671. }
  13672. $html .= '</tbody></table></div></div>';
  13673. echo json_encode ( array (
  13674. 'status' => 1,
  13675. 'receiptHtml' => $html
  13676. ) );
  13677. die ();
  13678. }
  13679. echo json_encode ( array (
  13680. 'status' => 2,
  13681. 'receiptHtml' => ''
  13682. ) );
  13683. die ();
  13684. }
  13685. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13686. if (! empty ( $receiptCollectList )) {
  13687. $receiptL = array (
  13688. '日常相关费用' => array (),
  13689. '差旅相关费用' => array (),
  13690. '内部培训费用'=>array(),
  13691. '培训班费用' => array (),
  13692. '其他' => array ()
  13693. );
  13694. $html = "";
  13695. $psum = 0;
  13696. foreach ( $aiList[$this->AGENCY] as $value ) {
  13697. $falg = true;
  13698. foreach ( $receiptCollectList as $v ) {
  13699. if ($v ['itemCategory'] == '日常相关费用') {
  13700. if ($v ['item'] == $value['name']) {
  13701. $psum += $v ['price'];
  13702. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13703. $falg = false;
  13704. break;
  13705. }
  13706. }
  13707. }
  13708. if ($falg)
  13709. $html .= '<td class="taR">-</td>';
  13710. }
  13711. if (! empty ( $psum ))
  13712. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13713. else
  13714. $psum = '<td class="colGreen taR">-</td>';
  13715. $receiptL ['日常相关费用'] = $psum . $html;
  13716. /* ----------------------------------- */
  13717. $html = "";
  13718. $psum = 0;
  13719. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13720. $falg = true;
  13721. foreach ( $receiptCollectList as $v ) {
  13722. if ($v ['itemCategory'] == '差旅相关费用') {
  13723. if ($v ['item'] == $value['name']) {
  13724. $psum += $v ['price'];
  13725. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13726. $falg = false;
  13727. break;
  13728. }
  13729. }
  13730. }
  13731. if ($falg)
  13732. $html .= '<td class="taR">-</td>';
  13733. }
  13734. if (! empty ( $psum ))
  13735. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13736. else
  13737. $psum = '<td class="colGreen taR">-</td>';
  13738. $receiptL ['差旅相关费用'] = $psum . $html;
  13739. /* ----------------------------------- */
  13740. $html = "";
  13741. $psum = 0;
  13742. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13743. $falg = true;
  13744. foreach ( $receiptCollectList as $v ) {
  13745. if ($v ['itemCategory'] == '内部培训费用') {
  13746. if ($v ['item'] == $value['name']) {
  13747. $psum += $v ['price'];
  13748. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13749. $falg = false;
  13750. break;
  13751. }
  13752. }
  13753. }
  13754. if ($falg)
  13755. $html .= '<td class="taR">-</td>';
  13756. }
  13757. if (! empty ( $psum ))
  13758. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13759. else
  13760. $psum = '<td class="colGreen taR">-</td>';
  13761. $receiptL ['内部培训费用'] = $psum . $html;
  13762. /* ------------------------------------- */
  13763. $html = "";
  13764. $psum = 0;
  13765. foreach ( $aiList[$this->TRAIN] as $value ) {
  13766. $falg = true;
  13767. foreach ( $receiptCollectList as $v ) {
  13768. if ($v ['itemCategory'] == '培训班费用') {
  13769. if ($v ['item'] == $value['name']) {
  13770. $psum += $v ['price'];
  13771. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13772. $falg = false;
  13773. break;
  13774. }
  13775. }
  13776. }
  13777. if ($falg)
  13778. $html .= '<td class="taR">-</td>';
  13779. }
  13780. if (! empty ( $psum ))
  13781. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13782. else
  13783. $psum = '<td class="colGreen taR">-</td>';
  13784. $receiptL ['培训班费用'] = $psum . $html;
  13785. /* ------------------------------------- */
  13786. $html = "";
  13787. $psum = 0;
  13788. foreach ( $aiList[$this->OTHER] as $value ) {
  13789. $falg = true;
  13790. foreach ( $receiptCollectList as $v ) {
  13791. if ($v ['itemCategory'] == '其他') {
  13792. if ($v ['item'] == $value['name']) {
  13793. $psum += $v ['price'];
  13794. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13795. $falg = false;
  13796. break;
  13797. }
  13798. }
  13799. }
  13800. if ($falg)
  13801. $html .= '<td class="taR">-</td>';
  13802. }
  13803. if (! empty ( $psum ))
  13804. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13805. else
  13806. $psum = '<td class="colGreen taR">-</td>';
  13807. $receiptL ['其他'] = $psum . $html;
  13808. /* ------------------------------------- */
  13809. $html = "";
  13810. $psum = 0;
  13811. foreach ( $receiptCollectList as $v ) {
  13812. if ($v ['itemCategory'] == '报销金额调整') {
  13813. if (! empty ( $v ['price'] ))
  13814. $psum += $v ['price'];
  13815. }
  13816. }
  13817. if (! empty ( $psum ))
  13818. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13819. else
  13820. $psum = '<td class="taR colOrange">-</td>';
  13821. $receiptL ['报销金额调整'] = $psum . $html;
  13822. } else {
  13823. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13824. foreach ( $aiList[$this->AGENCY] as $va ) {
  13825. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13826. }
  13827. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13828. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13829. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13830. }
  13831. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13832. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13833. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13834. }
  13835. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13836. foreach ( $aiList[$this->TRAIN] as $va ) {
  13837. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13838. }
  13839. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13840. foreach ( $aiList[$this->OTHER] as $va ) {
  13841. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13842. }
  13843. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13844. }
  13845. return $receiptL;
  13846. }
  13847. function eMail() {
  13848. Doo::loadModel ( 'staff' );
  13849. $staff = new staff ();
  13850. Doo::loadModel ( 'receipt' );
  13851. $receipt = new receipt ();
  13852. Doo::loadModel ( 'L_category' );
  13853. $Lcategory = new L_category ();
  13854. Doo::loadModel ( "verify" );
  13855. $verify = new verify ();
  13856. $staffList = $staff->find ( array (
  13857. 'asArray' => true
  13858. ) );
  13859. foreach ( $staffList as $key => $value ) {
  13860. if ($value ['username'] != 'admin') {
  13861. // 提交人
  13862. $receiptList = $receipt->find ( array (
  13863. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13864. 'asArray' => true
  13865. ) );
  13866. if (! empty ( $receiptList )) {
  13867. $html = '<br><div><style></style>
  13868. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13869. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13870. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13871. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13872. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13873. <tbody><tr>
  13874. <td style="padding: 0 40px;" align="left">
  13875. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13876. </td></tr><tr>
  13877. <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>
  13878. </tr>
  13879. </tbody> </table></td> </tr> <tr><td>
  13880. <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">
  13881. <tbody> <tr><td>
  13882. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13883. 以下报销单完成了审批,等着收款吧:</p>
  13884. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13885. foreach ( $receiptList as $k => $v ) {
  13886. $category = $Lcategory->getOne ( array (
  13887. 'where' => 'cid=' . $v ['cid'],
  13888. 'asArray' => true
  13889. ) );
  13890. $html .= '
  13891. <tr>
  13892. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13893. <td align="left">
  13894. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13895. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13896. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13897. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13898. </tr>';
  13899. }
  13900. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13901. <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>
  13902. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13903. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13904. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13905. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13906. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13907. $receipt = new receipt ();
  13908. $receipt->notice = 1;
  13909. $receipt->update ( array (
  13910. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13911. ) );
  13912. }
  13913. }
  13914. // 审批人
  13915. $verifyList = $verify->find ( array (
  13916. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13917. 'asArray' => true
  13918. ) );
  13919. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  13920. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  13921. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13922. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  13923. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13924. <tbody><tr><td style="padding: 0 40px;" align="left">
  13925. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13926. </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>
  13927. </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">
  13928. <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>
  13929. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  13930. foreach ( $verifyList as $k => $v ) {
  13931. $receiptList = $receipt->find ( array (
  13932. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  13933. 'asArray' => true
  13934. ) );
  13935. foreach ( $receiptList as $r => $l ) {
  13936. $category = $Lcategory->getOne ( array (
  13937. 'where' => 'cid=' . $l ['cid'],
  13938. 'asArray' => true
  13939. ) );
  13940. $staffDetile = $staff->getOne ( array (
  13941. 'where' => 'sid=' . $l ['staff'],
  13942. 'asArray' => true
  13943. ) );
  13944. $html .= '
  13945. <tr>
  13946. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13947. <td align="left">
  13948. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  13949. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  13950. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  13951. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  13952. </tr>';
  13953. }
  13954. }
  13955. $html .= '
  13956. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  13957. <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>
  13958. </tr></tbody></table></td></tr></tbody></table></div><br>';
  13959. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  13960. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  13961. // $receipt=new receipt();
  13962. // $receipt->notice=1;
  13963. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  13964. }
  13965. }
  13966. }
  13967. }
  13968. function setWXMsg($rid, $type) {
  13969. Doo::loadModel ( "receipt" );
  13970. $receipt = new receipt ();
  13971. $receiptDetail = $receipt->getOne ( array (
  13972. 'where' => 'rid=' . $rid,
  13973. 'asArray' => true
  13974. ) );
  13975. if (! empty ( $receiptDetail )) {
  13976. Doo::loadModel ( 'staff' );
  13977. $staff = new staff ();
  13978. $staffmsg = $staff->getOne ( array (
  13979. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  13980. 'asArray' => TRUE
  13981. ) );
  13982. if (! empty ( $staffmsg ['wxid'] )) {
  13983. require_once (SITE_PATH . '/protected/class/client.php');
  13984. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  13985. $user = $staffmsg ['wxid'];
  13986. $receiptName = '';
  13987. $msg = '';
  13988. switch ($receiptDetail ['Rtype']) {
  13989. case 0 :
  13990. $receiptName = '报销';
  13991. break;
  13992. case 1 :
  13993. $receiptName = '借款';
  13994. break;
  13995. case 2 :
  13996. $receiptName = '对公汇款';
  13997. break;
  13998. }
  13999. switch ($type) {
  14000. case 1 :
  14001. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14002. break;
  14003. case 2 :
  14004. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14005. break;
  14006. case 3 :
  14007. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14008. break;
  14009. }
  14010. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14011. }
  14012. }
  14013. }
  14014. // Email发送函数
  14015. function SMail($toemail, $subject, $contents) {
  14016. Doo::loadClass ( 'class.phpmailer' );
  14017. $mail = new PHPMailer ();
  14018. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14019. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14020. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14021. $mail->Password = "cDO1GjtY1seH"; // 密码
  14022. $mail->CharSet = "UTF8";
  14023. $mail->SMTPAuth = true;
  14024. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14025. $mail->Mailer = "smtp";
  14026. $mail->Port = 25;
  14027. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14028. $mail->MsgHTML ( $contents );
  14029. $mail->AddAddress ( $toemail );
  14030. $mail->CharSet = "UTF-8";
  14031. return $mail->Send ();
  14032. }
  14033. function h5Upload() {
  14034. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14035. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14036. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14037. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14038. header ( "HTTP/1.1 500 Internal Server Error" );
  14039. echo "POST exceeded maximum allowed size.";
  14040. exit ( 0 );
  14041. }
  14042. // Settings
  14043. $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)
  14044. $upload_name = "Filedata";
  14045. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14046. $extension_whitelist = array (
  14047. "doc",
  14048. "txt",
  14049. "jpg",
  14050. "gif",
  14051. "png"
  14052. ); // Allowed file extensions
  14053. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14054. // Other variables
  14055. $MAX_FILENAME_LENGTH = 260;
  14056. $file_name = "";
  14057. $file_extension = "";
  14058. $uploadErrors = array (
  14059. 0 => "文件上传成功",
  14060. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14061. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14062. 3 => "上传的文件仅为部分文件",
  14063. 4 => "没有文件上传",
  14064. 6 => "缺少临时文件夹"
  14065. );
  14066. $nk = time ();
  14067. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14068. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14069. echo "文件无法保存.";
  14070. exit ( 0 );
  14071. }
  14072. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14073. echo json_encode ( array (
  14074. 'filename' => $file_name,
  14075. 'id' => $nk
  14076. ) );
  14077. exit ( 0 );
  14078. }
  14079. function swfupload() {
  14080. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14081. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14082. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14083. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14084. header ( "HTTP/1.1 500 Internal Server Error" );
  14085. echo "POST exceeded maximum allowed size.";
  14086. exit ( 0 );
  14087. }
  14088. // Settings
  14089. $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)
  14090. $upload_name = "Filedata";
  14091. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14092. $extension_whitelist = array (
  14093. "doc",
  14094. "txt",
  14095. "jpg",
  14096. "gif",
  14097. "png"
  14098. ); // Allowed file extensions
  14099. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14100. // Other variables
  14101. $MAX_FILENAME_LENGTH = 260;
  14102. $file_name = "";
  14103. $file_extension = "";
  14104. $uploadErrors = array (
  14105. 0 => "文件上传成功",
  14106. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14107. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14108. 3 => "上传的文件仅为部分文件",
  14109. 4 => "没有文件上传",
  14110. 6 => "缺少临时文件夹"
  14111. );
  14112. $nk = time ();
  14113. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14114. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14115. echo "文件无法保存.";
  14116. exit ( 0 );
  14117. }
  14118. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14119. echo json_encode ( array (
  14120. 'filename' => $file_name,
  14121. 'id' => $nk
  14122. ) );
  14123. exit ( 0 );
  14124. }
  14125. function _GetFileEXT($filename) {
  14126. $pics = explode ( '.', $filename );
  14127. $num = count ( $pics );
  14128. return $pics [$num - 1];
  14129. }
  14130. /**
  14131. * 获取get或者POST值
  14132. * @param string $name 属性名称
  14133. * @return fixed 值
  14134. */
  14135. function get_args($name) {
  14136. if (isset ( $_GET [$name] )) {
  14137. if (is_array ( $_GET [$name] ))
  14138. return $_GET [$name];
  14139. else
  14140. return addslashes ( $_GET [$name] );
  14141. } elseif (isset ( $_POST [$name] )) {
  14142. if (is_array ( $_POST [$name] ))
  14143. return $_POST [$name];
  14144. else
  14145. return addslashes ( $_POST [$name] );
  14146. } else
  14147. return false;
  14148. }
  14149. function num_to_rmb($num) {
  14150. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14151. $c2 = "分角元拾佰仟万拾佰仟亿";
  14152. // 精确到分后面就不要了,所以只留两个小数位
  14153. $num = round ( $num, 2 );
  14154. // 将数字转化为整数
  14155. $num = $num * 100;
  14156. if (strlen ( $num ) > 10) {
  14157. return "金额太大,请检查";
  14158. }
  14159. $i = 0;
  14160. $c = "";
  14161. while ( 1 ) {
  14162. if ($i == 0) {
  14163. // 获取最后一位数字
  14164. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14165. } else {
  14166. $n = $num % 10;
  14167. }
  14168. // 每次将最后一位数字转化为中文
  14169. $p1 = substr ( $c1, 3 * $n, 3 );
  14170. $p2 = substr ( $c2, 3 * $i, 3 );
  14171. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14172. $c = $p1 . $p2 . $c;
  14173. } else {
  14174. $c = $p1 . $c;
  14175. }
  14176. $i = $i + 1;
  14177. // 去掉数字最后一位了
  14178. $num = $num / 10;
  14179. // echo $num.'</br>';
  14180. $num = ( int ) $num;
  14181. // $num =floor($num);
  14182. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14183. // echo $num.'</br>';
  14184. // 结束循环
  14185. if ($num == 0) {
  14186. break;
  14187. }
  14188. }
  14189. // echo $c.'</br>';
  14190. $j = 0;
  14191. $slen = strlen ( $c );
  14192. while ( $j < $slen ) {
  14193. // utf8一个汉字相当3个字符
  14194. $m = substr ( $c, $j, 6 );
  14195. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14196. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14197. $left = substr ( $c, 0, $j );
  14198. $right = substr ( $c, $j + 3 );
  14199. $c = $left . $right;
  14200. $j = $j - 3;
  14201. $slen = $slen - 3;
  14202. }
  14203. $j = $j + 3;
  14204. }
  14205. // 这个是为了去掉类似23.0中最后一个“零”字
  14206. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14207. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14208. }
  14209. // 将处理的汉字加上“整”
  14210. if (empty ( $c )) {
  14211. return "零元整";
  14212. } else {
  14213. return $c . "整";
  14214. }
  14215. }
  14216. /**
  14217. * 获得分页数据
  14218. * @param unknown_type $table
  14219. * @param unknown_type $condition
  14220. * @param unknown_type $on_page
  14221. * @param unknown_type $page_size
  14222. */
  14223. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14224. $page_c = "";
  14225. $page ['previous'] = $this->get_previous ( $on_page );
  14226. $page ['on_page'] = $on_page;
  14227. $total_count = $this->get_table_count ( $table, $condition );
  14228. $total = intval ( $total_count / $page_size );
  14229. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14230. $page ['total_data'] = $total_count;
  14231. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14232. $i = 1;
  14233. $page_max = 1;
  14234. $page_width = 3;
  14235. if ($on_page >= $page_width) {
  14236. $page_max = intval ( $on_page / $page_width ) + 1;
  14237. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14238. }
  14239. for(; $i <= $page ['total_page']; $i ++) {
  14240. if ($i == $on_page)
  14241. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14242. else
  14243. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14244. if ($i == ($page_width * $page_max))
  14245. break;
  14246. }
  14247. $page ['page'] = $page_c;
  14248. $page ['lower'] = (-- $on_page) * $page_size;
  14249. return $page;
  14250. }
  14251. /**
  14252. * 获取总页数
  14253. * @param unknown_type $table
  14254. * @param unknown_type $condition
  14255. */
  14256. public function get_table_count($table = "", $condition = "") {
  14257. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14258. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14259. // echo $sql;die;
  14260. $query = Doo::db ()->query ( $sql );
  14261. $result = $query->fetch ();
  14262. return $result ['count'];
  14263. }
  14264. /**
  14265. * 获取上一页
  14266. * @param unknown_type $on_page
  14267. */
  14268. function get_previous($on_page = 1) {
  14269. return $on_page != 0 ? $on_page - 1 : $on_page;
  14270. }
  14271. }
  14272. ?>