ReceiptController.php 545 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642
  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-statistics' );
  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. //print_r($this->executeId);
  135. $this->verifyId = $list;
  136. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  137. // 检测用户信息完成
  138. $this->data ['isStaffCompleteMsg'] = false;
  139. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  140. if (! empty ( $detail ))
  141. $this->data ['isStaffCompleteMsg'] = true;
  142. return "/";
  143. }
  144. }
  145. Doo::loadCore ( 'uri/DooUriRouter' );
  146. $router = new DooUriRouter ();
  147. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  148. if ($routeRs ['1'] != "login") {
  149. header ( 'Content-Type:text/html;charset=utf-8' );
  150. @header ( "Location: /login" );
  151. }
  152. }
  153. /**
  154. * 费用首页
  155. */
  156. function saeaBorad() {
  157. Doo::loadModel ( 'receipt' );
  158. $receipt = new receipt ();
  159. Doo::loadModel ( 'verify' );
  160. $verify = new verify ();
  161. Doo::loadModel ( 'L_category' );
  162. $lCategory = new L_category ();
  163. Doo::loadModel ( "role" );
  164. $role = new role ();
  165. Doo::loadModel ( "receiptLog" );
  166. $receiptLog = new receiptLog ();
  167. Doo::loadModel ( 'accountItem' );
  168. $accountItem = new accountItem ();
  169. Doo::loadClass ( 'XDeode' );
  170. $XDeode = new XDeode ( 7 );
  171. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  172. $receiptDetail = $receipt->find ( array (
  173. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  174. 'desc' => 'rid',
  175. 'asArray' => true
  176. ) );
  177. foreach ( $receiptDetail as $key => $value ) {
  178. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  179. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  180. $veList = $verify->getOne ( array (
  181. 'where' => 'vid=' . $value ['verify'],
  182. 'asArray' => true
  183. ) );
  184. $v = json_decode ( $veList ['staff'] );
  185. array_push ( $v [0], $veList ['description'] );
  186. foreach ( $v as $n => $m ) {
  187. if ($m ['1'] == 'ROLE') {
  188. $roleInfo = $role->getOne ( array (
  189. 'where' => 'rid=' . $m [0],
  190. 'asArray' => true
  191. ) );
  192. $v [$n] [1] = $roleInfo ['name'];
  193. }
  194. }
  195. $receiptDetail [$key] ['staff'] = $v;
  196. $category = $lCategory->getOne ( array (
  197. 'where' => 'cid=' . $value ['cid'],
  198. 'asArray' => true
  199. ) );
  200. $receiptDetail [$key] ['category'] = $category ['title'];
  201. }
  202. // print_r($receiptLogList);
  203. Doo::loadModel ( 'RAssist' );
  204. $RAssist = new RAssist ();
  205. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  206. //费用项目
  207. $acItem = $accountItem->find ( array ('asArray' => true) );
  208. $data ['acItem'] = $acItem;
  209. $data ['receiptExtendList'] = $receiptExtendList;
  210. $data ['receiptLogList'] = $receiptLogList;
  211. $data ['receiptDetail'] = $receiptDetail;
  212. $data ['memu'] = "receipt";
  213. $data ['staff'] = $this->staff;
  214. $data ['receiptMemu'] = 'saeaBorad';
  215. $data ['verifyId'] = $this->verifyId;
  216. $data ['executeId'] = $this->executeId;
  217. $this->render ( "/receipt/receiptFee", $data );
  218. }
  219. /**
  220. * 费用报销单-导流入哪个细分类
  221. */
  222. function receiptFeeDiversion(){
  223. $feeType= $this->get_args ( 'feeType' ) ? $this->get_args ( 'feeType' ) : "";
  224. if($feeType==2){
  225. return '/receipt/feeTravel';
  226. }elseif($feeType==3){
  227. return '/receipt/feeInternalTrain';
  228. }else{
  229. return '/receipt/feeAgency';
  230. }
  231. }
  232. /**
  233. * 办事处相关费用
  234. */
  235. function feeAgency(){
  236. Doo::loadModel ( 'L_category' );
  237. $lCategory = new L_category ();
  238. Doo::loadModel ( 'verify' );
  239. $verify = new verify ();
  240. Doo::loadModel ( 'accountItem' );
  241. $accountItem = new accountItem ();
  242. Doo::loadModel ( "role" );
  243. $role = new role ();
  244. $acItem = $accountItem->find ( array (
  245. 'asArray' => true
  246. ) );
  247. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  248. $data ['category'] = $lCategory->find ( array (
  249. 'asArray' => true
  250. ) );
  251. $data ['veList'] = $veList;
  252. $data ['acItem'] = $acItem;
  253. $data ['memu'] = "receipt";
  254. $data ['staff'] = $this->staff;
  255. $data ['receiptMemu'] = 'saeaBorad';
  256. $data ['verifyId'] = $this->verifyId;
  257. $data ['executeId'] = $this->executeId;
  258. $this->render ( "/receipt/feeAgency", $data );
  259. }
  260. /**
  261. * 添加费用报销单页面
  262. */
  263. function saeaCreate() {
  264. Doo::loadModel ( 'accountItem' );
  265. Doo::loadModel ( 'verify' );
  266. Doo::loadModel ( 'receipt' );
  267. Doo::loadModel ( 'L_category' );
  268. $lCategory = new L_category ();
  269. $receipt = new receipt ();
  270. $verify = new verify ();
  271. $accountItem = new accountItem ();
  272. Doo::loadModel ( "role" );
  273. $role = new role ();
  274. $acItem = $accountItem->find ( array (
  275. 'asArray' => true
  276. ) );
  277. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  278. $data ['category'] = $lCategory->find ( array (
  279. 'asArray' => true
  280. ) );
  281. $data ['veList'] = $veList;
  282. $data ['acItem'] = $acItem;
  283. $data ['memu'] = "receipt";
  284. $data ['staff'] = $this->staff;
  285. $data ['receiptMemu'] = 'saeaBorad';
  286. $data ['verifyId'] = $this->verifyId;
  287. $data ['executeId'] = $this->executeId;
  288. $this->render ( "/admin/saea_create", $data );
  289. }
  290. function addReceipt() {
  291. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  292. $agency = $this->get_args ( 'agency' );
  293. $travel = $this->get_args ( 'travel' );
  294. $train = $this->get_args ( 'train' );
  295. $other = $this->get_args ( 'other' );
  296. $inttrain = $this->get_args ( 'inttrain' );
  297. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  298. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  299. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  300. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  301. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  302. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  303. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  304. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  305. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  306. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  307. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  308. header ( 'Content-Type:text/html;charset=utf-8' );
  309. die ( '请填写联行号' );
  310. }
  311. Doo::loadModel ( 'receipt' );
  312. Doo::loadModel ( 'receiptDetail' );
  313. Doo::loadModel ( 'accountItem' );
  314. $accountItem = new accountItem ();
  315. $receipt = new receipt ();
  316. Doo::loadModel ( 'enclosur' );
  317. Doo::loadModel ( 'execute' );
  318. $execute = new execute ();
  319. $executeDetail = $execute->getOne ( array (
  320. 'where' => 'mold="报销单执行人"',
  321. 'asArray' => true
  322. ) );
  323. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  324. // if(!empty($receiptDetail))
  325. // return "/referReceipt/".$receiptDetail['rid'];
  326. $aItem = $accountItem->find ( array (
  327. 'asArray' => true
  328. ) );
  329. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  330. $ag = $tr = $ta = $ot= $it = 0;
  331. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  332. foreach ( $aItem as $key => $value ) {
  333. if ($value ['category'] == $this->AGENCY) {
  334. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  335. array_push ( $accountJson [$this->AGENCY], array (
  336. 'aid' => $value ['aid'],
  337. 'name' => $value ['name'],
  338. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  339. ) );
  340. $sum += $agency [$ag];
  341. $agencySum += $agency [$ag];
  342. }
  343. $ag ++;
  344. }
  345. if ($value ['category'] == $this->TRAVEL) {
  346. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  347. array_push ( $accountJson [$this->TRAVEL], array (
  348. 'aid' => $value ['aid'],
  349. 'name' => $value ['name'],
  350. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  351. ) );
  352. $sum += $travel [$tr];
  353. $travelSum += $travel [$tr];
  354. }
  355. $tr ++;
  356. }
  357. if ($value ['category'] == $this->TRAIN) {
  358. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  359. array_push ( $accountJson [$this->TRAIN], array (
  360. 'aid' => $value ['aid'],
  361. 'name' => $value ['name'],
  362. 'price' => number_format ( $train [$ta], 2, '.', '' )
  363. ) );
  364. $sum += $train [$ta];
  365. $trainSum += $train [$ta];
  366. }
  367. $ta ++;
  368. }
  369. if ($value ['category'] == $this->INTTRAIN) {
  370. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  371. array_push ( $accountJson [$this->INTTRAIN], array (
  372. 'aid' => $value ['aid'],
  373. 'name' => $value ['name'],
  374. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  375. ) );
  376. $sum += $inttrain [$it];
  377. $inttrainSum += $inttrain [$it];
  378. }
  379. $it ++;
  380. }
  381. if ($value ['category'] == $this->OTHER) {
  382. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  383. array_push ( $accountJson [$this->OTHER], array (
  384. 'aid' => $value ['aid'],
  385. 'name' => $value ['name'],
  386. 'price' => number_format ( $other [$ot], 2, '.', '' )
  387. ) );
  388. $sum += $other [$ot];
  389. $otherSum += $other [$ot];
  390. }
  391. $ot ++;
  392. }
  393. }
  394. $accountJson ['cSum'] = array (
  395. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  396. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  397. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  398. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  399. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  400. );
  401. // 报销单
  402. $receipt->accountItem = json_encode ( $accountJson );
  403. $receipt->staff = $this->staff [0] ['sid'];
  404. $receipt->sum = number_format ( $sum, 2, '.', '' );
  405. $receipt->date = date ( "Y-m-d" );
  406. $receipt->cid = $cid;
  407. $receipt->status = 5;
  408. // 修改审批流程加入角色
  409. $receipt->verify = $verify;
  410. $receipt->executeCopy = $executeDetail ['staff'];
  411. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  412. $order = array (
  413. "\r\n",
  414. "\n",
  415. "\r"
  416. );
  417. $replace = '<br/>';
  418. $explanation = str_replace ( $order, $replace, $explanation );
  419. $receipt->explanation = $explanation;
  420. $receipt->remittanceName = $remittanceName;
  421. $receipt->bankName = $bankName;
  422. $receipt->bankNumber = $bankNumber;
  423. $receipt->remittanceBankType = $remittanceBankType;
  424. if ($remittanceBankType == 1)
  425. $receipt->coupletNumber = $coupletNumber;
  426. $rid = $receipt->insert ();
  427. // 附件
  428. if (! empty ( $enclosurName )) {
  429. $enclosurArray = explode ( '-', $enclosurName );
  430. foreach ( $enclosurArray as $value ) {
  431. $enclosur = new enclosur ();
  432. $enclosur->name = $value;
  433. $enclosur->rid = $rid;
  434. $enclosur->insert ();
  435. }
  436. // print_r($enclosurArray);die;
  437. }
  438. // 报销详情
  439. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  440. $receiptDetail = new receiptDetail ();
  441. $receiptDetail->staff = $this->staff [0] ['sid'];
  442. $receiptDetail->item = $value ['name'];
  443. $receiptDetail->itemCategory = $this->AGENCY;
  444. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  445. $receiptDetail->date = date ( "Y-m-d" );
  446. $receiptDetail->cid = $cid;
  447. $receiptDetail->rid = $rid;
  448. $receiptDetail->status = 4;
  449. $receiptDetail->insert ();
  450. }
  451. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  452. $receiptDetail = new receiptDetail ();
  453. $receiptDetail->staff = $this->staff [0] ['sid'];
  454. $receiptDetail->item = $value ['name'];
  455. $receiptDetail->itemCategory = $this->TRAVEL;
  456. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  457. $receiptDetail->date = date ( "Y-m-d" );
  458. $receiptDetail->cid = $cid;
  459. $receiptDetail->rid = $rid;
  460. $receiptDetail->status = 4;
  461. $receiptDetail->insert ();
  462. }
  463. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  464. $receiptDetail = new receiptDetail ();
  465. $receiptDetail->staff = $this->staff [0] ['sid'];
  466. $receiptDetail->item = $value ['name'];
  467. $receiptDetail->itemCategory = $this->TRAIN;
  468. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  469. $receiptDetail->date = date ( "Y-m-d" );
  470. $receiptDetail->cid = $cid;
  471. $receiptDetail->rid = $rid;
  472. $receiptDetail->status = 4;
  473. $receiptDetail->insert ();
  474. }
  475. //内训
  476. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  477. $receiptDetail = new receiptDetail ();
  478. $receiptDetail->staff = $this->staff [0] ['sid'];
  479. $receiptDetail->item = $value ['name'];
  480. $receiptDetail->itemCategory = $this->INTTRAIN;
  481. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  482. $receiptDetail->date = date ( "Y-m-d" );
  483. $receiptDetail->cid = $cid;
  484. $receiptDetail->rid = $rid;
  485. $receiptDetail->status = 4;
  486. $receiptDetail->insert ();
  487. }
  488. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  489. $receiptDetail = new receiptDetail ();
  490. $receiptDetail->staff = $this->staff [0] ['sid'];
  491. $receiptDetail->item = $value ['name'];
  492. $receiptDetail->itemCategory = $this->OTHER;
  493. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  494. $receiptDetail->date = date ( "Y-m-d" );
  495. $receiptDetail->cid = $cid;
  496. $receiptDetail->rid = $rid;
  497. $receiptDetail->status = 4;
  498. $receiptDetail->insert ();
  499. }
  500. return "/saeaBorad";
  501. } else
  502. die ( 'illegal request' );
  503. }
  504. function referReceipt() {
  505. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  506. Doo::loadModel ( 'receipt' );
  507. Doo::loadModel ( 'verify' );
  508. $verify = new verify ();
  509. $receipt = new receipt ();
  510. Doo::loadModel ( 'L_category' );
  511. $lCategory = new L_category ();
  512. Doo::loadModel ( "role" );
  513. $role = new role ();
  514. $receiptDetail = $receipt->find ( array (
  515. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  516. 'asArray' => true
  517. ) );
  518. if (empty ( $receiptDetail ))
  519. return "/addReceipt";
  520. foreach ( $receiptDetail as $key => $value ) {
  521. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  522. $veList = $verify->getOne ( array (
  523. 'where' => 'vid=' . $value ['verify'],
  524. 'asArray' => true
  525. ) );
  526. $v = json_decode ( $veList ['staff'] );
  527. array_push ( $v [0], $veList ['description'] );
  528. foreach ( $v as $n => $m ) {
  529. if ($m ['1'] == 'ROLE') {
  530. $roleInfo = $role->getOne ( array (
  531. 'where' => 'rid=' . $m [0],
  532. 'asArray' => true
  533. ) );
  534. $v [$n] [1] = $roleInfo ['name'];
  535. }
  536. }
  537. $receiptDetail [$key] ['staff'] = $v;
  538. $category = $lCategory->getOne ( array (
  539. 'where' => 'cid=' . $value ['cid'],
  540. 'asArray' => true
  541. ) );
  542. $receiptDetail [$key] ['category'] = $category ['title'];
  543. }
  544. // print_r($receiptDetail);
  545. $data ['receiptDetail'] = $receiptDetail;
  546. $data ['memu'] = "receipt";
  547. $data ['staff'] = $this->staff;
  548. $data ['receiptMemu'] = 'saeaCreate';
  549. $data ['verifyId'] = $this->verifyId;
  550. $data ['executeId'] = $this->executeId;
  551. $this->render ( "/admin/saea_confirm", $data );
  552. }
  553. function editReceipt() {
  554. // edit status 4
  555. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  556. Doo::loadClass ( 'XDeode' );
  557. $XDeode = new XDeode ( 7 );
  558. $rid = $XDeode->decode ( $ridKey );
  559. if (empty ( $rid ))
  560. die ( 'illegal request' );
  561. // echo $rid.'sd';
  562. Doo::loadModel ( 'accountItem' );
  563. Doo::loadModel ( 'verify' );
  564. Doo::loadModel ( 'receipt' );
  565. $receipt = new receipt ();
  566. $verify = new verify ();
  567. $accountItem = new accountItem ();
  568. Doo::loadModel ( 'L_category' );
  569. $lCategory = new L_category ();
  570. Doo::loadModel ( "role" );
  571. $role = new role ();
  572. Doo::loadModel ( 'enclosur' );
  573. $enclosur = new enclosur ();
  574. $receiptDetail = $receipt->getOne ( array (
  575. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  576. 'asArray' => true
  577. ) );
  578. if (empty ( $receiptDetail ))
  579. die ( 'illegal request' );
  580. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  581. $acItem = $accountItem->find ( array (
  582. 'asArray' => true
  583. ) );
  584. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  585. // 配置编辑信息
  586. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  587. foreach ( $acItem as $key => $value ) {
  588. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  589. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  590. $acItem [$key] ['price'] = $v ['price'];
  591. }
  592. }
  593. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  594. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  595. $acItem [$key] ['price'] = $v ['price'];
  596. }
  597. }
  598. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  599. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  600. $acItem [$key] ['price'] = $v ['price'];
  601. }
  602. }
  603. //内训
  604. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  605. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  606. $acItem [$key] ['price'] = $v ['price'];
  607. }
  608. }
  609. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  610. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  611. $acItem [$key] ['price'] = $v ['price'];
  612. }
  613. }
  614. }
  615. $data ['category'] = $lCategory->find ( array (
  616. 'asArray' => true
  617. ) );
  618. $data ['cSum'] = $accountItemList ['cSum'];
  619. $data ['sum'] = $receiptDetail ['sum'];
  620. $data ['enclosurList'] = $enclosurList;
  621. $data ['receiptDetail'] = $receiptDetail;
  622. $data ['veList'] = $veList;
  623. $data ['acItem'] = $acItem;
  624. $data ['memu'] = "receipt";
  625. $data ['staff'] = $this->staff;
  626. $data ['receiptMemu'] = 'saeaBorad';
  627. $data ['verify'] = $receiptDetail ['verify'];
  628. $data ['verifyId'] = $this->verifyId;
  629. $data ['executeId'] = $this->executeId;
  630. $data ['rid'] = $ridKey;
  631. $this->render ( "/admin/saea_edit", $data );
  632. }
  633. function updateReceipt() {
  634. $agency = $this->get_args ( 'agency' );
  635. $travel = $this->get_args ( 'travel' );
  636. $train = $this->get_args ( 'train' );
  637. $other = $this->get_args ( 'other' );
  638. $inttrain = $this->get_args ( 'inttrain' );
  639. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  640. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  641. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  642. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  643. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  644. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  645. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  646. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  647. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  648. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 7 );
  651. $rid = $XDeode->decode ( $ridKey );
  652. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  653. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  654. header ( 'Content-Type:text/html;charset=utf-8' );
  655. die ( '请填写联行号' );
  656. }
  657. Doo::loadModel ( 'receipt' );
  658. Doo::loadModel ( 'receiptDetail' );
  659. Doo::loadModel ( 'accountItem' );
  660. $accountItem = new accountItem ();
  661. $receipt = new receipt ();
  662. Doo::loadModel ( 'enclosur' );
  663. Doo::loadModel ( 'execute' );
  664. $execute = new execute ();
  665. $receiptDetail = $receipt->getOne ( array (
  666. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  667. 'asArray' => true
  668. ) );
  669. if (empty ( $receiptDetail ))
  670. return "/saeaBorad";
  671. if ($receiptDetail ['Rtype'] == 1)
  672. $executeDetail = $execute->getOne ( array (
  673. 'where' => 'mold="借款费用执行人"',
  674. 'asArray' => true
  675. ) );
  676. else
  677. $executeDetail = $execute->getOne ( array (
  678. 'where' => 'mold="报销单执行人"',
  679. 'asArray' => true
  680. ) );
  681. $aItem = $accountItem->find ( array (
  682. 'asArray' => true
  683. ) );
  684. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  685. $ag = $tr = $ta = $ot = $it = 0 ;
  686. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  687. foreach ( $aItem as $key => $value ) {
  688. if ($value ['category'] == $this->AGENCY) {
  689. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  690. array_push ( $accountJson [$this->AGENCY], array (
  691. 'aid' => $value ['aid'],
  692. 'name' => $value ['name'],
  693. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  694. ) );
  695. $sum += $agency [$ag];
  696. $agencySum += $agency [$ag];
  697. }
  698. $ag ++;
  699. }
  700. if ($value ['category'] == $this->TRAVEL) {
  701. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  702. array_push ( $accountJson [$this->TRAVEL], array (
  703. 'aid' => $value ['aid'],
  704. 'name' => $value ['name'],
  705. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  706. ) );
  707. $sum += $travel [$tr];
  708. $travelSum += $travel [$tr];
  709. }
  710. $tr ++;
  711. }
  712. if ($value ['category'] == $this->TRAIN) {
  713. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  714. array_push ( $accountJson [$this->TRAIN], array (
  715. 'aid' => $value ['aid'],
  716. 'name' => $value ['name'],
  717. 'price' => number_format ( $train [$ta], 2, '.', '' )
  718. ) );
  719. $sum += $train [$ta];
  720. $trainSum += $train [$ta];
  721. }
  722. $ta ++;
  723. }
  724. if ($value ['category'] == $this->INTTRAIN) {
  725. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  726. array_push ( $accountJson [$this->INTTRAIN], array (
  727. 'aid' => $value ['aid'],
  728. 'name' => $value ['name'],
  729. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  730. ) );
  731. $sum += $inttrain [$it];
  732. $inttrainSum += $inttrain [$it];
  733. }
  734. $it ++;
  735. }
  736. if ($value ['category'] == $this->OTHER) {
  737. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  738. array_push ( $accountJson [$this->OTHER], array (
  739. 'aid' => $value ['aid'],
  740. 'name' => $value ['name'],
  741. 'price' => number_format ( $other [$ot], 2, '.', '' )
  742. ) );
  743. $sum += $other [$ot];
  744. $otherSum += $other [$ot];
  745. }
  746. $ot ++;
  747. }
  748. }
  749. $accountJson ['cSum'] = array (
  750. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  751. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  752. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  753. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  754. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  755. );
  756. // 报销单
  757. $rid = $receipt->rid = $receiptDetail ['rid'];
  758. $receipt->accountItem = json_encode ( $accountJson );
  759. $receipt->staff = $this->staff [0] ['sid'];
  760. $receipt->sum = number_format ( $sum, 2, '.', '' );
  761. $receipt->date = date ( "Y-m-d" );
  762. $receipt->cid = $cid;
  763. if (($receiptDetail ['status'] != 4)) {
  764. if ($receiptDetail ['Rtype'] == 1)
  765. $receipt->status = 7;
  766. else
  767. $receipt->status = 5;
  768. }
  769. if ($receiptDetail != 4 && ! empty ( $verify ))
  770. $receipt->verify = $verify;
  771. $receipt->executeCopy = $executeDetail ['staff'];
  772. $order = array (
  773. "\r\n",
  774. "\n",
  775. "\r"
  776. );
  777. $replace = '<br/>';
  778. $explanation = str_replace ( $order, $replace, $explanation );
  779. $receipt->explanation = $explanation;
  780. $receipt->remittanceName = $remittanceName;
  781. $receipt->bankName = $bankName;
  782. $receipt->bankNumber = $bankNumber;
  783. $receipt->remittanceBankType = $remittanceBankType;
  784. if ($remittanceBankType == 1)
  785. $receipt->coupletNumber = $coupletNumber;
  786. $receipt->update ();
  787. $receiptDetail = new receiptDetail ();
  788. $receiptDetail->delete ( array (
  789. 'where' => 'rid=' . $rid
  790. ) );
  791. // 报销详情
  792. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  793. $receiptDetail = new receiptDetail ();
  794. $receiptDetail->staff = $this->staff [0] ['sid'];
  795. $receiptDetail->item = $value ['name'];
  796. $receiptDetail->itemCategory = $this->AGENCY;
  797. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  798. $receiptDetail->date = date ( "Y-m-d" );
  799. $receiptDetail->cid = $cid;
  800. $receiptDetail->rid = $rid;
  801. $receiptDetail->status = 4;
  802. $receiptDetail->insert ();
  803. }
  804. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  805. $receiptDetail = new receiptDetail ();
  806. $receiptDetail->staff = $this->staff [0] ['sid'];
  807. $receiptDetail->item = $value ['name'];
  808. $receiptDetail->itemCategory = $this->TRAVEL;
  809. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  810. $receiptDetail->date = date ( "Y-m-d" );
  811. $receiptDetail->cid = $cid;
  812. $receiptDetail->rid = $rid;
  813. $receiptDetail->status = 4;
  814. $receiptDetail->insert ();
  815. }
  816. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  817. $receiptDetail = new receiptDetail ();
  818. $receiptDetail->staff = $this->staff [0] ['sid'];
  819. $receiptDetail->item = $value ['name'];
  820. $receiptDetail->itemCategory = $this->TRAIN;
  821. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  822. $receiptDetail->date = date ( "Y-m-d" );
  823. $receiptDetail->cid = $cid;
  824. $receiptDetail->rid = $rid;
  825. $receiptDetail->status = 4;
  826. $receiptDetail->insert ();
  827. }
  828. //内训
  829. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  830. $receiptDetail = new receiptDetail ();
  831. $receiptDetail->staff = $this->staff [0] ['sid'];
  832. $receiptDetail->item = $value ['name'];
  833. $receiptDetail->itemCategory = $this->INTTRAIN;
  834. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  835. $receiptDetail->date = date ( "Y-m-d" );
  836. $receiptDetail->cid = $cid;
  837. $receiptDetail->rid = $rid;
  838. $receiptDetail->status = 4;
  839. $receiptDetail->insert ();
  840. }
  841. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  842. $receiptDetail = new receiptDetail ();
  843. $receiptDetail->staff = $this->staff [0] ['sid'];
  844. $receiptDetail->item = $value ['name'];
  845. $receiptDetail->itemCategory = $this->OTHER;
  846. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  847. $receiptDetail->date = date ( "Y-m-d" );
  848. $receiptDetail->cid = $cid;
  849. $receiptDetail->rid = $rid;
  850. $receiptDetail->status = 4;
  851. $receiptDetail->insert ();
  852. }
  853. // 附件
  854. if (! empty ( $enclosurName )) {
  855. $enclosurArray = explode ( '-', $enclosurName );
  856. foreach ( $enclosurArray as $value ) {
  857. $enclosur = new enclosur ();
  858. $enclosur->name = $value;
  859. $enclosur->rid = $rid;
  860. $enclosur->insert ();
  861. }
  862. }
  863. // return "/referReceipt/".$rid;
  864. }
  865. return "/saeaBorad";
  866. }
  867. function remitAdd() {
  868. Doo::loadModel ( 'accountItem' );
  869. Doo::loadModel ( 'verify' );
  870. Doo::loadModel ( 'receipt' );
  871. Doo::loadModel ( 'L_category' );
  872. $lCategory = new L_category ();
  873. $receipt = new receipt ();
  874. $verify = new verify ();
  875. $accountItem = new accountItem ();
  876. Doo::loadModel ( "role" );
  877. $role = new role ();
  878. $acItem = $accountItem->find ( array (
  879. 'asArray' => true
  880. ) );
  881. $veList = $verify->getVerifyBySubordinate('REMIT');
  882. $data ['category'] = $lCategory->find ( array (
  883. 'asArray' => true
  884. ) );
  885. $data ['veList'] = $veList;
  886. $data ['acItem'] = $acItem;
  887. $data ['memu'] = "receipt";
  888. $data ['staff'] = $this->staff;
  889. $data ['receiptMemu'] = 'saeaBorad';
  890. $data ['verifyId'] = $this->verifyId;
  891. $data ['executeId'] = $this->executeId;
  892. $this->render ( "/admin/remitAdd", $data );
  893. }
  894. function remitAddDo() {
  895. $agency = $this->get_args ( 'agency' );
  896. $travel = $this->get_args ( 'travel' );
  897. $train = $this->get_args ( 'train' );
  898. $other = $this->get_args ( 'other' );
  899. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  900. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  901. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  902. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  903. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  904. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  905. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  906. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  907. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  908. // print_r($agency);die;
  909. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  910. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  911. header ( 'Content-Type:text/html;charset=utf-8' );
  912. die ( '请填写联行号' );
  913. }
  914. Doo::loadModel ( 'receipt' );
  915. Doo::loadModel ( 'receiptDetail' );
  916. Doo::loadModel ( 'accountItem' );
  917. $accountItem = new accountItem ();
  918. $receipt = new receipt ();
  919. Doo::loadModel ( 'enclosur' );
  920. Doo::loadModel ( 'execute' );
  921. $execute = new execute ();
  922. $executeDetail = $execute->getOne ( array (
  923. 'where' => 'mold="对公汇款执行人"',
  924. 'asArray' => true
  925. ) );
  926. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  927. $aItem = $accountItem->find ( array (
  928. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  929. 'asArray' => true
  930. ) );
  931. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  932. $ag = $tr = $ta = $ot = 0;
  933. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  934. print_r($aItem);
  935. foreach ( $aItem as $key => $value ) {
  936. if ($value ['category'] == $this->AGENCY) {
  937. if (isset ( $agency [$ag] )) {
  938. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  939. array_push ( $accountJson [$this->AGENCY], array (
  940. 'aid' => $value ['aid'],
  941. 'name' => $value ['name'],
  942. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  943. ) );
  944. $sum += $agency [$ag];
  945. $agencySum += $agency [$ag];
  946. }
  947. }
  948. $ag ++;
  949. }
  950. }
  951. $accountJson ['cSum'] = array (
  952. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  953. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  954. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  955. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  956. );
  957. //die;
  958. // 报销单
  959. $receipt->accountItem = json_encode ( $accountJson );
  960. $receipt->staff = $this->staff [0] ['sid'];
  961. $receipt->sum = number_format ( $sum, 2, '.', '' );
  962. $receipt->date = date ( "Y-m-d" );
  963. $receipt->cid = $cid;
  964. $receipt->status = 5;
  965. $receipt->Rtype = 2;
  966. // 修改审批流程加入角色
  967. $receipt->verify = $verify;
  968. $receipt->executeCopy = $executeDetail ['staff'];
  969. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  970. $order = array (
  971. "\r\n",
  972. "\n",
  973. "\r"
  974. );
  975. $replace = '<br/>';
  976. $explanation = str_replace ( $order, $replace, $explanation );
  977. $receipt->explanation = $explanation;
  978. $receipt->remittanceName = $remittanceName;
  979. $receipt->bankName = $bankName;
  980. $receipt->bankNumber = $bankNumber;
  981. $receipt->remittanceBankType = $remittanceBankType;
  982. if ($remittanceBankType == 1)
  983. $receipt->coupletNumber = $coupletNumber;
  984. $rid = $receipt->insert ();
  985. // 附件
  986. if (! empty ( $enclosurName )) {
  987. $enclosurArray = explode ( '-', $enclosurName );
  988. foreach ( $enclosurArray as $value ) {
  989. $enclosur = new enclosur ();
  990. $enclosur->name = $value;
  991. $enclosur->rid = $rid;
  992. $enclosur->insert ();
  993. }
  994. // print_r($enclosurArray);die;
  995. }
  996. // 报销详情
  997. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  998. $receiptDetail = new receiptDetail ();
  999. $receiptDetail->staff = $this->staff [0] ['sid'];
  1000. $receiptDetail->item = $value ['name'];
  1001. $receiptDetail->itemCategory = $this->AGENCY;
  1002. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1003. $receiptDetail->date = date ( "Y-m-d" );
  1004. $receiptDetail->cid = $cid;
  1005. $receiptDetail->rid = $rid;
  1006. $receiptDetail->status = 4;
  1007. $receiptDetail->insert ();
  1008. }
  1009. return "/saeaBorad";
  1010. } else
  1011. die ( 'illegal request' );
  1012. }
  1013. function remitEdit() {
  1014. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1015. Doo::loadClass ( 'XDeode' );
  1016. $XDeode = new XDeode ( 7 );
  1017. $rid = $XDeode->decode ( $ridKey );
  1018. if (! is_numeric ( $rid ))
  1019. die ( 'illegal request' );
  1020. Doo::loadModel ( 'accountItem' );
  1021. Doo::loadModel ( 'verify' );
  1022. Doo::loadModel ( 'receipt' );
  1023. $receipt = new receipt ();
  1024. $verify = new verify ();
  1025. $accountItem = new accountItem ();
  1026. Doo::loadModel ( 'L_category' );
  1027. $lCategory = new L_category ();
  1028. Doo::loadModel ( "role" );
  1029. $role = new role ();
  1030. Doo::loadModel ( 'enclosur' );
  1031. $enclosur = new enclosur ();
  1032. $receiptDetail = $receipt->getOne ( array (
  1033. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  1034. 'asArray' => true
  1035. ) );
  1036. if (empty ( $receiptDetail ))
  1037. return "/saeaCreate";
  1038. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  1039. $acItem = $accountItem->find ( array (
  1040. 'asArray' => true
  1041. ) );
  1042. $veList = $verify->getVerifyBySubordinate('REMIT');
  1043. // 配置编辑信息
  1044. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1045. foreach ( $acItem as $key => $value ) {
  1046. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1047. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1048. $acItem [$key] ['price'] = $v ['price'];
  1049. }
  1050. }
  1051. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1052. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1053. $acItem [$key] ['price'] = $v ['price'];
  1054. }
  1055. }
  1056. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1057. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1058. $acItem [$key] ['price'] = $v ['price'];
  1059. }
  1060. }
  1061. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1062. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1063. $acItem [$key] ['price'] = $v ['price'];
  1064. }
  1065. }
  1066. }
  1067. $data ['category'] = $lCategory->find ( array (
  1068. 'asArray' => true
  1069. ) );
  1070. $data ['enclosurList'] = $enclosurList;
  1071. $data ['cSum'] = $accountItemList ['cSum'];
  1072. $data ['sum'] = $receiptDetail ['sum'];
  1073. $data ['receiptDetail'] = $receiptDetail;
  1074. $data ['veList'] = $veList;
  1075. $data ['acItem'] = $acItem;
  1076. $data ['memu'] = "receipt";
  1077. $data ['staff'] = $this->staff;
  1078. $data ['receiptMemu'] = 'saeaBorad';
  1079. $data ['verify'] = $receiptDetail ['verify'];
  1080. $data ['verifyId'] = $this->verifyId;
  1081. $data ['executeId'] = $this->executeId;
  1082. $data ['rid'] = $rid;
  1083. $data ['ridKey'] = $ridKey;
  1084. $this->render ( "/admin/remitEdit", $data );
  1085. }
  1086. function remitEdiDo() {
  1087. $agency = $this->get_args ( 'agency' );
  1088. $travel = $this->get_args ( 'travel' );
  1089. $train = $this->get_args ( 'train' );
  1090. $other = $this->get_args ( 'other' );
  1091. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1092. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1093. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1094. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1095. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1096. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1097. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1098. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1099. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1100. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1101. Doo::loadClass ( 'XDeode' );
  1102. $XDeode = new XDeode ( 7 );
  1103. $rid = $XDeode->decode ( $ridKey );
  1104. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1105. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1106. header ( 'Content-Type:text/html;charset=utf-8' );
  1107. die ( '请填写联行号' );
  1108. }
  1109. Doo::loadModel ( 'receipt' );
  1110. Doo::loadModel ( 'receiptDetail' );
  1111. Doo::loadModel ( 'accountItem' );
  1112. $accountItem = new accountItem ();
  1113. $receipt = new receipt ();
  1114. Doo::loadModel ( 'enclosur' );
  1115. $enclosur = new enclosur ();
  1116. Doo::loadModel ( 'execute' );
  1117. $execute = new execute ();
  1118. $executeDetail = $execute->getOne ( array (
  1119. 'where' => 'mold="对公汇款执行人"',
  1120. 'asArray' => true
  1121. ) );
  1122. $receiptDetail = $receipt->getOne ( array (
  1123. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  1124. 'asArray' => true
  1125. ) );
  1126. if (empty ( $receiptDetail ))
  1127. return "/saeaBorad";
  1128. $aItem = $accountItem->find ( array (
  1129. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1130. 'asArray' => true
  1131. ) );
  1132. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1133. $ag = $tr = $ta = $ot = 0;
  1134. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1135. foreach ( $aItem as $key => $value ) {
  1136. if ($value ['category'] == $this->AGENCY) {
  1137. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1138. array_push ( $accountJson [$this->AGENCY], array (
  1139. 'aid' => $value ['aid'],
  1140. 'name' => $value ['name'],
  1141. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1142. ) );
  1143. $sum += $agency [$ag];
  1144. $agencySum += $agency [$ag];
  1145. }
  1146. $ag ++;
  1147. }
  1148. }
  1149. $accountJson ['cSum'] = array (
  1150. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1151. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1152. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1153. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1154. );
  1155. // 报销单
  1156. $rid = $receipt->rid = $receiptDetail ['rid'];
  1157. $receipt->accountItem = json_encode ( $accountJson );
  1158. $receipt->staff = $this->staff [0] ['sid'];
  1159. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1160. $receipt->date = date ( "Y-m-d" );
  1161. $receipt->cid = $cid;
  1162. if ($receiptDetail ['Rtype'] == 1)
  1163. $receipt->status = 7;
  1164. else
  1165. $receipt->status = 5;
  1166. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  1167. $receipt->verify = $verify;
  1168. $receipt->executeCopy = $executeDetail ['staff'];
  1169. $order = array (
  1170. "\r\n",
  1171. "\n",
  1172. "\r"
  1173. );
  1174. $replace = '<br/>';
  1175. $explanation = str_replace ( $order, $replace, $explanation );
  1176. $receipt->explanation = $explanation;
  1177. $receipt->remittanceName = $remittanceName;
  1178. $receipt->bankName = $bankName;
  1179. $receipt->bankNumber = $bankNumber;
  1180. $receipt->remittanceBankType = $remittanceBankType;
  1181. if ($remittanceBankType == 1)
  1182. $receipt->coupletNumber = $coupletNumber;
  1183. $receipt->update ();
  1184. $receiptDetail = new receiptDetail ();
  1185. $receiptDetail->delete ( array (
  1186. 'where' => 'rid=' . $rid
  1187. ) );
  1188. // 报销详情
  1189. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1190. $receiptDetail = new receiptDetail ();
  1191. $receiptDetail->staff = $this->staff [0] ['sid'];
  1192. $receiptDetail->item = $value ['name'];
  1193. $receiptDetail->itemCategory = $this->AGENCY;
  1194. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1195. $receiptDetail->date = date ( "Y-m-d" );
  1196. $receiptDetail->cid = $cid;
  1197. $receiptDetail->rid = $rid;
  1198. $receiptDetail->status = 4;
  1199. $receiptDetail->insert ();
  1200. }
  1201. // 附件
  1202. if (! empty ( $enclosurName )) {
  1203. $enclosurArray = explode ( '-', $enclosurName );
  1204. foreach ( $enclosurArray as $value ) {
  1205. $enclosur = new enclosur ();
  1206. $enclosur->name = $value;
  1207. $enclosur->rid = $rid;
  1208. $enclosur->insert ();
  1209. }
  1210. }
  1211. }
  1212. return "/saeaBorad";
  1213. }
  1214. function remitApproval() {
  1215. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1216. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  1217. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  1218. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  1219. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1220. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  1221. if (empty ( $status ))
  1222. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  1223. $vidList = array ();
  1224. $button = 0;
  1225. Doo::loadModel ( 'verify' );
  1226. Doo::loadModel ( 'receipt' );
  1227. Doo::loadModel ( 'staff' );
  1228. $staff = new staff ();
  1229. $receipt = new receipt ();
  1230. $verify = new verify ();
  1231. Doo::loadModel ( 'L_category' );
  1232. $Lcategory = new L_category ();
  1233. Doo::loadModel ( 'enclosur' );
  1234. $enclosur = new enclosur ();
  1235. // user verify ID
  1236. $verifyDetail = $verify->find ( array (
  1237. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  1238. 'asArray' => true
  1239. ) );
  1240. foreach ( $verifyDetail as $key => $value ) {
  1241. array_push ( $vidList, $value ['vid'] );
  1242. }
  1243. $vid = implode ( ",", $vidList );
  1244. if (empty ( $verifyDetail ))
  1245. $vid = 0;
  1246. $categoryList = $Lcategory->find ( array (
  1247. 'asArray' => true
  1248. ) );
  1249. $staffList = $staff->find ( array (
  1250. 'where' => 'cid=' . $cid,
  1251. 'asArray' => true
  1252. ) );
  1253. $ap = "";
  1254. if ($status == 4) {
  1255. $ap = 4;
  1256. $status = 2;
  1257. }
  1258. // get Receipt By verifyID status 2
  1259. $receiptList = $receipt->find ( array (
  1260. 'where' => 'rid =' . $rid . ' and status=2',
  1261. 'desc' => 'rid',
  1262. 'asArray' => true
  1263. ) );
  1264. if (empty ( $receiptList )) {
  1265. die ( 'illegal request' );
  1266. }
  1267. $Locate = 0;
  1268. $roleId = 0;
  1269. if ($ap == 4)
  1270. $status = 4;
  1271. foreach ( $receiptList as $key => $value ) {
  1272. $receiptList [$key] ['Locate'] = $Locate;
  1273. $Locate ++;
  1274. $receiptList [$key] ['reviseDetail'] = array ();
  1275. if (! empty ( $value ['reviseDetail'] ))
  1276. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1277. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1278. $categoryDetil = $Lcategory->getOne ( array (
  1279. 'where' => 'cid=' . $value ['cid'],
  1280. 'asArray' => true
  1281. ) );
  1282. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1283. // 检测编辑状态
  1284. $verifyList = $verify->getOne ( array (
  1285. 'where' => 'vid=' . $value ['verify'],
  1286. 'asArray' => true
  1287. ) );
  1288. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1289. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1290. Doo::loadModel ( 'role' );
  1291. $role = new role ();
  1292. // print_r($verifyList);
  1293. $flag = true;
  1294. $roleKey = 0;
  1295. $endStaffArray = array ();
  1296. $roleArrayCopy = array ();
  1297. foreach ( $verifyList as $k => $v ) {
  1298. // init verifyStaff
  1299. if ($v [1] == 'ROLE') {
  1300. if (! empty ( $verifyStaff )) {
  1301. $endStaffArray = end ( $verifyStaff );
  1302. if ($v [0] == $endStaffArray ['nextStaff']) {
  1303. $roleId = $v [0];
  1304. }
  1305. }
  1306. $roleVerify = json_decode ( $v [3], true );
  1307. $roleKey = $k;
  1308. $roleArray = array ();
  1309. $rolename = $role->getOne ( array (
  1310. 'where' => 'rid=' . $v [0],
  1311. 'asArray' => true
  1312. ) );
  1313. foreach ( $roleVerify as $o => $p ) {
  1314. $staffID = explode ( '_', $p );
  1315. $staffInfo = $staff->getOne ( array (
  1316. 'where' => 'sid=' . $staffID [0],
  1317. 'asArray' => true
  1318. ) );
  1319. // print_r($staffID);
  1320. $exp = array (
  1321. 0 => $staffInfo ['sid'],
  1322. 1 => $staffID [1],
  1323. 2 => $staffInfo ['avatar'],
  1324. 'date' => '',
  1325. 'date' => '',
  1326. 'opinion' => '',
  1327. 'status' => '',
  1328. 'rolename' => $rolename ['name']
  1329. );
  1330. array_push ( $roleArray, $exp );
  1331. }
  1332. $roleArrayCopy [$v [0]] = $roleArray;
  1333. // $verifyList[$k]['roleArray']=$roleArray;
  1334. }
  1335. // print_r($roleArray);
  1336. $verifyList [$k] ['date'] = "";
  1337. $verifyList [$k] ['opinion'] = "";
  1338. $verifyList [$k] ['status'] = "";
  1339. if (empty ( $verifyStaff )) {
  1340. $verifyList [$k] ['date'] = "";
  1341. $verifyList [$k] ['opinion'] = "";
  1342. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1343. $verifyList [$k] ['status'] = 4;
  1344. $button = 4;
  1345. $flag = false;
  1346. }
  1347. } else {
  1348. foreach ( $verifyStaff as $m => $u ) {
  1349. if ($v [0] == $m) {
  1350. $verifyList [$k] ['date'] = $u ['date'];
  1351. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1352. $verifyList [$k] ['status'] = $u ['status'];
  1353. $flag = false;
  1354. break;
  1355. }
  1356. }
  1357. $endStaffArray = end ( $verifyStaff );
  1358. if (isset ( $endStaffArray ['ROLE'] )) {
  1359. } else {
  1360. $endKey = key ( $verifyStaff );
  1361. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  1362. $button = 4;
  1363. $verifyList [$k] ['status'] = 4;
  1364. }
  1365. }
  1366. }
  1367. }
  1368. $rolename ['name'] = '';
  1369. if (! empty ( $roleId )) {
  1370. Doo::loadModel ( 'role' );
  1371. $role = new role ();
  1372. $rolename = $role->getOne ( array (
  1373. 'where' => 'rid=' . $roleId,
  1374. 'asArray' => true
  1375. ) );
  1376. }
  1377. if (! empty ( $verifyStaff ))
  1378. $endStaffArray = end ( $verifyStaff );
  1379. $KOP = false;
  1380. foreach ( $roleArrayCopy as $P => $A ) {
  1381. foreach ( $A as $MKI => $AVL ) {
  1382. if (! empty ( $verifyStaff )) {
  1383. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1384. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1385. $button = 4;
  1386. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1387. }
  1388. foreach ( $verifyStaff as $m => $u ) {
  1389. $AVLFK = $AVL [0] . '_R';
  1390. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1391. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1392. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1393. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1394. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1395. break;
  1396. }
  1397. }
  1398. } else {
  1399. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1400. $button = 4;
  1401. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1402. }
  1403. }
  1404. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1405. $KOP = true;
  1406. }
  1407. }
  1408. foreach ( $roleArrayCopy as $k => $v ) {
  1409. foreach ( $verifyList as $m => $n ) {
  1410. if ($n [0] == $k) {
  1411. array_splice ( $verifyList, $m, 1, $v );
  1412. }
  1413. }
  1414. }
  1415. $receiptList [$key] ['verifyList'] = $verifyList;
  1416. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1417. 'where' => 'sid=' . $value ['staff'],
  1418. 'asArray' => true
  1419. ) );
  1420. $receiptList [$key] ['button'] = $button;
  1421. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1422. }
  1423. $mothHtml = "";
  1424. for($i = 1; $i <= 12; $i ++) {
  1425. if ($month == $i)
  1426. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1427. else
  1428. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1429. }
  1430. // 获取审批日志
  1431. Doo::loadModel ( 'receiptLog' );
  1432. $receiptLog = new receiptLog ();
  1433. $rlList = array ();
  1434. $rlInfo = $receiptLog->getOne ( array (
  1435. 'where' => 'rid=' . $rid . ' and status=4',
  1436. 'asArray' => true
  1437. ) );
  1438. $tijdate = $receiptLog->getOne ( array (
  1439. 'where' => 'rid=' . $rid . ' and status=2',
  1440. 'asc' => 'rlid',
  1441. 'asArray' => true
  1442. ) );
  1443. if (! empty ( $rlInfo )) {
  1444. $rlList = $receiptLog->find ( array (
  1445. 'where' => 'rid=' . $rid,
  1446. 'asc' => 'rlid',
  1447. 'asArray' => true
  1448. ) );
  1449. }
  1450. $receiptList [0] ['rlList'] = $rlList;
  1451. $enclosurList = $enclosur->find ( array (
  1452. 'where' => 'rid=' . $rid,
  1453. 'asArray' => true
  1454. ) );
  1455. $enclosurHtml = '';
  1456. foreach ( $enclosurList as $value ) {
  1457. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  1458. }
  1459. // print_r($receiptList);
  1460. $data ['enclosurHtml'] = $enclosurHtml;
  1461. $data ['rolename'] = $rolename ['name'];
  1462. $data ['datetij'] = $tijdate ['date'];
  1463. $data ['mothHtml'] = $mothHtml;
  1464. $data ['rid'] = $rid;
  1465. $data ['receiptList'] = $receiptList;
  1466. $data ['receiptApprovalCount'] = count ( $receiptList );
  1467. $data ['status'] = $status;
  1468. $data ['year'] = $year;
  1469. $data ['categoryList'] = $categoryList;
  1470. $data ['staffList'] = $staffList;
  1471. $data ['cid'] = $cid;
  1472. $data ['sid'] = $sid;
  1473. $data ['ap'] = $ap;
  1474. $data ['memu'] = "receipt";
  1475. $data ['staff'] = $this->staff;
  1476. $data ['receiptMemu'] = 'approvalExpenses';
  1477. $data ['verifyId'] = $this->verifyId;
  1478. $data ['executeId'] = $this->executeId;
  1479. $this->render ( "/admin/remitApproval", $data );
  1480. }
  1481. function saeaLoanAdd() {
  1482. Doo::loadModel ( 'verify' );
  1483. $verify = new verify ();
  1484. Doo::loadModel ( "role" );
  1485. $role = new role ();
  1486. Doo::loadModel ( 'L_category' );
  1487. $lCategory = new L_category ();
  1488. $veList = $verify->getVerifyBySubordinate('LOAN');
  1489. $data ['category'] = $lCategory->find ( array (
  1490. 'asArray' => true
  1491. ) );
  1492. $data ['veList'] = $veList;
  1493. $data ['memu'] = "receipt";
  1494. $data ['staff'] = $this->staff;
  1495. $data ['receiptMemu'] = 'saeaBorad';
  1496. $data ['verifyId'] = $this->verifyId;
  1497. $data ['executeId'] = $this->executeId;
  1498. $this->render ( "/admin/saeaLoanAdd", $data );
  1499. }
  1500. function saeaLoanAddDo() {
  1501. $agency = $this->get_args ( 'agency' );
  1502. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1503. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1504. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1505. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1506. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1507. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1508. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1509. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1510. // die;
  1511. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1512. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1513. header ( 'Content-Type:text/html;charset=utf-8' );
  1514. die ( '请填写联行号' );
  1515. }
  1516. Doo::loadModel ( 'receipt' );
  1517. Doo::loadModel ( 'receiptDetail' );
  1518. Doo::loadModel ( 'accountItem' );
  1519. $accountItem = new accountItem ();
  1520. $receipt = new receipt ();
  1521. Doo::loadModel ( 'loanReceipt' );
  1522. $loanReceipt = new loanReceipt ();
  1523. Doo::loadModel ( 'execute' );
  1524. $execute = new execute ();
  1525. Doo::loadModel ( 'enclosur' );
  1526. $executeDetail = $execute->getOne ( array (
  1527. 'where' => 'mold="借款执行人"',
  1528. 'asArray' => true
  1529. ) );
  1530. $aItem = $accountItem->find ( array (
  1531. 'asArray' => true
  1532. ) );
  1533. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1534. $ag = $tr = $ta = $ot = 0;
  1535. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1536. array_push ( $accountJson ['借款费用'], array (
  1537. 'aid' => 0,
  1538. 'name' => '申请金额',
  1539. 'price' => number_format ( $agency, 2, '.', '' )
  1540. ) );
  1541. $sum += $agency;
  1542. $agencySum += $agency;
  1543. $accountJson ['cSum'] = array (
  1544. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1545. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1546. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1547. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1548. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1549. );
  1550. // 借款数据备份
  1551. $loanReceipt->loanItem = json_encode ( $accountJson );
  1552. $loanReceipt->staff = $this->staff [0] ['sid'];
  1553. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1554. $loanReceipt->date = date ( "Y-m-d" );
  1555. $loanReceipt->cid = $cid;
  1556. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1557. $loanReceipt->status = 5;
  1558. $loanReceipt->Rtype = 1;
  1559. $loanReceipt->verify = $verify;
  1560. $receipt->receiptOrder = $receipt->receiptOrder;
  1561. // 添加HTML换行符
  1562. // var_dump($explanation);
  1563. $order = array (
  1564. "\r\n",
  1565. "\n",
  1566. "\r"
  1567. );
  1568. $replace = '<br/>';
  1569. $explanation = str_replace ( $order, $replace, $explanation );
  1570. // $explanation=str_replace('\r',"<br/>",$explanation);
  1571. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  1572. $loanReceipt->explanation = $explanation;
  1573. $loanRid = $loanReceipt->insert ();
  1574. // 报销单
  1575. $receipt->loanItem = json_encode ( $accountJson );
  1576. $receipt->staff = $this->staff [0] ['sid'];
  1577. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1578. $receipt->date = date ( "Y-m-d" );
  1579. $receipt->cid = $cid;
  1580. // 特殊状态
  1581. $receipt->status = 5;
  1582. $receipt->Rtype = 1;
  1583. $receipt->loanRid = $loanRid;
  1584. // 修改审批流程加入角色
  1585. $receipt->verify = $verify;
  1586. $receipt->executeCopy = $executeDetail ['staff'];
  1587. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  1588. $receipt->explanation = $explanation;
  1589. $receipt->remittanceName = $remittanceName;
  1590. $receipt->bankName = $bankName;
  1591. $receipt->bankNumber = $bankNumber;
  1592. $receipt->remittanceBankType = $remittanceBankType;
  1593. if ($remittanceBankType == 1)
  1594. $receipt->coupletNumber = $coupletNumber;
  1595. $rid = $receipt->insert ();
  1596. return "/saeaBorad";
  1597. } else
  1598. die ( 'illegal request' );
  1599. }
  1600. function saeaLoanEdi() {
  1601. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1602. Doo::loadClass ( 'XDeode' );
  1603. $XDeode = new XDeode ( 7 );
  1604. $rid = $XDeode->decode ( $ridKey );
  1605. if (! is_numeric ( $rid ))
  1606. die ( 'illegal request' );
  1607. Doo::loadModel ( 'verify' );
  1608. $verify = new verify ();
  1609. Doo::loadModel ( "role" );
  1610. $role = new role ();
  1611. Doo::loadModel ( 'L_category' );
  1612. $lCategory = new L_category ();
  1613. Doo::loadModel ( 'receipt' );
  1614. $receipt = new receipt ();
  1615. $receiptInfo = $receipt->getOne ( array (
  1616. 'where' => 'rid=' . $rid,
  1617. 'asArray' => true
  1618. ) );
  1619. $veList = $verify->find ( array (
  1620. 'where'=>'subordinate like "%LOAN%"',
  1621. 'asArray' => true
  1622. ) );
  1623. foreach ( $veList as $key => $value ) {
  1624. $v = json_decode ( $value ['staff'] );
  1625. $list = array ();
  1626. foreach ( $v as $n => $m ) {
  1627. if ($m ['1'] == 'ROLE') {
  1628. $roleInfo = $role->getOne ( array (
  1629. 'where' => 'rid=' . $m [0],
  1630. 'asArray' => true
  1631. ) );
  1632. $v [$n] [1] = $roleInfo ['name'];
  1633. array_push ( $list, $roleInfo ['name'] );
  1634. } else {
  1635. array_push ( $list, $v [$n] [1] );
  1636. }
  1637. }
  1638. $veList [$key] ['staff'] = implode ( '>', $list );
  1639. }
  1640. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1641. // print_r($receiptInfo);
  1642. $data ['receiptInfo'] = $receiptInfo;
  1643. $data ['category'] = $lCategory->find ( array (
  1644. 'asArray' => true
  1645. ) );
  1646. $data ['veList'] = $veList;
  1647. $data ['ridKey'] = $ridKey;
  1648. $data ['memu'] = "receipt";
  1649. $data ['staff'] = $this->staff;
  1650. $data ['receiptMemu'] = 'saeaBorad';
  1651. $data ['verifyId'] = $this->verifyId;
  1652. $data ['executeId'] = $this->executeId;
  1653. $this->render ( "/admin/saeaLoanEdi", $data );
  1654. }
  1655. function saeaLoanEdiDo() {
  1656. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1657. $agency = $this->get_args ( 'agency' );
  1658. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1659. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1660. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1661. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1662. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1663. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1664. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1665. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1666. // die;
  1667. Doo::loadClass ( 'XDeode' );
  1668. $XDeode = new XDeode ( 7 );
  1669. $rid = $XDeode->decode ( $ridKey );
  1670. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1671. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1672. header ( 'Content-Type:text/html;charset=utf-8' );
  1673. die ( '请填写联行号' );
  1674. }
  1675. Doo::loadModel ( 'receipt' );
  1676. Doo::loadModel ( 'receiptDetail' );
  1677. Doo::loadModel ( 'accountItem' );
  1678. $accountItem = new accountItem ();
  1679. $receipt = new receipt ();
  1680. Doo::loadModel ( 'loanReceipt' );
  1681. $loanReceipt = new loanReceipt ();
  1682. Doo::loadModel ( 'enclosur' );
  1683. Doo::loadModel ( 'execute' );
  1684. $execute = new execute ();
  1685. $executeDetail = $execute->getOne ( array (
  1686. 'where' => 'mold="借款执行人"',
  1687. 'asArray' => true
  1688. ) );
  1689. $receiptDetail = $receipt->getOne ( array (
  1690. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1691. 'asArray' => true
  1692. ) );
  1693. if (empty ( $receiptDetail ))
  1694. die ( '参数错误' );
  1695. $aItem = $accountItem->find ( array (
  1696. 'asArray' => true
  1697. ) );
  1698. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1699. $ag = $tr = $ta = $ot = 0;
  1700. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1701. array_push ( $accountJson ['借款费用'], array (
  1702. 'aid' => 0,
  1703. 'name' => '申请金额',
  1704. 'price' => number_format ( $agency, 2, '.', '' )
  1705. ) );
  1706. $sum += $agency;
  1707. $agencySum += $agency;
  1708. $accountJson ['cSum'] = array (
  1709. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1710. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1711. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1712. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1713. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1714. );
  1715. // 报销单
  1716. $receipt->loanItem = json_encode ( $accountJson );
  1717. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1718. $receipt->cid = $cid;
  1719. // 特殊状态
  1720. // 修改审批流程加入角色
  1721. if ($receiptDetail ['status'] != 4)
  1722. $receipt->verify = $verify;
  1723. $order = array (
  1724. "\r\n",
  1725. "\n",
  1726. "\r"
  1727. );
  1728. $replace = '<br/>';
  1729. $explanation = str_replace ( $order, $replace, $explanation );
  1730. $receipt->explanation = $explanation;
  1731. $receipt->remittanceName = $remittanceName;
  1732. $receipt->bankName = $bankName;
  1733. $receipt->bankNumber = $bankNumber;
  1734. $receipt->remittanceBankType = $remittanceBankType;
  1735. if ($remittanceBankType == 1)
  1736. $receipt->coupletNumber = $coupletNumber;
  1737. $receipt->update ( array (
  1738. 'where' => 'rid=' . $rid
  1739. ) );
  1740. // 借款数据更新
  1741. $loanReceipt->loanItem = json_encode ( $accountJson );
  1742. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1743. $loanReceipt->cid = $cid;
  1744. if ($receiptDetail ['status'] != 4)
  1745. $loanReceipt->verify = $verify;
  1746. $loanReceipt->explanation = $explanation;
  1747. $receipt->executeCopy = $executeDetail ['staff'];
  1748. $loanReceipt->update ( array (
  1749. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1750. ) );
  1751. }
  1752. return "/saeaBorad";
  1753. }
  1754. function saeaLoanReceiptAdd() {
  1755. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1756. Doo::loadModel ( 'receipt' );
  1757. $receipt = new receipt ();
  1758. Doo::loadModel ( 'loanReceipt' );
  1759. $loanReceipt = new loanReceipt ();
  1760. Doo::loadModel ( 'L_category' );
  1761. $Lcategory = new L_category ();
  1762. Doo::loadModel ( 'verify' );
  1763. Doo::loadModel ( 'statistics' );
  1764. $statistics = new statistics ();
  1765. $verify = new verify ();
  1766. Doo::loadModel ( 'staff' );
  1767. $staff = new staff ();
  1768. $receiptDetail = $receipt->getOne ( array (
  1769. 'where' => 'rid=' . $rid,
  1770. 'desc' => 'rid',
  1771. 'asArray' => true
  1772. ) );
  1773. $receiptList = $loanReceipt->find ( array (
  1774. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1775. 'desc' => 'rid',
  1776. 'asArray' => true
  1777. ) );
  1778. $Locate = 0;
  1779. $roleId = 0;
  1780. $button = 0;
  1781. foreach ( $receiptList as $key => $value ) {
  1782. $receiptList [$key] ['Locate'] = $Locate;
  1783. $Locate ++;
  1784. $receiptList [$key] ['reviseDetail'] = array ();
  1785. if (! empty ( $value ['reviseDetail'] ))
  1786. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1787. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1788. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1789. $categoryDetil = $Lcategory->getOne ( array (
  1790. 'where' => 'cid=' . $value ['cid'],
  1791. 'asArray' => true
  1792. ) );
  1793. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1794. // 检测编辑状态
  1795. $verifyList = $verify->getOne ( array (
  1796. 'where' => 'vid=' . $value ['verify'],
  1797. 'asArray' => true
  1798. ) );
  1799. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1800. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1801. Doo::loadModel ( 'role' );
  1802. $role = new role ();
  1803. $flag = true;
  1804. $roleKey = 0;
  1805. $endStaffArray = array ();
  1806. $roleArrayCopy = array ();
  1807. foreach ( $verifyList as $k => $v ) {
  1808. // init verifyStaff
  1809. if ($v [1] == 'ROLE') {
  1810. if (! empty ( $verifyStaff )) {
  1811. $endStaffArray = end ( $verifyStaff );
  1812. // if ($v[0]==$endStaffArray['nextStaff']){
  1813. // $roleId=$v[0];
  1814. // }
  1815. }
  1816. $roleVerify = json_decode ( $v [3], true );
  1817. $roleKey = $k;
  1818. $roleArray = array ();
  1819. $rolename = $role->getOne ( array (
  1820. 'where' => 'rid=' . $v [0],
  1821. 'asArray' => true
  1822. ) );
  1823. foreach ( $roleVerify as $o => $p ) {
  1824. $staffID = explode ( '_', $p );
  1825. $staffInfo = $staff->getOne ( array (
  1826. 'where' => 'sid=' . $staffID [0],
  1827. 'asArray' => true
  1828. ) );
  1829. // print_r($staffID);
  1830. $exp = array (
  1831. 0 => $staffInfo ['sid'],
  1832. 1 => $staffID [1],
  1833. 2 => $staffInfo ['avatar'],
  1834. 'date' => '',
  1835. 'date' => '',
  1836. 'opinion' => '',
  1837. 'status' => '',
  1838. 'rolename' => $rolename ['name']
  1839. );
  1840. array_push ( $roleArray, $exp );
  1841. }
  1842. $roleArrayCopy [$v [0]] = $roleArray;
  1843. // $verifyList[$k]['roleArray']=$roleArray;
  1844. }
  1845. $verifyList [$k] ['date'] = "";
  1846. $verifyList [$k] ['opinion'] = "";
  1847. $verifyList [$k] ['status'] = "";
  1848. if (empty ( $verifyStaff )) {
  1849. $verifyList [$k] ['date'] = "";
  1850. $verifyList [$k] ['opinion'] = "";
  1851. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1852. $verifyList [$k] ['status'] = 4;
  1853. $flag = false;
  1854. }
  1855. } else {
  1856. foreach ( $verifyStaff as $m => $u ) {
  1857. if ($v [0] == $m) {
  1858. $verifyList [$k] ['date'] = $u ['date'];
  1859. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1860. $verifyList [$k] ['status'] = $u ['status'];
  1861. $flag = false;
  1862. break;
  1863. }
  1864. }
  1865. $endStaffArray = end ( $verifyStaff );
  1866. if (isset ( $endStaffArray ['ROLE'] )) {
  1867. } else {
  1868. // $endKey=key($verifyStaff);
  1869. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1870. // $button=4;
  1871. // $verifyList[$k]['status']=4;
  1872. // }
  1873. }
  1874. }
  1875. }
  1876. $rolename ['name'] = '';
  1877. if (! empty ( $roleId )) {
  1878. Doo::loadModel ( 'role' );
  1879. $role = new role ();
  1880. $rolename = $role->getOne ( array (
  1881. 'where' => 'rid=' . $roleId,
  1882. 'asArray' => true
  1883. ) );
  1884. }
  1885. if (! empty ( $verifyStaff ))
  1886. $endStaffArray = end ( $verifyStaff );
  1887. $KOP = false;
  1888. foreach ( $roleArrayCopy as $P => $A ) {
  1889. foreach ( $A as $MKI => $AVL ) {
  1890. if (! empty ( $verifyStaff )) {
  1891. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1892. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1893. $button = 4;
  1894. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1895. }
  1896. foreach ( $verifyStaff as $m => $u ) {
  1897. $AVLFK = $AVL [0] . '_R';
  1898. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1899. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1900. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1901. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1902. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1903. break;
  1904. }
  1905. }
  1906. } else {
  1907. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1908. $button = 4;
  1909. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1910. }
  1911. }
  1912. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1913. $KOP = true;
  1914. }
  1915. }
  1916. foreach ( $roleArrayCopy as $k => $v ) {
  1917. foreach ( $verifyList as $m => $n ) {
  1918. if ($n [0] == $k) {
  1919. array_splice ( $verifyList, $m, 1, $v );
  1920. }
  1921. }
  1922. }
  1923. $receiptList [$key] ['verifyList'] = $verifyList;
  1924. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1925. 'where' => 'sid=' . $value ['staff'],
  1926. 'asArray' => true
  1927. ) );
  1928. $receiptList [$key] ['button'] = $button;
  1929. //
  1930. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1931. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1932. }
  1933. $data ['receiptList'] = $receiptList;
  1934. $data ['receiptDetail'] = $receiptDetail;
  1935. Doo::loadModel ( 'L_category' );
  1936. $lCategory = new L_category ();
  1937. Doo::loadModel ( 'accountItem' );
  1938. $accountItem = new accountItem ();
  1939. $acItem = $accountItem->find ( array (
  1940. 'asArray' => true
  1941. ) );
  1942. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1943. $data ['rid'] = $rid;
  1944. $data ['category'] = $lCategory->find ( array (
  1945. 'asArray' => true
  1946. ) );
  1947. $data ['veList'] = $veList;
  1948. $data ['acItem'] = $acItem;
  1949. $data ['memu'] = "receipt";
  1950. $data ['staff'] = $this->staff;
  1951. $data ['receiptMemu'] = 'saeaBorad';
  1952. $data ['verifyId'] = $this->verifyId;
  1953. $data ['executeId'] = $this->executeId;
  1954. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1955. }
  1956. function saeaLoanReceiptAddDo() {
  1957. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1958. $agency = $this->get_args ( 'agency' );
  1959. $travel = $this->get_args ( 'travel' );
  1960. $train = $this->get_args ( 'train' );
  1961. $other = $this->get_args ( 'other' );
  1962. $inttrain = $this->get_args ( 'inttrain' );
  1963. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1964. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1965. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1966. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1967. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1968. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1969. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1970. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1971. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1972. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1973. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1974. header ( 'Content-Type:text/html;charset=utf-8' );
  1975. die ( '请填写联行号' );
  1976. }
  1977. Doo::loadModel ( 'receipt' );
  1978. Doo::loadModel ( 'receiptDetail' );
  1979. Doo::loadModel ( 'accountItem' );
  1980. $accountItem = new accountItem ();
  1981. $receipt = new receipt ();
  1982. Doo::loadModel ( 'enclosur' );
  1983. Doo::loadModel ( 'execute' );
  1984. $execute = new execute ();
  1985. $executeDetail = $execute->getOne ( array (
  1986. 'where' => 'mold="借款费用执行人"',
  1987. 'asArray' => true
  1988. ) );
  1989. $receiptDet = $receipt->getOne ( array (
  1990. 'where' => 'rid=' . $rid,
  1991. 'asArray' => true
  1992. ) );
  1993. // if(!empty($receiptDetail))
  1994. // return "/referReceipt/".$receiptDetail['rid'];
  1995. $aItem = $accountItem->find ( array (
  1996. 'asArray' => true
  1997. ) );
  1998. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1999. $ag = $tr = $ta = $ot =$it = 0;
  2000. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  2001. foreach ( $aItem as $key => $value ) {
  2002. if ($value ['category'] == $this->AGENCY) {
  2003. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  2004. array_push ( $accountJson [$this->AGENCY], array (
  2005. 'aid' => $value ['aid'],
  2006. 'name' => $value ['name'],
  2007. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  2008. ) );
  2009. $sum += $agency [$ag];
  2010. $agencySum += $agency [$ag];
  2011. }
  2012. $ag ++;
  2013. }
  2014. if ($value ['category'] == $this->TRAVEL) {
  2015. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  2016. array_push ( $accountJson [$this->TRAVEL], array (
  2017. 'aid' => $value ['aid'],
  2018. 'name' => $value ['name'],
  2019. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  2020. ) );
  2021. $sum += $travel [$tr];
  2022. $travelSum += $travel [$tr];
  2023. }
  2024. $tr ++;
  2025. }
  2026. if ($value ['category'] == $this->INTTRAIN) {
  2027. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  2028. array_push ( $accountJson [$this->INTTRAIN], array (
  2029. 'aid' => $value ['aid'],
  2030. 'name' => $value ['name'],
  2031. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  2032. ) );
  2033. $sum += $inttrain [$it];
  2034. $inttrainSum += $inttrain [$it];
  2035. }
  2036. $it ++;
  2037. }
  2038. if ($value ['category'] == $this->TRAIN) {
  2039. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  2040. array_push ( $accountJson [$this->TRAIN], array (
  2041. 'aid' => $value ['aid'],
  2042. 'name' => $value ['name'],
  2043. 'price' => number_format ( $train [$ta], 2, '.', '' )
  2044. ) );
  2045. $sum += $train [$ta];
  2046. $trainSum += $train [$ta];
  2047. }
  2048. $ta ++;
  2049. }
  2050. if ($value ['category'] == $this->OTHER) {
  2051. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  2052. array_push ( $accountJson [$this->OTHER], array (
  2053. 'aid' => $value ['aid'],
  2054. 'name' => $value ['name'],
  2055. 'price' => number_format ( $other [$ot], 2, '.', '' )
  2056. ) );
  2057. $sum += $other [$ot];
  2058. $otherSum += $other [$ot];
  2059. }
  2060. $ot ++;
  2061. }
  2062. }
  2063. $accountJson ['cSum'] = array (
  2064. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2065. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2066. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2067. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  2068. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2069. );
  2070. // 报销单
  2071. $receipt->accountItem = json_encode ( $accountJson );
  2072. $receipt->staff = $this->staff [0] ['sid'];
  2073. $receipt->loanSum = $receiptDet ['sum'];
  2074. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2075. $receipt->date = date ( "Y-m-d" );
  2076. $receipt->pastDate = '';
  2077. $receipt->cid = $cid;
  2078. $receipt->status = 7;
  2079. // 修改审批流程加入角色
  2080. $receipt->verify = $verify;
  2081. $receipt->verifyStaff = '';
  2082. $receipt->executeStaff = '';
  2083. $receipt->executeCopy = $executeDetail ['staff'];
  2084. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  2085. $receipt->explanation = $explanation;
  2086. $receipt->remittanceName = $remittanceName;
  2087. $receipt->bankName = $bankName;
  2088. $receipt->bankNumber = $bankNumber;
  2089. $receipt->remittanceBankType = $remittanceBankType;
  2090. if ($remittanceBankType == 1)
  2091. $receipt->coupletNumber = $coupletNumber;
  2092. $receipt->update ( array (
  2093. 'where' => 'rid=' . $rid
  2094. ) );
  2095. // 附件
  2096. if (! empty ( $enclosurName )) {
  2097. $enclosurArray = explode ( '-', $enclosurName );
  2098. foreach ( $enclosurArray as $value ) {
  2099. $enclosur = new enclosur ();
  2100. $enclosur->name = $value;
  2101. $enclosur->rid = $rid;
  2102. $enclosur->insert ();
  2103. }
  2104. // print_r($enclosurArray);die;
  2105. }
  2106. // 报销详情
  2107. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  2108. $receiptDetail = new receiptDetail ();
  2109. $receiptDetail->staff = $this->staff [0] ['sid'];
  2110. $receiptDetail->item = $value ['name'];
  2111. $receiptDetail->itemCategory = $this->AGENCY;
  2112. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2113. $receiptDetail->date = date ( "Y-m-d" );
  2114. $receiptDetail->cid = $cid;
  2115. $receiptDetail->rid = $rid;
  2116. $receiptDetail->status = 4;
  2117. $receiptDetail->insert ();
  2118. }
  2119. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  2120. $receiptDetail = new receiptDetail ();
  2121. $receiptDetail->staff = $this->staff [0] ['sid'];
  2122. $receiptDetail->item = $value ['name'];
  2123. $receiptDetail->itemCategory = $this->TRAVEL;
  2124. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2125. $receiptDetail->date = date ( "Y-m-d" );
  2126. $receiptDetail->cid = $cid;
  2127. $receiptDetail->rid = $rid;
  2128. $receiptDetail->status = 4;
  2129. $receiptDetail->insert ();
  2130. }
  2131. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  2132. $receiptDetail = new receiptDetail ();
  2133. $receiptDetail->staff = $this->staff [0] ['sid'];
  2134. $receiptDetail->item = $value ['name'];
  2135. $receiptDetail->itemCategory = $this->TRAIN;
  2136. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2137. $receiptDetail->date = date ( "Y-m-d" );
  2138. $receiptDetail->cid = $cid;
  2139. $receiptDetail->rid = $rid;
  2140. $receiptDetail->status = 4;
  2141. $receiptDetail->insert ();
  2142. }
  2143. //内训
  2144. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  2145. $receiptDetail = new receiptDetail ();
  2146. $receiptDetail->staff = $this->staff [0] ['sid'];
  2147. $receiptDetail->item = $value ['name'];
  2148. $receiptDetail->itemCategory = $this->INTTRAIN;
  2149. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2150. $receiptDetail->date = date ( "Y-m-d" );
  2151. $receiptDetail->cid = $cid;
  2152. $receiptDetail->rid = $rid;
  2153. $receiptDetail->status = 4;
  2154. $receiptDetail->insert ();
  2155. }
  2156. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  2157. $receiptDetail = new receiptDetail ();
  2158. $receiptDetail->staff = $this->staff [0] ['sid'];
  2159. $receiptDetail->item = $value ['name'];
  2160. $receiptDetail->itemCategory = $this->OTHER;
  2161. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2162. $receiptDetail->date = date ( "Y-m-d" );
  2163. $receiptDetail->cid = $cid;
  2164. $receiptDetail->rid = $rid;
  2165. $receiptDetail->status = 4;
  2166. $receiptDetail->insert ();
  2167. }
  2168. return "/saeaBorad";
  2169. }
  2170. return "/saeaLoanReceiptAdd/" . $rid;
  2171. }
  2172. function saeaLoanReceiptEdi() {
  2173. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2174. Doo::loadClass ( 'XDeode' );
  2175. $XDeode = new XDeode ( 7 );
  2176. $rid = $XDeode->decode ( $ridKey );
  2177. if (! is_numeric ( $rid ))
  2178. die ( 'illegal request' );
  2179. Doo::loadModel ( 'accountItem' );
  2180. Doo::loadModel ( 'verify' );
  2181. Doo::loadModel ( 'receipt' );
  2182. $receipt = new receipt ();
  2183. $verify = new verify ();
  2184. $accountItem = new accountItem ();
  2185. Doo::loadModel ( 'L_category' );
  2186. $Lcategory = new L_category ();
  2187. Doo::loadModel ( "role" );
  2188. $role = new role ();
  2189. Doo::loadModel ( 'loanReceipt' );
  2190. $loanReceipt = new loanReceipt ();
  2191. Doo::loadModel ( 'staff' );
  2192. $staff = new staff ();
  2193. $receiptDetail = $receipt->getOne ( array (
  2194. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  2195. 'asArray' => true
  2196. ) );
  2197. if (empty ( $receiptDetail ))
  2198. return "/saeaBorad";
  2199. $receiptList = $loanReceipt->find ( array (
  2200. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2201. 'desc' => 'rid',
  2202. 'asArray' => true
  2203. ) );
  2204. $Locate = 0;
  2205. $roleId = 0;
  2206. $button = 0;
  2207. foreach ( $receiptList as $key => $value ) {
  2208. $receiptList [$key] ['Locate'] = $Locate;
  2209. $Locate ++;
  2210. $receiptList [$key] ['reviseDetail'] = array ();
  2211. if (! empty ( $value ['reviseDetail'] ))
  2212. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2213. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2214. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2215. $categoryDetil = $Lcategory->getOne ( array (
  2216. 'where' => 'cid=' . $value ['cid'],
  2217. 'asArray' => true
  2218. ) );
  2219. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2220. // 检测编辑状态
  2221. $verifyList = $verify->getOne ( array (
  2222. 'where' => 'vid=' . $value ['verify'],
  2223. 'asArray' => true
  2224. ) );
  2225. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2226. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2227. Doo::loadModel ( 'role' );
  2228. $role = new role ();
  2229. $flag = true;
  2230. $roleKey = 0;
  2231. $endStaffArray = array ();
  2232. $roleArrayCopy = array ();
  2233. foreach ( $verifyList as $k => $v ) {
  2234. // init verifyStaff
  2235. if ($v [1] == 'ROLE') {
  2236. if (! empty ( $verifyStaff )) {
  2237. $endStaffArray = end ( $verifyStaff );
  2238. // if ($v[0]==$endStaffArray['nextStaff']){
  2239. // $roleId=$v[0];
  2240. // }
  2241. }
  2242. $roleVerify = json_decode ( $v [3], true );
  2243. $roleKey = $k;
  2244. $roleArray = array ();
  2245. $rolename = $role->getOne ( array (
  2246. 'where' => 'rid=' . $v [0],
  2247. 'asArray' => true
  2248. ) );
  2249. foreach ( $roleVerify as $o => $p ) {
  2250. $staffID = explode ( '_', $p );
  2251. $staffInfo = $staff->getOne ( array (
  2252. 'where' => 'sid=' . $staffID [0],
  2253. 'asArray' => true
  2254. ) );
  2255. // print_r($staffID);
  2256. $exp = array (
  2257. 0 => $staffInfo ['sid'],
  2258. 1 => $staffID [1],
  2259. 2 => $staffInfo ['avatar'],
  2260. 'date' => '',
  2261. 'date' => '',
  2262. 'opinion' => '',
  2263. 'status' => '',
  2264. 'rolename' => $rolename ['name']
  2265. );
  2266. array_push ( $roleArray, $exp );
  2267. }
  2268. $roleArrayCopy [$v [0]] = $roleArray;
  2269. // $verifyList[$k]['roleArray']=$roleArray;
  2270. }
  2271. $verifyList [$k] ['date'] = "";
  2272. $verifyList [$k] ['opinion'] = "";
  2273. $verifyList [$k] ['status'] = "";
  2274. if (empty ( $verifyStaff )) {
  2275. $verifyList [$k] ['date'] = "";
  2276. $verifyList [$k] ['opinion'] = "";
  2277. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2278. $verifyList [$k] ['status'] = 4;
  2279. $flag = false;
  2280. }
  2281. } else {
  2282. foreach ( $verifyStaff as $m => $u ) {
  2283. if ($v [0] == $m) {
  2284. $verifyList [$k] ['date'] = $u ['date'];
  2285. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2286. $verifyList [$k] ['status'] = $u ['status'];
  2287. $flag = false;
  2288. break;
  2289. }
  2290. }
  2291. $endStaffArray = end ( $verifyStaff );
  2292. if (isset ( $endStaffArray ['ROLE'] )) {
  2293. } else {
  2294. // $endKey=key($verifyStaff);
  2295. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2296. // $button=4;
  2297. // $verifyList[$k]['status']=4;
  2298. // }
  2299. }
  2300. }
  2301. }
  2302. $rolename ['name'] = '';
  2303. if (! empty ( $roleId )) {
  2304. Doo::loadModel ( 'role' );
  2305. $role = new role ();
  2306. $rolename = $role->getOne ( array (
  2307. 'where' => 'rid=' . $roleId,
  2308. 'asArray' => true
  2309. ) );
  2310. }
  2311. if (! empty ( $verifyStaff ))
  2312. $endStaffArray = end ( $verifyStaff );
  2313. $KOP = false;
  2314. foreach ( $roleArrayCopy as $P => $A ) {
  2315. foreach ( $A as $MKI => $AVL ) {
  2316. if (! empty ( $verifyStaff )) {
  2317. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2318. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2319. $button = 4;
  2320. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2321. }
  2322. foreach ( $verifyStaff as $m => $u ) {
  2323. $AVLFK = $AVL [0] . '_R';
  2324. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2325. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2326. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2327. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2328. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2329. break;
  2330. }
  2331. }
  2332. } else {
  2333. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2334. $button = 4;
  2335. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2336. }
  2337. }
  2338. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2339. $KOP = true;
  2340. }
  2341. }
  2342. foreach ( $roleArrayCopy as $k => $v ) {
  2343. foreach ( $verifyList as $m => $n ) {
  2344. if ($n [0] == $k) {
  2345. array_splice ( $verifyList, $m, 1, $v );
  2346. }
  2347. }
  2348. }
  2349. $receiptList [$key] ['verifyList'] = $verifyList;
  2350. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2351. 'where' => 'sid=' . $value ['staff'],
  2352. 'asArray' => true
  2353. ) );
  2354. $receiptList [$key] ['button'] = $button;
  2355. //
  2356. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2357. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2358. }
  2359. $data ['receiptList'] = $receiptList;
  2360. $acItem = $accountItem->find ( array (
  2361. 'asArray' => true
  2362. ) );
  2363. $veList = $verify->find ( array (
  2364. 'asArray' => true
  2365. ) );
  2366. foreach ( $veList as $key => $value ) {
  2367. $v = json_decode ( $value ['staff'] );
  2368. $list = array ();
  2369. foreach ( $v as $n => $m ) {
  2370. if ($m ['1'] == 'ROLE') {
  2371. $roleInfo = $role->getOne ( array (
  2372. 'where' => 'rid=' . $m [0],
  2373. 'asArray' => true
  2374. ) );
  2375. $v [$n] [1] = $roleInfo ['name'];
  2376. array_push ( $list, $roleInfo ['name'] );
  2377. } else {
  2378. array_push ( $list, $v [$n] [1] );
  2379. }
  2380. }
  2381. $veList [$key] ['staff'] = implode ( '>', $list );
  2382. }
  2383. // 配置编辑信息
  2384. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  2385. foreach ( $acItem as $key => $value ) {
  2386. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  2387. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  2388. $acItem [$key] ['price'] = $v ['price'];
  2389. }
  2390. }
  2391. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  2392. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2393. $acItem [$key] ['price'] = $v ['price'];
  2394. }
  2395. }
  2396. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  2397. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  2398. $acItem [$key] ['price'] = $v ['price'];
  2399. }
  2400. }
  2401. //内训
  2402. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  2403. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2404. $acItem [$key] ['price'] = $v ['price'];
  2405. }
  2406. }
  2407. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  2408. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  2409. $acItem [$key] ['price'] = $v ['price'];
  2410. }
  2411. }
  2412. }
  2413. $data ['category'] = $Lcategory->find ( array (
  2414. 'asArray' => true
  2415. ) );
  2416. $data ['ridKey'] = $ridKey;
  2417. $data ['cSum'] = $accountItemList ['cSum'];
  2418. $data ['sum'] = $receiptDetail ['sum'];
  2419. $data ['receiptDetail'] = $receiptDetail;
  2420. $data ['veList'] = $veList;
  2421. $data ['acItem'] = $acItem;
  2422. $data ['memu'] = "receipt";
  2423. $data ['staff'] = $this->staff;
  2424. $data ['receiptMemu'] = 'saeaBorad';
  2425. $data ['verify'] = $receiptDetail ['verify'];
  2426. $data ['verifyId'] = $this->verifyId;
  2427. $data ['executeId'] = $this->executeId;
  2428. $data ['rid'] = $rid;
  2429. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  2430. }
  2431. /**
  2432. * 培训班结算
  2433. */
  2434. function receiptTrainAdd() {
  2435. Doo::loadModel ( 'accountItem' );
  2436. $accountItem = new accountItem ();
  2437. $acItem = $accountItem->find ( array (
  2438. 'asArray' => true
  2439. ) );
  2440. // 审批组
  2441. Doo::loadModel ( 'verify' );
  2442. $verify = new verify ();
  2443. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2444. // 办事处
  2445. Doo::loadModel ( 'L_category' );
  2446. $lCategory = new L_category ();
  2447. $data ['category'] = $lCategory->getCategory ();
  2448. $data ['veList'] = $veList;
  2449. $data ['memu'] = "receipt";
  2450. $data ['staff'] = $this->staff;
  2451. $data ['acItem'] = $acItem;
  2452. $data ['receiptMemu'] = 'saeaBorad';
  2453. $data ['verifyId'] = $this->verifyId;
  2454. $data ['executeId'] = $this->executeId;
  2455. $this->render ( "/receipt/receiptTrainAdd", $data );
  2456. }
  2457. /**
  2458. * 添加培训班结算
  2459. */
  2460. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2461. // 培训班信息
  2462. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2463. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2464. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2465. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2466. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2467. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2468. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2469. // 发票信息
  2470. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2471. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2472. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2473. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2474. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2475. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2476. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2477. //&&! empty ( $participants )
  2478. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2479. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2480. header ( 'Content-Type:text/html;charset=utf-8' );
  2481. die ( '请填写联行号' );
  2482. }
  2483. Doo::loadModel ( 'execute' );
  2484. $execute = new execute ();
  2485. $executeDetail = $execute->getOne ( array (
  2486. 'where' => 'mold="培训班结算"',
  2487. 'asArray' => true
  2488. ) );
  2489. if (empty ( $executeDetail )) {
  2490. header ( 'Content-Type:text/html;charset=utf-8' );
  2491. die ( '未设置执行人' );
  2492. }
  2493. Doo::loadClass ( 'XDeode' );
  2494. $XDeode = new XDeode ( 5 );
  2495. $cid = $XDeode->decode ( $cid );
  2496. Doo::loadModel ( 'receipt' );
  2497. $receipt = new receipt ();
  2498. Doo::loadModel ( 'receiptTraining' );
  2499. $receiptTraining = new receiptTraining ();
  2500. // 创建费用培训班
  2501. $item = array (
  2502. 'cid' => $this->staff [0] ['cid'],
  2503. 'categoryName' => $this->staff [0] ['category'],
  2504. 'trainName' => $trainName,
  2505. 'trainStartDate' => $trainStartDate,
  2506. 'trainEndDate' => $trainEndDate,
  2507. 'participants' => $participants,
  2508. 'freeParticipants'=>$freeParticipants,
  2509. 'trainAddress' => $trainAddress,
  2510. 'trainRemarks' => $trainRemarks,
  2511. 'creator' => $this->staff [0] ['sid'],
  2512. 'creatorDate' => date ( "Y-m-d H:i:s" )
  2513. );
  2514. $irid = $receiptTraining->addReceiptTraining ( $item );
  2515. // 报销单
  2516. $receipt->status = 5;
  2517. $receipt->trainId = $irid;
  2518. $receipt->Rtype = 3;
  2519. $receipt->staff = $this->staff [0] ['sid'];
  2520. $receipt->cid = $cid;
  2521. $receipt->verify = $verify;
  2522. $receipt->date = date ( "Y-m-d" );
  2523. $receipt->executeCopy = $executeDetail ['staff'];
  2524. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2525. $receipt->remittanceName = $remittanceName;
  2526. $receipt->bankName = $bankName;
  2527. $receipt->bankNumber = $bankNumber;
  2528. $receipt->remittanceBankType = $remittanceBankType;
  2529. if ($remittanceBankType == 1)
  2530. $receipt->coupletNumber = $coupletNumber;
  2531. $rid = $receipt->insert ();
  2532. $XDeode = new XDeode ( 7 );
  2533. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  2534. } else
  2535. die ( 'illegal request' );
  2536. }
  2537. /**
  2538. * 培训班编辑
  2539. */
  2540. function receiptTrainEdi() {
  2541. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2542. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  2543. Doo::loadClass ( 'XDeode' );
  2544. $XDeode = new XDeode ( 7 );
  2545. $rid = $XDeode->decode ( $ridKey );
  2546. if (! is_numeric ( $rid ))
  2547. die ( 'illegal request' );
  2548. Doo::loadModel ( 'receipt' );
  2549. $receipt = new receipt ();
  2550. Doo::loadModel ( 'receiptTraining' );
  2551. $receiptTraining = new receiptTraining ();
  2552. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2553. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  2554. die ('illegal request--status');
  2555. }
  2556. //如有已入账已收款的发票,自动取消办事处已收款
  2557. // Doo::loadModel ( 'RIExtend' );
  2558. // $RIExtend = new RIExtend ();
  2559. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  2560. // if (!empty($RIExtendList)){
  2561. // foreach ($RIExtendList as $key=>$value){
  2562. // $RIExtend = new RIExtend ();
  2563. // $RIExtend->delete(array (
  2564. // 'where' => 'iid=' . $value['iid'],
  2565. // 'limit' => 1
  2566. // ));
  2567. // }
  2568. // }
  2569. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2570. // 汇总表合计
  2571. // 收入合计--加入开票合计
  2572. Doo::loadModel ( 'invoiceTraining' );
  2573. $invoiceTraining = new invoiceTraining ();
  2574. $invoiceTrainingDetail = array (
  2575. 'invoiceArriveAmount' => 0,
  2576. 'RIAmount' => 0,
  2577. 'invoiceTotalAmount' => 0,
  2578. 'invoiceCompanyAmount'=>0
  2579. );
  2580. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2581. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2582. }
  2583. // print_r($invoiceTrainingDetail);
  2584. $invoiceArriveAmount = $RIAmount = 0;
  2585. if (! empty ( $invoiceTrainingDetail )) {
  2586. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2587. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2588. }
  2589. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2590. //print_r($invoiceTrainingDetail);
  2591. // 支出项目
  2592. Doo::loadModel ( 'accountItem' );
  2593. $accountItem = new accountItem ();
  2594. // 项目金额合计
  2595. Doo::loadModel ( 'RItem' );
  2596. $RItem = new RItem ();
  2597. // 讲师获得
  2598. Doo::loadModel ( 'RILecturer' );
  2599. $RILecturer = new RILecturer ();
  2600. $RItemList = $RItem->getRItemByRid ( $rid );
  2601. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2602. // 支出项金额详情
  2603. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2604. // print_r($aiData);
  2605. // 利润
  2606. $profit=$invoiceArriveAmount - $aiData ['total'];
  2607. $companyProfit=$profit * 0.6;
  2608. $categoryProfit=$profit * 0.4;
  2609. $data ['profit'] = sprintf("%.2f",$profit);
  2610. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  2611. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  2612. //发票利润
  2613. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  2614. //发票公司利润
  2615. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  2616. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  2617. //办事处利润
  2618. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  2619. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  2620. // print_r($aiData['dataList']);
  2621. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2622. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  2623. // 备用金
  2624. $sum = 0;
  2625. $data ['receiptLoanDetail'] = array (
  2626. 'sum' => '0.00'
  2627. );
  2628. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2629. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2630. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2631. $sum=0;
  2632. foreach ($receiptLoanList as $key=>$value){
  2633. $sum+=$value['sum'];
  2634. }
  2635. $data ['receiptLoanDetail'] = array (
  2636. 'sum' => $sum
  2637. );
  2638. //$sum = $data ['receiptLoanDetail'] ['sum'];
  2639. }
  2640. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  2641. $data ['payment'] = sprintf("%.2f",$payment);
  2642. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  2643. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  2644. $data ['aiList'] = $aiData ['dataList'];
  2645. // 占比计算
  2646. if ($invoiceArriveAmount != 0) {
  2647. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  2648. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2649. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2650. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  2651. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  2652. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  2653. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  2654. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  2655. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  2656. } else {
  2657. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2658. }
  2659. //发票金额占比计算
  2660. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2661. //支出
  2662. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2663. //利润
  2664. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2665. //公司利润
  2666. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2667. //办事处利润
  2668. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2669. //公司收款
  2670. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2671. //备用金
  2672. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2673. //办事处收款
  2674. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2675. //办事处实际支出
  2676. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2677. //付总部款
  2678. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2679. }else{
  2680. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2681. }
  2682. //讲师人数
  2683. Doo::loadModel ( 'RILecturer' );
  2684. $RILecturer = new RILecturer ();
  2685. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2686. $data['lectureCount']=count($RILecturerList);
  2687. // 审批组
  2688. Doo::loadModel ( 'verify' );
  2689. $verify = new verify ();
  2690. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2691. // 办事处
  2692. Doo::loadModel ( 'L_category' );
  2693. $lCategory = new L_category ();
  2694. $data ['category'] = $lCategory->getCategory ();
  2695. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2696. $data ['receiptDetail'] = $receiptDetail;
  2697. $data ['veList'] = $veList;
  2698. $data ['trainEdiType'] = $trainEdiType;
  2699. $data ['ridKey'] = $ridKey;
  2700. $data ['memu'] = "receipt";
  2701. $data ['staff'] = $this->staff;
  2702. $data ['receiptMemu'] = 'saeaBorad';
  2703. $data ['verifyId'] = $this->verifyId;
  2704. $data ['executeId'] = $this->executeId;
  2705. $this->render ( "/receipt/receiptTrainEdi", $data );
  2706. }
  2707. /**
  2708. * 培训班借款编辑
  2709. */
  2710. function receiptTrainLoanEdi() {
  2711. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2712. Doo::loadClass ( 'XDeode' );
  2713. $XDeode = new XDeode ( 7 );
  2714. $rid = $XDeode->decode ( $ridKey );
  2715. if (! is_numeric ( $rid ))
  2716. die ( 'illegal request' );
  2717. Doo::loadModel ( 'receipt' );
  2718. $receipt = new receipt ();
  2719. Doo::loadModel ( 'receiptTraining' );
  2720. $receiptTraining = new receiptTraining ();
  2721. Doo::loadModel ( 'verify' );
  2722. $verify = new verify ();
  2723. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2724. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2725. die ();
  2726. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2727. // 借款详情HTML
  2728. // 获得借款信息
  2729. $receiptLoanHtml = '';
  2730. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2731. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2732. foreach ($receiptLoanList as $key=>$value){
  2733. // 获得某费用单审批信息
  2734. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  2735. Doo::loadClass ( 'receipt.func' );
  2736. $extendHtml = '<p><a class="button"
  2737. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2738. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  2739. }
  2740. }
  2741. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2742. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2743. $data ['receiptDetail'] = $receiptDetail;
  2744. $data ['trainEdiType'] = "LOAN";
  2745. $data ['ridKey'] = $ridKey;
  2746. $data ['memu'] = "receipt";
  2747. $data ['staff'] = $this->staff;
  2748. $data ['receiptMemu'] = 'saeaBorad';
  2749. $data ['verifyId'] = $this->verifyId;
  2750. $data ['executeId'] = $this->executeId;
  2751. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2752. }
  2753. /**
  2754. * 更新培训班结算基本信息
  2755. */
  2756. function receiptTrainInfoEdiDo() {
  2757. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2758. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2759. // 培训班信息
  2760. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2761. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2762. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2763. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2764. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2765. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2766. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2767. // 发票信息
  2768. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2769. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2770. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2771. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2772. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2773. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2774. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2775. //&& ! empty ( $participants )
  2776. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2777. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2778. header ( 'Content-Type:text/html;charset=utf-8' );
  2779. die ( '请填写联行号' );
  2780. }
  2781. Doo::loadClass ( 'XDeode' );
  2782. $XDeode = new XDeode ( 5 );
  2783. $cid = $XDeode->decode ( $cid );
  2784. $rtid = $XDeode->decode ( $rtid );
  2785. $rid = $XDeode->decode ( $rid );
  2786. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2787. die ( 'illegal request-IdError' );
  2788. }
  2789. Doo::loadModel ( 'receipt' );
  2790. $receipt = new receipt ();
  2791. Doo::loadModel ( 'receiptTraining' );
  2792. $receiptTraining = new receiptTraining ();
  2793. // 更新费用培训班
  2794. $item = array (
  2795. 'rtid' => $rtid,
  2796. 'trainName' => $trainName,
  2797. 'trainStartDate' => $trainStartDate,
  2798. 'trainEndDate' => $trainEndDate,
  2799. 'participants' => $participants,
  2800. 'freeParticipants'=>$freeParticipants,
  2801. 'trainAddress' => $trainAddress,
  2802. 'trainRemarks' => $trainRemarks
  2803. );
  2804. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2805. // 报销单
  2806. $receipt->rid = $rid;
  2807. $receipt->cid = $cid;
  2808. $receipt->verify = $verify;
  2809. $receipt->remittanceName = $remittanceName;
  2810. $receipt->bankName = $bankName;
  2811. $receipt->bankNumber = $bankNumber;
  2812. $receipt->remittanceBankType = $remittanceBankType;
  2813. if ($remittanceBankType == 1)
  2814. $receipt->coupletNumber = $coupletNumber;
  2815. $receipt->update ();
  2816. $XDeode = new XDeode ( 7 );
  2817. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2818. } else
  2819. die ( 'illegal request' );
  2820. }
  2821. /**
  2822. * 编辑培训班结算---更新借款
  2823. */
  2824. function receiptTrainLoanEdiDo() {
  2825. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2826. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2827. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2828. Doo::loadModel ( 'receipt' );
  2829. $receipt = new receipt ();
  2830. Doo::loadClass ( 'XDeode' );
  2831. $XDeode = new XDeode ( 5 );
  2832. $rid = $XDeode->decode ( $ridKey );
  2833. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2834. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2835. die ( 'illegal request-ridError' );
  2836. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2837. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2838. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2839. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2840. die ( 'illegal request-receiptError' );
  2841. }
  2842. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2843. die ( 'illegal request-receipLoantError' );
  2844. }
  2845. // 培训班结算挂钩借款
  2846. $receipt = new receipt ();
  2847. $trainLoanRid=$ridLoan;
  2848. if (!empty($receiptDetail['trainLoanRid'])){
  2849. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  2850. }
  2851. $item = array (
  2852. 'rid' => $rid,
  2853. 'trainLoanRid' => $trainLoanRid
  2854. );
  2855. $receipt->setReceiptByCondition ( $item );
  2856. // 更新借款状态变成已挂钩
  2857. $receipt = new receipt ();
  2858. $item = array (
  2859. 'rid' => $ridLoan,
  2860. 'status' => 10,
  2861. 'statusTrain' => 1
  2862. );
  2863. $receipt->setReceiptByCondition ( $item );
  2864. $XDeode = new XDeode ( 7 );
  2865. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2866. } else
  2867. die ( 'illegal request' );
  2868. }
  2869. /**
  2870. * 编辑培训班结算--移除借款
  2871. */
  2872. function receiptTrainLoanRemoveDo() {
  2873. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2874. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2875. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2876. Doo::loadModel ( 'receipt' );
  2877. $receipt = new receipt ();
  2878. Doo::loadClass ( 'XDeode' );
  2879. $XDeode = new XDeode ( 5 );
  2880. $rid = $XDeode->decode ( $ridKey );
  2881. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2882. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2883. die ( 'illegal request-ridError' );
  2884. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2885. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2886. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2887. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2888. die ( 'illegal request-receiptError' );
  2889. }
  2890. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2891. die ( 'illegal request-receipLoantError' );
  2892. }
  2893. // 培训班结算挂钩借款
  2894. $receipt = new receipt ();
  2895. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  2896. foreach ($trainLoanRidArray as $key=>$value){
  2897. if($value==$ridLoan){
  2898. unset($trainLoanRidArray[$key]);
  2899. }
  2900. }
  2901. $trainLoanRidString=implode(",", $trainLoanRidArray);
  2902. $item = array (
  2903. 'rid' => $rid,
  2904. 'trainLoanRid' => $trainLoanRidString
  2905. );
  2906. $receipt->setReceiptByCondition ( $item );
  2907. // 更新借款状态变成已挂钩
  2908. $receipt = new receipt ();
  2909. $item = array (
  2910. 'rid' => $ridLoan,
  2911. 'status' => 8,
  2912. 'statusTrain' => 0
  2913. );
  2914. $receipt->setReceiptByCondition ( $item );
  2915. $XDeode = new XDeode ( 7 );
  2916. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2917. } else
  2918. die ( 'illegal request' );
  2919. }
  2920. /**
  2921. * 编辑培训班结算 ---开票
  2922. */
  2923. function receiptTrainInvoiceEdi() {
  2924. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2925. Doo::loadClass ( 'XDeode' );
  2926. $XDeode = new XDeode ( 7 );
  2927. $rid = $XDeode->decode ( $ridKey );
  2928. if (! is_numeric ( $rid ))
  2929. die ( 'illegal request' );
  2930. Doo::loadModel ( 'receipt' );
  2931. $receipt = new receipt ();
  2932. Doo::loadModel ( 'receiptTraining' );
  2933. $receiptTraining = new receiptTraining ();
  2934. Doo::loadModel ( 'invoice' );
  2935. $invoice = new invoice ();
  2936. Doo::loadModel ( 'invoiceTraining' );
  2937. $invoiceTraining = new invoiceTraining ();
  2938. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2939. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2940. die ();
  2941. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2942. $invoiceList = $invoiceTrainingDetail = array ();
  2943. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2944. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2945. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2946. }
  2947. //print_r($invoiceList);
  2948. $data ['invoiceList'] = $invoiceList;
  2949. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2950. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2951. $data ['receiptDetail'] = $receiptDetail;
  2952. $data ['trainEdiType'] = "INVOICE";
  2953. $data ['ridKey'] = $ridKey;
  2954. $data ['memu'] = "receipt";
  2955. $data ['staff'] = $this->staff;
  2956. $data ['receiptMemu'] = 'saeaBorad';
  2957. $data ['verifyId'] = $this->verifyId;
  2958. $data ['executeId'] = $this->executeId;
  2959. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2960. }
  2961. /**
  2962. * 编辑培训班结算---更新开票
  2963. */
  2964. function receiptTrainInvoiceEdiDo() {
  2965. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2966. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2967. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2968. Doo::loadModel ( 'receipt' );
  2969. $receipt = new receipt ();
  2970. Doo::loadModel ( 'invoiceTraining' );
  2971. $invoiceTraining = new invoiceTraining ();
  2972. Doo::loadClass ( 'XDeode' );
  2973. $XDeode = new XDeode ( 5 );
  2974. $rid = $XDeode->decode ( $ridKey );
  2975. $itid = $XDeode->decode ( $itidKey );
  2976. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2977. die ( 'illegal request-idError' );
  2978. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2979. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2980. // 不合法的数据
  2981. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2982. die ( 'illegal request-receiptError' );
  2983. }
  2984. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2985. die ( 'illegal request-receipLoantError' );
  2986. }
  2987. // 培训班结算挂钩借款
  2988. $receipt = new receipt ();
  2989. $item = array (
  2990. 'rid' => $rid,
  2991. 'invoiceTrainId' => $itid
  2992. );
  2993. $receipt->setReceiptByCondition ( $item );
  2994. $invoiceTraining = new invoiceTraining ();
  2995. $item = array (
  2996. 'bindReceipt' => 1,
  2997. 'itid' => $itid
  2998. );
  2999. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3000. $XDeode = new XDeode ( 7 );
  3001. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  3002. } else
  3003. die ( 'illegal request' );
  3004. }
  3005. /**
  3006. * 更新培训班结算 收款和取消收款
  3007. */
  3008. function receiptTrainReceivables() {
  3009. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  3010. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3011. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3012. Doo::loadClass ( 'XDeode' );
  3013. $XDeode = new XDeode ( 5 );
  3014. $rid = $XDeode->decode ( $ridKey );
  3015. $iid = $XDeode->decode ( $iidKey );
  3016. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  3017. die ( 'illegal request-iid' );
  3018. Doo::loadModel ( 'RIExtend' );
  3019. $RIExtend = new RIExtend ();
  3020. if ($doType == 'CONFIRM') {
  3021. $RIExtend->rid = $rid;
  3022. $RIExtend->iid = $iid;
  3023. $RIExtend->RIstatus = 1;
  3024. $RIExtend->insert ();
  3025. echo json_encode ( array (
  3026. 'status' => 1,
  3027. ) );
  3028. die ( );
  3029. } elseif ($doType == 'CANCEL') {
  3030. $RIExtend->delete ( array (
  3031. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  3032. 'limit' => 1
  3033. ) );
  3034. echo json_encode ( array (
  3035. 'status' => 1,
  3036. ) );
  3037. die ( );
  3038. } else {
  3039. echo json_encode ( array (
  3040. 'status' => 2,
  3041. ) );
  3042. die ( );
  3043. }
  3044. }
  3045. /**
  3046. * 移除挂钩的培训班发票
  3047. */
  3048. function receiptTrainReceivablesDelDo() {
  3049. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3050. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  3051. Doo::loadModel ( 'receipt' );
  3052. $receipt = new receipt ();
  3053. Doo::loadModel ( 'RIExtend' );
  3054. $RIExtend = new RIExtend ();
  3055. Doo::loadClass ( 'XDeode' );
  3056. $XDeode = new XDeode ( 5 );
  3057. $rid = $XDeode->decode ( $ridKey );
  3058. $itid = $XDeode->decode ( $itidKey );
  3059. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  3060. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3061. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3062. die ( 'illegal request-status' );
  3063. }
  3064. $receipt = new receipt ();
  3065. $receipt->rid = $rid;
  3066. $receipt->invoiceTrainId = 0;
  3067. $receipt->update ();
  3068. Doo::loadModel ( 'invoiceTraining' );
  3069. $invoiceTraining = new invoiceTraining ();
  3070. $item = array (
  3071. 'bindReceipt' => 0,
  3072. 'itid' => $itid
  3073. );
  3074. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3075. $RIExtend->delete ( array (
  3076. 'where' => 'rid=' . $rid
  3077. ) );
  3078. $XDeode = new XDeode ( 7 );
  3079. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  3080. } else
  3081. die ( 'illegal request-iid' );
  3082. }
  3083. /**
  3084. * 编辑培训班结算
  3085. */
  3086. function receiptTrainItemEdi() {
  3087. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3088. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3089. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  3090. Doo::loadClass ( 'XDeode' );
  3091. $XDeode = new XDeode ( 7 );
  3092. $rid = $XDeode->decode ( $ridKey );
  3093. if (! is_numeric ( $rid ))
  3094. die ( 'illegal request' );
  3095. Doo::loadModel ( 'receipt' );
  3096. $receipt = new receipt ();
  3097. Doo::loadModel ( 'receiptTraining' );
  3098. $receiptTraining = new receiptTraining ();
  3099. Doo::loadModel ( 'RItem' );
  3100. $RItem = new RItem ();
  3101. Doo::loadModel ( 'accountItem' );
  3102. $accountItem = new accountItem ();
  3103. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3104. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3105. die ();
  3106. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3107. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  3108. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  3109. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  3110. // if($value['name']=='税款'){
  3111. // unset($aiList[$key]);break;
  3112. // }
  3113. // }
  3114. //print_r($RItemList);
  3115. $data ['name'] = $name;
  3116. $data ['RItemList'] = $RItemList;
  3117. $data ['aiList'] = $aiList;
  3118. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3119. $data ['receiptDetail'] = $receiptDetail;
  3120. $data ['trainEdiType'] = "ITEM";
  3121. $data ['ridKey'] = $ridKey;
  3122. $data ['memu'] = "receipt";
  3123. $data ['staff'] = $this->staff;
  3124. $data ['receiptMemu'] = 'saeaBorad';
  3125. $data ['verifyId'] = $this->verifyId;
  3126. $data ['executeId'] = $this->executeId;
  3127. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  3128. }
  3129. /**
  3130. * 添加支出项 需要修改 费用金额合计
  3131. */
  3132. function receiptTrainItemAddDo() {
  3133. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3134. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  3135. // 支出项信息
  3136. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3137. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  3138. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3139. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  3140. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  3141. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  3142. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  3143. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  3144. Doo::loadClass ( 'XDeode' );
  3145. $XDeode = new XDeode ( 5 );
  3146. Doo::loadModel ( 'RItem' );
  3147. $RItem = new RItem ();
  3148. $rid = $XDeode->decode ( $ridKey );
  3149. $rtid= $XDeode->decode ( $rtidKey );
  3150. if (! is_numeric ( $rid )){
  3151. die ( 'illegal request' );
  3152. }
  3153. Doo::loadModel ( 'receiptDetail' );
  3154. $receiptDetail = new receiptDetail ();
  3155. Doo::loadModel ( 'receipt' );
  3156. $receipt = new receipt ();
  3157. Doo::loadModel ( 'receiptTraining' );
  3158. $receiptTraining = new receiptTraining ();
  3159. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  3160. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  3161. $order = array (
  3162. "\r\n",
  3163. "\n",
  3164. "\r"
  3165. );
  3166. $replace = '<br/>';
  3167. $describe = str_replace ( $order, $replace, $describe );
  3168. $itemData = array (
  3169. 'rid' => $rid,
  3170. 'item' => $item,
  3171. 'price' => $price,
  3172. 'date' => $date,
  3173. 'inputer' => $inputer,
  3174. 'describe' => $describe,
  3175. 'creater' => $this->staff['0']['username'],
  3176. 'createrId' => $this->staff['0']['sid'],
  3177. 'creatDate' => date ( "Y-m-d H:i:s" ),
  3178. 'identifying'=>$identifyingTotal
  3179. );
  3180. if($payType=='company'){
  3181. $itemData += array (
  3182. 'payType' => 1
  3183. );
  3184. }
  3185. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  3186. //更新支出项标识总数
  3187. $itemData = array (
  3188. 'rtid'=>$rtid,
  3189. 'identifyingTotal'=>$identifyingTotal
  3190. );
  3191. $receiptTraining->setReceiptTrainByCondition($itemData);
  3192. $XDeode = new XDeode ( 7 );
  3193. if($payType=='company'){
  3194. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  3195. }else{
  3196. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  3197. }
  3198. } else
  3199. die ( 'illegal request-dataError' );
  3200. }
  3201. /**
  3202. * 培训班结算-讲师
  3203. */
  3204. function receiptTrainLecturerEdi() {
  3205. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3206. Doo::loadClass ( 'XDeode' );
  3207. $XDeode = new XDeode ( 7 );
  3208. $rid = $XDeode->decode ( $ridKey );
  3209. if (! is_numeric ( $rid ))
  3210. die ( 'illegal request' );
  3211. Doo::loadModel ( 'receipt' );
  3212. $receipt = new receipt ();
  3213. Doo::loadModel ( 'receiptTraining' );
  3214. $receiptTraining = new receiptTraining ();
  3215. Doo::loadModel ( 'RILecturer' );
  3216. $RILecturer = new RILecturer ();
  3217. Doo::loadModel ( 'lecturer' );
  3218. $lecturer = new lecturer ();
  3219. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3220. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3221. die ();
  3222. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3223. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3224. $lecturerList = $lecturer->getLecturerAll ();
  3225. $INSIDEhtml = $OUTSIDEhtml = '';
  3226. foreach ( $lecturerList as $key => $value ) {
  3227. if ($value ['ltype'] == 'INSIDE') {
  3228. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  3229. } elseif ($value ['ltype'] == 'OUTSIDE') {
  3230. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  3231. }
  3232. }
  3233. $data ['INSIDEhtml'] = $INSIDEhtml;
  3234. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  3235. // print_r($RItemList);
  3236. $data ['RILecturerList'] = $RILecturerList;
  3237. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3238. $data ['receiptDetail'] = $receiptDetail;
  3239. $data ['trainEdiType'] = "LECTURER";
  3240. $data ['ridKey'] = $ridKey;
  3241. $data ['memu'] = "receipt";
  3242. $data ['staff'] = $this->staff;
  3243. $data ['receiptMemu'] = 'saeaBorad';
  3244. $data ['verifyId'] = $this->verifyId;
  3245. $data ['executeId'] = $this->executeId;
  3246. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  3247. }
  3248. /**
  3249. * 添加讲师
  3250. */
  3251. function receiptTrainLecturerAddDo() {
  3252. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3253. // 支出项信息
  3254. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  3255. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  3256. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  3257. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  3258. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  3259. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  3260. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  3261. Doo::loadClass ( 'XDeode' );
  3262. $XDeode = new XDeode ( 5 );
  3263. Doo::loadModel ( 'RILecturer' );
  3264. $RILecturer = new RILecturer ();
  3265. $rid = $XDeode->decode ( $ridKey );
  3266. if (! is_numeric ( $rid ))
  3267. die ( 'illegal request' );
  3268. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  3269. die ( 'illegal request-taxationError' );
  3270. $RILecturer->rid = $rid;
  3271. $RILecturer->ltype = $ltype;
  3272. if ($ltype == 'OUTSIDE') {
  3273. if ($taxation == 'TAXATION') {
  3274. $RILecturer->taxation = 1;
  3275. } elseif ($taxation == 'NOTAXATION') {
  3276. $RILecturer->taxation = 0;
  3277. }
  3278. }
  3279. $RILecturer->lecturerName = $lecturerName;
  3280. $RILecturer->schoolDay = $schoolDay;
  3281. $RILecturer->price = $price;
  3282. $RILecturer->fees=$fees;
  3283. $RILecturer->insert ();
  3284. // 添加公司汇总
  3285. // 报销详情
  3286. Doo::loadModel ( 'receiptDetail' );
  3287. $receiptDetail = new receiptDetail ();
  3288. Doo::loadModel ( 'receipt' );
  3289. $receipt = new receipt ();
  3290. // 金额总计
  3291. $price = $price * $schoolDay;
  3292. $rInfo = $receipt->getReceiptByRid ( $rid );
  3293. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3294. if (empty ( $rdInfo )) {
  3295. $receiptDetail = new receiptDetail ();
  3296. $receiptDetail->staff = $rInfo ['staff'];
  3297. $receiptDetail->item = '讲课费';
  3298. $receiptDetail->itemCategory = '培训班费用';
  3299. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  3300. $receiptDetail->date = date ( "Y-m-d" );
  3301. $receiptDetail->cid = $rInfo ['cid'];
  3302. $receiptDetail->rid = $rid;
  3303. $receiptDetail->status = 4;
  3304. $receiptDetail->insert ();
  3305. } else {
  3306. $receiptDetail = new receiptDetail ();
  3307. $rdInfo ['price'] += $fees;
  3308. $receiptDetail->price = $rdInfo ['price'];
  3309. $receiptDetail->update ( array (
  3310. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3311. ) );
  3312. }
  3313. $receipt = new receipt ();
  3314. $receipt->sum=$rInfo['sum']+$fees;
  3315. $receipt->update ( array (
  3316. 'where' => 'rid=' . $rid
  3317. ) );
  3318. $XDeode = new XDeode ( 7 );
  3319. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3320. } else
  3321. die ( 'illegal request' );
  3322. }
  3323. /**
  3324. * 移除讲师
  3325. */
  3326. function receiptTrainLecturerDelDo() {
  3327. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3328. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  3329. Doo::loadModel ( 'receipt' );
  3330. $receipt = new receipt ();
  3331. Doo::loadModel ( 'RILecturer' );
  3332. $RILecturer = new RILecturer ();
  3333. Doo::loadClass ( 'XDeode' );
  3334. $XDeode = new XDeode ( 5 );
  3335. $rid = $XDeode->decode ( $ridKey );
  3336. $rlid = $XDeode->decode ( $rlidKey );
  3337. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  3338. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3339. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3340. die ( 'illegal request-status' );
  3341. }
  3342. $detail=$RILecturer->getRILecturerByRlid($rlid);
  3343. if (empty($detail)){
  3344. die ( 'illegal request-data' );
  3345. }
  3346. $RILecturer->delete ( array (
  3347. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  3348. ) );
  3349. //更新费用合计金额
  3350. $rInfo = $receipt->getReceiptByRid ( $rid );
  3351. $receipt = new receipt ();
  3352. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  3353. $receipt->update ( array (
  3354. 'where' => 'rid=' . $rid
  3355. ) );
  3356. Doo::loadModel ( 'receiptDetail' );
  3357. $receiptDetail = new receiptDetail ();
  3358. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3359. $receiptDetail = new receiptDetail ();
  3360. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  3361. $receiptDetail->price = $rdInfo ['price'];
  3362. $receiptDetail->update ( array (
  3363. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3364. ) );
  3365. $XDeode = new XDeode ( 7 );
  3366. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3367. } else
  3368. die ( 'illegal request-iid' );
  3369. }
  3370. /**
  3371. * 培训班提交审批
  3372. */
  3373. function receiptTrainDo() {
  3374. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3375. Doo::loadClass ( 'XDeode' );
  3376. $XDeode = new XDeode ( 7 );
  3377. $rid = $XDeode->decode ( $ridKey );
  3378. Doo::loadModel ( 'receipt' );
  3379. $receipt = new receipt ();
  3380. Doo::loadModel ( 'receiptDetail' );
  3381. $receiptDetail = new receiptDetail ();
  3382. Doo::loadModel ( 'statistics' );
  3383. $statistics = new statistics ();
  3384. Doo::loadModel ( "verify" );
  3385. $verify = new verify ();
  3386. // 审批状态的判定
  3387. $receiptDetailList = $receipt->getOne ( array (
  3388. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  3389. 'asArray' => true
  3390. ) );
  3391. if (empty ( $receiptDetailList ))
  3392. return "/saeaBorad";
  3393. $verifyDetail = $verify->getOne ( array (
  3394. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3395. 'asArray' => true
  3396. ) );
  3397. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3398. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3399. $nowStaff = "";
  3400. $nowStaffList = array ();
  3401. if ($verifyDetail [0] [1] == 'ROLE') {
  3402. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3403. foreach ( $vStaffString as $key => $value ) {
  3404. $staffK = explode ( "_", $value );
  3405. array_push ( $nowStaffList, $staffK [0] );
  3406. }
  3407. $nowStaff = implode ( ',', $nowStaffList );
  3408. } else {
  3409. $nowStaff = $verifyDetail [0] [0];
  3410. }
  3411. $receipt->nowStaff = $nowStaff;
  3412. }
  3413. // echo $nowStaff;
  3414. // print_r($verifyDetail);die;
  3415. $receipt->rid = $receiptDetailList ['rid'];
  3416. $receipt->date = date ( "Y-m-d" );
  3417. $receipt->status = 2;
  3418. $receipt->update ();
  3419. $receiptDetail->status = 2;
  3420. $receiptDetail->update ( array (
  3421. 'where' => 'rid=' . $receiptDetailList ['rid']
  3422. ) );
  3423. Doo::loadModel ( "receiptLog" );
  3424. $receiptLog = new receiptLog ();
  3425. Doo::loadModel ( "verify" );
  3426. $verify = new verify ();
  3427. $vr = $verify->getOne ( array (
  3428. 'where' => 'vid=' . $receiptDetailList ['verify'],
  3429. 'asArray' => true
  3430. ) );
  3431. $jd = json_decode ( $vr ['staff'] );
  3432. $roleId = 0;
  3433. foreach ( $jd as $key => $value ) {
  3434. if ($value [1] == 'ROLE') {
  3435. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3436. if ($pos !== false) {
  3437. $roleId = $value [0];
  3438. }
  3439. }
  3440. }
  3441. // 审批日志
  3442. // echo $roleId;die;
  3443. if (! empty ( $roleId )) {
  3444. Doo::loadModel ( "role" );
  3445. $role = new role ();
  3446. $roleInfo = $role->getOne ( array (
  3447. 'where' => 'rid=' . $roleId,
  3448. 'asArray' => true
  3449. ) );
  3450. // $receiptLog->rolename = $roleInfo ['name'];
  3451. }
  3452. $receiptLog->username = $this->staff [0] ['username'];
  3453. $receiptLog->uid = $this->staff [0] ['sid'];
  3454. $receiptLog->date = date ( "Y-m-d" );
  3455. $receiptLog->opinion = '提交审批';
  3456. $receiptLog->img = $this->staff [0] ['avatar'];
  3457. $receiptLog->status = 2;
  3458. $receiptLog->rid = $rid;
  3459. $receiptLog->insert ();
  3460. // 写入列表项
  3461. Doo::loadModel ( 'accountItem' );
  3462. $accountItem = new accountItem ();
  3463. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  3464. // 项目金额合计
  3465. Doo::loadModel ( 'RItem' );
  3466. $RItem = new RItem ();
  3467. // 讲师获得
  3468. Doo::loadModel ( 'RILecturer' );
  3469. $RILecturer = new RILecturer ();
  3470. $RItemList = $RItem->getRItemByRid ( $rid );
  3471. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3472. // 支出项金额详情
  3473. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  3474. // print_r($aItem);
  3475. // print_r($aiData);
  3476. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  3477. $ag = $tr = $ta = $ot = 0;
  3478. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  3479. foreach ( $aItem as $key => $value ) {
  3480. if ($value ['category'] == $this->TRAIN) {
  3481. foreach ( $aiData ['dataList'] as $k => $v ) {
  3482. if ($value ['name'] == $v ['name']) {
  3483. array_push ( $accountJson [$this->TRAIN], array (
  3484. 'aid' => $value ['aid'],
  3485. 'name' => $value ['name'],
  3486. 'price' => number_format ( $v ['price'], 2, '.', '' )
  3487. ) );
  3488. $sum += $v ['price'];
  3489. $trainSum += $v ['price'];
  3490. unset ( $aiData ['dataList'] [$k] );
  3491. break;
  3492. }
  3493. }
  3494. }
  3495. }
  3496. $accountJson ['cSum'] = array (
  3497. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  3498. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  3499. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  3500. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  3501. );
  3502. // 报销单
  3503. $receipt = new receipt ();
  3504. $receipt->accountItem = json_encode ( $accountJson );
  3505. $receipt->sum = number_format ( $sum, 2, '.', '' );
  3506. $receipt->update ( array (
  3507. 'where' => 'rid=' . $rid
  3508. ) );
  3509. // print_r($accountJson);
  3510. // statistics item 统计写入
  3511. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  3512. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  3513. $accountItem = $accountJson;
  3514. $stat = $statistics->getOne ( array (
  3515. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3516. 'asArray' => true
  3517. ) );
  3518. if (empty ( $stat )) {
  3519. $statistics->date = date ( "Y-m-d" );
  3520. $statistics->cid = $this->staff [0] ['cid'];
  3521. $statistics->staff = $this->staff [0] ['sid'];
  3522. $statistics->agPrice = 0;
  3523. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3524. $statistics->insert ();
  3525. } else {
  3526. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3527. $statistics->update ( array (
  3528. 'where' => 'sid=' . $stat ['sid']
  3529. ) );
  3530. }
  3531. return "/saeaBorad";
  3532. }
  3533. function confirmation() {
  3534. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3535. Doo::loadModel ( 'receipt' );
  3536. Doo::loadModel ( 'receiptDetail' );
  3537. $receipt = new receipt ();
  3538. $receiptDetail = new receiptDetail ();
  3539. Doo::loadModel ( 'statistics' );
  3540. Doo::loadModel ( 'itemStatistics' );
  3541. $statistics = new statistics ();
  3542. $itemStatistics = new itemStatistics ();
  3543. Doo::loadModel ( "verify" );
  3544. $verify = new verify ();
  3545. $receiptDetailList = $receipt->getOne ( array (
  3546. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  3547. 'asArray' => true
  3548. ) );
  3549. if (empty ( $receiptDetailList ))
  3550. return "/saeaBorad";
  3551. $verifyDetail = $verify->getOne ( array (
  3552. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3553. 'asArray' => true
  3554. ) );
  3555. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3556. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3557. $nowStaff = "";
  3558. $nowStaffList = array ();
  3559. if ($verifyDetail [0] [1] == 'ROLE') {
  3560. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3561. foreach ( $vStaffString as $key => $value ) {
  3562. $staffK = explode ( "_", $value );
  3563. array_push ( $nowStaffList, $staffK [0] );
  3564. }
  3565. $nowStaff = implode ( ',', $nowStaffList );
  3566. } else {
  3567. $nowStaff = $verifyDetail [0] [0];
  3568. }
  3569. $receipt->nowStaff = $nowStaff;
  3570. }
  3571. // echo $nowStaff;
  3572. // print_r($verifyDetail);die;
  3573. $receipt->rid = $receiptDetailList ['rid'];
  3574. $receipt->status = 2;
  3575. $receipt->update ();
  3576. // 操作日志
  3577. Doo::loadModel ( "receiptLog" );
  3578. $receiptLog = new receiptLog ();
  3579. $verify = new verify ();
  3580. $receiptInfo = $receipt->getOne ( array (
  3581. 'where' => 'rid=' . $rid,
  3582. 'asArray' => true
  3583. ) );
  3584. $vr = $verify->getOne ( array (
  3585. 'where' => 'vid=' . $receiptInfo ['verify'],
  3586. 'asArray' => true
  3587. ) );
  3588. $jd = json_decode ( $vr ['staff'] );
  3589. $roleId = 0;
  3590. foreach ( $jd as $key => $value ) {
  3591. if ($value [1] == 'ROLE') {
  3592. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3593. if ($pos !== false) {
  3594. $roleId = $value [0];
  3595. }
  3596. }
  3597. }
  3598. // 审批日志
  3599. // echo $roleId;die;
  3600. if (! empty ( $roleId )) {
  3601. Doo::loadModel ( "role" );
  3602. $role = new role ();
  3603. $roleInfo = $role->getOne ( array (
  3604. 'where' => 'rid=' . $roleId,
  3605. 'asArray' => true
  3606. ) );
  3607. // $receiptLog->rolename = $roleInfo ['name'];
  3608. }
  3609. $receiptLog->username = $this->staff [0] ['username'];
  3610. $receiptLog->uid = $this->staff [0] ['sid'];
  3611. $receiptLog->date = date ( "Y-m-d" );
  3612. $receiptLog->opinion = '提交审批';
  3613. $receiptLog->img = $this->staff [0] ['avatar'];
  3614. $receiptLog->status = 2;
  3615. $receiptLog->rid = $rid;
  3616. $receiptLog->insert ();
  3617. return "/expenses";
  3618. }
  3619. function expenses() {
  3620. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  3621. if (empty ( $item ))
  3622. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3623. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3624. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  3625. Doo::loadClass ( 'XDeode' );
  3626. $XDeode = new XDeode ( 7 );
  3627. Doo::loadModel ( 'receipt' );
  3628. $receipt = new receipt ();
  3629. Doo::loadModel ( 'L_category' );
  3630. $Lcategory = new L_category ();
  3631. Doo::loadModel ( 'verify' );
  3632. Doo::loadModel ( 'statistics' );
  3633. $statistics = new statistics ();
  3634. $verify = new verify ();
  3635. Doo::loadModel ( 'staff' );
  3636. $staff = new staff ();
  3637. $condition = "";
  3638. if ($item == "expenses")
  3639. $condition = " and Rtype=1 ";
  3640. elseif ($item == "receipts")
  3641. $condition = " and Rtype=0 ";
  3642. elseif ($item == "remits")
  3643. $condition = " and Rtype=2 ";
  3644. elseif ($item == "train")
  3645. $condition = " and Rtype=3 ";
  3646. $dateCondition = " and Year(date) =" . $year;
  3647. if (! empty ( $moth )) {
  3648. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  3649. $stList = $statistics->getOne ( array (
  3650. 'select' => 'rePrice ,agPrice',
  3651. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3652. 'asArray' => true
  3653. ) );
  3654. } else
  3655. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  3656. if (empty ( $stList ))
  3657. $stList = array (
  3658. 'rePrice' => 0,
  3659. 'agPrice' => 0
  3660. );
  3661. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3662. if (! isset ( $noPassSum ['sum'] ))
  3663. $noPassSum ['sum'] = 0;
  3664. $data ['stList'] = array (
  3665. 'rePrice' => $stList ['rePrice'],
  3666. 'agPrice' => $stList ['agPrice'],
  3667. 'skPrice' => ($noPassSum ['sum'])
  3668. );
  3669. $receiptList = $receipt->find ( array (
  3670. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3671. 'desc' => 'rid',
  3672. 'asArray' => true
  3673. ) );
  3674. $Locate = 0;
  3675. $roleId = 0;
  3676. $button = 0;
  3677. foreach ( $receiptList as $key => $value ) {
  3678. $receiptList[$key]['balance']='';
  3679. if($value['Rtype']==1){
  3680. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3681. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3682. }elseif($value['Rtype']==3){
  3683. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3684. $receiptList[$key]['payment']=$payment;
  3685. $receiptList[$key]['paymentABS']=abs($payment);
  3686. }
  3687. $receiptList [$key] ['Locate'] = $Locate;
  3688. $Locate ++;
  3689. $receiptList [$key] ['reviseDetail'] = array ();
  3690. if (! empty ( $value ['reviseDetail'] ))
  3691. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3692. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3693. $categoryDetil = $Lcategory->getOne ( array (
  3694. 'where' => 'cid=' . $value ['cid'],
  3695. 'asArray' => true
  3696. ) );
  3697. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3698. // 检测编辑状态
  3699. $verifyList = $verify->getOne ( array (
  3700. 'where' => 'vid=' . $value ['verify'],
  3701. 'asArray' => true
  3702. ) );
  3703. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3704. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3705. Doo::loadModel ( 'role' );
  3706. $role = new role ();
  3707. $flag = true;
  3708. $roleKey = 0;
  3709. $endStaffArray = array ();
  3710. $roleArrayCopy = array ();
  3711. foreach ( $verifyList as $k => $v ) {
  3712. // init verifyStaff
  3713. if ($v [1] == 'ROLE') {
  3714. if (! empty ( $verifyStaff )) {
  3715. $endStaffArray = end ( $verifyStaff );
  3716. // if ($v[0]==$endStaffArray['nextStaff']){
  3717. // $roleId=$v[0];
  3718. // }
  3719. }
  3720. $roleVerify = json_decode ( $v [3], true );
  3721. $roleKey = $k;
  3722. $roleArray = array ();
  3723. $rolename = $role->getOne ( array (
  3724. 'where' => 'rid=' . $v [0],
  3725. 'asArray' => true
  3726. ) );
  3727. foreach ( $roleVerify as $o => $p ) {
  3728. $staffID = explode ( '_', $p );
  3729. $staffInfo = $staff->getOne ( array (
  3730. 'where' => 'sid=' . $staffID [0],
  3731. 'asArray' => true
  3732. ) );
  3733. // print_r($staffID);
  3734. $exp = array (
  3735. 0 => $staffInfo ['sid'],
  3736. 1 => $staffID [1],
  3737. 2 => $staffInfo ['avatar'],
  3738. 'date' => '',
  3739. 'date' => '',
  3740. 'opinion' => '',
  3741. 'status' => '',
  3742. 'rolename' => $rolename ['name']
  3743. );
  3744. array_push ( $roleArray, $exp );
  3745. }
  3746. $roleArrayCopy [$v [0]] = $roleArray;
  3747. // $verifyList[$k]['roleArray']=$roleArray;
  3748. }
  3749. $verifyList [$k] ['date'] = "";
  3750. $verifyList [$k] ['opinion'] = "";
  3751. $verifyList [$k] ['status'] = "";
  3752. if (empty ( $verifyStaff )) {
  3753. $verifyList [$k] ['date'] = "";
  3754. $verifyList [$k] ['opinion'] = "";
  3755. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3756. $verifyList [$k] ['status'] = 4;
  3757. $flag = false;
  3758. }
  3759. } else {
  3760. foreach ( $verifyStaff as $m => $u ) {
  3761. if ($v [0] == $m) {
  3762. $verifyList [$k] ['date'] = $u ['date'];
  3763. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3764. $verifyList [$k] ['status'] = $u ['status'];
  3765. $flag = false;
  3766. break;
  3767. }
  3768. }
  3769. $endStaffArray = end ( $verifyStaff );
  3770. if (isset ( $endStaffArray ['ROLE'] )) {
  3771. } else {
  3772. // $endKey=key($verifyStaff);
  3773. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3774. // $button=4;
  3775. // $verifyList[$k]['status']=4;
  3776. // }
  3777. }
  3778. }
  3779. }
  3780. $rolename ['name'] = '';
  3781. if (! empty ( $roleId )) {
  3782. Doo::loadModel ( 'role' );
  3783. $role = new role ();
  3784. $rolename = $role->getOne ( array (
  3785. 'where' => 'rid=' . $roleId,
  3786. 'asArray' => true
  3787. ) );
  3788. }
  3789. if (! empty ( $verifyStaff ))
  3790. $endStaffArray = end ( $verifyStaff );
  3791. $KOP = false;
  3792. foreach ( $roleArrayCopy as $P => $A ) {
  3793. foreach ( $A as $MKI => $AVL ) {
  3794. if (! empty ( $verifyStaff )) {
  3795. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3796. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3797. $button = 4;
  3798. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3799. }
  3800. foreach ( $verifyStaff as $m => $u ) {
  3801. $AVLFK = $AVL [0] . '_R';
  3802. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3803. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3804. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3805. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3806. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3807. break;
  3808. }
  3809. }
  3810. } else {
  3811. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3812. $button = 4;
  3813. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3814. }
  3815. }
  3816. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3817. $KOP = true;
  3818. }
  3819. }
  3820. foreach ( $roleArrayCopy as $k => $v ) {
  3821. foreach ( $verifyList as $m => $n ) {
  3822. if ($n [0] == $k) {
  3823. array_splice ( $verifyList, $m, 1, $v );
  3824. }
  3825. }
  3826. }
  3827. $receiptList [$key] ['verifyList'] = $verifyList;
  3828. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3829. 'where' => 'sid=' . $value ['staff'],
  3830. 'asArray' => true
  3831. ) );
  3832. $receiptList [$key] ['button'] = $button;
  3833. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3834. }
  3835. // print_r($receiptList);die;
  3836. $mothHtml = "";
  3837. for($i = 1; $i <= 12; $i ++) {
  3838. if ($moth == $i)
  3839. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3840. else
  3841. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3842. }
  3843. $dateHtml = "";
  3844. $now = date ( "Y" );
  3845. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3846. if ($YEARD <= $now) {
  3847. $dateHtml .= '<option ';
  3848. if ($year == $YEARD) {
  3849. $dateHtml .= 'selected ';
  3850. }
  3851. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3852. }
  3853. }
  3854. $data ['dateHtml'] = $dateHtml;
  3855. $data ['mothHtml'] = $mothHtml;
  3856. $data ['receiptList'] = $receiptList;
  3857. $data ['memu'] = "receipt";
  3858. $data ['staff'] = $this->staff;
  3859. $data ['receiptMemu'] = 'expenses';
  3860. $data ['verifyId'] = $this->verifyId;
  3861. $data ['executeId'] = $this->executeId;
  3862. $data ['item'] = $item;
  3863. $data ['year'] = $year;
  3864. $this->render ( "/admin/expenses", $data );
  3865. }
  3866. function expensesCollect() {
  3867. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3868. Doo::loadModel ( 'receipt' );
  3869. $receipt = new receipt ();
  3870. Doo::loadModel ( 'L_category' );
  3871. $Lcategory = new L_category ();
  3872. Doo::loadModel ( 'verify' );
  3873. Doo::loadModel ( 'statistics' );
  3874. $statistics = new statistics ();
  3875. $verify = new verify ();
  3876. Doo::loadModel ( 'staff' );
  3877. $staff = new staff ();
  3878. Doo::loadModel ( 'loanReceipt' );
  3879. $loanReceipt = new loanReceipt ();
  3880. $receiptList = $receipt->find ( array (//去掉
  3881. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3882. 'desc' => 'rid',
  3883. 'asArray' => true
  3884. ) );
  3885. $loanList = $loanReceipt->find ( array (
  3886. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3887. 'desc' => 'rid',
  3888. 'asArray' => true
  3889. ) );
  3890. /*
  3891. * $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;
  3892. */
  3893. $data ['explanation'] = '';
  3894. if (! empty ( $loanList ))
  3895. $data ['explanation'] = $loanList [0] ['explanation'];
  3896. $Locate = 0;
  3897. $roleId = 0;
  3898. $button = 0;
  3899. foreach ( $receiptList as $key => $value ) {
  3900. $receiptList [$key] ['Locate'] = $Locate;
  3901. $Locate ++;
  3902. $receiptList [$key] ['reviseDetail'] = array ();
  3903. if (! empty ( $value ['reviseDetail'] ))
  3904. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3905. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3906. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3907. $categoryDetil = $Lcategory->getOne ( array (
  3908. 'where' => 'cid=' . $value ['cid'],
  3909. 'asArray' => true
  3910. ) );
  3911. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3912. // 检测编辑状态
  3913. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3914. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3915. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3916. else
  3917. $verifyList ['staff'] = $value ['verifyBreakup'];
  3918. } else
  3919. $verifyList = $verify->getOne ( array (
  3920. 'where' => 'vid=' . $value ['verify'],
  3921. 'asArray' => true
  3922. ) );
  3923. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3924. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3925. Doo::loadModel ( 'role' );
  3926. $role = new role ();
  3927. $flag = true;
  3928. $roleKey = 0;
  3929. $endStaffArray = array ();
  3930. $roleArrayCopy = array ();
  3931. foreach ( $verifyList as $k => $v ) {
  3932. // init verifyStaff
  3933. if ($v [1] == 'ROLE') {
  3934. if (! empty ( $verifyStaff )) {
  3935. $endStaffArray = end ( $verifyStaff );
  3936. // if ($v[0]==$endStaffArray['nextStaff']){
  3937. // $roleId=$v[0];
  3938. // }
  3939. }
  3940. $roleVerify = json_decode ( $v [3], true );
  3941. $roleKey = $k;
  3942. $roleArray = array ();
  3943. $rolename = $role->getOne ( array (
  3944. 'where' => 'rid=' . $v [0],
  3945. 'asArray' => true
  3946. ) );
  3947. foreach ( $roleVerify as $o => $p ) {
  3948. $staffID = explode ( '_', $p );
  3949. $staffInfo = $staff->getOne ( array (
  3950. 'where' => 'sid=' . $staffID [0],
  3951. 'asArray' => true
  3952. ) );
  3953. // print_r($staffID);
  3954. $exp = array (
  3955. 0 => $staffInfo ['sid'],
  3956. 1 => $staffID [1],
  3957. 2 => $staffInfo ['avatar'],
  3958. 'date' => '',
  3959. 'date' => '',
  3960. 'opinion' => '',
  3961. 'status' => '',
  3962. 'rolename' => $rolename ['name']
  3963. );
  3964. array_push ( $roleArray, $exp );
  3965. }
  3966. $roleArrayCopy [$v [0]] = $roleArray;
  3967. // $verifyList[$k]['roleArray']=$roleArray;
  3968. }
  3969. $verifyList [$k] ['date'] = "";
  3970. $verifyList [$k] ['opinion'] = "";
  3971. $verifyList [$k] ['status'] = "";
  3972. if (empty ( $verifyStaff )) {
  3973. $verifyList [$k] ['date'] = "";
  3974. $verifyList [$k] ['opinion'] = "";
  3975. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3976. $verifyList [$k] ['status'] = 4;
  3977. $flag = false;
  3978. }
  3979. } else {
  3980. foreach ( $verifyStaff as $m => $u ) {
  3981. if ($v [0] == $m) {
  3982. $verifyList [$k] ['date'] = $u ['date'];
  3983. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3984. $verifyList [$k] ['status'] = $u ['status'];
  3985. $flag = false;
  3986. break;
  3987. }
  3988. }
  3989. $endStaffArray = end ( $verifyStaff );
  3990. if (isset ( $endStaffArray ['ROLE'] )) {
  3991. } else {
  3992. // $endKey=key($verifyStaff);
  3993. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3994. // $button=4;
  3995. // $verifyList[$k]['status']=4;
  3996. // }
  3997. }
  3998. }
  3999. }
  4000. $rolename ['name'] = '';
  4001. if (! empty ( $roleId )) {
  4002. Doo::loadModel ( 'role' );
  4003. $role = new role ();
  4004. $rolename = $role->getOne ( array (
  4005. 'where' => 'rid=' . $roleId,
  4006. 'asArray' => true
  4007. ) );
  4008. }
  4009. if (! empty ( $verifyStaff ))
  4010. $endStaffArray = end ( $verifyStaff );
  4011. $KOP = false;
  4012. foreach ( $roleArrayCopy as $P => $A ) {
  4013. foreach ( $A as $MKI => $AVL ) {
  4014. if (! empty ( $verifyStaff )) {
  4015. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4016. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4017. $button = 4;
  4018. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4019. }
  4020. foreach ( $verifyStaff as $m => $u ) {
  4021. $AVLFK = $AVL [0] . '_R';
  4022. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4023. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4024. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4025. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4026. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4027. break;
  4028. }
  4029. }
  4030. } else {
  4031. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4032. $button = 4;
  4033. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4034. }
  4035. }
  4036. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4037. $KOP = true;
  4038. }
  4039. }
  4040. foreach ( $roleArrayCopy as $k => $v ) {
  4041. foreach ( $verifyList as $m => $n ) {
  4042. if ($n [0] == $k) {
  4043. array_splice ( $verifyList, $m, 1, $v );
  4044. }
  4045. }
  4046. }
  4047. // 费用执行人相关数据
  4048. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4049. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4050. foreach ( $executeCopy as $k => $v ) {
  4051. $executeCopy [$k] ['date'] = '';
  4052. $executeCopy [$k] ['opinion'] = '';
  4053. $executeCopy [$k] ['status'] = '';
  4054. if (! empty ( $executeStaff ))
  4055. foreach ( $executeStaff as $m => $u ) {
  4056. if ($v [0] == $m) {
  4057. $executeCopy [$k] ['date'] = $u ['date'];
  4058. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4059. $executeCopy [$k] ['status'] = $u ['status'];
  4060. break;
  4061. }
  4062. }
  4063. }
  4064. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4065. $receiptList [$key] ['verifyList'] = $verifyList;
  4066. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4067. 'where' => 'sid=' . $value ['staff'],
  4068. 'asArray' => true
  4069. ) );
  4070. $receiptList [$key] ['button'] = $button;
  4071. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4072. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4073. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4074. $receiptList [$key] ['relust'] = $relust;
  4075. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4076. }
  4077. Doo::loadModel ( 'enclosur' );
  4078. $enclosur = new enclosur ();
  4079. $enclosurList = $enclosur->find ( array (
  4080. 'where' => 'rid=' . $rid,
  4081. 'asArray' => true
  4082. ) );
  4083. $enclosurHtml = '';
  4084. foreach ( $enclosurList as $value ) {
  4085. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4086. }
  4087. $data ['enclosurHtml'] = $enclosurHtml;
  4088. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  4089. $data ['receiptList'] = $receiptList;
  4090. $data ['memu'] = "receipt";
  4091. $data ['staff'] = $this->staff;
  4092. $data ['receiptMemu'] = 'expenses';
  4093. $data ['verifyId'] = $this->verifyId;
  4094. $data ['executeId'] = $this->executeId;
  4095. $this->render ( "/admin/expensesCollect", $data );
  4096. }
  4097. function approvalExpenses() {
  4098. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  4099. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4100. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4101. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4102. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4103. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  4104. // echo $rdate;
  4105. if (empty ( $status ))
  4106. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4107. $page_size = 8;
  4108. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4109. $vidList = array ();
  4110. $button = 0;
  4111. Doo::loadModel ( 'verify' );
  4112. $verify = new verify ();
  4113. Doo::loadModel ( 'receipt' );
  4114. $receipt = new receipt ();
  4115. Doo::loadModel ( 'staff' );
  4116. $staff = new staff ();
  4117. Doo::loadModel ( 'L_category' );
  4118. $Lcategory = new L_category ();
  4119. // user verify ID
  4120. $verifyDetail = $verify->find ( array (
  4121. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4122. 'asArray' => true
  4123. ) );
  4124. foreach ( $verifyDetail as $key => $value ) {
  4125. array_push ( $vidList, $value ['vid'] );
  4126. }
  4127. $vid = implode ( ",", $vidList );
  4128. if (empty ( $verifyDetail ))
  4129. $vid = 0;
  4130. // if ($status==0)
  4131. // $dateCondition="";
  4132. // else
  4133. $dateCondition = " ";
  4134. // if (! empty ( $month ))
  4135. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  4136. if ($status == 'done' || $status == 'termination') {
  4137. if (! empty ( $year )) {
  4138. $dateCondition = " and Year(pastDate) =" . $year;
  4139. if (! empty ( $month ))
  4140. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4141. }
  4142. } elseif ($status == 'finish') {
  4143. if (! empty ( $year )) {
  4144. $dateCondition = " and Year(pastDate) =" . $year;
  4145. if (! empty ( $month ))
  4146. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4147. }
  4148. }
  4149. // date ( 'Y-m' )
  4150. // if (! empty ( $rdate ) && $status == 'done')
  4151. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  4152. // elseif (! empty ( $rdate ))
  4153. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  4154. $categoryList = $Lcategory->find ( array (
  4155. 'asArray' => true
  4156. ) );
  4157. $staffList = $staff->find ( array (
  4158. 'where' => 'cid=' . $cid,
  4159. 'asArray' => true
  4160. ) );
  4161. $cateCondition = "";
  4162. $staffCondition = "";
  4163. $approvalCondition = "";
  4164. if (! empty ( $cid )) {
  4165. $cateCondition = ' and cid=' . $cid;
  4166. }
  4167. if (! empty ( $sid )) {
  4168. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  4169. $cateCondition = "";
  4170. }
  4171. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  4172. if ($status == 'pendApproval') {
  4173. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4174. }
  4175. if ($status == 'ongoing') {
  4176. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  4177. }
  4178. if ($status == 'done') {
  4179. $approvalCondition = ' and (status=8 or status=9 ) ';
  4180. }
  4181. if ($status == 'termination') {
  4182. $approvalCondition = " and status=3";
  4183. }
  4184. if ($status == 'finish') {
  4185. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  4186. }
  4187. $pageinfo ['page'] = array (
  4188. 'previous' => ''
  4189. );
  4190. if(!empty($receiptOrder)){
  4191. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4192. $receiptList = $receipt->find ( array ( // $dateCondition
  4193. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  4194. 'desc' => 'rid',
  4195. 'asArray' => true
  4196. ) );
  4197. }else{
  4198. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  4199. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4200. $receiptList = $receipt->find ( array ( // $dateCondition.
  4201. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4202. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  4203. 'desc' => 'rid',
  4204. 'asArray' => true
  4205. ) );
  4206. } else {
  4207. $receiptList = $receipt->find ( array ( // $dateCondition
  4208. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4209. 'desc' => 'rid',
  4210. 'asArray' => true
  4211. ) );
  4212. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4213. }
  4214. }
  4215. $rLRes = $receipt->find ( array (
  4216. '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 . ')',
  4217. 'desc' => 'rid',
  4218. 'asArray' => true
  4219. ) );
  4220. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4221. // print_r($receiptList);
  4222. Doo::loadClass ( 'XDeode' );
  4223. $XDeode = new XDeode ( 7 );
  4224. $Locate = 0;
  4225. //
  4226. $reportList = $reportCateList = array ();
  4227. foreach ( $receiptList as $key => $value ) {
  4228. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4229. $receiptList [$key] ['Locate'] = $Locate;
  4230. $Locate ++;
  4231. $receiptList [$key] ['reviseDetail'] = array ();
  4232. if (! empty ( $value ['reviseDetail'] ))
  4233. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4234. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4235. $categoryDetil = $Lcategory->getOne ( array (
  4236. 'where' => 'cid=' . $value ['cid'],
  4237. 'asArray' => true
  4238. ) );
  4239. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4240. $verifyList = $verify->getOne ( array (
  4241. 'where' => 'vid=' . $value ['verify'],
  4242. 'asArray' => true
  4243. ) );
  4244. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4245. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4246. foreach ( $verifyList as $k => $v ) {
  4247. // init verifyStaff
  4248. $verifyList [$k] ['date'] = "";
  4249. $verifyList [$k] ['opinion'] = "";
  4250. $verifyList [$k] ['status'] = "";
  4251. if (empty ( $verifyStaff )) {
  4252. $verifyList [$k] ['date'] = "";
  4253. $verifyList [$k] ['opinion'] = "";
  4254. if ($v [0] == $this->staff [0] ['sid']) {
  4255. $verifyList [$k] ['status'] = 4;
  4256. $button = 4;
  4257. }
  4258. } else {
  4259. $flag = true;
  4260. foreach ( $verifyStaff as $m => $u ) {
  4261. if ($v [0] == $m) {
  4262. $verifyList [$k] ['date'] = $u ['date'];
  4263. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4264. $verifyList [$k] ['status'] = $u ['status'];
  4265. $flag = false;
  4266. break;
  4267. }
  4268. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4269. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4270. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4271. }
  4272. if ($flag) { // 检测可编辑
  4273. if ($v [0] == $this->staff [0] ['sid']) {
  4274. $verifyList [$k] ['status'] = 4;
  4275. $button = 4;
  4276. }
  4277. }
  4278. }
  4279. }
  4280. $receiptList [$key] ['verifyList'] = $verifyList;
  4281. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4282. 'where' => 'sid=' . $value ['staff'],
  4283. 'asArray' => true
  4284. ) );
  4285. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4286. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4287. $receiptList [$key] ['button'] = $button;
  4288. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  4289. //获得培训班结算RID 借款费用--已经锁定
  4290. if($value['status']==10){
  4291. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  4292. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  4293. }
  4294. }
  4295. $reportList = array_unique ( $reportList );
  4296. $reportHtml = '';
  4297. foreach ( $reportList as $key => $value ) {
  4298. $v = explode ( "-", $value );
  4299. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  4300. }
  4301. // print_r($reportList)
  4302. $data ['reportHtml'] = $reportHtml;
  4303. $reportCateList = array_unique ( $reportCateList );
  4304. $reportCateHtml = '';
  4305. foreach ( $reportCateList as $key => $value ) {
  4306. $v = explode ( "-", $value );
  4307. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  4308. }
  4309. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  4310. $data ['reportCateHtml'] = $reportCateHtml;
  4311. // print_r($receiptList);die;
  4312. // $data['verifyDetail']=$verifyDetail;
  4313. $mothHtml = "";
  4314. for($i = 1; $i <= 12; $i ++) {
  4315. if ($month == $i)
  4316. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  4317. else
  4318. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  4319. }
  4320. $data ['mothHtml'] = $mothHtml;
  4321. $dateHtml = "";
  4322. $now = date ( "Y" );
  4323. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4324. if ($YEARD <= $now) {
  4325. $dateHtml .= '<option ';
  4326. if ($year == $YEARD) {
  4327. $dateHtml .= 'selected ';
  4328. }
  4329. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4330. }
  4331. }
  4332. $data ['dateHtml'] = $dateHtml;
  4333. $data ['page'] = $pageinfo;
  4334. $data ['receiptList'] = $receiptList;
  4335. $data ['receiptApprovalCount'] = count ( $rLRes );
  4336. $data ['status'] = $status;
  4337. $data ['year'] = $year;
  4338. $data ['month'] = $month;
  4339. $data ['categoryList'] = $categoryList;
  4340. $data ['staffList'] = $staffList;
  4341. $data ['cid'] = $cid;
  4342. $data ['sid'] = $sid;
  4343. // print_r($receiptList);
  4344. $data['receiptOrder']=$receiptOrder;
  4345. $data ['memu'] = "receipt";
  4346. $data ['staff'] = $this->staff;
  4347. $data ['receiptMemu'] = 'approvalExpenses';
  4348. $data ['verifyId'] = $this->verifyId;
  4349. $data ['executeId'] = $this->executeId;
  4350. $this->render ( "/admin/approvalExpenses", $data );
  4351. }
  4352. function expensesDoc() {
  4353. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  4354. Doo::loadClass ( 'XDeode' );
  4355. $XDeode = new XDeode ( 5 );
  4356. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  4357. $rid = $XDeode->decode ( $rid );
  4358. if (! is_numeric ( $rid ))
  4359. die ( 'illegal request' );
  4360. Doo::loadModel ( 'receipt' );
  4361. $receipt = new receipt ();
  4362. Doo::loadModel ( 'L_category' );
  4363. $Lcategory = new L_category ();
  4364. Doo::loadModel ( 'verify' );
  4365. Doo::loadModel ( 'statistics' );
  4366. $statistics = new statistics ();
  4367. $verify = new verify ();
  4368. Doo::loadModel ( 'staff' );
  4369. $staff = new staff ();
  4370. Doo::loadModel ( 'loanReceipt' );
  4371. $loanReceipt = new loanReceipt ();
  4372. $receiptList = $receipt->find ( array (
  4373. 'where' => ' rid=' . $rid,
  4374. 'desc' => 'rid',
  4375. 'asArray' => true
  4376. ) );
  4377. $loanList = array ();
  4378. if (! empty ( $receiptList ))
  4379. $loanList = $loanReceipt->find ( array (
  4380. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4381. 'desc' => 'rid',
  4382. 'asArray' => true
  4383. ) );
  4384. $Locate = 0;
  4385. $roleId = 0;
  4386. $button = 0;
  4387. foreach ( $loanList as $key => $value ) {
  4388. $loanList [$key] ['Locate'] = $Locate;
  4389. $Locate ++;
  4390. $loanList [$key] ['reviseDetail'] = array ();
  4391. if (! empty ( $value ['reviseDetail'] ))
  4392. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4393. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4394. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4395. $categoryDetil = $Lcategory->getOne ( array (
  4396. 'where' => 'cid=' . $value ['cid'],
  4397. 'asArray' => true
  4398. ) );
  4399. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4400. // 检测编辑状态
  4401. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  4402. $verifyList ['staff'] = $value ['verifyBreakup'];
  4403. else
  4404. $verifyList = $verify->getOne ( array (
  4405. 'where' => 'vid=' . $value ['verify'],
  4406. 'asArray' => true
  4407. ) );
  4408. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4409. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4410. Doo::loadModel ( 'role' );
  4411. $role = new role ();
  4412. $flag = true;
  4413. $roleKey = 0;
  4414. $endStaffArray = array ();
  4415. $roleArrayCopy = array ();
  4416. foreach ( $verifyList as $k => $v ) {
  4417. // init verifyStaff
  4418. if ($v [1] == 'ROLE') {
  4419. if (! empty ( $verifyStaff )) {
  4420. $endStaffArray = end ( $verifyStaff );
  4421. // if ($v[0]==$endStaffArray['nextStaff']){
  4422. // $roleId=$v[0];
  4423. // }
  4424. }
  4425. $roleVerify = json_decode ( $v [3], true );
  4426. $roleKey = $k;
  4427. $roleArray = array ();
  4428. $rolename = $role->getOne ( array (
  4429. 'where' => 'rid=' . $v [0],
  4430. 'asArray' => true
  4431. ) );
  4432. foreach ( $roleVerify as $o => $p ) {
  4433. $staffID = explode ( '_', $p );
  4434. $staffInfo = $staff->getOne ( array (
  4435. 'where' => 'sid=' . $staffID [0],
  4436. 'asArray' => true
  4437. ) );
  4438. // print_r($staffID);
  4439. $exp = array (
  4440. 0 => $staffInfo ['sid'],
  4441. 1 => $staffID [1],
  4442. 2 => $staffInfo ['avatar'],
  4443. 'date' => '',
  4444. 'date' => '',
  4445. 'opinion' => '',
  4446. 'status' => '',
  4447. 'rolename' => $rolename ['name']
  4448. );
  4449. array_push ( $roleArray, $exp );
  4450. }
  4451. $roleArrayCopy [$v [0]] = $roleArray;
  4452. // $verifyList[$k]['roleArray']=$roleArray;
  4453. }
  4454. $verifyList [$k] ['date'] = "";
  4455. $verifyList [$k] ['opinion'] = "";
  4456. $verifyList [$k] ['status'] = "";
  4457. if (empty ( $verifyStaff )) {
  4458. $verifyList [$k] ['date'] = "";
  4459. $verifyList [$k] ['opinion'] = "";
  4460. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4461. $verifyList [$k] ['status'] = 4;
  4462. $flag = false;
  4463. }
  4464. } else {
  4465. foreach ( $verifyStaff as $m => $u ) {
  4466. if ($v [0] == $m) {
  4467. $verifyList [$k] ['date'] = $u ['date'];
  4468. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4469. $verifyList [$k] ['status'] = $u ['status'];
  4470. $flag = false;
  4471. break;
  4472. }
  4473. }
  4474. $endStaffArray = end ( $verifyStaff );
  4475. if (isset ( $endStaffArray ['ROLE'] )) {
  4476. } else {
  4477. // $endKey=key($verifyStaff);
  4478. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4479. // $button=4;
  4480. // $verifyList[$k]['status']=4;
  4481. // }
  4482. }
  4483. }
  4484. }
  4485. $rolename ['name'] = '';
  4486. if (! empty ( $roleId )) {
  4487. Doo::loadModel ( 'role' );
  4488. $role = new role ();
  4489. $rolename = $role->getOne ( array (
  4490. 'where' => 'rid=' . $roleId,
  4491. 'asArray' => true
  4492. ) );
  4493. }
  4494. if (! empty ( $verifyStaff ))
  4495. $endStaffArray = end ( $verifyStaff );
  4496. $KOP = false;
  4497. foreach ( $roleArrayCopy as $P => $A ) {
  4498. foreach ( $A as $MKI => $AVL ) {
  4499. if (! empty ( $verifyStaff )) {
  4500. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4501. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4502. $button = 4;
  4503. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4504. }
  4505. foreach ( $verifyStaff as $m => $u ) {
  4506. $AVLFK = $AVL [0] . '_R';
  4507. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4508. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4509. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4510. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4511. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4512. break;
  4513. }
  4514. }
  4515. } else {
  4516. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4517. $button = 4;
  4518. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4519. }
  4520. }
  4521. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4522. $KOP = true;
  4523. }
  4524. }
  4525. foreach ( $roleArrayCopy as $k => $v ) {
  4526. foreach ( $verifyList as $m => $n ) {
  4527. if ($n [0] == $k) {
  4528. array_splice ( $verifyList, $m, 1, $v );
  4529. }
  4530. }
  4531. }
  4532. $loanList [$key] ['verifyList'] = $verifyList;
  4533. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4534. 'where' => 'sid=' . $value ['staff'],
  4535. 'asArray' => true
  4536. ) );
  4537. $loanList [$key] ['button'] = $button;
  4538. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  4539. }
  4540. $data ['loanList'] = $loanList;
  4541. //print_r($loanList);
  4542. $Locate = 0;
  4543. $roleId = 0;
  4544. $button = 0;
  4545. foreach ( $receiptList as $key => $value ) {
  4546. $receiptList [$key] ['Locate'] = $Locate;
  4547. $Locate ++;
  4548. $receiptList [$key] ['reviseDetail'] = array ();
  4549. if (! empty ( $value ['reviseDetail'] ))
  4550. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4551. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4552. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4553. $categoryDetil = $Lcategory->getOne ( array (
  4554. 'where' => 'cid=' . $value ['cid'],
  4555. 'asArray' => true
  4556. ) );
  4557. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4558. // 检测编辑状态
  4559. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4560. $verifyList ['staff'] = $value ['verifyBreakup'];
  4561. } else
  4562. $verifyList = $verify->getOne ( array (
  4563. 'where' => 'vid=' . $value ['verify'],
  4564. 'asArray' => true
  4565. ) );
  4566. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4567. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4568. Doo::loadModel ( 'role' );
  4569. $role = new role ();
  4570. if ($verifyList == NULL)
  4571. $verifyList = array ();
  4572. $flag = true;
  4573. $roleKey = 0;
  4574. $endStaffArray = array ();
  4575. $roleArrayCopy = array ();
  4576. foreach ( $verifyList as $k => $v ) {
  4577. // init verifyStaff
  4578. if ($v [1] == 'ROLE') {
  4579. if (! empty ( $verifyStaff )) {
  4580. $endStaffArray = end ( $verifyStaff );
  4581. // if ($v[0]==$endStaffArray['nextStaff']){
  4582. // $roleId=$v[0];
  4583. // }
  4584. }
  4585. $roleVerify = json_decode ( $v [3], true );
  4586. $roleKey = $k;
  4587. $roleArray = array ();
  4588. $rolename = $role->getOne ( array (
  4589. 'where' => 'rid=' . $v [0],
  4590. 'asArray' => true
  4591. ) );
  4592. foreach ( $roleVerify as $o => $p ) {
  4593. $staffID = explode ( '_', $p );
  4594. $staffInfo = $staff->getOne ( array (
  4595. 'where' => 'sid=' . $staffID [0],
  4596. 'asArray' => true
  4597. ) );
  4598. // print_r($staffID);
  4599. $exp = array (
  4600. 0 => $staffInfo ['sid'],
  4601. 1 => $staffID [1],
  4602. 2 => $staffInfo ['avatar'],
  4603. 'date' => '',
  4604. 'date' => '',
  4605. 'opinion' => '',
  4606. 'status' => '',
  4607. 'rolename' => $rolename ['name']
  4608. );
  4609. array_push ( $roleArray, $exp );
  4610. }
  4611. $roleArrayCopy [$v [0]] = $roleArray;
  4612. // $verifyList[$k]['roleArray']=$roleArray;
  4613. }
  4614. $verifyList [$k] ['date'] = "";
  4615. $verifyList [$k] ['opinion'] = "";
  4616. $verifyList [$k] ['status'] = "";
  4617. if (empty ( $verifyStaff )) {
  4618. $verifyList [$k] ['date'] = "";
  4619. $verifyList [$k] ['opinion'] = "";
  4620. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4621. $verifyList [$k] ['status'] = 4;
  4622. $flag = false;
  4623. }
  4624. } else {
  4625. foreach ( $verifyStaff as $m => $u ) {
  4626. if ($v [0] == $m) {
  4627. $verifyList [$k] ['date'] = $u ['date'];
  4628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4629. $verifyList [$k] ['status'] = $u ['status'];
  4630. $flag = false;
  4631. break;
  4632. }
  4633. }
  4634. $endStaffArray = end ( $verifyStaff );
  4635. if (isset ( $endStaffArray ['ROLE'] )) {
  4636. } else {
  4637. // $endKey=key($verifyStaff);
  4638. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4639. // $button=4;
  4640. // $verifyList[$k]['status']=4;
  4641. // }
  4642. }
  4643. }
  4644. }
  4645. $FC = @$rolename ['name'];
  4646. $rolename ['name'] = '';
  4647. if (! empty ( $roleId )) {
  4648. Doo::loadModel ( 'role' );
  4649. $role = new role ();
  4650. $rolename = $role->getOne ( array (
  4651. 'where' => 'rid=' . $roleId,
  4652. 'asArray' => true
  4653. ) );
  4654. }
  4655. if (! empty ( $verifyStaff ))
  4656. $endStaffArray = end ( $verifyStaff );
  4657. $KOP = false;
  4658. foreach ( $roleArrayCopy as $P => $A ) {
  4659. foreach ( $A as $MKI => $AVL ) {
  4660. if (! empty ( $verifyStaff )) {
  4661. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4662. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4663. $button = 4;
  4664. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4665. }
  4666. foreach ( $verifyStaff as $m => $u ) {
  4667. $AVLFK = $AVL [0] . '_R';
  4668. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4669. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4670. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4671. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4672. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4673. break;
  4674. }
  4675. }
  4676. } else {
  4677. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4678. $button = 4;
  4679. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4680. }
  4681. }
  4682. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4683. $KOP = true;
  4684. }
  4685. }
  4686. foreach ( $roleArrayCopy as $k => $v ) {
  4687. foreach ( $verifyList as $m => $n ) {
  4688. if ($n [0] == $k) {
  4689. array_splice ( $verifyList, $m, 1, $v );
  4690. }
  4691. }
  4692. }
  4693. // 费用执行人相关数据
  4694. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4695. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4696. foreach ( $executeCopy as $k => $v ) {
  4697. $executeCopy [$k] ['date'] = '';
  4698. $executeCopy [$k] ['opinion'] = '';
  4699. $executeCopy [$k] ['status'] = '';
  4700. if (! empty ( $executeStaff ))
  4701. foreach ( $executeStaff as $m => $u ) {
  4702. if ($v [0] == $m) {
  4703. $executeCopy [$k] ['date'] = $u ['date'];
  4704. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4705. $executeCopy [$k] ['status'] = $u ['status'];
  4706. break;
  4707. }
  4708. }
  4709. }
  4710. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4711. // print_r($verifyList);
  4712. $receiptList [$key] ['verifyList'] = $verifyList;
  4713. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4714. 'where' => 'sid=' . $value ['staff'],
  4715. 'asArray' => true
  4716. ) );
  4717. $receiptList [$key] ['button'] = $button;
  4718. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4719. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4720. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4721. $receiptList [$key] ['relust'] = $relust;
  4722. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4723. }
  4724. // print_r($receiptList);
  4725. // 获取审批日志
  4726. Doo::loadModel ( 'receiptLog' );
  4727. $receiptLog = new receiptLog ();
  4728. $rlList = array ();
  4729. $rlInfo = $receiptLog->getOne ( array (
  4730. 'where' => 'rid=' . $rid . ' and status=4',
  4731. 'asArray' => true
  4732. ) );
  4733. // $tijdate = $receiptLog->getOne ( array (
  4734. // 'where' => 'rid=' . $rid . ' and status=2',
  4735. // 'asc' => 'rlid',
  4736. // 'asArray' => true
  4737. // ) );
  4738. if (! empty ( $rlInfo )) {
  4739. $rlList = $receiptLog->find ( array (
  4740. 'where' => 'rid=' . $rid,
  4741. 'asc' => 'rlid',
  4742. 'asArray' => true
  4743. ) );
  4744. }
  4745. $RN=array();
  4746. if (!empty( $rolename ['staff'])){
  4747. $RN = @json_decode ( $rolename ['staff'] );
  4748. }
  4749. //
  4750. foreach ( $rlList as $key => $value ) {
  4751. $rlList [$key] ['rolename'] = '';
  4752. foreach ( $RN as $k => $v ) {
  4753. $id = explode ( "_", $v );
  4754. if ($id [0] == $value ['uid']) {
  4755. $rlList [$key] ['rolename'] = $FC;
  4756. break;
  4757. }
  4758. }
  4759. }
  4760. Doo::loadModel ( 'enclosur' );
  4761. $enclosur = new enclosur ();
  4762. $enclosurList = $enclosur->find ( array (
  4763. 'where' => 'rid=' . $rid,
  4764. 'asArray' => true
  4765. ) );
  4766. $enclosurHtml = '';
  4767. foreach ( $enclosurList as $value ) {
  4768. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4769. }
  4770. $data ['enclosurHtml'] = $enclosurHtml;
  4771. $receiptList [0] ['rlList'] = $rlList;
  4772. $data ['receiptList'] = $receiptList;
  4773. // print_r($receiptList);
  4774. $data ['memu'] = "receipt";
  4775. $data ['staff'] = $this->staff;
  4776. $data ['receiptMemu'] = 'approvalExpenses';
  4777. $data ['verifyId'] = $this->verifyId;
  4778. $data ['executeId'] = $this->executeId;
  4779. $this->render ( "/admin/expensesDoc", $data );
  4780. }
  4781. function expensesEdi() {
  4782. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4783. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4784. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4785. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4786. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4787. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4788. if (empty ( $status ))
  4789. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4790. $vidList = array ();
  4791. $button = 0;
  4792. Doo::loadModel ( 'verify' );
  4793. Doo::loadModel ( 'receipt' );
  4794. Doo::loadModel ( 'staff' );
  4795. $staff = new staff ();
  4796. $receipt = new receipt ();
  4797. $verify = new verify ();
  4798. Doo::loadModel ( 'L_category' );
  4799. $Lcategory = new L_category ();
  4800. Doo::loadModel ( 'enclosur' );
  4801. $enclosur = new enclosur ();
  4802. // user verify ID
  4803. $verifyDetail = $verify->find ( array (
  4804. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4805. 'asArray' => true
  4806. ) );
  4807. foreach ( $verifyDetail as $key => $value ) {
  4808. array_push ( $vidList, $value ['vid'] );
  4809. }
  4810. $vid = implode ( ",", $vidList );
  4811. if (empty ( $verifyDetail ))
  4812. $vid = 0;
  4813. $categoryList = $Lcategory->find ( array (
  4814. 'asArray' => true
  4815. ) );
  4816. $staffList = $staff->find ( array (
  4817. 'where' => 'cid=' . $cid,
  4818. 'asArray' => true
  4819. ) );
  4820. $ap = "";
  4821. if ($status == 4) {
  4822. $ap = 4;
  4823. $status = 2;
  4824. }
  4825. // get Receipt By verifyID status 2
  4826. $receiptList = $receipt->find ( array (
  4827. 'where' => 'rid =' . $rid . ' and status=2',
  4828. 'desc' => 'rid',
  4829. 'asArray' => true
  4830. ) );
  4831. if (empty ( $receiptList )) {
  4832. die ( 'illegal request' );
  4833. }
  4834. $Locate = 0;
  4835. $roleId = 0;
  4836. if ($ap == 4)
  4837. $status = 4;
  4838. foreach ( $receiptList as $key => $value ) {
  4839. $receiptList [$key] ['Locate'] = $Locate;
  4840. $Locate ++;
  4841. $receiptList [$key] ['reviseDetail'] = array ();
  4842. if (! empty ( $value ['reviseDetail'] ))
  4843. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4844. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4845. $categoryDetil = $Lcategory->getOne ( array (
  4846. 'where' => 'cid=' . $value ['cid'],
  4847. 'asArray' => true
  4848. ) );
  4849. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4850. // 检测编辑状态
  4851. $verifyList = $verify->getOne ( array (
  4852. 'where' => 'vid=' . $value ['verify'],
  4853. 'asArray' => true
  4854. ) );
  4855. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4856. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4857. Doo::loadModel ( 'role' );
  4858. $role = new role ();
  4859. // print_r($verifyList);
  4860. $flag = true;
  4861. $roleKey = 0;
  4862. $endStaffArray = array ();
  4863. $roleArrayCopy = array ();
  4864. foreach ( $verifyList as $k => $v ) {
  4865. // init verifyStaff
  4866. if ($v [1] == 'ROLE') {
  4867. if (! empty ( $verifyStaff )) {
  4868. $endStaffArray = end ( $verifyStaff );
  4869. if ($v [0] == $endStaffArray ['nextStaff']) {
  4870. $roleId = $v [0];
  4871. }
  4872. }
  4873. $roleVerify = json_decode ( $v [3], true );
  4874. $roleKey = $k;
  4875. $roleArray = array ();
  4876. $rolename = $role->getOne ( array (
  4877. 'where' => 'rid=' . $v [0],
  4878. 'asArray' => true
  4879. ) );
  4880. foreach ( $roleVerify as $o => $p ) {
  4881. $staffID = explode ( '_', $p );
  4882. $staffInfo = $staff->getOne ( array (
  4883. 'where' => 'sid=' . $staffID [0],
  4884. 'asArray' => true
  4885. ) );
  4886. // print_r($staffID);
  4887. $exp = array (
  4888. 0 => $staffInfo ['sid'],
  4889. 1 => $staffID [1],
  4890. 2 => $staffInfo ['avatar'],
  4891. 'date' => '',
  4892. 'date' => '',
  4893. 'opinion' => '',
  4894. 'status' => '',
  4895. 'rolename' => $rolename ['name']
  4896. );
  4897. array_push ( $roleArray, $exp );
  4898. }
  4899. $roleArrayCopy [$v [0]] = $roleArray;
  4900. // $verifyList[$k]['roleArray']=$roleArray;
  4901. }
  4902. // print_r($roleArray);
  4903. $verifyList [$k] ['date'] = "";
  4904. $verifyList [$k] ['opinion'] = "";
  4905. $verifyList [$k] ['status'] = "";
  4906. if (empty ( $verifyStaff )) {
  4907. $verifyList [$k] ['date'] = "";
  4908. $verifyList [$k] ['opinion'] = "";
  4909. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4910. $verifyList [$k] ['status'] = 4;
  4911. $button = 4;
  4912. $flag = false;
  4913. }
  4914. } else {
  4915. foreach ( $verifyStaff as $m => $u ) {
  4916. if ($v [0] == $m) {
  4917. $verifyList [$k] ['date'] = $u ['date'];
  4918. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4919. $verifyList [$k] ['status'] = $u ['status'];
  4920. $flag = false;
  4921. break;
  4922. }
  4923. }
  4924. $endStaffArray = end ( $verifyStaff );
  4925. if (isset ( $endStaffArray ['ROLE'] )) {
  4926. } else {
  4927. $endKey = key ( $verifyStaff );
  4928. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4929. $button = 4;
  4930. $verifyList [$k] ['status'] = 4;
  4931. }
  4932. }
  4933. }
  4934. }
  4935. $rolename ['name'] = '';
  4936. if (! empty ( $roleId )) {
  4937. Doo::loadModel ( 'role' );
  4938. $role = new role ();
  4939. $rolename = $role->getOne ( array (
  4940. 'where' => 'rid=' . $roleId,
  4941. 'asArray' => true
  4942. ) );
  4943. }
  4944. if (! empty ( $verifyStaff ))
  4945. $endStaffArray = end ( $verifyStaff );
  4946. $KOP = false;
  4947. foreach ( $roleArrayCopy as $P => $A ) {
  4948. foreach ( $A as $MKI => $AVL ) {
  4949. if (! empty ( $verifyStaff )) {
  4950. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4951. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4952. $button = 4;
  4953. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4954. }
  4955. foreach ( $verifyStaff as $m => $u ) {
  4956. $AVLFK = $AVL [0] . '_R';
  4957. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4958. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4959. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4960. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4961. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4962. break;
  4963. }
  4964. }
  4965. } else {
  4966. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4967. $button = 4;
  4968. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4969. }
  4970. }
  4971. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4972. $KOP = true;
  4973. }
  4974. }
  4975. // print_r($roleArrayCopy);
  4976. // echo $roleKey;
  4977. foreach ( $roleArrayCopy as $k => $v ) {
  4978. foreach ( $verifyList as $m => $n ) {
  4979. if ($n [0] == $k) {
  4980. array_splice ( $verifyList, $m, 1, $v );
  4981. }
  4982. }
  4983. }
  4984. $receiptList [$key] ['verifyList'] = $verifyList;
  4985. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4986. 'where' => 'sid=' . $value ['staff'],
  4987. 'asArray' => true
  4988. ) );
  4989. $receiptList [$key] ['button'] = $button;
  4990. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4991. }
  4992. // $data['verifyDetail']=$verifyDetail;
  4993. $mothHtml = "";
  4994. for($i = 1; $i <= 12; $i ++) {
  4995. if ($month == $i)
  4996. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4997. else
  4998. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4999. }
  5000. // 获取审批日志
  5001. Doo::loadModel ( 'receiptLog' );
  5002. $receiptLog = new receiptLog ();
  5003. $rlList = array ();
  5004. $rlInfo = $receiptLog->getOne ( array (
  5005. 'where' => 'rid=' . $rid . ' and status=4',
  5006. 'asArray' => true
  5007. ) );
  5008. $tijdate = $receiptLog->getOne ( array (
  5009. 'where' => 'rid=' . $rid . ' and status=2',
  5010. 'asc' => 'rlid',
  5011. 'asArray' => true
  5012. ) );
  5013. if (! empty ( $rlInfo )) {
  5014. $rlList = $receiptLog->find ( array (
  5015. 'where' => 'rid=' . $rid,
  5016. 'asc' => 'rlid',
  5017. 'asArray' => true
  5018. ) );
  5019. }
  5020. $receiptList [0] ['rlList'] = $rlList;
  5021. $enclosurList = $enclosur->find ( array (
  5022. 'where' => 'rid=' . $rid,
  5023. 'asArray' => true
  5024. ) );
  5025. $enclosurHtml = '';
  5026. foreach ( $enclosurList as $value ) {
  5027. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5028. }
  5029. // print_r($receiptList);
  5030. $data ['rid'] = $rid;
  5031. $data ['enclosurHtml'] = $enclosurHtml;
  5032. $data ['rolename'] = $rolename ['name'];
  5033. $data ['datetij'] = $tijdate ['date'];
  5034. $data ['mothHtml'] = $mothHtml;
  5035. $data ['receiptList'] = $receiptList;
  5036. $data ['receiptApprovalCount'] = count ( $receiptList );
  5037. $data ['status'] = $status;
  5038. $data ['year'] = $year;
  5039. $data ['categoryList'] = $categoryList;
  5040. $data ['staffList'] = $staffList;
  5041. $data ['cid'] = $cid;
  5042. $data ['sid'] = $sid;
  5043. $data ['ap'] = $ap;
  5044. $data ['memu'] = "receipt";
  5045. $data ['staff'] = $this->staff;
  5046. $data ['receiptMemu'] = 'approvalExpenses';
  5047. $data ['verifyId'] = $this->verifyId;
  5048. $data ['executeId'] = $this->executeId;
  5049. $this->render ( "/admin/expensesEdi", $data );
  5050. }
  5051. function expensesDefray() {
  5052. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5053. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  5054. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5055. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  5056. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  5057. if (! empty ( $rid )) {
  5058. Doo::loadModel ( "verify" );
  5059. $verify = new verify ();
  5060. Doo::loadModel ( "receiptDetail" );
  5061. $receiptDetailObj = new receiptDetail ();
  5062. Doo::loadModel ( "itemStatistics" );
  5063. Doo::loadModel ( "statistics" );
  5064. $statistics = new statistics ();
  5065. $itemStatistics = new itemStatistics ();
  5066. Doo::loadModel ( "receipt" );
  5067. $receipt = new receipt ();
  5068. Doo::loadModel ( "loanReceipt" );
  5069. $loanReceipt = new loanReceipt ();
  5070. $receiptDetail = $receipt->getOne ( array (
  5071. 'where' => 'rid=' . $rid . ' and status=2 ',
  5072. 'asArray' => true
  5073. ) );
  5074. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  5075. $nsflag = true;
  5076. foreach ( $nslist as $value ) {
  5077. if ($value == $this->staff ['0'] ['sid']) {
  5078. $nsflag = false;
  5079. break;
  5080. }
  5081. }
  5082. // print_r($nslist);die;
  5083. if (empty ( $receiptDetail ) || $nsflag)
  5084. return "/approvalExpenses/pendApproval";
  5085. $verifyDetail = $verify->getOne ( array (
  5086. 'where' => ' vid =' . $receiptDetail ['verify'],
  5087. 'asArray' => true
  5088. ) );
  5089. $verifyString = $verifyDetail ['staff'];
  5090. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5091. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  5092. if (empty ( $opinion )) {
  5093. if ($status == 3)
  5094. $opinion = "终止";
  5095. else
  5096. $opinion = "同意支付";
  5097. }
  5098. $nowStaff = 0;
  5099. $nowStaffList = array ();
  5100. if (empty ( $verifyStaff )) {
  5101. // 还需加入是否已经进入角色审批
  5102. if ($verifyDetail [0] [1] == 'ROLE') {
  5103. // print_r($verifyDetail);echo "ddd";
  5104. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5105. foreach ( $vStaffString as $key => $value ) {
  5106. $staffK = explode ( "_", $value );
  5107. if ($staffK [0] != $this->staff [0] ['sid'])
  5108. array_push ( $nowStaffList, $staffK [0] );
  5109. }
  5110. // print_r($verifyDetail);
  5111. // die;
  5112. if (! empty ( $nowStaffList )) {
  5113. $nowStaff = implode ( ',', $nowStaffList );
  5114. $verifyStaff = array (
  5115. $this->staff [0] ['sid'] . "_R" => array (
  5116. 'date' => date ( 'Y-m-d' ),
  5117. 'opinion' => $opinion,
  5118. 'status' => $status,
  5119. 'nextStaff' => $verifyDetail [0] [0],
  5120. 'ROLE' => 1
  5121. )
  5122. );
  5123. } else {
  5124. $nowStaff = $verifyDetail [1] [0];
  5125. $verifyStaff = array (
  5126. $this->staff [0] ['sid'] . "_R" => array (
  5127. 'date' => date ( 'Y-m-d' ),
  5128. 'opinion' => $opinion,
  5129. 'status' => $status,
  5130. 'nextStaff' => $verifyDetail [1] [0]
  5131. )
  5132. );
  5133. }
  5134. } else {
  5135. if ($verifyDetail [1] [1] == 'ROLE') {
  5136. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  5137. // echo "dd";
  5138. foreach ( $vStaffString as $key => $value ) {
  5139. $staffK = explode ( "_", $value );
  5140. array_push ( $nowStaffList, $staffK [0] );
  5141. }
  5142. $nowStaff = implode ( ',', $nowStaffList );
  5143. $verifyStaff = array (
  5144. $this->staff [0] ['sid'] => array (
  5145. 'date' => date ( 'Y-m-d' ),
  5146. 'opinion' => $opinion,
  5147. 'status' => $status,
  5148. 'nextStaff' => $verifyDetail [1] [0],
  5149. 'ROLE' => 1
  5150. )
  5151. );
  5152. } else {
  5153. $nowStaff = $verifyDetail [1] [0];
  5154. $verifyStaff = array (
  5155. $this->staff [0] ['sid'] => array (
  5156. 'date' => date ( 'Y-m-d' ),
  5157. 'opinion' => $opinion,
  5158. 'status' => $status,
  5159. 'nextStaff' => $verifyDetail [1] [0]
  5160. )
  5161. );
  5162. }
  5163. }
  5164. if ($status == 3)
  5165. $verifyStaff = array (
  5166. 'final' => $status,
  5167. $this->staff [0] ['sid'] => array (
  5168. 'date' => date ( 'Y-m-d' ),
  5169. 'opinion' => $opinion,
  5170. 'status' => $status
  5171. )
  5172. );
  5173. $vStaffString = json_encode ( $verifyStaff );
  5174. $receipt->nowStaff = $nowStaff;
  5175. $receipt->verifyStaff = $vStaffString;
  5176. $loanReceipt->nowStaff = $nowStaff;
  5177. $loanReceipt->verifyStaff = $vStaffString;
  5178. } else {
  5179. $VS = end ( $verifyStaff );
  5180. // 非角色审批
  5181. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  5182. $nextStaff = 0;
  5183. $roleSTF = false;
  5184. foreach ( $verifyDetail as $key => $value ) {
  5185. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  5186. if (isset ( $verifyDetail [$key + 1] )) {
  5187. $nextStaff = $verifyDetail [$key + 1] [0];
  5188. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  5189. $roleSTF = true;
  5190. }
  5191. break;
  5192. }
  5193. }
  5194. if (! $roleSTF) {
  5195. $nowStaff = $nextStaff;
  5196. $verifyStaff [$this->staff [0] ['sid']] = array (
  5197. 'date' => date ( 'Y-m-d' ),
  5198. 'opinion' => $opinion,
  5199. 'status' => $status,
  5200. 'nextStaff' => $nextStaff
  5201. );
  5202. } else {
  5203. // 获取角色下的所有用户ID
  5204. $nowStaffList = array ();
  5205. foreach ( $verifyDetail as $vfk ) {
  5206. if ($vfk [1] == 'ROLE') {
  5207. $vStaffString = json_decode ( $vfk [3] );
  5208. foreach ( $vStaffString as $key => $value ) {
  5209. $staffK = explode ( "_", $value );
  5210. array_push ( $nowStaffList, $staffK [0] );
  5211. }
  5212. }
  5213. }
  5214. $nowStaff = implode ( ',', $nowStaffList );
  5215. $verifyStaff [$this->staff [0] ['sid']] = array (
  5216. 'date' => date ( 'Y-m-d' ),
  5217. 'opinion' => $opinion,
  5218. 'status' => $status,
  5219. 'nextStaff' => $nextStaff,
  5220. 'ROLE' => 0
  5221. );
  5222. }
  5223. if ($status == 3) {
  5224. $verifyStaff ['final'] = $status;
  5225. $verifyStaff [$this->staff [0] ['sid']] = array (
  5226. 'date' => date ( 'Y-m-d' ),
  5227. 'opinion' => $opinion,
  5228. 'status' => $status
  5229. );
  5230. }
  5231. $vStaffString = json_encode ( $verifyStaff );
  5232. $receipt->nowStaff = $nowStaff;
  5233. $receipt->verifyStaff = $vStaffString;
  5234. $loanReceipt->nowStaff = $nowStaff;
  5235. $loanReceipt->verifyStaff = $vStaffString;
  5236. }
  5237. // 角色审批
  5238. if (isset ( $VS ['ROLE'] )) {
  5239. // 找出角色人 当前审批角色组
  5240. $verifyJSStaff = array ();
  5241. $nowStaffList2 = array ();
  5242. foreach ( $verifyDetail as $key => $value ) {
  5243. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  5244. $verifyJSStaff = json_decode ( $value [3] );
  5245. foreach ( $verifyJSStaff as $m ) {
  5246. $staffK = explode ( "_", $m );
  5247. array_push ( $nowStaffList2, $staffK [0] );
  5248. }
  5249. // print_r($nowStaffList2);
  5250. }
  5251. }
  5252. $RoleVerifyStaff = array ();
  5253. foreach ( $verifyStaff as $key => $value ) {
  5254. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  5255. foreach ( $nowStaffList2 as $m ) {
  5256. if ($key == $m . "_R")
  5257. $RoleVerifyStaff [$key] = $value;
  5258. }
  5259. }
  5260. }
  5261. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  5262. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  5263. // 下一个审批人ID
  5264. $nextStaff = 0;
  5265. $falg = false;
  5266. foreach ( $verifyDetail as $key => $value ) {
  5267. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  5268. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  5269. $falg = true;
  5270. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  5271. $nowStaffList = array ();
  5272. foreach ( $vStaffString as $v ) {
  5273. $staffK = explode ( "_", $v );
  5274. array_push ( $nowStaffList, $staffK [0] );
  5275. }
  5276. $nowStaff = implode ( ',', $nowStaffList );
  5277. $nextStaff = $verifyDetail [$key + 1] [0];
  5278. } elseif (isset ( $verifyDetail [$key + 1] )) {
  5279. $nextStaff = $verifyDetail [$key + 1] [0];
  5280. $nowStaff = $nextStaff;
  5281. } else
  5282. $nowStaff = '';
  5283. break;
  5284. }
  5285. }
  5286. if ($falg)
  5287. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5288. 'date' => date ( 'Y-m-d' ),
  5289. 'opinion' => $opinion,
  5290. 'status' => $status,
  5291. 'nextStaff' => $nextStaff,
  5292. 'ROLE' => 1
  5293. );
  5294. else
  5295. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5296. 'date' => date ( 'Y-m-d' ),
  5297. 'opinion' => $opinion,
  5298. 'status' => $status,
  5299. 'nextStaff' => $nextStaff
  5300. );
  5301. // print_r($verifyStaff);
  5302. // echo $nowStaff;die;
  5303. } else { // 进入下一个角色或者审批人
  5304. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  5305. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5306. 'date' => date ( 'Y-m-d' ),
  5307. 'opinion' => $opinion,
  5308. 'status' => $status,
  5309. 'nextStaff' => $VS ['nextStaff'],
  5310. 'ROLE' => 1
  5311. );
  5312. }
  5313. if ($status == 3) {
  5314. $verifyStaff ['final'] = $status;
  5315. $verifyStaff [$this->staff [0] ['sid']] = array (
  5316. 'date' => date ( 'Y-m-d' ),
  5317. 'opinion' => $opinion,
  5318. 'status' => $status
  5319. );
  5320. }
  5321. $vStaffString = json_encode ( $verifyStaff );
  5322. $receipt->verifyStaff = $vStaffString;
  5323. $receipt->nowStaff = $nowStaff;
  5324. $loanReceipt->nowStaff = $nowStaff;
  5325. $loanReceipt->verifyStaff = $vStaffString;
  5326. }
  5327. // print_r($verifyStaff);die;
  5328. }
  5329. $roleKey = 0;
  5330. $roleId = 0;
  5331. $verifyDetailCopy = array ();
  5332. foreach ( $verifyDetail as $k => $v ) {
  5333. if ($v [1] == 'ROLE') {
  5334. $roleId = $v [0];
  5335. $roleVerify = json_decode ( $v [3], true );
  5336. $roleKey = $k;
  5337. $roleArray = array ();
  5338. foreach ( $roleVerify as $o => $p ) {
  5339. $staffID = explode ( '_', $p );
  5340. $exp = array (
  5341. 0 => $staffID [0],
  5342. 1 => $staffID [1]
  5343. );
  5344. array_push ( $roleArray, $exp );
  5345. }
  5346. $verifyDetailCopy [$v [0]] = $roleArray;
  5347. }
  5348. }
  5349. // print_r($verifyDetail);
  5350. foreach ( $verifyDetailCopy as $k => $v ) {
  5351. foreach ( $verifyDetail as $m => $n ) {
  5352. if ($n [0] == $k) {
  5353. array_splice ( $verifyDetail, $m, 1, $v );
  5354. }
  5355. }
  5356. }
  5357. // 审批日志
  5358. if (! isset ( $verifyStaff ['final'] )) {
  5359. Doo::loadModel ( "receiptLog" );
  5360. $receiptLog = new receiptLog ();
  5361. if (! empty ( $roleId )) {
  5362. Doo::loadModel ( "role" );
  5363. $role = new role ();
  5364. $roleInfo = $role->getOne ( array (
  5365. 'where' => 'rid=' . $roleId,
  5366. 'asArray' => true
  5367. ) );
  5368. $receiptLog->rolename = $roleInfo ['name'];
  5369. }
  5370. $receiptLog->username = $this->staff [0] ['username'];
  5371. $receiptLog->uid = $this->staff [0] ['sid'];
  5372. $receiptLog->date = date ( "Y-m-d" );
  5373. $receiptLog->opinion = $opinion;
  5374. $receiptLog->img = $this->staff [0] ['avatar'];
  5375. $receiptLog->status = 1;
  5376. $receiptLog->rid = $rid;
  5377. $receiptLog->insert ();
  5378. }
  5379. if (isset ( $verifyStaff ['final'] )) { // rDetail
  5380. $receipt->status = 3;
  5381. $receipt->verifyBreakup = $verifyString;
  5382. $receiptDetailObj->status = 3;
  5383. $receiptDetailObj->update ( array (
  5384. 'where' => 'rid=' . $rid
  5385. ) );
  5386. // 微信企业号通知
  5387. $this->setWXMsg ( $rid, 3 );
  5388. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  5389. $receipt->status = 6;
  5390. $receipt->pastDate = date ( "Y-m-d" );
  5391. $receipt->isBK = 1;
  5392. $loanReceipt->verifyBreakup = $verifyString;
  5393. $loanReceipt->status = 1;
  5394. $loanReceipt->pastDate = date ( "Y-m-d" );
  5395. //生成流水后 不更新汇款金额
  5396. Doo::loadModel ( 'wasteBook' );
  5397. $wasteBook = new wasteBook ();
  5398. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  5399. if (empty($wbDetail)){
  5400. $loanReceipt->amount = $receiptDetail ['amount'];
  5401. }
  5402. $loanReceipt->update ( array (
  5403. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  5404. ) );
  5405. // 微信企业号通知
  5406. $this->setWXMsg ( $rid, 1 );
  5407. }
  5408. $receipt->amount = $receiptDetail['sum'];
  5409. $receipt->update ( array (
  5410. 'where' => ' rid = ' . $rid
  5411. ) );
  5412. // 进入下一条审批费用新加需求
  5413. $vidList = array ();
  5414. $verifyDetail = $verify->find ( array (
  5415. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  5416. 'asArray' => true
  5417. ) );
  5418. foreach ( $verifyDetail as $key => $value ) {
  5419. array_push ( $vidList, $value ['vid'] );
  5420. }
  5421. $vid = implode ( ",", $vidList );
  5422. if (empty ( $verifyDetail ))
  5423. $vid = 0;
  5424. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  5425. $receipt = new receipt ();
  5426. $rd = $receipt->getOne ( array (
  5427. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  5428. 'asc' => 'rid',
  5429. 'asArray' => true
  5430. ) );
  5431. if (empty ( $rd )) {
  5432. return '/approvalExpenses/pendApproval';
  5433. }
  5434. if ($rd ['Rtype'] == 1) {
  5435. if ($rd ['isBK'] == 1) {
  5436. return '/receiptburEdi/' . $rd ['rid'];
  5437. } else {
  5438. return '/expensesEdi/' . $rd ['rid'];
  5439. }
  5440. } elseif ($rd ['Rtype'] == 2) {
  5441. return '/remitApproval/' . $rd ['rid'];
  5442. } else {
  5443. return '/receiptburEdi/' . $rd ['rid'];
  5444. }
  5445. // return "/approvalExpenses/pendApproval";
  5446. }
  5447. }
  5448. function ajaxExamineExe() {
  5449. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5450. Doo::loadModel ( 'receipt' );
  5451. $receipt = new receipt ();
  5452. Doo::loadClass ( 'XDeode' );
  5453. $XDeode = new XDeode ( 5 );
  5454. if (! empty ( $rid )) {
  5455. $rLRes = $receipt->find ( array (
  5456. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  5457. 'asArray' => true
  5458. ) );
  5459. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  5460. echo json_encode ( array (
  5461. 'status' => 1,
  5462. 'receipt' => $rLRes [0]
  5463. ) );
  5464. die ();
  5465. }
  5466. echo json_encode ( array (
  5467. 'status' => 0,
  5468. 'receipt' => array ()
  5469. ) );
  5470. die ();
  5471. }
  5472. function implement() {
  5473. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5474. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  5475. Doo::loadClass ( 'XDeode' );
  5476. $XDeode = new XDeode ( 5 );
  5477. Doo::loadModel ( 'receipt' );
  5478. $receipt = new receipt ();
  5479. Doo::loadModel ( 'L_category' );
  5480. $Lcategory = new L_category ();
  5481. Doo::loadModel ( 'verify' );
  5482. $verify = new verify ();
  5483. Doo::loadModel ( 'staff' );
  5484. $staff = new staff ();
  5485. Doo::loadModel ( "execute" );
  5486. $execute = new execute ();
  5487. $rid = $XDeode->decode ( $rid );
  5488. $receiptList = $receipt->find ( array (
  5489. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  5490. 'desc' => 'rid',
  5491. 'asArray' => true
  5492. ) );
  5493. Doo::loadModel ( 'loanReceipt' );
  5494. $loanReceipt = new loanReceipt ();
  5495. // print_r($receiptList);
  5496. $loanList = array ();
  5497. if (! isset ( $receiptList ))
  5498. $loanList = $loanReceipt->find ( array (
  5499. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5500. 'desc' => 'rid',
  5501. 'asArray' => true
  5502. ) );
  5503. $Locate = 0;
  5504. $roleId = 0;
  5505. $button = 0;
  5506. foreach ( $loanList as $key => $value ) {
  5507. $loanList [$key] ['Locate'] = $Locate;
  5508. $Locate ++;
  5509. $loanList [$key] ['reviseDetail'] = array ();
  5510. if (! empty ( $value ['reviseDetail'] ))
  5511. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5512. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5513. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5514. $categoryDetil = $Lcategory->getOne ( array (
  5515. 'where' => 'cid=' . $value ['cid'],
  5516. 'asArray' => true
  5517. ) );
  5518. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5519. // 检测编辑状态
  5520. $verifyList = $verify->getOne ( array (
  5521. 'where' => 'vid=' . $value ['verify'],
  5522. 'asArray' => true
  5523. ) );
  5524. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5525. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5526. Doo::loadModel ( 'role' );
  5527. $role = new role ();
  5528. $flag = true;
  5529. $roleKey = 0;
  5530. $endStaffArray = array ();
  5531. $roleArrayCopy = array ();
  5532. foreach ( $verifyList as $k => $v ) {
  5533. // init verifyStaff
  5534. if ($v [1] == 'ROLE') {
  5535. if (! empty ( $verifyStaff )) {
  5536. $endStaffArray = end ( $verifyStaff );
  5537. // if ($v[0]==$endStaffArray['nextStaff']){
  5538. // $roleId=$v[0];
  5539. // }
  5540. }
  5541. $roleVerify = json_decode ( $v [3], true );
  5542. $roleKey = $k;
  5543. $roleArray = array ();
  5544. $rolename = $role->getOne ( array (
  5545. 'where' => 'rid=' . $v [0],
  5546. 'asArray' => true
  5547. ) );
  5548. foreach ( $roleVerify as $o => $p ) {
  5549. $staffID = explode ( '_', $p );
  5550. $staffInfo = $staff->getOne ( array (
  5551. 'where' => 'sid=' . $staffID [0],
  5552. 'asArray' => true
  5553. ) );
  5554. // print_r($staffID);
  5555. $exp = array (
  5556. 0 => $staffInfo ['sid'],
  5557. 1 => $staffID [1],
  5558. 2 => $staffInfo ['avatar'],
  5559. 'date' => '',
  5560. 'date' => '',
  5561. 'opinion' => '',
  5562. 'status' => '',
  5563. 'rolename' => $rolename ['name']
  5564. );
  5565. array_push ( $roleArray, $exp );
  5566. }
  5567. $roleArrayCopy [$v [0]] = $roleArray;
  5568. // $verifyList[$k]['roleArray']=$roleArray;
  5569. }
  5570. $verifyList [$k] ['date'] = "";
  5571. $verifyList [$k] ['opinion'] = "";
  5572. $verifyList [$k] ['status'] = "";
  5573. if (empty ( $verifyStaff )) {
  5574. $verifyList [$k] ['date'] = "";
  5575. $verifyList [$k] ['opinion'] = "";
  5576. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5577. $verifyList [$k] ['status'] = 4;
  5578. $flag = false;
  5579. }
  5580. } else {
  5581. foreach ( $verifyStaff as $m => $u ) {
  5582. if ($v [0] == $m) {
  5583. $verifyList [$k] ['date'] = $u ['date'];
  5584. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5585. $verifyList [$k] ['status'] = $u ['status'];
  5586. $flag = false;
  5587. break;
  5588. }
  5589. }
  5590. $endStaffArray = end ( $verifyStaff );
  5591. if (isset ( $endStaffArray ['ROLE'] )) {
  5592. } else {
  5593. // $endKey=key($verifyStaff);
  5594. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5595. // $button=4;
  5596. // $verifyList[$k]['status']=4;
  5597. // }
  5598. }
  5599. }
  5600. }
  5601. $rolename ['name'] = '';
  5602. if (! empty ( $roleId )) {
  5603. Doo::loadModel ( 'role' );
  5604. $role = new role ();
  5605. $rolename = $role->getOne ( array (
  5606. 'where' => 'rid=' . $roleId,
  5607. 'asArray' => true
  5608. ) );
  5609. }
  5610. if (! empty ( $verifyStaff ))
  5611. $endStaffArray = end ( $verifyStaff );
  5612. $KOP = false;
  5613. foreach ( $roleArrayCopy as $P => $A ) {
  5614. foreach ( $A as $MKI => $AVL ) {
  5615. if (! empty ( $verifyStaff )) {
  5616. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5617. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5618. $button = 4;
  5619. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5620. }
  5621. foreach ( $verifyStaff as $m => $u ) {
  5622. $AVLFK = $AVL [0] . '_R';
  5623. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5624. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5625. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5626. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5627. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5628. break;
  5629. }
  5630. }
  5631. } else {
  5632. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5633. $button = 4;
  5634. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5635. }
  5636. }
  5637. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5638. $KOP = true;
  5639. }
  5640. }
  5641. foreach ( $roleArrayCopy as $k => $v ) {
  5642. foreach ( $verifyList as $m => $n ) {
  5643. if ($n [0] == $k) {
  5644. array_splice ( $verifyList, $m, 1, $v );
  5645. }
  5646. }
  5647. }
  5648. $loanList [$key] ['verifyList'] = $verifyList;
  5649. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  5650. 'where' => 'sid=' . $value ['staff'],
  5651. 'asArray' => true
  5652. ) );
  5653. }
  5654. $data ['loanList'] = $loanList;
  5655. $Locate = 0;
  5656. $roleId = 0;
  5657. $button = 0;
  5658. Doo::loadClass ( 'XDeode' );
  5659. $XDeode = new XDeode ( 5 );
  5660. foreach ( $receiptList as $key => $value ) {
  5661. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  5662. $button2 = 0;
  5663. $receiptList [$key] ['Locate'] = $Locate;
  5664. $Locate ++;
  5665. $receiptList [$key] ['reviseDetail'] = array ();
  5666. if (! empty ( $value ['reviseDetail'] ))
  5667. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5668. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5669. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5670. $categoryDetil = $Lcategory->getOne ( array (
  5671. 'where' => 'cid=' . $value ['cid'],
  5672. 'asArray' => true
  5673. ) );
  5674. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5675. $executeList = json_decode ( $value ['executeCopy'], true );
  5676. $executeStaff = array ();
  5677. if (! empty ( $value ['executeStaff'] ))
  5678. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5679. if (isset ( $executeList )) {
  5680. foreach ( $executeList as $op => $lo ) {
  5681. $executeList [$op] ['date'] = "";
  5682. $executeList [$op] ['opinion'] = "";
  5683. $executeList [$op] ['status'] = "";
  5684. foreach ( $executeStaff as $m => $u ) {
  5685. if ($lo [0] == $m) {
  5686. $executeList [$op] ['date'] = $u ['date'];
  5687. $executeList [$op] ['opinion'] = $u ['opinion'];
  5688. $executeList [$op] ['status'] = $u ['status'];
  5689. break;
  5690. }
  5691. }
  5692. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5693. $button2 = 1;
  5694. $executeList [$op] ['status'] = 4;
  5695. }
  5696. }
  5697. }
  5698. // 检测编辑状态
  5699. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5700. $verifyList ['staff'] = $value ['verifyBreakup'];
  5701. } else
  5702. $verifyList = $verify->getOne ( array (
  5703. 'where' => 'vid=' . $value ['verify'],
  5704. 'asArray' => true
  5705. ) );
  5706. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5707. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5708. Doo::loadModel ( 'role' );
  5709. $role = new role ();
  5710. if ($verifyList == NULL)
  5711. $verifyList = array ();
  5712. $flag = true;
  5713. $roleKey = 0;
  5714. $endStaffArray = array ();
  5715. $roleArrayCopy = array ();
  5716. foreach ( $verifyList as $k => $v ) {
  5717. // init verifyStaff
  5718. if ($v [1] == 'ROLE') {
  5719. if (! empty ( $verifyStaff )) {
  5720. $endStaffArray = end ( $verifyStaff );
  5721. // if ($v[0]==$endStaffArray['nextStaff']){
  5722. // $roleId=$v[0];
  5723. // }
  5724. }
  5725. $roleVerify = json_decode ( $v [3], true );
  5726. $roleKey = $k;
  5727. $roleArray = array ();
  5728. $rolename = $role->getOne ( array (
  5729. 'where' => 'rid=' . $v [0],
  5730. 'asArray' => true
  5731. ) );
  5732. foreach ( $roleVerify as $o => $p ) {
  5733. $staffID = explode ( '_', $p );
  5734. $staffInfo = $staff->getOne ( array (
  5735. 'where' => 'sid=' . $staffID [0],
  5736. 'asArray' => true
  5737. ) );
  5738. // print_r($staffID);
  5739. $exp = array (
  5740. 0 => $staffInfo ['sid'],
  5741. 1 => $staffID [1],
  5742. 2 => $staffInfo ['avatar'],
  5743. 'date' => '',
  5744. 'date' => '',
  5745. 'opinion' => '',
  5746. 'status' => '',
  5747. 'rolename' => $rolename ['name']
  5748. );
  5749. array_push ( $roleArray, $exp );
  5750. }
  5751. $roleArrayCopy [$v [0]] = $roleArray;
  5752. // $verifyList[$k]['roleArray']=$roleArray;
  5753. }
  5754. $verifyList [$k] ['date'] = "";
  5755. $verifyList [$k] ['opinion'] = "";
  5756. $verifyList [$k] ['status'] = "";
  5757. if (empty ( $verifyStaff )) {
  5758. $verifyList [$k] ['date'] = "";
  5759. $verifyList [$k] ['opinion'] = "";
  5760. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5761. $verifyList [$k] ['status'] = 4;
  5762. $flag = false;
  5763. }
  5764. } else {
  5765. foreach ( $verifyStaff as $m => $u ) {
  5766. if ($v [0] == $m) {
  5767. $verifyList [$k] ['date'] = $u ['date'];
  5768. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5769. $verifyList [$k] ['status'] = $u ['status'];
  5770. $flag = false;
  5771. break;
  5772. }
  5773. }
  5774. $endStaffArray = end ( $verifyStaff );
  5775. if (isset ( $endStaffArray ['ROLE'] )) {
  5776. } else {
  5777. // $endKey=key($verifyStaff);
  5778. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5779. // $button=4;
  5780. // $verifyList[$k]['status']=4;
  5781. // }
  5782. }
  5783. }
  5784. }
  5785. $rolename ['name'] = '';
  5786. if (! empty ( $roleId )) {
  5787. Doo::loadModel ( 'role' );
  5788. $role = new role ();
  5789. $rolename = $role->getOne ( array (
  5790. 'where' => 'rid=' . $roleId,
  5791. 'asArray' => true
  5792. ) );
  5793. }
  5794. if (! empty ( $verifyStaff ))
  5795. $endStaffArray = end ( $verifyStaff );
  5796. $KOP = false;
  5797. foreach ( $roleArrayCopy as $P => $A ) {
  5798. foreach ( $A as $MKI => $AVL ) {
  5799. if (! empty ( $verifyStaff )) {
  5800. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5801. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5802. $button = 4;
  5803. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5804. }
  5805. foreach ( $verifyStaff as $m => $u ) {
  5806. $AVLFK = $AVL [0] . '_R';
  5807. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5808. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5809. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5810. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5811. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5812. break;
  5813. }
  5814. }
  5815. } else {
  5816. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5817. $button = 4;
  5818. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5819. }
  5820. }
  5821. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5822. $KOP = true;
  5823. }
  5824. }
  5825. foreach ( $roleArrayCopy as $k => $v ) {
  5826. foreach ( $verifyList as $m => $n ) {
  5827. if ($n [0] == $k) {
  5828. array_splice ( $verifyList, $m, 1, $v );
  5829. }
  5830. }
  5831. }
  5832. $receiptList [$key] ['verifyList'] = $verifyList;
  5833. $receiptList [$key] ['executeList'] = $executeList;
  5834. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5835. 'where' => 'sid=' . $value ['staff'],
  5836. 'asArray' => true
  5837. ) );
  5838. $receiptList [$key] ['button2'] = $button2;
  5839. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5840. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5841. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5842. $receiptList [$key] ['relust'] = $relust;
  5843. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5844. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  5845. }
  5846. //执行人是否是最后一位
  5847. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  5848. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  5849. $executePrimary=count($executeCopy)-1;
  5850. $lastOne=true;
  5851. if($executePrimary!=count($executeStaff)){
  5852. $lastOne=false;
  5853. }
  5854. $data['lastOne']=$lastOne;
  5855. // 是否写入过流水
  5856. $accountType = 0;
  5857. if ($receiptList [0] ['Rtype'] == 0) {
  5858. $accountType = 3;
  5859. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5860. if (!empty($receiptList [0]['accountItem']) )
  5861. $accountType = 2;
  5862. else
  5863. $accountType = 1;
  5864. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5865. $accountType = 4;
  5866. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5867. $accountType = 12;
  5868. }
  5869. Doo::loadModel ( 'wasteBook' );
  5870. $wasteBook = new wasteBook ();
  5871. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5872. $data ['wbDetail'] = $wbDetail;
  5873. $wbDetailLoan=array();
  5874. if ($accountType==2){
  5875. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5876. }
  5877. $data ['wbDetailLoan'] = $wbDetailLoan;
  5878. $data['inputDate']=date ( "Y-m-d H:i:s" );
  5879. //print_r($wbDetail);
  5880. $data ['receiptList'] = $receiptList;
  5881. $data ['memu'] = "receipt";
  5882. $data ['staff'] = $this->staff;
  5883. $data ['receiptMemu'] = 'implement';
  5884. $data ['verifyId'] = $this->verifyId;
  5885. $data ['executeId'] = $this->executeId;
  5886. if ($Rtype=="loan"){
  5887. $this->render ( "/receipt/receiptImplementLoan", $data );
  5888. }elseif($Rtype=="receipt"){
  5889. $this->render ( "/receipt/receiptImplement", $data );
  5890. }elseif($Rtype=="public"){
  5891. $this->render ( "/receipt/receiptImplementPublic", $data );
  5892. }else{
  5893. //$this->render ( "/admin/implement", $data );
  5894. }
  5895. }
  5896. function implementDo() {
  5897. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  5898. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5899. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5900. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5901. // $ab = '';
  5902. // if ($accountBank == 'CGBDeposit')
  5903. // $ab = '纵横广发';
  5904. // elseif ($accountBank == 'ICBCDeposit')
  5905. // $ab = '纵横工行';
  5906. // elseif ($accountBank == 'HUADeposit')
  5907. // $ab = '华润银行';
  5908. // elseif ($accountBank == 'PersonalDeposit')
  5909. // $ab = '个人广发';
  5910. // if (empty ( $ab ))
  5911. // die ( 'illegal request--22' );
  5912. if (! empty ( $rid )) {
  5913. Doo::loadModel ( 'receipt' );
  5914. $receipt = new receipt ();
  5915. Doo::loadClass ( 'XDeode' );
  5916. $XDeode = new XDeode ( 5 );
  5917. $rid=$XDeode->decode($rid);
  5918. if (!is_numeric($rid)){
  5919. die;
  5920. }
  5921. // $rinfo = $receipt->getOne ( array (
  5922. // 'where' => 'rid=' . $rid,
  5923. // 'asArray' => true
  5924. // ) );
  5925. $rinfo = $receipt->getReceiptByRid ( $rid );
  5926. // $accountType = '';
  5927. // if ($rinfo ['Rtype'] == 1) {
  5928. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5929. // $accountType = 2;
  5930. // else
  5931. // $accountType = 1;
  5932. // } elseif ($rinfo ['Rtype'] == 2) {
  5933. // $accountType = 4;
  5934. // } elseif ($rinfo ['Rtype'] == 0)
  5935. // $accountType = 3;
  5936. // if (empty ( $accountType ))
  5937. // die ( 'illegal request' );
  5938. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5939. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5940. if (empty ( $executeStaff )) {
  5941. $executeStaff = array (
  5942. $this->staff [0] ['sid'] => array (
  5943. 'date' => date ( 'Y-m-d' ),
  5944. 'opinion' => $implementOpinions,
  5945. 'status' => 1
  5946. )
  5947. );
  5948. } else {
  5949. $executeStaff [$this->staff [0] ['sid']] = array (
  5950. 'date' => date ( 'Y-m-d' ),
  5951. 'opinion' => $implementOpinions,
  5952. 'status' => 1
  5953. );
  5954. }
  5955. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5956. $receipt->executeStaff = json_encode ( $executeStaff );
  5957. $receipt->status = 8;
  5958. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5959. $receipt->status = 9;
  5960. if ($rinfo ['status'] == 6) {
  5961. $receipt->loanDate = date ( "Y-m-d" );
  5962. }
  5963. $receipt->executeDate = date ( "Y-m-d" );
  5964. } else {
  5965. $receipt->executeStaff = json_encode ( $executeStaff );
  5966. }
  5967. //$receipt->amount = $amount;
  5968. $receipt->update ( array (
  5969. 'where' => 'rid=' . $rid
  5970. ) );
  5971. // 公司流水记录
  5972. // Doo::loadModel ( 'wasteBook' );
  5973. // $wasteBook = new wasteBook ();
  5974. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5975. // // 银行
  5976. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5977. // $item = array (
  5978. // 'dataID' => $rid,
  5979. // 'expensesType' => 2,
  5980. // 'accountType' => $accountType,
  5981. // 'accountPriceShow' => $amount,
  5982. // 'accountPrice' => - $amount,
  5983. // 'accountBank' => $accountBank,
  5984. // 'category' => $rinfo ['category'] [0] ['title'],
  5985. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5986. // 'name' => $rinfo ['staffDetail'] ['username'],
  5987. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5988. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5989. // );
  5990. // $wasteBook->setAccountBookStatistics ( $item );
  5991. // }
  5992. }
  5993. //$ridKey = $XDeode->encode ( $rid );
  5994. return "/hisImplement";
  5995. // return "/implement/" . $ridKey . ".html";
  5996. }
  5997. function receiptburEdi() {
  5998. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5999. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6000. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6001. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6002. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6003. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6004. if (empty ( $status ))
  6005. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6006. $vidList = array ();
  6007. $button = 0;
  6008. Doo::loadModel ( 'verify' );
  6009. Doo::loadModel ( 'receipt' );
  6010. Doo::loadModel ( 'staff' );
  6011. $staff = new staff ();
  6012. $receipt = new receipt ();
  6013. $verify = new verify ();
  6014. Doo::loadModel ( 'L_category' );
  6015. $Lcategory = new L_category ();
  6016. Doo::loadModel ( 'enclosur' );
  6017. $enclosur = new enclosur ();
  6018. Doo::loadModel ( 'loanReceipt' );
  6019. $loanReceipt = new loanReceipt ();
  6020. // user verify ID
  6021. $verifyDetail = $verify->find ( array (
  6022. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6023. 'asArray' => true
  6024. ) );
  6025. foreach ( $verifyDetail as $key => $value ) {
  6026. array_push ( $vidList, $value ['vid'] );
  6027. }
  6028. $vid = implode ( ",", $vidList );
  6029. if (empty ( $verifyDetail ))
  6030. $vid = 0;
  6031. $categoryList = $Lcategory->find ( array (
  6032. 'asArray' => true
  6033. ) );
  6034. $staffList = $staff->find ( array (
  6035. 'where' => 'cid=' . $cid,
  6036. 'asArray' => true
  6037. ) );
  6038. $ap = "";
  6039. if ($status == 4) {
  6040. $ap = 4;
  6041. $status = 2;
  6042. }
  6043. // get Receipt By verifyID status 2
  6044. $receiptList = $receipt->find ( array (
  6045. 'where' => 'rid =' . $rid . ' and status=2',
  6046. 'desc' => 'rid',
  6047. 'asArray' => true
  6048. ) );
  6049. if (empty ( $receiptList )) {
  6050. die ( 'illegal request' );
  6051. }
  6052. $loanList = $loanReceipt->find ( array (
  6053. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  6054. 'desc' => 'rid',
  6055. 'asArray' => true
  6056. ) );
  6057. $data ['explanation'] = '';
  6058. if (! empty ( $loanList ))
  6059. $data ['explanation'] = $loanList [0] ['explanation'];
  6060. $Locate = 0;
  6061. $roleId = 0;
  6062. $button = 0;
  6063. foreach ( $loanList as $key => $value ) {
  6064. $loanList [$key] ['Locate'] = $Locate;
  6065. $Locate ++;
  6066. $loanList [$key] ['reviseDetail'] = array ();
  6067. if (! empty ( $value ['reviseDetail'] ))
  6068. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6069. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6070. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6071. $categoryDetil = $Lcategory->getOne ( array (
  6072. 'where' => 'cid=' . $value ['cid'],
  6073. 'asArray' => true
  6074. ) );
  6075. $loanList [$key] ['category'] = $categoryDetil ['title'];
  6076. // 检测编辑状态
  6077. $verifyList = $verify->getOne ( array (
  6078. 'where' => 'vid=' . $value ['verify'],
  6079. 'asArray' => true
  6080. ) );
  6081. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6082. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6083. Doo::loadModel ( 'role' );
  6084. $role = new role ();
  6085. $flag = true;
  6086. $roleKey = 0;
  6087. $endStaffArray = array ();
  6088. $roleArrayCopy = array ();
  6089. foreach ( $verifyList as $k => $v ) {
  6090. // init verifyStaff
  6091. if ($v [1] == 'ROLE') {
  6092. if (! empty ( $verifyStaff )) {
  6093. $endStaffArray = end ( $verifyStaff );
  6094. }
  6095. $roleVerify = json_decode ( $v [3], true );
  6096. $roleKey = $k;
  6097. $roleArray = array ();
  6098. $rolename = $role->getOne ( array (
  6099. 'where' => 'rid=' . $v [0],
  6100. 'asArray' => true
  6101. ) );
  6102. foreach ( $roleVerify as $o => $p ) {
  6103. $staffID = explode ( '_', $p );
  6104. $staffInfo = $staff->getOne ( array (
  6105. 'where' => 'sid=' . $staffID [0],
  6106. 'asArray' => true
  6107. ) );
  6108. // print_r($staffID);
  6109. $exp = array (
  6110. 0 => $staffInfo ['sid'],
  6111. 1 => $staffID [1],
  6112. 2 => $staffInfo ['avatar'],
  6113. 'date' => '',
  6114. 'date' => '',
  6115. 'opinion' => '',
  6116. 'status' => '',
  6117. 'rolename' => $rolename ['name']
  6118. );
  6119. array_push ( $roleArray, $exp );
  6120. }
  6121. $roleArrayCopy [$v [0]] = $roleArray;
  6122. // $verifyList[$k]['roleArray']=$roleArray;
  6123. }
  6124. $verifyList [$k] ['date'] = "";
  6125. $verifyList [$k] ['opinion'] = "";
  6126. $verifyList [$k] ['status'] = "";
  6127. if (empty ( $verifyStaff )) {
  6128. $verifyList [$k] ['date'] = "";
  6129. $verifyList [$k] ['opinion'] = "";
  6130. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6131. $verifyList [$k] ['status'] = 4;
  6132. $flag = false;
  6133. }
  6134. } else {
  6135. foreach ( $verifyStaff as $m => $u ) {
  6136. if ($v [0] == $m) {
  6137. $verifyList [$k] ['date'] = $u ['date'];
  6138. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6139. $verifyList [$k] ['status'] = $u ['status'];
  6140. $flag = false;
  6141. break;
  6142. }
  6143. }
  6144. $endStaffArray = end ( $verifyStaff );
  6145. if (isset ( $endStaffArray ['ROLE'] )) {
  6146. } else {
  6147. }
  6148. }
  6149. }
  6150. $rolename ['name'] = '';
  6151. if (! empty ( $roleId )) {
  6152. Doo::loadModel ( 'role' );
  6153. $role = new role ();
  6154. $rolename = $role->getOne ( array (
  6155. 'where' => 'rid=' . $roleId,
  6156. 'asArray' => true
  6157. ) );
  6158. }
  6159. if (! empty ( $verifyStaff ))
  6160. $endStaffArray = end ( $verifyStaff );
  6161. $KOP = false;
  6162. foreach ( $roleArrayCopy as $P => $A ) {
  6163. foreach ( $A as $MKI => $AVL ) {
  6164. if (! empty ( $verifyStaff )) {
  6165. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6166. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6167. $button = 4;
  6168. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6169. }
  6170. foreach ( $verifyStaff as $m => $u ) {
  6171. $AVLFK = $AVL [0] . '_R';
  6172. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6173. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6174. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6175. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6176. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6177. break;
  6178. }
  6179. }
  6180. } else {
  6181. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6182. $button = 4;
  6183. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6184. }
  6185. }
  6186. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6187. $KOP = true;
  6188. }
  6189. }
  6190. foreach ( $roleArrayCopy as $k => $v ) {
  6191. foreach ( $verifyList as $m => $n ) {
  6192. if ($n [0] == $k) {
  6193. array_splice ( $verifyList, $m, 1, $v );
  6194. }
  6195. }
  6196. }
  6197. $loanList [$key] ['verifyList'] = $verifyList;
  6198. }
  6199. $htmlLoan = '';
  6200. $data ['loanReceiptDate'] = '';
  6201. if (isset ( $loanList [0] )) {
  6202. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  6203. if ($value ['status'] == 1)
  6204. $htmlLoan .= '<li class="done" >';
  6205. elseif ($value ['status'] == 3)
  6206. $htmlLoan .= '<li class="undone" >';
  6207. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  6208. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  6209. if (isset ( $value ['rolename'] ))
  6210. $htmlLoan .= $value ['rolename'];
  6211. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  6212. }
  6213. $data ['loanDate'] = $loanList [0] ['date'];
  6214. } else {
  6215. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  6216. }
  6217. $data ['htmlLoan'] = $htmlLoan;
  6218. // $data ['LoanReceipt']=$loanList[0];
  6219. // print_r($loanList);
  6220. $Locate = 0;
  6221. $roleId = 0;
  6222. $button = 0;
  6223. if ($ap == 4)
  6224. $status = 4;
  6225. Doo::loadClass ( 'XDeode' );
  6226. $XDeode = new XDeode ( 5 );
  6227. foreach ( $receiptList as $key => $value ) {
  6228. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6229. $receiptList [$key] ['Locate'] = $Locate;
  6230. $Locate ++;
  6231. $receiptList [$key] ['reviseDetail'] = array ();
  6232. // 调整金额 代码调整
  6233. if (! empty ( $value ['reviseDetail'] )) {
  6234. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  6235. foreach ( $reviseDetail as $ry => $re ) {
  6236. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  6237. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  6238. }
  6239. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  6240. // print_r($reviseDetail);
  6241. }
  6242. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6243. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6244. $categoryDetil = $Lcategory->getOne ( array (
  6245. 'where' => 'cid=' . $value ['cid'],
  6246. 'asArray' => true
  6247. ) );
  6248. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6249. // 检测编辑状态
  6250. $verifyList = $verify->getOne ( array (
  6251. 'where' => 'vid=' . $value ['verify'],
  6252. 'asArray' => true
  6253. ) );
  6254. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6255. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6256. Doo::loadModel ( 'role' );
  6257. $role = new role ();
  6258. // print_r($verifyList);
  6259. $flag = true;
  6260. $roleKey = 0;
  6261. $endStaffArray = array ();
  6262. $roleArrayCopy = array ();
  6263. foreach ( $verifyList as $k => $v ) {
  6264. // init verifyStaff
  6265. if ($v [1] == 'ROLE') {
  6266. if (! empty ( $verifyStaff )) {
  6267. $endStaffArray = end ( $verifyStaff );
  6268. if ($v [0] == $endStaffArray ['nextStaff']) {
  6269. $roleId = $v [0];
  6270. }
  6271. }
  6272. $roleVerify = json_decode ( $v [3], true );
  6273. $roleKey = $k;
  6274. $roleArray = array ();
  6275. $rolename = $role->getOne ( array (
  6276. 'where' => 'rid=' . $v [0],
  6277. 'asArray' => true
  6278. ) );
  6279. foreach ( $roleVerify as $o => $p ) {
  6280. $staffID = explode ( '_', $p );
  6281. $staffInfo = $staff->getOne ( array (
  6282. 'where' => 'sid=' . $staffID [0],
  6283. 'asArray' => true
  6284. ) );
  6285. // print_r($staffID);
  6286. $exp = array (
  6287. 0 => $staffInfo ['sid'],
  6288. 1 => $staffID [1],
  6289. 2 => $staffInfo ['avatar'],
  6290. 'date' => '',
  6291. 'date' => '',
  6292. 'opinion' => '',
  6293. 'status' => '',
  6294. 'rolename' => $rolename ['name']
  6295. );
  6296. array_push ( $roleArray, $exp );
  6297. }
  6298. $roleArrayCopy [$v [0]] = $roleArray;
  6299. // $verifyList[$k]['roleArray']=$roleArray;
  6300. }
  6301. // print_r($roleArray);
  6302. $verifyList [$k] ['date'] = "";
  6303. $verifyList [$k] ['opinion'] = "";
  6304. $verifyList [$k] ['status'] = "";
  6305. if (empty ( $verifyStaff )) {
  6306. $verifyList [$k] ['date'] = "";
  6307. $verifyList [$k] ['opinion'] = "";
  6308. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6309. $verifyList [$k] ['status'] = 4;
  6310. $button = 4;
  6311. $flag = false;
  6312. }
  6313. } else {
  6314. foreach ( $verifyStaff as $m => $u ) {
  6315. if ($v [0] == $m) {
  6316. $verifyList [$k] ['date'] = $u ['date'];
  6317. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6318. $verifyList [$k] ['status'] = $u ['status'];
  6319. $flag = false;
  6320. break;
  6321. }
  6322. }
  6323. $endStaffArray = end ( $verifyStaff );
  6324. if (isset ( $endStaffArray ['ROLE'] )) {
  6325. } else {
  6326. $endKey = key ( $verifyStaff );
  6327. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6328. $button = 4;
  6329. $verifyList [$k] ['status'] = 4;
  6330. }
  6331. }
  6332. }
  6333. }
  6334. $rolename ['name'] = '';
  6335. if (! empty ( $roleId )) {
  6336. Doo::loadModel ( 'role' );
  6337. $role = new role ();
  6338. $rolename = $role->getOne ( array (
  6339. 'where' => 'rid=' . $roleId,
  6340. 'asArray' => true
  6341. ) );
  6342. }
  6343. if (! empty ( $verifyStaff ))
  6344. $endStaffArray = end ( $verifyStaff );
  6345. $KOP = false;
  6346. foreach ( $roleArrayCopy as $P => $A ) {
  6347. foreach ( $A as $MKI => $AVL ) {
  6348. if (! empty ( $verifyStaff )) {
  6349. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6350. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6351. $button = 4;
  6352. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6353. }
  6354. foreach ( $verifyStaff as $m => $u ) {
  6355. $AVLFK = $AVL [0] . '_R';
  6356. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6357. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6358. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6359. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6360. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6361. break;
  6362. }
  6363. }
  6364. } else {
  6365. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6366. $button = 4;
  6367. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6368. }
  6369. }
  6370. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6371. $KOP = true;
  6372. }
  6373. }
  6374. foreach ( $roleArrayCopy as $k => $v ) {
  6375. foreach ( $verifyList as $m => $n ) {
  6376. if ($n [0] == $k) {
  6377. array_splice ( $verifyList, $m, 1, $v );
  6378. }
  6379. }
  6380. }
  6381. // print_r($verifyList);
  6382. $receiptList [$key] ['verifyList'] = $verifyList;
  6383. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6384. 'where' => 'sid=' . $value ['staff'],
  6385. 'asArray' => true
  6386. ) );
  6387. $receiptList [$key] ['button'] = $button;
  6388. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6389. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6390. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6391. $receiptList [$key] ['relust'] = $relust;
  6392. $receiptList [$key] ['relustABS'] = abs ( $relust );
  6393. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  6394. }
  6395. //print_r($receiptList);die;
  6396. // $data['verifyDetail']=$verifyDetail;
  6397. $mothHtml = "";
  6398. for($i = 1; $i <= 12; $i ++) {
  6399. if ($month == $i)
  6400. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6401. else
  6402. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6403. }
  6404. // 获取审批日志
  6405. Doo::loadModel ( 'receiptLog' );
  6406. $receiptLog = new receiptLog ();
  6407. $rlList = array ();
  6408. $rlInfo = $receiptLog->getOne ( array (
  6409. 'where' => 'rid=' . $rid . ' and status=4',
  6410. 'asArray' => true
  6411. ) );
  6412. $tijdate = $receiptLog->getOne ( array (
  6413. 'where' => 'rid=' . $rid . ' and status=2',
  6414. 'asc' => 'rlid',
  6415. 'asArray' => true
  6416. ) );
  6417. if (! empty ( $rlInfo )) {
  6418. $rlList = $receiptLog->find ( array (
  6419. 'where' => 'rid=' . $rid,
  6420. 'asc' => 'rlid',
  6421. 'asArray' => true
  6422. ) );
  6423. }
  6424. // echo $rid;
  6425. // print_r($receiptList);
  6426. $receiptList [0] ['rlList'] = $rlList;
  6427. // print_r($receiptList);
  6428. $enclosurList = $enclosur->find ( array (
  6429. 'where' => 'rid=' . $rid,
  6430. 'asArray' => true
  6431. ) );
  6432. $enclosurHtml = '';
  6433. foreach ( $enclosurList as $value ) {
  6434. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6435. }
  6436. $data ['enclosurHtml'] = $enclosurHtml;
  6437. $data ['rolename'] = $rolename ['name'];
  6438. $data ['mothHtml'] = $mothHtml;
  6439. // print_r($receiptList);
  6440. $data ['rid'] = $rid;
  6441. $data ['tijdate'] = $tijdate ['date'];
  6442. $data ['receiptList'] = $receiptList;
  6443. $data ['receiptApprovalCount'] = count ( $receiptList );
  6444. $data ['status'] = $status;
  6445. $data ['year'] = $year;
  6446. $data ['categoryList'] = $categoryList;
  6447. $data ['staffList'] = $staffList;
  6448. $data ['cid'] = $cid;
  6449. $data ['sid'] = $sid;
  6450. $data ['ap'] = $ap;
  6451. $data ['memu'] = "receipt";
  6452. $data ['staff'] = $this->staff;
  6453. $data ['receiptMemu'] = 'approvalExpenses';
  6454. $data ['verifyId'] = $this->verifyId;
  6455. $data ['executeId'] = $this->executeId;
  6456. $this->render ( "/admin/receiptburEdi", $data );
  6457. }
  6458. function hisImplement() {
  6459. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6460. if (empty ( $item ))
  6461. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  6462. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  6463. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6464. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  6465. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  6466. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  6467. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  6468. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  6469. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  6470. Doo::loadClass ( 'XDeode' );
  6471. $XDeode = new XDeode ( 5 );
  6472. Doo::loadModel ( 'receipt' );
  6473. $receipt = new receipt ();
  6474. Doo::loadModel ( 'L_category' );
  6475. $Lcategory = new L_category ();
  6476. Doo::loadModel ( 'verify' );
  6477. Doo::loadModel ( 'statistics' );
  6478. $statistics = new statistics ();
  6479. $verify = new verify ();
  6480. Doo::loadModel ( 'staff' );
  6481. $staff = new staff ();
  6482. Doo::loadClass ( 'XDeode' );
  6483. $XDeode = new XDeode ( 5 );
  6484. $XDeode7 = new XDeode ( 7 );
  6485. $cid = $XDeode->decode ( $cidKey );
  6486. $condition = "";
  6487. if ($item == "expenses")
  6488. $condition = " and Rtype=1 ";
  6489. elseif ($item == "receipts")
  6490. $condition = " and Rtype=0 ";
  6491. elseif ($item == "remits")
  6492. $condition = " and Rtype=2 ";
  6493. elseif($item == "train")
  6494. $condition = " and Rtype=3 ";
  6495. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  6496. $sopString = $cidString = "";
  6497. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  6498. if (empty ( $rdate ))
  6499. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  6500. else
  6501. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  6502. if ($status == 'pendImplement') {
  6503. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  6504. } elseif ($status == 'alerpts') {
  6505. $statusCon = '(status=8 or status=9 )';
  6506. if (empty ( $rdate ))
  6507. $dateCondition .= " and Year(date) =" . $year;
  6508. else
  6509. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  6510. }
  6511. if ($sop != 'SOP')
  6512. $sopString = " and staff=" . $sop;
  6513. if ($cidKey != 'ALL')
  6514. $cidString = " and cid=" . $cid;
  6515. //汇款信息需要提取出来
  6516. if(!empty($receiptOrder)){
  6517. $receiptList = $receipt->find ( array (
  6518. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6519. 'desc' => 'rid',
  6520. 'asArray' => true
  6521. ) );
  6522. // 员工筛选
  6523. $receiptList2 = $receipt->find ( array (
  6524. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6525. 'desc' => 'rid',
  6526. 'asArray' => true
  6527. ) );
  6528. }else{
  6529. $receiptList = $receipt->find ( array (
  6530. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  6531. 'desc' => 'rid',
  6532. 'asArray' => true
  6533. ) );
  6534. // 员工筛选
  6535. $receiptList2 = $receipt->find ( array (
  6536. 'where' => $statusCon . $condition . $dateCondition,
  6537. 'desc' => 'rid',
  6538. 'asArray' => true
  6539. ) );
  6540. }
  6541. $sopStaff = array ();
  6542. foreach ( $receiptList2 as $key => $value ) {
  6543. $staffDetail = $staff->getOne ( array (
  6544. 'select' => 'username',
  6545. 'where' => 'sid=' . $value ['staff'],
  6546. 'asArray' => true
  6547. ) );
  6548. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  6549. }
  6550. // 办事处筛选
  6551. $categoryScreen = array ();
  6552. $categorList = $Lcategory->getCategory ();
  6553. foreach ( $receiptList2 as $key => $value ) {
  6554. foreach ( $categorList as $k => $v ) {
  6555. if ($value ['cid'] == $v ['cid']) {
  6556. $categoryScreen [$v ['cidKey']] = $v ['title'];
  6557. break;
  6558. }
  6559. }
  6560. }
  6561. $categoryScreenHtml = "";
  6562. foreach ( $categoryScreen as $key => $value ) {
  6563. if ($cidKey == $key)
  6564. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6565. else
  6566. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6567. }
  6568. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  6569. $data ['cidKey'] = $cidKey;
  6570. $Locate = 0;
  6571. $roleId = 0;
  6572. $button = 0;
  6573. $staffBatchNumber = 100001;
  6574. $remittanceList = array ();
  6575. foreach ( $receiptList as $key => $value ) {
  6576. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  6577. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6578. $receiptList [$key] ['Texe'] = 'false';
  6579. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  6580. $receiptList [$key] ['Texe'] = 'true';
  6581. }
  6582. $receiptList [$key] ['TRexe'] = 'true';
  6583. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  6584. $receiptList [$key] ['TRexe'] = 'false';
  6585. }
  6586. $receiptList [$key] ['Locate'] = $Locate;
  6587. $Locate ++;
  6588. $receiptList [$key] ['reviseDetail'] = array ();
  6589. if (! empty ( $value ['reviseDetail'] ))
  6590. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6591. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6592. $categoryDetil = $Lcategory->getOne ( array (
  6593. 'where' => 'cid=' . $value ['cid'],
  6594. 'asArray' => true
  6595. ) );
  6596. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6597. // 检测编辑状态
  6598. $verifyList = $verify->getOne ( array (
  6599. 'where' => 'vid=' . $value ['verify'],
  6600. 'asArray' => true
  6601. ) );
  6602. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6603. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6604. Doo::loadModel ( 'role' );
  6605. $role = new role ();
  6606. $flag = true;
  6607. $roleKey = 0;
  6608. $endStaffArray = array ();
  6609. $roleArrayCopy = array ();
  6610. foreach ( $verifyList as $k => $v ) {
  6611. // init verifyStaff
  6612. if ($v [1] == 'ROLE') {
  6613. if (! empty ( $verifyStaff )) {
  6614. $endStaffArray = end ( $verifyStaff );
  6615. }
  6616. $roleVerify = json_decode ( $v [3], true );
  6617. $roleKey = $k;
  6618. $roleArray = array ();
  6619. $rolename = $role->getOne ( array (
  6620. 'where' => 'rid=' . $v [0],
  6621. 'asArray' => true
  6622. ) );
  6623. foreach ( $roleVerify as $o => $p ) {
  6624. $staffID = explode ( '_', $p );
  6625. $staffInfo = $staff->getOne ( array (
  6626. 'where' => 'sid=' . $staffID [0],
  6627. 'asArray' => true
  6628. ) );
  6629. $exp = array (
  6630. 0 => $staffInfo ['sid'],
  6631. 1 => $staffID [1],
  6632. 2 => $staffInfo ['avatar'],
  6633. 'date' => '',
  6634. 'date' => '',
  6635. 'opinion' => '',
  6636. 'status' => '',
  6637. 'rolename' => $rolename ['name']
  6638. );
  6639. array_push ( $roleArray, $exp );
  6640. }
  6641. $roleArrayCopy [$v [0]] = $roleArray;
  6642. }
  6643. $verifyList [$k] ['date'] = "";
  6644. $verifyList [$k] ['opinion'] = "";
  6645. $verifyList [$k] ['status'] = "";
  6646. if (empty ( $verifyStaff )) {
  6647. $verifyList [$k] ['date'] = "";
  6648. $verifyList [$k] ['opinion'] = "";
  6649. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6650. $verifyList [$k] ['status'] = 4;
  6651. $flag = false;
  6652. }
  6653. } else {
  6654. foreach ( $verifyStaff as $m => $u ) {
  6655. if ($v [0] == $m) {
  6656. $verifyList [$k] ['date'] = $u ['date'];
  6657. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6658. $verifyList [$k] ['status'] = $u ['status'];
  6659. $flag = false;
  6660. break;
  6661. }
  6662. }
  6663. $endStaffArray = end ( $verifyStaff );
  6664. }
  6665. }
  6666. $rolename ['name'] = '';
  6667. if (! empty ( $roleId )) {
  6668. Doo::loadModel ( 'role' );
  6669. $role = new role ();
  6670. $rolename = $role->getOne ( array (
  6671. 'where' => 'rid=' . $roleId,
  6672. 'asArray' => true
  6673. ) );
  6674. }
  6675. if (! empty ( $verifyStaff ))
  6676. $endStaffArray = end ( $verifyStaff );
  6677. $KOP = false;
  6678. foreach ( $roleArrayCopy as $P => $A ) {
  6679. foreach ( $A as $MKI => $AVL ) {
  6680. if (! empty ( $verifyStaff )) {
  6681. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6682. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6683. $button = 4;
  6684. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6685. }
  6686. foreach ( $verifyStaff as $m => $u ) {
  6687. $AVLFK = $AVL [0] . '_R';
  6688. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6689. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6690. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6691. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6692. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6693. break;
  6694. }
  6695. }
  6696. } else {
  6697. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6698. $button = 4;
  6699. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6700. }
  6701. }
  6702. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6703. $KOP = true;
  6704. }
  6705. }
  6706. foreach ( $roleArrayCopy as $k => $v ) {
  6707. foreach ( $verifyList as $m => $n ) {
  6708. if ($n [0] == $k) {
  6709. array_splice ( $verifyList, $m, 1, $v );
  6710. }
  6711. }
  6712. }
  6713. $receiptList [$key] ['verifyList'] = $verifyList;
  6714. $staffDetail = $staff->getOne ( array (
  6715. 'where' => 'sid=' . $value ['staff'],
  6716. 'asArray' => true
  6717. ) );
  6718. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6719. $receiptList [$key] ['button'] = $button;
  6720. if ($value['Rtype']==1){
  6721. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  6722. $receiptList [$key] ['relustABS'] = abs($receiptList [$key] ['relust']);
  6723. }elseif($value['Rtype']==3){
  6724. // 收入合计
  6725. Doo::loadModel ( 'invoiceTraining' );
  6726. $invoiceTraining = new invoiceTraining ();
  6727. $invoiceTrainingDetail = array (
  6728. 'invoiceArriveAmount' => '0.00',
  6729. 'RIAmount' => '0.00',
  6730. 'invoiceTotalAmount' => '0.00',
  6731. 'invoiceCompanyAmount' => '0.00',
  6732. 'invoiceArriveAmountM'=>'0.00',
  6733. 'invoiceCompanyAmountM'=>'0.00'
  6734. );
  6735. if ($value ['invoiceTrainId'] != 0) {
  6736. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  6737. }
  6738. $invoiceArriveAmount = $RIAmount = 0;
  6739. if (! empty ( $invoiceTrainingDetail )) {
  6740. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  6741. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  6742. }
  6743. // 备用金
  6744. $sum = 0;
  6745. if (! empty ( $value ['trainLoanRid'] )) {
  6746. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  6747. foreach ($receiptLoanList as $kll=>$vll){
  6748. $sum+=$vll['sum'];
  6749. }
  6750. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  6751. // $sum = $receiptLoanDetailBak ['sum'];
  6752. }
  6753. // 支出项金额详情
  6754. // 项目金额合计
  6755. Doo::loadModel ( 'RItem' );
  6756. $RItem = new RItem ();
  6757. Doo::loadModel ( 'accountItem' );
  6758. $accountItem = new accountItem ();
  6759. // 讲师获得
  6760. Doo::loadModel ( 'RILecturer' );
  6761. $RILecturer = new RILecturer ();
  6762. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  6763. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  6764. // 支出项金额详情
  6765. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  6766. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  6767. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  6768. $receiptList [$key] ['payment'] =$payment;
  6769. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  6770. }
  6771. // 设置导出汇款execl
  6772. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6773. $remittanceDetail = array (
  6774. $staffBatchNumber,
  6775. $value ['remittanceName'],
  6776. $value ['bankNumber'],
  6777. $value ['bankName'],
  6778. $value ['remittanceBankType'],
  6779. $value ['coupletNumber'],
  6780. $value ['sum']
  6781. );
  6782. array_push ( $remittanceList, $remittanceDetail );
  6783. $staffBatchNumber ++;
  6784. }
  6785. }
  6786. $data ['remittanceList'] = json_encode ( $remittanceList );
  6787. // print_r($receiptList);
  6788. $mothHtml = "";
  6789. for($i = 1; $i <= 12; $i ++) {
  6790. if ($moth == $i)
  6791. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6792. else
  6793. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6794. }
  6795. $dayHtml = "";
  6796. if ($day != "DAY" || $moth != "MONTH") {
  6797. for($i = 1; $i <= 31; $i ++) {
  6798. if ($day == $i)
  6799. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6800. else
  6801. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6802. }
  6803. }
  6804. $sopHtml = "";
  6805. foreach ( $sopStaff as $key => $value ) {
  6806. if ($sop == $key)
  6807. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6808. else
  6809. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6810. }
  6811. $data ['status'] = $status;
  6812. $data ['rdate'] = $rdate;
  6813. $data ['sopHtml'] = $sopHtml;
  6814. $data ['dayHtml'] = $dayHtml;
  6815. $data ['mothHtml'] = $mothHtml;
  6816. $data ['receiptList'] = $receiptList;
  6817. $data ['memu'] = "receipt";
  6818. $data ['staff'] = $this->staff;
  6819. $data ['receiptMemu'] = 'implement';
  6820. $data ['verifyId'] = $this->verifyId;
  6821. $data ['executeId'] = $this->executeId;
  6822. $data ['item'] = $item;
  6823. $data ['year'] = $year;
  6824. $data ['moth'] = $moth;
  6825. $data['receiptOrder']=$receiptOrder;
  6826. $data ['day'] = $day;
  6827. $data ['sop'] = $sop;
  6828. $this->render ( "/admin/hisImplement", $data );
  6829. }
  6830. /**
  6831. * 导出汇款信息的exelc
  6832. */
  6833. function exportRemittance() {
  6834. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6835. if (empty ( $remittanceInfo ))
  6836. die ( 'illegal request' );
  6837. $title = array (
  6838. '员工编号',
  6839. '姓名',
  6840. '员工账号',
  6841. '员工账户开户行',
  6842. '转账类型',
  6843. '联行号',
  6844. '金额'
  6845. );
  6846. $data = json_decode ( $remittanceInfo, true );
  6847. if (empty ( $data ))
  6848. die ( 'illegal request' );
  6849. Doo::loadClass ( 'receipt.func' );
  6850. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6851. header ( 'Content-Type:text/html;charset=utf-8' );
  6852. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6853. }
  6854. function ajaxExamine() {
  6855. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6856. Doo::loadModel ( 'receipt' );
  6857. $receipt = new receipt ();
  6858. if (! empty ( $rid )) {
  6859. $rLRes = $receipt->find ( array (
  6860. '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,
  6861. 'asArray' => true
  6862. ) );
  6863. if(!empty($rLRes)){
  6864. Doo::loadClass ( 'XDeode' );
  6865. $XDeode = new XDeode ( 7 );
  6866. $rLRes [0]['ridKey'] = $XDeode->encode( $rLRes [0]['rid'] );
  6867. echo json_encode ( array (
  6868. 'status' => 1,
  6869. 'receipt' => $rLRes [0]
  6870. ) );
  6871. die ();
  6872. }else{
  6873. echo json_encode ( array (
  6874. 'status' => 1,
  6875. 'receipt' => array ()
  6876. ) );
  6877. die ();
  6878. }
  6879. }
  6880. echo json_encode ( array (
  6881. 'status' => 0,
  6882. 'receipt' => array ()
  6883. ) );
  6884. die ();
  6885. }
  6886. /*
  6887. * 废弃
  6888. */
  6889. function myReceipt() {
  6890. // all approval past withdraw
  6891. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6892. if (empty ( $item ))
  6893. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6894. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6895. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6896. Doo::loadModel ( 'receipt' );
  6897. $receipt = new receipt ();
  6898. // pre-loaded
  6899. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6900. // have cache
  6901. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6902. if (! empty ( $moth )) // yearPage
  6903. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6904. $this->showCache ( $path );
  6905. }
  6906. Doo::loadModel ( 'L_category' );
  6907. $Lcategory = new L_category ();
  6908. Doo::loadModel ( 'verify' );
  6909. Doo::loadModel ( 'statistics' );
  6910. $statistics = new statistics ();
  6911. $verify = new verify ();
  6912. Doo::loadModel ( 'staff' );
  6913. $staff = new staff ();
  6914. $condition = " and status!=0 ";
  6915. if ($item == "approval")
  6916. $condition = " and status=2 ";
  6917. elseif ($item == "withdraw")
  6918. $condition = " and status=3 ";
  6919. elseif ($item == "past")
  6920. $condition = " and status=1 ";
  6921. elseif ($item == "whdw")
  6922. $condition = " and status=4 ";
  6923. $dateCondition = " and Year(date) =" . $year;
  6924. if (! empty ( $moth )) {
  6925. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6926. $stList = $statistics->getOne ( array (
  6927. 'select' => 'rePrice ,agPrice',
  6928. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6929. 'asArray' => true
  6930. ) );
  6931. } else
  6932. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6933. if (empty ( $stList ))
  6934. $stList = array (
  6935. 'rePrice' => 0,
  6936. 'agPrice' => 0
  6937. );
  6938. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6939. $data ['stList'] = array (
  6940. 'rePrice' => $stList ['rePrice'],
  6941. 'agPrice' => $stList ['agPrice'],
  6942. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6943. );
  6944. $receiptList = $receipt->find ( array (
  6945. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6946. 'desc' => 'rid',
  6947. 'asArray' => true
  6948. ) );
  6949. $Locate = 0;
  6950. $roleId = 0;
  6951. $button = 0;
  6952. foreach ( $receiptList as $key => $value ) {
  6953. $receiptList [$key] ['Locate'] = $Locate;
  6954. $Locate ++;
  6955. $receiptList [$key] ['reviseDetail'] = array ();
  6956. if (! empty ( $value ['reviseDetail'] ))
  6957. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6958. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6959. $categoryDetil = $Lcategory->getOne ( array (
  6960. 'where' => 'cid=' . $value ['cid'],
  6961. 'asArray' => true
  6962. ) );
  6963. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6964. // 检测编辑状态
  6965. $verifyList = $verify->getOne ( array (
  6966. 'where' => 'vid=' . $value ['verify'],
  6967. 'asArray' => true
  6968. ) );
  6969. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6970. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6971. Doo::loadModel ( 'role' );
  6972. $role = new role ();
  6973. $flag = true;
  6974. $roleKey = 0;
  6975. $endStaffArray = array ();
  6976. $roleArrayCopy = array ();
  6977. foreach ( $verifyList as $k => $v ) {
  6978. // init verifyStaff
  6979. if ($v [1] == 'ROLE') {
  6980. if (! empty ( $verifyStaff )) {
  6981. $endStaffArray = end ( $verifyStaff );
  6982. // if ($v[0]==$endStaffArray['nextStaff']){
  6983. // $roleId=$v[0];
  6984. // }
  6985. }
  6986. $roleVerify = json_decode ( $v [3], true );
  6987. $roleKey = $k;
  6988. $roleArray = array ();
  6989. $rolename = $role->getOne ( array (
  6990. 'where' => 'rid=' . $v [0],
  6991. 'asArray' => true
  6992. ) );
  6993. foreach ( $roleVerify as $o => $p ) {
  6994. $staffID = explode ( '_', $p );
  6995. $staffInfo = $staff->getOne ( array (
  6996. 'where' => 'sid=' . $staffID [0],
  6997. 'asArray' => true
  6998. ) );
  6999. // print_r($staffID);
  7000. $exp = array (
  7001. 0 => $staffInfo ['sid'],
  7002. 1 => $staffID [1],
  7003. 2 => $staffInfo ['avatar'],
  7004. 'date' => '',
  7005. 'date' => '',
  7006. 'opinion' => '',
  7007. 'status' => '',
  7008. 'rolename' => $rolename ['name']
  7009. );
  7010. array_push ( $roleArray, $exp );
  7011. }
  7012. $roleArrayCopy [$v [0]] = $roleArray;
  7013. // $verifyList[$k]['roleArray']=$roleArray;
  7014. }
  7015. $verifyList [$k] ['date'] = "";
  7016. $verifyList [$k] ['opinion'] = "";
  7017. $verifyList [$k] ['status'] = "";
  7018. if (empty ( $verifyStaff )) {
  7019. $verifyList [$k] ['date'] = "";
  7020. $verifyList [$k] ['opinion'] = "";
  7021. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7022. $verifyList [$k] ['status'] = 4;
  7023. $flag = false;
  7024. }
  7025. } else {
  7026. foreach ( $verifyStaff as $m => $u ) {
  7027. if ($v [0] == $m) {
  7028. $verifyList [$k] ['date'] = $u ['date'];
  7029. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7030. $verifyList [$k] ['status'] = $u ['status'];
  7031. $flag = false;
  7032. break;
  7033. }
  7034. }
  7035. $endStaffArray = end ( $verifyStaff );
  7036. if (isset ( $endStaffArray ['ROLE'] )) {
  7037. } else {
  7038. // $endKey=key($verifyStaff);
  7039. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  7040. // $button=4;
  7041. // $verifyList[$k]['status']=4;
  7042. // }
  7043. }
  7044. }
  7045. }
  7046. $rolename ['name'] = '';
  7047. if (! empty ( $roleId )) {
  7048. Doo::loadModel ( 'role' );
  7049. $role = new role ();
  7050. $rolename = $role->getOne ( array (
  7051. 'where' => 'rid=' . $roleId,
  7052. 'asArray' => true
  7053. ) );
  7054. }
  7055. if (! empty ( $verifyStaff ))
  7056. $endStaffArray = end ( $verifyStaff );
  7057. $KOP = false;
  7058. foreach ( $roleArrayCopy as $P => $A ) {
  7059. foreach ( $A as $MKI => $AVL ) {
  7060. if (! empty ( $verifyStaff )) {
  7061. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7062. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7063. $button = 4;
  7064. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7065. }
  7066. foreach ( $verifyStaff as $m => $u ) {
  7067. $AVLFK = $AVL [0] . '_R';
  7068. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7069. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7070. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7071. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7072. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7073. break;
  7074. }
  7075. }
  7076. } else {
  7077. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7078. $button = 4;
  7079. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7080. }
  7081. }
  7082. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7083. $KOP = true;
  7084. }
  7085. }
  7086. foreach ( $roleArrayCopy as $k => $v ) {
  7087. foreach ( $verifyList as $m => $n ) {
  7088. if ($n [0] == $k) {
  7089. array_splice ( $verifyList, $m, 1, $v );
  7090. }
  7091. }
  7092. }
  7093. $receiptList [$key] ['verifyList'] = $verifyList;
  7094. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7095. 'where' => 'sid=' . $value ['staff'],
  7096. 'asArray' => true
  7097. ) );
  7098. $receiptList [$key] ['button'] = $button;
  7099. }
  7100. // print_r($receiptList);die;
  7101. $mothHtml = "";
  7102. for($i = 1; $i <= 12; $i ++) {
  7103. if ($moth == $i)
  7104. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7105. else
  7106. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7107. }
  7108. $data ['mothHtml'] = $mothHtml;
  7109. $data ['receiptList'] = $receiptList;
  7110. $data ['memu'] = "receipt";
  7111. $data ['staff'] = $this->staff;
  7112. $data ['receiptMemu'] = 'receipt';
  7113. $data ['verifyId'] = $this->verifyId;
  7114. $data ['executeId'] = $this->executeId;
  7115. $data ['item'] = $item;
  7116. $data ['year'] = $year;
  7117. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7118. // sufficient condition to generate cache
  7119. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  7120. $receiptList = $receipt->find ( array (
  7121. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7122. 'asArray' => true
  7123. ) );
  7124. if (empty ( $receiptList )) { // generated files
  7125. ob_start ();
  7126. $this->render ( "/admin/saea_myList", $data );
  7127. $this->cacheFile ( $path );
  7128. die ();
  7129. // $content = ob_get_contents();
  7130. // $fp = fopen($path, "w");
  7131. // fwrite($fp, $content);
  7132. // fclose($fp);
  7133. }
  7134. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  7135. $receiptList = $receipt->find ( array (
  7136. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  7137. 'asArray' => true
  7138. ) );
  7139. if (empty ( $receiptList )) { // generated files
  7140. ob_start ();
  7141. $this->render ( "/admin/saea_myList", $data );
  7142. $this->cacheFile ( $path );
  7143. die ();
  7144. }
  7145. }
  7146. }
  7147. $this->render ( "/admin/saea_myList", $data );
  7148. }
  7149. function approvedReceipt() {
  7150. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7151. Doo::loadModel ( 'receipt' );
  7152. Doo::loadModel ( 'receiptDetail' );
  7153. $receipt = new receipt ();
  7154. $receiptDetail = new receiptDetail ();
  7155. Doo::loadModel ( 'statistics' );
  7156. Doo::loadModel ( 'itemStatistics' );
  7157. $statistics = new statistics ();
  7158. $itemStatistics = new itemStatistics ();
  7159. Doo::loadModel ( "verify" );
  7160. $verify = new verify ();
  7161. // 审批状态的判定
  7162. $receiptDetailList = $receipt->getOne ( array (
  7163. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7164. 'asArray' => true
  7165. ) );
  7166. if (empty ( $receiptDetailList ))
  7167. return "/saeaBorad";
  7168. $verifyDetail = $verify->getOne ( array (
  7169. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7170. 'asArray' => true
  7171. ) );
  7172. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7173. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7174. $nowStaff = "";
  7175. $nowStaffList = array ();
  7176. if ($verifyDetail [0] [1] == 'ROLE') {
  7177. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7178. foreach ( $vStaffString as $key => $value ) {
  7179. $staffK = explode ( "_", $value );
  7180. array_push ( $nowStaffList, $staffK [0] );
  7181. }
  7182. $nowStaff = implode ( ',', $nowStaffList );
  7183. } else {
  7184. $nowStaff = $verifyDetail [0] [0];
  7185. }
  7186. $receipt->nowStaff = $nowStaff;
  7187. }
  7188. // echo $nowStaff;
  7189. // print_r($verifyDetail);die;
  7190. $receipt->rid = $receiptDetailList ['rid'];
  7191. $receipt->date = date ( "Y-m-d" );
  7192. $receipt->status = 2;
  7193. $receipt->update ();
  7194. $receiptDetail->status = 2;
  7195. $receiptDetail->update ( array (
  7196. 'where' => 'rid=' . $receiptDetailList ['rid']
  7197. ) );
  7198. Doo::loadModel ( "receiptLog" );
  7199. $receiptLog = new receiptLog ();
  7200. Doo::loadModel ( "verify" );
  7201. $verify = new verify ();
  7202. $receiptInfo = $receipt->getOne ( array (
  7203. 'where' => 'rid=' . $rid,
  7204. 'asArray' => true
  7205. ) );
  7206. $vr = $verify->getOne ( array (
  7207. 'where' => 'vid=' . $receiptInfo ['verify'],
  7208. 'asArray' => true
  7209. ) );
  7210. $jd = json_decode ( $vr ['staff'] );
  7211. $roleId = 0;
  7212. foreach ( $jd as $key => $value ) {
  7213. if ($value [1] == 'ROLE') {
  7214. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7215. if ($pos !== false) {
  7216. $roleId = $value [0];
  7217. }
  7218. }
  7219. }
  7220. // 审批日志
  7221. // echo $roleId;die;
  7222. if (! empty ( $roleId )) {
  7223. Doo::loadModel ( "role" );
  7224. $role = new role ();
  7225. $roleInfo = $role->getOne ( array (
  7226. 'where' => 'rid=' . $roleId,
  7227. 'asArray' => true
  7228. ) );
  7229. // $receiptLog->rolename = $roleInfo ['name'];
  7230. }
  7231. $receiptLog->username = $this->staff [0] ['username'];
  7232. $receiptLog->uid = $this->staff [0] ['sid'];
  7233. $receiptLog->date = date ( "Y-m-d" );
  7234. $receiptLog->opinion = '提交审批';
  7235. $receiptLog->img = $this->staff [0] ['avatar'];
  7236. $receiptLog->status = 2;
  7237. $receiptLog->rid = $rid;
  7238. $receiptLog->insert ();
  7239. // statistics item
  7240. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7241. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7242. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7243. $stat = $statistics->getOne ( array (
  7244. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7245. 'asArray' => true
  7246. ) );
  7247. if (empty ( $stat )) {
  7248. $statistics->date = date ( "Y-m-d" );
  7249. $statistics->cid = $this->staff [0] ['cid'];
  7250. $statistics->staff = $this->staff [0] ['sid'];
  7251. $statistics->agPrice = 0;
  7252. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7253. $statistics->insert ();
  7254. } else {
  7255. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7256. $statistics->update ( array (
  7257. 'where' => 'sid=' . $stat ['sid']
  7258. ) );
  7259. }
  7260. return "/expenses";
  7261. }
  7262. function approval() {
  7263. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7264. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7265. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7266. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7267. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7268. if (empty ( $status ))
  7269. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7270. $vidList = array ();
  7271. $button = 0;
  7272. Doo::loadModel ( 'verify' );
  7273. $verify = new verify ();
  7274. Doo::loadModel ( 'receipt' );
  7275. $receipt = new receipt ();
  7276. Doo::loadModel ( 'staff' );
  7277. $staff = new staff ();
  7278. Doo::loadModel ( 'L_category' );
  7279. $Lcategory = new L_category ();
  7280. // user verify ID
  7281. $verifyDetail = $verify->find ( array (
  7282. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7283. 'asArray' => true
  7284. ) );
  7285. foreach ( $verifyDetail as $key => $value ) {
  7286. array_push ( $vidList, $value ['vid'] );
  7287. }
  7288. $vid = implode ( ",", $vidList );
  7289. if (empty ( $verifyDetail ))
  7290. $vid = 0;
  7291. /*
  7292. */
  7293. $dateCondition = " and Year(date) =" . $year;
  7294. if (! empty ( $month ))
  7295. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7296. $categoryList = $Lcategory->find ( array (
  7297. 'asArray' => true
  7298. ) );
  7299. $staffList = $staff->find ( array (
  7300. 'where' => 'cid=' . $cid,
  7301. 'asArray' => true
  7302. ) );
  7303. $cateCondition = "";
  7304. $staffCondition = "";
  7305. $approvalCondition = "";
  7306. if (! empty ( $cid ))
  7307. $cateCondition = ' and cid=' . $cid;
  7308. if (! empty ( $sid )) {
  7309. $staffCondition = ' and staff=' . $sid;
  7310. $cateCondition = "";
  7311. }
  7312. // elseif($status==1){
  7313. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7314. // }
  7315. if ($status == 2) {
  7316. // 查找角色审批人
  7317. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7318. }
  7319. $ap = "";
  7320. if ($status == 4) {
  7321. $ap = 4;
  7322. $status = 2;
  7323. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7324. }
  7325. if ($status == 5) {
  7326. $status = 4;
  7327. $ap = 5;
  7328. }
  7329. // echo $vid;
  7330. // get Receipt By verifyID status 2 .$approvalCondition
  7331. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7332. $receiptList = $receipt->find ( array (
  7333. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7334. 'desc' => 'rid',
  7335. 'asArray' => true
  7336. ) );
  7337. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7338. $Locate = 0;
  7339. if ($ap == 4)
  7340. $status = 4;
  7341. elseif ($ap == 5)
  7342. $status = 5;
  7343. foreach ( $receiptList as $key => $value ) {
  7344. $receiptList [$key] ['Locate'] = $Locate;
  7345. $Locate ++;
  7346. $receiptList [$key] ['reviseDetail'] = array ();
  7347. if (! empty ( $value ['reviseDetail'] ))
  7348. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7349. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7350. $categoryDetil = $Lcategory->getOne ( array (
  7351. 'where' => 'cid=' . $value ['cid'],
  7352. 'asArray' => true
  7353. ) );
  7354. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7355. $verifyList = $verify->getOne ( array (
  7356. 'where' => 'vid=' . $value ['verify'],
  7357. 'asArray' => true
  7358. ) );
  7359. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7360. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7361. foreach ( $verifyList as $k => $v ) {
  7362. // init verifyStaff
  7363. $verifyList [$k] ['date'] = "";
  7364. $verifyList [$k] ['opinion'] = "";
  7365. $verifyList [$k] ['status'] = "";
  7366. if (empty ( $verifyStaff )) {
  7367. $verifyList [$k] ['date'] = "";
  7368. $verifyList [$k] ['opinion'] = "";
  7369. if ($v [0] == $this->staff [0] ['sid']) {
  7370. $verifyList [$k] ['status'] = 4;
  7371. $button = 4;
  7372. }
  7373. } else {
  7374. $flag = true;
  7375. foreach ( $verifyStaff as $m => $u ) {
  7376. if ($v [0] == $m) {
  7377. $verifyList [$k] ['date'] = $u ['date'];
  7378. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7379. $verifyList [$k] ['status'] = $u ['status'];
  7380. $flag = false;
  7381. break;
  7382. }
  7383. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7384. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7385. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7386. }
  7387. if ($flag) { // 检测可编辑
  7388. if ($v [0] == $this->staff [0] ['sid']) {
  7389. $verifyList [$k] ['status'] = 4;
  7390. $button = 4;
  7391. }
  7392. }
  7393. }
  7394. }
  7395. $receiptList [$key] ['verifyList'] = $verifyList;
  7396. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7397. 'where' => 'sid=' . $value ['staff'],
  7398. 'asArray' => true
  7399. ) );
  7400. $receiptList [$key] ['button'] = $button;
  7401. }
  7402. // print_r($receiptList);die;
  7403. // $data['verifyDetail']=$verifyDetail;
  7404. $mothHtml = "";
  7405. for($i = 1; $i <= 12; $i ++) {
  7406. if ($month == $i)
  7407. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7408. else
  7409. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7410. }
  7411. $data ['mothHtml'] = $mothHtml;
  7412. $data ['receiptList'] = $receiptList;
  7413. $data ['receiptApprovalCount'] = count ( $receiptList );
  7414. $data ['status'] = $status;
  7415. $data ['year'] = $year;
  7416. $data ['categoryList'] = $categoryList;
  7417. $data ['staffList'] = $staffList;
  7418. $data ['cid'] = $cid;
  7419. $data ['sid'] = $sid;
  7420. $data ['ap'] = $ap;
  7421. $data ['memu'] = "receipt";
  7422. $data ['staff'] = $this->staff;
  7423. $data ['receiptMemu'] = 'approval';
  7424. $data ['verifyId'] = $this->verifyId;
  7425. $data ['executeId'] = $this->executeId;
  7426. $this->render ( "/admin/saea_reportList", $data );
  7427. }
  7428. function approvalDetails() {
  7429. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7430. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7431. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7432. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7433. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7434. Doo::loadModel ( 'verify' );
  7435. $verify = new verify ();
  7436. Doo::loadModel ( 'receipt' );
  7437. $receipt = new receipt ();
  7438. Doo::loadModel ( 'staff' );
  7439. $staff = new staff ();
  7440. Doo::loadModel ( 'L_category' );
  7441. $Lcategory = new L_category ();
  7442. Doo::loadModel ( 'enclosur' );
  7443. $enclosur = new enclosur ();
  7444. $vidList = array ();
  7445. $verifyDetail = $verify->find ( array (
  7446. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7447. 'asArray' => true
  7448. ) );
  7449. foreach ( $verifyDetail as $key => $value ) {
  7450. array_push ( $vidList, $value ['vid'] );
  7451. }
  7452. $vid = implode ( ",", $vidList );
  7453. if (empty ( $verifyDetail ))
  7454. $vid = 0;
  7455. $categoryList = $Lcategory->find ( array (
  7456. 'asArray' => true
  7457. ) );
  7458. $staffList = $staff->find ( array (
  7459. 'where' => 'cid=' . $cid,
  7460. 'asArray' => true
  7461. ) );
  7462. $ap = 0;
  7463. $receiptList = $receipt->find ( array (
  7464. 'where' => 'rid =' . $rid,
  7465. 'desc' => 'rid',
  7466. 'asArray' => true
  7467. ) );
  7468. $Locate = 0;
  7469. $roleId = 0;
  7470. $button = 0;
  7471. foreach ( $receiptList as $key => $value ) {
  7472. $receiptList [$key] ['Locate'] = $Locate;
  7473. $Locate ++;
  7474. $receiptList [$key] ['reviseDetail'] = array ();
  7475. if (! empty ( $value ['reviseDetail'] ))
  7476. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7477. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7478. $categoryDetil = $Lcategory->getOne ( array (
  7479. 'where' => 'cid=' . $value ['cid'],
  7480. 'asArray' => true
  7481. ) );
  7482. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7483. // 检测编辑状态
  7484. $verifyList = $verify->getOne ( array (
  7485. 'where' => 'vid=' . $value ['verify'],
  7486. 'asArray' => true
  7487. ) );
  7488. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7489. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7490. Doo::loadModel ( 'role' );
  7491. $role = new role ();
  7492. // print_r($verifyList);
  7493. $flag = true;
  7494. $roleKey = 0;
  7495. $endStaffArray = array ();
  7496. $roleArrayCopy = array ();
  7497. foreach ( $verifyList as $k => $v ) {
  7498. // init verifyStaff
  7499. if ($v [1] == 'ROLE') {
  7500. if (! empty ( $verifyStaff )) {
  7501. $endStaffArray = end ( $verifyStaff );
  7502. if ($v [0] == $endStaffArray ['nextStaff']) {
  7503. $roleId = $v [0];
  7504. }
  7505. }
  7506. $roleVerify = json_decode ( $v [3], true );
  7507. $roleKey = $k;
  7508. $roleArray = array ();
  7509. $rolename = $role->getOne ( array (
  7510. 'where' => 'rid=' . $v [0],
  7511. 'asArray' => true
  7512. ) );
  7513. foreach ( $roleVerify as $o => $p ) {
  7514. $staffID = explode ( '_', $p );
  7515. $staffInfo = $staff->getOne ( array (
  7516. 'where' => 'sid=' . $staffID [0],
  7517. 'asArray' => true
  7518. ) );
  7519. // print_r($staffID);
  7520. $exp = array (
  7521. 0 => $staffInfo ['sid'],
  7522. 1 => $staffID [1],
  7523. 2 => $staffInfo ['avatar'],
  7524. 'date' => '',
  7525. 'date' => '',
  7526. 'opinion' => '',
  7527. 'status' => '',
  7528. 'rolename' => $rolename ['name']
  7529. );
  7530. array_push ( $roleArray, $exp );
  7531. }
  7532. $roleArrayCopy [$v [0]] = $roleArray;
  7533. // $verifyList[$k]['roleArray']=$roleArray;
  7534. }
  7535. // print_r($roleArray);
  7536. $verifyList [$k] ['date'] = "";
  7537. $verifyList [$k] ['opinion'] = "";
  7538. $verifyList [$k] ['status'] = "";
  7539. if (empty ( $verifyStaff )) {
  7540. $verifyList [$k] ['date'] = "";
  7541. $verifyList [$k] ['opinion'] = "";
  7542. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7543. $verifyList [$k] ['status'] = 4;
  7544. $button = 4;
  7545. $flag = false;
  7546. }
  7547. } else {
  7548. foreach ( $verifyStaff as $m => $u ) {
  7549. if ($v [0] == $m) {
  7550. $verifyList [$k] ['date'] = $u ['date'];
  7551. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7552. $verifyList [$k] ['status'] = $u ['status'];
  7553. $flag = false;
  7554. break;
  7555. }
  7556. }
  7557. $endStaffArray = end ( $verifyStaff );
  7558. if (isset ( $endStaffArray ['ROLE'] )) {
  7559. } else {
  7560. $endKey = key ( $verifyStaff );
  7561. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7562. $button = 4;
  7563. $verifyList [$k] ['status'] = 4;
  7564. }
  7565. }
  7566. }
  7567. }
  7568. $rolename ['name'] = '';
  7569. if (! empty ( $roleId )) {
  7570. Doo::loadModel ( 'role' );
  7571. $role = new role ();
  7572. $rolename = $role->getOne ( array (
  7573. 'where' => 'rid=' . $roleId,
  7574. 'asArray' => true
  7575. ) );
  7576. }
  7577. if (! empty ( $verifyStaff ))
  7578. $endStaffArray = end ( $verifyStaff );
  7579. $KOP = false;
  7580. foreach ( $roleArrayCopy as $P => $A ) {
  7581. foreach ( $A as $MKI => $AVL ) {
  7582. if (! empty ( $verifyStaff )) {
  7583. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7584. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7585. $button = 4;
  7586. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7587. }
  7588. foreach ( $verifyStaff as $m => $u ) {
  7589. $AVLFK = $AVL [0] . '_R';
  7590. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7591. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7592. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7593. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7594. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7595. break;
  7596. }
  7597. }
  7598. } else {
  7599. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7600. $button = 4;
  7601. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7602. }
  7603. }
  7604. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7605. $KOP = true;
  7606. }
  7607. }
  7608. foreach ( $roleArrayCopy as $k => $v ) {
  7609. foreach ( $verifyList as $m => $n ) {
  7610. if ($n [0] == $k) {
  7611. array_splice ( $verifyList, $m, 1, $v );
  7612. }
  7613. }
  7614. }
  7615. $receiptList [$key] ['verifyList'] = $verifyList;
  7616. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7617. 'where' => 'sid=' . $value ['staff'],
  7618. 'asArray' => true
  7619. ) );
  7620. $receiptList [$key] ['button'] = $button;
  7621. }
  7622. $mothHtml = "";
  7623. for($i = 1; $i <= 12; $i ++) {
  7624. if ($month == $i)
  7625. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7626. else
  7627. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7628. }
  7629. // 获取审批日志
  7630. Doo::loadModel ( 'receiptLog' );
  7631. $receiptLog = new receiptLog ();
  7632. $rlList = array ();
  7633. $rlInfo = $receiptLog->getOne ( array (
  7634. 'where' => 'rid=' . $rid . ' and status=4',
  7635. 'asArray' => true
  7636. ) );
  7637. $tijdate = $receiptLog->getOne ( array (
  7638. 'where' => 'rid=' . $rid . ' and status=2',
  7639. 'asc' => 'rlid',
  7640. 'asArray' => true
  7641. ) );
  7642. if (! empty ( $rlInfo )) {
  7643. $rlList = $receiptLog->find ( array (
  7644. 'where' => 'rid=' . $rid,
  7645. 'asc' => 'rlid',
  7646. 'asArray' => true
  7647. ) );
  7648. }
  7649. $receiptList [0] ['rlList'] = $rlList;
  7650. $enclosurList = $enclosur->find ( array (
  7651. 'where' => 'rid=' . $rid,
  7652. 'asArray' => true
  7653. ) );
  7654. $enclosurHtml = '';
  7655. foreach ( $enclosurList as $value ) {
  7656. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7657. }
  7658. $data ['enclosurHtml'] = $enclosurHtml;
  7659. $data ['rolename'] = $rolename ['name'];
  7660. $data ['datetij'] = $tijdate ['date'];
  7661. $data ['mothHtml'] = $mothHtml;
  7662. $data ['receiptList'] = $receiptList;
  7663. $data ['receiptApprovalCount'] = count ( $receiptList );
  7664. $data ['year'] = $year;
  7665. $data ['categoryList'] = $categoryList;
  7666. $data ['staffList'] = $staffList;
  7667. $data ['cid'] = $cid;
  7668. $data ['sid'] = $sid;
  7669. $data ['status'] = 0;
  7670. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7671. $ap = 4;
  7672. } else
  7673. $data ['status'] = $receiptList [0] ['status'];
  7674. if ($receiptList [0] ['status'] == 4) {
  7675. $data ['status'] = 5;
  7676. $ap = 0;
  7677. }
  7678. $data ['ap'] = $ap;
  7679. $data ['memu'] = "receipt";
  7680. $data ['staff'] = $this->staff;
  7681. $data ['receiptMemu'] = 'approval';
  7682. $data ['verifyId'] = $this->verifyId;
  7683. $data ['executeId'] = $this->executeId;
  7684. $this->render ( "/admin/saeaReportListReport", $data );
  7685. }
  7686. function approvalEdi() {
  7687. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7688. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7689. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7690. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7691. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7692. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7693. if (empty ( $status ))
  7694. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7695. $vidList = array ();
  7696. $button = 0;
  7697. Doo::loadModel ( 'verify' );
  7698. Doo::loadModel ( 'receipt' );
  7699. Doo::loadModel ( 'staff' );
  7700. $staff = new staff ();
  7701. $receipt = new receipt ();
  7702. $verify = new verify ();
  7703. Doo::loadModel ( 'L_category' );
  7704. $Lcategory = new L_category ();
  7705. Doo::loadModel ( 'enclosur' );
  7706. $enclosur = new enclosur ();
  7707. // user verify ID
  7708. $verifyDetail = $verify->find ( array (
  7709. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7710. 'asArray' => true
  7711. ) );
  7712. foreach ( $verifyDetail as $key => $value ) {
  7713. array_push ( $vidList, $value ['vid'] );
  7714. }
  7715. $vid = implode ( ",", $vidList );
  7716. if (empty ( $verifyDetail ))
  7717. $vid = 0;
  7718. $categoryList = $Lcategory->find ( array (
  7719. 'asArray' => true
  7720. ) );
  7721. $staffList = $staff->find ( array (
  7722. 'where' => 'cid=' . $cid,
  7723. 'asArray' => true
  7724. ) );
  7725. $ap = "";
  7726. if ($status == 4) {
  7727. $ap = 4;
  7728. $status = 2;
  7729. }
  7730. // get Receipt By verifyID status 2
  7731. $receiptList = $receipt->find ( array (
  7732. 'where' => 'rid =' . $rid,
  7733. 'desc' => 'rid',
  7734. 'asArray' => true
  7735. ) );
  7736. $Locate = 0;
  7737. $roleId = 0;
  7738. if ($ap == 4)
  7739. $status = 4;
  7740. foreach ( $receiptList as $key => $value ) {
  7741. $receiptList [$key] ['Locate'] = $Locate;
  7742. $Locate ++;
  7743. $receiptList [$key] ['reviseDetail'] = array ();
  7744. if (! empty ( $value ['reviseDetail'] ))
  7745. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7746. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7747. $categoryDetil = $Lcategory->getOne ( array (
  7748. 'where' => 'cid=' . $value ['cid'],
  7749. 'asArray' => true
  7750. ) );
  7751. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7752. // 检测编辑状态
  7753. $verifyList = $verify->getOne ( array (
  7754. 'where' => 'vid=' . $value ['verify'],
  7755. 'asArray' => true
  7756. ) );
  7757. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7758. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7759. // print_r($verifyList);
  7760. //
  7761. // if (empty($verifyStaff)){
  7762. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7763. // $verifyList[0]['status']=4;$button=4;
  7764. // }
  7765. //
  7766. // }else{
  7767. //
  7768. // }
  7769. // die;
  7770. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7771. // echo array_search("green",$a);
  7772. //
  7773. Doo::loadModel ( 'role' );
  7774. $role = new role ();
  7775. // print_r($verifyList);
  7776. $flag = true;
  7777. $roleKey = 0;
  7778. $endStaffArray = array ();
  7779. $roleArrayCopy = array ();
  7780. foreach ( $verifyList as $k => $v ) {
  7781. // init verifyStaff
  7782. if ($v [1] == 'ROLE') {
  7783. if (! empty ( $verifyStaff )) {
  7784. $endStaffArray = end ( $verifyStaff );
  7785. if ($v [0] == $endStaffArray ['nextStaff']) {
  7786. $roleId = $v [0];
  7787. }
  7788. }
  7789. $roleVerify = json_decode ( $v [3], true );
  7790. $roleKey = $k;
  7791. $roleArray = array ();
  7792. $rolename = $role->getOne ( array (
  7793. 'where' => 'rid=' . $v [0],
  7794. 'asArray' => true
  7795. ) );
  7796. foreach ( $roleVerify as $o => $p ) {
  7797. $staffID = explode ( '_', $p );
  7798. $staffInfo = $staff->getOne ( array (
  7799. 'where' => 'sid=' . $staffID [0],
  7800. 'asArray' => true
  7801. ) );
  7802. // print_r($staffID);
  7803. $exp = array (
  7804. 0 => $staffInfo ['sid'],
  7805. 1 => $staffID [1],
  7806. 2 => $staffInfo ['avatar'],
  7807. 'date' => '',
  7808. 'date' => '',
  7809. 'opinion' => '',
  7810. 'status' => '',
  7811. 'rolename' => $rolename ['name']
  7812. );
  7813. array_push ( $roleArray, $exp );
  7814. }
  7815. $roleArrayCopy [$v [0]] = $roleArray;
  7816. // $verifyList[$k]['roleArray']=$roleArray;
  7817. }
  7818. // print_r($roleArray);
  7819. $verifyList [$k] ['date'] = "";
  7820. $verifyList [$k] ['opinion'] = "";
  7821. $verifyList [$k] ['status'] = "";
  7822. if (empty ( $verifyStaff )) {
  7823. $verifyList [$k] ['date'] = "";
  7824. $verifyList [$k] ['opinion'] = "";
  7825. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7826. $verifyList [$k] ['status'] = 4;
  7827. $button = 4;
  7828. $flag = false;
  7829. }
  7830. } else {
  7831. foreach ( $verifyStaff as $m => $u ) {
  7832. if ($v [0] == $m) {
  7833. $verifyList [$k] ['date'] = $u ['date'];
  7834. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7835. $verifyList [$k] ['status'] = $u ['status'];
  7836. $flag = false;
  7837. break;
  7838. }
  7839. }
  7840. $endStaffArray = end ( $verifyStaff );
  7841. if (isset ( $endStaffArray ['ROLE'] )) {
  7842. } else {
  7843. $endKey = key ( $verifyStaff );
  7844. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7845. $button = 4;
  7846. $verifyList [$k] ['status'] = 4;
  7847. }
  7848. }
  7849. // print_r($endStaffArray);die;
  7850. // if (empty($verifyStaff)){
  7851. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7852. // $verifyList[$k]['status']=4;$button=4;
  7853. // }
  7854. //
  7855. // }else{
  7856. //
  7857. // }
  7858. // if($flag){//检测可编辑
  7859. // if($v[0]==$this->staff[0]['sid']){
  7860. // $verifyList[$k]['status']=4;$button=4;
  7861. // }
  7862. // }
  7863. }
  7864. }
  7865. $rolename ['name'] = '';
  7866. if (! empty ( $roleId )) {
  7867. Doo::loadModel ( 'role' );
  7868. $role = new role ();
  7869. $rolename = $role->getOne ( array (
  7870. 'where' => 'rid=' . $roleId,
  7871. 'asArray' => true
  7872. ) );
  7873. }
  7874. if (! empty ( $verifyStaff ))
  7875. $endStaffArray = end ( $verifyStaff );
  7876. $KOP = false;
  7877. foreach ( $roleArrayCopy as $P => $A ) {
  7878. foreach ( $A as $MKI => $AVL ) {
  7879. if (! empty ( $verifyStaff )) {
  7880. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7881. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7882. $button = 4;
  7883. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7884. }
  7885. foreach ( $verifyStaff as $m => $u ) {
  7886. $AVLFK = $AVL [0] . '_R';
  7887. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7888. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7889. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7890. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7891. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7892. break;
  7893. }
  7894. }
  7895. } else {
  7896. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7897. $button = 4;
  7898. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7899. }
  7900. }
  7901. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7902. $KOP = true;
  7903. }
  7904. }
  7905. // print_r($roleArrayCopy);
  7906. // echo $roleKey;
  7907. foreach ( $roleArrayCopy as $k => $v ) {
  7908. foreach ( $verifyList as $m => $n ) {
  7909. if ($n [0] == $k) {
  7910. array_splice ( $verifyList, $m, 1, $v );
  7911. }
  7912. }
  7913. }
  7914. // if ($KOP)
  7915. // array_splice($verifyList,$roleKey,1,$roleArray);
  7916. // print_r($verifyList);
  7917. $receiptList [$key] ['verifyList'] = $verifyList;
  7918. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7919. 'where' => 'sid=' . $value ['staff'],
  7920. 'asArray' => true
  7921. ) );
  7922. $receiptList [$key] ['button'] = $button;
  7923. }
  7924. // $data['verifyDetail']=$verifyDetail;
  7925. $mothHtml = "";
  7926. for($i = 1; $i <= 12; $i ++) {
  7927. if ($month == $i)
  7928. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7929. else
  7930. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7931. }
  7932. // 获取审批日志
  7933. Doo::loadModel ( 'receiptLog' );
  7934. $receiptLog = new receiptLog ();
  7935. $rlList = array ();
  7936. $rlInfo = $receiptLog->getOne ( array (
  7937. 'where' => 'rid=' . $rid . ' and status=4',
  7938. 'asArray' => true
  7939. ) );
  7940. $tijdate = $receiptLog->getOne ( array (
  7941. 'where' => 'rid=' . $rid . ' and status=2',
  7942. 'asc' => 'rlid',
  7943. 'asArray' => true
  7944. ) );
  7945. if (! empty ( $rlInfo )) {
  7946. $rlList = $receiptLog->find ( array (
  7947. 'where' => 'rid=' . $rid,
  7948. 'asc' => 'rlid',
  7949. 'asArray' => true
  7950. ) );
  7951. }
  7952. $receiptList [0] ['rlList'] = $rlList;
  7953. $enclosurList = $enclosur->find ( array (
  7954. 'where' => 'rid=' . $rid,
  7955. 'asArray' => true
  7956. ) );
  7957. $enclosurHtml = '';
  7958. foreach ( $enclosurList as $value ) {
  7959. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7960. }
  7961. $data ['enclosurHtml'] = $enclosurHtml;
  7962. $data ['rolename'] = $rolename ['name'];
  7963. $data ['datetij'] = $tijdate ['date'];
  7964. $data ['mothHtml'] = $mothHtml;
  7965. $data ['receiptList'] = $receiptList;
  7966. $data ['receiptApprovalCount'] = count ( $receiptList );
  7967. $data ['status'] = $status;
  7968. $data ['year'] = $year;
  7969. $data ['categoryList'] = $categoryList;
  7970. $data ['staffList'] = $staffList;
  7971. $data ['cid'] = $cid;
  7972. $data ['sid'] = $sid;
  7973. $data ['ap'] = $ap;
  7974. $data ['memu'] = "receipt";
  7975. $data ['staff'] = $this->staff;
  7976. $data ['receiptMemu'] = 'approval';
  7977. $data ['verifyId'] = $this->verifyId;
  7978. $data ['executeId'] = $this->executeId;
  7979. $this->render ( "/admin/saeaReportListReport", $data );
  7980. }
  7981. function remittanceHky() {
  7982. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7983. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7984. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7985. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7986. $page_size = 15;
  7987. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7988. Doo::loadModel ( 'receipt' );
  7989. $receipt = new receipt ();
  7990. Doo::loadModel ( 'staff' );
  7991. $staff = new staff ();
  7992. $dateCondition = " and Year(executeDate) =" . $year;
  7993. if ($moth != 'MONTH')
  7994. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7995. if ($day != 'DAY' && $moth != 'MONTH')
  7996. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7997. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  7998. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7999. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  8000. $limit = $pageinfo ['lower'] . ',' . $page_size;
  8001. $dayList = $receipt->find ( array (
  8002. 'select' => 'executeDate,sum(amount) as amount',
  8003. 'where' => $sql,
  8004. 'desc' => 'executeDate',
  8005. 'groupby' => 'executeDate',
  8006. 'limit' => $limit,
  8007. 'asArray' => true
  8008. ) );
  8009. // print_r($dayList);
  8010. foreach ( $dayList as $key => $value ) {
  8011. $remitString = "";
  8012. $receiptList = $receipt->find ( array (
  8013. 'select' => 'rid,executeDate,amount,staff,cid',
  8014. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  8015. 'desc' => 'executeDate',
  8016. 'asArray' => true
  8017. ) );
  8018. foreach ( $receiptList as $k => $v ) {
  8019. $sinfo = $staff->getOne ( array (
  8020. 'select' => 'username,category',
  8021. 'where' => ' sid=' . $v ['staff'],
  8022. 'asArray' => true
  8023. ) );
  8024. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  8025. }
  8026. $dayList [$key] ['staff'] = $remitString;
  8027. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  8028. }
  8029. // print_r($dayList);
  8030. $mothHtml = "";
  8031. for($i = 1; $i <= 12; $i ++) {
  8032. if ($moth == $i)
  8033. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8034. else
  8035. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8036. }
  8037. $dayHtml = "";
  8038. if ($day != "DAY" || $moth != "MONTH") {
  8039. for($i = 1; $i <= 31; $i ++) {
  8040. if ($day == $i)
  8041. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  8042. else
  8043. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  8044. }
  8045. }
  8046. $dateHtml = "";
  8047. $now = date ( "Y" );
  8048. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8049. if ($YEARD <= $now) {
  8050. $dateHtml .= '<option ';
  8051. if ($year == $YEARD) {
  8052. $dateHtml .= 'selected ';
  8053. }
  8054. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8055. }
  8056. }
  8057. $data ['dateHtml'] = $dateHtml;
  8058. $data ['page'] = $pageinfo;
  8059. $data ['year'] = $year;
  8060. $data ['moth'] = $moth;
  8061. $data ['day'] = $day;
  8062. $data ['get'] = $get;
  8063. $data ['dayHtml'] = $dayHtml;
  8064. $data ['mothHtml'] = $mothHtml;
  8065. $data ['receiptList'] = $dayList;
  8066. $data ['memu'] = "receipt";
  8067. $data ['staff'] = $this->staff;
  8068. $data ['receiptMemu'] = 'remittanceHky';
  8069. $data ['verifyId'] = $this->verifyId;
  8070. $data ['executeId'] = $this->executeId;
  8071. $this->render ( "/admin/remittanceHky", $data );
  8072. }
  8073. function remittancep() {
  8074. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8075. Doo::loadModel ( 'receipt' );
  8076. $receipt = new receipt ();
  8077. Doo::loadModel ( 'staff' );
  8078. $staff = new staff ();
  8079. Doo::loadClass ( 'XDeode' );
  8080. $XDeode = new XDeode ( 5 );
  8081. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8082. $rplist = $receipt->find ( array (
  8083. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8084. 'asArray' => true
  8085. ) );
  8086. $dayList = $receipt->find ( array (
  8087. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8088. 'desc' => 'executeDate',
  8089. 'groupby' => 'staff',
  8090. 'asArray' => true
  8091. ) );
  8092. $html = '';
  8093. foreach ( $dayList as $key => $value ) {
  8094. $sinfo = $staff->getOne ( array (
  8095. 'select' => 'username,category',
  8096. 'where' => ' sid=' . $value ['staff'],
  8097. 'asArray' => true
  8098. ) );
  8099. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8100. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8101. $au = 0;
  8102. foreach ( $rplist as $k => $v ) {
  8103. if ($value ['staff'] == $v ['staff']) {
  8104. $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>';
  8105. $au += $v ['amount'];
  8106. }
  8107. }
  8108. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8109. }
  8110. $data ['html'] = $html;
  8111. $data ['memu'] = "receipt";
  8112. $data ['staff'] = $this->staff;
  8113. $data ['receiptMemu'] = 'remittanceHky';
  8114. $data ['verifyId'] = $this->verifyId;
  8115. $data ['executeId'] = $this->executeId;
  8116. $this->render ( "/admin/remittancep", $data );
  8117. }
  8118. function ajaxGetReceiptDetails() {
  8119. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8120. Doo::loadClass ( 'XDeode' );
  8121. $XDeode = new XDeode ( 5 );
  8122. $rid = $XDeode->decode ( $rid );
  8123. if (empty ( $rid )) {
  8124. echo json_encode ( array (
  8125. 'status' => 2,
  8126. 'msg' => 'illegal request'
  8127. ) );
  8128. die ();
  8129. }
  8130. Doo::loadModel ( 'receipt' );
  8131. $receipt = new receipt ();
  8132. Doo::loadModel ( 'staff' );
  8133. $staff = new staff ();
  8134. $rinfo = $receipt->getOne ( array (
  8135. 'where' => 'rid= ' . $rid,
  8136. 'asArray' => true
  8137. ) );
  8138. $sinfo = $staff->getOne ( array (
  8139. 'select' => 'username,category',
  8140. 'where' => ' sid=' . $rinfo ['staff'],
  8141. 'asArray' => true
  8142. ) );
  8143. $rinfo ['reviseDetail'] = array ();
  8144. if (! empty ( $rinfo ['reviseDetail'] ))
  8145. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8146. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8147. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8148. $rinfo ['category'] = $sinfo ['category'];
  8149. $verifyStaff = array ();
  8150. if (! empty ( $rinfo ['verifyStaff'] ))
  8151. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8152. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8153. $rinfo ['relust'] = $relust;
  8154. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8155. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8156. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8157. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8158. // 费用执行人相关数据
  8159. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8160. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8161. foreach ( $executeCopy as $k => $v ) {
  8162. $executeCopy [$k] ['date'] = '';
  8163. $executeCopy [$k] ['opinion'] = '';
  8164. $executeCopy [$k] ['status'] = '';
  8165. if (! empty ( $executeStaff ))
  8166. foreach ( $executeStaff as $m => $u ) {
  8167. if ($v [0] == $m) {
  8168. $executeCopy [$k] ['date'] = $u ['date'];
  8169. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8170. $executeCopy [$k] ['status'] = $u ['status'];
  8171. break;
  8172. }
  8173. }
  8174. }
  8175. $rinfo ['executeCopy'] = $executeCopy;
  8176. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8177. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8178. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8179. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8180. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8181. $html .= '<tr><th>' . $value ['name'] . '</th>
  8182. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8183. }
  8184. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8185. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8186. <tr><th class="taC" colspan="2">费用说明</th>
  8187. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8188. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8189. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8190. </tbody></table>';
  8191. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8192. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8193. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8194. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8195. $html .= '<tr><th>' . $value ['name'] . '</th>
  8196. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8197. }
  8198. $html .= '<tr><th class="taR">合计</th>
  8199. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8200. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8201. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8202. $html .= '<tr><th>' . $value ['name'] . '</th>
  8203. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8204. }
  8205. $html .= '<tr><th class="taR">合计</th>
  8206. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8207. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8208. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8209. $html .= '<tr><th>' . $value ['name'] . '</th>
  8210. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8211. }
  8212. $html .= '<tr><th class="taR">合计</th>
  8213. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8214. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8215. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8216. $html .= '<tr><th>' . $value ['name'] . '</th>
  8217. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8218. }
  8219. $html .= '<tr><th class="taR">合计</th>
  8220. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8221. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8222. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8223. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8224. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8225. }
  8226. $html .= '<tr><th class="taR">合计</th>
  8227. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8228. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8229. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8230. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8231. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8232. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8233. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8234. <tr';
  8235. if ($rinfo ['relust'] >= 0) {
  8236. $html .= 'class="success"';
  8237. } else {
  8238. $html .= 'class="error"';
  8239. }
  8240. $html .= '><td class="taR"><b>借款结余</b></td>
  8241. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8242. </tbody></table>
  8243. ';
  8244. }
  8245. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8246. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8247. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8248. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8249. $html .= '<tr><th>' . $value ['name'] . '</th>
  8250. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8251. }
  8252. $html .= '<tr><th class="taR">合计</th>
  8253. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8254. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8255. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8256. <tr><th class="taC" colspan="2">费用说明</th>
  8257. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8258. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8259. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8260. </tbody></table>';
  8261. } else {
  8262. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8263. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8264. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8265. $html .= '<tr><th>' . $value ['name'] . '</th>
  8266. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8267. }
  8268. $html .= '<tr><th class="taR">合计</th>
  8269. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8270. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8271. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8272. $html .= '<tr><th>' . $value ['name'] . '</th>
  8273. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8274. }
  8275. $html .= '<tr><th class="taR">合计</th>
  8276. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8277. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8278. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8279. $html .= '<tr><th>' . $value ['name'] . '</th>
  8280. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8281. }
  8282. $html .= '<tr><th class="taR">合计</th>
  8283. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8284. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8285. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8286. $html .= '<tr><th>' . $value ['name'] . '</th>
  8287. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8288. }
  8289. $html .= '<tr><th class="taR">合计</th>
  8290. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8291. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8292. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8293. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8294. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8295. }
  8296. $html .= '<tr><th class="taR">合计</th>
  8297. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8298. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8299. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8300. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8301. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8302. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8303. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8304. $html .= '</tbody></table>';
  8305. /*
  8306. * <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>
  8307. */
  8308. }
  8309. // print_r($verifyStaff);die;
  8310. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8311. foreach ( $verifyStaff as $key => $value ) {
  8312. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8313. $sinfo = $staff->getOne ( array (
  8314. 'select' => 'username',
  8315. 'where' => ' sid=' . $key,
  8316. 'asArray' => true
  8317. ) );
  8318. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8319. }
  8320. $html .= '</tbody></table>';
  8321. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8322. foreach ( $rinfo ['executeCopy'] as $value ) {
  8323. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8324. }
  8325. $html .= '</tbody></table>';
  8326. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8327. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8328. </tr></table>';
  8329. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8330. echo json_encode ( array (
  8331. 'status' => 1,
  8332. 'html' => $html
  8333. ) );
  8334. die ();
  8335. }
  8336. /**
  8337. * 删除附件
  8338. */
  8339. function ajaxRemEnclousur() {
  8340. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8341. if (empty ( $key ))
  8342. echo json_encode ( array (
  8343. 'status' => 2
  8344. ) );
  8345. Doo::loadModel ( 'enclosur' );
  8346. $enclosur = new enclosur ();
  8347. $enclosur->delEnclosurByEid ( $key );
  8348. echo json_encode ( array (
  8349. 'status' => 1
  8350. ) );
  8351. }
  8352. function remittance() {
  8353. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8354. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8355. Doo::loadModel ( 'receipt' );
  8356. $receipt = new receipt ();
  8357. Doo::loadModel ( 'staff' );
  8358. $staff = new staff ();
  8359. $dateCondition = " and Year(pastDate) =" . $year;
  8360. if (! empty ( $month ))
  8361. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8362. // get Receipt By verifyID status 1
  8363. $receiptList = $receipt->find ( array (
  8364. 'select' => 'sum(sum) as sum,staff,pastDate',
  8365. 'where' => ' status=1' . $dateCondition,
  8366. 'desc' => 'pastDate',
  8367. 'groupby' => 'staff,pastDate',
  8368. 'asArray' => true
  8369. ) );
  8370. $dateList = $receipt->find ( array (
  8371. 'select' => 'pastDate,verifyStaff',
  8372. 'where' => ' status=1' . $dateCondition,
  8373. 'desc' => 'pastDate',
  8374. 'groupby' => 'pastDate',
  8375. 'asArray' => true
  8376. ) );
  8377. $dataList = array ();
  8378. foreach ( $dateList as $d => $a ) {
  8379. $dataList [$a ['pastDate']] = array ();
  8380. $daySum = 0;
  8381. foreach ( $receiptList as $key => $value ) {
  8382. if ($a ['pastDate'] == $value ['pastDate']) {
  8383. $oderList = $receipt->find ( array (
  8384. 'select' => 'receiptOrder',
  8385. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8386. 'asArray' => true
  8387. ) );
  8388. $list = array ();
  8389. $html = "";
  8390. foreach ( $oderList as $v ) {
  8391. array_push ( $list, $v ['receiptOrder'] );
  8392. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8393. }
  8394. $receiptList [$key] ['receiptOrder'] = $html;
  8395. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8396. $sinfo = $staff->getOne ( array (
  8397. 'select' => 'username ',
  8398. 'where' => ' sid=' . $value ['staff'],
  8399. 'asArray' => true
  8400. ) );
  8401. $receiptList [$key] ['username'] = $sinfo ['username'];
  8402. $daySum += $value ['sum'];
  8403. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8404. }
  8405. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8406. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8407. }
  8408. }
  8409. // print_r($dataList);
  8410. $data ['dataList'] = $dataList;
  8411. $mothHtml = "";
  8412. for($i = 1; $i <= 12; $i ++) {
  8413. if ($month == $i)
  8414. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8415. else
  8416. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8417. }
  8418. $data ['year'] = $year;
  8419. $data ['mothHtml'] = $mothHtml;
  8420. $data ['memu'] = "receipt";
  8421. $data ['staff'] = $this->staff;
  8422. $data ['receiptMemu'] = 'approval';
  8423. $data ['verifyId'] = $this->verifyId;
  8424. $data ['executeId'] = $this->executeId;
  8425. $this->render ( "/admin/saeaReportListPay", $data );
  8426. }
  8427. /**
  8428. * 金额调整,提高稳定性
  8429. * @return string
  8430. */
  8431. function revocationAdjustment() {
  8432. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8433. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8434. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8435. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8436. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8437. Doo::loadClass ( 'XDeode' );
  8438. $XDeode = new XDeode ( 5 );
  8439. Doo::loadModel ( 'receipt' );
  8440. $receipt = new receipt ();
  8441. $sid = $XDeode->decode ( $sidKey );
  8442. $rid = $XDeode->decode ( $ridKey );
  8443. $reviseKey = $XDeode->decode ( $reviseKey );
  8444. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8445. die ( 'illegal request' );
  8446. $receiptDetail = $receipt->getOne ( array (
  8447. 'where' => 'rid=' . $rid,
  8448. 'asArray' => true
  8449. ) );
  8450. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8451. die ( 'illegal request' );
  8452. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8453. if (! isset ( $reviseDetail [$reviseKey] ))
  8454. die ( 'illegal request' );
  8455. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8456. unset ( $reviseDetail [$reviseKey] );
  8457. $revisePrice = 0;
  8458. foreach ( $reviseDetail as $key => $value ) {
  8459. $revisePrice += $value ['price'];
  8460. }
  8461. $reviseDetailString = json_encode ( $reviseDetail );
  8462. $receipt->reviseDetail = $reviseDetailString;
  8463. $receipt->sum = $receiptDetail ['sum'] - $price;
  8464. $receipt->revisePrice = $revisePrice;
  8465. $receipt->update ( array (
  8466. 'where' => 'rid=' . $rid
  8467. ) );
  8468. return '/receiptburEdi/' . $rid;
  8469. } else
  8470. die ( 'illegal request2' );
  8471. }
  8472. function updateApprovalReceipt() {
  8473. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8474. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8475. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8476. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8477. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8478. if (! empty ( $rid )) {
  8479. Doo::loadModel ( "verify" );
  8480. $verify = new verify ();
  8481. Doo::loadModel ( "receiptDetail" );
  8482. $receiptDetailObj = new receiptDetail ();
  8483. Doo::loadModel ( "itemStatistics" );
  8484. Doo::loadModel ( "statistics" );
  8485. $statistics = new statistics ();
  8486. $itemStatistics = new itemStatistics ();
  8487. Doo::loadModel ( "receipt" );
  8488. $receipt = new receipt ();
  8489. $receiptDetail = $receipt->getOne ( array (
  8490. 'where' => 'rid=' . $rid . ' and status=2 ',
  8491. 'asArray' => true
  8492. ) );
  8493. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8494. $nsflag = true;
  8495. foreach ( $nslist as $value ) {
  8496. if ($value == $this->staff ['0'] ['sid']) {
  8497. $nsflag = false;
  8498. break;
  8499. }
  8500. }
  8501. if (empty ( $receiptDetail ) || $nsflag)
  8502. return "/approvalExpenses/pendApproval";
  8503. $verifyDetail = $verify->getOne ( array (
  8504. 'where' => ' vid =' . $receiptDetail ['verify'],
  8505. 'asArray' => true
  8506. ) );
  8507. $verifyString = $verifyDetail ['staff'];
  8508. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8509. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8510. if (empty ( $opinion )) {
  8511. if ($status == 3)
  8512. $opinion = "终止";
  8513. else
  8514. $opinion = "同意支付";
  8515. }
  8516. $nowStaff = 0;
  8517. $nowStaffList = array ();
  8518. if (empty ( $verifyStaff )) {
  8519. // 还需加入是否已经进入角色审批
  8520. if ($verifyDetail [0] [1] == 'ROLE') {
  8521. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8522. foreach ( $vStaffString as $key => $value ) {
  8523. $staffK = explode ( "_", $value );
  8524. if ($staffK [0] != $this->staff [0] ['sid'])
  8525. array_push ( $nowStaffList, $staffK [0] );
  8526. }
  8527. // print_r($verifyDetail);
  8528. // die;
  8529. if (! empty ( $nowStaffList )) {
  8530. $nowStaff = implode ( ',', $nowStaffList );
  8531. $verifyStaff = array (
  8532. $this->staff [0] ['sid'] . "_R" => array (
  8533. 'date' => date ( 'Y-m-d' ),
  8534. 'opinion' => $opinion,
  8535. 'status' => $status,
  8536. 'nextStaff' => $verifyDetail [0] [0],
  8537. 'ROLE' => 1
  8538. )
  8539. );
  8540. } else {
  8541. $nowStaff = $verifyDetail [1] [0];
  8542. $verifyStaff = array (
  8543. $this->staff [0] ['sid'] . "_R" => array (
  8544. 'date' => date ( 'Y-m-d' ),
  8545. 'opinion' => $opinion,
  8546. 'status' => $status,
  8547. 'nextStaff' => $verifyDetail [1] [0]
  8548. )
  8549. );
  8550. }
  8551. } else {
  8552. if ($verifyDetail [1] [1] == 'ROLE') {
  8553. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8554. // echo "dd";
  8555. foreach ( $vStaffString as $key => $value ) {
  8556. $staffK = explode ( "_", $value );
  8557. array_push ( $nowStaffList, $staffK [0] );
  8558. }
  8559. $nowStaff = implode ( ',', $nowStaffList );
  8560. $verifyStaff = array (
  8561. $this->staff [0] ['sid'] => array (
  8562. 'date' => date ( 'Y-m-d' ),
  8563. 'opinion' => $opinion,
  8564. 'status' => $status,
  8565. 'nextStaff' => $verifyDetail [1] [0],
  8566. 'ROLE' => 1
  8567. )
  8568. );
  8569. } else {
  8570. $nowStaff = $verifyDetail [1] [0];
  8571. $verifyStaff = array (
  8572. $this->staff [0] ['sid'] => array (
  8573. 'date' => date ( 'Y-m-d' ),
  8574. 'opinion' => $opinion,
  8575. 'status' => $status,
  8576. 'nextStaff' => $verifyDetail [1] [0]
  8577. )
  8578. );
  8579. }
  8580. }
  8581. if ($status == 3)
  8582. $verifyStaff = array (
  8583. 'final' => $status,
  8584. $this->staff [0] ['sid'] => array (
  8585. 'date' => date ( 'Y-m-d' ),
  8586. 'opinion' => $opinion,
  8587. 'status' => $status
  8588. )
  8589. );
  8590. $vStaffString = json_encode ( $verifyStaff );
  8591. $receipt->nowStaff = $nowStaff;
  8592. $receipt->verifyStaff = $vStaffString;
  8593. } else {
  8594. $VS = end ( $verifyStaff );
  8595. // 非角色审批
  8596. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8597. $nextStaff = 0;
  8598. $roleSTF = false;
  8599. foreach ( $verifyDetail as $key => $value ) {
  8600. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8601. if (isset ( $verifyDetail [$key + 1] )) {
  8602. $nextStaff = $verifyDetail [$key + 1] [0];
  8603. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8604. $roleSTF = true;
  8605. }
  8606. break;
  8607. }
  8608. }
  8609. if (! $roleSTF) {
  8610. $nowStaff = $nextStaff;
  8611. $verifyStaff [$this->staff [0] ['sid']] = array (
  8612. 'date' => date ( 'Y-m-d' ),
  8613. 'opinion' => $opinion,
  8614. 'status' => $status,
  8615. 'nextStaff' => $nextStaff
  8616. );
  8617. } else {
  8618. // 获取角色下的所有用户ID
  8619. $nowStaffList = array ();
  8620. foreach ( $verifyDetail as $vfk ) {
  8621. if ($vfk [1] == 'ROLE') {
  8622. $vStaffString = json_decode ( $vfk [3] );
  8623. foreach ( $vStaffString as $key => $value ) {
  8624. $staffK = explode ( "_", $value );
  8625. array_push ( $nowStaffList, $staffK [0] );
  8626. }
  8627. }
  8628. }
  8629. $nowStaff = implode ( ',', $nowStaffList );
  8630. $verifyStaff [$this->staff [0] ['sid']] = array (
  8631. 'date' => date ( 'Y-m-d' ),
  8632. 'opinion' => $opinion,
  8633. 'status' => $status,
  8634. 'nextStaff' => $nextStaff,
  8635. 'ROLE' => 0
  8636. );
  8637. }
  8638. if ($status == 3) {
  8639. $verifyStaff ['final'] = $status;
  8640. $verifyStaff [$this->staff [0] ['sid']] = array (
  8641. 'date' => date ( 'Y-m-d' ),
  8642. 'opinion' => $opinion,
  8643. 'status' => $status
  8644. );
  8645. }
  8646. $vStaffString = json_encode ( $verifyStaff );
  8647. $receipt->nowStaff = $nowStaff;
  8648. $receipt->verifyStaff = $vStaffString;
  8649. }
  8650. // 角色审批
  8651. if (isset ( $VS ['ROLE'] )) {
  8652. // 找出角色人 当前审批角色组
  8653. $verifyJSStaff = array ();
  8654. $nowStaffList2 = array ();
  8655. foreach ( $verifyDetail as $key => $value ) {
  8656. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8657. $verifyJSStaff = json_decode ( $value [3] );
  8658. foreach ( $verifyJSStaff as $m ) {
  8659. $staffK = explode ( "_", $m );
  8660. array_push ( $nowStaffList2, $staffK [0] );
  8661. }
  8662. // print_r($nowStaffList2);
  8663. }
  8664. }
  8665. $RoleVerifyStaff = array ();
  8666. foreach ( $verifyStaff as $key => $value ) {
  8667. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8668. foreach ( $nowStaffList2 as $m ) {
  8669. if ($key == $m . "_R")
  8670. $RoleVerifyStaff [$key] = $value;
  8671. }
  8672. }
  8673. }
  8674. // print_r($verifyStaff);
  8675. // print_r($nowStaffList2);
  8676. // print_r($RoleVerifyStaff);
  8677. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8678. // print_r($verifyJSStaff);
  8679. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8680. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8681. // 下一个审批人ID
  8682. $nextStaff = 0;
  8683. $falg = false;
  8684. foreach ( $verifyDetail as $key => $value ) {
  8685. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8686. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8687. $falg = true;
  8688. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8689. $nowStaffList = array ();
  8690. foreach ( $vStaffString as $v ) {
  8691. $staffK = explode ( "_", $v );
  8692. array_push ( $nowStaffList, $staffK [0] );
  8693. }
  8694. $nowStaff = implode ( ',', $nowStaffList );
  8695. $nextStaff = $verifyDetail [$key + 1] [0];
  8696. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8697. $nextStaff = $verifyDetail [$key + 1] [0];
  8698. $nowStaff = $nextStaff;
  8699. } else
  8700. $nowStaff = '';
  8701. break;
  8702. }
  8703. }
  8704. if ($falg)
  8705. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8706. 'date' => date ( 'Y-m-d' ),
  8707. 'opinion' => $opinion,
  8708. 'status' => $status,
  8709. 'nextStaff' => $nextStaff,
  8710. 'ROLE' => 1
  8711. );
  8712. else
  8713. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8714. 'date' => date ( 'Y-m-d' ),
  8715. 'opinion' => $opinion,
  8716. 'status' => $status,
  8717. 'nextStaff' => $nextStaff
  8718. );
  8719. // print_r($verifyStaff);
  8720. // echo $nowStaff;die;
  8721. } else { // 进入下一个角色或者审批人
  8722. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8723. //
  8724. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8725. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8726. 'date' => date ( 'Y-m-d' ),
  8727. 'opinion' => $opinion,
  8728. 'status' => $status,
  8729. 'nextStaff' => $VS ['nextStaff'],
  8730. 'ROLE' => 1
  8731. );
  8732. // print_r($verifyStaff);
  8733. // die;
  8734. }
  8735. if ($status == 3) {
  8736. $verifyStaff ['final'] = $status;
  8737. $verifyStaff [$this->staff [0] ['sid']] = array (
  8738. 'date' => date ( 'Y-m-d' ),
  8739. 'opinion' => $opinion,
  8740. 'status' => $status
  8741. );
  8742. }
  8743. $vStaffString = json_encode ( $verifyStaff );
  8744. $receipt->verifyStaff = $vStaffString;
  8745. $receipt->nowStaff = $nowStaff;
  8746. // die;
  8747. // }
  8748. // print_r($verifyStaff);
  8749. // die;
  8750. }
  8751. // print_r($verifyStaff);die;
  8752. }
  8753. // print_r($verifyDetail);
  8754. $roleKey = 0;
  8755. $roleId = 0;
  8756. $verifyDetailCopy = array ();
  8757. foreach ( $verifyDetail as $k => $v ) {
  8758. if ($v [1] == 'ROLE') {
  8759. $roleId = $v [0];
  8760. $roleVerify = json_decode ( $v [3], true );
  8761. $roleKey = $k;
  8762. $roleArray = array ();
  8763. foreach ( $roleVerify as $o => $p ) {
  8764. $staffID = explode ( '_', $p );
  8765. $exp = array (
  8766. 0 => $staffID [0],
  8767. 1 => $staffID [1]
  8768. );
  8769. array_push ( $roleArray, $exp );
  8770. }
  8771. $verifyDetailCopy [$v [0]] = $roleArray;
  8772. }
  8773. }
  8774. // print_r($verifyDetail);
  8775. foreach ( $verifyDetailCopy as $k => $v ) {
  8776. foreach ( $verifyDetail as $m => $n ) {
  8777. if ($n [0] == $k) {
  8778. array_splice ( $verifyDetail, $m, 1, $v );
  8779. }
  8780. }
  8781. }
  8782. // die;
  8783. // if (!empty($roleArray))
  8784. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8785. // echo $roleId;
  8786. // print_r($verifyStaff);
  8787. // print_r($verifyDetail);
  8788. // die;
  8789. Doo::loadModel ( "receiptLog" );
  8790. $receiptLog = new receiptLog ();
  8791. // 审批日志
  8792. if (! isset ( $verifyStaff ['final'] )) {
  8793. if (! empty ( $roleId )) {
  8794. Doo::loadModel ( "role" );
  8795. $role = new role ();
  8796. $roleInfo = $role->getOne ( array (
  8797. 'where' => 'rid=' . $roleId,
  8798. 'asArray' => true
  8799. ) );
  8800. $receiptLog->rolename = $roleInfo ['name'];
  8801. }
  8802. $receiptLog->username = $this->staff [0] ['username'];
  8803. $receiptLog->uid = $this->staff [0] ['sid'];
  8804. $receiptLog->date = date ( "Y-m-d" );
  8805. $receiptLog->opinion = $opinion;
  8806. $receiptLog->img = $this->staff [0] ['avatar'];
  8807. $receiptLog->status = 1;
  8808. $receiptLog->rid = $rid;
  8809. $receiptLog->insert ();
  8810. }
  8811. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8812. $receipt->verifyBreakup = $verifyString;
  8813. $receipt->status = 3;
  8814. $receiptDetailObj->status = 3;
  8815. $receiptDetailObj->update ( array (
  8816. 'where' => 'rid=' . $rid
  8817. ) );
  8818. if (! empty ( $roleId )) {
  8819. Doo::loadModel ( "role" );
  8820. $role = new role ();
  8821. $roleInfo = $role->getOne ( array (
  8822. 'where' => 'rid=' . $roleId,
  8823. 'asArray' => true
  8824. ) );
  8825. $receiptLog->rolename = $roleInfo ['name'];
  8826. }
  8827. $receiptLog->username = $this->staff [0] ['username'];
  8828. $receiptLog->uid = $this->staff [0] ['sid'];
  8829. $receiptLog->date = date ( "Y-m-d" );
  8830. $receiptLog->opinion = $opinion;
  8831. $receiptLog->img = $this->staff [0] ['avatar'];
  8832. $receiptLog->status = 3;
  8833. $receiptLog->rid = $rid;
  8834. $receiptLog->insert ();
  8835. // 微信企业号通知
  8836. $this->setWXMsg ( $rid, 3 );
  8837. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8838. $receipt->status = 1;
  8839. $reviseSum = 0;
  8840. $receipt->verifyBreakup = $verifyString;
  8841. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8842. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8843. foreach ( $reviseDetail as $key => $value ) {
  8844. $receiptDetailObj = new receiptDetail ();
  8845. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8846. $receiptDetailObj->item = $value ['description'];
  8847. $receiptDetailObj->itemCategory = "报销金额调整";
  8848. $receiptDetailObj->price = $value ['price'];
  8849. $receiptDetailObj->date = $receiptDetail ['date'];
  8850. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8851. $receiptDetailObj->rid = $rid;
  8852. $receiptDetailObj->status = 1;
  8853. $receiptDetailObj->insert ();
  8854. $reviseSum += $value ['price'];
  8855. }
  8856. $itemStatistics = new itemStatistics ();
  8857. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8858. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8859. $itemStatistics->price = $reviseSum;
  8860. $itemStatistics->itemCategory = "报销金额调整";
  8861. $itemStatistics->date = $receiptDetail ['date'];
  8862. $itemStatistics->insert ();
  8863. }
  8864. $receiptDetailObj = new receiptDetail ();
  8865. $receiptDetailObj->status = 1;
  8866. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8867. $receiptDetailObj->update ( array (
  8868. 'where' => 'rid=' . $rid
  8869. ) );
  8870. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8871. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8872. $stat = $statistics->getOne ( array (
  8873. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8874. 'asArray' => true
  8875. ) );
  8876. if (empty ( $stat )) {
  8877. $statistics->date = $receiptDetail ['date'];
  8878. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8879. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8880. $statistics->agPrice = $receiptDetail ['sum'];
  8881. $statistics->rePrice = $reviseSum;
  8882. $statistics->insert ();
  8883. } else {
  8884. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8885. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8886. $statistics->update ( array (
  8887. 'where' => 'sid=' . $stat ['sid']
  8888. ) );
  8889. }
  8890. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8891. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8892. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8893. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8894. if ($key == "agencySum") {
  8895. $iStatistics = $itemStatistics->getOne ( array (
  8896. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8897. 'asArray' => true
  8898. ) );
  8899. if (empty ( $iStatistics )) {
  8900. $itemStatistics->cid = $receiptDetail ['cid'];
  8901. ;
  8902. $itemStatistics->staff = $receiptDetail ['staff'];
  8903. $itemStatistics->price = $value;
  8904. $itemStatistics->itemCategory = $this->AGENCY;
  8905. $itemStatistics->date = $receiptDetail ['date'];
  8906. $itemStatistics->insert ();
  8907. } else {
  8908. if (! empty ( $value )) {
  8909. $itemStatistics->price = $value + $iStatistics ['price'];
  8910. $itemStatistics->update ( array (
  8911. 'where' => 'sid=' . $iStatistics ['sid']
  8912. ) );
  8913. }
  8914. }
  8915. } elseif ($key == "travelSum") {
  8916. $iStatistics = $itemStatistics->getOne ( array (
  8917. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8918. 'asArray' => true
  8919. ) );
  8920. if (empty ( $iStatistics )) {
  8921. $itemStatistics->cid = $receiptDetail ['cid'];
  8922. $itemStatistics->staff = $receiptDetail ['staff'];
  8923. $itemStatistics->price = $value;
  8924. $itemStatistics->itemCategory = $this->TRAVEL;
  8925. $itemStatistics->date = $receiptDetail ['date'];
  8926. $itemStatistics->insert ();
  8927. } else {
  8928. if (! empty ( $value )) {
  8929. $itemStatistics->price = $value + $iStatistics ['price'];
  8930. $itemStatistics->update ( array (
  8931. 'where' => 'sid=' . $iStatistics ['sid']
  8932. ) );
  8933. }
  8934. }
  8935. } elseif ($key == "trainSum") {
  8936. $iStatistics = $itemStatistics->getOne ( array (
  8937. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8938. 'asArray' => true
  8939. ) );
  8940. if (empty ( $iStatistics )) {
  8941. $itemStatistics->cid = $receiptDetail ['cid'];
  8942. $itemStatistics->staff = $receiptDetail ['staff'];
  8943. $itemStatistics->price = $value;
  8944. $itemStatistics->itemCategory = $this->TRAIN;
  8945. $itemStatistics->date = $receiptDetail ['date'];
  8946. $itemStatistics->insert ();
  8947. } else {
  8948. if (! empty ( $value )) {
  8949. $itemStatistics->price = $value + $iStatistics ['price'];
  8950. $itemStatistics->update ( array (
  8951. 'where' => 'sid=' . $iStatistics ['sid']
  8952. ) );
  8953. }
  8954. }
  8955. } elseif ($key == "otherSum") {
  8956. $iStatistics = $itemStatistics->getOne ( array (
  8957. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8958. 'asArray' => true
  8959. ) );
  8960. if (empty ( $iStatistics )) {
  8961. $itemStatistics->cid = $receiptDetail ['cid'];
  8962. $itemStatistics->staff = $receiptDetail ['staff'];
  8963. $itemStatistics->price = $value;
  8964. $itemStatistics->itemCategory = $this->OTHER;
  8965. $itemStatistics->date = $receiptDetail ['date'];
  8966. $itemStatistics->insert ();
  8967. } else {
  8968. if (! empty ( $value )) {
  8969. $itemStatistics->price = $value + $iStatistics ['price'];
  8970. $itemStatistics->update ( array (
  8971. 'where' => 'sid=' . $iStatistics ['sid']
  8972. ) );
  8973. }
  8974. }
  8975. }
  8976. }
  8977. $receipt->pastDate = date ( "Y-m-d" );
  8978. // 微信企业号通知
  8979. $this->setWXMsg ( $rid, 1 );
  8980. }
  8981. //是否有流水
  8982. Doo::loadModel ( 'wasteBook' );
  8983. $wasteBook = new wasteBook ();
  8984. $accountType=3;
  8985. if ($receiptDetail['Rtype']==1){
  8986. $accountType=2;
  8987. }elseif($receiptDetail['Rtype']==2){
  8988. $accountType=4;
  8989. }
  8990. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8991. if (empty($wbDetail)){
  8992. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  8993. $receipt->amount = $rsum;//$amount;
  8994. }
  8995. $receipt->update ( array (
  8996. 'where' => ' rid = ' . $rid
  8997. ) );
  8998. // 进入下一条审批费用新加需求
  8999. $vidList = array ();
  9000. $verifyDetail = $verify->find ( array (
  9001. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  9002. 'asArray' => true
  9003. ) );
  9004. foreach ( $verifyDetail as $key => $value ) {
  9005. array_push ( $vidList, $value ['vid'] );
  9006. }
  9007. $vid = implode ( ",", $vidList );
  9008. if (empty ( $verifyDetail ))
  9009. $vid = 0;
  9010. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9011. $receipt = new receipt ();
  9012. $rd = $receipt->getOne ( array (
  9013. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  9014. 'asc' => 'rid',
  9015. 'asArray' => true
  9016. ) );
  9017. if (empty ( $rd )) {
  9018. return '/approvalExpenses/pendApproval';
  9019. }
  9020. if ($rd ['Rtype'] == 1) {
  9021. if ($rd ['isBK'] == 1) {
  9022. return '/receiptburEdi/' . $rd ['rid'];
  9023. } else {
  9024. return '/expensesEdi/' . $rd ['rid'];
  9025. }
  9026. } elseif ($rd ['Rtype'] == 2) {
  9027. return '/remitApproval/' . $rd ['rid'];
  9028. } else {
  9029. return '/receiptburEdi/' . $rd ['rid'];
  9030. }
  9031. // return "/approvalExpenses/pendApproval";
  9032. }
  9033. }
  9034. function expensesRetreats() {
  9035. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  9036. if (! empty ( $rid )) {
  9037. // 操作记录
  9038. Doo::loadModel ( "receipt" );
  9039. $receipt = new receipt ();
  9040. Doo::loadModel ( "receiptLog" );
  9041. $receiptLog = new receiptLog ();
  9042. Doo::loadModel ( "verify" );
  9043. $verify = new verify ();
  9044. $receiptInfo = $receipt->getOne ( array (
  9045. 'where' => 'rid=' . $rid,
  9046. 'asArray' => true
  9047. ) );
  9048. $vr = $verify->getOne ( array (
  9049. 'where' => 'vid=' . $receiptInfo ['verify'],
  9050. 'asArray' => true
  9051. ) );
  9052. $jd = json_decode ( $vr ['staff'] );
  9053. $roleId = 0;
  9054. foreach ( $jd as $key => $value ) {
  9055. if ($value [1] == 'ROLE') {
  9056. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9057. if ($pos !== false) {
  9058. $roleId = $value [0];
  9059. }
  9060. }
  9061. }
  9062. // 审批日志
  9063. // echo $roleId;die;
  9064. if (! empty ( $roleId )) {
  9065. Doo::loadModel ( "role" );
  9066. $role = new role ();
  9067. $roleInfo = $role->getOne ( array (
  9068. 'where' => 'rid=' . $roleId,
  9069. 'asArray' => true
  9070. ) );
  9071. $receiptLog->rolename = $roleInfo ['name'];
  9072. }
  9073. $receiptLog->username = $this->staff [0] ['username'];
  9074. $receiptLog->uid = $this->staff [0] ['sid'];
  9075. $receiptLog->date = date ( "Y-m-d" );
  9076. $receiptLog->opinion = '撤回';
  9077. $receiptLog->img = $this->staff [0] ['avatar'];
  9078. $receiptLog->status = 4;
  9079. $receiptLog->rid = $rid;
  9080. $receiptLog->insert ();
  9081. $receipt->status = 4;
  9082. $receipt->update ( array (
  9083. 'where' => 'rid=' . $rid
  9084. ) );
  9085. // 微信企业号通知
  9086. $this->setWXMsg ( $rid, 2 );
  9087. }
  9088. // echo "ddd";
  9089. return '/approvalExpenses/pendApproval';
  9090. }
  9091. function updateCheReceipt() {
  9092. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9093. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9094. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9095. if (! empty ( $rid )) {
  9096. // 操作记录
  9097. Doo::loadModel ( "receipt" );
  9098. $receipt = new receipt ();
  9099. Doo::loadModel ( "receiptLog" );
  9100. $receiptLog = new receiptLog ();
  9101. Doo::loadModel ( "verify" );
  9102. $verify = new verify ();
  9103. $receiptInfo = $receipt->getOne ( array (
  9104. 'where' => 'rid=' . $rid . ' and status=2',
  9105. 'asArray' => true
  9106. ) );
  9107. if (empty ( $receiptInfo )) {
  9108. echo json_encode ( array (
  9109. 'status' => 2
  9110. ) );
  9111. die ();
  9112. }
  9113. $vr = $verify->getOne ( array (
  9114. 'where' => 'vid=' . $receiptInfo ['verify'],
  9115. 'asArray' => true
  9116. ) );
  9117. $jd = json_decode ( $vr ['staff'] );
  9118. $roleId = 0;
  9119. foreach ( $jd as $key => $value ) {
  9120. if ($value [1] == 'ROLE') {
  9121. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9122. if ($pos !== false) {
  9123. $roleId = $value [0];
  9124. }
  9125. }
  9126. }
  9127. // 审批日志
  9128. // echo $roleId;die;
  9129. if (! empty ( $roleId )) {
  9130. Doo::loadModel ( "role" );
  9131. $role = new role ();
  9132. $roleInfo = $role->getOne ( array (
  9133. 'where' => 'rid=' . $roleId,
  9134. 'asArray' => true
  9135. ) );
  9136. $receiptLog->rolename = $roleInfo ['name'];
  9137. }
  9138. $receiptLog->username = $this->staff [0] ['username'];
  9139. $receiptLog->uid = $this->staff [0] ['sid'];
  9140. $receiptLog->date = date ( "Y-m-d" );
  9141. $receiptLog->opinion = $opinion;
  9142. $receiptLog->img = $this->staff [0] ['avatar'];
  9143. $receiptLog->status = 4;
  9144. $receiptLog->rid = $rid;
  9145. $receiptLog->insert ();
  9146. $receipt->status = 4;
  9147. $receipt->update ( array (
  9148. 'where' => 'rid=' . $rid
  9149. ) );
  9150. // 微信企业号通知
  9151. $this->setWXMsg ( $rid, 2 );
  9152. echo json_encode ( array (
  9153. 'status' => 1
  9154. ) );
  9155. // Header("HTTP/1.1 303 See Other");
  9156. // Header("Location: /approvalExpenses/pendApproval");
  9157. die ();
  9158. }
  9159. echo json_encode ( array (
  9160. 'status' => 2
  9161. ) );
  9162. die ();
  9163. // echo "ddd";
  9164. // return '/saeaBorad';
  9165. }
  9166. function revisePrice() {
  9167. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9168. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9169. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9170. // echo $price;die;
  9171. if (! empty ( $rid )) {
  9172. Doo::loadModel ( "receipt" );
  9173. $receipt = new receipt ();
  9174. $receiptDetail = $receipt->getOne ( array (
  9175. 'where' => 'rid=' . $rid . ' and status=2 ',
  9176. 'asArray' => true
  9177. ) );
  9178. if (empty ( $receiptDetail ))
  9179. die ( 'illegal request' );
  9180. $reviseDetail = array ();
  9181. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9182. array_push ( $reviseDetail, array (
  9183. 'sid' => $this->staff [0] ['sid'],
  9184. 'name' => $this->staff [0] ['username'],
  9185. 'description' => $description,
  9186. 'price' => $price
  9187. ) );
  9188. $reviseDetailString = json_encode ( $reviseDetail );
  9189. $receipt->reviseDetail = $reviseDetailString;
  9190. $receipt->revisePrice = $price;
  9191. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9192. } else {
  9193. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9194. array_push ( $reviseDetail, array (
  9195. 'sid' => $this->staff [0] ['sid'],
  9196. 'name' => $this->staff [0] ['username'],
  9197. 'description' => $description,
  9198. 'price' => $price
  9199. ) );
  9200. $reviseDetailString = json_encode ( $reviseDetail );
  9201. $receipt->reviseDetail = $reviseDetailString;
  9202. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9203. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9204. }
  9205. $receipt->update ( array (
  9206. 'where' => 'rid=' . $rid
  9207. ) );
  9208. if ($receiptDetail ['Rtype'] == 1) {
  9209. if ($receiptDetail ['isBK'] == 1) {
  9210. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9211. }
  9212. } elseif ($receiptDetail ['Rtype'] == 2) {
  9213. } else {
  9214. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9215. }
  9216. }
  9217. die ( 'illegal request' );
  9218. }
  9219. function personalCollect() {
  9220. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9221. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9222. $this->showCache ( $path );
  9223. Doo::loadModel ( "receiptDetail" );
  9224. Doo::loadModel ( "itemStatistics" );
  9225. Doo::loadModel ( 'statistics' );
  9226. $statistics = new statistics ();
  9227. $itemStatistics = new itemStatistics ();
  9228. $receiptDetail = new receiptDetail ();
  9229. $receiptCollectList = $receiptDetail->find ( array (
  9230. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9231. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9232. 'groupby' => 'itemCategory,Month(date)',
  9233. 'asArray' => true
  9234. ) );
  9235. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9236. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9237. 'asArray' => true
  9238. ) );
  9239. // create collect html
  9240. $collectArray = array (
  9241. '日常相关费用' => array (),
  9242. '差旅相关费用' => array (),
  9243. '培训班费用' => array (),
  9244. '其他' => array ()
  9245. );
  9246. $adjustment = array ();
  9247. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9248. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9249. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9250. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9251. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9252. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9253. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9254. array_push ( $collectArray ['其他'], $collectHtml );
  9255. $data ['collectArray'] = $collectArray;
  9256. // statistics html
  9257. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9258. if (empty ( $stList ))
  9259. $stList = array (
  9260. 'rePrice' => 0,
  9261. 'agPrice' => 0
  9262. );
  9263. $data ['stList'] = array (
  9264. 'rePrice' => $stList ['rePrice'],
  9265. 'agPrice' => $stList ['agPrice'],
  9266. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9267. );
  9268. // Adjustment price html
  9269. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9270. array_push ( $adjustment, $collectHtml );
  9271. $data ['adjustment'] = $adjustment;
  9272. // total price html
  9273. $collectHtml = "";
  9274. $total = 0;
  9275. for($i = 1; $i <= 12; $i ++) {
  9276. $sumPrice = 0;
  9277. foreach ( $receiptCollectList as $key => $value ) {
  9278. if ($value ['month'] == $i) {
  9279. $sumPrice += $value ['price'];
  9280. }
  9281. }
  9282. if ($sumPrice == 0)
  9283. $collectHtml .= '<td class="taR">-</td>';
  9284. else
  9285. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9286. $total += $sumPrice;
  9287. }
  9288. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9289. $data ['totalPrice'] = $collectHtml;
  9290. $dateHtml = "";
  9291. $now = date ( "Y" );
  9292. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9293. if ($YEARD <= $now) {
  9294. $dateHtml .= '<option ';
  9295. if ($year == $YEARD) {
  9296. $dateHtml .= 'selected ';
  9297. }
  9298. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9299. }
  9300. }
  9301. $data ['dateHtml'] = $dateHtml;
  9302. $data ['year'] = $year;
  9303. $data ['totalYear'] = $total;
  9304. $data ['memu'] = "receipt";
  9305. $data ['staff'] = $this->staff;
  9306. $data ['receiptMemu'] = 'personalCollect';
  9307. $data ['verifyId'] = $this->verifyId;
  9308. $data ['executeId'] = $this->executeId;
  9309. // year staff status 2,4
  9310. if ($year < date ( "Y" )) {
  9311. Doo::loadModel ( 'receipt' );
  9312. $receipt = new receipt ();
  9313. $receiptList = $receipt->find ( array (
  9314. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9315. 'asArray' => true
  9316. ) );
  9317. if (empty ( $receiptList )) {
  9318. ob_start ();
  9319. $this->render ( "/admin/saea_slist_collect", $data );
  9320. $this->cacheFile ( $path );
  9321. die ();
  9322. }
  9323. }
  9324. $this->render ( "/admin/saea_slist_collect", $data );
  9325. }
  9326. function personalCollectDetail() {
  9327. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9328. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9329. $this->showCache ( $path );
  9330. Doo::loadModel ( "receiptDetail" );
  9331. Doo::loadModel ( "itemStatistics" );
  9332. Doo::loadModel ( 'statistics' );
  9333. Doo::loadModel ( 'accountItem' );
  9334. $accountItem = new accountItem ();
  9335. $statistics = new statistics ();
  9336. $itemStatistics = new itemStatistics ();
  9337. $receiptDetail = new receiptDetail ();
  9338. $receiptCollectList = $receiptDetail->find ( array (
  9339. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9340. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9341. 'groupby' => 'item,Month(date)',
  9342. 'asArray' => true
  9343. ) );
  9344. $accountList = $accountItem->find ( array (
  9345. 'asArray' => true
  9346. ) );
  9347. // create CollectDetail HTML
  9348. $collectHtml = array ();
  9349. foreach ( $accountList as $key => $value ) {
  9350. $html = "";
  9351. $asum = 0;
  9352. for($i = 1; $i <= 12; $i ++) {
  9353. $falg = true;
  9354. foreach ( $receiptCollectList as $v ) {
  9355. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9356. $asum += $v ['price'];
  9357. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9358. $falg = false;
  9359. break;
  9360. }
  9361. }
  9362. if ($falg)
  9363. $html .= '<td class="taR">-</td>';
  9364. }
  9365. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9366. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9367. }
  9368. $data ['collectHtml'] = $collectHtml;
  9369. // create Adjustment price html
  9370. $receiptCollectList = $receiptDetail->find ( array (
  9371. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9372. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9373. 'groupby' => 'itemCategory,Month(date)',
  9374. 'asArray' => true
  9375. ) );
  9376. $adjustment = array ();
  9377. $collectArray = array (
  9378. '日常相关费用' => array (),
  9379. '差旅相关费用' => array (),
  9380. '培训班费用' => array (),
  9381. '其他' => array ()
  9382. );
  9383. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9384. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9385. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9386. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9387. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9388. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9389. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9390. array_push ( $collectArray ['其他'], $collectHtml );
  9391. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9392. array_push ( $adjustment, $collectHtml );
  9393. // total price html
  9394. $collectHtml = "";
  9395. $total = 0;
  9396. for($i = 1; $i <= 12; $i ++) {
  9397. $sumPrice = 0;
  9398. foreach ( $receiptCollectList as $key => $value ) {
  9399. if ($value ['month'] == $i) {
  9400. $sumPrice += $value ['price'];
  9401. }
  9402. }
  9403. if ($sumPrice == 0)
  9404. $collectHtml .= '<td class="taR">-</td>';
  9405. else
  9406. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9407. $total += $sumPrice;
  9408. }
  9409. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9410. // statistics html
  9411. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9412. if (empty ( $stList ))
  9413. $stList = array (
  9414. 'rePrice' => 0,
  9415. 'agPrice' => 0
  9416. );
  9417. $data ['stList'] = array (
  9418. 'rePrice' => $stList ['rePrice'],
  9419. 'agPrice' => $stList ['agPrice'],
  9420. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9421. );
  9422. $data ['collectArray'] = $collectArray;
  9423. $data ['adjustment'] = $adjustment;
  9424. $data ['totalPrice'] = $collectHtml;
  9425. $data ['totalYear'] = $total;
  9426. $data ['year'] = $year;
  9427. $dateHtml = "";
  9428. $now = date ( "Y" );
  9429. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9430. if ($YEARD <= $now) {
  9431. $dateHtml .= '<option ';
  9432. if ($year == $YEARD) {
  9433. $dateHtml .= 'selected ';
  9434. }
  9435. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9436. }
  9437. }
  9438. $data ['dateHtml'] = $dateHtml;
  9439. $data ['memu'] = "receipt";
  9440. $data ['staff'] = $this->staff;
  9441. $data ['receiptMemu'] = 'personalCollect';
  9442. $data ['verifyId'] = $this->verifyId;
  9443. $data ['executeId'] = $this->executeId;
  9444. // year staff status 2,4
  9445. if ($year < date ( "Y" )) {
  9446. Doo::loadModel ( 'receipt' );
  9447. $receipt = new receipt ();
  9448. $receiptList = $receipt->find ( array (
  9449. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9450. 'asArray' => true
  9451. ) );
  9452. if (empty ( $receiptList )) {
  9453. ob_start ();
  9454. $this->render ( "/admin/saeaCollectArticles", $data );
  9455. $this->cacheFile ( $path );
  9456. die ();
  9457. }
  9458. }
  9459. $this->render ( "/admin/saeaCollectArticles", $data );
  9460. }
  9461. function companyCategoryCollect() {
  9462. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9463. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9464. $this->showCache ( $path );
  9465. Doo::loadModel ( 'L_category' );
  9466. Doo::loadModel ( 'itemStatistics' );
  9467. Doo::loadModel ( 'statistics' );
  9468. $statistics = new statistics ();
  9469. $Lcategory = new L_category ();
  9470. $itemStatistics = new itemStatistics ();
  9471. Doo::loadModel ( "receiptAuthorityManage" );
  9472. $receiptAuthorityManage = new receiptAuthorityManage ();
  9473. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9474. $cidList = array ();
  9475. foreach ( $imcStaff as $key => $value ) {
  9476. array_push ( $cidList, $value ['cid'] );
  9477. }
  9478. $cidString = implode ( ',', $cidList );
  9479. $LcategoryList = $Lcategory->find ( array (
  9480. 'where' => ' cid in (' . $cidString . ')',
  9481. 'asArray' => true
  9482. ) ); // 'staff='.$this->staff[0]['sid']." and
  9483. $itemStatisticsList = $itemStatistics->find ( array (
  9484. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9485. 'where' => " Year(date)=" . $year,
  9486. 'groupby' => 'cid,Month(date)',
  9487. 'asArray' => true
  9488. ) );
  9489. // ceatre companyCollectHtml
  9490. foreach ( $LcategoryList as $value ) {
  9491. $html = "";
  9492. $asum = 0;
  9493. for($i = 1; $i <= 12; $i ++) {
  9494. $falg = true;
  9495. foreach ( $itemStatisticsList as $v ) {
  9496. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9497. $asum += $v ['price'];
  9498. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9499. $falg = false;
  9500. break;
  9501. }
  9502. }
  9503. if ($falg)
  9504. $html .= '<td class="taR">-</td>';
  9505. }
  9506. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9507. $collectHtml [$value ['title']] = array (
  9508. 'html' => $html,
  9509. 'cid' => $value ['cid']
  9510. );
  9511. }
  9512. $data ['companyHtml'] = $collectHtml;
  9513. // total price html
  9514. $collectHtml = "";
  9515. $total = 0;
  9516. for($i = 1; $i <= 12; $i ++) {
  9517. $sumPrice = 0;
  9518. foreach ( $itemStatisticsList as $key => $value ) {
  9519. if ($value ['month'] == $i) {
  9520. $sumPrice += $value ['price'];
  9521. }
  9522. }
  9523. if ($sumPrice == 0)
  9524. $collectHtml .= '<td class="taR">-</td>';
  9525. else
  9526. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9527. $total += $sumPrice;
  9528. }
  9529. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9530. $data ['companyTotalHtml'] = $collectHtml;
  9531. $data ['total'] = $total;
  9532. // statistics html
  9533. // echo $cidString;
  9534. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9535. if (empty ( $stList ))
  9536. $stList = array (
  9537. 'rePrice' => 0,
  9538. 'agPrice' => 0
  9539. );
  9540. $data ['stList'] = array (
  9541. 'rePrice' => $stList ['rePrice'],
  9542. 'agPrice' => $stList ['agPrice'],
  9543. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9544. );
  9545. $data ['year'] = $year;
  9546. $data ['memu'] = "receipt";
  9547. $data ['staff'] = $this->staff;
  9548. $data ['receiptMemu'] = 'companyCategoryCollect';
  9549. $data ['verifyId'] = $this->verifyId;
  9550. $data ['executeId'] = $this->executeId;
  9551. $dateHtml = "";
  9552. $now = date ( "Y" );
  9553. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9554. if ($YEARD <= $now) {
  9555. $dateHtml .= '<option ';
  9556. if ($year == $YEARD) {
  9557. $dateHtml .= 'selected ';
  9558. }
  9559. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9560. }
  9561. }
  9562. $data ['dateHtml'] = $dateHtml;
  9563. // year staff status 2,4
  9564. if ($year < date ( "Y" )) {
  9565. Doo::loadModel ( 'receipt' );
  9566. $receipt = new receipt ();
  9567. $receiptList = $receipt->find ( array (
  9568. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9569. 'asArray' => true
  9570. ) );
  9571. if (empty ( $receiptList )) {
  9572. ob_start ();
  9573. $this->render ( "/admin/saeaCompanyCollect", $data );
  9574. $this->cacheFile ( $path );
  9575. die ();
  9576. }
  9577. }
  9578. $this->render ( "/admin/saeaCompanyCollect", $data );
  9579. }
  9580. function categoryCollectDetail() {
  9581. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9582. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9583. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9584. $this->showCache ( $path ); */
  9585. Doo::loadModel ( 'statistics' );
  9586. $statistics = new statistics ();
  9587. Doo::loadModel ( "receiptDetail" );
  9588. $receiptDetail = new receiptDetail ();
  9589. Doo::loadModel ( 'L_category' );
  9590. $Lcategory = new L_category ();
  9591. Doo::loadModel ( 'accountItem' );
  9592. $accountItem = new accountItem ();
  9593. Doo::loadModel ( "receiptAuthorityManage" );
  9594. $receiptAuthorityManage = new receiptAuthorityManage ();
  9595. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9596. $cidList = array ();
  9597. foreach ( $imcStaff as $key => $value ) {
  9598. array_push ( $cidList, $value ['cid'] );
  9599. }
  9600. $cidString = implode ( ',', $cidList );
  9601. $LcategoryList = $Lcategory->find ( array (
  9602. 'where' => 'cid in (' . $cidString . ')',
  9603. 'asArray' => true
  9604. ) );
  9605. if ($cid == 0) {
  9606. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9607. if ($cid == 0)
  9608. $cid = $LcategoryList [0] ['cid'];
  9609. }
  9610. $data ['LcategoryList'] = $LcategoryList;
  9611. $receiptCollectList = $receiptDetail->find ( array (
  9612. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9613. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9614. 'groupby' => 'item,Month(pastDate)',
  9615. 'asArray' => true
  9616. ) );
  9617. $accountList = $accountItem->find ( array (
  9618. 'asArray' => true
  9619. ) );
  9620. // create CollectDetail HTML
  9621. $collectHtml = array ();
  9622. foreach ( $accountList as $key => $value ) {
  9623. $html = "";
  9624. $asum = 0;
  9625. for($i = 1; $i <= 12; $i ++) {
  9626. $falg = true;
  9627. foreach ( $receiptCollectList as $v ) {
  9628. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9629. $asum += $v ['price'];
  9630. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9631. $falg = false;
  9632. break;
  9633. }
  9634. }
  9635. if ($falg)
  9636. $html .= '<td class="taR">-</td>';
  9637. }
  9638. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9639. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9640. }
  9641. $data ['collectHtml'] = $collectHtml;
  9642. // create Adjustment price html
  9643. $receiptCollectList = $receiptDetail->find ( array (
  9644. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9645. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9646. 'groupby' => 'itemCategory,Month(pastDate)',
  9647. 'asArray' => true
  9648. ) );
  9649. $adjustment = array ();
  9650. $collectArray = array (
  9651. '日常相关费用' => array (),
  9652. '差旅相关费用' => array (),
  9653. '培训班费用' => array (),
  9654. '内部培训费用'=>array(),
  9655. '其他' => array ()
  9656. );
  9657. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9658. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9659. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9660. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9661. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9662. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9663. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9664. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9665. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9666. array_push ( $collectArray ['其他'], $collectHtml );
  9667. $data ['collectArray'] = $collectArray;
  9668. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9669. array_push ( $adjustment, $collectHtml );
  9670. $data ['adjustment'] = $adjustment;
  9671. // total price html
  9672. $collectHtml = "";
  9673. $total = 0;
  9674. for($i = 1; $i <= 12; $i ++) {
  9675. $sumPrice = 0;
  9676. foreach ( $receiptCollectList as $key => $value ) {
  9677. if ($value ['month'] == $i) {
  9678. $sumPrice += $value ['price'];
  9679. }
  9680. }
  9681. if ($sumPrice == 0)
  9682. $collectHtml .= '<td class="taR">-</td>';
  9683. else
  9684. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9685. $total += $sumPrice;
  9686. }
  9687. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9688. // statistics html
  9689. $stList = $statistics->statisticsByCid ( $year, $cid );
  9690. if (empty ( $stList ))
  9691. $stList = array (
  9692. 'rePrice' => 0,
  9693. 'agPrice' => 0
  9694. );
  9695. $data ['stList'] = array (
  9696. 'rePrice' => $stList ['rePrice'],
  9697. 'agPrice' => $stList ['agPrice'],
  9698. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9699. );
  9700. $data ['totalYear'] = $total;
  9701. $data ['year'] = $year;
  9702. $data ['cid'] = $cid;
  9703. $data ['memu'] = "receipt";
  9704. $data ['staff'] = $this->staff;
  9705. $data ['receiptMemu'] = 'companyCategoryCollect';
  9706. $data ['verifyId'] = $this->verifyId;
  9707. $data ['executeId'] = $this->executeId;
  9708. // year staff status 2,4
  9709. /* if ($year < date ( "Y" )) {
  9710. Doo::loadModel ( 'receipt' );
  9711. $receipt = new receipt ();
  9712. $receiptList = $receipt->find ( array (
  9713. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9714. 'asArray' => true
  9715. ) );
  9716. if (empty ( $receiptList )) {
  9717. ob_start ();
  9718. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9719. $this->cacheFile ( $path );
  9720. die ();
  9721. }
  9722. } */
  9723. $dateHtml = "";
  9724. $now = date ( "Y" );
  9725. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9726. if ($YEARD <= $now) {
  9727. $dateHtml .= '<option ';
  9728. if ($year == $YEARD) {
  9729. $dateHtml .= 'selected ';
  9730. }
  9731. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9732. }
  9733. }
  9734. $data ['dateHtml'] = $dateHtml;
  9735. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9736. }
  9737. function staffCollect() {
  9738. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9739. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9740. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9741. // $this->showCache($path);
  9742. Doo::loadModel ( 'statistics' );
  9743. $statistics = new statistics ();
  9744. Doo::loadModel ( "receiptDetail" );
  9745. $receiptDetail = new receiptDetail ();
  9746. Doo::loadModel ( 'L_category' );
  9747. $Lcategory = new L_category ();
  9748. Doo::loadModel ( 'accountItem' );
  9749. $accountItem = new accountItem ();
  9750. Doo::loadModel ( 'staff' );
  9751. $staff = new staff ();
  9752. Doo::loadModel ( 'itemStatistics' );
  9753. $itemStatistics = new itemStatistics ();
  9754. Doo::loadModel ( "receiptAuthorityManage" );
  9755. $receiptAuthorityManage = new receiptAuthorityManage ();
  9756. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9757. $cidList = array ();
  9758. foreach ( $imcStaff as $key => $value ) {
  9759. array_push ( $cidList, $value ['cid'] );
  9760. }
  9761. $cidString = implode ( ',', $cidList );
  9762. $naturecon='';
  9763. if ($nature=='ONJOB'){
  9764. $naturecon=' and (nature!=4 )';
  9765. }elseif($nature=='LEAVEJOB'){
  9766. $naturecon=' and (nature=4 )';
  9767. }else{
  9768. die ( 'illegal request--nature' );
  9769. }
  9770. // statistics html
  9771. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9772. if (empty ( $stList ))
  9773. $stList = array (
  9774. 'rePrice' => 0,
  9775. 'agPrice' => 0
  9776. );
  9777. $data ['stList'] = array (
  9778. 'rePrice' => $stList ['rePrice'],
  9779. 'agPrice' => $stList ['agPrice'],
  9780. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9781. );
  9782. // ---
  9783. $staffList = $staff->find ( array (
  9784. 'where' => 'username !="admin" '.$naturecon,
  9785. 'asArray' => true
  9786. ) );
  9787. $LcategoryList = $Lcategory->find ( array (
  9788. 'asArray' => true
  9789. ) ); // 'staff='.$this->staff[0]['sid']." and
  9790. $itemStatisticsList = $itemStatistics->find ( array (
  9791. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9792. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9793. 'groupby' => 'staff,Month(date)',
  9794. 'asArray' => true
  9795. ) );
  9796. $categoryList = $staff->find ( array (
  9797. 'select' => 'COUNT(*) as count,cid,category',
  9798. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9799. 'groupby' => 'cid',
  9800. 'asArray' => true
  9801. ) );
  9802. // print_r($itemStatisticsList);die;
  9803. // ceatre companyCollectHtml
  9804. foreach ( $categoryList as $vlu ) {
  9805. $count = $vlu ['count'] + 1;
  9806. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9807. $m1 = 0;
  9808. $m2 = 0;
  9809. $m3 = 0;
  9810. $m4 = 0;
  9811. $m5 = 0;
  9812. $m6 = 0;
  9813. $m7 = 0;
  9814. $m8 = 0;
  9815. $m9 = 0;
  9816. $m10 = 0;
  9817. $m11 = 0;
  9818. $m12 = 0;
  9819. $m13 = 0;
  9820. foreach ( $staffList as $value ) {
  9821. if ($vlu ['cid'] == $value ['cid']) {
  9822. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9823. $asum = 0;
  9824. for($i = 1; $i <= 12; $i ++) {
  9825. $falg = true;
  9826. foreach ( $itemStatisticsList as $v ) {
  9827. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9828. if ($v ['month'] == 1)
  9829. $m1 += $v ['price'];
  9830. if ($v ['month'] == 2)
  9831. $m2 += $v ['price'];
  9832. if ($v ['month'] == 3)
  9833. $m3 += $v ['price'];
  9834. if ($v ['month'] == 4)
  9835. $m4 += $v ['price'];
  9836. if ($v ['month'] == 5)
  9837. $m5 += $v ['price'];
  9838. if ($v ['month'] == 6)
  9839. $m6 += $v ['price'];
  9840. if ($v ['month'] == 7)
  9841. $m7 += $v ['price'];
  9842. if ($v ['month'] == 8)
  9843. $m8 += $v ['price'];
  9844. if ($v ['month'] == 9)
  9845. $m9 += $v ['price'];
  9846. if ($v ['month'] == 10)
  9847. $m10 += $v ['price'];
  9848. if ($v ['month'] == 11)
  9849. $m11 += $v ['price'];
  9850. if ($v ['month'] == 12)
  9851. $m12 += $v ['price'];
  9852. $asum += $v ['price'];
  9853. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9854. $falg = false;
  9855. break;
  9856. }
  9857. }
  9858. if ($falg)
  9859. $html .= '<td class="taR">-</td>';
  9860. }
  9861. $m13 += $asum;
  9862. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9863. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9864. 'html' => $html,
  9865. 'sid' => $value ['sid']
  9866. );
  9867. $html = "";
  9868. }
  9869. }
  9870. $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>
  9871. <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>
  9872. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9873. $collectHtml [$vlu ['cid']] = array (
  9874. 'html' => $hl,
  9875. 'sid' => ''
  9876. );
  9877. }
  9878. $data ['companyHtml'] = $collectHtml;
  9879. // total price html
  9880. $collectHtml = "";
  9881. $total = 0;
  9882. for($i = 1; $i <= 12; $i ++) {
  9883. $sumPrice = 0;
  9884. foreach ( $itemStatisticsList as $key => $value ) {
  9885. if ($value ['month'] == $i) {
  9886. $sumPrice += $value ['price'];
  9887. }
  9888. }
  9889. if ($sumPrice == 0)
  9890. $collectHtml .= '<td class="taR">-</td>';
  9891. else
  9892. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9893. $total += $sumPrice;
  9894. }
  9895. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9896. $data ['companyTotalHtml'] = $collectHtml;
  9897. $data ['total'] = $total;
  9898. $data ['nature'] =$nature;
  9899. $data ['year'] = $year;
  9900. $data ['memu'] = "receipt";
  9901. $data ['staff'] = $this->staff;
  9902. $data ['receiptMemu'] = 'companyCategoryCollect';
  9903. $data ['verifyId'] = $this->verifyId;
  9904. $data ['executeId'] = $this->executeId;
  9905. if ($year <= date ( "Y" )) {
  9906. Doo::loadModel ( 'receipt' );
  9907. $receipt = new receipt ();
  9908. $receiptList = $receipt->find ( array (
  9909. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9910. 'asArray' => true
  9911. ) );
  9912. if (empty ( $receiptList )) { // generated files
  9913. ob_start ();
  9914. $this->render ( "/admin/saeaStaffCollectB", $data );
  9915. $this->cacheFile ( $path );
  9916. die ();
  9917. }
  9918. }
  9919. $this->render ( "/admin/saeaStaffCollectB", $data );
  9920. }
  9921. function staffCollectBak() {
  9922. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9923. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9924. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9925. $this->showCache ( $path );
  9926. Doo::loadModel ( 'statistics' );
  9927. $statistics = new statistics ();
  9928. Doo::loadModel ( "receiptDetail" );
  9929. $receiptDetail = new receiptDetail ();
  9930. Doo::loadModel ( 'L_category' );
  9931. $Lcategory = new L_category ();
  9932. Doo::loadModel ( 'accountItem' );
  9933. $accountItem = new accountItem ();
  9934. Doo::loadModel ( 'staff' );
  9935. $staff = new staff ();
  9936. Doo::loadModel ( 'itemStatistics' );
  9937. $itemStatistics = new itemStatistics ();
  9938. $itemStatisticsList = $itemStatistics->find ( array (
  9939. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9940. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9941. 'groupby' => 'staff,itemCategory,Month(date)',
  9942. 'asArray' => true
  9943. ) );
  9944. $itemCategoryList = $itemStatistics->find ( array (
  9945. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9946. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9947. 'groupby' => 'cid,itemCategory,Month(date)',
  9948. 'asArray' => true
  9949. ) );
  9950. $LcategoryList = $Lcategory->find ( array (
  9951. 'asArray' => true
  9952. ) );
  9953. $staffList = $staff->find ( array (
  9954. 'asArray' => true
  9955. ) );
  9956. $htmlArray = array ();
  9957. foreach ( $LcategoryList as $value ) {
  9958. $htmlArray [$value ['title']] = array ();
  9959. foreach ( $staffList as $v ) {
  9960. if ($value ['cid'] == $v ['cid']) {
  9961. $html = "";
  9962. $falg = true;
  9963. $staffSumPrice = 0;
  9964. foreach ( $itemStatisticsList as $a ) {
  9965. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9966. if (empty ( $a ['price'] )) {
  9967. $html .= '<td class="taR">-</td>';
  9968. $falg = false;
  9969. break;
  9970. } else {
  9971. $staffSumPrice += $a ['price'];
  9972. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9973. $falg = false;
  9974. break;
  9975. }
  9976. }
  9977. }
  9978. if ($falg) {
  9979. $html .= '<td class="taR">-</td>';
  9980. $falg = true;
  9981. }
  9982. $falg = true;
  9983. foreach ( $itemStatisticsList as $a ) {
  9984. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9985. if (empty ( $a ['price'] )) {
  9986. $html .= '<td class="taR">-</td>';
  9987. $falg = false;
  9988. break;
  9989. } else {
  9990. $staffSumPrice += $a ['price'];
  9991. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9992. $falg = false;
  9993. break;
  9994. }
  9995. }
  9996. }
  9997. if ($falg) {
  9998. $html .= '<td class="taR">-</td>';
  9999. $falg = true;
  10000. }
  10001. $falg = true;
  10002. foreach ( $itemStatisticsList as $a ) {
  10003. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  10004. if (empty ( $a ['price'] )) {
  10005. $html .= '<td class="taR">-</td>';
  10006. $falg = false;
  10007. break;
  10008. } else {
  10009. $staffSumPrice += $a ['price'];
  10010. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10011. $falg = false;
  10012. break;
  10013. }
  10014. }
  10015. }
  10016. if ($falg) {
  10017. $html .= '<td class="taR">-</td>';
  10018. $falg = true;
  10019. }
  10020. $falg = true;
  10021. foreach ( $itemStatisticsList as $a ) {
  10022. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  10023. if (! empty ( $a ['price'] )) {
  10024. $staffSumPrice += $a ['price'];
  10025. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10026. $falg = false;
  10027. break;
  10028. } else {
  10029. $html .= '<td class="taR">-</td>';
  10030. $falg = false;
  10031. break;
  10032. }
  10033. }
  10034. }
  10035. if ($falg) {
  10036. $html .= '<td class="taR">-</td>';
  10037. $falg = true;
  10038. }
  10039. $falg = true;
  10040. foreach ( $itemStatisticsList as $a ) {
  10041. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  10042. if (! empty ( $a ['price'] )) {
  10043. $staffSumPrice += $a ['price'];
  10044. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10045. $falg = false;
  10046. break;
  10047. } else {
  10048. $html .= '<td class="taR">-</td>';
  10049. $falg = false;
  10050. break;
  10051. }
  10052. }
  10053. }
  10054. if ($falg) {
  10055. $html .= '<td class="taR">-</td>';
  10056. $falg = true;
  10057. }
  10058. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  10059. $htmlArray [$value ['title']] [$v ['username']] = $html;
  10060. }
  10061. }
  10062. /* -- --- */
  10063. // 合计费用
  10064. $cateHtml = "";
  10065. $catePrice = 0;
  10066. $cateFalg = true;
  10067. foreach ( $itemCategoryList as $l ) {
  10068. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10069. if (empty ( $l ['price'] )) {
  10070. $cateHtml .= '<td class="colGreen taR">-</td>';
  10071. $cateFalg = false;
  10072. break;
  10073. } else {
  10074. $catePrice += $l ['price'];
  10075. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10076. $cateFalg = false;
  10077. break;
  10078. }
  10079. }
  10080. }
  10081. if ($cateFalg) {
  10082. $cateHtml .= '<td class="colGreen taR">-</td>';
  10083. $cateFalg = true;
  10084. }
  10085. $cateFalg = true;
  10086. foreach ( $itemCategoryList as $l ) {
  10087. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10088. if (empty ( $l ['price'] )) {
  10089. $cateHtml .= '<td class="colGreen taR">-</td>';
  10090. $cateFalg = false;
  10091. break;
  10092. } else {
  10093. $catePrice += $l ['price'];
  10094. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10095. $cateFalg = false;
  10096. break;
  10097. }
  10098. }
  10099. }
  10100. if ($cateFalg) {
  10101. $cateHtml .= '<td class="colGreen taR">-</td>';
  10102. $cateFalg = true;
  10103. }
  10104. $cateFalg = true;
  10105. foreach ( $itemCategoryList as $l ) {
  10106. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10107. if (empty ( $l ['price'] )) {
  10108. $cateHtml .= '<td class="colGreen taR">-</td>';
  10109. $cateFalg = false;
  10110. break;
  10111. } else {
  10112. $catePrice += $l ['price'];
  10113. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10114. $cateFalg = false;
  10115. break;
  10116. }
  10117. }
  10118. }
  10119. if ($cateFalg) {
  10120. $cateHtml .= '<td class="colGreen taR">-</td>';
  10121. $cateFalg = true;
  10122. }
  10123. $cateFalg = true;
  10124. foreach ( $itemCategoryList as $l ) {
  10125. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10126. if (empty ( $l ['price'] )) {
  10127. $cateHtml .= '<td class="colGreen taR">-</td>';
  10128. $cateFalg = false;
  10129. break;
  10130. } else {
  10131. $catePrice += $l ['price'];
  10132. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10133. $cateFalg = false;
  10134. break;
  10135. }
  10136. }
  10137. }
  10138. if ($cateFalg) {
  10139. $cateHtml .= '<td class="colGreen taR">-</td>';
  10140. $cateFalg = true;
  10141. }
  10142. $cateFalg = true;
  10143. foreach ( $itemCategoryList as $l ) {
  10144. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10145. if (empty ( $l ['price'] )) {
  10146. $cateHtml .= '<td class="colGreen taR">-</td>';
  10147. $cateFalg = false;
  10148. break;
  10149. } else {
  10150. $catePrice += $l ['price'];
  10151. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10152. $cateFalg = false;
  10153. break;
  10154. }
  10155. }
  10156. }
  10157. if ($cateFalg) {
  10158. $cateHtml .= '<td class="colGreen taR">-</td>';
  10159. $cateFalg = true;
  10160. }
  10161. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10162. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10163. /* -- --- */
  10164. }
  10165. // print_r($htmlArray);die;
  10166. $data ['htmlArray'] = $htmlArray;
  10167. // statistics html
  10168. $stList = $statistics->getOne ( array (
  10169. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10170. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10171. 'groupby' => 'Month(date)',
  10172. 'asArray' => true
  10173. ) );
  10174. if (empty ( $stList ))
  10175. $stList = array (
  10176. 'rePrice' => 0,
  10177. 'agPrice' => 0
  10178. );
  10179. $data ['stList'] = array (
  10180. 'rePrice' => $stList ['rePrice'],
  10181. 'agPrice' => $stList ['agPrice'],
  10182. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10183. );
  10184. $monthHtml = "";
  10185. for($i = 1; $i <= 12; $i ++) {
  10186. if ($i == $month)
  10187. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10188. else
  10189. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10190. }
  10191. $data ['monthHtml'] = $monthHtml;
  10192. $data ['year'] = $year;
  10193. $data ['month'] = $month;
  10194. $data ['memu'] = "receipt";
  10195. $data ['staff'] = $this->staff;
  10196. $data ['receiptMemu'] = 'companyCategoryCollect';
  10197. $data ['verifyId'] = $this->verifyId;
  10198. $data ['executeId'] = $this->executeId;
  10199. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10200. Doo::loadModel ( 'receipt' );
  10201. $receipt = new receipt ();
  10202. $receiptList = $receipt->find ( array (
  10203. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10204. 'asArray' => true
  10205. ) );
  10206. if (empty ( $receiptList )) { // generated files
  10207. ob_start ();
  10208. $this->render ( "/admin/saeaStaffCollect", $data );
  10209. $this->cacheFile ( $path );
  10210. die ();
  10211. }
  10212. }
  10213. $this->render ( "/admin/saeaStaffCollect", $data );
  10214. }
  10215. /**
  10216. * 日常收支
  10217. */
  10218. function payments() {
  10219. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10220. Doo::loadModel ( "execute" );
  10221. $execute = new execute ();
  10222. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10223. die ( 'illegal request' );
  10224. }
  10225. Doo::loadModel ( "accountBook" );
  10226. $accountBook = new accountBook ();
  10227. Doo::loadModel ( "accountBookStatistics" );
  10228. $accountBookStatistics = new accountBookStatistics ();
  10229. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10230. $list = $accountBook->getAccountBookByLimit ( 10 );
  10231. $data ['date'] = date ( "Y-m-d" );
  10232. $data ['statisticsList'] = $statisticsList;
  10233. $data ['list'] = $list;
  10234. $data ['memu'] = "receipt";
  10235. $data ['staff'] = $this->staff;
  10236. $data ['receiptMemu'] = 'payments';
  10237. $data ['verifyId'] = $this->verifyId;
  10238. $data ['executeId'] = $this->executeId;
  10239. $this->render ( "/expenses/payments", $data );
  10240. }
  10241. function paymentsIncomeDo() {
  10242. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10243. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10244. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10245. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10246. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10247. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10248. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10249. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10250. Doo::loadClass ( 'XDeode' );
  10251. $XDeode = new XDeode ( 5 );
  10252. Doo::loadModel ( "accountBook" );
  10253. Doo::loadModel ( "accountBookStatistics" );
  10254. Doo::loadModel ( 'wasteBook' );
  10255. // 记录流水时银行的转换
  10256. $accountBank = '';
  10257. if ($receivedBank == '纵横广发') {
  10258. $accountBank = 'CGBDeposit';
  10259. } elseif ($receivedBank == '纵横工行') {
  10260. $accountBank = 'ICBCDeposit';
  10261. } elseif ($receivedBank == '华润银行') {
  10262. $accountBank = 'HUADeposit';
  10263. } elseif ($receivedBank == '个人广发') {
  10264. $accountBank = 'PersonalDeposit';
  10265. }
  10266. if (empty ( $accountBank ))
  10267. die ( 'illegal request' );
  10268. // 收入为理财时特殊处理
  10269. if ($accountType == 7 || $accountType == 9) {
  10270. if ($receivedBank == '个人广发') {
  10271. die ( '个人广发 illegal request' );
  10272. }
  10273. // 添加一条收入
  10274. $accountBook = new accountBook ();
  10275. $accountBook->accountType = 10;
  10276. $accountBook->accountMsg = $accountMsg;
  10277. $accountBook->receivedPrice = $receivedPrice;
  10278. $accountBook->receivedMsg = $receivedMsg;
  10279. $accountBook->receivedBank = $receivedBank;
  10280. $accountBook->receivedDate = $receivedDate;
  10281. $accountBook->remarks = $remarks;
  10282. $accountBook->expensesType = 1;
  10283. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10284. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10285. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10286. $inComeId = $accountBook->insert ();
  10287. // 收支汇总-添加一条收入日常汇总
  10288. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10289. $accountBookStatistics = new accountBookStatistics ();
  10290. $item = array (
  10291. 'date' => date ( "Y-m-d" ),
  10292. 'accountType' => $abDetail ['accountType'],
  10293. 'accountMsg' => $abDetail ['accountMsg'],
  10294. 'aid' => $abDetail ['aid'],
  10295. 'inComePrice' => $abDetail ['receivedPrice'],
  10296. 'expensesType' => $abDetail ['expensesType']
  10297. );
  10298. $accountBookStatistics->setAccountBookStatistics ( $item );
  10299. // 添加收入流水
  10300. $wasteBook = new wasteBook ();
  10301. $itemWaste = array (
  10302. 'accountPriceShow' => $receivedPrice,
  10303. 'accountPrice' => $receivedPrice,
  10304. 'expensesType' => 1,
  10305. 'accountType' => 6, // 流水类型
  10306. 'dataID' => $inComeId,
  10307. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10308. 'accountBank' => $accountBank,
  10309. 'category' => $this->staff [0] ['category'],
  10310. 'cid' => $this->staff [0] ['cid'],
  10311. 'name' => $this->staff [0] ['username'],
  10312. 'sid' => $this->staff [0] ['sid'],
  10313. 'inputDate' => date ( "Y-m-d H:i:s" )
  10314. );
  10315. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10316. // 添加一条理财支出
  10317. $accountBank = 'CGBDeposit';
  10318. $expenditureBank = '纵横广发';
  10319. $dailyExpenditureType = 4;
  10320. if ($accountType == 9) {
  10321. $accountBank = 'ICBCDeposit';
  10322. $expenditureBank = '纵横工行';
  10323. $dailyExpenditureType = 6;
  10324. }
  10325. $accountBook = new accountBook ();
  10326. $accountBook->expensesType = 2;
  10327. $accountBook->expenditureType = $dailyExpenditureType;
  10328. $accountBook->expenditureMsg = $accountMsg;
  10329. $accountBook->expenditurePrice = $receivedPrice;
  10330. $accountBook->expenditureBank = $expenditureBank;
  10331. $accountBook->expenditureDate = $receivedDate;
  10332. $accountBook->remarks = $remarks;
  10333. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10334. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10335. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10336. $id = $accountBook->insert ();
  10337. // 收支汇总-添加一条理财支出汇总
  10338. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10339. $accountBookStatistics = new accountBookStatistics ();
  10340. $item = array (
  10341. 'date' => date ( "Y-m-d" ),
  10342. 'accountType' => $abDetail ['accountType'],
  10343. 'accountMsg' => $abDetail ['accountMsg'],
  10344. 'aid' => $abDetail ['aid'],
  10345. 'financingPrice' => - $receivedPrice,
  10346. 'expensesType' => 3
  10347. );
  10348. $accountBookStatistics->setAccountBookStatistics ( $item );
  10349. // 添加一条支出理财流水
  10350. $accountTypeWaste = 5;
  10351. if ($accountMsg == '公司固定') {
  10352. $accountTypeWaste = 9;
  10353. } elseif ($accountMsg == '公司活期') {
  10354. $accountTypeWaste = 10;
  10355. } elseif ($accountMsg == '个人(GR)') {
  10356. $accountBank = 'PersonalDeposit';
  10357. }
  10358. $itemWaste = array (
  10359. 'expensesType' => 2,
  10360. 'accountType' => $accountTypeWaste,
  10361. 'accountPriceShow' => $receivedPrice,
  10362. 'accountPrice' => - $receivedPrice,
  10363. 'dataID' => $id,
  10364. 'dailyExpenditureType' => $dailyExpenditureType,
  10365. 'accountBank' => $accountBank,
  10366. 'category' => $this->staff [0] ['category'],
  10367. 'cid' => $this->staff [0] ['cid'],
  10368. 'name' => $this->staff [0] ['username'],
  10369. 'sid' => $this->staff [0] ['sid'],
  10370. 'inputDate' => date ( "Y-m-d H:i:s" )
  10371. );
  10372. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10373. } elseif ($accountType == 1) {
  10374. if ($receivedBank == '个人广发')
  10375. die ( 'illegal request' );
  10376. // 添加一条收入
  10377. $accountBook = new accountBook ();
  10378. $accountBook->accountType = $accountType;
  10379. $accountBook->accountMsg = $accountMsg;
  10380. $accountBook->receivedPrice = $receivedPrice;
  10381. $accountBook->receivedMsg = $receivedMsg;
  10382. $accountBook->receivedBank = $receivedBank;
  10383. $accountBook->receivedDate = $receivedDate;
  10384. $accountBook->remarks = $remarks;
  10385. $accountBook->expensesType = 1;
  10386. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10387. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10388. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10389. $id = $accountBook->insert ();
  10390. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10391. // 收支汇总-添加一条收入日常汇总
  10392. $accountBookStatistics = new accountBookStatistics ();
  10393. $item = array (
  10394. 'date' => date ( "Y-m-d" ),
  10395. 'accountType' => $abDetail ['accountType'],
  10396. 'accountMsg' => $abDetail ['accountMsg'],
  10397. 'aid' => $abDetail ['aid'],
  10398. 'expensesType' => $abDetail ['expensesType']
  10399. );
  10400. if ($abDetail ['accountType'] == 8) {
  10401. $item += array (
  10402. 'inComePrice' => $abDetail ['receivedPrice']
  10403. );
  10404. } else {
  10405. $item += array (
  10406. 'inComePrice' => $abDetail ['receivedPrice']
  10407. );
  10408. }
  10409. $accountBookStatistics->setAccountBookStatistics ( $item );
  10410. // 流水存储方向
  10411. $itemWaste = array (
  10412. 'accountType' => 6
  10413. ); // 流水类型
  10414. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10415. // }else
  10416. if ($accountMsg == '活期理财收益') {
  10417. $itemWaste = array (
  10418. 'accountType' => 10
  10419. ); // 流水类型
  10420. }
  10421. // 添加收入流水
  10422. $wasteBook = new wasteBook ();
  10423. $itemWaste += array (
  10424. 'accountPrice' => $receivedPrice,
  10425. 'accountPriceShow' => $receivedPrice,
  10426. 'expensesType' => 1,
  10427. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10428. 'dataID' => $id,
  10429. 'accountBank' => $accountBank,
  10430. 'category' => $this->staff [0] ['category'],
  10431. 'cid' => $this->staff [0] ['cid'],
  10432. 'name' => $this->staff [0] ['username'],
  10433. 'sid' => $this->staff [0] ['sid'],
  10434. 'inputDate' => date ( "Y-m-d H:i:s" )
  10435. );
  10436. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10437. } else { // 普通日常收入处理
  10438. // 添加一条收入
  10439. $accountBook = new accountBook ();
  10440. $accountBook->accountType = $accountType;
  10441. $accountBook->accountMsg = $accountMsg;
  10442. $accountBook->receivedPrice = $receivedPrice;
  10443. $accountBook->receivedMsg = $receivedMsg;
  10444. $accountBook->receivedBank = $receivedBank;
  10445. $accountBook->receivedDate = $receivedDate;
  10446. $accountBook->remarks = $remarks;
  10447. $accountBook->expensesType = 1;
  10448. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10449. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10450. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10451. $id = $accountBook->insert ();
  10452. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10453. // 收支汇总-添加一条收入日常汇总
  10454. $accountBookStatistics = new accountBookStatistics ();
  10455. $item = array (
  10456. 'date' => date ( "Y-m-d" ),
  10457. 'accountType' => $abDetail ['accountType'],
  10458. 'accountMsg' => $abDetail ['accountMsg'],
  10459. 'aid' => $abDetail ['aid'],
  10460. 'expensesType' => $abDetail ['expensesType']
  10461. );
  10462. if ($abDetail ['accountType'] == 8) {
  10463. $item += array (
  10464. 'inComePrice' => $abDetail ['receivedPrice']
  10465. );
  10466. } else {
  10467. $item += array (
  10468. 'inComePrice' => $abDetail ['receivedPrice']
  10469. );
  10470. }
  10471. $accountBookStatistics->setAccountBookStatistics ( $item );
  10472. // 添加收入流水
  10473. $itemWaste = array (
  10474. 'accountPrice' => $receivedPrice
  10475. );
  10476. if ($receivedBank == '个人广发') {
  10477. $itemWaste = array (
  10478. 'accountPrice' => - $receivedPrice
  10479. );
  10480. }
  10481. $wasteBook = new wasteBook ();
  10482. $itemWaste += array (
  10483. 'accountPriceShow' => $receivedPrice,
  10484. 'expensesType' => 1,
  10485. 'accountType' => 6, // 流水类型
  10486. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10487. 'dataID' => $id,
  10488. 'accountBank' => $accountBank,
  10489. 'category' => $this->staff [0] ['category'],
  10490. 'cid' => $this->staff [0] ['cid'],
  10491. 'name' => $this->staff [0] ['username'],
  10492. 'sid' => $this->staff [0] ['sid'],
  10493. 'inputDate' => date ( "Y-m-d H:i:s" )
  10494. );
  10495. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10496. }
  10497. }
  10498. return '/payments';
  10499. }
  10500. /**
  10501. * 添加收入
  10502. * @return string
  10503. */
  10504. function paymentsIncomeDo_() {
  10505. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10506. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10507. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10508. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10509. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10510. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10511. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10512. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10513. Doo::loadClass ( 'XDeode' );
  10514. $XDeode = new XDeode ( 5 );
  10515. Doo::loadModel ( "accountBook" );
  10516. $accountBook = new accountBook ();
  10517. $accountBank = '';
  10518. $accountTypeWaste = 6;
  10519. if ($receivedBank == '纵横广发') {
  10520. $accountBank = 'CGBDeposit';
  10521. } elseif ($receivedBank == '纵横工行') {
  10522. $accountBank = 'ICBCDeposit';
  10523. } elseif ($receivedBank == '华润银行') {
  10524. $accountBank = 'HUADeposit';
  10525. } elseif ($receivedBank == '个人广发') {
  10526. $accountBank = 'PersonalDeposit';
  10527. }
  10528. if (empty ( $accountBank ))
  10529. die ( 'illegal request' );
  10530. $dailyIncomeType = '';
  10531. $itemWaste = array (
  10532. 'accountPrice' => $receivedPrice,
  10533. 'expensesType' => 1
  10534. );
  10535. if ($receivedBank == '个人广发') {
  10536. $itemWaste = array (
  10537. 'accountPrice' => - $receivedPrice,
  10538. 'expensesType' => 1
  10539. );
  10540. }
  10541. if ($accountType == 4) {
  10542. $dailyIncomeType = 4;
  10543. } elseif ($accountType == 1) {
  10544. $dailyIncomeType = 1;
  10545. } elseif ($accountType == 2) {
  10546. $dailyIncomeType = 2;
  10547. } elseif ($accountType == 3) {
  10548. $dailyIncomeType = 3;
  10549. } elseif ($accountType == 5) {
  10550. $dailyIncomeType = 5;
  10551. } elseif ($accountType == 6) {
  10552. $dailyIncomeType = 6;
  10553. } elseif ($accountType == 7 || $accountType == 9) {
  10554. $dailyIncomeType = 7;
  10555. if ($accountMsg == '公司固定') {
  10556. $accountTypeWaste = 9;
  10557. } elseif ($accountMsg == '公司活期') {
  10558. $accountTypeWaste = 10;
  10559. } elseif ($accountMsg == '个人(GR)') {
  10560. $accountBank = 'PersonalDeposit';
  10561. }
  10562. $itemWaste = array (
  10563. 'accountPrice' => - $receivedPrice,
  10564. 'expensesType' => 2
  10565. );
  10566. } elseif ($accountType == 8) {
  10567. $dailyIncomeType = 8;
  10568. }
  10569. if (empty ( $dailyIncomeType ))
  10570. die ( 'illegal request' );
  10571. $accountBook->accountType = $accountType;
  10572. $accountBook->accountMsg = $accountMsg;
  10573. $accountBook->receivedPrice = $receivedPrice;
  10574. $accountBook->receivedMsg = $receivedMsg;
  10575. $accountBook->receivedBank = $receivedBank;
  10576. $accountBook->receivedDate = $receivedDate;
  10577. $accountBook->remarks = $remarks;
  10578. $accountBook->expensesType = 1;
  10579. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10580. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10581. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10582. $id = $accountBook->insert ();
  10583. //
  10584. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10585. // 收支汇总
  10586. Doo::loadModel ( "accountBookStatistics" );
  10587. $accountBookStatistics = new accountBookStatistics ();
  10588. $item = array (
  10589. 'date' => date ( "Y-m-d" ),
  10590. 'accountType' => $abDetail ['accountType'],
  10591. 'accountMsg' => $abDetail ['accountMsg'],
  10592. 'aid' => $abDetail ['aid']
  10593. );
  10594. if ($abDetail ['expensesType'] == 1) {
  10595. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10596. $item += array (
  10597. 'financingPrice' => - $receivedPrice,
  10598. 'expensesType' => 3
  10599. );
  10600. } else if ($abDetail ['accountType'] == 8) {
  10601. $item += array (
  10602. 'inComePrice' => - $abDetail ['receivedPrice'],
  10603. 'expensesType' => $abDetail ['expensesType']
  10604. );
  10605. } else {
  10606. $item += array (
  10607. 'inComePrice' => $abDetail ['receivedPrice'],
  10608. 'expensesType' => $abDetail ['expensesType']
  10609. );
  10610. }
  10611. }
  10612. $accountBookStatistics->setAccountBookStatistics ( $item );
  10613. // 为理财时需添加一条日常支出
  10614. if ($accountType == 7 || $accountType == 9) {
  10615. }
  10616. // 公司流水记录
  10617. Doo::loadModel ( 'wasteBook' );
  10618. $wasteBook = new wasteBook ();
  10619. // 银行
  10620. // if (empty($abDetail)){
  10621. $itemWaste += array (
  10622. 'accountPriceShow' => $receivedPrice,
  10623. 'dataID' => $id,
  10624. 'accountType' => $accountTypeWaste,
  10625. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10626. 'accountBank' => $accountBank,
  10627. 'category' => $this->staff [0] ['category'],
  10628. 'cid' => $this->staff [0] ['cid'],
  10629. 'name' => $this->staff [0] ['username'],
  10630. 'sid' => $this->staff [0] ['sid'],
  10631. 'inputDate' => date ( "Y-m-d H:i:s" )
  10632. );
  10633. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10634. // }
  10635. // 类型为理财7或者9 要添加一笔理财支出
  10636. if ($accountType == 7 || $accountType == 9) {
  10637. $accountBank = 'CGBDeposit';
  10638. $expenditureBank = '纵横广发';
  10639. $dailyExpenditureType = 4;
  10640. if ($accountType == 9) {
  10641. $accountBank = 'ICBCDeposit';
  10642. $expenditureBank = '纵横工行';
  10643. $dailyExpenditureType = 6;
  10644. }
  10645. // 添加一条支出
  10646. $accountBook = new accountBook ();
  10647. $accountBook->expenditureType = $dailyExpenditureType;
  10648. $accountBook->expenditureMsg = $accountMsg;
  10649. $accountBook->expenditurePrice = $receivedPrice;
  10650. $accountBook->expenditureBank = $expenditureBank;
  10651. $accountBook->expenditureDate = $receivedDate;
  10652. $accountBook->remarks = $remarks;
  10653. $accountBook->expensesType = 2;
  10654. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10655. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10656. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10657. $id = $accountBook->insert ();
  10658. // 添加一条收入流水
  10659. $itemWaste = array (
  10660. 'accountPriceShow' => $receivedPrice,
  10661. 'accountPrice' => $receivedPrice,
  10662. 'dataID' => $id,
  10663. 'expensesType' => 2,
  10664. 'accountType' => $accountTypeWaste,
  10665. 'dailyExpenditureType' => $dailyExpenditureType,
  10666. 'accountBank' => $accountBank,
  10667. 'category' => $this->staff [0] ['category'],
  10668. 'cid' => $this->staff [0] ['cid'],
  10669. 'name' => $this->staff [0] ['username'],
  10670. 'sid' => $this->staff [0] ['sid'],
  10671. 'inputDate' => date ( "Y-m-d H:i:s" )
  10672. );
  10673. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10674. }
  10675. }
  10676. return '/payments';
  10677. }
  10678. function paymentsExpenditureDo() {
  10679. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10680. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10681. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10682. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10683. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10684. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10685. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10686. // 理财支出特殊处理
  10687. Doo::loadModel ( "accountBook" );
  10688. Doo::loadModel ( "accountBookStatistics" );
  10689. Doo::loadModel ( 'wasteBook' );
  10690. $accountBank = '';
  10691. if ($expenditureBank == '纵横广发') {
  10692. $accountBank = 'CGBDeposit';
  10693. } elseif ($expenditureBank == '纵横工行') {
  10694. $accountBank = 'ICBCDeposit';
  10695. } elseif ($expenditureBank == '华润银行') {
  10696. $accountBank = 'HUADeposit';
  10697. } elseif ($expenditureBank == '个人广发') {
  10698. $accountBank = 'PersonalDeposit';
  10699. }
  10700. if (empty ( $accountBank ))
  10701. die ( 'illegal request' );
  10702. if ($expenditureType == 4 || $expenditureType == 6) {
  10703. if ($expenditureBank == '个人广发') {
  10704. die ( '个人广发 illegal request' );
  10705. }
  10706. // 添加一笔日常支出
  10707. $accountBook = new accountBook ();
  10708. $accountBook->expensesType = 2;
  10709. $accountBook->expenditureType = 7;
  10710. $accountBook->expenditureMsg = $expenditureMsg;
  10711. $accountBook->expenditurePrice = $expenditurePrice;
  10712. $accountBook->expenditureBank = $expenditureBank;
  10713. $accountBook->expenditureDate = $expenditureDate;
  10714. $accountBook->remarks = $remarks;
  10715. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10716. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10717. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10718. $expenditureId = $accountBook->insert ();
  10719. // 添加日常支出汇总
  10720. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10721. $accountBookStatistics = new accountBookStatistics ();
  10722. $item = array (
  10723. 'date' => date ( "Y-m-d" ),
  10724. 'expenditureType' => $abDetail ['expenditureType'],
  10725. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10726. 'aid' => $abDetail ['aid'],
  10727. 'payPrice' => $abDetail ['expenditurePrice'],
  10728. 'expensesType' => $abDetail ['expensesType']
  10729. );
  10730. $accountBookStatistics->setAccountBookStatistics ( $item );
  10731. // 公司日常支出流水
  10732. $wasteBook = new wasteBook ();
  10733. $itemWaste = array (
  10734. 'accountPrice' => - $expenditurePrice
  10735. );
  10736. if ($expenditureBank == '个人广发') {
  10737. $itemWaste = array (
  10738. 'accountPrice' => $expenditurePrice
  10739. );
  10740. }
  10741. $itemWaste += array (
  10742. 'expensesType' => 2,
  10743. 'accountType' => 5,
  10744. 'dailyExpenditureType' => $expenditureType,
  10745. 'accountPriceShow' => $expenditurePrice,
  10746. 'accountPrice' => - $expenditurePrice,
  10747. 'dataID' => $expenditureId,
  10748. 'accountBank' => $accountBank,
  10749. 'category' => $this->staff [0] ['category'],
  10750. 'cid' => $this->staff [0] ['cid'],
  10751. 'name' => $this->staff [0] ['username'],
  10752. 'sid' => $this->staff [0] ['sid'],
  10753. 'inputDate' => date ( "Y-m-d H:i:s" )
  10754. );
  10755. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10756. // 添加一笔理财收入
  10757. $accountBank = 'CGBDeposit';
  10758. $dailyIncomeType = 7;
  10759. $receivedBank = '纵横广发';
  10760. if ($expenditureType == 6) {
  10761. $accountBank = 'ICBCDeposit';
  10762. $receivedBank = '纵横工行';
  10763. $dailyIncomeType = 9;
  10764. }
  10765. $accountBook = new accountBook ();
  10766. $accountBook->expensesType = 1;
  10767. $accountBook->accountType = $dailyIncomeType;
  10768. $accountBook->accountMsg = $expenditureMsg;
  10769. $accountBook->receivedPrice = $expenditurePrice;
  10770. $accountBook->receivedBank = $receivedBank;
  10771. $accountBook->receivedDate = $expenditureDate;
  10772. $accountBook->remarks = $remarks;
  10773. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10774. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10775. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10776. $id = $accountBook->insert ();
  10777. // 添加日常理财收入汇总
  10778. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10779. $accountBookStatistics = new accountBookStatistics ();
  10780. $item = array (
  10781. 'date' => date ( "Y-m-d" ),
  10782. 'expenditureType' => $abDetail ['expenditureType'],
  10783. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10784. 'aid' => $abDetail ['aid'],
  10785. 'financingPrice' => $expenditurePrice,
  10786. 'expensesType' => 3
  10787. );
  10788. $accountBookStatistics->setAccountBookStatistics ( $item );
  10789. // 添加一笔收入流水
  10790. if ($expenditureMsg == '公司固定') {
  10791. $accountTypeWaste = 9;
  10792. } elseif ($expenditureMsg == '公司活期') {
  10793. $accountTypeWaste = 10;
  10794. } elseif ($expenditureMsg == '个人(GR)') {
  10795. $accountBank = 'PersonalDeposit';
  10796. }
  10797. $itemWaste = array (
  10798. 'expensesType' => 1,
  10799. 'accountType' => $accountTypeWaste,
  10800. 'accountPriceShow' => $expenditurePrice,
  10801. 'accountPrice' => $expenditurePrice,
  10802. 'dataID' => $id,
  10803. 'dailyIncomeType' => $dailyIncomeType,
  10804. 'accountBank' => $accountBank,
  10805. 'category' => $this->staff [0] ['category'],
  10806. 'cid' => $this->staff [0] ['cid'],
  10807. 'name' => $this->staff [0] ['username'],
  10808. 'sid' => $this->staff [0] ['sid'],
  10809. 'inputDate' => date ( "Y-m-d H:i:s" )
  10810. );
  10811. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10812. } else {
  10813. // 添加一笔日常支出
  10814. $accountBook = new accountBook ();
  10815. $accountBook->expensesType = 2;
  10816. $accountBook->expenditureType = $expenditureType;
  10817. $accountBook->expenditureMsg = $expenditureMsg;
  10818. $accountBook->expenditurePrice = $expenditurePrice;
  10819. $accountBook->expenditureBank = $expenditureBank;
  10820. $accountBook->expenditureDate = $expenditureDate;
  10821. $accountBook->remarks = $remarks;
  10822. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10823. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10824. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10825. $id = $accountBook->insert ();
  10826. // 添加日常支出汇总
  10827. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10828. $accountBookStatistics = new accountBookStatistics ();
  10829. $item = array (
  10830. 'date' => date ( "Y-m-d" ),
  10831. 'expenditureType' => $abDetail ['expenditureType'],
  10832. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10833. 'aid' => $abDetail ['aid'],
  10834. 'expensesType' => $abDetail ['expensesType']
  10835. );
  10836. if ($expenditureType == 5) {
  10837. $item += array (
  10838. 'payPrice' => - $abDetail ['expenditurePrice']
  10839. );
  10840. } else {
  10841. $item += array (
  10842. 'payPrice' => $abDetail ['expenditurePrice']
  10843. );
  10844. }
  10845. $accountBookStatistics->setAccountBookStatistics ( $item );
  10846. // 公司日常支出流水
  10847. $wasteBook = new wasteBook ();
  10848. $itemWaste = array (
  10849. 'accountPrice' => - $expenditurePrice
  10850. );
  10851. if ($expenditureBank == '个人广发') {
  10852. $itemWaste = array (
  10853. 'accountPrice' => $expenditurePrice
  10854. );
  10855. }
  10856. $itemWaste += array (
  10857. 'expensesType' => 2,
  10858. 'accountType' => 5,
  10859. 'accountPriceShow' => $expenditurePrice,
  10860. 'dataID' => $id,
  10861. 'dailyExpenditureType' => $expenditureType,
  10862. 'accountBank' => $accountBank,
  10863. 'category' => $this->staff [0] ['category'],
  10864. 'cid' => $this->staff [0] ['cid'],
  10865. 'name' => $this->staff [0] ['username'],
  10866. 'sid' => $this->staff [0] ['sid'],
  10867. 'inputDate' => date ( "Y-m-d H:i:s" )
  10868. );
  10869. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10870. }
  10871. }
  10872. return '/payments';
  10873. }
  10874. /**
  10875. * 添加支出
  10876. */
  10877. function paymentsExpenditureDo_() {
  10878. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10879. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10880. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10881. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10882. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10883. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10884. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10885. $dailyExpenditureType = '';
  10886. $accountTypeWaste = 5;
  10887. $accountBank = '';
  10888. if ($expenditureBank == '纵横广发') {
  10889. $accountBank = 'CGBDeposit';
  10890. } elseif ($expenditureBank == '纵横工行') {
  10891. $accountBank = 'ICBCDeposit';
  10892. } elseif ($expenditureBank == '华润银行') {
  10893. $accountBank = 'HUADeposit';
  10894. } elseif ($expenditureBank == '个人广发') {
  10895. $accountBank = 'PersonalDeposit';
  10896. }
  10897. if (empty ( $accountBank ))
  10898. die ( 'illegal request' );
  10899. $itemWaste = array (
  10900. 'accountPrice' => - $expenditurePrice
  10901. );
  10902. if ($expenditureBank == '个人广发') {
  10903. $itemWaste = array (
  10904. 'accountPrice' => $expenditurePrice
  10905. );
  10906. }
  10907. if ($expenditureType == 4 || $expenditureType == 6) {
  10908. $dailyExpenditureType = 4;
  10909. if ($expenditureMsg == '公司固定') {
  10910. $accountTypeWaste = 9;
  10911. } elseif ($expenditureMsg == '公司活期') {
  10912. $accountTypeWaste = 10;
  10913. } elseif ($expenditureMsg == '个人(GR)') {
  10914. $accountBank = 'PersonalDeposit';
  10915. }
  10916. $itemWaste = array (
  10917. 'accountPrice' => $expenditurePrice
  10918. );
  10919. } elseif ($expenditureType == 1) {
  10920. $dailyExpenditureType = 1;
  10921. } elseif ($expenditureType == 2) {
  10922. $dailyExpenditureType = 2;
  10923. } elseif ($expenditureType == 3) {
  10924. $dailyExpenditureType = 3;
  10925. } elseif ($expenditureType == 5) {
  10926. $dailyExpenditureType = 5;
  10927. }
  10928. if (empty ( $dailyExpenditureType ))
  10929. die ( 'illegal request' );
  10930. Doo::loadModel ( "accountBook" );
  10931. $accountBook = new accountBook ();
  10932. $accountBook->expenditureType = $expenditureType;
  10933. $accountBook->expenditureMsg = $expenditureMsg;
  10934. $accountBook->expenditurePrice = $expenditurePrice;
  10935. $accountBook->expenditureBank = $expenditureBank;
  10936. $accountBook->expenditureDate = $expenditureDate;
  10937. $accountBook->remarks = $remarks;
  10938. $accountBook->expensesType = 2;
  10939. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10940. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10941. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10942. $id = $accountBook->insert ();
  10943. //
  10944. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10945. Doo::loadModel ( "accountBookStatistics" );
  10946. $accountBookStatistics = new accountBookStatistics ();
  10947. $item = array (
  10948. 'date' => date ( "Y-m-d" ),
  10949. 'expenditureType' => $abDetail ['expenditureType'],
  10950. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10951. 'aid' => $abDetail ['aid']
  10952. );
  10953. if ($abDetail ['expensesType'] == 2) {
  10954. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10955. $item += array (
  10956. 'financingPrice' => $expenditurePrice,
  10957. 'expensesType' => 3
  10958. );
  10959. } elseif ($abDetail ['expenditureType'] == 5) {
  10960. $item += array (
  10961. 'payPrice' => $abDetail ['expenditurePrice'],
  10962. 'expensesType' => $abDetail ['expensesType']
  10963. );
  10964. } else {
  10965. $item += array (
  10966. 'payPrice' => $abDetail ['expenditurePrice'],
  10967. 'expensesType' => $abDetail ['expensesType']
  10968. );
  10969. }
  10970. }
  10971. $accountBookStatistics->setAccountBookStatistics ( $item );
  10972. // 公司流水记录
  10973. Doo::loadModel ( 'wasteBook' );
  10974. $wasteBook = new wasteBook ();
  10975. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10976. // 银行
  10977. if (empty ( $abDetail )) {
  10978. $itemWaste += array (
  10979. 'accountPriceShow' => $expenditurePrice,
  10980. 'dataID' => $id,
  10981. 'expensesType' => 2,
  10982. 'accountType' => $accountTypeWaste,
  10983. 'dailyExpenditureType' => $expenditureType,
  10984. 'accountBank' => $accountBank,
  10985. 'category' => $this->staff [0] ['category'],
  10986. 'cid' => $this->staff [0] ['cid'],
  10987. 'name' => $this->staff [0] ['username'],
  10988. 'sid' => $this->staff [0] ['sid'],
  10989. 'inputDate' => date ( "Y-m-d H:i:s" )
  10990. );
  10991. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10992. }
  10993. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10994. if ($expenditureType == 4 || $expenditureType == 6) {
  10995. $accountBank = 'CGBDeposit';
  10996. $dailyIncomeType = 7;
  10997. $receivedBank = '纵横广发';
  10998. if ($expenditureType == 6) {
  10999. $accountBank = 'ICBCDeposit';
  11000. $receivedBank = '纵横工行';
  11001. $dailyIncomeType = 9;
  11002. }
  11003. // 添加一笔收入
  11004. $accountBook = new accountBook ();
  11005. $accountBook->accountType = $dailyIncomeType;
  11006. $accountBook->accountMsg = $expenditureMsg;
  11007. $accountBook->receivedPrice = $expenditurePrice;
  11008. $accountBook->receivedBank = $receivedBank;
  11009. $accountBook->receivedDate = $expenditureDate;
  11010. $accountBook->remarks = $remarks;
  11011. $accountBook->expensesType = 1;
  11012. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11013. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11014. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11015. $id = $accountBook->insert ();
  11016. // 添加一笔收入流水
  11017. $itemWaste = array (
  11018. 'accountPriceShow' => $expenditurePrice,
  11019. 'accountPrice' => - $expenditurePrice,
  11020. 'dataID' => $id,
  11021. 'expensesType' => 1,
  11022. 'accountType' => $accountTypeWaste,
  11023. 'dailyIncomeType' => $dailyIncomeType,
  11024. 'accountBank' => $accountBank,
  11025. 'category' => $this->staff [0] ['category'],
  11026. 'cid' => $this->staff [0] ['cid'],
  11027. 'name' => $this->staff [0] ['username'],
  11028. 'sid' => $this->staff [0] ['sid'],
  11029. 'inputDate' => date ( "Y-m-d H:i:s" )
  11030. );
  11031. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11032. }
  11033. }
  11034. return '/payments';
  11035. }
  11036. /**
  11037. * 所有收支
  11038. */
  11039. function paymentsAchieve() {
  11040. $page_size = 12;
  11041. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  11042. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  11043. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11044. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  11045. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11046. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11047. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11048. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  11049. Doo::loadModel ( "accountBookStatistics" );
  11050. $accountBookStatistics = new accountBookStatistics ();
  11051. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  11052. $data ['statisticsList'] = $statisticsList;
  11053. Doo::loadModel ( "accountBook" );
  11054. $accountBook = new accountBook ();
  11055. $con = '';
  11056. if ($expensesType == 'INCOME')
  11057. $con = ' and expensesType=1 ';
  11058. elseif ($expensesType == 'PAY')
  11059. $con = ' and expensesType=2 ';
  11060. $dateArr = explode ( ':', $date );
  11061. $D1 = $dateString = '';
  11062. $D2 = '';
  11063. if (! empty ( $date )) {
  11064. $D1 = $dateArr [0];
  11065. if (isset ( $dateArr [1] ))
  11066. $D2 = $dateArr [1];
  11067. else
  11068. $D2 = '';
  11069. $dateString = $D1 . " : " . $D2;
  11070. }
  11071. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11072. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11073. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11074. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11075. if (! empty ( $price ))
  11076. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11077. if ($submitType == 1) {
  11078. if ($accountType != '') {
  11079. $expenditureType = '';
  11080. $con .= ' and accountType=' . $accountType;
  11081. if (! empty ( $accountMsg ))
  11082. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11083. }
  11084. } elseif ($submitType == 2) {
  11085. if ($expenditureType != '') {
  11086. $accountType = $accountMsg = '';
  11087. $con .= ' and expenditureType=' . $expenditureType;
  11088. }
  11089. } else {
  11090. $accountType = $accountMsg = $expenditureType = '';
  11091. }
  11092. $sql = "" . $con;
  11093. $action = "paymentsAchieve";
  11094. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11095. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11096. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11097. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11098. $data ['expenditureType'] = $expenditureType;
  11099. $data ['accountMsg'] = $accountMsg;
  11100. $data ['accountType'] = $accountType;
  11101. $data ['inputDate'] = $date;
  11102. $data ['price'] = $price;
  11103. $data ['expensesType'] = $expensesType;
  11104. $data ['page'] = $pageinfo;
  11105. $data ['list'] = $list;
  11106. $data ['memu'] = "receipt";
  11107. $data ['staff'] = $this->staff;
  11108. $data ['receiptMemu'] = 'payments';
  11109. $data ['verifyId'] = $this->verifyId;
  11110. $data ['executeId'] = $this->executeId;
  11111. $this->render ( "/expenses/paymentsAchieve", $data );
  11112. }
  11113. function paymentsIncomeUpdateDo() {
  11114. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11115. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11116. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11117. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11118. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11119. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11120. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11121. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11122. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11123. Doo::loadClass ( 'XDeode' );
  11124. $XDeode = new XDeode ( 5 );
  11125. $aid = $XDeode->decode ( $aidKey );
  11126. Doo::loadModel ( "accountBook" );
  11127. $accountBook = new accountBook ();
  11128. //
  11129. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11130. $price = $receivedPrice - $abDetail [inComePrice];
  11131. Doo::loadModel ( "accountBookStatistics" );
  11132. $accountBookStatistics = new accountBookStatistics ();
  11133. if ($abDetail ['accountType'] == 7) {
  11134. $item += array (
  11135. 'date' => date ( "Y-m-d" ),
  11136. 'financingPrice' => - $price,
  11137. 'expensesType' => 3,
  11138. 'aid' => $abDetail ['aid']
  11139. );
  11140. } elseif ($abDetail ['accountType'] == 8) {
  11141. $item += array (
  11142. 'date' => date ( "Y-m-d" ),
  11143. 'expensesType' => $abDetail ['expensesType'],
  11144. 'inComePrice' => - $price,
  11145. 'aid' => $abDetail ['aid']
  11146. );
  11147. } else {
  11148. $item = array (
  11149. 'date' => date ( "Y-m-d" ),
  11150. 'expensesType' => $abDetail ['expensesType'],
  11151. 'inComePrice' => $price,
  11152. 'aid' => $abDetail ['aid']
  11153. );
  11154. }
  11155. $accountBookStatistics->setAccountBookStatistics ( $item );
  11156. $accountBook->accountType = $accountType;
  11157. $accountBook->accountMsg = $accountMsg;
  11158. $accountBook->receivedPrice = $receivedPrice;
  11159. $accountBook->receivedMsg = $receivedMsg;
  11160. $accountBook->receivedBank = $receivedBank;
  11161. $accountBook->receivedDate = $receivedDate;
  11162. $accountBook->remarks = $remarks;
  11163. $accountBook->aid = $aid;
  11164. $accountBook->update ();
  11165. }
  11166. return '/paymentsAchieve';
  11167. }
  11168. function paymentsExpenditureEdiDo() {
  11169. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11170. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11171. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11172. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11173. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11174. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11175. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11176. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11177. Doo::loadClass ( 'XDeode' );
  11178. $XDeode = new XDeode ( 5 );
  11179. $aid = $XDeode->decode ( $aidKey );
  11180. Doo::loadModel ( "accountBook" );
  11181. $accountBook = new accountBook ();
  11182. // 汇总信息
  11183. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11184. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11185. Doo::loadModel ( "accountBookStatistics" );
  11186. $accountBookStatistics = new accountBookStatistics ();
  11187. if ($abDetail ['expenditureType'] == 4) {
  11188. $item += array (
  11189. 'date' => date ( "Y-m-d" ),
  11190. 'financingPrice' => $price,
  11191. 'expensesType' => 3,
  11192. 'aid' => $abDetail ['aid']
  11193. );
  11194. } elseif ($abDetail ['expenditureType'] == 5) {
  11195. $item += array (
  11196. 'date' => date ( "Y-m-d" ),
  11197. 'expensesType' => $abDetail ['expensesType'],
  11198. 'payPrice' => $price,
  11199. 'aid' => $abDetail ['aid']
  11200. );
  11201. } else {
  11202. $item = array (
  11203. 'date' => date ( "Y-m-d" ),
  11204. 'expensesType' => $abDetail ['expensesType'],
  11205. 'payPrice' => $price,
  11206. 'aid' => $abDetail ['aid']
  11207. );
  11208. }
  11209. $accountBookStatistics->setAccountBookStatistics ( $item );
  11210. //
  11211. $accountBook->expenditureType = $expenditureType;
  11212. $accountBook->expenditureMsg = $expenditureMsg;
  11213. $accountBook->expenditurePrice = $expenditurePrice;
  11214. $accountBook->expenditureBank = $expenditureBank;
  11215. $accountBook->remarks = $remarks;
  11216. $accountBook->expenditureDate = $expenditureDate;
  11217. $accountBook->aid = $aid;
  11218. $id = $accountBook->update ();
  11219. }
  11220. return '/paymentsAchieve';
  11221. }
  11222. function paymentsDelDo() {
  11223. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11224. if (! empty ( $aidKey )) {
  11225. Doo::loadClass ( 'XDeode' );
  11226. $XDeode = new XDeode ( 5 );
  11227. $aid = $XDeode->decode ( $aidKey );
  11228. Doo::loadModel ( "accountBook" );
  11229. $accountBook = new accountBook ();
  11230. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11231. if (empty ( $abDetail ))
  11232. die ( 'illegal request' );
  11233. // 删除收支
  11234. Doo::loadModel ( "accountBookStatistics" );
  11235. $accountBookStatistics = new accountBookStatistics ();
  11236. $item = array (
  11237. 'date' => date ( "Y-m-d" ),
  11238. 'aid' => $abDetail ['aid']
  11239. );
  11240. $accountType = '';
  11241. if ($abDetail ['expensesType'] == 1) {
  11242. $accountType = 6;
  11243. if ($abDetail ['accountType'] != 7) {
  11244. $item += array (
  11245. 'expensesType' => $abDetail ['expensesType'],
  11246. 'inComePrice' => - $abDetail ['receivedPrice']
  11247. );
  11248. } else {
  11249. $item += array (
  11250. 'financingPrice' => $abDetail ['receivedPrice'],
  11251. 'expensesType' => 3
  11252. );
  11253. }
  11254. } elseif ($abDetail ['expensesType'] == 2) {
  11255. $accountType = 5;
  11256. if ($abDetail ['accountType'] != 7) {
  11257. $item += array (
  11258. 'expensesType' => $abDetail ['expensesType'],
  11259. 'payPrice' => - $abDetail ['expenditurePrice']
  11260. );
  11261. } else {
  11262. $item += array (
  11263. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11264. 'expensesType' => 3
  11265. );
  11266. }
  11267. }
  11268. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11269. if ($abDetail ['expenditureMsg'] == '公司固定')
  11270. $accountType = 9;
  11271. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11272. $accountType = 10;
  11273. }
  11274. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11275. if ($abDetail ['accountMsg'] == '公司固定')
  11276. $accountType = 9;
  11277. elseif ($abDetail ['accountMsg'] == '公司活期')
  11278. $accountType = 10;
  11279. }
  11280. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11281. $accountType = 10;
  11282. }
  11283. $accountBookStatistics->setAccountBookStatistics ( $item );
  11284. $accountBook->delete ( array (
  11285. 'where' => 'aid=' . $aid,
  11286. 'limit' => 1
  11287. ) );
  11288. // 删除收入流水
  11289. if (! empty ( $accountType )) {
  11290. Doo::loadModel ( 'wasteBook' );
  11291. $wasteBook = new wasteBook ();
  11292. $wasteBook->delete ( array (
  11293. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11294. 'limit' => 1
  11295. ) );
  11296. }
  11297. }
  11298. return '/paymentsAchieve';
  11299. }
  11300. function paymentsCollect() {
  11301. Doo::loadModel ( "execute" );
  11302. $execute = new execute ();
  11303. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11304. die ( 'illegal request' );
  11305. }
  11306. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11307. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11308. Doo::loadModel ( "accountBookStatistics" );
  11309. $accountBookStatistics = new accountBookStatistics ();
  11310. Doo::loadClass ( 'receipt.func' );
  11311. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11312. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11313. $data ['html'] = $html ['html'];
  11314. $data ['inSum'] = $html ['sum'];
  11315. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11316. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11317. $data ['payHtml'] = $html ['html'];
  11318. $data ['paySum'] = $html ['sum'];
  11319. // 余额统计
  11320. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11321. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11322. include './protected/config/wasteBook.conf.php';
  11323. Doo::loadModel ( 'wasteBook' );
  11324. $wasteBook = new wasteBook ();
  11325. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11326. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11327. // 获得年份之前所有金额
  11328. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11329. // print_r($detail);
  11330. // $waste['total'];
  11331. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11332. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11333. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11334. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11335. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11336. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11337. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11338. if (date ( 'Y' ) > $year) {
  11339. $limitMonth = 12;
  11340. }
  11341. for($i = 1; $i <= 12; $i ++) {
  11342. $inComeA = $payB = 0;
  11343. $falg = true;
  11344. foreach ( $inComePay as $key => $value ) {
  11345. if ($value ['month'] == $i) {
  11346. $falg = false;
  11347. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11348. $inSum += $value ['accountPrice'];
  11349. $showInSum += $value ['accountPriceShow'];
  11350. $inComeA = $value ['accountPrice'];
  11351. break;
  11352. }
  11353. }
  11354. if ($falg)
  11355. $inComeHtml .= '<td class="taR">-</td>';
  11356. $payFalg = true;
  11357. foreach ( $pay as $key => $value ) {
  11358. if ($value ['month'] == $i) {
  11359. $payFalg = false;
  11360. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11361. $paySum += $value ['accountPrice'];
  11362. $showPaySum += $value ['accountPriceShow'];
  11363. $payB = $value ['accountPrice'];
  11364. break;
  11365. }
  11366. }
  11367. if ($payFalg)
  11368. $payHtml .= '<td class="taR">-</td>';
  11369. if (empty ( $balanceC ) || $limitMonth < $i)
  11370. $lastBalanceHtml .= '<td class="taR">-</td>';
  11371. else
  11372. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11373. $balanceC = $balanceC + $inComeA + $payB;
  11374. $balanceSum += $balanceC;
  11375. if (empty ( $balanceC ) || $limitMonth < $i)
  11376. $BalanceHtml .= '<td class="taR">-</td>';
  11377. else
  11378. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11379. // 余额统计
  11380. }
  11381. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11382. $data ['inComeHtml'] = $inComeHtml;
  11383. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11384. $data ['payBalanceHtml'] = $payHtml;
  11385. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11386. $data ['BalanceHtml'] = $BalanceHtml;
  11387. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11388. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11389. $mothHtml = "";
  11390. for($i = 1; $i <= 12; $i ++) {
  11391. if ($moth == $i)
  11392. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11393. else
  11394. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11395. }
  11396. $data ['mothHtml'] = $mothHtml;
  11397. $dateHtml = "";
  11398. $now = date ( "Y" );
  11399. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11400. if ($YEARD <= $now) {
  11401. $dateHtml .= '<option ';
  11402. if ($year == $YEARD) {
  11403. $dateHtml .= 'selected ';
  11404. }
  11405. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11406. }
  11407. }
  11408. $data ['dateHtml'] = $dateHtml;
  11409. $data ['year'] = $year;
  11410. $data ['memu'] = "receipt";
  11411. $data ['staff'] = $this->staff;
  11412. $data ['receiptMemu'] = 'paymentsCollect';
  11413. $data ['verifyId'] = $this->verifyId;
  11414. $data ['executeId'] = $this->executeId;
  11415. $this->render ( "/expenses/paymentsCollect", $data );
  11416. }
  11417. function paymentsCollectDay() {
  11418. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11419. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11420. if (empty ( $moth ))
  11421. return 'paymentsCollect';
  11422. Doo::loadModel ( "accountBookStatistics" );
  11423. $accountBookStatistics = new accountBookStatistics ();
  11424. $i = 2;
  11425. $y = 2013;
  11426. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11427. Doo::loadClass ( 'receipt.func' );
  11428. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11429. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11430. $data ['html'] = $html ['html'];
  11431. $data ['inSum'] = $html ['sum'];
  11432. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11433. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11434. $data ['payHtml'] = $html ['html'];
  11435. $data ['paySum'] = $html ['sum'];
  11436. $mothHtml = "";
  11437. for($i = 1; $i <= 12; $i ++) {
  11438. if ($moth == $i)
  11439. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11440. else
  11441. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11442. }
  11443. $data ['mothHtml'] = $mothHtml;
  11444. $data ['year'] = $year;
  11445. // 余额
  11446. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11447. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11448. include './protected/config/wasteBook.conf.php';
  11449. Doo::loadModel ( 'wasteBook' );
  11450. $wasteBook = new wasteBook ();
  11451. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11452. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11453. // 获得年份之前所有金额
  11454. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11455. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11456. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11457. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11458. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11459. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11460. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11461. // $balanceC = 0;
  11462. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11463. $limitDay = date ( 'd' );
  11464. $monthLK = ( int ) date ( 'm' );
  11465. if (date ( 'Y' ) > $year) {
  11466. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11467. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11468. $limitDay = 0;
  11469. }
  11470. for($i = 1; $i <= $day; $i ++) {
  11471. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11472. $inComeA = $payB = 0;
  11473. $falg = true;
  11474. foreach ( $inComePay as $key => $value ) {
  11475. if ($value ['day'] == $i) {
  11476. $falg = false;
  11477. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11478. $inSum += $value ['accountPrice'];
  11479. $showInSum += $value ['accountPriceShow'];
  11480. $inComeA = $value ['accountPrice'];
  11481. break;
  11482. }
  11483. }
  11484. if ($falg)
  11485. $inComeHtml .= '<td class="taR">-</td>';
  11486. $payFalg = true;
  11487. foreach ( $pay as $key => $value ) {
  11488. if ($value ['day'] == $i) {
  11489. $payFalg = false;
  11490. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11491. $paySum += $value ['accountPrice'];
  11492. $showPaySum += $value ['accountPriceShow'];
  11493. $payB = $value ['accountPrice'];
  11494. break;
  11495. }
  11496. }
  11497. if ($payFalg)
  11498. $payHtml .= '<td class="taR">-</td>';
  11499. if (empty ( $balanceC ) || $limitDay < $i)
  11500. $lastBalanceHtml .= '<td class="taR">-</td>';
  11501. else
  11502. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11503. $balanceC = $balanceC + $inComeA + $payB;
  11504. $balanceSum += $balanceC;
  11505. if (empty ( $balanceC ) || $limitDay < $i)
  11506. $BalanceHtml .= '<td class="taR">-</td>';
  11507. else
  11508. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11509. }
  11510. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11511. $data ['inComeHtml'] = $inComeHtml;
  11512. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11513. $data ['payBalanceHtml'] = $payHtml;
  11514. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11515. $data ['BalanceHtml'] = $BalanceHtml;
  11516. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11517. $data ['dayHtml'] = $dayHtml;
  11518. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11519. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11520. $dateHtml = "";
  11521. $now = date ( "Y" );
  11522. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11523. if ($YEARD <= $now) {
  11524. $dateHtml .= '<option ';
  11525. if ($year == $YEARD) {
  11526. $dateHtml .= 'selected ';
  11527. }
  11528. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11529. }
  11530. }
  11531. $data ['dateHtml'] = $dateHtml;
  11532. $data ['memu'] = "receipt";
  11533. $data ['staff'] = $this->staff;
  11534. $data ['receiptMemu'] = 'paymentsCollect';
  11535. $data ['verifyId'] = $this->verifyId;
  11536. $data ['executeId'] = $this->executeId;
  11537. $this->render ( "/expenses/paymentsCollectDay", $data );
  11538. }
  11539. // 公司流水
  11540. function wasteBook() {
  11541. Doo::loadModel ( "execute" );
  11542. $execute = new execute ();
  11543. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11544. die ( 'illegal request' );
  11545. }
  11546. include './protected/config/wasteBook.conf.php';
  11547. Doo::loadModel ( 'wasteBook' );
  11548. $wasteBook = new wasteBook ();
  11549. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11550. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11551. //+ $waste ['bank'] ['HUADeposit']
  11552. $total = $waste ['bank'] ['CGBDeposit'] + $waste ['bank'] ['ICBCDeposit'] + $waste ['bank'] ['PersonalDeposit'] + $waste ['financial'] ['current'] ['CGBDeposit'] + $waste ['financial'] ['current'] ['ICBCDeposit'] + $waste ['financial'] ['fixed'] ['CGBDeposit'] + $waste ['financial'] ['fixed'] ['ICBCDeposit'];
  11553. // print_r($waste);
  11554. $data ['waste'] = $waste;
  11555. $data ['total'] = $total;
  11556. // 月流水数据结构
  11557. $monthStatistics = array ();
  11558. $incomeMothStatistics = array ();
  11559. $expenditureMothStatistics = array ();
  11560. for($i = 1; $i <= 12; $i ++) {
  11561. $month = date ( 'Y' ) . '-' . $i;
  11562. if ($i < 10)
  11563. $month = date ( 'Y' ) . '-0' . $i;
  11564. array_push ( $monthStatistics, $month );
  11565. }
  11566. foreach ( $monthStatistics as $value ) {
  11567. $falg = true;
  11568. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11569. if ($value == $v ['inputDate']) {
  11570. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11571. $falg = false;
  11572. }
  11573. }
  11574. if ($falg) {
  11575. array_push ( $incomeMothStatistics, '' );
  11576. }
  11577. $falgEx = true;
  11578. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11579. if ($value == $v ['inputDate']) {
  11580. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11581. $falg = false;
  11582. }
  11583. }
  11584. if ($falgEx) {
  11585. array_push ( $expenditureMothStatistics, '' );
  11586. }
  11587. }
  11588. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11589. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11590. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11591. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11592. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11593. // print_r($incomeList);
  11594. $data ['expenditureList'] = $expenditureList;
  11595. $data ['incomeList'] = $incomeList;
  11596. $data ['memu'] = "receipt";
  11597. $data ['staff'] = $this->staff;
  11598. $data ['receiptMemu'] = 'wasteBook';
  11599. $data ['verifyId'] = $this->verifyId;
  11600. $data ['executeId'] = $this->executeId;
  11601. $this->render ( "/expenses/wasteBook", $data );
  11602. }
  11603. function wasteBookIncome() {
  11604. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11605. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11606. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11607. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11608. $data ['dailyIncomeType'] = $dailyIncomeType;
  11609. Doo::loadModel ( 'wasteBook' );
  11610. $wasteBook = new wasteBook ();
  11611. Doo::loadModel ( 'L_category' );
  11612. $L_category = new L_category ();
  11613. Doo::loadClass ( 'XDeode' );
  11614. $XDeode = new XDeode ( 5 );
  11615. // echo $XDeode->encode(1).'<br>';
  11616. // echo $XDeode->encode(2).'<br>';
  11617. // echo $XDeode->encode(3).'<br>';
  11618. // echo $XDeode->encode(4).'<br>';
  11619. // echo $XDeode->encode(5).'<br>';
  11620. // echo $XDeode->encode(6).'<br>';
  11621. // echo $XDeode->encode(7).'<br>';
  11622. // echo $XDeode->encode(8).'<br>';
  11623. // echo $XDeode->encode(9).'<br>';
  11624. // echo $XDeode->encode(10).'<br>';
  11625. $year=date("Y");
  11626. $theDay=date("Y-m-d");
  11627. $dateArr = explode ( ':', $date );
  11628. $D1 = '';
  11629. $D2 = '';
  11630. $con = '';
  11631. if (! empty ( $date )) {
  11632. $D1 = $dateArr [0];
  11633. $D2 = $dateArr [1];
  11634. }
  11635. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11636. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11637. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11638. $con = ' and inputDate = "' . $D1 . '"';
  11639. else{
  11640. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11641. }
  11642. if ($cid != 'ALL') {
  11643. $cid = $XDeode->decode ( $cid );
  11644. $con .= ' and cid = "' . $cid . '"';
  11645. }
  11646. if ($accountType != 'ALL') {
  11647. if ($accountType == 'INVOICE') {
  11648. $con .= ' and (accountType = 7 or accountType = 8)';
  11649. } elseif ($accountType == 'PAYMENTS') {
  11650. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11651. if ($dailyIncomeType != 'ALL') {
  11652. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11653. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11654. }
  11655. }
  11656. }
  11657. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11658. $sum = 0;$thsDaySum=0;
  11659. foreach ( $incomeList as $key => $value ) {
  11660. $sum += $value ['accountPrice'];
  11661. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11662. $thsDaySum+=$value ['accountPrice'];
  11663. }
  11664. }
  11665. // print_r($incomeList);
  11666. // 获得办事和部门
  11667. $categoryList = $L_category->getCategory ();
  11668. $data ['accountType'] = $accountType;
  11669. $data ['cid'] = $cid;
  11670. $data ['categoryList'] = $categoryList;
  11671. $data ['sum'] = $sum;
  11672. $data ['incomeList'] = $incomeList;
  11673. $data ['inputDate'] = $date;
  11674. $data['year']=$year;
  11675. $data ['thsDay'] =$theDay;
  11676. $data ['thsDaySum'] =$thsDaySum;
  11677. $data ['memu'] = "receipt";
  11678. $data ['staff'] = $this->staff;
  11679. $data ['receiptMemu'] = 'wasteBook';
  11680. $data ['verifyId'] = $this->verifyId;
  11681. $data ['executeId'] = $this->executeId;
  11682. $this->render ( "/expenses/wasteBookIncome", $data );
  11683. }
  11684. /**
  11685. * 所有支出
  11686. */
  11687. function wasteBookExpenditure() {
  11688. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11689. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11690. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11691. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11692. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11693. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11694. $data ['receiptType'] = $receiptType;
  11695. Doo::loadModel ( 'wasteBook' );
  11696. $wasteBook = new wasteBook ();
  11697. Doo::loadModel ( 'L_category' );
  11698. $L_category = new L_category ();
  11699. Doo::loadClass ( 'XDeode' );
  11700. $XDeode = new XDeode ( 5 );
  11701. $year=date("Y");
  11702. $theDay=date("Y-m-d");
  11703. $dateArr = explode ( ':', $date );
  11704. $D1 = '';
  11705. $D2 = '';
  11706. $con = '';
  11707. if (! empty ( $date )) {
  11708. $D1 = $dateArr [0];
  11709. $D2 = $dateArr [1];
  11710. }
  11711. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11712. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11713. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11714. $con = ' and inputDate = "' . $D1 . '"';
  11715. else{
  11716. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11717. }
  11718. if ($cid != 'ALL') {
  11719. $cid = $XDeode->decode ( $cid );
  11720. $con .= ' and cid = "' . $cid . '"';
  11721. }
  11722. if ($accountType != 'ALL') {
  11723. if ($accountType == 'INVOICE') {
  11724. $con .= ' and accountType = 11';
  11725. } elseif ($accountType == 'PAYMENTS') {
  11726. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11727. if ($dailyExpenditureType != 'ALL') {
  11728. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11729. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11730. }
  11731. } elseif ($accountType == 'RECEIPT') {
  11732. if ($receiptType == 'ALL') {
  11733. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11734. } else {
  11735. $receiptType = $XDeode->decode ( $receiptType );
  11736. echo $receiptType;
  11737. if ($receiptType == 1) {
  11738. $con .= ' and (accountType = 1 or accountType=2)';
  11739. } else {
  11740. $con .= ' and accountType = ' . $receiptType;
  11741. }
  11742. }
  11743. }
  11744. }
  11745. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11746. $sum = 0;$thsDaySum=0;
  11747. foreach ( $incomeList as $key => $value ) {
  11748. $sum += $value ['accountPriceShow'];
  11749. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11750. $thsDaySum+=$value ['accountPriceShow'];
  11751. }
  11752. }
  11753. // print_r($incomeList);
  11754. // 获得办事和部门
  11755. $categoryList = $L_category->getCategory ();
  11756. $data ['accountType'] = $accountType;
  11757. $data ['cid'] = $cid;
  11758. $data ['categoryList'] = $categoryList;
  11759. $data ['sum'] = $sum;
  11760. $data ['incomeList'] = $incomeList;
  11761. $data ['inputDate'] = $date;
  11762. $data['year']=$year;
  11763. $data ['thsDay'] =$theDay;
  11764. $data ['thsDaySum'] =$thsDaySum;
  11765. $data ['memu'] = "receipt";
  11766. $data ['staff'] = $this->staff;
  11767. $data ['receiptMemu'] = 'wasteBook';
  11768. $data ['verifyId'] = $this->verifyId;
  11769. $data ['executeId'] = $this->executeId;
  11770. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11771. }
  11772. function ajaxGetWasteinvoiceReceivables() {
  11773. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11774. Doo::loadClass ( 'XDeode' );
  11775. $XDeode = new XDeode ( 5 );
  11776. $irid = $XDeode->decode ( $serial );
  11777. Doo::loadModel ( 'invoiceReceivables' );
  11778. $invoiceReceivables = new invoiceReceivables ();
  11779. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11780. echo json_encode ( array (
  11781. 'status' => 1,
  11782. 'detail' => $detail
  11783. ) );
  11784. }
  11785. function ajaxGetPaymentsByAid() {
  11786. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11787. Doo::loadModel ( "accountBook" );
  11788. $accountBook = new accountBook ();
  11789. $detail = $accountBook->getAccountBookByAid ( $serial );
  11790. echo json_encode ( array (
  11791. 'status' => 1,
  11792. 'detail' => $detail
  11793. ) );
  11794. }
  11795. function ajaxGetWasteInvoice() {
  11796. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11797. Doo::loadModel ( 'invoice' );
  11798. $invoice = new invoice ();
  11799. Doo::loadModel ( 'invoiceReceivables' );
  11800. $invoiceReceivables = new invoiceReceivables ();
  11801. $detail = $invoice->getInvoiceByIid ( $serial );
  11802. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11803. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11804. echo json_encode ( array (
  11805. 'status' => 1,
  11806. 'detail' => $detail
  11807. ) );
  11808. }
  11809. /**
  11810. */
  11811. function ajaxGetWasteReceipt() {
  11812. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11813. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11814. Doo::loadModel ( 'receipt' );
  11815. $receipt = new receipt ();
  11816. Doo::loadClass ( 'XDeode' );
  11817. $XDeode = new XDeode ( 5 );
  11818. $rid = $XDeode->decode ( $serial );
  11819. $accountType= $XDeode->decode ( $accountTypeKey );
  11820. // 获得个数据
  11821. $detail = $receipt->getReceiptByRid ( $rid );
  11822. // 初始化
  11823. $detail ['reviseDetail'] = array ();
  11824. if (! empty ( $value ['reviseDetail'] ))
  11825. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11826. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11827. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11828. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11829. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11830. // 获得费用html
  11831. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11832. // 获得费用审批人数据
  11833. $detail = $this->getReceiptApproverHtml ( $detail );
  11834. // 审批执行
  11835. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11836. <th class="taC" width="90">审批人</th>
  11837. <th class="taC">审批意见</th></tr>';
  11838. foreach ( $detail ['verifyList'] as $key => $value ) {
  11839. $html .= '<tr>
  11840. <td>' . $value [1] . '</td>
  11841. <td>' . $value ['opinion'] . '</td>
  11842. </tr>
  11843. ';
  11844. }
  11845. $html .= ' </tbody></table>';
  11846. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11847. <th class="taC" width="90">执行人</th>
  11848. <th class="taC">执行意见</th></tr>';
  11849. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11850. $html .= '<tr>
  11851. <td>' . $value [1] . '</td>
  11852. <td>' . $value ['opinion'] . '</td>
  11853. </tr>
  11854. ';
  11855. }
  11856. $html .= ' </tbody></table>';
  11857. if($accountType==1){
  11858. Doo::loadModel ( 'loanReceipt' );
  11859. $loanReceipt = new loanReceipt ();
  11860. $loanList = $loanReceipt->getOne ( array (
  11861. 'where' => 'rid=' . $detail ['loanRid'],
  11862. 'desc' => 'rid',
  11863. 'asArray' => true
  11864. ) );
  11865. $html .= '<table class="table table-bordered table-condensed">
  11866. <tr class="warning">
  11867. <td class="taR"><b>汇款金额</b></td>
  11868. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11869. </tr>
  11870. </table>';
  11871. }else{
  11872. $html .= '<table class="table table-bordered table-condensed">
  11873. <tr class="warning">
  11874. <td class="taR"><b>汇款金额</b></td>
  11875. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11876. </tr>
  11877. </table>';
  11878. }
  11879. // print_r($detail['verifyList']);
  11880. // header ( 'Content-Type:text/html;charset=utf-8' );
  11881. // echo $html;
  11882. echo json_encode ( array (
  11883. 'status' => 1,
  11884. 'html' => $html,
  11885. 'detail' => $detail
  11886. ) );
  11887. }
  11888. function getReceiptApproverHtml($detail = array()) {
  11889. Doo::loadModel ( 'loanReceipt' );
  11890. $loanReceipt = new loanReceipt ();
  11891. Doo::loadModel ( 'verify' );
  11892. $verify = new verify ();
  11893. Doo::loadModel ( 'staff' );
  11894. $staff = new staff ();
  11895. if (empty ( $detail ))
  11896. return array ();
  11897. $loanList = $loanReceipt->getOne ( array (
  11898. 'where' => 'rid=' . $detail ['loanRid'],
  11899. 'desc' => 'rid',
  11900. 'asArray' => true
  11901. ) );
  11902. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11903. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11904. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11905. else
  11906. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11907. } else
  11908. $verifyList = $verify->getOne ( array (
  11909. 'where' => 'vid=' . $detail ['verify'],
  11910. 'asArray' => true
  11911. ) );
  11912. $verifyList = json_decode ( $verifyList ['staff'], true );
  11913. Doo::loadModel ( 'role' );
  11914. $role = new role ();
  11915. $roleId = 0;
  11916. $flag = true;
  11917. $roleKey = 0;
  11918. $endStaffArray = array ();
  11919. $roleArrayCopy = array ();
  11920. foreach ( $verifyList as $k => $v ) {
  11921. // init verifyStaff
  11922. if ($v [1] == 'ROLE') {
  11923. if (! empty ( $verifyStaff )) {
  11924. $endStaffArray = end ( $verifyStaff );
  11925. }
  11926. $roleVerify = json_decode ( $v [3], true );
  11927. $roleKey = $k;
  11928. $roleArray = array ();
  11929. $rolename = $role->getOne ( array (
  11930. 'where' => 'rid=' . $v [0],
  11931. 'asArray' => true
  11932. ) );
  11933. foreach ( $roleVerify as $o => $p ) {
  11934. $staffID = explode ( '_', $p );
  11935. $staffInfo = $staff->getOne ( array (
  11936. 'where' => 'sid=' . $staffID [0],
  11937. 'asArray' => true
  11938. ) );
  11939. // print_r($staffID);
  11940. $exp = array (
  11941. 0 => $staffInfo ['sid'],
  11942. 1 => $staffID [1],
  11943. 2 => $staffInfo ['avatar'],
  11944. 'date' => '',
  11945. 'date' => '',
  11946. 'opinion' => '',
  11947. 'status' => '',
  11948. 'rolename' => $rolename ['name']
  11949. );
  11950. array_push ( $roleArray, $exp );
  11951. }
  11952. $roleArrayCopy [$v [0]] = $roleArray;
  11953. // $verifyList[$k]['roleArray']=$roleArray;
  11954. }
  11955. $verifyList [$k] ['date'] = "";
  11956. $verifyList [$k] ['opinion'] = "";
  11957. $verifyList [$k] ['status'] = "";
  11958. if (empty ( $verifyStaff )) {
  11959. $verifyList [$k] ['date'] = "";
  11960. $verifyList [$k] ['opinion'] = "";
  11961. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11962. $verifyList [$k] ['status'] = 4;
  11963. $flag = false;
  11964. }
  11965. } else {
  11966. foreach ( $verifyStaff as $m => $u ) {
  11967. if ($v [0] == $m) {
  11968. $verifyList [$k] ['date'] = $u ['date'];
  11969. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11970. $verifyList [$k] ['status'] = $u ['status'];
  11971. $flag = false;
  11972. break;
  11973. }
  11974. }
  11975. $endStaffArray = end ( $verifyStaff );
  11976. }
  11977. }
  11978. $rolename ['name'] = '';
  11979. if (! empty ( $roleId )) {
  11980. Doo::loadModel ( 'role' );
  11981. $role = new role ();
  11982. $rolename = $role->getOne ( array (
  11983. 'where' => 'rid=' . $roleId,
  11984. 'asArray' => true
  11985. ) );
  11986. }
  11987. if (! empty ( $verifyStaff ))
  11988. $endStaffArray = end ( $verifyStaff );
  11989. $KOP = false;
  11990. foreach ( $roleArrayCopy as $P => $A ) {
  11991. foreach ( $A as $MKI => $AVL ) {
  11992. if (! empty ( $verifyStaff )) {
  11993. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11994. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11995. $button = 4;
  11996. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11997. }
  11998. foreach ( $verifyStaff as $m => $u ) {
  11999. $AVLFK = $AVL [0] . '_R';
  12000. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12001. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12002. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12003. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12004. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12005. break;
  12006. }
  12007. }
  12008. } else {
  12009. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12010. $button = 4;
  12011. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12012. }
  12013. }
  12014. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12015. $KOP = true;
  12016. }
  12017. }
  12018. foreach ( $roleArrayCopy as $k => $v ) {
  12019. foreach ( $verifyList as $m => $n ) {
  12020. if ($n [0] == $k) {
  12021. array_splice ( $verifyList, $m, 1, $v );
  12022. }
  12023. }
  12024. }
  12025. // 费用执行人相关数据
  12026. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12027. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12028. foreach ( $executeCopy as $k => $v ) {
  12029. $executeCopy [$k] ['date'] = '';
  12030. $executeCopy [$k] ['opinion'] = '';
  12031. $executeCopy [$k] ['status'] = '';
  12032. if (! empty ( $executeStaff ))
  12033. foreach ( $executeStaff as $m => $u ) {
  12034. if ($v [0] == $m) {
  12035. $executeCopy [$k] ['date'] = $u ['date'];
  12036. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12037. $executeCopy [$k] ['status'] = $u ['status'];
  12038. break;
  12039. }
  12040. }
  12041. }
  12042. $detail ['executeCopy'] = $executeCopy;
  12043. $detail ['verifyList'] = $verifyList;
  12044. return $detail;
  12045. }
  12046. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12047. if (empty ( $detail ))
  12048. return '';
  12049. $html = '';
  12050. if ($detail ['Rtype'] == 0) { // 报销单
  12051. $html .= '<table class="table table-bordered table-condensed">
  12052. <tbody>
  12053. <tr>
  12054. <th colspan="2" class="taC">日常相关费用</th>
  12055. </tr>';
  12056. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12057. $html .= '
  12058. <tr>
  12059. <th>' . $value ['name'] . '</th>
  12060. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12061. </tr>';
  12062. }
  12063. $html .= '
  12064. <tr>
  12065. <th class="taR">合计</th>
  12066. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12067. </tr>';
  12068. $html .= '<tr>
  12069. <th colspan="2" class="taC">差旅相关费用</th>
  12070. </tr>';
  12071. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12072. $html .= '
  12073. <tr>
  12074. <th>' . $value ['name'] . '</th>
  12075. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12076. </tr>';
  12077. }
  12078. $html .= '
  12079. <tr>
  12080. <th class="taR">合计</th>
  12081. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12082. </tr>';
  12083. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12084. $html .= '<tr>
  12085. <th colspan="2" class="taC">内部培训费用</th>
  12086. </tr>';
  12087. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12088. $html .= '
  12089. <tr>
  12090. <th>' . $value ['name'] . '</th>
  12091. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12092. </tr>';
  12093. }
  12094. $html .= '
  12095. <tr>
  12096. <th class="taR">合计</th>
  12097. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12098. </tr>';
  12099. }
  12100. $html .= '<tr>
  12101. <th colspan="2" class="taC">其他</th>
  12102. </tr>';
  12103. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12104. $html .= '
  12105. <tr>
  12106. <th>' . $value ['name'] . '</th>
  12107. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12108. </tr>';
  12109. }
  12110. $html .= '
  12111. <tr>
  12112. <th class="taR">合计</th>
  12113. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12114. </tr>';
  12115. $html .= '<tr>
  12116. <th colspan="2" class="taC">报销金额调整</th>
  12117. </tr>';
  12118. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12119. $html .= '
  12120. <tr>
  12121. <th>' . $value ['name'] . '</th>
  12122. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12123. </tr>';
  12124. }
  12125. $html .= '
  12126. <tr>
  12127. <th class="taR">合计</th>
  12128. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12129. </tr>';
  12130. $html .= '
  12131. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12132. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12133. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12134. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12135. <tr class="warning">
  12136. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12137. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12138. </tr>
  12139. </tbody>
  12140. </table>';
  12141. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12142. $html .= '
  12143. <table class="table table-bordered table-condensed">
  12144. <tbody>
  12145. <tr>
  12146. <th colspan="2" class="taC">办事处相关费用</th>
  12147. </tr>';
  12148. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12149. $html .= '
  12150. <tr>
  12151. <th>' . $value ['name'] . '</th>
  12152. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12153. </tr>';
  12154. }
  12155. $html .= '
  12156. <tr>
  12157. <th class="taR">合计</th>
  12158. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12159. </tr>';
  12160. $html .= '
  12161. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12162. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12163. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12164. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12165. <tr class="warning">
  12166. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12167. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12168. </tr>
  12169. </tbody>
  12170. </table>';
  12171. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12172. Doo::loadModel ( 'loanReceipt' );
  12173. $loanReceipt = new loanReceipt ();
  12174. $loanList = $loanReceipt->getOne ( array (
  12175. 'where' => 'rid=' . $detail ['loanRid'],
  12176. 'desc' => 'rid',
  12177. 'asArray' => true
  12178. ) );
  12179. // print_r($loanList);
  12180. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12181. $html .= '<table class="table table-bordered table-condensed">
  12182. <tbody>
  12183. <tr>
  12184. <th colspan="2" class="taC">借款费用</th>
  12185. </tr>';
  12186. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12187. $html .= '<tr>
  12188. <th>' . $value ['name'] . '</th>
  12189. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12190. </tr>';
  12191. }
  12192. $html .= '<tr>
  12193. <th class="taC" colspan="2">产生费用所在办事处</th>
  12194. </tr>
  12195. <tr>
  12196. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12197. </tr>
  12198. <tr>
  12199. <th class="taC" colspan="2">费用说明</th>
  12200. </tr>
  12201. <tr>
  12202. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12203. </tr>
  12204. <tr class="warning">
  12205. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12206. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12207. </tr>
  12208. </tbody>
  12209. </table>
  12210. ';
  12211. if ( $accountType==2) {
  12212. $balance=$detail ['sum']-$loanList ['sum'];
  12213. $balanceCN=$this->num_to_rmb($balance);
  12214. $html .= '<table class="table table-bordered table-condensed">
  12215. <tbody>
  12216. <tr>
  12217. <th colspan="2" class="taC">日常相关费用</th>
  12218. </tr>';
  12219. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12220. $html .= '
  12221. <tr>
  12222. <th>' . $value ['name'] . '</th>
  12223. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12224. </tr>';
  12225. }
  12226. $html .= '
  12227. <tr>
  12228. <th class="taR">合计</th>
  12229. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12230. </tr>';
  12231. $html .= '<tr>
  12232. <th colspan="2" class="taC">差旅相关费用</th>
  12233. </tr>';
  12234. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12235. $html .= '
  12236. <tr>
  12237. <th>' . $value ['name'] . '</th>
  12238. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12239. </tr>';
  12240. }
  12241. $html .= '
  12242. <tr>
  12243. <th class="taR">合计</th>
  12244. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12245. </tr>';
  12246. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12247. $html .= '<tr>
  12248. <th colspan="2" class="taC">内部培训费用</th>
  12249. </tr>';
  12250. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12251. $html .= '
  12252. <tr>
  12253. <th>' . $value ['name'] . '</th>
  12254. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12255. </tr>';
  12256. }
  12257. $html .= '
  12258. <tr>
  12259. <th class="taR">合计</th>
  12260. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12261. </tr>';
  12262. }
  12263. $html .= '<tr>
  12264. <th colspan="2" class="taC">其他</th>
  12265. </tr>';
  12266. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12267. $html .= '
  12268. <tr>
  12269. <th>' . $value ['name'] . '</th>
  12270. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12271. </tr>';
  12272. }
  12273. $html .= '
  12274. <tr>
  12275. <th class="taR">合计</th>
  12276. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12277. </tr>';
  12278. $html .= '<tr>
  12279. <th colspan="2" class="taC">报销金额调整</th>
  12280. </tr>';
  12281. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12282. $html .= '
  12283. <tr>
  12284. <th>' . $value ['name'] . '</th>
  12285. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12286. </tr>';
  12287. }
  12288. $html .= '
  12289. <tr>
  12290. <th class="taR">合计</th>
  12291. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12292. </tr>';
  12293. $html .= '
  12294. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12295. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12296. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12297. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12298. <tr class="warning">
  12299. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12300. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12301. </tr>
  12302. <tr class="success">
  12303. <td class="taR"><b>借款结余</b></td>
  12304. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12305. </tr>
  12306. </tbody>
  12307. </table>';
  12308. }
  12309. }
  12310. return $html;
  12311. }
  12312. /**
  12313. * 计算流水
  12314. */
  12315. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12316. $bakWaste ['bank'] = array (
  12317. 'CGBDeposit' => 0,
  12318. 'ICBCDeposit' => 0,
  12319. 'HUADeposit' => 0,
  12320. 'PersonalDeposit' => 0
  12321. );
  12322. $bakWaste ['financial'] = array (
  12323. 'current' => array (
  12324. 'CGBDeposit' => 0,
  12325. 'ICBCDeposit' => 0
  12326. ),
  12327. 'fixed' => array (
  12328. 'CGBDeposit' => 0,
  12329. 'ICBCDeposit' => 0
  12330. )
  12331. );
  12332. // 存款
  12333. foreach ( $waste ['bank'] as $key => $value ) {
  12334. // 收入
  12335. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12336. // 广发
  12337. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12338. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12339. }
  12340. // 工商
  12341. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12342. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12343. }
  12344. // 华润
  12345. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12346. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12347. }
  12348. // 个人
  12349. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12350. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12351. }
  12352. }
  12353. }
  12354. foreach ( $waste ['bank'] as $key => $value ) {
  12355. // 支出
  12356. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12357. // 广发
  12358. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12359. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12360. }
  12361. // 工商
  12362. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12363. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12364. }
  12365. // 华润
  12366. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12367. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12368. }
  12369. // 个人
  12370. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12371. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12372. }
  12373. }
  12374. }
  12375. // 活期
  12376. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12377. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12378. // 广发
  12379. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12380. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12381. }
  12382. // 工商
  12383. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12384. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12385. }
  12386. // 个人
  12387. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12388. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12389. }
  12390. }
  12391. }
  12392. // print_r($inComeStatistics ['fixedStatistics']);
  12393. // 固期
  12394. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12395. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12396. // 广发
  12397. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12398. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12399. }
  12400. // 工商
  12401. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12402. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12403. }
  12404. // 个人
  12405. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12406. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12407. }
  12408. }
  12409. }
  12410. return $waste;
  12411. }
  12412. function lyt() {
  12413. Doo::loadModel ( "receiptDetail" );
  12414. $receiptDetail = new receiptDetail ();
  12415. $receiptCollectList = $receiptDetail->find ( array (
  12416. 'where' => 'status=1 ',
  12417. 'asArray' => true
  12418. ) );
  12419. foreach ( $receiptCollectList as $key => $value ) {
  12420. $receiptDetail = new receiptDetail ();
  12421. $receiptDetail->pastDate = $value ['date'];
  12422. $receiptDetail->update ( array (
  12423. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12424. ) );
  12425. }
  12426. }
  12427. function staffCollectMonthDetail() {
  12428. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12429. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12430. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12431. if (! $year)
  12432. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12433. if (! $month)
  12434. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12435. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12436. if (! $nature){
  12437. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12438. }
  12439. Doo::loadModel ( 'staff' );
  12440. $staff = new staff ();
  12441. Doo::loadModel ( "receiptDetail" );
  12442. $receiptDetail = new receiptDetail ();
  12443. Doo::loadModel ( 'accountItem' );
  12444. $accountItem = new accountItem ();
  12445. Doo::loadModel ( 'statistics' );
  12446. $statistics = new statistics ();
  12447. Doo::loadModel ( "receiptAuthorityManage" );
  12448. $receiptAuthorityManage = new receiptAuthorityManage ();
  12449. $aiList=$accountItem->getAccountItem();
  12450. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12451. $cidList = array ();
  12452. foreach ( $imcStaff as $key => $value ) {
  12453. array_push ( $cidList, $value ['cid'] );
  12454. }
  12455. $cidString = implode ( ',', $cidList );
  12456. $naturecon='';
  12457. if ($nature=='ONJOB'){
  12458. $naturecon=' and (nature!=4 )';
  12459. }elseif($nature=='LEAVEJOB'){
  12460. $naturecon=' and (nature=4 )';
  12461. }else{
  12462. die ( 'illegal request--nature' );
  12463. }
  12464. $staffList = $staff->find ( array (
  12465. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12466. 'asArray' => true
  12467. ) );
  12468. $categoryList = $staff->find ( array (
  12469. 'select' => 'COUNT(*) as count,cid,category',
  12470. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12471. 'groupby' => 'cid',
  12472. 'asArray' => true
  12473. ) );
  12474. $list = array ();
  12475. foreach($aiList as $key=>$value){
  12476. foreach ($value as $v){
  12477. $subtotal[$key][$v['name']]=0;
  12478. }
  12479. }
  12480. foreach ( $categoryList as $vlu ) {
  12481. $s1 = 0;
  12482. $m1 = 0;
  12483. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12484. foreach ( $staffList as $value ) {
  12485. if ($vlu ['cid'] == $value ['cid']) {
  12486. // pastDate
  12487. $receiptCollectList = $receiptDetail->find ( array (
  12488. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12489. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12490. 'groupby' => 'item,Month(pastDate),itemCategory',
  12491. 'asArray' => true
  12492. ) );
  12493. if (! empty ( $receiptCollectList )) {
  12494. $receiptL = array (
  12495. '日常相关费用' => array (),
  12496. '差旅相关费用' => array (),
  12497. '内部培训费用' => array (),
  12498. '培训班费用' => array (),
  12499. '其他' => array ()
  12500. );
  12501. $html = "";
  12502. $psum = 0;
  12503. foreach ( $aiList[$this->AGENCY] as $va ) {
  12504. $falg = true;
  12505. foreach ( $receiptCollectList as $v ) {
  12506. if ($v ['itemCategory'] == '日常相关费用') {
  12507. if ($v ['item'] == $va['name']) {
  12508. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12509. $psum += $v ['price'];
  12510. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12511. $falg = false;
  12512. break;
  12513. }
  12514. }
  12515. }
  12516. if ($falg)
  12517. $html .= '<td class="taR">-</td>';
  12518. }
  12519. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12520. if (! empty ( $psum ))
  12521. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12522. else
  12523. $psum = '<td class="colGreen taR">-</td>';
  12524. $receiptL ['日常相关费用'] = $psum . $html;
  12525. /* ----------------------------------- */
  12526. $html = "";
  12527. $psum = 0;
  12528. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12529. $falg = true;
  12530. foreach ( $receiptCollectList as $v ) {
  12531. if ($v ['itemCategory'] == '差旅相关费用') {
  12532. if ($v ['item'] == $va['name']) {
  12533. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12534. $psum += $v ['price'];
  12535. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12536. $falg = false;
  12537. break;
  12538. }
  12539. }
  12540. }
  12541. if ($falg)
  12542. $html .= '<td class="taR">-</td>';
  12543. }
  12544. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12545. if (! empty ( $psum ))
  12546. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12547. else
  12548. $psum = '<td class="colGreen taR">-</td>';
  12549. $receiptL ['差旅相关费用'] = $psum . $html;
  12550. /* ------------------------------------- */
  12551. $html = "";
  12552. $psum = 0;
  12553. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12554. $falg = true;
  12555. foreach ( $receiptCollectList as $v ) {
  12556. if ($v ['itemCategory'] == '内部培训费用') {
  12557. if ($v ['item'] == $va['name']) {
  12558. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12559. $psum += $v ['price'];
  12560. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12561. $falg = false;
  12562. break;
  12563. }
  12564. }
  12565. }
  12566. if ($falg)
  12567. $html .= '<td class="taR">-</td>';
  12568. }
  12569. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12570. if (! empty ( $psum ))
  12571. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12572. else
  12573. $psum = '<td class="colGreen taR">-</td>';
  12574. $receiptL ['内部培训费用'] = $psum . $html;
  12575. /* ----------------------------------- */
  12576. $html = "";
  12577. $psum = 0;
  12578. foreach ( $aiList[$this->TRAIN] as $va ) {
  12579. $falg = true;
  12580. foreach ( $receiptCollectList as $v ) {
  12581. if ($v ['itemCategory'] == '培训班费用') {
  12582. if ($v ['item'] == $va['name']) {
  12583. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12584. $psum += $v ['price'];
  12585. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12586. $falg = false;
  12587. break;
  12588. }
  12589. }
  12590. }
  12591. if ($falg)
  12592. $html .= '<td class="taR">-</td>';
  12593. }
  12594. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12595. if (! empty ( $psum ))
  12596. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12597. else
  12598. $psum = '<td class="colGreen taR">-</td>';
  12599. $receiptL ['培训班费用'] = $psum . $html;
  12600. /* ------------------------------------- */
  12601. $html = "";
  12602. $psum = 0;
  12603. foreach ( $aiList[$this->OTHER] as $va ) {
  12604. $falg = true;
  12605. foreach ( $receiptCollectList as $v ) {
  12606. if ($v ['itemCategory'] == '其他') {
  12607. if (trim ( $v ['item'] ) == $va['name']) {
  12608. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12609. $psum += $v ['price'];
  12610. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12611. $falg = false;
  12612. break;
  12613. }
  12614. }
  12615. }
  12616. if ($falg)
  12617. $html .= '<td class="taR">-</td>';
  12618. }
  12619. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12620. if (! empty ( $psum ))
  12621. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12622. else
  12623. $psum = '<td class="colGreen taR">-</td>';
  12624. $receiptL ['其他'] = $psum . $html;
  12625. /* ------------------------------------- */
  12626. $html = "";
  12627. $psum = 0;
  12628. foreach ( $receiptCollectList as $v ) {
  12629. if ($v ['itemCategory'] == '报销金额调整') {
  12630. if (! empty ( $v ['price'] )) {
  12631. $psum += $v ['price'];
  12632. }
  12633. }
  12634. }
  12635. $s1 += $psum;
  12636. if (! empty ( $psum ))
  12637. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12638. else
  12639. $psum = '<td class="taR colOrange">-</td>';
  12640. $receiptL ['报销金额调整'] = $psum . $html;
  12641. } else {
  12642. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12643. foreach ( $aiList[$this->AGENCY] as $va ) {
  12644. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12645. }
  12646. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12647. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12648. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12649. }
  12650. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12651. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12652. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12653. }
  12654. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12655. foreach ( $aiList[$this->TRAIN] as $va ) {
  12656. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12657. }
  12658. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12659. foreach ( $aiList[$this->OTHER] as $va ) {
  12660. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12661. }
  12662. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12663. }
  12664. $monthStaffPrice = $receiptDetail->find ( array (
  12665. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12666. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12667. 'groupby' => 'Month(pastDate)',
  12668. 'asArray' => true
  12669. ) );
  12670. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12671. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12672. $m1 += $monthStaffPrice [0] ['price'];
  12673. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12674. } else
  12675. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12676. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12677. $list [$value ['username']] = $receiptL;
  12678. }
  12679. }
  12680. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12681. foreach ( $aiList[$this->AGENCY] as $va ) {
  12682. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12683. $subtotal[$this->AGENCY][$va['name']]=0;
  12684. }
  12685. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12686. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12687. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12688. $subtotal[$this->TRAVEL][$va['name']]=0;
  12689. }
  12690. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12691. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12692. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12693. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12694. }
  12695. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12696. foreach ( $aiList[$this->TRAIN] as $va ) {
  12697. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12698. $subtotal[$this->TRAIN][$va['name']]=0;
  12699. }
  12700. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12701. foreach ( $aiList[$this->OTHER] as $va ) {
  12702. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12703. $subtotal[$this->OTHER][$va['name']]=0;
  12704. }
  12705. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12706. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12707. $receiptL ['usernameEn'] =false;
  12708. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12709. }
  12710. $data ['list'] = $list;
  12711. // print_r($list);
  12712. $receiptCollectList = $receiptDetail->find ( array (
  12713. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12714. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12715. 'groupby' => 'item,Month(pastDate),itemCategory',
  12716. 'asArray' => true
  12717. ) );
  12718. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12719. // statistics html
  12720. $stList = $statistics->getOne ( array (
  12721. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12722. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12723. 'groupby' => 'Month(date)',
  12724. 'asArray' => true
  12725. ) );
  12726. if (empty ( $stList ))
  12727. $stList = array (
  12728. 'rePrice' => 0,
  12729. 'agPrice' => 0
  12730. );
  12731. $data ['stList'] = array (
  12732. 'rePrice' => $stList ['rePrice'],
  12733. 'agPrice' => $stList ['agPrice'],
  12734. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12735. );
  12736. $monthHtml = "";
  12737. for($i = 1; $i <= 12; $i ++) {
  12738. if ($i == $month)
  12739. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12740. else
  12741. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12742. }
  12743. $data ['monthHtml'] = $monthHtml;
  12744. $data ['year'] = $year;
  12745. $data ['month'] = $month;
  12746. $data ['nature'] = $nature;
  12747. $data ['aiList'] = $aiList;
  12748. $data ['memu'] = "receipt";
  12749. $data ['staff'] = $this->staff;
  12750. $data ['receiptMemu'] = 'companyCategoryCollect';
  12751. $data ['verifyId'] = $this->verifyId;
  12752. $data ['executeId'] = $this->executeId;
  12753. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12754. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12755. }
  12756. function staffCollectMonthDetail2() {
  12757. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12758. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12759. if (! $year)
  12760. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12761. if (! $month)
  12762. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12763. Doo::loadModel ( 'staff' );
  12764. $staff = new staff ();
  12765. Doo::loadModel ( "receiptDetail" );
  12766. $receiptDetail = new receiptDetail ();
  12767. Doo::loadModel ( 'accountItem' );
  12768. $accountItem = new accountItem ();
  12769. Doo::loadModel ( 'statistics' );
  12770. $statistics = new statistics ();
  12771. Doo::loadModel ( 'L_category' );
  12772. $lCategory = new L_category ();
  12773. $staffList = $staff->find ( array (
  12774. 'where' => 'username!="admin"',
  12775. 'asArray' => true
  12776. ) );
  12777. $categoryList = $staff->find ( array (
  12778. 'select' => 'COUNT(*) as count,cid,category',
  12779. 'where' => 'username !="admin"',
  12780. 'groupby' => 'cid',
  12781. 'asArray' => true
  12782. ) );
  12783. $list = array ();
  12784. foreach ( $categoryList as $vlu ) {
  12785. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12786. $r1 = 0;
  12787. $r2 = 0;
  12788. $r3 = 0;
  12789. $r4 = 0;
  12790. $r5 = 0;
  12791. $r6 = 0;
  12792. $r7 = 0;
  12793. $r8 = 0;
  12794. $r9 = 0;
  12795. $r10 = 0;
  12796. $r11 = 0;
  12797. $r12 = 0;
  12798. $r13 = 0;
  12799. $r14 = 0;
  12800. $r15 = 0;
  12801. $c1 = 0;
  12802. $c2 = 0;
  12803. $c3 = 0;
  12804. $c4 = 0;
  12805. $c5 = 0;
  12806. $c6 = 0;
  12807. $p1 = 0;
  12808. $p2 = 0;
  12809. $p3 = 0;
  12810. $p4 = 0;
  12811. $p5 = 0;
  12812. $p6 = 0;
  12813. $p7 = 0;
  12814. $p8 = 0;
  12815. $p9 = 0;
  12816. $t1 = 0;
  12817. $t2 = 0;
  12818. $t3 = 0;
  12819. $t4 = 0;
  12820. $t5 = 0;
  12821. $s1 = 0;
  12822. $m1 = 0;
  12823. foreach ( $staffList as $value ) {
  12824. if ($vlu ['cid'] == $value ['cid']) {
  12825. $receiptCollectList = $receiptDetail->find ( array (
  12826. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12827. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12828. 'groupby' => 'item,Month(date),itemCategory',
  12829. 'asArray' => true
  12830. ) );
  12831. if (! empty ( $receiptCollectList )) {
  12832. $receiptL = array (
  12833. '日常相关费用' => array (),
  12834. '差旅相关费用' => array (),
  12835. '培训班费用' => array (),
  12836. '其他' => array ()
  12837. );
  12838. $html = "";
  12839. $psum = 0;
  12840. $item = array (
  12841. '市内交通费',
  12842. '市内出租费',
  12843. '办事处房租',
  12844. '电话费',
  12845. '水费',
  12846. '电费',
  12847. '办公费用',
  12848. '邮寄费',
  12849. '其他费用',
  12850. '车辆费用',
  12851. '广告费',
  12852. '团队建设费',
  12853. '物业管理费',
  12854. '宽带费'
  12855. );
  12856. foreach ( $item as $va ) {
  12857. $falg = true;
  12858. foreach ( $receiptCollectList as $v ) {
  12859. if ($v ['itemCategory'] == '日常相关费用') {
  12860. if ($v ['item'] == $va) {
  12861. if ($va == '市内交通费')
  12862. $r1 += $v ['price'];
  12863. if ($va == '市内出租费')
  12864. $r2 += $v ['price'];
  12865. if ($va == '办事处房租')
  12866. $r3 += $v ['price'];
  12867. if ($va == '电话费')
  12868. $r4 += $v ['price'];
  12869. if ($va == '水费')
  12870. $r5 += $v ['price'];
  12871. if ($va == '电费')
  12872. $r6 += $v ['price'];
  12873. if ($va == '办公费用')
  12874. $r7 += $v ['price'];
  12875. if ($va == '邮寄费')
  12876. $r8 += $v ['price'];
  12877. if ($va == '其他费用')
  12878. $r9 += $v ['price'];
  12879. if ($va == '车辆费用')
  12880. $r10 += $v ['price'];
  12881. if ($va == '广告费')
  12882. $r11 += $v ['price'];
  12883. if ($va == '团队建设费')
  12884. $r13 += $v ['price'];
  12885. if ($va == '物业管理费')
  12886. $r14 += $v ['price'];
  12887. if ($va == '宽带费')
  12888. $r15 += $v ['price'];
  12889. $psum += $v ['price'];
  12890. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12891. $falg = false;
  12892. break;
  12893. }
  12894. }
  12895. }
  12896. if ($falg)
  12897. $html .= '<td class="taR">-</td>';
  12898. }
  12899. $r12 += $psum;
  12900. if (! empty ( $psum ))
  12901. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12902. else
  12903. $psum = '<td class="colGreen taR">-</td>';
  12904. $receiptL ['日常相关费用'] = $psum . $html;
  12905. /* ----------------------------------- */
  12906. $html = "";
  12907. $psum = 0;
  12908. $item = array (
  12909. '往来交通费',
  12910. '市内交通费',
  12911. '出差住宿费',
  12912. '出差补助',
  12913. '其他费用'
  12914. );
  12915. foreach ( $item as $va ) {
  12916. $falg = true;
  12917. foreach ( $receiptCollectList as $v ) {
  12918. if ($v ['itemCategory'] == '差旅相关费用') {
  12919. if ($v ['item'] == $va) {
  12920. if ($va == '往来交通费')
  12921. $c1 += $v ['price'];
  12922. if ($va == '市内交通费')
  12923. $c2 += $v ['price'];
  12924. if ($va == '出差住宿费')
  12925. $c3 += $v ['price'];
  12926. if ($va == '出差补助')
  12927. $c4 += $v ['price'];
  12928. if ($va == '其他费用')
  12929. $c5 += $v ['price'];
  12930. $psum += $v ['price'];
  12931. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12932. $falg = false;
  12933. break;
  12934. }
  12935. }
  12936. }
  12937. if ($falg)
  12938. $html .= '<td class="taR">-</td>';
  12939. }
  12940. $c6 += $psum;
  12941. if (! empty ( $psum ))
  12942. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12943. else
  12944. $psum = '<td class="colGreen taR">-</td>';
  12945. $receiptL ['差旅相关费用'] = $psum . $html;
  12946. /* ------------------------------------- */
  12947. $html = "";
  12948. $psum = 0;
  12949. $item = array (
  12950. '场租费',
  12951. '薪酬',
  12952. '住宿费',
  12953. '交通费',
  12954. '餐饮费',
  12955. '办公费',
  12956. '公关费',
  12957. '其他'
  12958. );
  12959. foreach ( $item as $va ) {
  12960. $falg = true;
  12961. foreach ( $receiptCollectList as $v ) {
  12962. if ($v ['itemCategory'] == '培训班费用') {
  12963. if ($v ['item'] == $va) {
  12964. if ($va == '场租费')
  12965. $p1 += $v ['price'];
  12966. if ($va == '薪酬')
  12967. $p2 += $v ['price'];
  12968. if ($va == '住宿费')
  12969. $p3 += $v ['price'];
  12970. if ($va == '交通费')
  12971. $p4 += $v ['price'];
  12972. if ($va == '餐饮费')
  12973. $p5 += $v ['price'];
  12974. if ($va == '办公费')
  12975. $p6 += $v ['price'];
  12976. if ($va == '公关费')
  12977. $p7 += $v ['price'];
  12978. if ($va == '其他')
  12979. $p8 += $v ['price'];
  12980. $psum += $v ['price'];
  12981. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12982. $falg = false;
  12983. break;
  12984. }
  12985. }
  12986. }
  12987. if ($falg)
  12988. $html .= '<td class="taR">-</td>';
  12989. }
  12990. $p9 += $psum;
  12991. if (! empty ( $psum ))
  12992. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12993. else
  12994. $psum = '<td class="colGreen taR">-</td>';
  12995. $receiptL ['培训班费用'] = $psum . $html;
  12996. /* ------------------------------------- */
  12997. $html = "";
  12998. $psum = 0;
  12999. $item = array (
  13000. '公关费',
  13001. '广告费',
  13002. '借款',
  13003. '可自加费用'
  13004. );
  13005. foreach ( $item as $va ) {
  13006. $falg = true;
  13007. foreach ( $receiptCollectList as $v ) {
  13008. if ($v ['itemCategory'] == '其他') {
  13009. if ($v ['item'] == $va) {
  13010. if ($va == '公关费')
  13011. $t1 += $v ['price'];
  13012. if ($va == '广告费')
  13013. $t2 += $v ['price'];
  13014. if ($va == '借款')
  13015. $t3 += $v ['price'];
  13016. if ($va == '可自加费用')
  13017. $t4 += $v ['price'];
  13018. $psum += $v ['price'];
  13019. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13020. $falg = false;
  13021. break;
  13022. }
  13023. }
  13024. }
  13025. if ($falg)
  13026. $html .= '<td class="taR">-</td>';
  13027. }
  13028. $t5 += $psum;
  13029. if (! empty ( $psum ))
  13030. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13031. else
  13032. $psum = '<td class="colGreen taR">-</td>';
  13033. $receiptL ['其他'] = $psum . $html;
  13034. /* ------------------------------------- */
  13035. $html = "";
  13036. $psum = 0;
  13037. foreach ( $receiptCollectList as $v ) {
  13038. if ($v ['itemCategory'] == '报销金额调整') {
  13039. if (! empty ( $v ['price'] )) {
  13040. $psum += $v ['price'];
  13041. }
  13042. }
  13043. }
  13044. $s1 += $psum;
  13045. if (! empty ( $psum ))
  13046. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13047. else
  13048. $psum = '<td class="taR colOrange">-</td>';
  13049. $receiptL ['报销金额调整'] = $psum . $html;
  13050. } else {
  13051. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13052. <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>';
  13053. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13054. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13055. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13056. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13057. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13058. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13059. }
  13060. $monthStaffPrice = $receiptDetail->find ( array (
  13061. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13062. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13063. 'asArray' => true
  13064. ) );
  13065. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13066. $m1 += $monthStaffPrice [0] ['price'];
  13067. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13068. } else
  13069. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13070. $list [$value ['username']] = $receiptL;
  13071. }
  13072. }
  13073. $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>
  13074. <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>
  13075. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13076. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13077. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13078. $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>
  13079. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13080. $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>';
  13081. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13082. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13083. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13084. }
  13085. $data ['list'] = $list;
  13086. $receiptCollectList = $receiptDetail->find ( array (
  13087. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13088. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13089. 'groupby' => 'item,Month(date),itemCategory',
  13090. 'asArray' => true
  13091. ) );
  13092. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13093. // statistics html
  13094. $stList = $statistics->getOne ( array (
  13095. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13096. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13097. 'groupby' => 'Month(date)',
  13098. 'asArray' => true
  13099. ) );
  13100. if (empty ( $stList ))
  13101. $stList = array (
  13102. 'rePrice' => 0,
  13103. 'agPrice' => 0
  13104. );
  13105. $data ['stList'] = array (
  13106. 'rePrice' => $stList ['rePrice'],
  13107. 'agPrice' => $stList ['agPrice'],
  13108. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13109. );
  13110. $monthHtml = "";
  13111. for($i = 1; $i <= 12; $i ++) {
  13112. if ($i == $month)
  13113. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13114. else
  13115. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13116. }
  13117. $data ['monthHtml'] = $monthHtml;
  13118. $data ['year'] = $year;
  13119. $data ['month'] = $month;
  13120. $data ['memu'] = "receipt";
  13121. $data ['staff'] = $this->staff;
  13122. $data ['receiptMemu'] = 'companyCategoryCollect';
  13123. $data ['verifyId'] = $this->verifyId;
  13124. $data ['executeId'] = $this->executeId;
  13125. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13126. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13127. }
  13128. /**
  13129. * 用户报销单列表
  13130. */
  13131. function receiptStatisticsStaffDetail() {
  13132. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13133. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13134. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13135. Doo::loadModel ( "receipt" );
  13136. $receipt = new receipt ();
  13137. Doo::loadModel ( "receiptDetail" );
  13138. $receiptDetail = new receiptDetail ();
  13139. Doo::loadModel ( 'staff' );
  13140. $staff = new staff ();
  13141. Doo::loadModel ( 'accountItem' );
  13142. $accountItem = new accountItem ();
  13143. Doo::loadModel ( 'statistics' );
  13144. $statistics = new statistics ();
  13145. if (! empty ( $username )) {
  13146. $username = addslashes ( urldecode ( $username ) );
  13147. $staffDetail = $staff->getStaffByName ( $username );
  13148. if (empty ( $staffDetail ))
  13149. die ( 'illegal request' );
  13150. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13151. $itemList = $accountItem->getAccountItem ();
  13152. $itemHtml = '';
  13153. $categoryHtml = '';
  13154. $itemKeyList = array_keys ( $itemList );
  13155. $revisePrice = 0;
  13156. // 报销单内容详情
  13157. foreach ( $list as $key => $value ) {
  13158. $accountItemList = json_decode ( $value ['accountItem'], true );
  13159. $list [$key] ['accountItemList'] = $accountItemList;
  13160. $receiptItemHtml = '';
  13161. foreach ( $itemKeyList as $v ) {
  13162. if ($v == '日常相关费用')
  13163. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13164. elseif ($v == '差旅相关费用')
  13165. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13166. elseif ($v == '培训班费用')
  13167. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13168. elseif ($v == '内部培训费用'){
  13169. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13170. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13171. }else{
  13172. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13173. }
  13174. }elseif ($v == '其他')
  13175. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13176. foreach ( $itemList [$v] as $ke => $va ) {
  13177. $falg = true;
  13178. if (! empty ( $accountItemList [$v] )) {
  13179. foreach ( $accountItemList [$v] as $ve ) {
  13180. if ($va ['name'] == $ve ['name']) {
  13181. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13182. $falg = false;
  13183. break;
  13184. }
  13185. }
  13186. }
  13187. if ($falg)
  13188. $receiptItemHtml .= '<td class="taR"></td>';
  13189. }
  13190. }
  13191. // 金额调整和费用查看
  13192. $revisePrice += $value ['revisePrice'];
  13193. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13194. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13195. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13196. }
  13197. // 报销单合计
  13198. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13199. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13200. $receiptTotalHtml = '';
  13201. // 报销单项目抬头
  13202. foreach ( $itemKeyList as $value ) {
  13203. $count = count ( $itemList [$value] ) + 1;
  13204. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13205. $categoryHtml .= '<th class="taC">合计</th>';
  13206. $sumfalg=true;
  13207. foreach ( $rtl as $rtlValue ) {
  13208. if ($rtlValue ['itemCategory'] == $value) {
  13209. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13210. $sumfalg=false;
  13211. break;
  13212. }
  13213. }
  13214. if ($sumfalg)
  13215. $receiptTotalHtml .= '<th></th>';
  13216. foreach ( $itemList [$value] as $k => $v ) {
  13217. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13218. // 合计
  13219. $falg = true;
  13220. foreach ( $receiptTotalList as $ve ) {
  13221. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13222. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13223. $falg = false;
  13224. break;
  13225. }
  13226. }
  13227. if ($falg)
  13228. $receiptTotalHtml .= '<th></th>';
  13229. }
  13230. }
  13231. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13232. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13233. if (empty ( $stList ))
  13234. $stList = array (
  13235. 'rePrice' => 0,
  13236. 'agPrice' => 0
  13237. );
  13238. $data ['stList'] = array (
  13239. 'rePrice' => $stList ['rePrice'],
  13240. 'agPrice' => $stList ['agPrice'],
  13241. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13242. );
  13243. $monthHtml = "";
  13244. for($i = 1; $i <= 12; $i ++) {
  13245. if ($i == $month)
  13246. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13247. else
  13248. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13249. }
  13250. $data ['username'] = urlencode ( $username );
  13251. $data ['usernameEN'] = $username;
  13252. $data ['monthHtml'] = $monthHtml;
  13253. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13254. $data ['list'] = $list;
  13255. $data ['categoryHtml'] = $categoryHtml;
  13256. $data ['itemHtml'] = $itemHtml;
  13257. $data ['itemList'] = $itemList;
  13258. $data ['year'] = $year;
  13259. $data ['month'] = $month;
  13260. $data ['memu'] = "receipt";
  13261. $data ['staff'] = $this->staff;
  13262. $data ['receiptMemu'] = 'companyCategoryCollect';
  13263. $data ['verifyId'] = $this->verifyId;
  13264. $data ['executeId'] = $this->executeId;
  13265. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13266. }
  13267. die ( 'illegal request' );
  13268. }
  13269. function companyMonthCollectDetail() {
  13270. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13271. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13272. if (! $year)
  13273. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13274. if (! $month)
  13275. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13276. Doo::loadModel ( 'staff' );
  13277. $staff = new staff ();
  13278. Doo::loadModel ( "receiptDetail" );
  13279. $receiptDetail = new receiptDetail ();
  13280. Doo::loadModel ( 'accountItem' );
  13281. $accountItem = new accountItem ();
  13282. Doo::loadModel ( 'statistics' );
  13283. $statistics = new statistics ();
  13284. Doo::loadModel ( 'L_category' );
  13285. $lCategory = new L_category ();
  13286. $staffList = $staff->find ( array (
  13287. 'where' => 'username!="admin"',
  13288. 'asArray' => true
  13289. ) );
  13290. $categoryList = $lCategory->find ( array (
  13291. 'asArray' => true
  13292. ) );
  13293. $aiList=$accountItem->getAccountItem();
  13294. $list = array ();
  13295. foreach ( $categoryList as $value ) {
  13296. $receiptCollectList = $receiptDetail->find ( array (
  13297. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13298. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13299. 'groupby' => 'item,Month(pastDate),itemCategory',
  13300. 'asArray' => true
  13301. ) );
  13302. if (! empty ( $receiptCollectList )) {
  13303. $receiptL = array (
  13304. '日常相关费用' => array (),
  13305. '差旅相关费用' => array (),
  13306. '内部培训费用' => array (),
  13307. '培训班费用' => array (),
  13308. '其他' => array ()
  13309. );
  13310. $html = "";
  13311. $psum = 0;
  13312. foreach ( $aiList[$this->AGENCY] as $va ) {
  13313. $falg = true;
  13314. foreach ( $receiptCollectList as $v ) {
  13315. if ($v ['itemCategory'] == $this->AGENCY) {
  13316. if ($v ['item'] == $va['name']) {
  13317. $psum += $v ['price'];
  13318. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13319. $falg = false;
  13320. break;
  13321. }
  13322. }
  13323. }
  13324. if ($falg)
  13325. $html .= '<td class="taR">-</td>';
  13326. }
  13327. if (! empty ( $psum ))
  13328. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13329. else
  13330. $psum = '<td class="colGreen taR">-</td>';
  13331. $receiptL [$this->AGENCY] = $psum . $html;
  13332. /* ----------------------------------- */
  13333. $html = "";
  13334. $psum = 0;
  13335. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13336. $falg = true;
  13337. foreach ( $receiptCollectList as $v ) {
  13338. if ($v ['itemCategory'] == $this->TRAVEL) {
  13339. if ($v ['item'] == $va['name']) {
  13340. $psum += $v ['price'];
  13341. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13342. $falg = false;
  13343. break;
  13344. }
  13345. }
  13346. }
  13347. if ($falg)
  13348. $html .= '<td class="taR">-</td>';
  13349. }
  13350. if (! empty ( $psum ))
  13351. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13352. else
  13353. $psum = '<td class="colGreen taR">-</td>';
  13354. $receiptL [$this->TRAVEL] = $psum . $html;
  13355. /* ------------------------------------- */
  13356. $html = "";
  13357. $psum = 0;
  13358. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13359. $falg = true;
  13360. foreach ( $receiptCollectList as $v ) {
  13361. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13362. if ($v ['item'] == $va['name']) {
  13363. $psum += $v ['price'];
  13364. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13365. $falg = false;
  13366. break;
  13367. }
  13368. }
  13369. }
  13370. if ($falg)
  13371. $html .= '<td class="taR">-</td>';
  13372. }
  13373. if (! empty ( $psum ))
  13374. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13375. else
  13376. $psum = '<td class="colGreen taR">-</td>';
  13377. $receiptL [$this->INTTRAIN] = $psum . $html;
  13378. /* ------------------------------------- */
  13379. $html = "";
  13380. $psum = 0;
  13381. foreach ( $aiList[$this->TRAIN] as $va ) {
  13382. $falg = true;
  13383. foreach ( $receiptCollectList as $v ) {
  13384. if ($v ['itemCategory'] == $this->TRAIN) {
  13385. if ($v ['item'] == $va['name']) {
  13386. $psum += $v ['price'];
  13387. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13388. $falg = false;
  13389. break;
  13390. }
  13391. }
  13392. }
  13393. if ($falg)
  13394. $html .= '<td class="taR">-</td>';
  13395. }
  13396. if (! empty ( $psum ))
  13397. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13398. else
  13399. $psum = '<td class="colGreen taR">-</td>';
  13400. $receiptL [$this->TRAIN] = $psum . $html;
  13401. /* ------------------------------------- */
  13402. $html = "";
  13403. $psum = 0;
  13404. foreach ( $aiList[$this->OTHER] as $va ) {
  13405. $falg = true;
  13406. foreach ( $receiptCollectList as $v ) {
  13407. if ($v ['itemCategory'] == $this->OTHER) {
  13408. if ($v ['item'] == $va['name']) {
  13409. $psum += $v ['price'];
  13410. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13411. $falg = false;
  13412. break;
  13413. }
  13414. }
  13415. }
  13416. if ($falg)
  13417. $html .= '<td class="taR">-</td>';
  13418. }
  13419. if (! empty ( $psum ))
  13420. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13421. else
  13422. $psum = '<td class="colGreen taR">-</td>';
  13423. $receiptL [$this->OTHER] = $psum . $html;
  13424. /* ------------------------------------- */
  13425. $html = "";
  13426. $psum = 0;
  13427. foreach ( $receiptCollectList as $v ) {
  13428. if ($v ['itemCategory'] == '报销金额调整') {
  13429. if (! empty ( $v ['price'] ))
  13430. $psum += $v ['price'];
  13431. }
  13432. }
  13433. if (! empty ( $psum ))
  13434. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13435. else
  13436. $psum = '<td class="taR colOrange">-</td>';
  13437. $receiptL ['报销金额调整'] = $psum . $html;
  13438. } else {
  13439. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13440. foreach ( $aiList[$this->AGENCY] as $va ) {
  13441. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13442. }
  13443. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13444. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13445. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13446. }
  13447. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13448. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13449. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13450. }
  13451. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13452. foreach ( $aiList[$this->TRAIN] as $va ) {
  13453. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13454. }
  13455. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13456. foreach ( $aiList[$this->OTHER] as $va ) {
  13457. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13458. }
  13459. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13460. }
  13461. $monthStaffPrice = $receiptDetail->find ( array (
  13462. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13463. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13464. 'asArray' => true
  13465. ) );
  13466. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13467. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13468. else
  13469. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13470. $list [$value ['title']] = $receiptL;
  13471. }
  13472. $data ['list'] = $list;
  13473. $receiptCollectList = $receiptDetail->find ( array (
  13474. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13475. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13476. 'groupby' => 'item,Month(pastDate),itemCategory',
  13477. 'asArray' => true
  13478. ) );
  13479. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13480. //print_r($data['monthPriceHtml']);
  13481. // foreach ($data['monthPriceHtml'] as $value){
  13482. // echo $value;
  13483. // }
  13484. // die;
  13485. // statistics html
  13486. $stList = $statistics->getOne ( array (
  13487. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13488. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13489. 'groupby' => 'Month(date)',
  13490. 'asArray' => true
  13491. ) );
  13492. if (empty ( $stList ))
  13493. $stList = array (
  13494. 'rePrice' => 0,
  13495. 'agPrice' => 0
  13496. );
  13497. $data ['stList'] = array (
  13498. 'rePrice' => $stList ['rePrice'],
  13499. 'agPrice' => $stList ['agPrice'],
  13500. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13501. );
  13502. $monthHtml = "";
  13503. for($i = 1; $i <= 12; $i ++) {
  13504. if ($i == $month)
  13505. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13506. else
  13507. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13508. }
  13509. $data ['aiList'] = $aiList;
  13510. $dateHtml = "";
  13511. $now = date ( "Y" );
  13512. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13513. if ($YEARD <= $now) {
  13514. $dateHtml .= '<option ';
  13515. if ($year == $YEARD) {
  13516. $dateHtml .= 'selected ';
  13517. }
  13518. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13519. }
  13520. }
  13521. $data ['dateHtml'] = $dateHtml;
  13522. $data ['monthHtml'] = $monthHtml;
  13523. $data ['year'] = $year;
  13524. $data ['month'] = $month;
  13525. $data ['memu'] = "receipt";
  13526. $data ['staff'] = $this->staff;
  13527. $data ['receiptMemu'] = 'companyCategoryCollect';
  13528. $data ['verifyId'] = $this->verifyId;
  13529. $data ['executeId'] = $this->executeId;
  13530. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13531. }
  13532. function staffCollectDetail() {
  13533. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13534. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13535. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13536. if (! $staffname) {
  13537. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13538. $staffname = urldecode ( $staffname );
  13539. }
  13540. Doo::loadModel ( 'staff' );
  13541. $staff = new staff ();
  13542. Doo::loadModel ( "receiptDetail" );
  13543. $receiptDetail = new receiptDetail ();
  13544. Doo::loadModel ( 'accountItem' );
  13545. $accountItem = new accountItem ();
  13546. Doo::loadModel ( 'statistics' );
  13547. $statistics = new statistics ();
  13548. Doo::loadModel ( 'L_category' );
  13549. $lCategory = new L_category ();
  13550. Doo::loadModel ( "receiptAuthorityManage" );
  13551. $receiptAuthorityManage = new receiptAuthorityManage ();
  13552. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13553. $cidList = array ();
  13554. foreach ( $imcStaff as $key => $value ) {
  13555. array_push ( $cidList, $value ['cid'] );
  13556. }
  13557. $cidString = implode ( ',', $cidList );
  13558. $staffList = $staff->find ( array (
  13559. 'where' => ' cid in (' . $cidString . ')',
  13560. 'asArray' => true
  13561. ) );
  13562. $stHtml = '';
  13563. $stTitle = "";
  13564. $staffId = 0;
  13565. $cid = 0;
  13566. $ocid = 0;
  13567. foreach ( $staffList as $value ) {
  13568. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13569. $stTitle = $value ['category'] . '-' . $value ['username'];
  13570. $staffId = $value ['sid'];
  13571. $cid = $value ['cid'];
  13572. $ocid = $value ['cid'];
  13573. if (! empty ( $value ['othercid'] ))
  13574. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13575. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13576. } elseif ($value ['username'] != 'admin')
  13577. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13578. }
  13579. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13580. 'where' => 'cid in(' . $cid . ')',
  13581. 'asArray' => true
  13582. ) );
  13583. if (empty ( $pcid ))
  13584. $pcid = $ocid;
  13585. $data ['ocid'] = $pcid;
  13586. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13587. $this->showCache ( $path );
  13588. //
  13589. $receiptCollectList = $receiptDetail->find ( array (
  13590. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13591. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13592. 'groupby' => 'item,Month(pastDate),itemCategory',
  13593. 'asArray' => true
  13594. ) );
  13595. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13596. // print_r($receiptCollectList);
  13597. $accountList = $accountItem->find ( array (
  13598. 'asArray' => true
  13599. ) );
  13600. // create CollectDetail HTML
  13601. $collectHtml = array ();
  13602. foreach ( $accountList as $key => $value ) {
  13603. $html = "";
  13604. $asum = 0;
  13605. for($i = 1; $i <= 12; $i ++) {
  13606. $falg = true;
  13607. foreach ( $receiptCollectList as $v ) {
  13608. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13609. if ($v ['item'] == '可自加费用') {
  13610. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13611. }
  13612. $asum += $v ['price'];
  13613. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13614. $falg = false;
  13615. break;
  13616. }
  13617. }
  13618. if ($falg)
  13619. $html .= '<td class="taR">-</td>';
  13620. }
  13621. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13622. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13623. }
  13624. $data ['collectHtml'] = $collectHtml;
  13625. // print_r($collectHtml);
  13626. // create Adjustment price html
  13627. $receiptCollectList = $receiptDetail->find ( array (
  13628. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13629. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13630. 'groupby' => 'itemCategory,Month(pastDate)',
  13631. 'asArray' => true
  13632. ) );
  13633. $adjustment = array ();
  13634. $collectArray = array (
  13635. '日常相关费用' => array (),
  13636. '差旅相关费用' => array (),
  13637. '培训班费用' => array (),
  13638. '内部培训费用'=>array(),
  13639. '其他' => array ()
  13640. );
  13641. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13642. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13643. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13644. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13645. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13646. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13647. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13648. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13649. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13650. array_push ( $collectArray ['其他'], $collectHtml );
  13651. $data ['collectArray'] = $collectArray;
  13652. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13653. array_push ( $adjustment, $collectHtml );
  13654. $data ['adjustment'] = $adjustment;
  13655. // total price html
  13656. $collectHtml = "";
  13657. $total = 0;
  13658. for($i = 1; $i <= 12; $i ++) {
  13659. $sumPrice = 0;
  13660. foreach ( $receiptCollectList as $key => $value ) {
  13661. if ($value ['month'] == $i) {
  13662. $sumPrice += $value ['price'];
  13663. }
  13664. }
  13665. if ($sumPrice == 0)
  13666. $collectHtml .= '<td class="taR">-</td>';
  13667. else
  13668. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13669. $total += $sumPrice;
  13670. }
  13671. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13672. // statistics html
  13673. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13674. if (empty ( $stList ))
  13675. $stList = array (
  13676. 'rePrice' => 0,
  13677. 'agPrice' => 0
  13678. );
  13679. $data ['stList'] = array (
  13680. 'rePrice' => $stList ['rePrice'],
  13681. 'agPrice' => $stList ['agPrice'],
  13682. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13683. );
  13684. $data ['totalPrice'] = $collectHtml;
  13685. $data ['totalYear'] = $total;
  13686. $data ['stHtml'] = $stHtml;
  13687. $data ['year'] = $year;
  13688. $data ['stTitle'] = $stTitle;
  13689. $data ['staffname'] = urlencode ( $staffname );
  13690. $data ['memu'] = "receipt";
  13691. $data ['staff'] = $this->staff;
  13692. $data ['receiptMemu'] = 'companyCategoryCollect';
  13693. $data ['verifyId'] = $this->verifyId;
  13694. $data ['executeId'] = $this->executeId;
  13695. if ($year < date ( "Y" )) {
  13696. Doo::loadModel ( 'receipt' );
  13697. $receipt = new receipt ();
  13698. $receiptList = $receipt->find ( array (
  13699. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13700. 'asArray' => true
  13701. ) );
  13702. if (empty ( $receiptList )) { // generated files
  13703. ob_start ();
  13704. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13705. $this->cacheFile ( $path );
  13706. die ();
  13707. }
  13708. }
  13709. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13710. }
  13711. function BUGFLAG() {
  13712. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13713. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13714. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13715. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13716. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13717. if (empty ( $status ))
  13718. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13719. $page_size = 12;
  13720. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13721. $vidList = array ();
  13722. $button = 0;
  13723. Doo::loadModel ( 'verify' );
  13724. $verify = new verify ();
  13725. Doo::loadModel ( 'receipt' );
  13726. $receipt = new receipt ();
  13727. Doo::loadModel ( 'staff' );
  13728. $staff = new staff ();
  13729. Doo::loadModel ( 'L_category' );
  13730. $Lcategory = new L_category ();
  13731. $dateCondition = " and Year(date) =" . $year;
  13732. if (! empty ( $month ))
  13733. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13734. $categoryList = $Lcategory->find ( array (
  13735. 'asArray' => true
  13736. ) );
  13737. $staffList = $staff->find ( array (
  13738. 'where' => 'cid=' . $cid,
  13739. 'asArray' => true
  13740. ) );
  13741. $cateCondition = "";
  13742. $staffCondition = "";
  13743. $approvalCondition = "";
  13744. if (! empty ( $cid ))
  13745. $cateCondition = ' and cid=' . $cid;
  13746. if (! empty ( $sid )) {
  13747. $staffCondition = ' and staff=' . $sid;
  13748. $cateCondition = "";
  13749. }
  13750. $approvalCondition = " and status=" . $status;
  13751. if ($status == 2) {
  13752. // 查找角色审批人
  13753. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13754. }
  13755. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13756. $approvalCondition = ' and status=2 ';
  13757. }
  13758. if ($status == 1) {
  13759. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13760. }
  13761. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13762. $pageinfo ['page'] = array (
  13763. 'previous' => ''
  13764. );
  13765. if ($status == 0) {
  13766. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13767. $receiptList = $receipt->find ( array (
  13768. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13769. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13770. 'desc' => 'rid',
  13771. 'asArray' => true
  13772. ) );
  13773. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13774. } else
  13775. $receiptList = $receipt->find ( array (
  13776. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13777. 'desc' => 'rid',
  13778. 'asArray' => true
  13779. ) );
  13780. $rLRes = $receipt->find ( array (
  13781. '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,
  13782. 'desc' => 'rid',
  13783. 'asArray' => true
  13784. ) );
  13785. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13786. // print_r($pageinfo);
  13787. $Locate = 0;
  13788. foreach ( $receiptList as $key => $value ) {
  13789. $receiptList [$key] ['Locate'] = $Locate;
  13790. $Locate ++;
  13791. $receiptList [$key] ['reviseDetail'] = array ();
  13792. if (! empty ( $value ['reviseDetail'] ))
  13793. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13794. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13795. $categoryDetil = $Lcategory->getOne ( array (
  13796. 'where' => 'cid=' . $value ['cid'],
  13797. 'asArray' => true
  13798. ) );
  13799. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13800. $verifyList = $verify->getOne ( array (
  13801. 'where' => 'vid=' . $value ['verify'],
  13802. 'asArray' => true
  13803. ) );
  13804. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13805. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13806. foreach ( $verifyList as $k => $v ) {
  13807. // init verifyStaff
  13808. $verifyList [$k] ['date'] = "";
  13809. $verifyList [$k] ['opinion'] = "";
  13810. $verifyList [$k] ['status'] = "";
  13811. if (empty ( $verifyStaff )) {
  13812. $verifyList [$k] ['date'] = "";
  13813. $verifyList [$k] ['opinion'] = "";
  13814. if ($v [0] == $this->staff [0] ['sid']) {
  13815. $verifyList [$k] ['status'] = 4;
  13816. $button = 4;
  13817. }
  13818. } else {
  13819. $flag = true;
  13820. foreach ( $verifyStaff as $m => $u ) {
  13821. if ($v [0] == $m) {
  13822. $verifyList [$k] ['date'] = $u ['date'];
  13823. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13824. $verifyList [$k] ['status'] = $u ['status'];
  13825. $flag = false;
  13826. break;
  13827. }
  13828. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13829. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13830. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13831. }
  13832. if ($flag) { // 检测可编辑
  13833. if ($v [0] == $this->staff [0] ['sid']) {
  13834. $verifyList [$k] ['status'] = 4;
  13835. $button = 4;
  13836. }
  13837. }
  13838. }
  13839. }
  13840. $receiptList [$key] ['verifyList'] = $verifyList;
  13841. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13842. 'where' => 'sid=' . $value ['staff'],
  13843. 'asArray' => true
  13844. ) );
  13845. $receiptList [$key] ['button'] = $button;
  13846. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13847. }
  13848. // print_r($receiptList);die;
  13849. // $data['verifyDetail']=$verifyDetail;
  13850. $mothHtml = "";
  13851. for($i = 1; $i <= 12; $i ++) {
  13852. if ($month == $i)
  13853. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13854. else
  13855. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13856. }
  13857. $data ['mothHtml'] = $mothHtml;
  13858. $data ['page'] = $pageinfo;
  13859. $data ['receiptList'] = $receiptList;
  13860. $data ['receiptApprovalCount'] = count ( $rLRes );
  13861. $data ['status'] = $status;
  13862. $data ['year'] = $year;
  13863. $data ['categoryList'] = $categoryList;
  13864. $data ['staffList'] = $staffList;
  13865. $data ['cid'] = $cid;
  13866. $data ['sid'] = $sid;
  13867. // print_r($receiptList);
  13868. $data ['memu'] = "receipt";
  13869. $data ['staff'] = $this->staff;
  13870. $data ['receiptMemu'] = 'approvalExpenses';
  13871. $data ['verifyId'] = $this->verifyId;
  13872. $data ['executeId'] = $this->executeId;
  13873. $this->render ( "/admin/FALG", $data );
  13874. }
  13875. function ajaxGetReceiptOrder() {
  13876. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13877. if (! empty ( $receiptOrder )) {
  13878. Doo::loadModel ( 'receipt' );
  13879. $receipt = new receipt ();
  13880. Doo::loadModel ( 'staff' );
  13881. $staff = new staff ();
  13882. $receiptInfo = $receipt->getOne ( array (
  13883. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13884. 'asArray' => true
  13885. ) );
  13886. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13887. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13888. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13889. </tbody></table><table class="table table table-bordered"><tbody>';
  13890. foreach ( $verifyStaff as $key => $value ) {
  13891. $staffInfo = $staff->getOne ( array (
  13892. 'select' => 'username',
  13893. 'where' => ' sid="' . $key . '"',
  13894. 'asArray' => true
  13895. ) );
  13896. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13897. }
  13898. $html .= '</tbody></table></div></div>';
  13899. echo json_encode ( array (
  13900. 'status' => 1,
  13901. 'receiptHtml' => $html
  13902. ) );
  13903. die ();
  13904. }
  13905. echo json_encode ( array (
  13906. 'status' => 2,
  13907. 'receiptHtml' => ''
  13908. ) );
  13909. die ();
  13910. }
  13911. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13912. if (! empty ( $receiptCollectList )) {
  13913. $receiptL = array (
  13914. '日常相关费用' => array (),
  13915. '差旅相关费用' => array (),
  13916. '内部培训费用'=>array(),
  13917. '培训班费用' => array (),
  13918. '其他' => array ()
  13919. );
  13920. $html = "";
  13921. $psum = 0;
  13922. foreach ( $aiList[$this->AGENCY] as $value ) {
  13923. $falg = true;
  13924. foreach ( $receiptCollectList as $v ) {
  13925. if ($v ['itemCategory'] == '日常相关费用') {
  13926. if ($v ['item'] == $value['name']) {
  13927. $psum += $v ['price'];
  13928. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13929. $falg = false;
  13930. break;
  13931. }
  13932. }
  13933. }
  13934. if ($falg)
  13935. $html .= '<td class="taR">-</td>';
  13936. }
  13937. if (! empty ( $psum ))
  13938. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13939. else
  13940. $psum = '<td class="colGreen taR">-</td>';
  13941. $receiptL ['日常相关费用'] = $psum . $html;
  13942. /* ----------------------------------- */
  13943. $html = "";
  13944. $psum = 0;
  13945. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13946. $falg = true;
  13947. foreach ( $receiptCollectList as $v ) {
  13948. if ($v ['itemCategory'] == '差旅相关费用') {
  13949. if ($v ['item'] == $value['name']) {
  13950. $psum += $v ['price'];
  13951. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13952. $falg = false;
  13953. break;
  13954. }
  13955. }
  13956. }
  13957. if ($falg)
  13958. $html .= '<td class="taR">-</td>';
  13959. }
  13960. if (! empty ( $psum ))
  13961. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13962. else
  13963. $psum = '<td class="colGreen taR">-</td>';
  13964. $receiptL ['差旅相关费用'] = $psum . $html;
  13965. /* ----------------------------------- */
  13966. $html = "";
  13967. $psum = 0;
  13968. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13969. $falg = true;
  13970. foreach ( $receiptCollectList as $v ) {
  13971. if ($v ['itemCategory'] == '内部培训费用') {
  13972. if ($v ['item'] == $value['name']) {
  13973. $psum += $v ['price'];
  13974. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13975. $falg = false;
  13976. break;
  13977. }
  13978. }
  13979. }
  13980. if ($falg)
  13981. $html .= '<td class="taR">-</td>';
  13982. }
  13983. if (! empty ( $psum ))
  13984. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13985. else
  13986. $psum = '<td class="colGreen taR">-</td>';
  13987. $receiptL ['内部培训费用'] = $psum . $html;
  13988. /* ------------------------------------- */
  13989. $html = "";
  13990. $psum = 0;
  13991. foreach ( $aiList[$this->TRAIN] as $value ) {
  13992. $falg = true;
  13993. foreach ( $receiptCollectList as $v ) {
  13994. if ($v ['itemCategory'] == '培训班费用') {
  13995. if ($v ['item'] == $value['name']) {
  13996. $psum += $v ['price'];
  13997. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13998. $falg = false;
  13999. break;
  14000. }
  14001. }
  14002. }
  14003. if ($falg)
  14004. $html .= '<td class="taR">-</td>';
  14005. }
  14006. if (! empty ( $psum ))
  14007. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14008. else
  14009. $psum = '<td class="colGreen taR">-</td>';
  14010. $receiptL ['培训班费用'] = $psum . $html;
  14011. /* ------------------------------------- */
  14012. $html = "";
  14013. $psum = 0;
  14014. foreach ( $aiList[$this->OTHER] as $value ) {
  14015. $falg = true;
  14016. foreach ( $receiptCollectList as $v ) {
  14017. if ($v ['itemCategory'] == '其他') {
  14018. if ($v ['item'] == $value['name']) {
  14019. $psum += $v ['price'];
  14020. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14021. $falg = false;
  14022. break;
  14023. }
  14024. }
  14025. }
  14026. if ($falg)
  14027. $html .= '<td class="taR">-</td>';
  14028. }
  14029. if (! empty ( $psum ))
  14030. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14031. else
  14032. $psum = '<td class="colGreen taR">-</td>';
  14033. $receiptL ['其他'] = $psum . $html;
  14034. /* ------------------------------------- */
  14035. $html = "";
  14036. $psum = 0;
  14037. foreach ( $receiptCollectList as $v ) {
  14038. if ($v ['itemCategory'] == '报销金额调整') {
  14039. if (! empty ( $v ['price'] ))
  14040. $psum += $v ['price'];
  14041. }
  14042. }
  14043. if (! empty ( $psum ))
  14044. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14045. else
  14046. $psum = '<td class="taR colOrange">-</td>';
  14047. $receiptL ['报销金额调整'] = $psum . $html;
  14048. } else {
  14049. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14050. foreach ( $aiList[$this->AGENCY] as $va ) {
  14051. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14052. }
  14053. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14054. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14055. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14056. }
  14057. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14058. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14059. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14060. }
  14061. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14062. foreach ( $aiList[$this->TRAIN] as $va ) {
  14063. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14064. }
  14065. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14066. foreach ( $aiList[$this->OTHER] as $va ) {
  14067. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14068. }
  14069. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14070. }
  14071. return $receiptL;
  14072. }
  14073. function eMail() {
  14074. Doo::loadModel ( 'staff' );
  14075. $staff = new staff ();
  14076. Doo::loadModel ( 'receipt' );
  14077. $receipt = new receipt ();
  14078. Doo::loadModel ( 'L_category' );
  14079. $Lcategory = new L_category ();
  14080. Doo::loadModel ( "verify" );
  14081. $verify = new verify ();
  14082. $staffList = $staff->find ( array (
  14083. 'asArray' => true
  14084. ) );
  14085. foreach ( $staffList as $key => $value ) {
  14086. if ($value ['username'] != 'admin') {
  14087. // 提交人
  14088. $receiptList = $receipt->find ( array (
  14089. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14090. 'asArray' => true
  14091. ) );
  14092. if (! empty ( $receiptList )) {
  14093. $html = '<br><div><style></style>
  14094. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14095. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14096. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14097. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14098. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14099. <tbody><tr>
  14100. <td style="padding: 0 40px;" align="left">
  14101. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14102. </td></tr><tr>
  14103. <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>
  14104. </tr>
  14105. </tbody> </table></td> </tr> <tr><td>
  14106. <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">
  14107. <tbody> <tr><td>
  14108. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14109. 以下报销单完成了审批,等着收款吧:</p>
  14110. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14111. foreach ( $receiptList as $k => $v ) {
  14112. $category = $Lcategory->getOne ( array (
  14113. 'where' => 'cid=' . $v ['cid'],
  14114. 'asArray' => true
  14115. ) );
  14116. $html .= '
  14117. <tr>
  14118. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14119. <td align="left">
  14120. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14121. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14122. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14123. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14124. </tr>';
  14125. }
  14126. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14127. <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>
  14128. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14129. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14130. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14131. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14132. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14133. $receipt = new receipt ();
  14134. $receipt->notice = 1;
  14135. $receipt->update ( array (
  14136. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14137. ) );
  14138. }
  14139. }
  14140. // 审批人
  14141. $verifyList = $verify->find ( array (
  14142. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14143. 'asArray' => true
  14144. ) );
  14145. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14146. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14147. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14148. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14149. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14150. <tbody><tr><td style="padding: 0 40px;" align="left">
  14151. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14152. </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>
  14153. </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">
  14154. <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>
  14155. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14156. foreach ( $verifyList as $k => $v ) {
  14157. $receiptList = $receipt->find ( array (
  14158. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14159. 'asArray' => true
  14160. ) );
  14161. foreach ( $receiptList as $r => $l ) {
  14162. $category = $Lcategory->getOne ( array (
  14163. 'where' => 'cid=' . $l ['cid'],
  14164. 'asArray' => true
  14165. ) );
  14166. $staffDetile = $staff->getOne ( array (
  14167. 'where' => 'sid=' . $l ['staff'],
  14168. 'asArray' => true
  14169. ) );
  14170. $html .= '
  14171. <tr>
  14172. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14173. <td align="left">
  14174. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14175. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14176. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14177. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14178. </tr>';
  14179. }
  14180. }
  14181. $html .= '
  14182. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14183. <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>
  14184. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14185. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14186. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14187. // $receipt=new receipt();
  14188. // $receipt->notice=1;
  14189. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14190. }
  14191. }
  14192. }
  14193. }
  14194. function setWXMsg($rid, $type) {
  14195. Doo::loadModel ( "receipt" );
  14196. $receipt = new receipt ();
  14197. $receiptDetail = $receipt->getOne ( array (
  14198. 'where' => 'rid=' . $rid,
  14199. 'asArray' => true
  14200. ) );
  14201. if (! empty ( $receiptDetail )) {
  14202. Doo::loadModel ( 'staff' );
  14203. $staff = new staff ();
  14204. $staffmsg = $staff->getOne ( array (
  14205. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14206. 'asArray' => TRUE
  14207. ) );
  14208. if (! empty ( $staffmsg ['wxid'] )) {
  14209. require_once (SITE_PATH . '/protected/class/client.php');
  14210. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14211. $user = $staffmsg ['wxid'];
  14212. $receiptName = '';
  14213. $msg = '';
  14214. switch ($receiptDetail ['Rtype']) {
  14215. case 0 :
  14216. $receiptName = '报销';
  14217. break;
  14218. case 1 :
  14219. $receiptName = '借款';
  14220. break;
  14221. case 2 :
  14222. $receiptName = '对公汇款';
  14223. break;
  14224. }
  14225. switch ($type) {
  14226. case 1 :
  14227. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14228. break;
  14229. case 2 :
  14230. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14231. break;
  14232. case 3 :
  14233. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14234. break;
  14235. }
  14236. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14237. }
  14238. }
  14239. }
  14240. // Email发送函数
  14241. function SMail($toemail, $subject, $contents) {
  14242. Doo::loadClass ( 'class.phpmailer' );
  14243. $mail = new PHPMailer ();
  14244. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14245. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14246. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14247. $mail->Password = "cDO1GjtY1seH"; // 密码
  14248. $mail->CharSet = "UTF8";
  14249. $mail->SMTPAuth = true;
  14250. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14251. $mail->Mailer = "smtp";
  14252. $mail->Port = 25;
  14253. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14254. $mail->MsgHTML ( $contents );
  14255. $mail->AddAddress ( $toemail );
  14256. $mail->CharSet = "UTF-8";
  14257. return $mail->Send ();
  14258. }
  14259. function h5Upload() {
  14260. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14261. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14262. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14263. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14264. header ( "HTTP/1.1 500 Internal Server Error" );
  14265. echo "POST exceeded maximum allowed size.";
  14266. exit ( 0 );
  14267. }
  14268. // Settings
  14269. $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)
  14270. $upload_name = "Filedata";
  14271. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14272. $extension_whitelist = array (
  14273. "doc",
  14274. "txt",
  14275. "jpg",
  14276. "gif",
  14277. "png"
  14278. ); // Allowed file extensions
  14279. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14280. // Other variables
  14281. $MAX_FILENAME_LENGTH = 260;
  14282. $file_name = "";
  14283. $file_extension = "";
  14284. $uploadErrors = array (
  14285. 0 => "文件上传成功",
  14286. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14287. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14288. 3 => "上传的文件仅为部分文件",
  14289. 4 => "没有文件上传",
  14290. 6 => "缺少临时文件夹"
  14291. );
  14292. $nk = time ();
  14293. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14294. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14295. echo "文件无法保存.";
  14296. exit ( 0 );
  14297. }
  14298. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14299. echo json_encode ( array (
  14300. 'filename' => $file_name,
  14301. 'id' => $nk
  14302. ) );
  14303. exit ( 0 );
  14304. }
  14305. function swfupload() {
  14306. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14307. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14308. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14309. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14310. header ( "HTTP/1.1 500 Internal Server Error" );
  14311. echo "POST exceeded maximum allowed size.";
  14312. exit ( 0 );
  14313. }
  14314. // Settings
  14315. $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)
  14316. $upload_name = "Filedata";
  14317. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14318. $extension_whitelist = array (
  14319. "doc",
  14320. "txt",
  14321. "jpg",
  14322. "gif",
  14323. "png"
  14324. ); // Allowed file extensions
  14325. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14326. // Other variables
  14327. $MAX_FILENAME_LENGTH = 260;
  14328. $file_name = "";
  14329. $file_extension = "";
  14330. $uploadErrors = array (
  14331. 0 => "文件上传成功",
  14332. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14333. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14334. 3 => "上传的文件仅为部分文件",
  14335. 4 => "没有文件上传",
  14336. 6 => "缺少临时文件夹"
  14337. );
  14338. $nk = time ();
  14339. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14340. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14341. echo "文件无法保存.";
  14342. exit ( 0 );
  14343. }
  14344. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14345. echo json_encode ( array (
  14346. 'filename' => $file_name,
  14347. 'id' => $nk
  14348. ) );
  14349. exit ( 0 );
  14350. }
  14351. function _GetFileEXT($filename) {
  14352. $pics = explode ( '.', $filename );
  14353. $num = count ( $pics );
  14354. return $pics [$num - 1];
  14355. }
  14356. /**
  14357. * 获取get或者POST值
  14358. * @param string $name 属性名称
  14359. * @return fixed 值
  14360. */
  14361. function get_args($name) {
  14362. if (isset ( $_GET [$name] )) {
  14363. if (is_array ( $_GET [$name] ))
  14364. return $_GET [$name];
  14365. else
  14366. return addslashes ( $_GET [$name] );
  14367. } elseif (isset ( $_POST [$name] )) {
  14368. if (is_array ( $_POST [$name] ))
  14369. return $_POST [$name];
  14370. else
  14371. return addslashes ( $_POST [$name] );
  14372. } else
  14373. return false;
  14374. }
  14375. function num_to_rmb($num) {
  14376. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14377. $c2 = "分角元拾佰仟万拾佰仟亿";
  14378. // 精确到分后面就不要了,所以只留两个小数位
  14379. $num = round ( $num, 2 );
  14380. // 将数字转化为整数
  14381. $num = $num * 100;
  14382. if (strlen ( $num ) > 10) {
  14383. return "金额太大,请检查";
  14384. }
  14385. $i = 0;
  14386. $c = "";
  14387. while ( 1 ) {
  14388. if ($i == 0) {
  14389. // 获取最后一位数字
  14390. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14391. } else {
  14392. $n = $num % 10;
  14393. }
  14394. // 每次将最后一位数字转化为中文
  14395. $p1 = substr ( $c1, 3 * $n, 3 );
  14396. $p2 = substr ( $c2, 3 * $i, 3 );
  14397. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14398. $c = $p1 . $p2 . $c;
  14399. } else {
  14400. $c = $p1 . $c;
  14401. }
  14402. $i = $i + 1;
  14403. // 去掉数字最后一位了
  14404. $num = $num / 10;
  14405. // echo $num.'</br>';
  14406. $num = ( int ) $num;
  14407. // $num =floor($num);
  14408. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14409. // echo $num.'</br>';
  14410. // 结束循环
  14411. if ($num == 0) {
  14412. break;
  14413. }
  14414. }
  14415. // echo $c.'</br>';
  14416. $j = 0;
  14417. $slen = strlen ( $c );
  14418. while ( $j < $slen ) {
  14419. // utf8一个汉字相当3个字符
  14420. $m = substr ( $c, $j, 6 );
  14421. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14422. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14423. $left = substr ( $c, 0, $j );
  14424. $right = substr ( $c, $j + 3 );
  14425. $c = $left . $right;
  14426. $j = $j - 3;
  14427. $slen = $slen - 3;
  14428. }
  14429. $j = $j + 3;
  14430. }
  14431. // 这个是为了去掉类似23.0中最后一个“零”字
  14432. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14433. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14434. }
  14435. // 将处理的汉字加上“整”
  14436. if (empty ( $c )) {
  14437. return "零元整";
  14438. } else {
  14439. return $c . "整";
  14440. }
  14441. }
  14442. /**
  14443. * 获得分页数据
  14444. * @param unknown_type $table
  14445. * @param unknown_type $condition
  14446. * @param unknown_type $on_page
  14447. * @param unknown_type $page_size
  14448. */
  14449. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14450. $page_c = "";
  14451. $page ['previous'] = $this->get_previous ( $on_page );
  14452. $page ['on_page'] = $on_page;
  14453. $total_count = $this->get_table_count ( $table, $condition );
  14454. $total = intval ( $total_count / $page_size );
  14455. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14456. $page ['total_data'] = $total_count;
  14457. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14458. $i = 1;
  14459. $page_max = 1;
  14460. $page_width = 3;
  14461. if ($on_page >= $page_width) {
  14462. $page_max = intval ( $on_page / $page_width ) + 1;
  14463. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14464. }
  14465. for(; $i <= $page ['total_page']; $i ++) {
  14466. if ($i == $on_page)
  14467. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14468. else
  14469. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14470. if ($i == ($page_width * $page_max))
  14471. break;
  14472. }
  14473. $page ['page'] = $page_c;
  14474. $page ['lower'] = (-- $on_page) * $page_size;
  14475. return $page;
  14476. }
  14477. /**
  14478. * 获取总页数
  14479. * @param unknown_type $table
  14480. * @param unknown_type $condition
  14481. */
  14482. public function get_table_count($table = "", $condition = "") {
  14483. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14484. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14485. // echo $sql;die;
  14486. $query = Doo::db ()->query ( $sql );
  14487. $result = $query->fetch ();
  14488. return $result ['count'];
  14489. }
  14490. /**
  14491. * 获取上一页
  14492. * @param unknown_type $on_page
  14493. */
  14494. function get_previous($on_page = 1) {
  14495. return $on_page != 0 ? $on_page - 1 : $on_page;
  14496. }
  14497. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14498. // 收入合计
  14499. Doo::loadModel ( 'invoiceTraining' );
  14500. $invoiceTraining = new invoiceTraining ();
  14501. Doo::loadModel ( 'receipt' );
  14502. $receipt = new receipt ();
  14503. $invoiceTrainingDetail = array (
  14504. 'invoiceArriveAmount' => '0.00',
  14505. 'RIAmount' => '0.00',
  14506. 'invoiceTotalAmount' => '0.00',
  14507. 'invoiceCompanyAmount' => '0.00',
  14508. 'invoiceArriveAmountM'=>'0.00',
  14509. 'invoiceCompanyAmountM'=>'0.00'
  14510. );
  14511. if ($invoiceTrainId != 0) {
  14512. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14513. }
  14514. $invoiceArriveAmount = $RIAmount = 0;
  14515. if (! empty ( $invoiceTrainingDetail )) {
  14516. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14517. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14518. }
  14519. // 备用金
  14520. $sum = 0;
  14521. if (! empty ( $trainLoanRid )) {
  14522. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14523. foreach ($receiptLoanList as $key=>$value){
  14524. $sum+=$value['sum'];
  14525. }
  14526. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14527. // $sum = $receiptLoanDetailBak ['sum'];
  14528. }
  14529. // 支出项金额详情
  14530. // 项目金额合计
  14531. Doo::loadModel ( 'RItem' );
  14532. $RItem = new RItem ();
  14533. Doo::loadModel ( 'accountItem' );
  14534. $accountItem = new accountItem ();
  14535. // 讲师获得
  14536. Doo::loadModel ( 'RILecturer' );
  14537. $RILecturer = new RILecturer ();
  14538. $RItemList = $RItem->getRItemByRid ($rid );
  14539. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14540. // 支出项金额详情
  14541. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14542. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14543. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14544. return $payment;
  14545. }
  14546. }
  14547. ?>