ReceiptController.php 545 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641
  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. $total = $waste ['bank'] ['CGBDeposit'] + $waste ['bank'] ['ICBCDeposit'] + $waste ['bank'] ['HUADeposit'] + $waste ['bank'] ['PersonalDeposit'] + $waste ['financial'] ['current'] ['CGBDeposit'] + $waste ['financial'] ['current'] ['ICBCDeposit'] + $waste ['financial'] ['fixed'] ['CGBDeposit'] + $waste ['financial'] ['fixed'] ['ICBCDeposit'];
  11552. // print_r($waste);
  11553. $data ['waste'] = $waste;
  11554. $data ['total'] = $total;
  11555. // 月流水数据结构
  11556. $monthStatistics = array ();
  11557. $incomeMothStatistics = array ();
  11558. $expenditureMothStatistics = array ();
  11559. for($i = 1; $i <= 12; $i ++) {
  11560. $month = date ( 'Y' ) . '-' . $i;
  11561. if ($i < 10)
  11562. $month = date ( 'Y' ) . '-0' . $i;
  11563. array_push ( $monthStatistics, $month );
  11564. }
  11565. foreach ( $monthStatistics as $value ) {
  11566. $falg = true;
  11567. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11568. if ($value == $v ['inputDate']) {
  11569. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11570. $falg = false;
  11571. }
  11572. }
  11573. if ($falg) {
  11574. array_push ( $incomeMothStatistics, '' );
  11575. }
  11576. $falgEx = true;
  11577. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11578. if ($value == $v ['inputDate']) {
  11579. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11580. $falg = false;
  11581. }
  11582. }
  11583. if ($falgEx) {
  11584. array_push ( $expenditureMothStatistics, '' );
  11585. }
  11586. }
  11587. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11588. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11589. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11590. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11591. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11592. // print_r($incomeList);
  11593. $data ['expenditureList'] = $expenditureList;
  11594. $data ['incomeList'] = $incomeList;
  11595. $data ['memu'] = "receipt";
  11596. $data ['staff'] = $this->staff;
  11597. $data ['receiptMemu'] = 'wasteBook';
  11598. $data ['verifyId'] = $this->verifyId;
  11599. $data ['executeId'] = $this->executeId;
  11600. $this->render ( "/expenses/wasteBook", $data );
  11601. }
  11602. function wasteBookIncome() {
  11603. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11604. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11605. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11606. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11607. $data ['dailyIncomeType'] = $dailyIncomeType;
  11608. Doo::loadModel ( 'wasteBook' );
  11609. $wasteBook = new wasteBook ();
  11610. Doo::loadModel ( 'L_category' );
  11611. $L_category = new L_category ();
  11612. Doo::loadClass ( 'XDeode' );
  11613. $XDeode = new XDeode ( 5 );
  11614. // echo $XDeode->encode(1).'<br>';
  11615. // echo $XDeode->encode(2).'<br>';
  11616. // echo $XDeode->encode(3).'<br>';
  11617. // echo $XDeode->encode(4).'<br>';
  11618. // echo $XDeode->encode(5).'<br>';
  11619. // echo $XDeode->encode(6).'<br>';
  11620. // echo $XDeode->encode(7).'<br>';
  11621. // echo $XDeode->encode(8).'<br>';
  11622. // echo $XDeode->encode(9).'<br>';
  11623. // echo $XDeode->encode(10).'<br>';
  11624. $year=date("Y");
  11625. $theDay=date("Y-m-d");
  11626. $dateArr = explode ( ':', $date );
  11627. $D1 = '';
  11628. $D2 = '';
  11629. $con = '';
  11630. if (! empty ( $date )) {
  11631. $D1 = $dateArr [0];
  11632. $D2 = $dateArr [1];
  11633. }
  11634. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11635. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11636. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11637. $con = ' and inputDate = "' . $D1 . '"';
  11638. else{
  11639. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11640. }
  11641. if ($cid != 'ALL') {
  11642. $cid = $XDeode->decode ( $cid );
  11643. $con .= ' and cid = "' . $cid . '"';
  11644. }
  11645. if ($accountType != 'ALL') {
  11646. if ($accountType == 'INVOICE') {
  11647. $con .= ' and (accountType = 7 or accountType = 8)';
  11648. } elseif ($accountType == 'PAYMENTS') {
  11649. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11650. if ($dailyIncomeType != 'ALL') {
  11651. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11652. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11653. }
  11654. }
  11655. }
  11656. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11657. $sum = 0;$thsDaySum=0;
  11658. foreach ( $incomeList as $key => $value ) {
  11659. $sum += $value ['accountPrice'];
  11660. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11661. $thsDaySum+=$value ['accountPrice'];
  11662. }
  11663. }
  11664. // print_r($incomeList);
  11665. // 获得办事和部门
  11666. $categoryList = $L_category->getCategory ();
  11667. $data ['accountType'] = $accountType;
  11668. $data ['cid'] = $cid;
  11669. $data ['categoryList'] = $categoryList;
  11670. $data ['sum'] = $sum;
  11671. $data ['incomeList'] = $incomeList;
  11672. $data ['inputDate'] = $date;
  11673. $data['year']=$year;
  11674. $data ['thsDay'] =$theDay;
  11675. $data ['thsDaySum'] =$thsDaySum;
  11676. $data ['memu'] = "receipt";
  11677. $data ['staff'] = $this->staff;
  11678. $data ['receiptMemu'] = 'wasteBook';
  11679. $data ['verifyId'] = $this->verifyId;
  11680. $data ['executeId'] = $this->executeId;
  11681. $this->render ( "/expenses/wasteBookIncome", $data );
  11682. }
  11683. /**
  11684. * 所有支出
  11685. */
  11686. function wasteBookExpenditure() {
  11687. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11688. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11689. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11690. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11691. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11692. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11693. $data ['receiptType'] = $receiptType;
  11694. Doo::loadModel ( 'wasteBook' );
  11695. $wasteBook = new wasteBook ();
  11696. Doo::loadModel ( 'L_category' );
  11697. $L_category = new L_category ();
  11698. Doo::loadClass ( 'XDeode' );
  11699. $XDeode = new XDeode ( 5 );
  11700. $year=date("Y");
  11701. $theDay=date("Y-m-d");
  11702. $dateArr = explode ( ':', $date );
  11703. $D1 = '';
  11704. $D2 = '';
  11705. $con = '';
  11706. if (! empty ( $date )) {
  11707. $D1 = $dateArr [0];
  11708. $D2 = $dateArr [1];
  11709. }
  11710. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11711. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11712. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11713. $con = ' and inputDate = "' . $D1 . '"';
  11714. else{
  11715. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11716. }
  11717. if ($cid != 'ALL') {
  11718. $cid = $XDeode->decode ( $cid );
  11719. $con .= ' and cid = "' . $cid . '"';
  11720. }
  11721. if ($accountType != 'ALL') {
  11722. if ($accountType == 'INVOICE') {
  11723. $con .= ' and accountType = 11';
  11724. } elseif ($accountType == 'PAYMENTS') {
  11725. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11726. if ($dailyExpenditureType != 'ALL') {
  11727. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11728. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11729. }
  11730. } elseif ($accountType == 'RECEIPT') {
  11731. if ($receiptType == 'ALL') {
  11732. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11733. } else {
  11734. $receiptType = $XDeode->decode ( $receiptType );
  11735. echo $receiptType;
  11736. if ($receiptType == 1) {
  11737. $con .= ' and (accountType = 1 or accountType=2)';
  11738. } else {
  11739. $con .= ' and accountType = ' . $receiptType;
  11740. }
  11741. }
  11742. }
  11743. }
  11744. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11745. $sum = 0;$thsDaySum=0;
  11746. foreach ( $incomeList as $key => $value ) {
  11747. $sum += $value ['accountPriceShow'];
  11748. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11749. $thsDaySum+=$value ['accountPriceShow'];
  11750. }
  11751. }
  11752. // print_r($incomeList);
  11753. // 获得办事和部门
  11754. $categoryList = $L_category->getCategory ();
  11755. $data ['accountType'] = $accountType;
  11756. $data ['cid'] = $cid;
  11757. $data ['categoryList'] = $categoryList;
  11758. $data ['sum'] = $sum;
  11759. $data ['incomeList'] = $incomeList;
  11760. $data ['inputDate'] = $date;
  11761. $data['year']=$year;
  11762. $data ['thsDay'] =$theDay;
  11763. $data ['thsDaySum'] =$thsDaySum;
  11764. $data ['memu'] = "receipt";
  11765. $data ['staff'] = $this->staff;
  11766. $data ['receiptMemu'] = 'wasteBook';
  11767. $data ['verifyId'] = $this->verifyId;
  11768. $data ['executeId'] = $this->executeId;
  11769. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11770. }
  11771. function ajaxGetWasteinvoiceReceivables() {
  11772. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11773. Doo::loadClass ( 'XDeode' );
  11774. $XDeode = new XDeode ( 5 );
  11775. $irid = $XDeode->decode ( $serial );
  11776. Doo::loadModel ( 'invoiceReceivables' );
  11777. $invoiceReceivables = new invoiceReceivables ();
  11778. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11779. echo json_encode ( array (
  11780. 'status' => 1,
  11781. 'detail' => $detail
  11782. ) );
  11783. }
  11784. function ajaxGetPaymentsByAid() {
  11785. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11786. Doo::loadModel ( "accountBook" );
  11787. $accountBook = new accountBook ();
  11788. $detail = $accountBook->getAccountBookByAid ( $serial );
  11789. echo json_encode ( array (
  11790. 'status' => 1,
  11791. 'detail' => $detail
  11792. ) );
  11793. }
  11794. function ajaxGetWasteInvoice() {
  11795. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11796. Doo::loadModel ( 'invoice' );
  11797. $invoice = new invoice ();
  11798. Doo::loadModel ( 'invoiceReceivables' );
  11799. $invoiceReceivables = new invoiceReceivables ();
  11800. $detail = $invoice->getInvoiceByIid ( $serial );
  11801. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11802. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11803. echo json_encode ( array (
  11804. 'status' => 1,
  11805. 'detail' => $detail
  11806. ) );
  11807. }
  11808. /**
  11809. */
  11810. function ajaxGetWasteReceipt() {
  11811. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11812. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11813. Doo::loadModel ( 'receipt' );
  11814. $receipt = new receipt ();
  11815. Doo::loadClass ( 'XDeode' );
  11816. $XDeode = new XDeode ( 5 );
  11817. $rid = $XDeode->decode ( $serial );
  11818. $accountType= $XDeode->decode ( $accountTypeKey );
  11819. // 获得个数据
  11820. $detail = $receipt->getReceiptByRid ( $rid );
  11821. // 初始化
  11822. $detail ['reviseDetail'] = array ();
  11823. if (! empty ( $value ['reviseDetail'] ))
  11824. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11825. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11826. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11827. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11828. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11829. // 获得费用html
  11830. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11831. // 获得费用审批人数据
  11832. $detail = $this->getReceiptApproverHtml ( $detail );
  11833. // 审批执行
  11834. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11835. <th class="taC" width="90">审批人</th>
  11836. <th class="taC">审批意见</th></tr>';
  11837. foreach ( $detail ['verifyList'] as $key => $value ) {
  11838. $html .= '<tr>
  11839. <td>' . $value [1] . '</td>
  11840. <td>' . $value ['opinion'] . '</td>
  11841. </tr>
  11842. ';
  11843. }
  11844. $html .= ' </tbody></table>';
  11845. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11846. <th class="taC" width="90">执行人</th>
  11847. <th class="taC">执行意见</th></tr>';
  11848. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11849. $html .= '<tr>
  11850. <td>' . $value [1] . '</td>
  11851. <td>' . $value ['opinion'] . '</td>
  11852. </tr>
  11853. ';
  11854. }
  11855. $html .= ' </tbody></table>';
  11856. if($accountType==1){
  11857. Doo::loadModel ( 'loanReceipt' );
  11858. $loanReceipt = new loanReceipt ();
  11859. $loanList = $loanReceipt->getOne ( array (
  11860. 'where' => 'rid=' . $detail ['loanRid'],
  11861. 'desc' => 'rid',
  11862. 'asArray' => true
  11863. ) );
  11864. $html .= '<table class="table table-bordered table-condensed">
  11865. <tr class="warning">
  11866. <td class="taR"><b>汇款金额</b></td>
  11867. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11868. </tr>
  11869. </table>';
  11870. }else{
  11871. $html .= '<table class="table table-bordered table-condensed">
  11872. <tr class="warning">
  11873. <td class="taR"><b>汇款金额</b></td>
  11874. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11875. </tr>
  11876. </table>';
  11877. }
  11878. // print_r($detail['verifyList']);
  11879. // header ( 'Content-Type:text/html;charset=utf-8' );
  11880. // echo $html;
  11881. echo json_encode ( array (
  11882. 'status' => 1,
  11883. 'html' => $html,
  11884. 'detail' => $detail
  11885. ) );
  11886. }
  11887. function getReceiptApproverHtml($detail = array()) {
  11888. Doo::loadModel ( 'loanReceipt' );
  11889. $loanReceipt = new loanReceipt ();
  11890. Doo::loadModel ( 'verify' );
  11891. $verify = new verify ();
  11892. Doo::loadModel ( 'staff' );
  11893. $staff = new staff ();
  11894. if (empty ( $detail ))
  11895. return array ();
  11896. $loanList = $loanReceipt->getOne ( array (
  11897. 'where' => 'rid=' . $detail ['loanRid'],
  11898. 'desc' => 'rid',
  11899. 'asArray' => true
  11900. ) );
  11901. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11902. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11903. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11904. else
  11905. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11906. } else
  11907. $verifyList = $verify->getOne ( array (
  11908. 'where' => 'vid=' . $detail ['verify'],
  11909. 'asArray' => true
  11910. ) );
  11911. $verifyList = json_decode ( $verifyList ['staff'], true );
  11912. Doo::loadModel ( 'role' );
  11913. $role = new role ();
  11914. $roleId = 0;
  11915. $flag = true;
  11916. $roleKey = 0;
  11917. $endStaffArray = array ();
  11918. $roleArrayCopy = array ();
  11919. foreach ( $verifyList as $k => $v ) {
  11920. // init verifyStaff
  11921. if ($v [1] == 'ROLE') {
  11922. if (! empty ( $verifyStaff )) {
  11923. $endStaffArray = end ( $verifyStaff );
  11924. }
  11925. $roleVerify = json_decode ( $v [3], true );
  11926. $roleKey = $k;
  11927. $roleArray = array ();
  11928. $rolename = $role->getOne ( array (
  11929. 'where' => 'rid=' . $v [0],
  11930. 'asArray' => true
  11931. ) );
  11932. foreach ( $roleVerify as $o => $p ) {
  11933. $staffID = explode ( '_', $p );
  11934. $staffInfo = $staff->getOne ( array (
  11935. 'where' => 'sid=' . $staffID [0],
  11936. 'asArray' => true
  11937. ) );
  11938. // print_r($staffID);
  11939. $exp = array (
  11940. 0 => $staffInfo ['sid'],
  11941. 1 => $staffID [1],
  11942. 2 => $staffInfo ['avatar'],
  11943. 'date' => '',
  11944. 'date' => '',
  11945. 'opinion' => '',
  11946. 'status' => '',
  11947. 'rolename' => $rolename ['name']
  11948. );
  11949. array_push ( $roleArray, $exp );
  11950. }
  11951. $roleArrayCopy [$v [0]] = $roleArray;
  11952. // $verifyList[$k]['roleArray']=$roleArray;
  11953. }
  11954. $verifyList [$k] ['date'] = "";
  11955. $verifyList [$k] ['opinion'] = "";
  11956. $verifyList [$k] ['status'] = "";
  11957. if (empty ( $verifyStaff )) {
  11958. $verifyList [$k] ['date'] = "";
  11959. $verifyList [$k] ['opinion'] = "";
  11960. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11961. $verifyList [$k] ['status'] = 4;
  11962. $flag = false;
  11963. }
  11964. } else {
  11965. foreach ( $verifyStaff as $m => $u ) {
  11966. if ($v [0] == $m) {
  11967. $verifyList [$k] ['date'] = $u ['date'];
  11968. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11969. $verifyList [$k] ['status'] = $u ['status'];
  11970. $flag = false;
  11971. break;
  11972. }
  11973. }
  11974. $endStaffArray = end ( $verifyStaff );
  11975. }
  11976. }
  11977. $rolename ['name'] = '';
  11978. if (! empty ( $roleId )) {
  11979. Doo::loadModel ( 'role' );
  11980. $role = new role ();
  11981. $rolename = $role->getOne ( array (
  11982. 'where' => 'rid=' . $roleId,
  11983. 'asArray' => true
  11984. ) );
  11985. }
  11986. if (! empty ( $verifyStaff ))
  11987. $endStaffArray = end ( $verifyStaff );
  11988. $KOP = false;
  11989. foreach ( $roleArrayCopy as $P => $A ) {
  11990. foreach ( $A as $MKI => $AVL ) {
  11991. if (! empty ( $verifyStaff )) {
  11992. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11993. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11994. $button = 4;
  11995. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11996. }
  11997. foreach ( $verifyStaff as $m => $u ) {
  11998. $AVLFK = $AVL [0] . '_R';
  11999. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12000. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12001. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12002. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12003. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12004. break;
  12005. }
  12006. }
  12007. } else {
  12008. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12009. $button = 4;
  12010. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12011. }
  12012. }
  12013. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12014. $KOP = true;
  12015. }
  12016. }
  12017. foreach ( $roleArrayCopy as $k => $v ) {
  12018. foreach ( $verifyList as $m => $n ) {
  12019. if ($n [0] == $k) {
  12020. array_splice ( $verifyList, $m, 1, $v );
  12021. }
  12022. }
  12023. }
  12024. // 费用执行人相关数据
  12025. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12026. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12027. foreach ( $executeCopy as $k => $v ) {
  12028. $executeCopy [$k] ['date'] = '';
  12029. $executeCopy [$k] ['opinion'] = '';
  12030. $executeCopy [$k] ['status'] = '';
  12031. if (! empty ( $executeStaff ))
  12032. foreach ( $executeStaff as $m => $u ) {
  12033. if ($v [0] == $m) {
  12034. $executeCopy [$k] ['date'] = $u ['date'];
  12035. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12036. $executeCopy [$k] ['status'] = $u ['status'];
  12037. break;
  12038. }
  12039. }
  12040. }
  12041. $detail ['executeCopy'] = $executeCopy;
  12042. $detail ['verifyList'] = $verifyList;
  12043. return $detail;
  12044. }
  12045. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12046. if (empty ( $detail ))
  12047. return '';
  12048. $html = '';
  12049. if ($detail ['Rtype'] == 0) { // 报销单
  12050. $html .= '<table class="table table-bordered table-condensed">
  12051. <tbody>
  12052. <tr>
  12053. <th colspan="2" class="taC">日常相关费用</th>
  12054. </tr>';
  12055. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12056. $html .= '
  12057. <tr>
  12058. <th>' . $value ['name'] . '</th>
  12059. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12060. </tr>';
  12061. }
  12062. $html .= '
  12063. <tr>
  12064. <th class="taR">合计</th>
  12065. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12066. </tr>';
  12067. $html .= '<tr>
  12068. <th colspan="2" class="taC">差旅相关费用</th>
  12069. </tr>';
  12070. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12071. $html .= '
  12072. <tr>
  12073. <th>' . $value ['name'] . '</th>
  12074. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12075. </tr>';
  12076. }
  12077. $html .= '
  12078. <tr>
  12079. <th class="taR">合计</th>
  12080. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12081. </tr>';
  12082. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12083. $html .= '<tr>
  12084. <th colspan="2" class="taC">内部培训费用</th>
  12085. </tr>';
  12086. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12087. $html .= '
  12088. <tr>
  12089. <th>' . $value ['name'] . '</th>
  12090. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12091. </tr>';
  12092. }
  12093. $html .= '
  12094. <tr>
  12095. <th class="taR">合计</th>
  12096. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12097. </tr>';
  12098. }
  12099. $html .= '<tr>
  12100. <th colspan="2" class="taC">其他</th>
  12101. </tr>';
  12102. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12103. $html .= '
  12104. <tr>
  12105. <th>' . $value ['name'] . '</th>
  12106. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12107. </tr>';
  12108. }
  12109. $html .= '
  12110. <tr>
  12111. <th class="taR">合计</th>
  12112. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12113. </tr>';
  12114. $html .= '<tr>
  12115. <th colspan="2" class="taC">报销金额调整</th>
  12116. </tr>';
  12117. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12118. $html .= '
  12119. <tr>
  12120. <th>' . $value ['name'] . '</th>
  12121. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12122. </tr>';
  12123. }
  12124. $html .= '
  12125. <tr>
  12126. <th class="taR">合计</th>
  12127. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12128. </tr>';
  12129. $html .= '
  12130. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12131. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12132. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12133. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12134. <tr class="warning">
  12135. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12136. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12137. </tr>
  12138. </tbody>
  12139. </table>';
  12140. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12141. $html .= '
  12142. <table class="table table-bordered table-condensed">
  12143. <tbody>
  12144. <tr>
  12145. <th colspan="2" class="taC">办事处相关费用</th>
  12146. </tr>';
  12147. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12148. $html .= '
  12149. <tr>
  12150. <th>' . $value ['name'] . '</th>
  12151. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12152. </tr>';
  12153. }
  12154. $html .= '
  12155. <tr>
  12156. <th class="taR">合计</th>
  12157. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12158. </tr>';
  12159. $html .= '
  12160. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12161. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12162. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12163. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12164. <tr class="warning">
  12165. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12166. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12167. </tr>
  12168. </tbody>
  12169. </table>';
  12170. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12171. Doo::loadModel ( 'loanReceipt' );
  12172. $loanReceipt = new loanReceipt ();
  12173. $loanList = $loanReceipt->getOne ( array (
  12174. 'where' => 'rid=' . $detail ['loanRid'],
  12175. 'desc' => 'rid',
  12176. 'asArray' => true
  12177. ) );
  12178. // print_r($loanList);
  12179. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12180. $html .= '<table class="table table-bordered table-condensed">
  12181. <tbody>
  12182. <tr>
  12183. <th colspan="2" class="taC">借款费用</th>
  12184. </tr>';
  12185. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12186. $html .= '<tr>
  12187. <th>' . $value ['name'] . '</th>
  12188. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12189. </tr>';
  12190. }
  12191. $html .= '<tr>
  12192. <th class="taC" colspan="2">产生费用所在办事处</th>
  12193. </tr>
  12194. <tr>
  12195. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12196. </tr>
  12197. <tr>
  12198. <th class="taC" colspan="2">费用说明</th>
  12199. </tr>
  12200. <tr>
  12201. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12202. </tr>
  12203. <tr class="warning">
  12204. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12205. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12206. </tr>
  12207. </tbody>
  12208. </table>
  12209. ';
  12210. if ( $accountType==2) {
  12211. $balance=$detail ['sum']-$loanList ['sum'];
  12212. $balanceCN=$this->num_to_rmb($balance);
  12213. $html .= '<table class="table table-bordered table-condensed">
  12214. <tbody>
  12215. <tr>
  12216. <th colspan="2" class="taC">日常相关费用</th>
  12217. </tr>';
  12218. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12219. $html .= '
  12220. <tr>
  12221. <th>' . $value ['name'] . '</th>
  12222. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12223. </tr>';
  12224. }
  12225. $html .= '
  12226. <tr>
  12227. <th class="taR">合计</th>
  12228. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12229. </tr>';
  12230. $html .= '<tr>
  12231. <th colspan="2" class="taC">差旅相关费用</th>
  12232. </tr>';
  12233. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12234. $html .= '
  12235. <tr>
  12236. <th>' . $value ['name'] . '</th>
  12237. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12238. </tr>';
  12239. }
  12240. $html .= '
  12241. <tr>
  12242. <th class="taR">合计</th>
  12243. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12244. </tr>';
  12245. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12246. $html .= '<tr>
  12247. <th colspan="2" class="taC">内部培训费用</th>
  12248. </tr>';
  12249. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12250. $html .= '
  12251. <tr>
  12252. <th>' . $value ['name'] . '</th>
  12253. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12254. </tr>';
  12255. }
  12256. $html .= '
  12257. <tr>
  12258. <th class="taR">合计</th>
  12259. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12260. </tr>';
  12261. }
  12262. $html .= '<tr>
  12263. <th colspan="2" class="taC">其他</th>
  12264. </tr>';
  12265. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12266. $html .= '
  12267. <tr>
  12268. <th>' . $value ['name'] . '</th>
  12269. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12270. </tr>';
  12271. }
  12272. $html .= '
  12273. <tr>
  12274. <th class="taR">合计</th>
  12275. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12276. </tr>';
  12277. $html .= '<tr>
  12278. <th colspan="2" class="taC">报销金额调整</th>
  12279. </tr>';
  12280. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12281. $html .= '
  12282. <tr>
  12283. <th>' . $value ['name'] . '</th>
  12284. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12285. </tr>';
  12286. }
  12287. $html .= '
  12288. <tr>
  12289. <th class="taR">合计</th>
  12290. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12291. </tr>';
  12292. $html .= '
  12293. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12294. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12295. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12296. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12297. <tr class="warning">
  12298. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12299. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12300. </tr>
  12301. <tr class="success">
  12302. <td class="taR"><b>借款结余</b></td>
  12303. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12304. </tr>
  12305. </tbody>
  12306. </table>';
  12307. }
  12308. }
  12309. return $html;
  12310. }
  12311. /**
  12312. * 计算流水
  12313. */
  12314. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12315. $bakWaste ['bank'] = array (
  12316. 'CGBDeposit' => 0,
  12317. 'ICBCDeposit' => 0,
  12318. 'HUADeposit' => 0,
  12319. 'PersonalDeposit' => 0
  12320. );
  12321. $bakWaste ['financial'] = array (
  12322. 'current' => array (
  12323. 'CGBDeposit' => 0,
  12324. 'ICBCDeposit' => 0
  12325. ),
  12326. 'fixed' => array (
  12327. 'CGBDeposit' => 0,
  12328. 'ICBCDeposit' => 0
  12329. )
  12330. );
  12331. // 存款
  12332. foreach ( $waste ['bank'] as $key => $value ) {
  12333. // 收入
  12334. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12335. // 广发
  12336. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12337. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12338. }
  12339. // 工商
  12340. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12341. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12342. }
  12343. // 华润
  12344. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12345. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12346. }
  12347. // 个人
  12348. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12349. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12350. }
  12351. }
  12352. }
  12353. foreach ( $waste ['bank'] as $key => $value ) {
  12354. // 支出
  12355. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12356. // 广发
  12357. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12358. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12359. }
  12360. // 工商
  12361. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12362. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12363. }
  12364. // 华润
  12365. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12366. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12367. }
  12368. // 个人
  12369. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12370. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12371. }
  12372. }
  12373. }
  12374. // 活期
  12375. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12376. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12377. // 广发
  12378. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12379. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12380. }
  12381. // 工商
  12382. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12383. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12384. }
  12385. // 个人
  12386. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12387. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12388. }
  12389. }
  12390. }
  12391. // print_r($inComeStatistics ['fixedStatistics']);
  12392. // 固期
  12393. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12394. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12395. // 广发
  12396. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12397. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12398. }
  12399. // 工商
  12400. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12401. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12402. }
  12403. // 个人
  12404. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12405. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12406. }
  12407. }
  12408. }
  12409. return $waste;
  12410. }
  12411. function lyt() {
  12412. Doo::loadModel ( "receiptDetail" );
  12413. $receiptDetail = new receiptDetail ();
  12414. $receiptCollectList = $receiptDetail->find ( array (
  12415. 'where' => 'status=1 ',
  12416. 'asArray' => true
  12417. ) );
  12418. foreach ( $receiptCollectList as $key => $value ) {
  12419. $receiptDetail = new receiptDetail ();
  12420. $receiptDetail->pastDate = $value ['date'];
  12421. $receiptDetail->update ( array (
  12422. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12423. ) );
  12424. }
  12425. }
  12426. function staffCollectMonthDetail() {
  12427. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12428. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12429. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12430. if (! $year)
  12431. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12432. if (! $month)
  12433. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12434. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12435. if (! $nature){
  12436. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12437. }
  12438. Doo::loadModel ( 'staff' );
  12439. $staff = new staff ();
  12440. Doo::loadModel ( "receiptDetail" );
  12441. $receiptDetail = new receiptDetail ();
  12442. Doo::loadModel ( 'accountItem' );
  12443. $accountItem = new accountItem ();
  12444. Doo::loadModel ( 'statistics' );
  12445. $statistics = new statistics ();
  12446. Doo::loadModel ( "receiptAuthorityManage" );
  12447. $receiptAuthorityManage = new receiptAuthorityManage ();
  12448. $aiList=$accountItem->getAccountItem();
  12449. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12450. $cidList = array ();
  12451. foreach ( $imcStaff as $key => $value ) {
  12452. array_push ( $cidList, $value ['cid'] );
  12453. }
  12454. $cidString = implode ( ',', $cidList );
  12455. $naturecon='';
  12456. if ($nature=='ONJOB'){
  12457. $naturecon=' and (nature!=4 )';
  12458. }elseif($nature=='LEAVEJOB'){
  12459. $naturecon=' and (nature=4 )';
  12460. }else{
  12461. die ( 'illegal request--nature' );
  12462. }
  12463. $staffList = $staff->find ( array (
  12464. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12465. 'asArray' => true
  12466. ) );
  12467. $categoryList = $staff->find ( array (
  12468. 'select' => 'COUNT(*) as count,cid,category',
  12469. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12470. 'groupby' => 'cid',
  12471. 'asArray' => true
  12472. ) );
  12473. $list = array ();
  12474. foreach($aiList as $key=>$value){
  12475. foreach ($value as $v){
  12476. $subtotal[$key][$v['name']]=0;
  12477. }
  12478. }
  12479. foreach ( $categoryList as $vlu ) {
  12480. $s1 = 0;
  12481. $m1 = 0;
  12482. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12483. foreach ( $staffList as $value ) {
  12484. if ($vlu ['cid'] == $value ['cid']) {
  12485. // pastDate
  12486. $receiptCollectList = $receiptDetail->find ( array (
  12487. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12488. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12489. 'groupby' => 'item,Month(pastDate),itemCategory',
  12490. 'asArray' => true
  12491. ) );
  12492. if (! empty ( $receiptCollectList )) {
  12493. $receiptL = array (
  12494. '日常相关费用' => array (),
  12495. '差旅相关费用' => array (),
  12496. '内部培训费用' => array (),
  12497. '培训班费用' => array (),
  12498. '其他' => array ()
  12499. );
  12500. $html = "";
  12501. $psum = 0;
  12502. foreach ( $aiList[$this->AGENCY] as $va ) {
  12503. $falg = true;
  12504. foreach ( $receiptCollectList as $v ) {
  12505. if ($v ['itemCategory'] == '日常相关费用') {
  12506. if ($v ['item'] == $va['name']) {
  12507. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12508. $psum += $v ['price'];
  12509. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12510. $falg = false;
  12511. break;
  12512. }
  12513. }
  12514. }
  12515. if ($falg)
  12516. $html .= '<td class="taR">-</td>';
  12517. }
  12518. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12519. if (! empty ( $psum ))
  12520. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12521. else
  12522. $psum = '<td class="colGreen taR">-</td>';
  12523. $receiptL ['日常相关费用'] = $psum . $html;
  12524. /* ----------------------------------- */
  12525. $html = "";
  12526. $psum = 0;
  12527. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12528. $falg = true;
  12529. foreach ( $receiptCollectList as $v ) {
  12530. if ($v ['itemCategory'] == '差旅相关费用') {
  12531. if ($v ['item'] == $va['name']) {
  12532. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12533. $psum += $v ['price'];
  12534. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12535. $falg = false;
  12536. break;
  12537. }
  12538. }
  12539. }
  12540. if ($falg)
  12541. $html .= '<td class="taR">-</td>';
  12542. }
  12543. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12544. if (! empty ( $psum ))
  12545. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12546. else
  12547. $psum = '<td class="colGreen taR">-</td>';
  12548. $receiptL ['差旅相关费用'] = $psum . $html;
  12549. /* ------------------------------------- */
  12550. $html = "";
  12551. $psum = 0;
  12552. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12553. $falg = true;
  12554. foreach ( $receiptCollectList as $v ) {
  12555. if ($v ['itemCategory'] == '内部培训费用') {
  12556. if ($v ['item'] == $va['name']) {
  12557. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12558. $psum += $v ['price'];
  12559. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12560. $falg = false;
  12561. break;
  12562. }
  12563. }
  12564. }
  12565. if ($falg)
  12566. $html .= '<td class="taR">-</td>';
  12567. }
  12568. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12569. if (! empty ( $psum ))
  12570. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12571. else
  12572. $psum = '<td class="colGreen taR">-</td>';
  12573. $receiptL ['内部培训费用'] = $psum . $html;
  12574. /* ----------------------------------- */
  12575. $html = "";
  12576. $psum = 0;
  12577. foreach ( $aiList[$this->TRAIN] as $va ) {
  12578. $falg = true;
  12579. foreach ( $receiptCollectList as $v ) {
  12580. if ($v ['itemCategory'] == '培训班费用') {
  12581. if ($v ['item'] == $va['name']) {
  12582. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12583. $psum += $v ['price'];
  12584. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12585. $falg = false;
  12586. break;
  12587. }
  12588. }
  12589. }
  12590. if ($falg)
  12591. $html .= '<td class="taR">-</td>';
  12592. }
  12593. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12594. if (! empty ( $psum ))
  12595. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12596. else
  12597. $psum = '<td class="colGreen taR">-</td>';
  12598. $receiptL ['培训班费用'] = $psum . $html;
  12599. /* ------------------------------------- */
  12600. $html = "";
  12601. $psum = 0;
  12602. foreach ( $aiList[$this->OTHER] as $va ) {
  12603. $falg = true;
  12604. foreach ( $receiptCollectList as $v ) {
  12605. if ($v ['itemCategory'] == '其他') {
  12606. if (trim ( $v ['item'] ) == $va['name']) {
  12607. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12608. $psum += $v ['price'];
  12609. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12610. $falg = false;
  12611. break;
  12612. }
  12613. }
  12614. }
  12615. if ($falg)
  12616. $html .= '<td class="taR">-</td>';
  12617. }
  12618. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12619. if (! empty ( $psum ))
  12620. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12621. else
  12622. $psum = '<td class="colGreen taR">-</td>';
  12623. $receiptL ['其他'] = $psum . $html;
  12624. /* ------------------------------------- */
  12625. $html = "";
  12626. $psum = 0;
  12627. foreach ( $receiptCollectList as $v ) {
  12628. if ($v ['itemCategory'] == '报销金额调整') {
  12629. if (! empty ( $v ['price'] )) {
  12630. $psum += $v ['price'];
  12631. }
  12632. }
  12633. }
  12634. $s1 += $psum;
  12635. if (! empty ( $psum ))
  12636. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12637. else
  12638. $psum = '<td class="taR colOrange">-</td>';
  12639. $receiptL ['报销金额调整'] = $psum . $html;
  12640. } else {
  12641. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12642. foreach ( $aiList[$this->AGENCY] as $va ) {
  12643. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12644. }
  12645. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12646. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12647. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12648. }
  12649. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12650. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12651. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12652. }
  12653. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12654. foreach ( $aiList[$this->TRAIN] as $va ) {
  12655. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12656. }
  12657. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12658. foreach ( $aiList[$this->OTHER] as $va ) {
  12659. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12660. }
  12661. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12662. }
  12663. $monthStaffPrice = $receiptDetail->find ( array (
  12664. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12665. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12666. 'groupby' => 'Month(pastDate)',
  12667. 'asArray' => true
  12668. ) );
  12669. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12670. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12671. $m1 += $monthStaffPrice [0] ['price'];
  12672. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12673. } else
  12674. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12675. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12676. $list [$value ['username']] = $receiptL;
  12677. }
  12678. }
  12679. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12680. foreach ( $aiList[$this->AGENCY] as $va ) {
  12681. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12682. $subtotal[$this->AGENCY][$va['name']]=0;
  12683. }
  12684. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12685. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12686. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12687. $subtotal[$this->TRAVEL][$va['name']]=0;
  12688. }
  12689. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12690. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12691. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12692. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12693. }
  12694. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12695. foreach ( $aiList[$this->TRAIN] as $va ) {
  12696. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12697. $subtotal[$this->TRAIN][$va['name']]=0;
  12698. }
  12699. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12700. foreach ( $aiList[$this->OTHER] as $va ) {
  12701. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12702. $subtotal[$this->OTHER][$va['name']]=0;
  12703. }
  12704. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12705. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12706. $receiptL ['usernameEn'] =false;
  12707. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12708. }
  12709. $data ['list'] = $list;
  12710. // print_r($list);
  12711. $receiptCollectList = $receiptDetail->find ( array (
  12712. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12713. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12714. 'groupby' => 'item,Month(pastDate),itemCategory',
  12715. 'asArray' => true
  12716. ) );
  12717. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12718. // statistics html
  12719. $stList = $statistics->getOne ( array (
  12720. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12721. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12722. 'groupby' => 'Month(date)',
  12723. 'asArray' => true
  12724. ) );
  12725. if (empty ( $stList ))
  12726. $stList = array (
  12727. 'rePrice' => 0,
  12728. 'agPrice' => 0
  12729. );
  12730. $data ['stList'] = array (
  12731. 'rePrice' => $stList ['rePrice'],
  12732. 'agPrice' => $stList ['agPrice'],
  12733. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12734. );
  12735. $monthHtml = "";
  12736. for($i = 1; $i <= 12; $i ++) {
  12737. if ($i == $month)
  12738. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12739. else
  12740. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12741. }
  12742. $data ['monthHtml'] = $monthHtml;
  12743. $data ['year'] = $year;
  12744. $data ['month'] = $month;
  12745. $data ['nature'] = $nature;
  12746. $data ['aiList'] = $aiList;
  12747. $data ['memu'] = "receipt";
  12748. $data ['staff'] = $this->staff;
  12749. $data ['receiptMemu'] = 'companyCategoryCollect';
  12750. $data ['verifyId'] = $this->verifyId;
  12751. $data ['executeId'] = $this->executeId;
  12752. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12753. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12754. }
  12755. function staffCollectMonthDetail2() {
  12756. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12757. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12758. if (! $year)
  12759. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12760. if (! $month)
  12761. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12762. Doo::loadModel ( 'staff' );
  12763. $staff = new staff ();
  12764. Doo::loadModel ( "receiptDetail" );
  12765. $receiptDetail = new receiptDetail ();
  12766. Doo::loadModel ( 'accountItem' );
  12767. $accountItem = new accountItem ();
  12768. Doo::loadModel ( 'statistics' );
  12769. $statistics = new statistics ();
  12770. Doo::loadModel ( 'L_category' );
  12771. $lCategory = new L_category ();
  12772. $staffList = $staff->find ( array (
  12773. 'where' => 'username!="admin"',
  12774. 'asArray' => true
  12775. ) );
  12776. $categoryList = $staff->find ( array (
  12777. 'select' => 'COUNT(*) as count,cid,category',
  12778. 'where' => 'username !="admin"',
  12779. 'groupby' => 'cid',
  12780. 'asArray' => true
  12781. ) );
  12782. $list = array ();
  12783. foreach ( $categoryList as $vlu ) {
  12784. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12785. $r1 = 0;
  12786. $r2 = 0;
  12787. $r3 = 0;
  12788. $r4 = 0;
  12789. $r5 = 0;
  12790. $r6 = 0;
  12791. $r7 = 0;
  12792. $r8 = 0;
  12793. $r9 = 0;
  12794. $r10 = 0;
  12795. $r11 = 0;
  12796. $r12 = 0;
  12797. $r13 = 0;
  12798. $r14 = 0;
  12799. $r15 = 0;
  12800. $c1 = 0;
  12801. $c2 = 0;
  12802. $c3 = 0;
  12803. $c4 = 0;
  12804. $c5 = 0;
  12805. $c6 = 0;
  12806. $p1 = 0;
  12807. $p2 = 0;
  12808. $p3 = 0;
  12809. $p4 = 0;
  12810. $p5 = 0;
  12811. $p6 = 0;
  12812. $p7 = 0;
  12813. $p8 = 0;
  12814. $p9 = 0;
  12815. $t1 = 0;
  12816. $t2 = 0;
  12817. $t3 = 0;
  12818. $t4 = 0;
  12819. $t5 = 0;
  12820. $s1 = 0;
  12821. $m1 = 0;
  12822. foreach ( $staffList as $value ) {
  12823. if ($vlu ['cid'] == $value ['cid']) {
  12824. $receiptCollectList = $receiptDetail->find ( array (
  12825. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12826. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12827. 'groupby' => 'item,Month(date),itemCategory',
  12828. 'asArray' => true
  12829. ) );
  12830. if (! empty ( $receiptCollectList )) {
  12831. $receiptL = array (
  12832. '日常相关费用' => array (),
  12833. '差旅相关费用' => array (),
  12834. '培训班费用' => array (),
  12835. '其他' => array ()
  12836. );
  12837. $html = "";
  12838. $psum = 0;
  12839. $item = array (
  12840. '市内交通费',
  12841. '市内出租费',
  12842. '办事处房租',
  12843. '电话费',
  12844. '水费',
  12845. '电费',
  12846. '办公费用',
  12847. '邮寄费',
  12848. '其他费用',
  12849. '车辆费用',
  12850. '广告费',
  12851. '团队建设费',
  12852. '物业管理费',
  12853. '宽带费'
  12854. );
  12855. foreach ( $item as $va ) {
  12856. $falg = true;
  12857. foreach ( $receiptCollectList as $v ) {
  12858. if ($v ['itemCategory'] == '日常相关费用') {
  12859. if ($v ['item'] == $va) {
  12860. if ($va == '市内交通费')
  12861. $r1 += $v ['price'];
  12862. if ($va == '市内出租费')
  12863. $r2 += $v ['price'];
  12864. if ($va == '办事处房租')
  12865. $r3 += $v ['price'];
  12866. if ($va == '电话费')
  12867. $r4 += $v ['price'];
  12868. if ($va == '水费')
  12869. $r5 += $v ['price'];
  12870. if ($va == '电费')
  12871. $r6 += $v ['price'];
  12872. if ($va == '办公费用')
  12873. $r7 += $v ['price'];
  12874. if ($va == '邮寄费')
  12875. $r8 += $v ['price'];
  12876. if ($va == '其他费用')
  12877. $r9 += $v ['price'];
  12878. if ($va == '车辆费用')
  12879. $r10 += $v ['price'];
  12880. if ($va == '广告费')
  12881. $r11 += $v ['price'];
  12882. if ($va == '团队建设费')
  12883. $r13 += $v ['price'];
  12884. if ($va == '物业管理费')
  12885. $r14 += $v ['price'];
  12886. if ($va == '宽带费')
  12887. $r15 += $v ['price'];
  12888. $psum += $v ['price'];
  12889. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12890. $falg = false;
  12891. break;
  12892. }
  12893. }
  12894. }
  12895. if ($falg)
  12896. $html .= '<td class="taR">-</td>';
  12897. }
  12898. $r12 += $psum;
  12899. if (! empty ( $psum ))
  12900. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12901. else
  12902. $psum = '<td class="colGreen taR">-</td>';
  12903. $receiptL ['日常相关费用'] = $psum . $html;
  12904. /* ----------------------------------- */
  12905. $html = "";
  12906. $psum = 0;
  12907. $item = array (
  12908. '往来交通费',
  12909. '市内交通费',
  12910. '出差住宿费',
  12911. '出差补助',
  12912. '其他费用'
  12913. );
  12914. foreach ( $item as $va ) {
  12915. $falg = true;
  12916. foreach ( $receiptCollectList as $v ) {
  12917. if ($v ['itemCategory'] == '差旅相关费用') {
  12918. if ($v ['item'] == $va) {
  12919. if ($va == '往来交通费')
  12920. $c1 += $v ['price'];
  12921. if ($va == '市内交通费')
  12922. $c2 += $v ['price'];
  12923. if ($va == '出差住宿费')
  12924. $c3 += $v ['price'];
  12925. if ($va == '出差补助')
  12926. $c4 += $v ['price'];
  12927. if ($va == '其他费用')
  12928. $c5 += $v ['price'];
  12929. $psum += $v ['price'];
  12930. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12931. $falg = false;
  12932. break;
  12933. }
  12934. }
  12935. }
  12936. if ($falg)
  12937. $html .= '<td class="taR">-</td>';
  12938. }
  12939. $c6 += $psum;
  12940. if (! empty ( $psum ))
  12941. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12942. else
  12943. $psum = '<td class="colGreen taR">-</td>';
  12944. $receiptL ['差旅相关费用'] = $psum . $html;
  12945. /* ------------------------------------- */
  12946. $html = "";
  12947. $psum = 0;
  12948. $item = array (
  12949. '场租费',
  12950. '薪酬',
  12951. '住宿费',
  12952. '交通费',
  12953. '餐饮费',
  12954. '办公费',
  12955. '公关费',
  12956. '其他'
  12957. );
  12958. foreach ( $item as $va ) {
  12959. $falg = true;
  12960. foreach ( $receiptCollectList as $v ) {
  12961. if ($v ['itemCategory'] == '培训班费用') {
  12962. if ($v ['item'] == $va) {
  12963. if ($va == '场租费')
  12964. $p1 += $v ['price'];
  12965. if ($va == '薪酬')
  12966. $p2 += $v ['price'];
  12967. if ($va == '住宿费')
  12968. $p3 += $v ['price'];
  12969. if ($va == '交通费')
  12970. $p4 += $v ['price'];
  12971. if ($va == '餐饮费')
  12972. $p5 += $v ['price'];
  12973. if ($va == '办公费')
  12974. $p6 += $v ['price'];
  12975. if ($va == '公关费')
  12976. $p7 += $v ['price'];
  12977. if ($va == '其他')
  12978. $p8 += $v ['price'];
  12979. $psum += $v ['price'];
  12980. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12981. $falg = false;
  12982. break;
  12983. }
  12984. }
  12985. }
  12986. if ($falg)
  12987. $html .= '<td class="taR">-</td>';
  12988. }
  12989. $p9 += $psum;
  12990. if (! empty ( $psum ))
  12991. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12992. else
  12993. $psum = '<td class="colGreen taR">-</td>';
  12994. $receiptL ['培训班费用'] = $psum . $html;
  12995. /* ------------------------------------- */
  12996. $html = "";
  12997. $psum = 0;
  12998. $item = array (
  12999. '公关费',
  13000. '广告费',
  13001. '借款',
  13002. '可自加费用'
  13003. );
  13004. foreach ( $item as $va ) {
  13005. $falg = true;
  13006. foreach ( $receiptCollectList as $v ) {
  13007. if ($v ['itemCategory'] == '其他') {
  13008. if ($v ['item'] == $va) {
  13009. if ($va == '公关费')
  13010. $t1 += $v ['price'];
  13011. if ($va == '广告费')
  13012. $t2 += $v ['price'];
  13013. if ($va == '借款')
  13014. $t3 += $v ['price'];
  13015. if ($va == '可自加费用')
  13016. $t4 += $v ['price'];
  13017. $psum += $v ['price'];
  13018. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13019. $falg = false;
  13020. break;
  13021. }
  13022. }
  13023. }
  13024. if ($falg)
  13025. $html .= '<td class="taR">-</td>';
  13026. }
  13027. $t5 += $psum;
  13028. if (! empty ( $psum ))
  13029. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13030. else
  13031. $psum = '<td class="colGreen taR">-</td>';
  13032. $receiptL ['其他'] = $psum . $html;
  13033. /* ------------------------------------- */
  13034. $html = "";
  13035. $psum = 0;
  13036. foreach ( $receiptCollectList as $v ) {
  13037. if ($v ['itemCategory'] == '报销金额调整') {
  13038. if (! empty ( $v ['price'] )) {
  13039. $psum += $v ['price'];
  13040. }
  13041. }
  13042. }
  13043. $s1 += $psum;
  13044. if (! empty ( $psum ))
  13045. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13046. else
  13047. $psum = '<td class="taR colOrange">-</td>';
  13048. $receiptL ['报销金额调整'] = $psum . $html;
  13049. } else {
  13050. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13051. <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>';
  13052. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13053. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13054. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13055. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13056. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13057. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13058. }
  13059. $monthStaffPrice = $receiptDetail->find ( array (
  13060. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13061. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13062. 'asArray' => true
  13063. ) );
  13064. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13065. $m1 += $monthStaffPrice [0] ['price'];
  13066. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13067. } else
  13068. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13069. $list [$value ['username']] = $receiptL;
  13070. }
  13071. }
  13072. $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>
  13073. <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>
  13074. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13075. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13076. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13077. $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>
  13078. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13079. $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>';
  13080. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13081. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13082. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13083. }
  13084. $data ['list'] = $list;
  13085. $receiptCollectList = $receiptDetail->find ( array (
  13086. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13087. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13088. 'groupby' => 'item,Month(date),itemCategory',
  13089. 'asArray' => true
  13090. ) );
  13091. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13092. // statistics html
  13093. $stList = $statistics->getOne ( array (
  13094. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13095. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13096. 'groupby' => 'Month(date)',
  13097. 'asArray' => true
  13098. ) );
  13099. if (empty ( $stList ))
  13100. $stList = array (
  13101. 'rePrice' => 0,
  13102. 'agPrice' => 0
  13103. );
  13104. $data ['stList'] = array (
  13105. 'rePrice' => $stList ['rePrice'],
  13106. 'agPrice' => $stList ['agPrice'],
  13107. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13108. );
  13109. $monthHtml = "";
  13110. for($i = 1; $i <= 12; $i ++) {
  13111. if ($i == $month)
  13112. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13113. else
  13114. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13115. }
  13116. $data ['monthHtml'] = $monthHtml;
  13117. $data ['year'] = $year;
  13118. $data ['month'] = $month;
  13119. $data ['memu'] = "receipt";
  13120. $data ['staff'] = $this->staff;
  13121. $data ['receiptMemu'] = 'companyCategoryCollect';
  13122. $data ['verifyId'] = $this->verifyId;
  13123. $data ['executeId'] = $this->executeId;
  13124. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13125. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13126. }
  13127. /**
  13128. * 用户报销单列表
  13129. */
  13130. function receiptStatisticsStaffDetail() {
  13131. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13132. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13133. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13134. Doo::loadModel ( "receipt" );
  13135. $receipt = new receipt ();
  13136. Doo::loadModel ( "receiptDetail" );
  13137. $receiptDetail = new receiptDetail ();
  13138. Doo::loadModel ( 'staff' );
  13139. $staff = new staff ();
  13140. Doo::loadModel ( 'accountItem' );
  13141. $accountItem = new accountItem ();
  13142. Doo::loadModel ( 'statistics' );
  13143. $statistics = new statistics ();
  13144. if (! empty ( $username )) {
  13145. $username = addslashes ( urldecode ( $username ) );
  13146. $staffDetail = $staff->getStaffByName ( $username );
  13147. if (empty ( $staffDetail ))
  13148. die ( 'illegal request' );
  13149. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13150. $itemList = $accountItem->getAccountItem ();
  13151. $itemHtml = '';
  13152. $categoryHtml = '';
  13153. $itemKeyList = array_keys ( $itemList );
  13154. $revisePrice = 0;
  13155. // 报销单内容详情
  13156. foreach ( $list as $key => $value ) {
  13157. $accountItemList = json_decode ( $value ['accountItem'], true );
  13158. $list [$key] ['accountItemList'] = $accountItemList;
  13159. $receiptItemHtml = '';
  13160. foreach ( $itemKeyList as $v ) {
  13161. if ($v == '日常相关费用')
  13162. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13163. elseif ($v == '差旅相关费用')
  13164. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13165. elseif ($v == '培训班费用')
  13166. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13167. elseif ($v == '内部培训费用'){
  13168. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13169. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13170. }else{
  13171. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13172. }
  13173. }elseif ($v == '其他')
  13174. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13175. foreach ( $itemList [$v] as $ke => $va ) {
  13176. $falg = true;
  13177. if (! empty ( $accountItemList [$v] )) {
  13178. foreach ( $accountItemList [$v] as $ve ) {
  13179. if ($va ['name'] == $ve ['name']) {
  13180. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13181. $falg = false;
  13182. break;
  13183. }
  13184. }
  13185. }
  13186. if ($falg)
  13187. $receiptItemHtml .= '<td class="taR"></td>';
  13188. }
  13189. }
  13190. // 金额调整和费用查看
  13191. $revisePrice += $value ['revisePrice'];
  13192. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13193. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13194. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13195. }
  13196. // 报销单合计
  13197. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13198. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13199. $receiptTotalHtml = '';
  13200. // 报销单项目抬头
  13201. foreach ( $itemKeyList as $value ) {
  13202. $count = count ( $itemList [$value] ) + 1;
  13203. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13204. $categoryHtml .= '<th class="taC">合计</th>';
  13205. $sumfalg=true;
  13206. foreach ( $rtl as $rtlValue ) {
  13207. if ($rtlValue ['itemCategory'] == $value) {
  13208. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13209. $sumfalg=false;
  13210. break;
  13211. }
  13212. }
  13213. if ($sumfalg)
  13214. $receiptTotalHtml .= '<th></th>';
  13215. foreach ( $itemList [$value] as $k => $v ) {
  13216. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13217. // 合计
  13218. $falg = true;
  13219. foreach ( $receiptTotalList as $ve ) {
  13220. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13221. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13222. $falg = false;
  13223. break;
  13224. }
  13225. }
  13226. if ($falg)
  13227. $receiptTotalHtml .= '<th></th>';
  13228. }
  13229. }
  13230. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13231. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13232. if (empty ( $stList ))
  13233. $stList = array (
  13234. 'rePrice' => 0,
  13235. 'agPrice' => 0
  13236. );
  13237. $data ['stList'] = array (
  13238. 'rePrice' => $stList ['rePrice'],
  13239. 'agPrice' => $stList ['agPrice'],
  13240. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13241. );
  13242. $monthHtml = "";
  13243. for($i = 1; $i <= 12; $i ++) {
  13244. if ($i == $month)
  13245. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13246. else
  13247. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13248. }
  13249. $data ['username'] = urlencode ( $username );
  13250. $data ['usernameEN'] = $username;
  13251. $data ['monthHtml'] = $monthHtml;
  13252. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13253. $data ['list'] = $list;
  13254. $data ['categoryHtml'] = $categoryHtml;
  13255. $data ['itemHtml'] = $itemHtml;
  13256. $data ['itemList'] = $itemList;
  13257. $data ['year'] = $year;
  13258. $data ['month'] = $month;
  13259. $data ['memu'] = "receipt";
  13260. $data ['staff'] = $this->staff;
  13261. $data ['receiptMemu'] = 'companyCategoryCollect';
  13262. $data ['verifyId'] = $this->verifyId;
  13263. $data ['executeId'] = $this->executeId;
  13264. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13265. }
  13266. die ( 'illegal request' );
  13267. }
  13268. function companyMonthCollectDetail() {
  13269. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13270. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13271. if (! $year)
  13272. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13273. if (! $month)
  13274. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13275. Doo::loadModel ( 'staff' );
  13276. $staff = new staff ();
  13277. Doo::loadModel ( "receiptDetail" );
  13278. $receiptDetail = new receiptDetail ();
  13279. Doo::loadModel ( 'accountItem' );
  13280. $accountItem = new accountItem ();
  13281. Doo::loadModel ( 'statistics' );
  13282. $statistics = new statistics ();
  13283. Doo::loadModel ( 'L_category' );
  13284. $lCategory = new L_category ();
  13285. $staffList = $staff->find ( array (
  13286. 'where' => 'username!="admin"',
  13287. 'asArray' => true
  13288. ) );
  13289. $categoryList = $lCategory->find ( array (
  13290. 'asArray' => true
  13291. ) );
  13292. $aiList=$accountItem->getAccountItem();
  13293. $list = array ();
  13294. foreach ( $categoryList as $value ) {
  13295. $receiptCollectList = $receiptDetail->find ( array (
  13296. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13297. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13298. 'groupby' => 'item,Month(pastDate),itemCategory',
  13299. 'asArray' => true
  13300. ) );
  13301. if (! empty ( $receiptCollectList )) {
  13302. $receiptL = array (
  13303. '日常相关费用' => array (),
  13304. '差旅相关费用' => array (),
  13305. '内部培训费用' => array (),
  13306. '培训班费用' => array (),
  13307. '其他' => array ()
  13308. );
  13309. $html = "";
  13310. $psum = 0;
  13311. foreach ( $aiList[$this->AGENCY] as $va ) {
  13312. $falg = true;
  13313. foreach ( $receiptCollectList as $v ) {
  13314. if ($v ['itemCategory'] == $this->AGENCY) {
  13315. if ($v ['item'] == $va['name']) {
  13316. $psum += $v ['price'];
  13317. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13318. $falg = false;
  13319. break;
  13320. }
  13321. }
  13322. }
  13323. if ($falg)
  13324. $html .= '<td class="taR">-</td>';
  13325. }
  13326. if (! empty ( $psum ))
  13327. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13328. else
  13329. $psum = '<td class="colGreen taR">-</td>';
  13330. $receiptL [$this->AGENCY] = $psum . $html;
  13331. /* ----------------------------------- */
  13332. $html = "";
  13333. $psum = 0;
  13334. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13335. $falg = true;
  13336. foreach ( $receiptCollectList as $v ) {
  13337. if ($v ['itemCategory'] == $this->TRAVEL) {
  13338. if ($v ['item'] == $va['name']) {
  13339. $psum += $v ['price'];
  13340. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13341. $falg = false;
  13342. break;
  13343. }
  13344. }
  13345. }
  13346. if ($falg)
  13347. $html .= '<td class="taR">-</td>';
  13348. }
  13349. if (! empty ( $psum ))
  13350. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13351. else
  13352. $psum = '<td class="colGreen taR">-</td>';
  13353. $receiptL [$this->TRAVEL] = $psum . $html;
  13354. /* ------------------------------------- */
  13355. $html = "";
  13356. $psum = 0;
  13357. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13358. $falg = true;
  13359. foreach ( $receiptCollectList as $v ) {
  13360. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13361. if ($v ['item'] == $va['name']) {
  13362. $psum += $v ['price'];
  13363. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13364. $falg = false;
  13365. break;
  13366. }
  13367. }
  13368. }
  13369. if ($falg)
  13370. $html .= '<td class="taR">-</td>';
  13371. }
  13372. if (! empty ( $psum ))
  13373. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13374. else
  13375. $psum = '<td class="colGreen taR">-</td>';
  13376. $receiptL [$this->INTTRAIN] = $psum . $html;
  13377. /* ------------------------------------- */
  13378. $html = "";
  13379. $psum = 0;
  13380. foreach ( $aiList[$this->TRAIN] as $va ) {
  13381. $falg = true;
  13382. foreach ( $receiptCollectList as $v ) {
  13383. if ($v ['itemCategory'] == $this->TRAIN) {
  13384. if ($v ['item'] == $va['name']) {
  13385. $psum += $v ['price'];
  13386. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13387. $falg = false;
  13388. break;
  13389. }
  13390. }
  13391. }
  13392. if ($falg)
  13393. $html .= '<td class="taR">-</td>';
  13394. }
  13395. if (! empty ( $psum ))
  13396. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13397. else
  13398. $psum = '<td class="colGreen taR">-</td>';
  13399. $receiptL [$this->TRAIN] = $psum . $html;
  13400. /* ------------------------------------- */
  13401. $html = "";
  13402. $psum = 0;
  13403. foreach ( $aiList[$this->OTHER] as $va ) {
  13404. $falg = true;
  13405. foreach ( $receiptCollectList as $v ) {
  13406. if ($v ['itemCategory'] == $this->OTHER) {
  13407. if ($v ['item'] == $va['name']) {
  13408. $psum += $v ['price'];
  13409. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13410. $falg = false;
  13411. break;
  13412. }
  13413. }
  13414. }
  13415. if ($falg)
  13416. $html .= '<td class="taR">-</td>';
  13417. }
  13418. if (! empty ( $psum ))
  13419. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13420. else
  13421. $psum = '<td class="colGreen taR">-</td>';
  13422. $receiptL [$this->OTHER] = $psum . $html;
  13423. /* ------------------------------------- */
  13424. $html = "";
  13425. $psum = 0;
  13426. foreach ( $receiptCollectList as $v ) {
  13427. if ($v ['itemCategory'] == '报销金额调整') {
  13428. if (! empty ( $v ['price'] ))
  13429. $psum += $v ['price'];
  13430. }
  13431. }
  13432. if (! empty ( $psum ))
  13433. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13434. else
  13435. $psum = '<td class="taR colOrange">-</td>';
  13436. $receiptL ['报销金额调整'] = $psum . $html;
  13437. } else {
  13438. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13439. foreach ( $aiList[$this->AGENCY] as $va ) {
  13440. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13441. }
  13442. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13443. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13444. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13445. }
  13446. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13447. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13448. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13449. }
  13450. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13451. foreach ( $aiList[$this->TRAIN] as $va ) {
  13452. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13453. }
  13454. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13455. foreach ( $aiList[$this->OTHER] as $va ) {
  13456. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13457. }
  13458. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13459. }
  13460. $monthStaffPrice = $receiptDetail->find ( array (
  13461. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13462. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13463. 'asArray' => true
  13464. ) );
  13465. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13466. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13467. else
  13468. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13469. $list [$value ['title']] = $receiptL;
  13470. }
  13471. $data ['list'] = $list;
  13472. $receiptCollectList = $receiptDetail->find ( array (
  13473. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13474. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13475. 'groupby' => 'item,Month(pastDate),itemCategory',
  13476. 'asArray' => true
  13477. ) );
  13478. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13479. //print_r($data['monthPriceHtml']);
  13480. // foreach ($data['monthPriceHtml'] as $value){
  13481. // echo $value;
  13482. // }
  13483. // die;
  13484. // statistics html
  13485. $stList = $statistics->getOne ( array (
  13486. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13487. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13488. 'groupby' => 'Month(date)',
  13489. 'asArray' => true
  13490. ) );
  13491. if (empty ( $stList ))
  13492. $stList = array (
  13493. 'rePrice' => 0,
  13494. 'agPrice' => 0
  13495. );
  13496. $data ['stList'] = array (
  13497. 'rePrice' => $stList ['rePrice'],
  13498. 'agPrice' => $stList ['agPrice'],
  13499. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13500. );
  13501. $monthHtml = "";
  13502. for($i = 1; $i <= 12; $i ++) {
  13503. if ($i == $month)
  13504. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13505. else
  13506. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13507. }
  13508. $data ['aiList'] = $aiList;
  13509. $dateHtml = "";
  13510. $now = date ( "Y" );
  13511. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13512. if ($YEARD <= $now) {
  13513. $dateHtml .= '<option ';
  13514. if ($year == $YEARD) {
  13515. $dateHtml .= 'selected ';
  13516. }
  13517. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13518. }
  13519. }
  13520. $data ['dateHtml'] = $dateHtml;
  13521. $data ['monthHtml'] = $monthHtml;
  13522. $data ['year'] = $year;
  13523. $data ['month'] = $month;
  13524. $data ['memu'] = "receipt";
  13525. $data ['staff'] = $this->staff;
  13526. $data ['receiptMemu'] = 'companyCategoryCollect';
  13527. $data ['verifyId'] = $this->verifyId;
  13528. $data ['executeId'] = $this->executeId;
  13529. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13530. }
  13531. function staffCollectDetail() {
  13532. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13533. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13534. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13535. if (! $staffname) {
  13536. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13537. $staffname = urldecode ( $staffname );
  13538. }
  13539. Doo::loadModel ( 'staff' );
  13540. $staff = new staff ();
  13541. Doo::loadModel ( "receiptDetail" );
  13542. $receiptDetail = new receiptDetail ();
  13543. Doo::loadModel ( 'accountItem' );
  13544. $accountItem = new accountItem ();
  13545. Doo::loadModel ( 'statistics' );
  13546. $statistics = new statistics ();
  13547. Doo::loadModel ( 'L_category' );
  13548. $lCategory = new L_category ();
  13549. Doo::loadModel ( "receiptAuthorityManage" );
  13550. $receiptAuthorityManage = new receiptAuthorityManage ();
  13551. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13552. $cidList = array ();
  13553. foreach ( $imcStaff as $key => $value ) {
  13554. array_push ( $cidList, $value ['cid'] );
  13555. }
  13556. $cidString = implode ( ',', $cidList );
  13557. $staffList = $staff->find ( array (
  13558. 'where' => ' cid in (' . $cidString . ')',
  13559. 'asArray' => true
  13560. ) );
  13561. $stHtml = '';
  13562. $stTitle = "";
  13563. $staffId = 0;
  13564. $cid = 0;
  13565. $ocid = 0;
  13566. foreach ( $staffList as $value ) {
  13567. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13568. $stTitle = $value ['category'] . '-' . $value ['username'];
  13569. $staffId = $value ['sid'];
  13570. $cid = $value ['cid'];
  13571. $ocid = $value ['cid'];
  13572. if (! empty ( $value ['othercid'] ))
  13573. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13574. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13575. } elseif ($value ['username'] != 'admin')
  13576. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13577. }
  13578. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13579. 'where' => 'cid in(' . $cid . ')',
  13580. 'asArray' => true
  13581. ) );
  13582. if (empty ( $pcid ))
  13583. $pcid = $ocid;
  13584. $data ['ocid'] = $pcid;
  13585. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13586. $this->showCache ( $path );
  13587. //
  13588. $receiptCollectList = $receiptDetail->find ( array (
  13589. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13590. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13591. 'groupby' => 'item,Month(pastDate),itemCategory',
  13592. 'asArray' => true
  13593. ) );
  13594. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13595. // print_r($receiptCollectList);
  13596. $accountList = $accountItem->find ( array (
  13597. 'asArray' => true
  13598. ) );
  13599. // create CollectDetail HTML
  13600. $collectHtml = array ();
  13601. foreach ( $accountList as $key => $value ) {
  13602. $html = "";
  13603. $asum = 0;
  13604. for($i = 1; $i <= 12; $i ++) {
  13605. $falg = true;
  13606. foreach ( $receiptCollectList as $v ) {
  13607. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13608. if ($v ['item'] == '可自加费用') {
  13609. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13610. }
  13611. $asum += $v ['price'];
  13612. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13613. $falg = false;
  13614. break;
  13615. }
  13616. }
  13617. if ($falg)
  13618. $html .= '<td class="taR">-</td>';
  13619. }
  13620. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13621. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13622. }
  13623. $data ['collectHtml'] = $collectHtml;
  13624. // print_r($collectHtml);
  13625. // create Adjustment price html
  13626. $receiptCollectList = $receiptDetail->find ( array (
  13627. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13628. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13629. 'groupby' => 'itemCategory,Month(pastDate)',
  13630. 'asArray' => true
  13631. ) );
  13632. $adjustment = array ();
  13633. $collectArray = array (
  13634. '日常相关费用' => array (),
  13635. '差旅相关费用' => array (),
  13636. '培训班费用' => array (),
  13637. '内部培训费用'=>array(),
  13638. '其他' => array ()
  13639. );
  13640. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13641. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13642. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13643. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13644. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13645. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13646. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13647. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13648. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13649. array_push ( $collectArray ['其他'], $collectHtml );
  13650. $data ['collectArray'] = $collectArray;
  13651. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13652. array_push ( $adjustment, $collectHtml );
  13653. $data ['adjustment'] = $adjustment;
  13654. // total price html
  13655. $collectHtml = "";
  13656. $total = 0;
  13657. for($i = 1; $i <= 12; $i ++) {
  13658. $sumPrice = 0;
  13659. foreach ( $receiptCollectList as $key => $value ) {
  13660. if ($value ['month'] == $i) {
  13661. $sumPrice += $value ['price'];
  13662. }
  13663. }
  13664. if ($sumPrice == 0)
  13665. $collectHtml .= '<td class="taR">-</td>';
  13666. else
  13667. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13668. $total += $sumPrice;
  13669. }
  13670. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13671. // statistics html
  13672. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13673. if (empty ( $stList ))
  13674. $stList = array (
  13675. 'rePrice' => 0,
  13676. 'agPrice' => 0
  13677. );
  13678. $data ['stList'] = array (
  13679. 'rePrice' => $stList ['rePrice'],
  13680. 'agPrice' => $stList ['agPrice'],
  13681. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13682. );
  13683. $data ['totalPrice'] = $collectHtml;
  13684. $data ['totalYear'] = $total;
  13685. $data ['stHtml'] = $stHtml;
  13686. $data ['year'] = $year;
  13687. $data ['stTitle'] = $stTitle;
  13688. $data ['staffname'] = urlencode ( $staffname );
  13689. $data ['memu'] = "receipt";
  13690. $data ['staff'] = $this->staff;
  13691. $data ['receiptMemu'] = 'companyCategoryCollect';
  13692. $data ['verifyId'] = $this->verifyId;
  13693. $data ['executeId'] = $this->executeId;
  13694. if ($year < date ( "Y" )) {
  13695. Doo::loadModel ( 'receipt' );
  13696. $receipt = new receipt ();
  13697. $receiptList = $receipt->find ( array (
  13698. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13699. 'asArray' => true
  13700. ) );
  13701. if (empty ( $receiptList )) { // generated files
  13702. ob_start ();
  13703. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13704. $this->cacheFile ( $path );
  13705. die ();
  13706. }
  13707. }
  13708. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13709. }
  13710. function BUGFLAG() {
  13711. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13712. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13713. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13714. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13715. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13716. if (empty ( $status ))
  13717. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13718. $page_size = 12;
  13719. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13720. $vidList = array ();
  13721. $button = 0;
  13722. Doo::loadModel ( 'verify' );
  13723. $verify = new verify ();
  13724. Doo::loadModel ( 'receipt' );
  13725. $receipt = new receipt ();
  13726. Doo::loadModel ( 'staff' );
  13727. $staff = new staff ();
  13728. Doo::loadModel ( 'L_category' );
  13729. $Lcategory = new L_category ();
  13730. $dateCondition = " and Year(date) =" . $year;
  13731. if (! empty ( $month ))
  13732. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13733. $categoryList = $Lcategory->find ( array (
  13734. 'asArray' => true
  13735. ) );
  13736. $staffList = $staff->find ( array (
  13737. 'where' => 'cid=' . $cid,
  13738. 'asArray' => true
  13739. ) );
  13740. $cateCondition = "";
  13741. $staffCondition = "";
  13742. $approvalCondition = "";
  13743. if (! empty ( $cid ))
  13744. $cateCondition = ' and cid=' . $cid;
  13745. if (! empty ( $sid )) {
  13746. $staffCondition = ' and staff=' . $sid;
  13747. $cateCondition = "";
  13748. }
  13749. $approvalCondition = " and status=" . $status;
  13750. if ($status == 2) {
  13751. // 查找角色审批人
  13752. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13753. }
  13754. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13755. $approvalCondition = ' and status=2 ';
  13756. }
  13757. if ($status == 1) {
  13758. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13759. }
  13760. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13761. $pageinfo ['page'] = array (
  13762. 'previous' => ''
  13763. );
  13764. if ($status == 0) {
  13765. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13766. $receiptList = $receipt->find ( array (
  13767. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13768. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13769. 'desc' => 'rid',
  13770. 'asArray' => true
  13771. ) );
  13772. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13773. } else
  13774. $receiptList = $receipt->find ( array (
  13775. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13776. 'desc' => 'rid',
  13777. 'asArray' => true
  13778. ) );
  13779. $rLRes = $receipt->find ( array (
  13780. '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,
  13781. 'desc' => 'rid',
  13782. 'asArray' => true
  13783. ) );
  13784. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13785. // print_r($pageinfo);
  13786. $Locate = 0;
  13787. foreach ( $receiptList as $key => $value ) {
  13788. $receiptList [$key] ['Locate'] = $Locate;
  13789. $Locate ++;
  13790. $receiptList [$key] ['reviseDetail'] = array ();
  13791. if (! empty ( $value ['reviseDetail'] ))
  13792. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13793. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13794. $categoryDetil = $Lcategory->getOne ( array (
  13795. 'where' => 'cid=' . $value ['cid'],
  13796. 'asArray' => true
  13797. ) );
  13798. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13799. $verifyList = $verify->getOne ( array (
  13800. 'where' => 'vid=' . $value ['verify'],
  13801. 'asArray' => true
  13802. ) );
  13803. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13804. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13805. foreach ( $verifyList as $k => $v ) {
  13806. // init verifyStaff
  13807. $verifyList [$k] ['date'] = "";
  13808. $verifyList [$k] ['opinion'] = "";
  13809. $verifyList [$k] ['status'] = "";
  13810. if (empty ( $verifyStaff )) {
  13811. $verifyList [$k] ['date'] = "";
  13812. $verifyList [$k] ['opinion'] = "";
  13813. if ($v [0] == $this->staff [0] ['sid']) {
  13814. $verifyList [$k] ['status'] = 4;
  13815. $button = 4;
  13816. }
  13817. } else {
  13818. $flag = true;
  13819. foreach ( $verifyStaff as $m => $u ) {
  13820. if ($v [0] == $m) {
  13821. $verifyList [$k] ['date'] = $u ['date'];
  13822. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13823. $verifyList [$k] ['status'] = $u ['status'];
  13824. $flag = false;
  13825. break;
  13826. }
  13827. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13828. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13829. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13830. }
  13831. if ($flag) { // 检测可编辑
  13832. if ($v [0] == $this->staff [0] ['sid']) {
  13833. $verifyList [$k] ['status'] = 4;
  13834. $button = 4;
  13835. }
  13836. }
  13837. }
  13838. }
  13839. $receiptList [$key] ['verifyList'] = $verifyList;
  13840. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13841. 'where' => 'sid=' . $value ['staff'],
  13842. 'asArray' => true
  13843. ) );
  13844. $receiptList [$key] ['button'] = $button;
  13845. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13846. }
  13847. // print_r($receiptList);die;
  13848. // $data['verifyDetail']=$verifyDetail;
  13849. $mothHtml = "";
  13850. for($i = 1; $i <= 12; $i ++) {
  13851. if ($month == $i)
  13852. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13853. else
  13854. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13855. }
  13856. $data ['mothHtml'] = $mothHtml;
  13857. $data ['page'] = $pageinfo;
  13858. $data ['receiptList'] = $receiptList;
  13859. $data ['receiptApprovalCount'] = count ( $rLRes );
  13860. $data ['status'] = $status;
  13861. $data ['year'] = $year;
  13862. $data ['categoryList'] = $categoryList;
  13863. $data ['staffList'] = $staffList;
  13864. $data ['cid'] = $cid;
  13865. $data ['sid'] = $sid;
  13866. // print_r($receiptList);
  13867. $data ['memu'] = "receipt";
  13868. $data ['staff'] = $this->staff;
  13869. $data ['receiptMemu'] = 'approvalExpenses';
  13870. $data ['verifyId'] = $this->verifyId;
  13871. $data ['executeId'] = $this->executeId;
  13872. $this->render ( "/admin/FALG", $data );
  13873. }
  13874. function ajaxGetReceiptOrder() {
  13875. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13876. if (! empty ( $receiptOrder )) {
  13877. Doo::loadModel ( 'receipt' );
  13878. $receipt = new receipt ();
  13879. Doo::loadModel ( 'staff' );
  13880. $staff = new staff ();
  13881. $receiptInfo = $receipt->getOne ( array (
  13882. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13883. 'asArray' => true
  13884. ) );
  13885. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13886. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13887. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13888. </tbody></table><table class="table table table-bordered"><tbody>';
  13889. foreach ( $verifyStaff as $key => $value ) {
  13890. $staffInfo = $staff->getOne ( array (
  13891. 'select' => 'username',
  13892. 'where' => ' sid="' . $key . '"',
  13893. 'asArray' => true
  13894. ) );
  13895. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13896. }
  13897. $html .= '</tbody></table></div></div>';
  13898. echo json_encode ( array (
  13899. 'status' => 1,
  13900. 'receiptHtml' => $html
  13901. ) );
  13902. die ();
  13903. }
  13904. echo json_encode ( array (
  13905. 'status' => 2,
  13906. 'receiptHtml' => ''
  13907. ) );
  13908. die ();
  13909. }
  13910. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13911. if (! empty ( $receiptCollectList )) {
  13912. $receiptL = array (
  13913. '日常相关费用' => array (),
  13914. '差旅相关费用' => array (),
  13915. '内部培训费用'=>array(),
  13916. '培训班费用' => array (),
  13917. '其他' => array ()
  13918. );
  13919. $html = "";
  13920. $psum = 0;
  13921. foreach ( $aiList[$this->AGENCY] as $value ) {
  13922. $falg = true;
  13923. foreach ( $receiptCollectList as $v ) {
  13924. if ($v ['itemCategory'] == '日常相关费用') {
  13925. if ($v ['item'] == $value['name']) {
  13926. $psum += $v ['price'];
  13927. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13928. $falg = false;
  13929. break;
  13930. }
  13931. }
  13932. }
  13933. if ($falg)
  13934. $html .= '<td class="taR">-</td>';
  13935. }
  13936. if (! empty ( $psum ))
  13937. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13938. else
  13939. $psum = '<td class="colGreen taR">-</td>';
  13940. $receiptL ['日常相关费用'] = $psum . $html;
  13941. /* ----------------------------------- */
  13942. $html = "";
  13943. $psum = 0;
  13944. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13945. $falg = true;
  13946. foreach ( $receiptCollectList as $v ) {
  13947. if ($v ['itemCategory'] == '差旅相关费用') {
  13948. if ($v ['item'] == $value['name']) {
  13949. $psum += $v ['price'];
  13950. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13951. $falg = false;
  13952. break;
  13953. }
  13954. }
  13955. }
  13956. if ($falg)
  13957. $html .= '<td class="taR">-</td>';
  13958. }
  13959. if (! empty ( $psum ))
  13960. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13961. else
  13962. $psum = '<td class="colGreen taR">-</td>';
  13963. $receiptL ['差旅相关费用'] = $psum . $html;
  13964. /* ----------------------------------- */
  13965. $html = "";
  13966. $psum = 0;
  13967. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13968. $falg = true;
  13969. foreach ( $receiptCollectList as $v ) {
  13970. if ($v ['itemCategory'] == '内部培训费用') {
  13971. if ($v ['item'] == $value['name']) {
  13972. $psum += $v ['price'];
  13973. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13974. $falg = false;
  13975. break;
  13976. }
  13977. }
  13978. }
  13979. if ($falg)
  13980. $html .= '<td class="taR">-</td>';
  13981. }
  13982. if (! empty ( $psum ))
  13983. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13984. else
  13985. $psum = '<td class="colGreen taR">-</td>';
  13986. $receiptL ['内部培训费用'] = $psum . $html;
  13987. /* ------------------------------------- */
  13988. $html = "";
  13989. $psum = 0;
  13990. foreach ( $aiList[$this->TRAIN] as $value ) {
  13991. $falg = true;
  13992. foreach ( $receiptCollectList as $v ) {
  13993. if ($v ['itemCategory'] == '培训班费用') {
  13994. if ($v ['item'] == $value['name']) {
  13995. $psum += $v ['price'];
  13996. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13997. $falg = false;
  13998. break;
  13999. }
  14000. }
  14001. }
  14002. if ($falg)
  14003. $html .= '<td class="taR">-</td>';
  14004. }
  14005. if (! empty ( $psum ))
  14006. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14007. else
  14008. $psum = '<td class="colGreen taR">-</td>';
  14009. $receiptL ['培训班费用'] = $psum . $html;
  14010. /* ------------------------------------- */
  14011. $html = "";
  14012. $psum = 0;
  14013. foreach ( $aiList[$this->OTHER] as $value ) {
  14014. $falg = true;
  14015. foreach ( $receiptCollectList as $v ) {
  14016. if ($v ['itemCategory'] == '其他') {
  14017. if ($v ['item'] == $value['name']) {
  14018. $psum += $v ['price'];
  14019. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14020. $falg = false;
  14021. break;
  14022. }
  14023. }
  14024. }
  14025. if ($falg)
  14026. $html .= '<td class="taR">-</td>';
  14027. }
  14028. if (! empty ( $psum ))
  14029. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14030. else
  14031. $psum = '<td class="colGreen taR">-</td>';
  14032. $receiptL ['其他'] = $psum . $html;
  14033. /* ------------------------------------- */
  14034. $html = "";
  14035. $psum = 0;
  14036. foreach ( $receiptCollectList as $v ) {
  14037. if ($v ['itemCategory'] == '报销金额调整') {
  14038. if (! empty ( $v ['price'] ))
  14039. $psum += $v ['price'];
  14040. }
  14041. }
  14042. if (! empty ( $psum ))
  14043. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14044. else
  14045. $psum = '<td class="taR colOrange">-</td>';
  14046. $receiptL ['报销金额调整'] = $psum . $html;
  14047. } else {
  14048. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14049. foreach ( $aiList[$this->AGENCY] as $va ) {
  14050. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14051. }
  14052. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14053. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14054. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14055. }
  14056. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14057. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14058. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14059. }
  14060. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14061. foreach ( $aiList[$this->TRAIN] as $va ) {
  14062. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14063. }
  14064. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14065. foreach ( $aiList[$this->OTHER] as $va ) {
  14066. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14067. }
  14068. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14069. }
  14070. return $receiptL;
  14071. }
  14072. function eMail() {
  14073. Doo::loadModel ( 'staff' );
  14074. $staff = new staff ();
  14075. Doo::loadModel ( 'receipt' );
  14076. $receipt = new receipt ();
  14077. Doo::loadModel ( 'L_category' );
  14078. $Lcategory = new L_category ();
  14079. Doo::loadModel ( "verify" );
  14080. $verify = new verify ();
  14081. $staffList = $staff->find ( array (
  14082. 'asArray' => true
  14083. ) );
  14084. foreach ( $staffList as $key => $value ) {
  14085. if ($value ['username'] != 'admin') {
  14086. // 提交人
  14087. $receiptList = $receipt->find ( array (
  14088. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14089. 'asArray' => true
  14090. ) );
  14091. if (! empty ( $receiptList )) {
  14092. $html = '<br><div><style></style>
  14093. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14094. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14095. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14096. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14097. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14098. <tbody><tr>
  14099. <td style="padding: 0 40px;" align="left">
  14100. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14101. </td></tr><tr>
  14102. <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>
  14103. </tr>
  14104. </tbody> </table></td> </tr> <tr><td>
  14105. <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">
  14106. <tbody> <tr><td>
  14107. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14108. 以下报销单完成了审批,等着收款吧:</p>
  14109. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14110. foreach ( $receiptList as $k => $v ) {
  14111. $category = $Lcategory->getOne ( array (
  14112. 'where' => 'cid=' . $v ['cid'],
  14113. 'asArray' => true
  14114. ) );
  14115. $html .= '
  14116. <tr>
  14117. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14118. <td align="left">
  14119. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14120. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14121. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14122. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14123. </tr>';
  14124. }
  14125. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14126. <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>
  14127. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14128. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14129. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14130. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14131. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14132. $receipt = new receipt ();
  14133. $receipt->notice = 1;
  14134. $receipt->update ( array (
  14135. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14136. ) );
  14137. }
  14138. }
  14139. // 审批人
  14140. $verifyList = $verify->find ( array (
  14141. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14142. 'asArray' => true
  14143. ) );
  14144. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14145. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14146. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14147. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14148. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14149. <tbody><tr><td style="padding: 0 40px;" align="left">
  14150. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14151. </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>
  14152. </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">
  14153. <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>
  14154. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14155. foreach ( $verifyList as $k => $v ) {
  14156. $receiptList = $receipt->find ( array (
  14157. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14158. 'asArray' => true
  14159. ) );
  14160. foreach ( $receiptList as $r => $l ) {
  14161. $category = $Lcategory->getOne ( array (
  14162. 'where' => 'cid=' . $l ['cid'],
  14163. 'asArray' => true
  14164. ) );
  14165. $staffDetile = $staff->getOne ( array (
  14166. 'where' => 'sid=' . $l ['staff'],
  14167. 'asArray' => true
  14168. ) );
  14169. $html .= '
  14170. <tr>
  14171. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14172. <td align="left">
  14173. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14174. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14175. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14176. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14177. </tr>';
  14178. }
  14179. }
  14180. $html .= '
  14181. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14182. <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>
  14183. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14184. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14185. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14186. // $receipt=new receipt();
  14187. // $receipt->notice=1;
  14188. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14189. }
  14190. }
  14191. }
  14192. }
  14193. function setWXMsg($rid, $type) {
  14194. Doo::loadModel ( "receipt" );
  14195. $receipt = new receipt ();
  14196. $receiptDetail = $receipt->getOne ( array (
  14197. 'where' => 'rid=' . $rid,
  14198. 'asArray' => true
  14199. ) );
  14200. if (! empty ( $receiptDetail )) {
  14201. Doo::loadModel ( 'staff' );
  14202. $staff = new staff ();
  14203. $staffmsg = $staff->getOne ( array (
  14204. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14205. 'asArray' => TRUE
  14206. ) );
  14207. if (! empty ( $staffmsg ['wxid'] )) {
  14208. require_once (SITE_PATH . '/protected/class/client.php');
  14209. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14210. $user = $staffmsg ['wxid'];
  14211. $receiptName = '';
  14212. $msg = '';
  14213. switch ($receiptDetail ['Rtype']) {
  14214. case 0 :
  14215. $receiptName = '报销';
  14216. break;
  14217. case 1 :
  14218. $receiptName = '借款';
  14219. break;
  14220. case 2 :
  14221. $receiptName = '对公汇款';
  14222. break;
  14223. }
  14224. switch ($type) {
  14225. case 1 :
  14226. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14227. break;
  14228. case 2 :
  14229. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14230. break;
  14231. case 3 :
  14232. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14233. break;
  14234. }
  14235. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14236. }
  14237. }
  14238. }
  14239. // Email发送函数
  14240. function SMail($toemail, $subject, $contents) {
  14241. Doo::loadClass ( 'class.phpmailer' );
  14242. $mail = new PHPMailer ();
  14243. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14244. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14245. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14246. $mail->Password = "cDO1GjtY1seH"; // 密码
  14247. $mail->CharSet = "UTF8";
  14248. $mail->SMTPAuth = true;
  14249. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14250. $mail->Mailer = "smtp";
  14251. $mail->Port = 25;
  14252. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14253. $mail->MsgHTML ( $contents );
  14254. $mail->AddAddress ( $toemail );
  14255. $mail->CharSet = "UTF-8";
  14256. return $mail->Send ();
  14257. }
  14258. function h5Upload() {
  14259. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14260. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14261. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14262. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14263. header ( "HTTP/1.1 500 Internal Server Error" );
  14264. echo "POST exceeded maximum allowed size.";
  14265. exit ( 0 );
  14266. }
  14267. // Settings
  14268. $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)
  14269. $upload_name = "Filedata";
  14270. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14271. $extension_whitelist = array (
  14272. "doc",
  14273. "txt",
  14274. "jpg",
  14275. "gif",
  14276. "png"
  14277. ); // Allowed file extensions
  14278. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14279. // Other variables
  14280. $MAX_FILENAME_LENGTH = 260;
  14281. $file_name = "";
  14282. $file_extension = "";
  14283. $uploadErrors = array (
  14284. 0 => "文件上传成功",
  14285. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14286. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14287. 3 => "上传的文件仅为部分文件",
  14288. 4 => "没有文件上传",
  14289. 6 => "缺少临时文件夹"
  14290. );
  14291. $nk = time ();
  14292. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14293. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14294. echo "文件无法保存.";
  14295. exit ( 0 );
  14296. }
  14297. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14298. echo json_encode ( array (
  14299. 'filename' => $file_name,
  14300. 'id' => $nk
  14301. ) );
  14302. exit ( 0 );
  14303. }
  14304. function swfupload() {
  14305. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14306. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14307. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14308. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14309. header ( "HTTP/1.1 500 Internal Server Error" );
  14310. echo "POST exceeded maximum allowed size.";
  14311. exit ( 0 );
  14312. }
  14313. // Settings
  14314. $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)
  14315. $upload_name = "Filedata";
  14316. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14317. $extension_whitelist = array (
  14318. "doc",
  14319. "txt",
  14320. "jpg",
  14321. "gif",
  14322. "png"
  14323. ); // Allowed file extensions
  14324. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14325. // Other variables
  14326. $MAX_FILENAME_LENGTH = 260;
  14327. $file_name = "";
  14328. $file_extension = "";
  14329. $uploadErrors = array (
  14330. 0 => "文件上传成功",
  14331. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14332. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14333. 3 => "上传的文件仅为部分文件",
  14334. 4 => "没有文件上传",
  14335. 6 => "缺少临时文件夹"
  14336. );
  14337. $nk = time ();
  14338. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14339. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14340. echo "文件无法保存.";
  14341. exit ( 0 );
  14342. }
  14343. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14344. echo json_encode ( array (
  14345. 'filename' => $file_name,
  14346. 'id' => $nk
  14347. ) );
  14348. exit ( 0 );
  14349. }
  14350. function _GetFileEXT($filename) {
  14351. $pics = explode ( '.', $filename );
  14352. $num = count ( $pics );
  14353. return $pics [$num - 1];
  14354. }
  14355. /**
  14356. * 获取get或者POST值
  14357. * @param string $name 属性名称
  14358. * @return fixed 值
  14359. */
  14360. function get_args($name) {
  14361. if (isset ( $_GET [$name] )) {
  14362. if (is_array ( $_GET [$name] ))
  14363. return $_GET [$name];
  14364. else
  14365. return addslashes ( $_GET [$name] );
  14366. } elseif (isset ( $_POST [$name] )) {
  14367. if (is_array ( $_POST [$name] ))
  14368. return $_POST [$name];
  14369. else
  14370. return addslashes ( $_POST [$name] );
  14371. } else
  14372. return false;
  14373. }
  14374. function num_to_rmb($num) {
  14375. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14376. $c2 = "分角元拾佰仟万拾佰仟亿";
  14377. // 精确到分后面就不要了,所以只留两个小数位
  14378. $num = round ( $num, 2 );
  14379. // 将数字转化为整数
  14380. $num = $num * 100;
  14381. if (strlen ( $num ) > 10) {
  14382. return "金额太大,请检查";
  14383. }
  14384. $i = 0;
  14385. $c = "";
  14386. while ( 1 ) {
  14387. if ($i == 0) {
  14388. // 获取最后一位数字
  14389. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14390. } else {
  14391. $n = $num % 10;
  14392. }
  14393. // 每次将最后一位数字转化为中文
  14394. $p1 = substr ( $c1, 3 * $n, 3 );
  14395. $p2 = substr ( $c2, 3 * $i, 3 );
  14396. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14397. $c = $p1 . $p2 . $c;
  14398. } else {
  14399. $c = $p1 . $c;
  14400. }
  14401. $i = $i + 1;
  14402. // 去掉数字最后一位了
  14403. $num = $num / 10;
  14404. // echo $num.'</br>';
  14405. $num = ( int ) $num;
  14406. // $num =floor($num);
  14407. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14408. // echo $num.'</br>';
  14409. // 结束循环
  14410. if ($num == 0) {
  14411. break;
  14412. }
  14413. }
  14414. // echo $c.'</br>';
  14415. $j = 0;
  14416. $slen = strlen ( $c );
  14417. while ( $j < $slen ) {
  14418. // utf8一个汉字相当3个字符
  14419. $m = substr ( $c, $j, 6 );
  14420. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14421. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14422. $left = substr ( $c, 0, $j );
  14423. $right = substr ( $c, $j + 3 );
  14424. $c = $left . $right;
  14425. $j = $j - 3;
  14426. $slen = $slen - 3;
  14427. }
  14428. $j = $j + 3;
  14429. }
  14430. // 这个是为了去掉类似23.0中最后一个“零”字
  14431. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14432. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14433. }
  14434. // 将处理的汉字加上“整”
  14435. if (empty ( $c )) {
  14436. return "零元整";
  14437. } else {
  14438. return $c . "整";
  14439. }
  14440. }
  14441. /**
  14442. * 获得分页数据
  14443. * @param unknown_type $table
  14444. * @param unknown_type $condition
  14445. * @param unknown_type $on_page
  14446. * @param unknown_type $page_size
  14447. */
  14448. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14449. $page_c = "";
  14450. $page ['previous'] = $this->get_previous ( $on_page );
  14451. $page ['on_page'] = $on_page;
  14452. $total_count = $this->get_table_count ( $table, $condition );
  14453. $total = intval ( $total_count / $page_size );
  14454. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14455. $page ['total_data'] = $total_count;
  14456. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14457. $i = 1;
  14458. $page_max = 1;
  14459. $page_width = 3;
  14460. if ($on_page >= $page_width) {
  14461. $page_max = intval ( $on_page / $page_width ) + 1;
  14462. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14463. }
  14464. for(; $i <= $page ['total_page']; $i ++) {
  14465. if ($i == $on_page)
  14466. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14467. else
  14468. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14469. if ($i == ($page_width * $page_max))
  14470. break;
  14471. }
  14472. $page ['page'] = $page_c;
  14473. $page ['lower'] = (-- $on_page) * $page_size;
  14474. return $page;
  14475. }
  14476. /**
  14477. * 获取总页数
  14478. * @param unknown_type $table
  14479. * @param unknown_type $condition
  14480. */
  14481. public function get_table_count($table = "", $condition = "") {
  14482. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14483. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14484. // echo $sql;die;
  14485. $query = Doo::db ()->query ( $sql );
  14486. $result = $query->fetch ();
  14487. return $result ['count'];
  14488. }
  14489. /**
  14490. * 获取上一页
  14491. * @param unknown_type $on_page
  14492. */
  14493. function get_previous($on_page = 1) {
  14494. return $on_page != 0 ? $on_page - 1 : $on_page;
  14495. }
  14496. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14497. // 收入合计
  14498. Doo::loadModel ( 'invoiceTraining' );
  14499. $invoiceTraining = new invoiceTraining ();
  14500. Doo::loadModel ( 'receipt' );
  14501. $receipt = new receipt ();
  14502. $invoiceTrainingDetail = array (
  14503. 'invoiceArriveAmount' => '0.00',
  14504. 'RIAmount' => '0.00',
  14505. 'invoiceTotalAmount' => '0.00',
  14506. 'invoiceCompanyAmount' => '0.00',
  14507. 'invoiceArriveAmountM'=>'0.00',
  14508. 'invoiceCompanyAmountM'=>'0.00'
  14509. );
  14510. if ($invoiceTrainId != 0) {
  14511. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14512. }
  14513. $invoiceArriveAmount = $RIAmount = 0;
  14514. if (! empty ( $invoiceTrainingDetail )) {
  14515. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14516. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14517. }
  14518. // 备用金
  14519. $sum = 0;
  14520. if (! empty ( $trainLoanRid )) {
  14521. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14522. foreach ($receiptLoanList as $key=>$value){
  14523. $sum+=$value['sum'];
  14524. }
  14525. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14526. // $sum = $receiptLoanDetailBak ['sum'];
  14527. }
  14528. // 支出项金额详情
  14529. // 项目金额合计
  14530. Doo::loadModel ( 'RItem' );
  14531. $RItem = new RItem ();
  14532. Doo::loadModel ( 'accountItem' );
  14533. $accountItem = new accountItem ();
  14534. // 讲师获得
  14535. Doo::loadModel ( 'RILecturer' );
  14536. $RILecturer = new RILecturer ();
  14537. $RItemList = $RItem->getRItemByRid ($rid );
  14538. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14539. // 支出项金额详情
  14540. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14541. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14542. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14543. return $payment;
  14544. }
  14545. }
  14546. ?>