ReceiptController.php 520 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040
  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. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  15. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  16. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  17. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  18. private function showCache($path) {
  19. if (file_exists ( $path )) {
  20. echo "<!DOCTYPE html>";
  21. include $path;
  22. die ();
  23. }
  24. }
  25. private function cacheFile($path) {
  26. $content = ob_get_contents ();
  27. $fp = fopen ( $path, "w" );
  28. fwrite ( $fp, $content );
  29. fclose ( $fp );
  30. }
  31. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  32. $collectHtml = "";
  33. $sumPrice = 0.00;
  34. for($i = 1; $i <= 12; $i ++) {
  35. $falg = true;
  36. foreach ( $receiptCollectList as $key => $value ) {
  37. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  38. $sumPrice += $value ['price'];
  39. if ($classType == "b") {
  40. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  41. $falg = false;
  42. break;
  43. } else {
  44. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  45. $falg = false;
  46. break;
  47. }
  48. }
  49. }
  50. if ($falg)
  51. $collectHtml .= '<td class="taR">-</td>';
  52. }
  53. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  54. return $collectHtml;
  55. }
  56. public function beforeRun($resource, $action) {
  57. Doo::loadClass ( 'XDeode' );
  58. $XDeode = new XDeode ( 5 );
  59. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  60. // 单独判断公司汇总的访问权限
  61. if ($action == 'companyCategoryCollect') {
  62. Doo::loadModel ( "receiptAuthorityManage" );
  63. $invoiceCompanyManage = new receiptAuthorityManage ();
  64. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  65. if (empty ( $icm ))
  66. die ( 'illegal request' );
  67. }
  68. Doo::loadModel ( 'staff' );
  69. $staff = new staff ();
  70. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  71. $accessModular = 'RECEIPTS';
  72. if (empty ( $detail ['cldAccessArray'] ))
  73. die ( 'illegal request' );
  74. else {
  75. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  76. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  77. $flag = true;
  78. } else {
  79. $flag = false;
  80. }
  81. } else {
  82. die ( 'illegal request' );
  83. }
  84. }
  85. if (! $flag)
  86. die ( 'illegal request' );
  87. }
  88. function __construct() {
  89. if (isset ( $_COOKIE ["staff"] )) {
  90. if (! empty ( $_COOKIE ["staff"] )) {
  91. Doo::loadModel ( 'staff' );
  92. Doo::loadModel ( 'verify' );
  93. $verify = new verify ();
  94. $staff = new staff ();
  95. Doo::loadModel ( "execute" );
  96. $execute = new execute ();
  97. $verifyList = $verify->find ( array (
  98. 'select' => 'staff',
  99. 'asArray' => true
  100. ) );
  101. $list = array ();
  102. // 判断角色的审批权限
  103. foreach ( $verifyList as $key => $value ) {
  104. $ver = json_decode ( $value ['staff'] );
  105. foreach ( $ver as $k => $v ) {
  106. if ($v [1] == 'ROLE') {
  107. $roleList = json_decode ( $v [3] );
  108. foreach ( $roleList as $t => $g ) {
  109. $gList = explode ( "_", $g );
  110. array_push ( $list, $gList [0] );
  111. // print_r($list);
  112. }
  113. } else
  114. array_push ( $list, $v [0] );
  115. }
  116. }
  117. // 判断执行人的审批权限
  118. $executeList = $execute->find ( array (
  119. 'select' => 'staff',
  120. 'asArray' => true
  121. ) );
  122. $list2 = array ();
  123. foreach ( $executeList as $key => $value ) {
  124. $ver = json_decode ( $value ['staff'] );
  125. foreach ( $ver as $k => $v ) {
  126. array_push ( $list2, $v [0] );
  127. }
  128. }
  129. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  130. $eidList = array_filter ( explode ( ",", $eidList ) );
  131. $this->executeId = array_merge ( $list2, $eidList );
  132. $this->verifyId = $list;
  133. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  134. // 检测用户信息完成
  135. $this->data ['isStaffCompleteMsg'] = false;
  136. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  137. if (! empty ( $detail ))
  138. $this->data ['isStaffCompleteMsg'] = true;
  139. return "/";
  140. }
  141. }
  142. Doo::loadCore ( 'uri/DooUriRouter' );
  143. $router = new DooUriRouter ();
  144. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  145. if ($routeRs ['1'] != "login") {
  146. header ( 'Content-Type:text/html;charset=utf-8' );
  147. @header ( "Location: /login" );
  148. }
  149. }
  150. function saeaBorad() {
  151. Doo::loadModel ( 'receipt' );
  152. Doo::loadModel ( 'verify' );
  153. $verify = new verify ();
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'L_category' );
  156. $lCategory = new L_category ();
  157. Doo::loadModel ( "role" );
  158. $role = new role ();
  159. Doo::loadModel ( "receiptLog" );
  160. $receiptLog = new receiptLog ();
  161. Doo::loadClass ( 'XDeode' );
  162. $XDeode = new XDeode ( 7 );
  163. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  164. $receiptDetail = $receipt->find ( array (
  165. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  166. 'desc' => 'rid',
  167. 'asArray' => true
  168. ) );
  169. foreach ( $receiptDetail as $key => $value ) {
  170. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  171. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  172. $veList = $verify->getOne ( array (
  173. 'where' => 'vid=' . $value ['verify'],
  174. 'asArray' => true
  175. ) );
  176. $v = json_decode ( $veList ['staff'] );
  177. array_push ( $v [0], $veList ['description'] );
  178. foreach ( $v as $n => $m ) {
  179. if ($m ['1'] == 'ROLE') {
  180. $roleInfo = $role->getOne ( array (
  181. 'where' => 'rid=' . $m [0],
  182. 'asArray' => true
  183. ) );
  184. $v [$n] [1] = $roleInfo ['name'];
  185. }
  186. }
  187. $receiptDetail [$key] ['staff'] = $v;
  188. $category = $lCategory->getOne ( array (
  189. 'where' => 'cid=' . $value ['cid'],
  190. 'asArray' => true
  191. ) );
  192. $receiptDetail [$key] ['category'] = $category ['title'];
  193. }
  194. // print_r($receiptLogList);
  195. $data ['receiptLogList'] = $receiptLogList;
  196. $data ['receiptDetail'] = $receiptDetail;
  197. $data ['memu'] = "receipt";
  198. $data ['staff'] = $this->staff;
  199. $data ['receiptMemu'] = 'saeaBorad';
  200. $data ['verifyId'] = $this->verifyId;
  201. $data ['executeId'] = $this->executeId;
  202. $this->render ( "/admin/saeaBorad", $data );
  203. }
  204. function remitAdd() {
  205. Doo::loadModel ( 'accountItem' );
  206. Doo::loadModel ( 'verify' );
  207. Doo::loadModel ( 'receipt' );
  208. Doo::loadModel ( 'L_category' );
  209. $lCategory = new L_category ();
  210. $receipt = new receipt ();
  211. $verify = new verify ();
  212. $accountItem = new accountItem ();
  213. Doo::loadModel ( "role" );
  214. $role = new role ();
  215. $acItem = $accountItem->find ( array (
  216. 'asArray' => true
  217. ) );
  218. $veList = $verify->find ( array (
  219. 'asArray' => true
  220. ) );
  221. foreach ( $veList as $key => $value ) {
  222. $v = json_decode ( $value ['staff'] );
  223. $list = array ();
  224. foreach ( $v as $n => $m ) {
  225. if ($m ['1'] == 'ROLE') {
  226. $roleInfo = $role->getOne ( array (
  227. 'where' => 'rid=' . $m [0],
  228. 'asArray' => true
  229. ) );
  230. $v [$n] [1] = $roleInfo ['name'];
  231. array_push ( $list, $roleInfo ['name'] );
  232. } else {
  233. array_push ( $list, $v [$n] [1] );
  234. }
  235. }
  236. $veList [$key] ['staff'] = implode ( '>', $list );
  237. }
  238. $data ['category'] = $lCategory->find ( array (
  239. 'asArray' => true
  240. ) );
  241. $data ['veList'] = $veList;
  242. $data ['acItem'] = $acItem;
  243. $data ['memu'] = "receipt";
  244. $data ['staff'] = $this->staff;
  245. $data ['receiptMemu'] = 'saeaBorad';
  246. $data ['verifyId'] = $this->verifyId;
  247. $data ['executeId'] = $this->executeId;
  248. $this->render ( "/admin/remitAdd", $data );
  249. }
  250. function remitAddDo() {
  251. $agency = $this->get_args ( 'agency' );
  252. $travel = $this->get_args ( 'travel' );
  253. $train = $this->get_args ( 'train' );
  254. $other = $this->get_args ( 'other' );
  255. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  256. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  257. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  258. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  259. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  260. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  261. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  262. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  263. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  264. // print_r($agency);die;
  265. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  266. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  267. header ( 'Content-Type:text/html;charset=utf-8' );
  268. die ( '请填写联行号' );
  269. }
  270. Doo::loadModel ( 'receipt' );
  271. Doo::loadModel ( 'receiptDetail' );
  272. Doo::loadModel ( 'accountItem' );
  273. $accountItem = new accountItem ();
  274. $receipt = new receipt ();
  275. Doo::loadModel ( 'enclosur' );
  276. Doo::loadModel ( 'execute' );
  277. $execute = new execute ();
  278. $executeDetail = $execute->getOne ( array (
  279. 'where' => 'mold="对公汇款执行人"',
  280. 'asArray' => true
  281. ) );
  282. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  283. $aItem = $accountItem->find ( array (
  284. 'where' => 'name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保"',
  285. 'asArray' => true
  286. ) );
  287. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  288. $ag = $tr = $ta = $ot = 0;
  289. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  290. foreach ( $aItem as $key => $value ) {
  291. if ($value ['category'] == $this->AGENCY) {
  292. if (isset ( $agency [$ag] )) {
  293. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  294. array_push ( $accountJson [$this->AGENCY], array (
  295. 'aid' => $value ['aid'],
  296. 'name' => $value ['name'],
  297. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  298. ) );
  299. $sum += $agency [$ag];
  300. $agencySum += $agency [$ag];
  301. }
  302. }
  303. $ag ++;
  304. }
  305. }
  306. $accountJson ['cSum'] = array (
  307. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  308. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  309. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  310. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  311. );
  312. // 报销单
  313. $receipt->accountItem = json_encode ( $accountJson );
  314. $receipt->staff = $this->staff [0] ['sid'];
  315. $receipt->sum = number_format ( $sum, 2, '.', '' );
  316. $receipt->date = date ( "Y-m-d" );
  317. $receipt->cid = $cid;
  318. $receipt->status = 5;
  319. $receipt->Rtype = 2;
  320. // 修改审批流程加入角色
  321. $receipt->verify = $verify;
  322. $receipt->executeCopy = $executeDetail ['staff'];
  323. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  324. $order = array (
  325. "\r\n",
  326. "\n",
  327. "\r"
  328. );
  329. $replace = '<br/>';
  330. $explanation = str_replace ( $order, $replace, $explanation );
  331. $receipt->explanation = $explanation;
  332. $receipt->remittanceName = $remittanceName;
  333. $receipt->bankName = $bankName;
  334. $receipt->bankNumber = $bankNumber;
  335. $receipt->remittanceBankType = $remittanceBankType;
  336. if ($remittanceBankType == 1)
  337. $receipt->coupletNumber = $coupletNumber;
  338. $rid = $receipt->insert ();
  339. // 附件
  340. if (! empty ( $enclosurName )) {
  341. $enclosurArray = explode ( '-', $enclosurName );
  342. foreach ( $enclosurArray as $value ) {
  343. $enclosur = new enclosur ();
  344. $enclosur->name = $value;
  345. $enclosur->rid = $rid;
  346. $enclosur->insert ();
  347. }
  348. // print_r($enclosurArray);die;
  349. }
  350. // 报销详情
  351. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  352. $receiptDetail = new receiptDetail ();
  353. $receiptDetail->staff = $this->staff [0] ['sid'];
  354. $receiptDetail->item = $value ['name'];
  355. $receiptDetail->itemCategory = $this->AGENCY;
  356. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  357. $receiptDetail->date = date ( "Y-m-d" );
  358. $receiptDetail->cid = $cid;
  359. $receiptDetail->rid = $rid;
  360. $receiptDetail->status = 4;
  361. $receiptDetail->insert ();
  362. }
  363. return "/saeaBorad";
  364. } else
  365. die ( 'illegal request' );
  366. }
  367. function remitEdit() {
  368. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  369. Doo::loadClass ( 'XDeode' );
  370. $XDeode = new XDeode ( 7 );
  371. $rid = $XDeode->decode ( $ridKey );
  372. if (! is_numeric ( $rid ))
  373. die ( 'illegal request' );
  374. Doo::loadModel ( 'accountItem' );
  375. Doo::loadModel ( 'verify' );
  376. Doo::loadModel ( 'receipt' );
  377. $receipt = new receipt ();
  378. $verify = new verify ();
  379. $accountItem = new accountItem ();
  380. Doo::loadModel ( 'L_category' );
  381. $lCategory = new L_category ();
  382. Doo::loadModel ( "role" );
  383. $role = new role ();
  384. Doo::loadModel ( 'enclosur' );
  385. $enclosur = new enclosur ();
  386. $receiptDetail = $receipt->getOne ( array (
  387. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  388. 'asArray' => true
  389. ) );
  390. if (empty ( $receiptDetail ))
  391. return "/saeaCreate";
  392. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  393. $acItem = $accountItem->find ( array (
  394. 'asArray' => true
  395. ) );
  396. $veList = $verify->find ( array (
  397. 'asArray' => true
  398. ) );
  399. foreach ( $veList as $key => $value ) {
  400. $v = json_decode ( $value ['staff'] );
  401. $list = array ();
  402. foreach ( $v as $n => $m ) {
  403. if ($m ['1'] == 'ROLE') {
  404. $roleInfo = $role->getOne ( array (
  405. 'where' => 'rid=' . $m [0],
  406. 'asArray' => true
  407. ) );
  408. $v [$n] [1] = $roleInfo ['name'];
  409. array_push ( $list, $roleInfo ['name'] );
  410. } else {
  411. array_push ( $list, $v [$n] [1] );
  412. }
  413. }
  414. $veList [$key] ['staff'] = implode ( '>', $list );
  415. }
  416. // 配置编辑信息
  417. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  418. foreach ( $acItem as $key => $value ) {
  419. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  420. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  421. $acItem [$key] ['price'] = $v ['price'];
  422. }
  423. }
  424. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  425. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  426. $acItem [$key] ['price'] = $v ['price'];
  427. }
  428. }
  429. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  430. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  431. $acItem [$key] ['price'] = $v ['price'];
  432. }
  433. }
  434. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  435. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  436. $acItem [$key] ['price'] = $v ['price'];
  437. }
  438. }
  439. }
  440. $data ['category'] = $lCategory->find ( array (
  441. 'asArray' => true
  442. ) );
  443. $data ['enclosurList'] = $enclosurList;
  444. $data ['cSum'] = $accountItemList ['cSum'];
  445. $data ['sum'] = $receiptDetail ['sum'];
  446. $data ['receiptDetail'] = $receiptDetail;
  447. $data ['veList'] = $veList;
  448. $data ['acItem'] = $acItem;
  449. $data ['memu'] = "receipt";
  450. $data ['staff'] = $this->staff;
  451. $data ['receiptMemu'] = 'saeaBorad';
  452. $data ['verify'] = $receiptDetail ['verify'];
  453. $data ['verifyId'] = $this->verifyId;
  454. $data ['executeId'] = $this->executeId;
  455. $data ['rid'] = $rid;
  456. $data ['ridKey'] = $ridKey;
  457. $this->render ( "/admin/remitEdit", $data );
  458. }
  459. function remitEdiDo() {
  460. $agency = $this->get_args ( 'agency' );
  461. $travel = $this->get_args ( 'travel' );
  462. $train = $this->get_args ( 'train' );
  463. $other = $this->get_args ( 'other' );
  464. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  465. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  466. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  467. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  468. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  469. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  470. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  471. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  472. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  473. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  474. Doo::loadClass ( 'XDeode' );
  475. $XDeode = new XDeode ( 7 );
  476. $rid = $XDeode->decode ( $ridKey );
  477. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  478. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  479. header ( 'Content-Type:text/html;charset=utf-8' );
  480. die ( '请填写联行号' );
  481. }
  482. Doo::loadModel ( 'receipt' );
  483. Doo::loadModel ( 'receiptDetail' );
  484. Doo::loadModel ( 'accountItem' );
  485. $accountItem = new accountItem ();
  486. $receipt = new receipt ();
  487. Doo::loadModel ( 'enclosur' );
  488. $enclosur = new enclosur ();
  489. Doo::loadModel ( 'execute' );
  490. $execute = new execute ();
  491. $executeDetail = $execute->getOne ( array (
  492. 'where' => 'mold="对公汇款执行人"',
  493. 'asArray' => true
  494. ) );
  495. $receiptDetail = $receipt->getOne ( array (
  496. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  497. 'asArray' => true
  498. ) );
  499. if (empty ( $receiptDetail ))
  500. return "/saeaBorad";
  501. $aItem = $accountItem->find ( array (
  502. 'where' => 'name like "办公费用" or name like "其他费用" or name like "公积金" or name like "社保"',
  503. 'asArray' => true
  504. ) );
  505. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  506. $ag = $tr = $ta = $ot = 0;
  507. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  508. foreach ( $aItem as $key => $value ) {
  509. if ($value ['category'] == $this->AGENCY) {
  510. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  511. array_push ( $accountJson [$this->AGENCY], array (
  512. 'aid' => $value ['aid'],
  513. 'name' => $value ['name'],
  514. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  515. ) );
  516. $sum += $agency [$ag];
  517. $agencySum += $agency [$ag];
  518. }
  519. $ag ++;
  520. }
  521. }
  522. $accountJson ['cSum'] = array (
  523. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  524. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  525. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  526. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  527. );
  528. // 报销单
  529. $rid = $receipt->rid = $receiptDetail ['rid'];
  530. $receipt->accountItem = json_encode ( $accountJson );
  531. $receipt->staff = $this->staff [0] ['sid'];
  532. $receipt->sum = number_format ( $sum, 2, '.', '' );
  533. $receipt->date = date ( "Y-m-d" );
  534. $receipt->cid = $cid;
  535. if ($receiptDetail ['Rtype'] == 1)
  536. $receipt->status = 7;
  537. else
  538. $receipt->status = 5;
  539. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  540. $receipt->verify = $verify;
  541. $receipt->executeCopy = $executeDetail ['staff'];
  542. $order = array (
  543. "\r\n",
  544. "\n",
  545. "\r"
  546. );
  547. $replace = '<br/>';
  548. $explanation = str_replace ( $order, $replace, $explanation );
  549. $receipt->explanation = $explanation;
  550. $receipt->remittanceName = $remittanceName;
  551. $receipt->bankName = $bankName;
  552. $receipt->bankNumber = $bankNumber;
  553. $receipt->remittanceBankType = $remittanceBankType;
  554. if ($remittanceBankType == 1)
  555. $receipt->coupletNumber = $coupletNumber;
  556. $receipt->update ();
  557. $receiptDetail = new receiptDetail ();
  558. $receiptDetail->delete ( array (
  559. 'where' => 'rid=' . $rid
  560. ) );
  561. // 报销详情
  562. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  563. $receiptDetail = new receiptDetail ();
  564. $receiptDetail->staff = $this->staff [0] ['sid'];
  565. $receiptDetail->item = $value ['name'];
  566. $receiptDetail->itemCategory = $this->AGENCY;
  567. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  568. $receiptDetail->date = date ( "Y-m-d" );
  569. $receiptDetail->cid = $cid;
  570. $receiptDetail->rid = $rid;
  571. $receiptDetail->status = 4;
  572. $receiptDetail->insert ();
  573. }
  574. // 附件
  575. if (! empty ( $enclosurName )) {
  576. $enclosurArray = explode ( '-', $enclosurName );
  577. foreach ( $enclosurArray as $value ) {
  578. $enclosur = new enclosur ();
  579. $enclosur->name = $value;
  580. $enclosur->rid = $rid;
  581. $enclosur->insert ();
  582. }
  583. }
  584. }
  585. return "/saeaBorad";
  586. }
  587. function remitApproval() {
  588. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  589. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  590. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  591. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  592. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  593. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  594. if (empty ( $status ))
  595. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  596. $vidList = array ();
  597. $button = 0;
  598. Doo::loadModel ( 'verify' );
  599. Doo::loadModel ( 'receipt' );
  600. Doo::loadModel ( 'staff' );
  601. $staff = new staff ();
  602. $receipt = new receipt ();
  603. $verify = new verify ();
  604. Doo::loadModel ( 'L_category' );
  605. $Lcategory = new L_category ();
  606. Doo::loadModel ( 'enclosur' );
  607. $enclosur = new enclosur ();
  608. // user verify ID
  609. $verifyDetail = $verify->find ( array (
  610. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  611. 'asArray' => true
  612. ) );
  613. foreach ( $verifyDetail as $key => $value ) {
  614. array_push ( $vidList, $value ['vid'] );
  615. }
  616. $vid = implode ( ",", $vidList );
  617. if (empty ( $verifyDetail ))
  618. $vid = 0;
  619. $categoryList = $Lcategory->find ( array (
  620. 'asArray' => true
  621. ) );
  622. $staffList = $staff->find ( array (
  623. 'where' => 'cid=' . $cid,
  624. 'asArray' => true
  625. ) );
  626. $ap = "";
  627. if ($status == 4) {
  628. $ap = 4;
  629. $status = 2;
  630. }
  631. // get Receipt By verifyID status 2
  632. $receiptList = $receipt->find ( array (
  633. 'where' => 'rid =' . $rid . ' and status=2',
  634. 'desc' => 'rid',
  635. 'asArray' => true
  636. ) );
  637. if (empty ( $receiptList )) {
  638. die ( 'illegal request' );
  639. }
  640. $Locate = 0;
  641. $roleId = 0;
  642. if ($ap == 4)
  643. $status = 4;
  644. foreach ( $receiptList as $key => $value ) {
  645. $receiptList [$key] ['Locate'] = $Locate;
  646. $Locate ++;
  647. $receiptList [$key] ['reviseDetail'] = array ();
  648. if (! empty ( $value ['reviseDetail'] ))
  649. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  650. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  651. $categoryDetil = $Lcategory->getOne ( array (
  652. 'where' => 'cid=' . $value ['cid'],
  653. 'asArray' => true
  654. ) );
  655. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  656. // 检测编辑状态
  657. $verifyList = $verify->getOne ( array (
  658. 'where' => 'vid=' . $value ['verify'],
  659. 'asArray' => true
  660. ) );
  661. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  662. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  663. Doo::loadModel ( 'role' );
  664. $role = new role ();
  665. // print_r($verifyList);
  666. $flag = true;
  667. $roleKey = 0;
  668. $endStaffArray = array ();
  669. $roleArrayCopy = array ();
  670. foreach ( $verifyList as $k => $v ) {
  671. // init verifyStaff
  672. if ($v [1] == 'ROLE') {
  673. if (! empty ( $verifyStaff )) {
  674. $endStaffArray = end ( $verifyStaff );
  675. if ($v [0] == $endStaffArray ['nextStaff']) {
  676. $roleId = $v [0];
  677. }
  678. }
  679. $roleVerify = json_decode ( $v [3], true );
  680. $roleKey = $k;
  681. $roleArray = array ();
  682. $rolename = $role->getOne ( array (
  683. 'where' => 'rid=' . $v [0],
  684. 'asArray' => true
  685. ) );
  686. foreach ( $roleVerify as $o => $p ) {
  687. $staffID = explode ( '_', $p );
  688. $staffInfo = $staff->getOne ( array (
  689. 'where' => 'sid=' . $staffID [0],
  690. 'asArray' => true
  691. ) );
  692. // print_r($staffID);
  693. $exp = array (
  694. 0 => $staffInfo ['sid'],
  695. 1 => $staffID [1],
  696. 2 => $staffInfo ['avatar'],
  697. 'date' => '',
  698. 'date' => '',
  699. 'opinion' => '',
  700. 'status' => '',
  701. 'rolename' => $rolename ['name']
  702. );
  703. array_push ( $roleArray, $exp );
  704. }
  705. $roleArrayCopy [$v [0]] = $roleArray;
  706. // $verifyList[$k]['roleArray']=$roleArray;
  707. }
  708. // print_r($roleArray);
  709. $verifyList [$k] ['date'] = "";
  710. $verifyList [$k] ['opinion'] = "";
  711. $verifyList [$k] ['status'] = "";
  712. if (empty ( $verifyStaff )) {
  713. $verifyList [$k] ['date'] = "";
  714. $verifyList [$k] ['opinion'] = "";
  715. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  716. $verifyList [$k] ['status'] = 4;
  717. $button = 4;
  718. $flag = false;
  719. }
  720. } else {
  721. foreach ( $verifyStaff as $m => $u ) {
  722. if ($v [0] == $m) {
  723. $verifyList [$k] ['date'] = $u ['date'];
  724. $verifyList [$k] ['opinion'] = $u ['opinion'];
  725. $verifyList [$k] ['status'] = $u ['status'];
  726. $flag = false;
  727. break;
  728. }
  729. }
  730. $endStaffArray = end ( $verifyStaff );
  731. if (isset ( $endStaffArray ['ROLE'] )) {
  732. } else {
  733. $endKey = key ( $verifyStaff );
  734. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  735. $button = 4;
  736. $verifyList [$k] ['status'] = 4;
  737. }
  738. }
  739. }
  740. }
  741. $rolename ['name'] = '';
  742. if (! empty ( $roleId )) {
  743. Doo::loadModel ( 'role' );
  744. $role = new role ();
  745. $rolename = $role->getOne ( array (
  746. 'where' => 'rid=' . $roleId,
  747. 'asArray' => true
  748. ) );
  749. }
  750. if (! empty ( $verifyStaff ))
  751. $endStaffArray = end ( $verifyStaff );
  752. $KOP = false;
  753. foreach ( $roleArrayCopy as $P => $A ) {
  754. foreach ( $A as $MKI => $AVL ) {
  755. if (! empty ( $verifyStaff )) {
  756. // &&$rolename['rid']==$endStaffArray['nextStaff']
  757. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  758. $button = 4;
  759. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  760. }
  761. foreach ( $verifyStaff as $m => $u ) {
  762. $AVLFK = $AVL [0] . '_R';
  763. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  764. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  765. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  766. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  767. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  768. break;
  769. }
  770. }
  771. } else {
  772. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  773. $button = 4;
  774. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  775. }
  776. }
  777. // $roleArray[$MKI]['rolename']=$rolename['name'];
  778. $KOP = true;
  779. }
  780. }
  781. foreach ( $roleArrayCopy as $k => $v ) {
  782. foreach ( $verifyList as $m => $n ) {
  783. if ($n [0] == $k) {
  784. array_splice ( $verifyList, $m, 1, $v );
  785. }
  786. }
  787. }
  788. $receiptList [$key] ['verifyList'] = $verifyList;
  789. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  790. 'where' => 'sid=' . $value ['staff'],
  791. 'asArray' => true
  792. ) );
  793. $receiptList [$key] ['button'] = $button;
  794. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  795. }
  796. $mothHtml = "";
  797. for($i = 1; $i <= 12; $i ++) {
  798. if ($month == $i)
  799. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  800. else
  801. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  802. }
  803. // 获取审批日志
  804. Doo::loadModel ( 'receiptLog' );
  805. $receiptLog = new receiptLog ();
  806. $rlList = array ();
  807. $rlInfo = $receiptLog->getOne ( array (
  808. 'where' => 'rid=' . $rid . ' and status=4',
  809. 'asArray' => true
  810. ) );
  811. $tijdate = $receiptLog->getOne ( array (
  812. 'where' => 'rid=' . $rid . ' and status=2',
  813. 'asc' => 'rlid',
  814. 'asArray' => true
  815. ) );
  816. if (! empty ( $rlInfo )) {
  817. $rlList = $receiptLog->find ( array (
  818. 'where' => 'rid=' . $rid,
  819. 'asc' => 'rlid',
  820. 'asArray' => true
  821. ) );
  822. }
  823. $receiptList [0] ['rlList'] = $rlList;
  824. $enclosurList = $enclosur->find ( array (
  825. 'where' => 'rid=' . $rid,
  826. 'asArray' => true
  827. ) );
  828. $enclosurHtml = '';
  829. foreach ( $enclosurList as $value ) {
  830. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  831. }
  832. // print_r($receiptList);
  833. $data ['enclosurHtml'] = $enclosurHtml;
  834. $data ['rolename'] = $rolename ['name'];
  835. $data ['datetij'] = $tijdate ['date'];
  836. $data ['mothHtml'] = $mothHtml;
  837. $data ['rid'] = $rid;
  838. $data ['receiptList'] = $receiptList;
  839. $data ['receiptApprovalCount'] = count ( $receiptList );
  840. $data ['status'] = $status;
  841. $data ['year'] = $year;
  842. $data ['categoryList'] = $categoryList;
  843. $data ['staffList'] = $staffList;
  844. $data ['cid'] = $cid;
  845. $data ['sid'] = $sid;
  846. $data ['ap'] = $ap;
  847. $data ['memu'] = "receipt";
  848. $data ['staff'] = $this->staff;
  849. $data ['receiptMemu'] = 'approvalExpenses';
  850. $data ['verifyId'] = $this->verifyId;
  851. $data ['executeId'] = $this->executeId;
  852. $this->render ( "/admin/remitApproval", $data );
  853. }
  854. function saeaLoanAdd() {
  855. Doo::loadModel ( 'verify' );
  856. $verify = new verify ();
  857. Doo::loadModel ( "role" );
  858. $role = new role ();
  859. Doo::loadModel ( 'L_category' );
  860. $lCategory = new L_category ();
  861. $veList = $verify->find ( array (
  862. 'asArray' => true
  863. ) );
  864. foreach ( $veList as $key => $value ) {
  865. $v = json_decode ( $value ['staff'] );
  866. $list = array ();
  867. foreach ( $v as $n => $m ) {
  868. if ($m ['1'] == 'ROLE') {
  869. $roleInfo = $role->getOne ( array (
  870. 'where' => 'rid=' . $m [0],
  871. 'asArray' => true
  872. ) );
  873. $v [$n] [1] = $roleInfo ['name'];
  874. array_push ( $list, $roleInfo ['name'] );
  875. } else {
  876. array_push ( $list, $v [$n] [1] );
  877. }
  878. }
  879. $veList [$key] ['staff'] = implode ( '>', $list );
  880. }
  881. $data ['category'] = $lCategory->find ( array (
  882. 'asArray' => true
  883. ) );
  884. $data ['veList'] = $veList;
  885. $data ['memu'] = "receipt";
  886. $data ['staff'] = $this->staff;
  887. $data ['receiptMemu'] = 'saeaBorad';
  888. $data ['verifyId'] = $this->verifyId;
  889. $data ['executeId'] = $this->executeId;
  890. $this->render ( "/admin/saeaLoanAdd", $data );
  891. }
  892. function saeaLoanAddDo() {
  893. $agency = $this->get_args ( 'agency' );
  894. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  895. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  896. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  897. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  898. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  899. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  900. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  901. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  902. // die;
  903. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  904. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  905. header ( 'Content-Type:text/html;charset=utf-8' );
  906. die ( '请填写联行号' );
  907. }
  908. Doo::loadModel ( 'receipt' );
  909. Doo::loadModel ( 'receiptDetail' );
  910. Doo::loadModel ( 'accountItem' );
  911. $accountItem = new accountItem ();
  912. $receipt = new receipt ();
  913. Doo::loadModel ( 'loanReceipt' );
  914. $loanReceipt = new loanReceipt ();
  915. Doo::loadModel ( 'execute' );
  916. $execute = new execute ();
  917. Doo::loadModel ( 'enclosur' );
  918. $executeDetail = $execute->getOne ( array (
  919. 'where' => 'mold="借款执行人"',
  920. 'asArray' => true
  921. ) );
  922. $aItem = $accountItem->find ( array (
  923. 'asArray' => true
  924. ) );
  925. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  926. $ag = $tr = $ta = $ot = 0;
  927. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  928. array_push ( $accountJson ['借款费用'], array (
  929. 'aid' => 0,
  930. 'name' => '申请金额',
  931. 'price' => number_format ( $agency, 2, '.', '' )
  932. ) );
  933. $sum += $agency;
  934. $agencySum += $agency;
  935. $accountJson ['cSum'] = array (
  936. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  937. 'agencySum' => number_format ( 0, 2, '.', '' ),
  938. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  939. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  940. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  941. );
  942. // 借款数据备份
  943. $loanReceipt->loanItem = json_encode ( $accountJson );
  944. $loanReceipt->staff = $this->staff [0] ['sid'];
  945. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  946. $loanReceipt->date = date ( "Y-m-d" );
  947. $loanReceipt->cid = $cid;
  948. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  949. $loanReceipt->status = 5;
  950. $loanReceipt->Rtype = 1;
  951. $loanReceipt->verify = $verify;
  952. $receipt->receiptOrder = $receipt->receiptOrder;
  953. // 添加HTML换行符
  954. // var_dump($explanation);
  955. $order = array (
  956. "\r\n",
  957. "\n",
  958. "\r"
  959. );
  960. $replace = '<br/>';
  961. $explanation = str_replace ( $order, $replace, $explanation );
  962. // $explanation=str_replace('\r',"<br/>",$explanation);
  963. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  964. $loanReceipt->explanation = $explanation;
  965. $loanRid = $loanReceipt->insert ();
  966. // 报销单
  967. $receipt->loanItem = json_encode ( $accountJson );
  968. $receipt->staff = $this->staff [0] ['sid'];
  969. $receipt->sum = number_format ( $sum, 2, '.', '' );
  970. $receipt->date = date ( "Y-m-d" );
  971. $receipt->cid = $cid;
  972. // 特殊状态
  973. $receipt->status = 5;
  974. $receipt->Rtype = 1;
  975. $receipt->loanRid = $loanRid;
  976. // 修改审批流程加入角色
  977. $receipt->verify = $verify;
  978. $receipt->executeCopy = $executeDetail ['staff'];
  979. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  980. $receipt->explanation = $explanation;
  981. $receipt->remittanceName = $remittanceName;
  982. $receipt->bankName = $bankName;
  983. $receipt->bankNumber = $bankNumber;
  984. $receipt->remittanceBankType = $remittanceBankType;
  985. if ($remittanceBankType == 1)
  986. $receipt->coupletNumber = $coupletNumber;
  987. $rid = $receipt->insert ();
  988. return "/saeaBorad";
  989. } else
  990. die ( 'illegal request' );
  991. }
  992. function saeaLoanEdi() {
  993. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  994. Doo::loadClass ( 'XDeode' );
  995. $XDeode = new XDeode ( 7 );
  996. $rid = $XDeode->decode ( $ridKey );
  997. if (! is_numeric ( $rid ))
  998. die ( 'illegal request' );
  999. Doo::loadModel ( 'verify' );
  1000. $verify = new verify ();
  1001. Doo::loadModel ( "role" );
  1002. $role = new role ();
  1003. Doo::loadModel ( 'L_category' );
  1004. $lCategory = new L_category ();
  1005. Doo::loadModel ( 'receipt' );
  1006. $receipt = new receipt ();
  1007. $receiptInfo = $receipt->getOne ( array (
  1008. 'where' => 'rid=' . $rid,
  1009. 'asArray' => true
  1010. ) );
  1011. $veList = $verify->find ( array (
  1012. 'asArray' => true
  1013. ) );
  1014. foreach ( $veList as $key => $value ) {
  1015. $v = json_decode ( $value ['staff'] );
  1016. $list = array ();
  1017. foreach ( $v as $n => $m ) {
  1018. if ($m ['1'] == 'ROLE') {
  1019. $roleInfo = $role->getOne ( array (
  1020. 'where' => 'rid=' . $m [0],
  1021. 'asArray' => true
  1022. ) );
  1023. $v [$n] [1] = $roleInfo ['name'];
  1024. array_push ( $list, $roleInfo ['name'] );
  1025. } else {
  1026. array_push ( $list, $v [$n] [1] );
  1027. }
  1028. }
  1029. $veList [$key] ['staff'] = implode ( '>', $list );
  1030. }
  1031. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1032. // print_r($receiptInfo);
  1033. $data ['receiptInfo'] = $receiptInfo;
  1034. $data ['category'] = $lCategory->find ( array (
  1035. 'asArray' => true
  1036. ) );
  1037. $data ['veList'] = $veList;
  1038. $data ['ridKey'] = $ridKey;
  1039. $data ['memu'] = "receipt";
  1040. $data ['staff'] = $this->staff;
  1041. $data ['receiptMemu'] = 'saeaBorad';
  1042. $data ['verifyId'] = $this->verifyId;
  1043. $data ['executeId'] = $this->executeId;
  1044. $this->render ( "/admin/saeaLoanEdi", $data );
  1045. }
  1046. function saeaLoanEdiDo() {
  1047. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1048. $agency = $this->get_args ( 'agency' );
  1049. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1050. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1051. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1052. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1053. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1054. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1055. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1056. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1057. // die;
  1058. Doo::loadClass ( 'XDeode' );
  1059. $XDeode = new XDeode ( 7 );
  1060. $rid = $XDeode->decode ( $ridKey );
  1061. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1062. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1063. header ( 'Content-Type:text/html;charset=utf-8' );
  1064. die ( '请填写联行号' );
  1065. }
  1066. Doo::loadModel ( 'receipt' );
  1067. Doo::loadModel ( 'receiptDetail' );
  1068. Doo::loadModel ( 'accountItem' );
  1069. $accountItem = new accountItem ();
  1070. $receipt = new receipt ();
  1071. Doo::loadModel ( 'loanReceipt' );
  1072. $loanReceipt = new loanReceipt ();
  1073. Doo::loadModel ( 'enclosur' );
  1074. Doo::loadModel ( 'execute' );
  1075. $execute = new execute ();
  1076. $executeDetail = $execute->getOne ( array (
  1077. 'where' => 'mold="借款执行人"',
  1078. 'asArray' => true
  1079. ) );
  1080. $receiptDetail = $receipt->getOne ( array (
  1081. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1082. 'asArray' => true
  1083. ) );
  1084. if (empty ( $receiptDetail ))
  1085. die ( '参数错误' );
  1086. $aItem = $accountItem->find ( array (
  1087. 'asArray' => true
  1088. ) );
  1089. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1090. $ag = $tr = $ta = $ot = 0;
  1091. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1092. array_push ( $accountJson ['借款费用'], array (
  1093. 'aid' => 0,
  1094. 'name' => '申请金额',
  1095. 'price' => number_format ( $agency, 2, '.', '' )
  1096. ) );
  1097. $sum += $agency;
  1098. $agencySum += $agency;
  1099. $accountJson ['cSum'] = array (
  1100. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1101. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1102. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1103. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1104. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1105. );
  1106. // 报销单
  1107. $receipt->loanItem = json_encode ( $accountJson );
  1108. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1109. $receipt->cid = $cid;
  1110. // 特殊状态
  1111. // 修改审批流程加入角色
  1112. if ($receiptDetail ['status'] != 4)
  1113. $receipt->verify = $verify;
  1114. $order = array (
  1115. "\r\n",
  1116. "\n",
  1117. "\r"
  1118. );
  1119. $replace = '<br/>';
  1120. $explanation = str_replace ( $order, $replace, $explanation );
  1121. $receipt->explanation = $explanation;
  1122. $receipt->remittanceName = $remittanceName;
  1123. $receipt->bankName = $bankName;
  1124. $receipt->bankNumber = $bankNumber;
  1125. $receipt->remittanceBankType = $remittanceBankType;
  1126. if ($remittanceBankType == 1)
  1127. $receipt->coupletNumber = $coupletNumber;
  1128. $receipt->update ( array (
  1129. 'where' => 'rid=' . $rid
  1130. ) );
  1131. // 借款数据更新
  1132. $loanReceipt->loanItem = json_encode ( $accountJson );
  1133. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1134. $loanReceipt->cid = $cid;
  1135. if ($receiptDetail ['status'] != 4)
  1136. $loanReceipt->verify = $verify;
  1137. $loanReceipt->explanation = $explanation;
  1138. $receipt->executeCopy = $executeDetail ['staff'];
  1139. $loanReceipt->update ( array (
  1140. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1141. ) );
  1142. }
  1143. return "/saeaBorad";
  1144. }
  1145. function saeaLoanReceiptAdd() {
  1146. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1147. Doo::loadModel ( 'receipt' );
  1148. $receipt = new receipt ();
  1149. Doo::loadModel ( 'loanReceipt' );
  1150. $loanReceipt = new loanReceipt ();
  1151. Doo::loadModel ( 'L_category' );
  1152. $Lcategory = new L_category ();
  1153. Doo::loadModel ( 'verify' );
  1154. Doo::loadModel ( 'statistics' );
  1155. $statistics = new statistics ();
  1156. $verify = new verify ();
  1157. Doo::loadModel ( 'staff' );
  1158. $staff = new staff ();
  1159. $receiptDetail = $receipt->getOne ( array (
  1160. 'where' => 'rid=' . $rid,
  1161. 'desc' => 'rid',
  1162. 'asArray' => true
  1163. ) );
  1164. $receiptList = $loanReceipt->find ( array (
  1165. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1166. 'desc' => 'rid',
  1167. 'asArray' => true
  1168. ) );
  1169. $Locate = 0;
  1170. $roleId = 0;
  1171. $button = 0;
  1172. foreach ( $receiptList as $key => $value ) {
  1173. $receiptList [$key] ['Locate'] = $Locate;
  1174. $Locate ++;
  1175. $receiptList [$key] ['reviseDetail'] = array ();
  1176. if (! empty ( $value ['reviseDetail'] ))
  1177. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1178. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1179. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1180. $categoryDetil = $Lcategory->getOne ( array (
  1181. 'where' => 'cid=' . $value ['cid'],
  1182. 'asArray' => true
  1183. ) );
  1184. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1185. // 检测编辑状态
  1186. $verifyList = $verify->getOne ( array (
  1187. 'where' => 'vid=' . $value ['verify'],
  1188. 'asArray' => true
  1189. ) );
  1190. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1191. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1192. Doo::loadModel ( 'role' );
  1193. $role = new role ();
  1194. $flag = true;
  1195. $roleKey = 0;
  1196. $endStaffArray = array ();
  1197. $roleArrayCopy = array ();
  1198. foreach ( $verifyList as $k => $v ) {
  1199. // init verifyStaff
  1200. if ($v [1] == 'ROLE') {
  1201. if (! empty ( $verifyStaff )) {
  1202. $endStaffArray = end ( $verifyStaff );
  1203. // if ($v[0]==$endStaffArray['nextStaff']){
  1204. // $roleId=$v[0];
  1205. // }
  1206. }
  1207. $roleVerify = json_decode ( $v [3], true );
  1208. $roleKey = $k;
  1209. $roleArray = array ();
  1210. $rolename = $role->getOne ( array (
  1211. 'where' => 'rid=' . $v [0],
  1212. 'asArray' => true
  1213. ) );
  1214. foreach ( $roleVerify as $o => $p ) {
  1215. $staffID = explode ( '_', $p );
  1216. $staffInfo = $staff->getOne ( array (
  1217. 'where' => 'sid=' . $staffID [0],
  1218. 'asArray' => true
  1219. ) );
  1220. // print_r($staffID);
  1221. $exp = array (
  1222. 0 => $staffInfo ['sid'],
  1223. 1 => $staffID [1],
  1224. 2 => $staffInfo ['avatar'],
  1225. 'date' => '',
  1226. 'date' => '',
  1227. 'opinion' => '',
  1228. 'status' => '',
  1229. 'rolename' => $rolename ['name']
  1230. );
  1231. array_push ( $roleArray, $exp );
  1232. }
  1233. $roleArrayCopy [$v [0]] = $roleArray;
  1234. // $verifyList[$k]['roleArray']=$roleArray;
  1235. }
  1236. $verifyList [$k] ['date'] = "";
  1237. $verifyList [$k] ['opinion'] = "";
  1238. $verifyList [$k] ['status'] = "";
  1239. if (empty ( $verifyStaff )) {
  1240. $verifyList [$k] ['date'] = "";
  1241. $verifyList [$k] ['opinion'] = "";
  1242. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1243. $verifyList [$k] ['status'] = 4;
  1244. $flag = false;
  1245. }
  1246. } else {
  1247. foreach ( $verifyStaff as $m => $u ) {
  1248. if ($v [0] == $m) {
  1249. $verifyList [$k] ['date'] = $u ['date'];
  1250. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1251. $verifyList [$k] ['status'] = $u ['status'];
  1252. $flag = false;
  1253. break;
  1254. }
  1255. }
  1256. $endStaffArray = end ( $verifyStaff );
  1257. if (isset ( $endStaffArray ['ROLE'] )) {
  1258. } else {
  1259. // $endKey=key($verifyStaff);
  1260. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1261. // $button=4;
  1262. // $verifyList[$k]['status']=4;
  1263. // }
  1264. }
  1265. }
  1266. }
  1267. $rolename ['name'] = '';
  1268. if (! empty ( $roleId )) {
  1269. Doo::loadModel ( 'role' );
  1270. $role = new role ();
  1271. $rolename = $role->getOne ( array (
  1272. 'where' => 'rid=' . $roleId,
  1273. 'asArray' => true
  1274. ) );
  1275. }
  1276. if (! empty ( $verifyStaff ))
  1277. $endStaffArray = end ( $verifyStaff );
  1278. $KOP = false;
  1279. foreach ( $roleArrayCopy as $P => $A ) {
  1280. foreach ( $A as $MKI => $AVL ) {
  1281. if (! empty ( $verifyStaff )) {
  1282. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1283. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1284. $button = 4;
  1285. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1286. }
  1287. foreach ( $verifyStaff as $m => $u ) {
  1288. $AVLFK = $AVL [0] . '_R';
  1289. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1290. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1291. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1292. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1293. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1294. break;
  1295. }
  1296. }
  1297. } else {
  1298. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1299. $button = 4;
  1300. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1301. }
  1302. }
  1303. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1304. $KOP = true;
  1305. }
  1306. }
  1307. foreach ( $roleArrayCopy as $k => $v ) {
  1308. foreach ( $verifyList as $m => $n ) {
  1309. if ($n [0] == $k) {
  1310. array_splice ( $verifyList, $m, 1, $v );
  1311. }
  1312. }
  1313. }
  1314. $receiptList [$key] ['verifyList'] = $verifyList;
  1315. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1316. 'where' => 'sid=' . $value ['staff'],
  1317. 'asArray' => true
  1318. ) );
  1319. $receiptList [$key] ['button'] = $button;
  1320. //
  1321. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1322. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1323. }
  1324. $data ['receiptList'] = $receiptList;
  1325. $data ['receiptDetail'] = $receiptDetail;
  1326. Doo::loadModel ( 'L_category' );
  1327. $lCategory = new L_category ();
  1328. Doo::loadModel ( 'accountItem' );
  1329. $accountItem = new accountItem ();
  1330. $acItem = $accountItem->find ( array (
  1331. 'asArray' => true
  1332. ) );
  1333. $veList = $verify->find ( array (
  1334. 'asArray' => true
  1335. ) );
  1336. foreach ( $veList as $key => $value ) {
  1337. $v = json_decode ( $value ['staff'] );
  1338. $list = array ();
  1339. foreach ( $v as $n => $m ) {
  1340. if ($m ['1'] == 'ROLE') {
  1341. $roleInfo = $role->getOne ( array (
  1342. 'where' => 'rid=' . $m [0],
  1343. 'asArray' => true
  1344. ) );
  1345. $v [$n] [1] = $roleInfo ['name'];
  1346. array_push ( $list, $roleInfo ['name'] );
  1347. } else {
  1348. array_push ( $list, $v [$n] [1] );
  1349. }
  1350. }
  1351. $veList [$key] ['staff'] = implode ( '>', $list );
  1352. }
  1353. $data ['rid'] = $rid;
  1354. $data ['category'] = $lCategory->find ( array (
  1355. 'asArray' => true
  1356. ) );
  1357. $data ['veList'] = $veList;
  1358. $data ['acItem'] = $acItem;
  1359. $data ['memu'] = "receipt";
  1360. $data ['staff'] = $this->staff;
  1361. $data ['receiptMemu'] = 'saeaBorad';
  1362. $data ['verifyId'] = $this->verifyId;
  1363. $data ['executeId'] = $this->executeId;
  1364. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1365. }
  1366. function saeaLoanReceiptAddDo() {
  1367. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1368. $agency = $this->get_args ( 'agency' );
  1369. $travel = $this->get_args ( 'travel' );
  1370. $train = $this->get_args ( 'train' );
  1371. $other = $this->get_args ( 'other' );
  1372. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1373. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1374. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1375. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1376. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1377. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1378. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1379. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1380. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1381. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1382. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1383. header ( 'Content-Type:text/html;charset=utf-8' );
  1384. die ( '请填写联行号' );
  1385. }
  1386. Doo::loadModel ( 'receipt' );
  1387. Doo::loadModel ( 'receiptDetail' );
  1388. Doo::loadModel ( 'accountItem' );
  1389. $accountItem = new accountItem ();
  1390. $receipt = new receipt ();
  1391. Doo::loadModel ( 'enclosur' );
  1392. Doo::loadModel ( 'execute' );
  1393. $execute = new execute ();
  1394. $executeDetail = $execute->getOne ( array (
  1395. 'where' => 'mold="借款费用执行人"',
  1396. 'asArray' => true
  1397. ) );
  1398. $receiptDet = $receipt->getOne ( array (
  1399. 'where' => 'rid=' . $rid,
  1400. 'asArray' => true
  1401. ) );
  1402. // if(!empty($receiptDetail))
  1403. // return "/referReceipt/".$receiptDetail['rid'];
  1404. $aItem = $accountItem->find ( array (
  1405. 'asArray' => true
  1406. ) );
  1407. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1408. $ag = $tr = $ta = $ot = 0;
  1409. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1410. foreach ( $aItem as $key => $value ) {
  1411. if ($value ['category'] == $this->AGENCY) {
  1412. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1413. array_push ( $accountJson [$this->AGENCY], array (
  1414. 'aid' => $value ['aid'],
  1415. 'name' => $value ['name'],
  1416. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1417. ) );
  1418. $sum += $agency [$ag];
  1419. $agencySum += $agency [$ag];
  1420. }
  1421. $ag ++;
  1422. }
  1423. if ($value ['category'] == $this->TRAVEL) {
  1424. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1425. array_push ( $accountJson [$this->TRAVEL], array (
  1426. 'aid' => $value ['aid'],
  1427. 'name' => $value ['name'],
  1428. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1429. ) );
  1430. $sum += $travel [$tr];
  1431. $travelSum += $travel [$tr];
  1432. }
  1433. $tr ++;
  1434. }
  1435. if ($value ['category'] == $this->TRAIN) {
  1436. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1437. array_push ( $accountJson [$this->TRAIN], array (
  1438. 'aid' => $value ['aid'],
  1439. 'name' => $value ['name'],
  1440. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1441. ) );
  1442. $sum += $train [$ta];
  1443. $trainSum += $train [$ta];
  1444. }
  1445. $ta ++;
  1446. }
  1447. if ($value ['category'] == $this->OTHER) {
  1448. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1449. array_push ( $accountJson [$this->OTHER], array (
  1450. 'aid' => $value ['aid'],
  1451. 'name' => $value ['name'],
  1452. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1453. ) );
  1454. $sum += $other [$ot];
  1455. $otherSum += $other [$ot];
  1456. }
  1457. $ot ++;
  1458. }
  1459. }
  1460. $accountJson ['cSum'] = array (
  1461. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1462. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1463. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1464. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1465. );
  1466. // 报销单
  1467. $receipt->accountItem = json_encode ( $accountJson );
  1468. $receipt->staff = $this->staff [0] ['sid'];
  1469. $receipt->loanSum = $receiptDet ['sum'];
  1470. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1471. $receipt->date = date ( "Y-m-d" );
  1472. $receipt->pastDate = '';
  1473. $receipt->cid = $cid;
  1474. $receipt->status = 7;
  1475. // 修改审批流程加入角色
  1476. $receipt->verify = $verify;
  1477. $receipt->verifyStaff = '';
  1478. $receipt->executeStaff = '';
  1479. $receipt->executeCopy = $executeDetail ['staff'];
  1480. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1481. $receipt->explanation = $explanation;
  1482. $receipt->remittanceName = $remittanceName;
  1483. $receipt->bankName = $bankName;
  1484. $receipt->bankNumber = $bankNumber;
  1485. $receipt->remittanceBankType = $remittanceBankType;
  1486. if ($remittanceBankType == 1)
  1487. $receipt->coupletNumber = $coupletNumber;
  1488. $receipt->update ( array (
  1489. 'where' => 'rid=' . $rid
  1490. ) );
  1491. // 附件
  1492. if (! empty ( $enclosurName )) {
  1493. $enclosurArray = explode ( '-', $enclosurName );
  1494. foreach ( $enclosurArray as $value ) {
  1495. $enclosur = new enclosur ();
  1496. $enclosur->name = $value;
  1497. $enclosur->rid = $rid;
  1498. $enclosur->insert ();
  1499. }
  1500. // print_r($enclosurArray);die;
  1501. }
  1502. // 报销详情
  1503. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1504. $receiptDetail = new receiptDetail ();
  1505. $receiptDetail->staff = $this->staff [0] ['sid'];
  1506. $receiptDetail->item = $value ['name'];
  1507. $receiptDetail->itemCategory = $this->AGENCY;
  1508. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1509. $receiptDetail->date = date ( "Y-m-d" );
  1510. $receiptDetail->cid = $cid;
  1511. $receiptDetail->rid = $rid;
  1512. $receiptDetail->status = 4;
  1513. $receiptDetail->insert ();
  1514. }
  1515. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1516. $receiptDetail = new receiptDetail ();
  1517. $receiptDetail->staff = $this->staff [0] ['sid'];
  1518. $receiptDetail->item = $value ['name'];
  1519. $receiptDetail->itemCategory = $this->TRAVEL;
  1520. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1521. $receiptDetail->date = date ( "Y-m-d" );
  1522. $receiptDetail->cid = $cid;
  1523. $receiptDetail->rid = $rid;
  1524. $receiptDetail->status = 4;
  1525. $receiptDetail->insert ();
  1526. }
  1527. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1528. $receiptDetail = new receiptDetail ();
  1529. $receiptDetail->staff = $this->staff [0] ['sid'];
  1530. $receiptDetail->item = $value ['name'];
  1531. $receiptDetail->itemCategory = $this->TRAIN;
  1532. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1533. $receiptDetail->date = date ( "Y-m-d" );
  1534. $receiptDetail->cid = $cid;
  1535. $receiptDetail->rid = $rid;
  1536. $receiptDetail->status = 4;
  1537. $receiptDetail->insert ();
  1538. }
  1539. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1540. $receiptDetail = new receiptDetail ();
  1541. $receiptDetail->staff = $this->staff [0] ['sid'];
  1542. $receiptDetail->item = $value ['name'];
  1543. $receiptDetail->itemCategory = $this->OTHER;
  1544. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1545. $receiptDetail->date = date ( "Y-m-d" );
  1546. $receiptDetail->cid = $cid;
  1547. $receiptDetail->rid = $rid;
  1548. $receiptDetail->status = 4;
  1549. $receiptDetail->insert ();
  1550. }
  1551. return "/saeaBorad";
  1552. }
  1553. return "/saeaLoanReceiptAdd/" . $rid;
  1554. }
  1555. function saeaLoanReceiptEdi() {
  1556. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1557. Doo::loadClass ( 'XDeode' );
  1558. $XDeode = new XDeode ( 7 );
  1559. $rid = $XDeode->decode ( $ridKey );
  1560. if (! is_numeric ( $rid ))
  1561. die ( 'illegal request' );
  1562. Doo::loadModel ( 'accountItem' );
  1563. Doo::loadModel ( 'verify' );
  1564. Doo::loadModel ( 'receipt' );
  1565. $receipt = new receipt ();
  1566. $verify = new verify ();
  1567. $accountItem = new accountItem ();
  1568. Doo::loadModel ( 'L_category' );
  1569. $Lcategory = new L_category ();
  1570. Doo::loadModel ( "role" );
  1571. $role = new role ();
  1572. Doo::loadModel ( 'loanReceipt' );
  1573. $loanReceipt = new loanReceipt ();
  1574. Doo::loadModel ( 'staff' );
  1575. $staff = new staff ();
  1576. $receiptDetail = $receipt->getOne ( array (
  1577. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1578. 'asArray' => true
  1579. ) );
  1580. if (empty ( $receiptDetail ))
  1581. return "/saeaBorad";
  1582. $receiptList = $loanReceipt->find ( array (
  1583. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1584. 'desc' => 'rid',
  1585. 'asArray' => true
  1586. ) );
  1587. $Locate = 0;
  1588. $roleId = 0;
  1589. $button = 0;
  1590. foreach ( $receiptList as $key => $value ) {
  1591. $receiptList [$key] ['Locate'] = $Locate;
  1592. $Locate ++;
  1593. $receiptList [$key] ['reviseDetail'] = array ();
  1594. if (! empty ( $value ['reviseDetail'] ))
  1595. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1596. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1597. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1598. $categoryDetil = $Lcategory->getOne ( array (
  1599. 'where' => 'cid=' . $value ['cid'],
  1600. 'asArray' => true
  1601. ) );
  1602. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1603. // 检测编辑状态
  1604. $verifyList = $verify->getOne ( array (
  1605. 'where' => 'vid=' . $value ['verify'],
  1606. 'asArray' => true
  1607. ) );
  1608. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1609. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1610. Doo::loadModel ( 'role' );
  1611. $role = new role ();
  1612. $flag = true;
  1613. $roleKey = 0;
  1614. $endStaffArray = array ();
  1615. $roleArrayCopy = array ();
  1616. foreach ( $verifyList as $k => $v ) {
  1617. // init verifyStaff
  1618. if ($v [1] == 'ROLE') {
  1619. if (! empty ( $verifyStaff )) {
  1620. $endStaffArray = end ( $verifyStaff );
  1621. // if ($v[0]==$endStaffArray['nextStaff']){
  1622. // $roleId=$v[0];
  1623. // }
  1624. }
  1625. $roleVerify = json_decode ( $v [3], true );
  1626. $roleKey = $k;
  1627. $roleArray = array ();
  1628. $rolename = $role->getOne ( array (
  1629. 'where' => 'rid=' . $v [0],
  1630. 'asArray' => true
  1631. ) );
  1632. foreach ( $roleVerify as $o => $p ) {
  1633. $staffID = explode ( '_', $p );
  1634. $staffInfo = $staff->getOne ( array (
  1635. 'where' => 'sid=' . $staffID [0],
  1636. 'asArray' => true
  1637. ) );
  1638. // print_r($staffID);
  1639. $exp = array (
  1640. 0 => $staffInfo ['sid'],
  1641. 1 => $staffID [1],
  1642. 2 => $staffInfo ['avatar'],
  1643. 'date' => '',
  1644. 'date' => '',
  1645. 'opinion' => '',
  1646. 'status' => '',
  1647. 'rolename' => $rolename ['name']
  1648. );
  1649. array_push ( $roleArray, $exp );
  1650. }
  1651. $roleArrayCopy [$v [0]] = $roleArray;
  1652. // $verifyList[$k]['roleArray']=$roleArray;
  1653. }
  1654. $verifyList [$k] ['date'] = "";
  1655. $verifyList [$k] ['opinion'] = "";
  1656. $verifyList [$k] ['status'] = "";
  1657. if (empty ( $verifyStaff )) {
  1658. $verifyList [$k] ['date'] = "";
  1659. $verifyList [$k] ['opinion'] = "";
  1660. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1661. $verifyList [$k] ['status'] = 4;
  1662. $flag = false;
  1663. }
  1664. } else {
  1665. foreach ( $verifyStaff as $m => $u ) {
  1666. if ($v [0] == $m) {
  1667. $verifyList [$k] ['date'] = $u ['date'];
  1668. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1669. $verifyList [$k] ['status'] = $u ['status'];
  1670. $flag = false;
  1671. break;
  1672. }
  1673. }
  1674. $endStaffArray = end ( $verifyStaff );
  1675. if (isset ( $endStaffArray ['ROLE'] )) {
  1676. } else {
  1677. // $endKey=key($verifyStaff);
  1678. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1679. // $button=4;
  1680. // $verifyList[$k]['status']=4;
  1681. // }
  1682. }
  1683. }
  1684. }
  1685. $rolename ['name'] = '';
  1686. if (! empty ( $roleId )) {
  1687. Doo::loadModel ( 'role' );
  1688. $role = new role ();
  1689. $rolename = $role->getOne ( array (
  1690. 'where' => 'rid=' . $roleId,
  1691. 'asArray' => true
  1692. ) );
  1693. }
  1694. if (! empty ( $verifyStaff ))
  1695. $endStaffArray = end ( $verifyStaff );
  1696. $KOP = false;
  1697. foreach ( $roleArrayCopy as $P => $A ) {
  1698. foreach ( $A as $MKI => $AVL ) {
  1699. if (! empty ( $verifyStaff )) {
  1700. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1701. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1702. $button = 4;
  1703. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1704. }
  1705. foreach ( $verifyStaff as $m => $u ) {
  1706. $AVLFK = $AVL [0] . '_R';
  1707. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1708. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1709. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1710. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1711. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1712. break;
  1713. }
  1714. }
  1715. } else {
  1716. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1717. $button = 4;
  1718. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1719. }
  1720. }
  1721. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1722. $KOP = true;
  1723. }
  1724. }
  1725. foreach ( $roleArrayCopy as $k => $v ) {
  1726. foreach ( $verifyList as $m => $n ) {
  1727. if ($n [0] == $k) {
  1728. array_splice ( $verifyList, $m, 1, $v );
  1729. }
  1730. }
  1731. }
  1732. $receiptList [$key] ['verifyList'] = $verifyList;
  1733. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1734. 'where' => 'sid=' . $value ['staff'],
  1735. 'asArray' => true
  1736. ) );
  1737. $receiptList [$key] ['button'] = $button;
  1738. //
  1739. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1740. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1741. }
  1742. $data ['receiptList'] = $receiptList;
  1743. $acItem = $accountItem->find ( array (
  1744. 'asArray' => true
  1745. ) );
  1746. $veList = $verify->find ( array (
  1747. 'asArray' => true
  1748. ) );
  1749. foreach ( $veList as $key => $value ) {
  1750. $v = json_decode ( $value ['staff'] );
  1751. $list = array ();
  1752. foreach ( $v as $n => $m ) {
  1753. if ($m ['1'] == 'ROLE') {
  1754. $roleInfo = $role->getOne ( array (
  1755. 'where' => 'rid=' . $m [0],
  1756. 'asArray' => true
  1757. ) );
  1758. $v [$n] [1] = $roleInfo ['name'];
  1759. array_push ( $list, $roleInfo ['name'] );
  1760. } else {
  1761. array_push ( $list, $v [$n] [1] );
  1762. }
  1763. }
  1764. $veList [$key] ['staff'] = implode ( '>', $list );
  1765. }
  1766. // 配置编辑信息
  1767. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1768. foreach ( $acItem as $key => $value ) {
  1769. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1770. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1771. $acItem [$key] ['price'] = $v ['price'];
  1772. }
  1773. }
  1774. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1775. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1776. $acItem [$key] ['price'] = $v ['price'];
  1777. }
  1778. }
  1779. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1780. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1781. $acItem [$key] ['price'] = $v ['price'];
  1782. }
  1783. }
  1784. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1785. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1786. $acItem [$key] ['price'] = $v ['price'];
  1787. }
  1788. }
  1789. }
  1790. $data ['category'] = $Lcategory->find ( array (
  1791. 'asArray' => true
  1792. ) );
  1793. $data ['ridKey'] = $ridKey;
  1794. $data ['cSum'] = $accountItemList ['cSum'];
  1795. $data ['sum'] = $receiptDetail ['sum'];
  1796. $data ['receiptDetail'] = $receiptDetail;
  1797. $data ['veList'] = $veList;
  1798. $data ['acItem'] = $acItem;
  1799. $data ['memu'] = "receipt";
  1800. $data ['staff'] = $this->staff;
  1801. $data ['receiptMemu'] = 'saeaBorad';
  1802. $data ['verify'] = $receiptDetail ['verify'];
  1803. $data ['verifyId'] = $this->verifyId;
  1804. $data ['executeId'] = $this->executeId;
  1805. $data ['rid'] = $rid;
  1806. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1807. }
  1808. /**
  1809. * 培训班结算
  1810. */
  1811. function receiptTrainAdd() {
  1812. Doo::loadModel ( 'accountItem' );
  1813. $accountItem = new accountItem ();
  1814. $acItem = $accountItem->find ( array (
  1815. 'asArray' => true
  1816. ) );
  1817. // 审批组
  1818. Doo::loadModel ( 'verify' );
  1819. $verify = new verify ();
  1820. $veList = $verify->getVerifyByAll ();
  1821. // 办事处
  1822. Doo::loadModel ( 'L_category' );
  1823. $lCategory = new L_category ();
  1824. $data ['category'] = $lCategory->getCategory ();
  1825. $data ['veList'] = $veList;
  1826. $data ['memu'] = "receipt";
  1827. $data ['staff'] = $this->staff;
  1828. $data ['acItem'] = $acItem;
  1829. $data ['receiptMemu'] = 'saeaBorad';
  1830. $data ['verifyId'] = $this->verifyId;
  1831. $data ['executeId'] = $this->executeId;
  1832. $this->render ( "/receipt/receiptTrainAdd", $data );
  1833. }
  1834. /**
  1835. * 添加培训班结算
  1836. */
  1837. function receiptTrainAddDo() {
  1838. // 培训班信息
  1839. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1840. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1841. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1842. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1843. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1844. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1845. // 发票信息
  1846. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1847. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1848. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1849. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1850. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1851. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1852. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1853. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1854. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1855. header ( 'Content-Type:text/html;charset=utf-8' );
  1856. die ( '请填写联行号' );
  1857. }
  1858. Doo::loadModel ( 'execute' );
  1859. $execute = new execute ();
  1860. $executeDetail = $execute->getOne ( array (
  1861. 'where' => 'mold="培训班结算"',
  1862. 'asArray' => true
  1863. ) );
  1864. if (empty ( $executeDetail )) {
  1865. header ( 'Content-Type:text/html;charset=utf-8' );
  1866. die ( '未设置执行人' );
  1867. }
  1868. Doo::loadClass ( 'XDeode' );
  1869. $XDeode = new XDeode ( 5 );
  1870. $cid = $XDeode->decode ( $cid );
  1871. Doo::loadModel ( 'receipt' );
  1872. $receipt = new receipt ();
  1873. Doo::loadModel ( 'receiptTraining' );
  1874. $receiptTraining = new receiptTraining ();
  1875. // 创建费用培训班
  1876. $item = array (
  1877. 'cid' => $this->staff [0] ['cid'],
  1878. 'categoryName' => $this->staff [0] ['category'],
  1879. 'trainName' => $trainName,
  1880. 'trainStartDate' => $trainStartDate,
  1881. 'trainEndDate' => $trainEndDate,
  1882. 'participants' => $participants,
  1883. 'trainAddress' => $trainAddress,
  1884. 'trainRemarks' => $trainRemarks,
  1885. 'creator' => $this->staff [0] ['sid'],
  1886. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1887. );
  1888. $irid = $receiptTraining->addReceiptTraining ( $item );
  1889. // 报销单
  1890. $receipt->status = 5;
  1891. $receipt->trainId = $irid;
  1892. $receipt->Rtype = 3;
  1893. $receipt->staff = $this->staff [0] ['sid'];
  1894. $receipt->cid = $cid;
  1895. $receipt->verify = $verify;
  1896. $receipt->date = date ( "Y-m-d" );
  1897. $receipt->executeCopy = $executeDetail ['staff'];
  1898. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1899. $receipt->remittanceName = $remittanceName;
  1900. $receipt->bankName = $bankName;
  1901. $receipt->bankNumber = $bankNumber;
  1902. $receipt->remittanceBankType = $remittanceBankType;
  1903. if ($remittanceBankType == 1)
  1904. $receipt->coupletNumber = $coupletNumber;
  1905. $rid = $receipt->insert ();
  1906. $XDeode = new XDeode ( 7 );
  1907. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1908. } else
  1909. die ( 'illegal request' );
  1910. }
  1911. /**
  1912. * 培训班编辑
  1913. */
  1914. function receiptTrainEdi() {
  1915. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1916. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1917. Doo::loadClass ( 'XDeode' );
  1918. $XDeode = new XDeode ( 7 );
  1919. $rid = $XDeode->decode ( $ridKey );
  1920. if (! is_numeric ( $rid ))
  1921. die ( 'illegal request' );
  1922. Doo::loadModel ( 'receipt' );
  1923. $receipt = new receipt ();
  1924. Doo::loadModel ( 'receiptTraining' );
  1925. $receiptTraining = new receiptTraining ();
  1926. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1927. if ($receiptDetail ['status'] != 5)
  1928. die ();
  1929. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1930. // 汇总表合计
  1931. // 收入合计
  1932. Doo::loadModel ( 'invoiceTraining' );
  1933. $invoiceTraining = new invoiceTraining ();
  1934. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1935. // print_r($invoiceTrainingDetail);
  1936. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1937. // 支出项目
  1938. Doo::loadModel ( 'accountItem' );
  1939. $accountItem = new accountItem ();
  1940. // 项目金额合计
  1941. Doo::loadModel ( 'RItem' );
  1942. $RItem = new RItem ();
  1943. // 讲师获得
  1944. Doo::loadModel ( 'RILecturer' );
  1945. $RILecturer = new RILecturer ();
  1946. $RItemList = $RItem->getRItemByRid ( $rid );
  1947. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1948. // 支出项金额详情
  1949. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceTrainingDetail ['invoiceArriveAmount'] );
  1950. //print_r($aiData);
  1951. // 利润
  1952. $data ['profit'] = $invoiceTrainingDetail ['invoiceArriveAmount'] - $aiData ['total'];
  1953. $data ['companyProfit'] = $data ['profit'] * 0.6;
  1954. $data ['categoryProfit'] = $data ['profit'] * 0.4;
  1955. // print_r($aiData['dataList']);
  1956. $data ['categoryActualExpenditure'] = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1957. // 备用金
  1958. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1959. $data ['payment'] = $data ['receiptLoanDetail'] ['sum'] + $invoiceTrainingDetail ['RIAmount'] - $data ['categoryActualExpenditure'];
  1960. $data ['total'] = $aiData ['total'];
  1961. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1962. $data ['aiList'] = $aiData ['dataList'];
  1963. // 占比计算
  1964. $data ['totalProportion'] = number_format ( $aiData ['total'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1965. $data ['profitProportion'] = number_format ( $data ['profit'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1966. $data ['sumProportion'] = number_format ( $data ['receiptLoanDetail'] ['sum'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1967. $data ['invoiceTotalAmountProportion'] = number_format ( $data ['invoiceTrainingDetail'] ['invoiceTotalAmount'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1968. $data ['RIAmountProportion'] = number_format ( $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1969. $data ['companyProfitProportion'] = number_format ( $data ['companyProfit'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1970. $data ['categoryProportion'] = number_format ( $data ['categoryProfit'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1971. $data ['categoryActualExpenditureProportion'] = number_format ( $data ['categoryActualExpenditure'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1972. $data ['paymentProportion'] = number_format ( $data ['payment'] / $invoiceTrainingDetail ['invoiceArriveAmount'], 2, '.', '' ) * 100;
  1973. // 审批组
  1974. Doo::loadModel ( 'verify' );
  1975. $verify = new verify ();
  1976. $veList = $verify->getVerifyByAll ();
  1977. // 办事处
  1978. Doo::loadModel ( 'L_category' );
  1979. $lCategory = new L_category ();
  1980. $data ['category'] = $lCategory->getCategory ();
  1981. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  1982. $data ['receiptDetail'] = $receiptDetail;
  1983. $data ['veList'] = $veList;
  1984. $data ['trainEdiType'] = $trainEdiType;
  1985. $data ['ridKey'] = $ridKey;
  1986. $data ['memu'] = "receipt";
  1987. $data ['staff'] = $this->staff;
  1988. $data ['receiptMemu'] = 'saeaBorad';
  1989. $data ['verifyId'] = $this->verifyId;
  1990. $data ['executeId'] = $this->executeId;
  1991. $this->render ( "/receipt/receiptTrainEdi", $data );
  1992. }
  1993. /**
  1994. * 培训班借款编辑
  1995. */
  1996. function receiptTrainLoanEdi() {
  1997. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1998. Doo::loadClass ( 'XDeode' );
  1999. $XDeode = new XDeode ( 7 );
  2000. $rid = $XDeode->decode ( $ridKey );
  2001. if (! is_numeric ( $rid ))
  2002. die ( 'illegal request' );
  2003. Doo::loadModel ( 'receipt' );
  2004. $receipt = new receipt ();
  2005. Doo::loadModel ( 'receiptTraining' );
  2006. $receiptTraining = new receiptTraining ();
  2007. Doo::loadModel ( 'verify' );
  2008. $verify = new verify ();
  2009. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2010. if ($receiptDetail ['status'] != 5)
  2011. die ();
  2012. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2013. // 借款详情HTML
  2014. // 获得借款信息
  2015. $receiptLoanHtml = '';
  2016. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2017. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2018. // 获得某费用单审批信息
  2019. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2020. Doo::loadClass ( 'receipt.func' );
  2021. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2022. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2023. }
  2024. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2025. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2026. $data ['receiptDetail'] = $receiptDetail;
  2027. $data ['trainEdiType'] = "LOAN";
  2028. $data ['ridKey'] = $ridKey;
  2029. $data ['memu'] = "receipt";
  2030. $data ['staff'] = $this->staff;
  2031. $data ['receiptMemu'] = 'saeaBorad';
  2032. $data ['verifyId'] = $this->verifyId;
  2033. $data ['executeId'] = $this->executeId;
  2034. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2035. }
  2036. /**
  2037. * 更新培训班结算基本信息
  2038. */
  2039. function receiptTrainInfoEdiDo() {
  2040. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2041. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2042. // 培训班信息
  2043. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2044. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2045. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2046. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2047. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2048. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2049. // 发票信息
  2050. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2051. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2052. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2053. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2054. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2055. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2056. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2057. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2058. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2059. header ( 'Content-Type:text/html;charset=utf-8' );
  2060. die ( '请填写联行号' );
  2061. }
  2062. Doo::loadClass ( 'XDeode' );
  2063. $XDeode = new XDeode ( 5 );
  2064. $cid = $XDeode->decode ( $cid );
  2065. $rtid = $XDeode->decode ( $rtid );
  2066. $rid = $XDeode->decode ( $rid );
  2067. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2068. die ( 'illegal request-IdError' );
  2069. }
  2070. Doo::loadModel ( 'receipt' );
  2071. $receipt = new receipt ();
  2072. Doo::loadModel ( 'receiptTraining' );
  2073. $receiptTraining = new receiptTraining ();
  2074. // 更新费用培训班
  2075. $item = array (
  2076. 'rtid' => $rtid,
  2077. 'trainName' => $trainName,
  2078. 'trainStartDate' => $trainStartDate,
  2079. 'trainEndDate' => $trainEndDate,
  2080. 'participants' => $participants,
  2081. 'trainAddress' => $trainAddress,
  2082. 'trainRemarks' => $trainRemarks
  2083. );
  2084. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2085. // 报销单
  2086. $receipt->rid = $rid;
  2087. $receipt->cid = $cid;
  2088. $receipt->verify = $verify;
  2089. $receipt->remittanceName = $remittanceName;
  2090. $receipt->bankName = $bankName;
  2091. $receipt->bankNumber = $bankNumber;
  2092. $receipt->remittanceBankType = $remittanceBankType;
  2093. if ($remittanceBankType == 1)
  2094. $receipt->coupletNumber = $coupletNumber;
  2095. $receipt->update ();
  2096. $XDeode = new XDeode ( 7 );
  2097. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2098. } else
  2099. die ( 'illegal request' );
  2100. }
  2101. /**
  2102. * 编辑培训班结算---更新借款
  2103. */
  2104. function receiptTrainLoanEdiDo() {
  2105. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2106. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2107. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2108. Doo::loadModel ( 'receipt' );
  2109. $receipt = new receipt ();
  2110. Doo::loadClass ( 'XDeode' );
  2111. $XDeode = new XDeode ( 5 );
  2112. $rid = $XDeode->decode ( $ridKey );
  2113. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2114. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2115. die ( 'illegal request-ridError' );
  2116. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2117. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2118. // 不合法的数据
  2119. if ($receiptDetail ['status'] != 5 || $receiptDetail ['Rtype'] != 3) {
  2120. die ( 'illegal request-receiptError' );
  2121. }
  2122. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2123. die ( 'illegal request-receipLoantError' );
  2124. }
  2125. // 培训班结算挂钩借款
  2126. $receipt = new receipt ();
  2127. $item = array (
  2128. 'rid' => $rid,
  2129. 'trainLoanRid' => $ridLoan
  2130. );
  2131. $receipt->setReceiptByCondition ( $item );
  2132. // 更新借款状态变成已挂钩
  2133. $receipt = new receipt ();
  2134. $item = array (
  2135. 'rid' => $ridLoan,
  2136. 'status' => 10,
  2137. 'statusTrain' => 1
  2138. );
  2139. $receipt->setReceiptByCondition ( $item );
  2140. $XDeode = new XDeode ( 7 );
  2141. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2142. } else
  2143. die ( 'illegal request' );
  2144. }
  2145. /**
  2146. * 编辑培训班结算--移除借款
  2147. */
  2148. function receiptTrainLoanRemoveDo() {
  2149. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2150. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2151. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2152. Doo::loadModel ( 'receipt' );
  2153. $receipt = new receipt ();
  2154. Doo::loadClass ( 'XDeode' );
  2155. $XDeode = new XDeode ( 5 );
  2156. $rid = $XDeode->decode ( $ridKey );
  2157. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2158. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2159. die ( 'illegal request-ridError' );
  2160. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2161. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2162. // 不合法的数据
  2163. if ($receiptDetail ['status'] != 5 || $receiptDetail ['Rtype'] != 3) {
  2164. die ( 'illegal request-receiptError' );
  2165. }
  2166. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2167. die ( 'illegal request-receipLoantError' );
  2168. }
  2169. // 培训班结算挂钩借款
  2170. $receipt = new receipt ();
  2171. $item = array (
  2172. 'rid' => $rid,
  2173. 'trainLoanRid' => 0
  2174. );
  2175. $receipt->setReceiptByCondition ( $item );
  2176. // 更新借款状态变成已挂钩
  2177. $receipt = new receipt ();
  2178. $item = array (
  2179. 'rid' => $ridLoan,
  2180. 'status' => 8,
  2181. 'statusTrain' => 0
  2182. );
  2183. $receipt->setReceiptByCondition ( $item );
  2184. $XDeode = new XDeode ( 7 );
  2185. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2186. } else
  2187. die ( 'illegal request' );
  2188. }
  2189. /**
  2190. * 编辑培训班结算 ---开票
  2191. */
  2192. function receiptTrainInvoiceEdi() {
  2193. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2194. Doo::loadClass ( 'XDeode' );
  2195. $XDeode = new XDeode ( 7 );
  2196. $rid = $XDeode->decode ( $ridKey );
  2197. if (! is_numeric ( $rid ))
  2198. die ( 'illegal request' );
  2199. Doo::loadModel ( 'receipt' );
  2200. $receipt = new receipt ();
  2201. Doo::loadModel ( 'receiptTraining' );
  2202. $receiptTraining = new receiptTraining ();
  2203. Doo::loadModel ( 'invoice' );
  2204. $invoice = new invoice ();
  2205. Doo::loadModel ( 'invoiceTraining' );
  2206. $invoiceTraining = new invoiceTraining ();
  2207. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2208. if ($receiptDetail ['status'] != 5)
  2209. die ();
  2210. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2211. $invoiceList = $invoiceTrainingDetail = array ();
  2212. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2213. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2214. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2215. }
  2216. // print_r($invoiceList);
  2217. $data ['invoiceList'] = $invoiceList;
  2218. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2219. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2220. $data ['receiptDetail'] = $receiptDetail;
  2221. $data ['trainEdiType'] = "INVOICE";
  2222. $data ['ridKey'] = $ridKey;
  2223. $data ['memu'] = "receipt";
  2224. $data ['staff'] = $this->staff;
  2225. $data ['receiptMemu'] = 'saeaBorad';
  2226. $data ['verifyId'] = $this->verifyId;
  2227. $data ['executeId'] = $this->executeId;
  2228. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2229. }
  2230. /**
  2231. * 编辑培训班结算---更新开票
  2232. */
  2233. function receiptTrainInvoiceEdiDo() {
  2234. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2235. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2236. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2237. Doo::loadModel ( 'receipt' );
  2238. $receipt = new receipt ();
  2239. Doo::loadModel ( 'invoiceTraining' );
  2240. $invoiceTraining = new invoiceTraining ();
  2241. Doo::loadClass ( 'XDeode' );
  2242. $XDeode = new XDeode ( 5 );
  2243. $rid = $XDeode->decode ( $ridKey );
  2244. $itid = $XDeode->decode ( $itidKey );
  2245. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2246. die ( 'illegal request-idError' );
  2247. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2248. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2249. // 不合法的数据
  2250. if ($receiptDetail ['status'] != 5 || $receiptDetail ['Rtype'] != 3) {
  2251. die ( 'illegal request-receiptError' );
  2252. }
  2253. if (empty ( $invoiceTrainDetail )) {
  2254. die ( 'illegal request-receipLoantError' );
  2255. }
  2256. // 培训班结算挂钩借款
  2257. $receipt = new receipt ();
  2258. $item = array (
  2259. 'rid' => $rid,
  2260. 'invoiceTrainId' => $itid
  2261. );
  2262. $receipt->setReceiptByCondition ( $item );
  2263. $XDeode = new XDeode ( 7 );
  2264. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2265. } else
  2266. die ( 'illegal request' );
  2267. }
  2268. /**
  2269. * 更新培训班结算 收款和取消收款
  2270. */
  2271. function receiptTrainReceivables() {
  2272. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2273. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2274. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2275. Doo::loadClass ( 'XDeode' );
  2276. $XDeode = new XDeode ( 5 );
  2277. $rid = $XDeode->decode ( $ridKey );
  2278. $iid = $XDeode->decode ( $iidKey );
  2279. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2280. die ( 'illegal request-iid' );
  2281. Doo::loadModel ( 'RIExtend' );
  2282. $RIExtend = new RIExtend ();
  2283. if ($doType == 'CONFIRM') {
  2284. $RIExtend->rid = $rid;
  2285. $RIExtend->iid = $iid;
  2286. $RIExtend->RIstatus = 1;
  2287. $RIExtend->insert ();
  2288. $XDeode = new XDeode ( 7 );
  2289. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2290. } elseif ($doType == 'CANCEL') {
  2291. $RIExtend->delete ( array (
  2292. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2293. 'limit' => 1
  2294. ) );
  2295. $XDeode = new XDeode ( 7 );
  2296. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2297. } else {
  2298. die ( 'illegal request' );
  2299. }
  2300. }
  2301. /**
  2302. * 移除挂钩的培训班发票
  2303. */
  2304. function receiptTrainReceivablesDelDo() {
  2305. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2306. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2307. Doo::loadModel ( 'receipt' );
  2308. $receipt = new receipt ();
  2309. Doo::loadModel ( 'RIExtend' );
  2310. $RIExtend = new RIExtend ();
  2311. Doo::loadClass ( 'XDeode' );
  2312. $XDeode = new XDeode ( 5 );
  2313. $rid = $XDeode->decode ( $ridKey );
  2314. $itid = $XDeode->decode ( $itidKey );
  2315. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2316. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2317. if ($receiptDetail ['status'] != 5)
  2318. die ( 'illegal request-status' );
  2319. $receipt = new receipt ();
  2320. $receipt->rid = $rid;
  2321. $receipt->invoiceTrainId = 0;
  2322. $receipt->update ();
  2323. $RIExtend->delete ( array (
  2324. 'where' => 'rid=' . $rid
  2325. ) );
  2326. $XDeode = new XDeode ( 7 );
  2327. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2328. } else
  2329. die ( 'illegal request-iid' );
  2330. }
  2331. /**
  2332. * 编辑培训班结算
  2333. */
  2334. function receiptTrainItemEdi() {
  2335. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2336. Doo::loadClass ( 'XDeode' );
  2337. $XDeode = new XDeode ( 7 );
  2338. $rid = $XDeode->decode ( $ridKey );
  2339. if (! is_numeric ( $rid ))
  2340. die ( 'illegal request' );
  2341. Doo::loadModel ( 'receipt' );
  2342. $receipt = new receipt ();
  2343. Doo::loadModel ( 'receiptTraining' );
  2344. $receiptTraining = new receiptTraining ();
  2345. Doo::loadModel ( 'RItem' );
  2346. $RItem = new RItem ();
  2347. Doo::loadModel ( 'accountItem' );
  2348. $accountItem = new accountItem ();
  2349. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2350. if ($receiptDetail ['status'] != 5)
  2351. die ();
  2352. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2353. $RItemList = $RItem->getRItemByRid ( $rid );
  2354. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2355. // print_r($RItemList);
  2356. $data ['RItemList'] = $RItemList;
  2357. $data ['aiList'] = $aiList;
  2358. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2359. $data ['receiptDetail'] = $receiptDetail;
  2360. $data ['trainEdiType'] = "ITEM";
  2361. $data ['ridKey'] = $ridKey;
  2362. $data ['memu'] = "receipt";
  2363. $data ['staff'] = $this->staff;
  2364. $data ['receiptMemu'] = 'saeaBorad';
  2365. $data ['verifyId'] = $this->verifyId;
  2366. $data ['executeId'] = $this->executeId;
  2367. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2368. }
  2369. /**
  2370. * 添加支出项
  2371. */
  2372. function receiptTrainItemAddDo() {
  2373. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2374. // 支出项信息
  2375. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2376. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2377. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2378. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2379. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2380. if (! empty ( $ridKey ) && ! empty ( $item ) && ! empty ( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2381. Doo::loadClass ( 'XDeode' );
  2382. $XDeode = new XDeode ( 5 );
  2383. Doo::loadModel ( 'RItem' );
  2384. $RItem = new RItem ();
  2385. $rid = $XDeode->decode ( $ridKey );
  2386. if (! is_numeric ( $rid ))
  2387. die ( 'illegal request' );
  2388. $RItem->rid = $rid;
  2389. $RItem->item = $item;
  2390. $RItem->price = $price;
  2391. $RItem->date = $date;
  2392. $RItem->inputer = $inputer;
  2393. $RItem->describe = $describe;
  2394. $RItem->insert ();
  2395. // 添加公司汇总
  2396. // 报销详情
  2397. Doo::loadModel ( 'receiptDetail' );
  2398. $receiptDetail = new receiptDetail ();
  2399. Doo::loadModel ( 'receipt' );
  2400. $receipt = new receipt ();
  2401. $rInfo = $receipt->getReceiptByRid ( $rid );
  2402. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, $item, '培训班费用' );
  2403. if (empty ( $rdInfo )) {
  2404. $receiptDetail = new receiptDetail ();
  2405. $receiptDetail->staff = $this->staff [0] ['sid'];
  2406. $receiptDetail->item = $item;
  2407. $receiptDetail->itemCategory = '培训班费用';
  2408. $receiptDetail->price = number_format ( $price, 2, '.', '' );
  2409. $receiptDetail->date = date ( "Y-m-d" );
  2410. $receiptDetail->cid = $rInfo ['cid'];
  2411. $receiptDetail->rid = $rid;
  2412. $receiptDetail->status = 4;
  2413. $receiptDetail->insert ();
  2414. } else {
  2415. $receiptDetail = new receiptDetail ();
  2416. $rdInfo ['price'] += number_format ( $price, 2, '.', '' );
  2417. $receiptDetail->price = $rdInfo ['price'];
  2418. $receiptDetail->update ( array (
  2419. 'where' => 'rid=' . $rid . ' and item like "' . $item . '" and itemCategory like "培训班费用"'
  2420. ) );
  2421. }
  2422. $XDeode = new XDeode ( 7 );
  2423. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2424. } else
  2425. die ( 'illegal request' );
  2426. }
  2427. /**
  2428. * 培训班结算-讲师
  2429. */
  2430. function receiptTrainLecturerEdi() {
  2431. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2432. Doo::loadClass ( 'XDeode' );
  2433. $XDeode = new XDeode ( 7 );
  2434. $rid = $XDeode->decode ( $ridKey );
  2435. if (! is_numeric ( $rid ))
  2436. die ( 'illegal request' );
  2437. Doo::loadModel ( 'receipt' );
  2438. $receipt = new receipt ();
  2439. Doo::loadModel ( 'receiptTraining' );
  2440. $receiptTraining = new receiptTraining ();
  2441. Doo::loadModel ( 'RILecturer' );
  2442. $RILecturer = new RILecturer ();
  2443. Doo::loadModel ( 'lecturer' );
  2444. $lecturer = new lecturer ();
  2445. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2446. if ($receiptDetail ['status'] != 5)
  2447. die ();
  2448. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2449. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2450. $lecturerList = $lecturer->getLecturerAll ();
  2451. $INSIDEhtml = $OUTSIDEhtml = '';
  2452. foreach ( $lecturerList as $key => $value ) {
  2453. if ($value ['ltype'] == 'INSIDE') {
  2454. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2455. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2456. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2457. }
  2458. }
  2459. $data ['INSIDEhtml'] = $INSIDEhtml;
  2460. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2461. // print_r($RItemList);
  2462. $data ['RILecturerList'] = $RILecturerList;
  2463. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2464. $data ['receiptDetail'] = $receiptDetail;
  2465. $data ['trainEdiType'] = "LECTURER";
  2466. $data ['ridKey'] = $ridKey;
  2467. $data ['memu'] = "receipt";
  2468. $data ['staff'] = $this->staff;
  2469. $data ['receiptMemu'] = 'saeaBorad';
  2470. $data ['verifyId'] = $this->verifyId;
  2471. $data ['executeId'] = $this->executeId;
  2472. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2473. }
  2474. /**
  2475. * 添加讲师
  2476. */
  2477. function receiptTrainLecturerAddDo() {
  2478. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2479. // 支出项信息
  2480. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2481. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2482. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2483. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2484. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2485. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2486. Doo::loadClass ( 'XDeode' );
  2487. $XDeode = new XDeode ( 5 );
  2488. Doo::loadModel ( 'RILecturer' );
  2489. $RILecturer = new RILecturer ();
  2490. $rid = $XDeode->decode ( $ridKey );
  2491. if (! is_numeric ( $rid ))
  2492. die ( 'illegal request' );
  2493. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2494. die ( 'illegal request-taxationError' );
  2495. $RILecturer->rid = $rid;
  2496. $RILecturer->ltype = $ltype;
  2497. if ($ltype == 'OUTSIDE') {
  2498. if ($taxation == 'TAXATION') {
  2499. $RILecturer->taxation = 1;
  2500. } elseif ($taxation == 'NOTAXATION') {
  2501. $RILecturer->taxation = 0;
  2502. }
  2503. }
  2504. $RILecturer->lecturerName = $lecturerName;
  2505. $RILecturer->schoolDay = $schoolDay;
  2506. $RILecturer->price = $price;
  2507. $RILecturer->insert ();
  2508. // 添加公司汇总
  2509. // 报销详情
  2510. Doo::loadModel ( 'receiptDetail' );
  2511. $receiptDetail = new receiptDetail ();
  2512. Doo::loadModel ( 'receipt' );
  2513. $receipt = new receipt ();
  2514. // 金额总计
  2515. $price = $price * $schoolDay;
  2516. $rInfo = $receipt->getReceiptByRid ( $rid );
  2517. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2518. if (empty ( $rdInfo )) {
  2519. $receiptDetail = new receiptDetail ();
  2520. $receiptDetail->staff = $this->staff [0] ['sid'];
  2521. $receiptDetail->item = '讲课费';
  2522. $receiptDetail->itemCategory = '培训班费用';
  2523. $receiptDetail->price = number_format ( $price, 2, '.', '' );
  2524. $receiptDetail->date = date ( "Y-m-d" );
  2525. $receiptDetail->cid = $rInfo ['cid'];
  2526. $receiptDetail->rid = $rid;
  2527. $receiptDetail->status = 4;
  2528. $receiptDetail->insert ();
  2529. } else {
  2530. $receiptDetail = new receiptDetail ();
  2531. $rdInfo ['price'] += number_format ( $price, 2, '.', '' );
  2532. $receiptDetail->price = $rdInfo ['price'];
  2533. $receiptDetail->update ( array (
  2534. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2535. ) );
  2536. }
  2537. $XDeode = new XDeode ( 7 );
  2538. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2539. } else
  2540. die ( 'illegal request' );
  2541. }
  2542. /**
  2543. * 移除讲师
  2544. */
  2545. function receiptTrainLecturerDelDo() {
  2546. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2547. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2548. Doo::loadModel ( 'receipt' );
  2549. $receipt = new receipt ();
  2550. Doo::loadModel ( 'RILecturer' );
  2551. $RILecturer = new RILecturer ();
  2552. Doo::loadClass ( 'XDeode' );
  2553. $XDeode = new XDeode ( 5 );
  2554. $rid = $XDeode->decode ( $ridKey );
  2555. $rlid = $XDeode->decode ( $rlidKey );
  2556. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2557. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2558. if ($receiptDetail ['status'] != 5)
  2559. die ( 'illegal request-status' );
  2560. $RILecturer->delete ( array (
  2561. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2562. ) );
  2563. $XDeode = new XDeode ( 7 );
  2564. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2565. } else
  2566. die ( 'illegal request-iid' );
  2567. }
  2568. /**
  2569. * 培训班提交审批
  2570. */
  2571. function receiptTrainApprovalDo() {
  2572. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";;
  2573. Doo::loadClass ( 'XDeode' );
  2574. $XDeode = new XDeode ( 7 );
  2575. $rid = $XDeode->decode ( $ridKey );
  2576. Doo::loadModel ( 'receipt' );
  2577. $receipt = new receipt ();
  2578. Doo::loadModel ( 'receiptDetail' );
  2579. $receiptDetail = new receiptDetail ();
  2580. Doo::loadModel ( 'statistics' );
  2581. $statistics = new statistics ();
  2582. Doo::loadModel ( "verify" );
  2583. $verify = new verify ();
  2584. // 审批状态的判定
  2585. $receiptDetailList = $receipt->getOne ( array (
  2586. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2587. 'asArray' => true
  2588. ) );
  2589. if (empty ( $receiptDetailList ))
  2590. return "/saeaBorad";
  2591. $verifyDetail = $verify->getOne ( array (
  2592. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2593. 'asArray' => true
  2594. ) );
  2595. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2596. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2597. $nowStaff = "";
  2598. $nowStaffList = array ();
  2599. if ($verifyDetail [0] [1] == 'ROLE') {
  2600. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2601. foreach ( $vStaffString as $key => $value ) {
  2602. $staffK = explode ( "_", $value );
  2603. array_push ( $nowStaffList, $staffK [0] );
  2604. }
  2605. $nowStaff = implode ( ',', $nowStaffList );
  2606. } else {
  2607. $nowStaff = $verifyDetail [0] [0];
  2608. }
  2609. $receipt->nowStaff = $nowStaff;
  2610. }
  2611. // echo $nowStaff;
  2612. // print_r($verifyDetail);die;
  2613. $receipt->rid = $receiptDetailList ['rid'];
  2614. $receipt->date = date ( "Y-m-d" );
  2615. $receipt->status = 2;
  2616. $receipt->update ();
  2617. $receiptDetail->status = 2;
  2618. $receiptDetail->update ( array (
  2619. 'where' => 'rid=' . $receiptDetailList ['rid']
  2620. ) );
  2621. Doo::loadModel ( "receiptLog" );
  2622. $receiptLog = new receiptLog ();
  2623. Doo::loadModel ( "verify" );
  2624. $verify = new verify ();
  2625. $vr = $verify->getOne ( array (
  2626. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2627. 'asArray' => true
  2628. ) );
  2629. $jd = json_decode ( $vr ['staff'] );
  2630. $roleId = 0;
  2631. foreach ( $jd as $key => $value ) {
  2632. if ($value [1] == 'ROLE') {
  2633. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2634. if ($pos !== false) {
  2635. $roleId = $value [0];
  2636. }
  2637. }
  2638. }
  2639. // 审批日志
  2640. // echo $roleId;die;
  2641. if (! empty ( $roleId )) {
  2642. Doo::loadModel ( "role" );
  2643. $role = new role ();
  2644. $roleInfo = $role->getOne ( array (
  2645. 'where' => 'rid=' . $roleId,
  2646. 'asArray' => true
  2647. ) );
  2648. // $receiptLog->rolename = $roleInfo ['name'];
  2649. }
  2650. $receiptLog->username = $this->staff [0] ['username'];
  2651. $receiptLog->uid = $this->staff [0] ['sid'];
  2652. $receiptLog->date = date ( "Y-m-d" );
  2653. $receiptLog->opinion = '提交审批';
  2654. $receiptLog->img = $this->staff [0] ['avatar'];
  2655. $receiptLog->status = 2;
  2656. $receiptLog->rid = $rid;
  2657. $receiptLog->insert ();
  2658. //写入列表项
  2659. Doo::loadModel ( 'accountItem' );
  2660. $accountItem = new accountItem ();
  2661. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2662. // 项目金额合计
  2663. Doo::loadModel ( 'RItem' );
  2664. $RItem = new RItem ();
  2665. // 讲师获得
  2666. Doo::loadModel ( 'RILecturer' );
  2667. $RILecturer = new RILecturer ();
  2668. $RItemList = $RItem->getRItemByRid ( $rid );
  2669. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2670. // 支出项金额详情
  2671. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2672. //print_r($aItem);
  2673. //print_r($aiData);
  2674. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2675. $ag = $tr = $ta = $ot = 0;
  2676. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2677. foreach ( $aItem as $key => $value ) {
  2678. if ($value ['category'] == $this->TRAIN) {
  2679. foreach ($aiData['dataList'] as $k=>$v){
  2680. if ($value ['name'] == $v['name']) {
  2681. array_push ( $accountJson [$this->TRAIN], array (
  2682. 'aid' => $value ['aid'],
  2683. 'name' => $value ['name'],
  2684. 'price' => number_format ( $v['price'], 2, '.', '' )
  2685. ) );
  2686. $sum += $v['price'];
  2687. $trainSum += $v['price'];
  2688. unset($aiData['dataList'][$k]);
  2689. break;
  2690. }
  2691. }
  2692. }
  2693. }
  2694. $accountJson ['cSum'] = array (
  2695. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2696. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2697. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2698. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2699. );
  2700. // 报销单
  2701. $receipt = new receipt ();
  2702. $receipt->accountItem = json_encode ( $accountJson );
  2703. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2704. $receipt->update ( array (
  2705. 'where' => 'rid=' . $rid
  2706. ) );
  2707. //print_r($accountJson);
  2708. // statistics item 统计写入
  2709. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2710. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2711. $accountItem = $accountJson ;
  2712. $stat = $statistics->getOne ( array (
  2713. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2714. 'asArray' => true
  2715. ) );
  2716. if (empty ( $stat )) {
  2717. $statistics->date = date ( "Y-m-d" );
  2718. $statistics->cid = $this->staff [0] ['cid'];
  2719. $statistics->staff = $this->staff [0] ['sid'];
  2720. $statistics->agPrice = 0;
  2721. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2722. $statistics->insert ();
  2723. } else {
  2724. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2725. $statistics->update ( array (
  2726. 'where' => 'sid=' . $stat ['sid']
  2727. ) );
  2728. }
  2729. return "/saeaBorad";
  2730. }
  2731. function confirmation() {
  2732. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2733. Doo::loadModel ( 'receipt' );
  2734. Doo::loadModel ( 'receiptDetail' );
  2735. $receipt = new receipt ();
  2736. $receiptDetail = new receiptDetail ();
  2737. Doo::loadModel ( 'statistics' );
  2738. Doo::loadModel ( 'itemStatistics' );
  2739. $statistics = new statistics ();
  2740. $itemStatistics = new itemStatistics ();
  2741. Doo::loadModel ( "verify" );
  2742. $verify = new verify ();
  2743. $receiptDetailList = $receipt->getOne ( array (
  2744. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2745. 'asArray' => true
  2746. ) );
  2747. if (empty ( $receiptDetailList ))
  2748. return "/saeaBorad";
  2749. $verifyDetail = $verify->getOne ( array (
  2750. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2751. 'asArray' => true
  2752. ) );
  2753. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2754. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2755. $nowStaff = "";
  2756. $nowStaffList = array ();
  2757. if ($verifyDetail [0] [1] == 'ROLE') {
  2758. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2759. foreach ( $vStaffString as $key => $value ) {
  2760. $staffK = explode ( "_", $value );
  2761. array_push ( $nowStaffList, $staffK [0] );
  2762. }
  2763. $nowStaff = implode ( ',', $nowStaffList );
  2764. } else {
  2765. $nowStaff = $verifyDetail [0] [0];
  2766. }
  2767. $receipt->nowStaff = $nowStaff;
  2768. }
  2769. // echo $nowStaff;
  2770. // print_r($verifyDetail);die;
  2771. $receipt->rid = $receiptDetailList ['rid'];
  2772. $receipt->status = 2;
  2773. $receipt->update ();
  2774. // 操作日志
  2775. Doo::loadModel ( "receiptLog" );
  2776. $receiptLog = new receiptLog ();
  2777. $verify = new verify ();
  2778. $receiptInfo = $receipt->getOne ( array (
  2779. 'where' => 'rid=' . $rid,
  2780. 'asArray' => true
  2781. ) );
  2782. $vr = $verify->getOne ( array (
  2783. 'where' => 'vid=' . $receiptInfo ['verify'],
  2784. 'asArray' => true
  2785. ) );
  2786. $jd = json_decode ( $vr ['staff'] );
  2787. $roleId = 0;
  2788. foreach ( $jd as $key => $value ) {
  2789. if ($value [1] == 'ROLE') {
  2790. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2791. if ($pos !== false) {
  2792. $roleId = $value [0];
  2793. }
  2794. }
  2795. }
  2796. // 审批日志
  2797. // echo $roleId;die;
  2798. if (! empty ( $roleId )) {
  2799. Doo::loadModel ( "role" );
  2800. $role = new role ();
  2801. $roleInfo = $role->getOne ( array (
  2802. 'where' => 'rid=' . $roleId,
  2803. 'asArray' => true
  2804. ) );
  2805. // $receiptLog->rolename = $roleInfo ['name'];
  2806. }
  2807. $receiptLog->username = $this->staff [0] ['username'];
  2808. $receiptLog->uid = $this->staff [0] ['sid'];
  2809. $receiptLog->date = date ( "Y-m-d" );
  2810. $receiptLog->opinion = '提交审批';
  2811. $receiptLog->img = $this->staff [0] ['avatar'];
  2812. $receiptLog->status = 2;
  2813. $receiptLog->rid = $rid;
  2814. $receiptLog->insert ();
  2815. return "/expenses";
  2816. }
  2817. function expenses() {
  2818. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2819. if (empty ( $item ))
  2820. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2821. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2822. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2823. Doo::loadModel ( 'receipt' );
  2824. $receipt = new receipt ();
  2825. Doo::loadModel ( 'L_category' );
  2826. $Lcategory = new L_category ();
  2827. Doo::loadModel ( 'verify' );
  2828. Doo::loadModel ( 'statistics' );
  2829. $statistics = new statistics ();
  2830. $verify = new verify ();
  2831. Doo::loadModel ( 'staff' );
  2832. $staff = new staff ();
  2833. $condition = "";
  2834. if ($item == "expenses")
  2835. $condition = " and Rtype=1 ";
  2836. elseif ($item == "receipts")
  2837. $condition = " and Rtype=0 ";
  2838. elseif ($item == "remits")
  2839. $condition = " and Rtype=2 ";
  2840. $dateCondition = " and Year(date) =" . $year;
  2841. if (! empty ( $moth )) {
  2842. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2843. $stList = $statistics->getOne ( array (
  2844. 'select' => 'rePrice ,agPrice',
  2845. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2846. 'asArray' => true
  2847. ) );
  2848. } else
  2849. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2850. if (empty ( $stList ))
  2851. $stList = array (
  2852. 'rePrice' => 0,
  2853. 'agPrice' => 0
  2854. );
  2855. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2856. if (! isset ( $noPassSum ['sum'] ))
  2857. $noPassSum ['sum'] = 0;
  2858. $data ['stList'] = array (
  2859. 'rePrice' => $stList ['rePrice'],
  2860. 'agPrice' => $stList ['agPrice'],
  2861. 'skPrice' => ($noPassSum ['sum'])
  2862. );
  2863. $receiptList = $receipt->find ( array (
  2864. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2865. 'desc' => 'rid',
  2866. 'asArray' => true
  2867. ) );
  2868. $Locate = 0;
  2869. $roleId = 0;
  2870. $button = 0;
  2871. foreach ( $receiptList as $key => $value ) {
  2872. $receiptList [$key] ['Locate'] = $Locate;
  2873. $Locate ++;
  2874. $receiptList [$key] ['reviseDetail'] = array ();
  2875. if (! empty ( $value ['reviseDetail'] ))
  2876. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2877. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2878. $categoryDetil = $Lcategory->getOne ( array (
  2879. 'where' => 'cid=' . $value ['cid'],
  2880. 'asArray' => true
  2881. ) );
  2882. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2883. // 检测编辑状态
  2884. $verifyList = $verify->getOne ( array (
  2885. 'where' => 'vid=' . $value ['verify'],
  2886. 'asArray' => true
  2887. ) );
  2888. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2889. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2890. Doo::loadModel ( 'role' );
  2891. $role = new role ();
  2892. $flag = true;
  2893. $roleKey = 0;
  2894. $endStaffArray = array ();
  2895. $roleArrayCopy = array ();
  2896. foreach ( $verifyList as $k => $v ) {
  2897. // init verifyStaff
  2898. if ($v [1] == 'ROLE') {
  2899. if (! empty ( $verifyStaff )) {
  2900. $endStaffArray = end ( $verifyStaff );
  2901. // if ($v[0]==$endStaffArray['nextStaff']){
  2902. // $roleId=$v[0];
  2903. // }
  2904. }
  2905. $roleVerify = json_decode ( $v [3], true );
  2906. $roleKey = $k;
  2907. $roleArray = array ();
  2908. $rolename = $role->getOne ( array (
  2909. 'where' => 'rid=' . $v [0],
  2910. 'asArray' => true
  2911. ) );
  2912. foreach ( $roleVerify as $o => $p ) {
  2913. $staffID = explode ( '_', $p );
  2914. $staffInfo = $staff->getOne ( array (
  2915. 'where' => 'sid=' . $staffID [0],
  2916. 'asArray' => true
  2917. ) );
  2918. // print_r($staffID);
  2919. $exp = array (
  2920. 0 => $staffInfo ['sid'],
  2921. 1 => $staffID [1],
  2922. 2 => $staffInfo ['avatar'],
  2923. 'date' => '',
  2924. 'date' => '',
  2925. 'opinion' => '',
  2926. 'status' => '',
  2927. 'rolename' => $rolename ['name']
  2928. );
  2929. array_push ( $roleArray, $exp );
  2930. }
  2931. $roleArrayCopy [$v [0]] = $roleArray;
  2932. // $verifyList[$k]['roleArray']=$roleArray;
  2933. }
  2934. $verifyList [$k] ['date'] = "";
  2935. $verifyList [$k] ['opinion'] = "";
  2936. $verifyList [$k] ['status'] = "";
  2937. if (empty ( $verifyStaff )) {
  2938. $verifyList [$k] ['date'] = "";
  2939. $verifyList [$k] ['opinion'] = "";
  2940. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2941. $verifyList [$k] ['status'] = 4;
  2942. $flag = false;
  2943. }
  2944. } else {
  2945. foreach ( $verifyStaff as $m => $u ) {
  2946. if ($v [0] == $m) {
  2947. $verifyList [$k] ['date'] = $u ['date'];
  2948. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2949. $verifyList [$k] ['status'] = $u ['status'];
  2950. $flag = false;
  2951. break;
  2952. }
  2953. }
  2954. $endStaffArray = end ( $verifyStaff );
  2955. if (isset ( $endStaffArray ['ROLE'] )) {
  2956. } else {
  2957. // $endKey=key($verifyStaff);
  2958. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2959. // $button=4;
  2960. // $verifyList[$k]['status']=4;
  2961. // }
  2962. }
  2963. }
  2964. }
  2965. $rolename ['name'] = '';
  2966. if (! empty ( $roleId )) {
  2967. Doo::loadModel ( 'role' );
  2968. $role = new role ();
  2969. $rolename = $role->getOne ( array (
  2970. 'where' => 'rid=' . $roleId,
  2971. 'asArray' => true
  2972. ) );
  2973. }
  2974. if (! empty ( $verifyStaff ))
  2975. $endStaffArray = end ( $verifyStaff );
  2976. $KOP = false;
  2977. foreach ( $roleArrayCopy as $P => $A ) {
  2978. foreach ( $A as $MKI => $AVL ) {
  2979. if (! empty ( $verifyStaff )) {
  2980. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2981. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2982. $button = 4;
  2983. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2984. }
  2985. foreach ( $verifyStaff as $m => $u ) {
  2986. $AVLFK = $AVL [0] . '_R';
  2987. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2988. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2989. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2990. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2991. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2992. break;
  2993. }
  2994. }
  2995. } else {
  2996. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2997. $button = 4;
  2998. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2999. }
  3000. }
  3001. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3002. $KOP = true;
  3003. }
  3004. }
  3005. foreach ( $roleArrayCopy as $k => $v ) {
  3006. foreach ( $verifyList as $m => $n ) {
  3007. if ($n [0] == $k) {
  3008. array_splice ( $verifyList, $m, 1, $v );
  3009. }
  3010. }
  3011. }
  3012. $receiptList [$key] ['verifyList'] = $verifyList;
  3013. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3014. 'where' => 'sid=' . $value ['staff'],
  3015. 'asArray' => true
  3016. ) );
  3017. $receiptList [$key] ['button'] = $button;
  3018. }
  3019. // print_r($receiptList);die;
  3020. $mothHtml = "";
  3021. for($i = 1; $i <= 12; $i ++) {
  3022. if ($moth == $i)
  3023. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3024. else
  3025. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3026. }
  3027. $dateHtml = "";
  3028. $now = date ( "Y" );
  3029. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3030. if ($YEARD <= $now) {
  3031. $dateHtml .= '<option ';
  3032. if ($year == $YEARD) {
  3033. $dateHtml .= 'selected ';
  3034. }
  3035. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3036. }
  3037. }
  3038. $data ['dateHtml'] = $dateHtml;
  3039. $data ['mothHtml'] = $mothHtml;
  3040. $data ['receiptList'] = $receiptList;
  3041. $data ['memu'] = "receipt";
  3042. $data ['staff'] = $this->staff;
  3043. $data ['receiptMemu'] = 'expenses';
  3044. $data ['verifyId'] = $this->verifyId;
  3045. $data ['executeId'] = $this->executeId;
  3046. $data ['item'] = $item;
  3047. $data ['year'] = $year;
  3048. $this->render ( "/admin/expenses", $data );
  3049. }
  3050. function expensesCollect() {
  3051. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3052. Doo::loadModel ( 'receipt' );
  3053. $receipt = new receipt ();
  3054. Doo::loadModel ( 'L_category' );
  3055. $Lcategory = new L_category ();
  3056. Doo::loadModel ( 'verify' );
  3057. Doo::loadModel ( 'statistics' );
  3058. $statistics = new statistics ();
  3059. $verify = new verify ();
  3060. Doo::loadModel ( 'staff' );
  3061. $staff = new staff ();
  3062. Doo::loadModel ( 'loanReceipt' );
  3063. $loanReceipt = new loanReceipt ();
  3064. $receiptList = $receipt->find ( array (
  3065. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3066. 'desc' => 'rid',
  3067. 'asArray' => true
  3068. ) );
  3069. $loanList = $loanReceipt->find ( array (
  3070. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3071. 'desc' => 'rid',
  3072. 'asArray' => true
  3073. ) );
  3074. /*
  3075. * $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;
  3076. */
  3077. $data ['explanation'] = '';
  3078. if (! empty ( $loanList ))
  3079. $data ['explanation'] = $loanList [0] ['explanation'];
  3080. $Locate = 0;
  3081. $roleId = 0;
  3082. $button = 0;
  3083. foreach ( $receiptList as $key => $value ) {
  3084. $receiptList [$key] ['Locate'] = $Locate;
  3085. $Locate ++;
  3086. $receiptList [$key] ['reviseDetail'] = array ();
  3087. if (! empty ( $value ['reviseDetail'] ))
  3088. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3089. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3090. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3091. $categoryDetil = $Lcategory->getOne ( array (
  3092. 'where' => 'cid=' . $value ['cid'],
  3093. 'asArray' => true
  3094. ) );
  3095. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3096. // 检测编辑状态
  3097. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3098. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3099. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3100. else
  3101. $verifyList ['staff'] = $value ['verifyBreakup'];
  3102. } else
  3103. $verifyList = $verify->getOne ( array (
  3104. 'where' => 'vid=' . $value ['verify'],
  3105. 'asArray' => true
  3106. ) );
  3107. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3108. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3109. Doo::loadModel ( 'role' );
  3110. $role = new role ();
  3111. $flag = true;
  3112. $roleKey = 0;
  3113. $endStaffArray = array ();
  3114. $roleArrayCopy = array ();
  3115. foreach ( $verifyList as $k => $v ) {
  3116. // init verifyStaff
  3117. if ($v [1] == 'ROLE') {
  3118. if (! empty ( $verifyStaff )) {
  3119. $endStaffArray = end ( $verifyStaff );
  3120. // if ($v[0]==$endStaffArray['nextStaff']){
  3121. // $roleId=$v[0];
  3122. // }
  3123. }
  3124. $roleVerify = json_decode ( $v [3], true );
  3125. $roleKey = $k;
  3126. $roleArray = array ();
  3127. $rolename = $role->getOne ( array (
  3128. 'where' => 'rid=' . $v [0],
  3129. 'asArray' => true
  3130. ) );
  3131. foreach ( $roleVerify as $o => $p ) {
  3132. $staffID = explode ( '_', $p );
  3133. $staffInfo = $staff->getOne ( array (
  3134. 'where' => 'sid=' . $staffID [0],
  3135. 'asArray' => true
  3136. ) );
  3137. // print_r($staffID);
  3138. $exp = array (
  3139. 0 => $staffInfo ['sid'],
  3140. 1 => $staffID [1],
  3141. 2 => $staffInfo ['avatar'],
  3142. 'date' => '',
  3143. 'date' => '',
  3144. 'opinion' => '',
  3145. 'status' => '',
  3146. 'rolename' => $rolename ['name']
  3147. );
  3148. array_push ( $roleArray, $exp );
  3149. }
  3150. $roleArrayCopy [$v [0]] = $roleArray;
  3151. // $verifyList[$k]['roleArray']=$roleArray;
  3152. }
  3153. $verifyList [$k] ['date'] = "";
  3154. $verifyList [$k] ['opinion'] = "";
  3155. $verifyList [$k] ['status'] = "";
  3156. if (empty ( $verifyStaff )) {
  3157. $verifyList [$k] ['date'] = "";
  3158. $verifyList [$k] ['opinion'] = "";
  3159. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3160. $verifyList [$k] ['status'] = 4;
  3161. $flag = false;
  3162. }
  3163. } else {
  3164. foreach ( $verifyStaff as $m => $u ) {
  3165. if ($v [0] == $m) {
  3166. $verifyList [$k] ['date'] = $u ['date'];
  3167. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3168. $verifyList [$k] ['status'] = $u ['status'];
  3169. $flag = false;
  3170. break;
  3171. }
  3172. }
  3173. $endStaffArray = end ( $verifyStaff );
  3174. if (isset ( $endStaffArray ['ROLE'] )) {
  3175. } else {
  3176. // $endKey=key($verifyStaff);
  3177. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3178. // $button=4;
  3179. // $verifyList[$k]['status']=4;
  3180. // }
  3181. }
  3182. }
  3183. }
  3184. $rolename ['name'] = '';
  3185. if (! empty ( $roleId )) {
  3186. Doo::loadModel ( 'role' );
  3187. $role = new role ();
  3188. $rolename = $role->getOne ( array (
  3189. 'where' => 'rid=' . $roleId,
  3190. 'asArray' => true
  3191. ) );
  3192. }
  3193. if (! empty ( $verifyStaff ))
  3194. $endStaffArray = end ( $verifyStaff );
  3195. $KOP = false;
  3196. foreach ( $roleArrayCopy as $P => $A ) {
  3197. foreach ( $A as $MKI => $AVL ) {
  3198. if (! empty ( $verifyStaff )) {
  3199. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3200. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3201. $button = 4;
  3202. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3203. }
  3204. foreach ( $verifyStaff as $m => $u ) {
  3205. $AVLFK = $AVL [0] . '_R';
  3206. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3207. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3208. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3209. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3210. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3211. break;
  3212. }
  3213. }
  3214. } else {
  3215. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3216. $button = 4;
  3217. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3218. }
  3219. }
  3220. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3221. $KOP = true;
  3222. }
  3223. }
  3224. foreach ( $roleArrayCopy as $k => $v ) {
  3225. foreach ( $verifyList as $m => $n ) {
  3226. if ($n [0] == $k) {
  3227. array_splice ( $verifyList, $m, 1, $v );
  3228. }
  3229. }
  3230. }
  3231. // 费用执行人相关数据
  3232. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3233. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3234. foreach ( $executeCopy as $k => $v ) {
  3235. $executeCopy [$k] ['date'] = '';
  3236. $executeCopy [$k] ['opinion'] = '';
  3237. $executeCopy [$k] ['status'] = '';
  3238. if (! empty ( $executeStaff ))
  3239. foreach ( $executeStaff as $m => $u ) {
  3240. if ($v [0] == $m) {
  3241. $executeCopy [$k] ['date'] = $u ['date'];
  3242. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3243. $executeCopy [$k] ['status'] = $u ['status'];
  3244. break;
  3245. }
  3246. }
  3247. }
  3248. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3249. $receiptList [$key] ['verifyList'] = $verifyList;
  3250. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3251. 'where' => 'sid=' . $value ['staff'],
  3252. 'asArray' => true
  3253. ) );
  3254. $receiptList [$key] ['button'] = $button;
  3255. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3256. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3257. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3258. $receiptList [$key] ['relust'] = $relust;
  3259. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3260. }
  3261. Doo::loadModel ( 'enclosur' );
  3262. $enclosur = new enclosur ();
  3263. $enclosurList = $enclosur->find ( array (
  3264. 'where' => 'rid=' . $rid,
  3265. 'asArray' => true
  3266. ) );
  3267. $enclosurHtml = '';
  3268. foreach ( $enclosurList as $value ) {
  3269. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3270. }
  3271. $data ['enclosurHtml'] = $enclosurHtml;
  3272. // print_r($receiptList);
  3273. $data ['receiptList'] = $receiptList;
  3274. $data ['memu'] = "receipt";
  3275. $data ['staff'] = $this->staff;
  3276. $data ['receiptMemu'] = 'expenses';
  3277. $data ['verifyId'] = $this->verifyId;
  3278. $data ['executeId'] = $this->executeId;
  3279. $this->render ( "/admin/expensesCollect", $data );
  3280. }
  3281. function approvalExpenses() {
  3282. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3283. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3284. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3285. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3286. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3287. // $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) :"";
  3288. // echo $rdate;
  3289. if (empty ( $status ))
  3290. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3291. $page_size = 2;
  3292. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3293. $vidList = array ();
  3294. $button = 0;
  3295. Doo::loadModel ( 'verify' );
  3296. $verify = new verify ();
  3297. Doo::loadModel ( 'receipt' );
  3298. $receipt = new receipt ();
  3299. Doo::loadModel ( 'staff' );
  3300. $staff = new staff ();
  3301. Doo::loadModel ( 'L_category' );
  3302. $Lcategory = new L_category ();
  3303. // user verify ID
  3304. $verifyDetail = $verify->find ( array (
  3305. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3306. 'asArray' => true
  3307. ) );
  3308. foreach ( $verifyDetail as $key => $value ) {
  3309. array_push ( $vidList, $value ['vid'] );
  3310. }
  3311. $vid = implode ( ",", $vidList );
  3312. if (empty ( $verifyDetail ))
  3313. $vid = 0;
  3314. // if ($status==0)
  3315. // $dateCondition="";
  3316. // else
  3317. $dateCondition = " ";
  3318. // if (! empty ( $month ))
  3319. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3320. if ($status == 'done' || $status == 'termination') {
  3321. if (! empty ( $year )) {
  3322. $dateCondition = " and Year(pastDate) =" . $year;
  3323. if (! empty ( $month ))
  3324. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3325. }
  3326. } elseif ($status == 'finish') {
  3327. if (! empty ( $year )) {
  3328. $dateCondition = " and Year(pastDate) =" . $year;
  3329. if (! empty ( $month ))
  3330. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3331. }
  3332. }
  3333. // date ( 'Y-m' )
  3334. // if (! empty ( $rdate ) && $status == 'done')
  3335. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3336. // elseif (! empty ( $rdate ))
  3337. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3338. $categoryList = $Lcategory->find ( array (
  3339. 'asArray' => true
  3340. ) );
  3341. $staffList = $staff->find ( array (
  3342. 'where' => 'cid=' . $cid,
  3343. 'asArray' => true
  3344. ) );
  3345. $cateCondition = "";
  3346. $staffCondition = "";
  3347. $approvalCondition = "";
  3348. if (! empty ( $cid )) {
  3349. $cateCondition = ' and cid=' . $cid;
  3350. }
  3351. if (! empty ( $sid )) {
  3352. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3353. $cateCondition = "";
  3354. }
  3355. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3356. if ($status == 'pendApproval') {
  3357. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3358. }
  3359. if ($status == 'ongoing') {
  3360. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3361. }
  3362. if ($status == 'done') {
  3363. $approvalCondition = ' and (status=8 or status=9 ) ';
  3364. }
  3365. if ($status == 'termination') {
  3366. $approvalCondition = " and status=3";
  3367. }
  3368. if ($status == 'finish') {
  3369. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3370. }
  3371. $pageinfo ['page'] = array (
  3372. 'previous' => ''
  3373. );
  3374. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3375. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3376. $receiptList = $receipt->find ( array ( // $dateCondition.
  3377. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3378. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3379. 'desc' => 'rid',
  3380. 'asArray' => true
  3381. ) );
  3382. } else {
  3383. $receiptList = $receipt->find ( array ( // $dateCondition
  3384. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3385. 'desc' => 'rid',
  3386. 'asArray' => true
  3387. ) );
  3388. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3389. }
  3390. $rLRes = $receipt->find ( array (
  3391. '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 . ')',
  3392. 'desc' => 'rid',
  3393. 'asArray' => true
  3394. ) );
  3395. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3396. // print_r($receiptList);
  3397. $Locate = 0;
  3398. $reportList = $reportCateList = array ();
  3399. foreach ( $receiptList as $key => $value ) {
  3400. $receiptList [$key] ['Locate'] = $Locate;
  3401. $Locate ++;
  3402. $receiptList [$key] ['reviseDetail'] = array ();
  3403. if (! empty ( $value ['reviseDetail'] ))
  3404. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3405. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3406. $categoryDetil = $Lcategory->getOne ( array (
  3407. 'where' => 'cid=' . $value ['cid'],
  3408. 'asArray' => true
  3409. ) );
  3410. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3411. $verifyList = $verify->getOne ( array (
  3412. 'where' => 'vid=' . $value ['verify'],
  3413. 'asArray' => true
  3414. ) );
  3415. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3416. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3417. foreach ( $verifyList as $k => $v ) {
  3418. // init verifyStaff
  3419. $verifyList [$k] ['date'] = "";
  3420. $verifyList [$k] ['opinion'] = "";
  3421. $verifyList [$k] ['status'] = "";
  3422. if (empty ( $verifyStaff )) {
  3423. $verifyList [$k] ['date'] = "";
  3424. $verifyList [$k] ['opinion'] = "";
  3425. if ($v [0] == $this->staff [0] ['sid']) {
  3426. $verifyList [$k] ['status'] = 4;
  3427. $button = 4;
  3428. }
  3429. } else {
  3430. $flag = true;
  3431. foreach ( $verifyStaff as $m => $u ) {
  3432. if ($v [0] == $m) {
  3433. $verifyList [$k] ['date'] = $u ['date'];
  3434. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3435. $verifyList [$k] ['status'] = $u ['status'];
  3436. $flag = false;
  3437. break;
  3438. }
  3439. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3440. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3441. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3442. }
  3443. if ($flag) { // 检测可编辑
  3444. if ($v [0] == $this->staff [0] ['sid']) {
  3445. $verifyList [$k] ['status'] = 4;
  3446. $button = 4;
  3447. }
  3448. }
  3449. }
  3450. }
  3451. $receiptList [$key] ['verifyList'] = $verifyList;
  3452. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3453. 'where' => 'sid=' . $value ['staff'],
  3454. 'asArray' => true
  3455. ) );
  3456. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3457. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3458. $receiptList [$key] ['button'] = $button;
  3459. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3460. }
  3461. $reportList = array_unique ( $reportList );
  3462. $reportHtml = '';
  3463. foreach ( $reportList as $key => $value ) {
  3464. $v = explode ( "-", $value );
  3465. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3466. }
  3467. // print_r($reportList)
  3468. $data ['reportHtml'] = $reportHtml;
  3469. $reportCateList = array_unique ( $reportCateList );
  3470. $reportCateHtml = '';
  3471. foreach ( $reportCateList as $key => $value ) {
  3472. $v = explode ( "-", $value );
  3473. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3474. }
  3475. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3476. $data ['reportCateHtml'] = $reportCateHtml;
  3477. // print_r($receiptList);die;
  3478. // $data['verifyDetail']=$verifyDetail;
  3479. $mothHtml = "";
  3480. for($i = 1; $i <= 12; $i ++) {
  3481. if ($month == $i)
  3482. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3483. else
  3484. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3485. }
  3486. $data ['mothHtml'] = $mothHtml;
  3487. $dateHtml = "";
  3488. $now = date ( "Y" );
  3489. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3490. if ($YEARD <= $now) {
  3491. $dateHtml .= '<option ';
  3492. if ($year == $YEARD) {
  3493. $dateHtml .= 'selected ';
  3494. }
  3495. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3496. }
  3497. }
  3498. $data ['dateHtml'] = $dateHtml;
  3499. $data ['page'] = $pageinfo;
  3500. $data ['receiptList'] = $receiptList;
  3501. $data ['receiptApprovalCount'] = count ( $rLRes );
  3502. $data ['status'] = $status;
  3503. $data ['year'] = $year;
  3504. $data ['month'] = $month;
  3505. $data ['categoryList'] = $categoryList;
  3506. $data ['staffList'] = $staffList;
  3507. $data ['cid'] = $cid;
  3508. $data ['sid'] = $sid;
  3509. // print_r($receiptList);
  3510. $data ['memu'] = "receipt";
  3511. $data ['staff'] = $this->staff;
  3512. $data ['receiptMemu'] = 'approvalExpenses';
  3513. $data ['verifyId'] = $this->verifyId;
  3514. $data ['executeId'] = $this->executeId;
  3515. $this->render ( "/admin/approvalExpenses", $data );
  3516. }
  3517. function expensesDoc() {
  3518. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3519. Doo::loadClass ( 'XDeode' );
  3520. $XDeode = new XDeode ( 5 );
  3521. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3522. $rid = $XDeode->decode ( $rid );
  3523. if (! is_numeric ( $rid ))
  3524. die ( 'illegal request' );
  3525. Doo::loadModel ( 'receipt' );
  3526. $receipt = new receipt ();
  3527. Doo::loadModel ( 'L_category' );
  3528. $Lcategory = new L_category ();
  3529. Doo::loadModel ( 'verify' );
  3530. Doo::loadModel ( 'statistics' );
  3531. $statistics = new statistics ();
  3532. $verify = new verify ();
  3533. Doo::loadModel ( 'staff' );
  3534. $staff = new staff ();
  3535. Doo::loadModel ( 'loanReceipt' );
  3536. $loanReceipt = new loanReceipt ();
  3537. $receiptList = $receipt->find ( array (
  3538. 'where' => ' rid=' . $rid,
  3539. 'desc' => 'rid',
  3540. 'asArray' => true
  3541. ) );
  3542. $loanList = array ();
  3543. if (! empty ( $receiptList ))
  3544. $loanList = $loanReceipt->find ( array (
  3545. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3546. 'desc' => 'rid',
  3547. 'asArray' => true
  3548. ) );
  3549. $Locate = 0;
  3550. $roleId = 0;
  3551. $button = 0;
  3552. foreach ( $loanList as $key => $value ) {
  3553. $loanList [$key] ['Locate'] = $Locate;
  3554. $Locate ++;
  3555. $loanList [$key] ['reviseDetail'] = array ();
  3556. if (! empty ( $value ['reviseDetail'] ))
  3557. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3558. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3559. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3560. $categoryDetil = $Lcategory->getOne ( array (
  3561. 'where' => 'cid=' . $value ['cid'],
  3562. 'asArray' => true
  3563. ) );
  3564. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3565. // 检测编辑状态
  3566. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3567. $verifyList ['staff'] = $value ['verifyBreakup'];
  3568. else
  3569. $verifyList = $verify->getOne ( array (
  3570. 'where' => 'vid=' . $value ['verify'],
  3571. 'asArray' => true
  3572. ) );
  3573. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3574. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3575. Doo::loadModel ( 'role' );
  3576. $role = new role ();
  3577. $flag = true;
  3578. $roleKey = 0;
  3579. $endStaffArray = array ();
  3580. $roleArrayCopy = array ();
  3581. foreach ( $verifyList as $k => $v ) {
  3582. // init verifyStaff
  3583. if ($v [1] == 'ROLE') {
  3584. if (! empty ( $verifyStaff )) {
  3585. $endStaffArray = end ( $verifyStaff );
  3586. // if ($v[0]==$endStaffArray['nextStaff']){
  3587. // $roleId=$v[0];
  3588. // }
  3589. }
  3590. $roleVerify = json_decode ( $v [3], true );
  3591. $roleKey = $k;
  3592. $roleArray = array ();
  3593. $rolename = $role->getOne ( array (
  3594. 'where' => 'rid=' . $v [0],
  3595. 'asArray' => true
  3596. ) );
  3597. foreach ( $roleVerify as $o => $p ) {
  3598. $staffID = explode ( '_', $p );
  3599. $staffInfo = $staff->getOne ( array (
  3600. 'where' => 'sid=' . $staffID [0],
  3601. 'asArray' => true
  3602. ) );
  3603. // print_r($staffID);
  3604. $exp = array (
  3605. 0 => $staffInfo ['sid'],
  3606. 1 => $staffID [1],
  3607. 2 => $staffInfo ['avatar'],
  3608. 'date' => '',
  3609. 'date' => '',
  3610. 'opinion' => '',
  3611. 'status' => '',
  3612. 'rolename' => $rolename ['name']
  3613. );
  3614. array_push ( $roleArray, $exp );
  3615. }
  3616. $roleArrayCopy [$v [0]] = $roleArray;
  3617. // $verifyList[$k]['roleArray']=$roleArray;
  3618. }
  3619. $verifyList [$k] ['date'] = "";
  3620. $verifyList [$k] ['opinion'] = "";
  3621. $verifyList [$k] ['status'] = "";
  3622. if (empty ( $verifyStaff )) {
  3623. $verifyList [$k] ['date'] = "";
  3624. $verifyList [$k] ['opinion'] = "";
  3625. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3626. $verifyList [$k] ['status'] = 4;
  3627. $flag = false;
  3628. }
  3629. } else {
  3630. foreach ( $verifyStaff as $m => $u ) {
  3631. if ($v [0] == $m) {
  3632. $verifyList [$k] ['date'] = $u ['date'];
  3633. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3634. $verifyList [$k] ['status'] = $u ['status'];
  3635. $flag = false;
  3636. break;
  3637. }
  3638. }
  3639. $endStaffArray = end ( $verifyStaff );
  3640. if (isset ( $endStaffArray ['ROLE'] )) {
  3641. } else {
  3642. // $endKey=key($verifyStaff);
  3643. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3644. // $button=4;
  3645. // $verifyList[$k]['status']=4;
  3646. // }
  3647. }
  3648. }
  3649. }
  3650. $rolename ['name'] = '';
  3651. if (! empty ( $roleId )) {
  3652. Doo::loadModel ( 'role' );
  3653. $role = new role ();
  3654. $rolename = $role->getOne ( array (
  3655. 'where' => 'rid=' . $roleId,
  3656. 'asArray' => true
  3657. ) );
  3658. }
  3659. if (! empty ( $verifyStaff ))
  3660. $endStaffArray = end ( $verifyStaff );
  3661. $KOP = false;
  3662. foreach ( $roleArrayCopy as $P => $A ) {
  3663. foreach ( $A as $MKI => $AVL ) {
  3664. if (! empty ( $verifyStaff )) {
  3665. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3666. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3667. $button = 4;
  3668. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3669. }
  3670. foreach ( $verifyStaff as $m => $u ) {
  3671. $AVLFK = $AVL [0] . '_R';
  3672. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3673. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3674. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3675. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3676. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3677. break;
  3678. }
  3679. }
  3680. } else {
  3681. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3682. $button = 4;
  3683. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3684. }
  3685. }
  3686. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3687. $KOP = true;
  3688. }
  3689. }
  3690. foreach ( $roleArrayCopy as $k => $v ) {
  3691. foreach ( $verifyList as $m => $n ) {
  3692. if ($n [0] == $k) {
  3693. array_splice ( $verifyList, $m, 1, $v );
  3694. }
  3695. }
  3696. }
  3697. $loanList [$key] ['verifyList'] = $verifyList;
  3698. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3699. 'where' => 'sid=' . $value ['staff'],
  3700. 'asArray' => true
  3701. ) );
  3702. $loanList [$key] ['button'] = $button;
  3703. // $loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3704. }
  3705. $data ['loanList'] = $loanList;
  3706. // print_r($loanList);
  3707. $Locate = 0;
  3708. $roleId = 0;
  3709. $button = 0;
  3710. foreach ( $receiptList as $key => $value ) {
  3711. $receiptList [$key] ['Locate'] = $Locate;
  3712. $Locate ++;
  3713. $receiptList [$key] ['reviseDetail'] = array ();
  3714. if (! empty ( $value ['reviseDetail'] ))
  3715. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3716. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3717. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3718. $categoryDetil = $Lcategory->getOne ( array (
  3719. 'where' => 'cid=' . $value ['cid'],
  3720. 'asArray' => true
  3721. ) );
  3722. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3723. // 检测编辑状态
  3724. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3725. $verifyList ['staff'] = $value ['verifyBreakup'];
  3726. } else
  3727. $verifyList = $verify->getOne ( array (
  3728. 'where' => 'vid=' . $value ['verify'],
  3729. 'asArray' => true
  3730. ) );
  3731. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3732. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3733. Doo::loadModel ( 'role' );
  3734. $role = new role ();
  3735. if ($verifyList == NULL)
  3736. $verifyList = array ();
  3737. $flag = true;
  3738. $roleKey = 0;
  3739. $endStaffArray = array ();
  3740. $roleArrayCopy = array ();
  3741. foreach ( $verifyList as $k => $v ) {
  3742. // init verifyStaff
  3743. if ($v [1] == 'ROLE') {
  3744. if (! empty ( $verifyStaff )) {
  3745. $endStaffArray = end ( $verifyStaff );
  3746. // if ($v[0]==$endStaffArray['nextStaff']){
  3747. // $roleId=$v[0];
  3748. // }
  3749. }
  3750. $roleVerify = json_decode ( $v [3], true );
  3751. $roleKey = $k;
  3752. $roleArray = array ();
  3753. $rolename = $role->getOne ( array (
  3754. 'where' => 'rid=' . $v [0],
  3755. 'asArray' => true
  3756. ) );
  3757. foreach ( $roleVerify as $o => $p ) {
  3758. $staffID = explode ( '_', $p );
  3759. $staffInfo = $staff->getOne ( array (
  3760. 'where' => 'sid=' . $staffID [0],
  3761. 'asArray' => true
  3762. ) );
  3763. // print_r($staffID);
  3764. $exp = array (
  3765. 0 => $staffInfo ['sid'],
  3766. 1 => $staffID [1],
  3767. 2 => $staffInfo ['avatar'],
  3768. 'date' => '',
  3769. 'date' => '',
  3770. 'opinion' => '',
  3771. 'status' => '',
  3772. 'rolename' => $rolename ['name']
  3773. );
  3774. array_push ( $roleArray, $exp );
  3775. }
  3776. $roleArrayCopy [$v [0]] = $roleArray;
  3777. // $verifyList[$k]['roleArray']=$roleArray;
  3778. }
  3779. $verifyList [$k] ['date'] = "";
  3780. $verifyList [$k] ['opinion'] = "";
  3781. $verifyList [$k] ['status'] = "";
  3782. if (empty ( $verifyStaff )) {
  3783. $verifyList [$k] ['date'] = "";
  3784. $verifyList [$k] ['opinion'] = "";
  3785. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3786. $verifyList [$k] ['status'] = 4;
  3787. $flag = false;
  3788. }
  3789. } else {
  3790. foreach ( $verifyStaff as $m => $u ) {
  3791. if ($v [0] == $m) {
  3792. $verifyList [$k] ['date'] = $u ['date'];
  3793. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3794. $verifyList [$k] ['status'] = $u ['status'];
  3795. $flag = false;
  3796. break;
  3797. }
  3798. }
  3799. $endStaffArray = end ( $verifyStaff );
  3800. if (isset ( $endStaffArray ['ROLE'] )) {
  3801. } else {
  3802. // $endKey=key($verifyStaff);
  3803. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3804. // $button=4;
  3805. // $verifyList[$k]['status']=4;
  3806. // }
  3807. }
  3808. }
  3809. }
  3810. $FC = @$rolename ['name'];
  3811. $rolename ['name'] = '';
  3812. if (! empty ( $roleId )) {
  3813. Doo::loadModel ( 'role' );
  3814. $role = new role ();
  3815. $rolename = $role->getOne ( array (
  3816. 'where' => 'rid=' . $roleId,
  3817. 'asArray' => true
  3818. ) );
  3819. }
  3820. if (! empty ( $verifyStaff ))
  3821. $endStaffArray = end ( $verifyStaff );
  3822. $KOP = false;
  3823. foreach ( $roleArrayCopy as $P => $A ) {
  3824. foreach ( $A as $MKI => $AVL ) {
  3825. if (! empty ( $verifyStaff )) {
  3826. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3827. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3828. $button = 4;
  3829. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3830. }
  3831. foreach ( $verifyStaff as $m => $u ) {
  3832. $AVLFK = $AVL [0] . '_R';
  3833. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3834. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3835. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3836. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3837. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3838. break;
  3839. }
  3840. }
  3841. } else {
  3842. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3843. $button = 4;
  3844. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3845. }
  3846. }
  3847. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3848. $KOP = true;
  3849. }
  3850. }
  3851. foreach ( $roleArrayCopy as $k => $v ) {
  3852. foreach ( $verifyList as $m => $n ) {
  3853. if ($n [0] == $k) {
  3854. array_splice ( $verifyList, $m, 1, $v );
  3855. }
  3856. }
  3857. }
  3858. // 费用执行人相关数据
  3859. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3860. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3861. foreach ( $executeCopy as $k => $v ) {
  3862. $executeCopy [$k] ['date'] = '';
  3863. $executeCopy [$k] ['opinion'] = '';
  3864. $executeCopy [$k] ['status'] = '';
  3865. if (! empty ( $executeStaff ))
  3866. foreach ( $executeStaff as $m => $u ) {
  3867. if ($v [0] == $m) {
  3868. $executeCopy [$k] ['date'] = $u ['date'];
  3869. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3870. $executeCopy [$k] ['status'] = $u ['status'];
  3871. break;
  3872. }
  3873. }
  3874. }
  3875. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3876. // print_r($verifyList);
  3877. $receiptList [$key] ['verifyList'] = $verifyList;
  3878. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3879. 'where' => 'sid=' . $value ['staff'],
  3880. 'asArray' => true
  3881. ) );
  3882. $receiptList [$key] ['button'] = $button;
  3883. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3884. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3885. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3886. $receiptList [$key] ['relust'] = $relust;
  3887. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3888. }
  3889. // print_r($receiptList);
  3890. // 获取审批日志
  3891. Doo::loadModel ( 'receiptLog' );
  3892. $receiptLog = new receiptLog ();
  3893. $rlList = array ();
  3894. $rlInfo = $receiptLog->getOne ( array (
  3895. 'where' => 'rid=' . $rid . ' and status=4',
  3896. 'asArray' => true
  3897. ) );
  3898. $tijdate = $receiptLog->getOne ( array (
  3899. 'where' => 'rid=' . $rid . ' and status=2',
  3900. 'asc' => 'rlid',
  3901. 'asArray' => true
  3902. ) );
  3903. if (! empty ( $rlInfo )) {
  3904. $rlList = $receiptLog->find ( array (
  3905. 'where' => 'rid=' . $rid,
  3906. 'asc' => 'rlid',
  3907. 'asArray' => true
  3908. ) );
  3909. }
  3910. $RN = @json_decode ( $rolename ['staff'] );
  3911. //
  3912. foreach ( $rlList as $key => $value ) {
  3913. $rlList [$key] ['rolename'] = '';
  3914. foreach ( $RN as $k => $v ) {
  3915. $id = explode ( "_", $v );
  3916. if ($id [0] == $value ['uid']) {
  3917. $rlList [$key] ['rolename'] = $FC;
  3918. break;
  3919. }
  3920. }
  3921. }
  3922. Doo::loadModel ( 'enclosur' );
  3923. $enclosur = new enclosur ();
  3924. $enclosurList = $enclosur->find ( array (
  3925. 'where' => 'rid=' . $rid,
  3926. 'asArray' => true
  3927. ) );
  3928. $enclosurHtml = '';
  3929. foreach ( $enclosurList as $value ) {
  3930. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3931. }
  3932. $data ['enclosurHtml'] = $enclosurHtml;
  3933. $receiptList [0] ['rlList'] = $rlList;
  3934. $data ['receiptList'] = $receiptList;
  3935. // print_r($receiptList);
  3936. $data ['memu'] = "receipt";
  3937. $data ['staff'] = $this->staff;
  3938. $data ['receiptMemu'] = 'approvalExpenses';
  3939. $data ['verifyId'] = $this->verifyId;
  3940. $data ['executeId'] = $this->executeId;
  3941. $this->render ( "/admin/expensesDoc", $data );
  3942. }
  3943. function expensesEdi() {
  3944. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3945. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  3946. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3947. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3948. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3949. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3950. if (empty ( $status ))
  3951. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  3952. $vidList = array ();
  3953. $button = 0;
  3954. Doo::loadModel ( 'verify' );
  3955. Doo::loadModel ( 'receipt' );
  3956. Doo::loadModel ( 'staff' );
  3957. $staff = new staff ();
  3958. $receipt = new receipt ();
  3959. $verify = new verify ();
  3960. Doo::loadModel ( 'L_category' );
  3961. $Lcategory = new L_category ();
  3962. Doo::loadModel ( 'enclosur' );
  3963. $enclosur = new enclosur ();
  3964. // user verify ID
  3965. $verifyDetail = $verify->find ( array (
  3966. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  3967. 'asArray' => true
  3968. ) );
  3969. foreach ( $verifyDetail as $key => $value ) {
  3970. array_push ( $vidList, $value ['vid'] );
  3971. }
  3972. $vid = implode ( ",", $vidList );
  3973. if (empty ( $verifyDetail ))
  3974. $vid = 0;
  3975. $categoryList = $Lcategory->find ( array (
  3976. 'asArray' => true
  3977. ) );
  3978. $staffList = $staff->find ( array (
  3979. 'where' => 'cid=' . $cid,
  3980. 'asArray' => true
  3981. ) );
  3982. $ap = "";
  3983. if ($status == 4) {
  3984. $ap = 4;
  3985. $status = 2;
  3986. }
  3987. // get Receipt By verifyID status 2
  3988. $receiptList = $receipt->find ( array (
  3989. 'where' => 'rid =' . $rid . ' and status=2',
  3990. 'desc' => 'rid',
  3991. 'asArray' => true
  3992. ) );
  3993. if (empty ( $receiptList )) {
  3994. die ( 'illegal request' );
  3995. }
  3996. $Locate = 0;
  3997. $roleId = 0;
  3998. if ($ap == 4)
  3999. $status = 4;
  4000. foreach ( $receiptList as $key => $value ) {
  4001. $receiptList [$key] ['Locate'] = $Locate;
  4002. $Locate ++;
  4003. $receiptList [$key] ['reviseDetail'] = array ();
  4004. if (! empty ( $value ['reviseDetail'] ))
  4005. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4006. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4007. $categoryDetil = $Lcategory->getOne ( array (
  4008. 'where' => 'cid=' . $value ['cid'],
  4009. 'asArray' => true
  4010. ) );
  4011. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4012. // 检测编辑状态
  4013. $verifyList = $verify->getOne ( array (
  4014. 'where' => 'vid=' . $value ['verify'],
  4015. 'asArray' => true
  4016. ) );
  4017. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4018. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4019. Doo::loadModel ( 'role' );
  4020. $role = new role ();
  4021. // print_r($verifyList);
  4022. $flag = true;
  4023. $roleKey = 0;
  4024. $endStaffArray = array ();
  4025. $roleArrayCopy = array ();
  4026. foreach ( $verifyList as $k => $v ) {
  4027. // init verifyStaff
  4028. if ($v [1] == 'ROLE') {
  4029. if (! empty ( $verifyStaff )) {
  4030. $endStaffArray = end ( $verifyStaff );
  4031. if ($v [0] == $endStaffArray ['nextStaff']) {
  4032. $roleId = $v [0];
  4033. }
  4034. }
  4035. $roleVerify = json_decode ( $v [3], true );
  4036. $roleKey = $k;
  4037. $roleArray = array ();
  4038. $rolename = $role->getOne ( array (
  4039. 'where' => 'rid=' . $v [0],
  4040. 'asArray' => true
  4041. ) );
  4042. foreach ( $roleVerify as $o => $p ) {
  4043. $staffID = explode ( '_', $p );
  4044. $staffInfo = $staff->getOne ( array (
  4045. 'where' => 'sid=' . $staffID [0],
  4046. 'asArray' => true
  4047. ) );
  4048. // print_r($staffID);
  4049. $exp = array (
  4050. 0 => $staffInfo ['sid'],
  4051. 1 => $staffID [1],
  4052. 2 => $staffInfo ['avatar'],
  4053. 'date' => '',
  4054. 'date' => '',
  4055. 'opinion' => '',
  4056. 'status' => '',
  4057. 'rolename' => $rolename ['name']
  4058. );
  4059. array_push ( $roleArray, $exp );
  4060. }
  4061. $roleArrayCopy [$v [0]] = $roleArray;
  4062. // $verifyList[$k]['roleArray']=$roleArray;
  4063. }
  4064. // print_r($roleArray);
  4065. $verifyList [$k] ['date'] = "";
  4066. $verifyList [$k] ['opinion'] = "";
  4067. $verifyList [$k] ['status'] = "";
  4068. if (empty ( $verifyStaff )) {
  4069. $verifyList [$k] ['date'] = "";
  4070. $verifyList [$k] ['opinion'] = "";
  4071. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4072. $verifyList [$k] ['status'] = 4;
  4073. $button = 4;
  4074. $flag = false;
  4075. }
  4076. } else {
  4077. foreach ( $verifyStaff as $m => $u ) {
  4078. if ($v [0] == $m) {
  4079. $verifyList [$k] ['date'] = $u ['date'];
  4080. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4081. $verifyList [$k] ['status'] = $u ['status'];
  4082. $flag = false;
  4083. break;
  4084. }
  4085. }
  4086. $endStaffArray = end ( $verifyStaff );
  4087. if (isset ( $endStaffArray ['ROLE'] )) {
  4088. } else {
  4089. $endKey = key ( $verifyStaff );
  4090. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4091. $button = 4;
  4092. $verifyList [$k] ['status'] = 4;
  4093. }
  4094. }
  4095. }
  4096. }
  4097. $rolename ['name'] = '';
  4098. if (! empty ( $roleId )) {
  4099. Doo::loadModel ( 'role' );
  4100. $role = new role ();
  4101. $rolename = $role->getOne ( array (
  4102. 'where' => 'rid=' . $roleId,
  4103. 'asArray' => true
  4104. ) );
  4105. }
  4106. if (! empty ( $verifyStaff ))
  4107. $endStaffArray = end ( $verifyStaff );
  4108. $KOP = false;
  4109. foreach ( $roleArrayCopy as $P => $A ) {
  4110. foreach ( $A as $MKI => $AVL ) {
  4111. if (! empty ( $verifyStaff )) {
  4112. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4113. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4114. $button = 4;
  4115. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4116. }
  4117. foreach ( $verifyStaff as $m => $u ) {
  4118. $AVLFK = $AVL [0] . '_R';
  4119. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4120. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4121. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4122. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4123. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4124. break;
  4125. }
  4126. }
  4127. } else {
  4128. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4129. $button = 4;
  4130. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4131. }
  4132. }
  4133. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4134. $KOP = true;
  4135. }
  4136. }
  4137. // print_r($roleArrayCopy);
  4138. // echo $roleKey;
  4139. foreach ( $roleArrayCopy as $k => $v ) {
  4140. foreach ( $verifyList as $m => $n ) {
  4141. if ($n [0] == $k) {
  4142. array_splice ( $verifyList, $m, 1, $v );
  4143. }
  4144. }
  4145. }
  4146. $receiptList [$key] ['verifyList'] = $verifyList;
  4147. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4148. 'where' => 'sid=' . $value ['staff'],
  4149. 'asArray' => true
  4150. ) );
  4151. $receiptList [$key] ['button'] = $button;
  4152. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4153. }
  4154. // $data['verifyDetail']=$verifyDetail;
  4155. $mothHtml = "";
  4156. for($i = 1; $i <= 12; $i ++) {
  4157. if ($month == $i)
  4158. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4159. else
  4160. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4161. }
  4162. // 获取审批日志
  4163. Doo::loadModel ( 'receiptLog' );
  4164. $receiptLog = new receiptLog ();
  4165. $rlList = array ();
  4166. $rlInfo = $receiptLog->getOne ( array (
  4167. 'where' => 'rid=' . $rid . ' and status=4',
  4168. 'asArray' => true
  4169. ) );
  4170. $tijdate = $receiptLog->getOne ( array (
  4171. 'where' => 'rid=' . $rid . ' and status=2',
  4172. 'asc' => 'rlid',
  4173. 'asArray' => true
  4174. ) );
  4175. if (! empty ( $rlInfo )) {
  4176. $rlList = $receiptLog->find ( array (
  4177. 'where' => 'rid=' . $rid,
  4178. 'asc' => 'rlid',
  4179. 'asArray' => true
  4180. ) );
  4181. }
  4182. $receiptList [0] ['rlList'] = $rlList;
  4183. $enclosurList = $enclosur->find ( array (
  4184. 'where' => 'rid=' . $rid,
  4185. 'asArray' => true
  4186. ) );
  4187. $enclosurHtml = '';
  4188. foreach ( $enclosurList as $value ) {
  4189. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4190. }
  4191. // print_r($receiptList);
  4192. $data ['rid'] = $rid;
  4193. $data ['enclosurHtml'] = $enclosurHtml;
  4194. $data ['rolename'] = $rolename ['name'];
  4195. $data ['datetij'] = $tijdate ['date'];
  4196. $data ['mothHtml'] = $mothHtml;
  4197. $data ['receiptList'] = $receiptList;
  4198. $data ['receiptApprovalCount'] = count ( $receiptList );
  4199. $data ['status'] = $status;
  4200. $data ['year'] = $year;
  4201. $data ['categoryList'] = $categoryList;
  4202. $data ['staffList'] = $staffList;
  4203. $data ['cid'] = $cid;
  4204. $data ['sid'] = $sid;
  4205. $data ['ap'] = $ap;
  4206. $data ['memu'] = "receipt";
  4207. $data ['staff'] = $this->staff;
  4208. $data ['receiptMemu'] = 'approvalExpenses';
  4209. $data ['verifyId'] = $this->verifyId;
  4210. $data ['executeId'] = $this->executeId;
  4211. $this->render ( "/admin/expensesEdi", $data );
  4212. }
  4213. function expensesDefray() {
  4214. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4215. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4216. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4217. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4218. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4219. if (! empty ( $rid )) {
  4220. Doo::loadModel ( "verify" );
  4221. $verify = new verify ();
  4222. Doo::loadModel ( "receiptDetail" );
  4223. $receiptDetailObj = new receiptDetail ();
  4224. Doo::loadModel ( "itemStatistics" );
  4225. Doo::loadModel ( "statistics" );
  4226. $statistics = new statistics ();
  4227. $itemStatistics = new itemStatistics ();
  4228. Doo::loadModel ( "receipt" );
  4229. $receipt = new receipt ();
  4230. Doo::loadModel ( "loanReceipt" );
  4231. $loanReceipt = new loanReceipt ();
  4232. $receiptDetail = $receipt->getOne ( array (
  4233. 'where' => 'rid=' . $rid . ' and status=2 ',
  4234. 'asArray' => true
  4235. ) );
  4236. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4237. $nsflag = true;
  4238. foreach ( $nslist as $value ) {
  4239. if ($value == $this->staff ['0'] ['sid']) {
  4240. $nsflag = false;
  4241. break;
  4242. }
  4243. }
  4244. // print_r($nslist);die;
  4245. if (empty ( $receiptDetail ) || $nsflag)
  4246. return "/approvalExpenses/pendApproval";
  4247. $verifyDetail = $verify->getOne ( array (
  4248. 'where' => ' vid =' . $receiptDetail ['verify'],
  4249. 'asArray' => true
  4250. ) );
  4251. $verifyString = $verifyDetail ['staff'];
  4252. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4253. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4254. if (empty ( $opinion )) {
  4255. if ($status == 3)
  4256. $opinion = "终止";
  4257. else
  4258. $opinion = "同意支付";
  4259. }
  4260. $nowStaff = 0;
  4261. $nowStaffList = array ();
  4262. if (empty ( $verifyStaff )) {
  4263. // 还需加入是否已经进入角色审批
  4264. if ($verifyDetail [0] [1] == 'ROLE') {
  4265. // print_r($verifyDetail);echo "ddd";
  4266. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4267. foreach ( $vStaffString as $key => $value ) {
  4268. $staffK = explode ( "_", $value );
  4269. if ($staffK [0] != $this->staff [0] ['sid'])
  4270. array_push ( $nowStaffList, $staffK [0] );
  4271. }
  4272. // print_r($verifyDetail);
  4273. // die;
  4274. if (! empty ( $nowStaffList )) {
  4275. $nowStaff = implode ( ',', $nowStaffList );
  4276. $verifyStaff = array (
  4277. $this->staff [0] ['sid'] . "_R" => array (
  4278. 'date' => date ( 'Y-m-d' ),
  4279. 'opinion' => $opinion,
  4280. 'status' => $status,
  4281. 'nextStaff' => $verifyDetail [0] [0],
  4282. 'ROLE' => 1
  4283. )
  4284. );
  4285. } else {
  4286. $nowStaff = $verifyDetail [1] [0];
  4287. $verifyStaff = array (
  4288. $this->staff [0] ['sid'] . "_R" => array (
  4289. 'date' => date ( 'Y-m-d' ),
  4290. 'opinion' => $opinion,
  4291. 'status' => $status,
  4292. 'nextStaff' => $verifyDetail [1] [0]
  4293. )
  4294. );
  4295. }
  4296. } else {
  4297. if ($verifyDetail [1] [1] == 'ROLE') {
  4298. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4299. // echo "dd";
  4300. foreach ( $vStaffString as $key => $value ) {
  4301. $staffK = explode ( "_", $value );
  4302. array_push ( $nowStaffList, $staffK [0] );
  4303. }
  4304. $nowStaff = implode ( ',', $nowStaffList );
  4305. $verifyStaff = array (
  4306. $this->staff [0] ['sid'] => array (
  4307. 'date' => date ( 'Y-m-d' ),
  4308. 'opinion' => $opinion,
  4309. 'status' => $status,
  4310. 'nextStaff' => $verifyDetail [1] [0],
  4311. 'ROLE' => 1
  4312. )
  4313. );
  4314. } else {
  4315. $nowStaff = $verifyDetail [1] [0];
  4316. $verifyStaff = array (
  4317. $this->staff [0] ['sid'] => array (
  4318. 'date' => date ( 'Y-m-d' ),
  4319. 'opinion' => $opinion,
  4320. 'status' => $status,
  4321. 'nextStaff' => $verifyDetail [1] [0]
  4322. )
  4323. );
  4324. }
  4325. }
  4326. if ($status == 3)
  4327. $verifyStaff = array (
  4328. 'final' => $status,
  4329. $this->staff [0] ['sid'] => array (
  4330. 'date' => date ( 'Y-m-d' ),
  4331. 'opinion' => $opinion,
  4332. 'status' => $status
  4333. )
  4334. );
  4335. $vStaffString = json_encode ( $verifyStaff );
  4336. $receipt->nowStaff = $nowStaff;
  4337. $receipt->verifyStaff = $vStaffString;
  4338. $loanReceipt->nowStaff = $nowStaff;
  4339. $loanReceipt->verifyStaff = $vStaffString;
  4340. } else {
  4341. $VS = end ( $verifyStaff );
  4342. // 非角色审批
  4343. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4344. $nextStaff = 0;
  4345. $roleSTF = false;
  4346. foreach ( $verifyDetail as $key => $value ) {
  4347. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4348. if (isset ( $verifyDetail [$key + 1] )) {
  4349. $nextStaff = $verifyDetail [$key + 1] [0];
  4350. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4351. $roleSTF = true;
  4352. }
  4353. break;
  4354. }
  4355. }
  4356. if (! $roleSTF) {
  4357. $nowStaff = $nextStaff;
  4358. $verifyStaff [$this->staff [0] ['sid']] = array (
  4359. 'date' => date ( 'Y-m-d' ),
  4360. 'opinion' => $opinion,
  4361. 'status' => $status,
  4362. 'nextStaff' => $nextStaff
  4363. );
  4364. } else {
  4365. // 获取角色下的所有用户ID
  4366. $nowStaffList = array ();
  4367. foreach ( $verifyDetail as $vfk ) {
  4368. if ($vfk [1] == 'ROLE') {
  4369. $vStaffString = json_decode ( $vfk [3] );
  4370. foreach ( $vStaffString as $key => $value ) {
  4371. $staffK = explode ( "_", $value );
  4372. array_push ( $nowStaffList, $staffK [0] );
  4373. }
  4374. }
  4375. }
  4376. $nowStaff = implode ( ',', $nowStaffList );
  4377. $verifyStaff [$this->staff [0] ['sid']] = array (
  4378. 'date' => date ( 'Y-m-d' ),
  4379. 'opinion' => $opinion,
  4380. 'status' => $status,
  4381. 'nextStaff' => $nextStaff,
  4382. 'ROLE' => 0
  4383. );
  4384. }
  4385. if ($status == 3) {
  4386. $verifyStaff ['final'] = $status;
  4387. $verifyStaff [$this->staff [0] ['sid']] = array (
  4388. 'date' => date ( 'Y-m-d' ),
  4389. 'opinion' => $opinion,
  4390. 'status' => $status
  4391. );
  4392. }
  4393. $vStaffString = json_encode ( $verifyStaff );
  4394. $receipt->nowStaff = $nowStaff;
  4395. $receipt->verifyStaff = $vStaffString;
  4396. $loanReceipt->nowStaff = $nowStaff;
  4397. $loanReceipt->verifyStaff = $vStaffString;
  4398. }
  4399. // 角色审批
  4400. if (isset ( $VS ['ROLE'] )) {
  4401. // 找出角色人 当前审批角色组
  4402. $verifyJSStaff = array ();
  4403. $nowStaffList2 = array ();
  4404. foreach ( $verifyDetail as $key => $value ) {
  4405. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4406. $verifyJSStaff = json_decode ( $value [3] );
  4407. foreach ( $verifyJSStaff as $m ) {
  4408. $staffK = explode ( "_", $m );
  4409. array_push ( $nowStaffList2, $staffK [0] );
  4410. }
  4411. // print_r($nowStaffList2);
  4412. }
  4413. }
  4414. $RoleVerifyStaff = array ();
  4415. foreach ( $verifyStaff as $key => $value ) {
  4416. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4417. foreach ( $nowStaffList2 as $m ) {
  4418. if ($key == $m . "_R")
  4419. $RoleVerifyStaff [$key] = $value;
  4420. }
  4421. }
  4422. }
  4423. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4424. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4425. // 下一个审批人ID
  4426. $nextStaff = 0;
  4427. $falg = false;
  4428. foreach ( $verifyDetail as $key => $value ) {
  4429. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4430. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4431. $falg = true;
  4432. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4433. $nowStaffList = array ();
  4434. foreach ( $vStaffString as $v ) {
  4435. $staffK = explode ( "_", $v );
  4436. array_push ( $nowStaffList, $staffK [0] );
  4437. }
  4438. $nowStaff = implode ( ',', $nowStaffList );
  4439. $nextStaff = $verifyDetail [$key + 1] [0];
  4440. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4441. $nextStaff = $verifyDetail [$key + 1] [0];
  4442. $nowStaff = $nextStaff;
  4443. } else
  4444. $nowStaff = '';
  4445. break;
  4446. }
  4447. }
  4448. if ($falg)
  4449. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4450. 'date' => date ( 'Y-m-d' ),
  4451. 'opinion' => $opinion,
  4452. 'status' => $status,
  4453. 'nextStaff' => $nextStaff,
  4454. 'ROLE' => 1
  4455. );
  4456. else
  4457. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4458. 'date' => date ( 'Y-m-d' ),
  4459. 'opinion' => $opinion,
  4460. 'status' => $status,
  4461. 'nextStaff' => $nextStaff
  4462. );
  4463. // print_r($verifyStaff);
  4464. // echo $nowStaff;die;
  4465. } else { // 进入下一个角色或者审批人
  4466. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  4467. //
  4468. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4469. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4470. 'date' => date ( 'Y-m-d' ),
  4471. 'opinion' => $opinion,
  4472. 'status' => $status,
  4473. 'nextStaff' => $VS ['nextStaff'],
  4474. 'ROLE' => 1
  4475. );
  4476. // print_r($verifyStaff);
  4477. // die;
  4478. }
  4479. if ($status == 3) {
  4480. $verifyStaff ['final'] = $status;
  4481. $verifyStaff [$this->staff [0] ['sid']] = array (
  4482. 'date' => date ( 'Y-m-d' ),
  4483. 'opinion' => $opinion,
  4484. 'status' => $status
  4485. );
  4486. }
  4487. $vStaffString = json_encode ( $verifyStaff );
  4488. $receipt->verifyStaff = $vStaffString;
  4489. $receipt->nowStaff = $nowStaff;
  4490. $loanReceipt->nowStaff = $nowStaff;
  4491. $loanReceipt->verifyStaff = $vStaffString;
  4492. // die;
  4493. // }
  4494. // print_r($verifyStaff);
  4495. // die;
  4496. }
  4497. // print_r($verifyStaff);die;
  4498. }
  4499. // print_r($verifyDetail);
  4500. $roleKey = 0;
  4501. $roleId = 0;
  4502. $verifyDetailCopy = array ();
  4503. foreach ( $verifyDetail as $k => $v ) {
  4504. if ($v [1] == 'ROLE') {
  4505. $roleId = $v [0];
  4506. $roleVerify = json_decode ( $v [3], true );
  4507. $roleKey = $k;
  4508. $roleArray = array ();
  4509. foreach ( $roleVerify as $o => $p ) {
  4510. $staffID = explode ( '_', $p );
  4511. $exp = array (
  4512. 0 => $staffID [0],
  4513. 1 => $staffID [1]
  4514. );
  4515. array_push ( $roleArray, $exp );
  4516. }
  4517. $verifyDetailCopy [$v [0]] = $roleArray;
  4518. }
  4519. }
  4520. // print_r($verifyDetail);
  4521. foreach ( $verifyDetailCopy as $k => $v ) {
  4522. foreach ( $verifyDetail as $m => $n ) {
  4523. if ($n [0] == $k) {
  4524. array_splice ( $verifyDetail, $m, 1, $v );
  4525. }
  4526. }
  4527. }
  4528. // 审批日志
  4529. if (! isset ( $verifyStaff ['final'] )) {
  4530. Doo::loadModel ( "receiptLog" );
  4531. $receiptLog = new receiptLog ();
  4532. if (! empty ( $roleId )) {
  4533. Doo::loadModel ( "role" );
  4534. $role = new role ();
  4535. $roleInfo = $role->getOne ( array (
  4536. 'where' => 'rid=' . $roleId,
  4537. 'asArray' => true
  4538. ) );
  4539. $receiptLog->rolename = $roleInfo ['name'];
  4540. }
  4541. $receiptLog->username = $this->staff [0] ['username'];
  4542. $receiptLog->uid = $this->staff [0] ['sid'];
  4543. $receiptLog->date = date ( "Y-m-d" );
  4544. $receiptLog->opinion = $opinion;
  4545. $receiptLog->img = $this->staff [0] ['avatar'];
  4546. $receiptLog->status = 1;
  4547. $receiptLog->rid = $rid;
  4548. $receiptLog->insert ();
  4549. }
  4550. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4551. $receipt->status = 3;
  4552. $receipt->verifyBreakup = $verifyString;
  4553. $receiptDetailObj->status = 3;
  4554. $receiptDetailObj->update ( array (
  4555. 'where' => 'rid=' . $rid
  4556. ) );
  4557. // 微信企业号通知
  4558. $this->setWXMsg ( $rid, 3 );
  4559. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4560. $receipt->status = 6;
  4561. $receipt->pastDate = date ( "Y-m-d" );
  4562. $receipt->isBK = 1;
  4563. $loanReceipt->verifyBreakup = $verifyString;
  4564. $loanReceipt->status = 1;
  4565. $loanReceipt->pastDate = date ( "Y-m-d" );
  4566. $loanReceipt->amount = $receiptDetail ['amount'];
  4567. $loanReceipt->update ( array (
  4568. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4569. ) );
  4570. // 微信企业号通知
  4571. $this->setWXMsg ( $rid, 1 );
  4572. }
  4573. $receipt->amount = $amount;
  4574. $receipt->update ( array (
  4575. 'where' => ' rid = ' . $rid
  4576. ) );
  4577. // 进入下一条审批费用新加需求
  4578. $vidList = array ();
  4579. $verifyDetail = $verify->find ( array (
  4580. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4581. 'asArray' => true
  4582. ) );
  4583. foreach ( $verifyDetail as $key => $value ) {
  4584. array_push ( $vidList, $value ['vid'] );
  4585. }
  4586. $vid = implode ( ",", $vidList );
  4587. if (empty ( $verifyDetail ))
  4588. $vid = 0;
  4589. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4590. $receipt = new receipt ();
  4591. $rd = $receipt->getOne ( array (
  4592. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4593. 'asc' => 'rid',
  4594. 'asArray' => true
  4595. ) );
  4596. if (empty ( $rd )) {
  4597. return '/approvalExpenses/pendApproval';
  4598. }
  4599. if ($rd ['Rtype'] == 1) {
  4600. if ($rd ['isBK'] == 1) {
  4601. return '/receiptburEdi/' . $rd ['rid'];
  4602. } else {
  4603. return '/expensesEdi/' . $rd ['rid'];
  4604. }
  4605. } elseif ($rd ['Rtype'] == 2) {
  4606. return '/remitApproval/' . $rd ['rid'];
  4607. } else {
  4608. return '/receiptburEdi/' . $rd ['rid'];
  4609. }
  4610. // return "/approvalExpenses/pendApproval";
  4611. }
  4612. }
  4613. function ajaxExamineExe() {
  4614. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4615. Doo::loadModel ( 'receipt' );
  4616. $receipt = new receipt ();
  4617. Doo::loadClass ( 'XDeode' );
  4618. $XDeode = new XDeode ( 5 );
  4619. if (! empty ( $rid )) {
  4620. $rLRes = $receipt->find ( array (
  4621. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4622. 'asArray' => true
  4623. ) );
  4624. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4625. echo json_encode ( array (
  4626. 'status' => 1,
  4627. 'receipt' => $rLRes [0]
  4628. ) );
  4629. die ();
  4630. }
  4631. echo json_encode ( array (
  4632. 'status' => 0,
  4633. 'receipt' => array ()
  4634. ) );
  4635. die ();
  4636. }
  4637. function implement() {
  4638. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4639. Doo::loadClass ( 'XDeode' );
  4640. $XDeode = new XDeode ( 5 );
  4641. Doo::loadModel ( 'receipt' );
  4642. $receipt = new receipt ();
  4643. Doo::loadModel ( 'L_category' );
  4644. $Lcategory = new L_category ();
  4645. Doo::loadModel ( 'verify' );
  4646. $verify = new verify ();
  4647. Doo::loadModel ( 'staff' );
  4648. $staff = new staff ();
  4649. Doo::loadModel ( "execute" );
  4650. $execute = new execute ();
  4651. $rid = $XDeode->decode ( $rid );
  4652. $receiptList = $receipt->find ( array (
  4653. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4654. 'desc' => 'rid',
  4655. 'asArray' => true
  4656. ) );
  4657. Doo::loadModel ( 'loanReceipt' );
  4658. $loanReceipt = new loanReceipt ();
  4659. // print_r($receiptList);
  4660. $loanList = array ();
  4661. if (! isset ( $receiptList ))
  4662. $loanList = $loanReceipt->find ( array (
  4663. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4664. 'desc' => 'rid',
  4665. 'asArray' => true
  4666. ) );
  4667. $Locate = 0;
  4668. $roleId = 0;
  4669. $button = 0;
  4670. foreach ( $loanList as $key => $value ) {
  4671. $loanList [$key] ['Locate'] = $Locate;
  4672. $Locate ++;
  4673. $loanList [$key] ['reviseDetail'] = array ();
  4674. if (! empty ( $value ['reviseDetail'] ))
  4675. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4676. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4677. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4678. $categoryDetil = $Lcategory->getOne ( array (
  4679. 'where' => 'cid=' . $value ['cid'],
  4680. 'asArray' => true
  4681. ) );
  4682. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4683. // 检测编辑状态
  4684. $verifyList = $verify->getOne ( array (
  4685. 'where' => 'vid=' . $value ['verify'],
  4686. 'asArray' => true
  4687. ) );
  4688. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4689. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4690. Doo::loadModel ( 'role' );
  4691. $role = new role ();
  4692. $flag = true;
  4693. $roleKey = 0;
  4694. $endStaffArray = array ();
  4695. $roleArrayCopy = array ();
  4696. foreach ( $verifyList as $k => $v ) {
  4697. // init verifyStaff
  4698. if ($v [1] == 'ROLE') {
  4699. if (! empty ( $verifyStaff )) {
  4700. $endStaffArray = end ( $verifyStaff );
  4701. // if ($v[0]==$endStaffArray['nextStaff']){
  4702. // $roleId=$v[0];
  4703. // }
  4704. }
  4705. $roleVerify = json_decode ( $v [3], true );
  4706. $roleKey = $k;
  4707. $roleArray = array ();
  4708. $rolename = $role->getOne ( array (
  4709. 'where' => 'rid=' . $v [0],
  4710. 'asArray' => true
  4711. ) );
  4712. foreach ( $roleVerify as $o => $p ) {
  4713. $staffID = explode ( '_', $p );
  4714. $staffInfo = $staff->getOne ( array (
  4715. 'where' => 'sid=' . $staffID [0],
  4716. 'asArray' => true
  4717. ) );
  4718. // print_r($staffID);
  4719. $exp = array (
  4720. 0 => $staffInfo ['sid'],
  4721. 1 => $staffID [1],
  4722. 2 => $staffInfo ['avatar'],
  4723. 'date' => '',
  4724. 'date' => '',
  4725. 'opinion' => '',
  4726. 'status' => '',
  4727. 'rolename' => $rolename ['name']
  4728. );
  4729. array_push ( $roleArray, $exp );
  4730. }
  4731. $roleArrayCopy [$v [0]] = $roleArray;
  4732. // $verifyList[$k]['roleArray']=$roleArray;
  4733. }
  4734. $verifyList [$k] ['date'] = "";
  4735. $verifyList [$k] ['opinion'] = "";
  4736. $verifyList [$k] ['status'] = "";
  4737. if (empty ( $verifyStaff )) {
  4738. $verifyList [$k] ['date'] = "";
  4739. $verifyList [$k] ['opinion'] = "";
  4740. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4741. $verifyList [$k] ['status'] = 4;
  4742. $flag = false;
  4743. }
  4744. } else {
  4745. foreach ( $verifyStaff as $m => $u ) {
  4746. if ($v [0] == $m) {
  4747. $verifyList [$k] ['date'] = $u ['date'];
  4748. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4749. $verifyList [$k] ['status'] = $u ['status'];
  4750. $flag = false;
  4751. break;
  4752. }
  4753. }
  4754. $endStaffArray = end ( $verifyStaff );
  4755. if (isset ( $endStaffArray ['ROLE'] )) {
  4756. } else {
  4757. // $endKey=key($verifyStaff);
  4758. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4759. // $button=4;
  4760. // $verifyList[$k]['status']=4;
  4761. // }
  4762. }
  4763. }
  4764. }
  4765. $rolename ['name'] = '';
  4766. if (! empty ( $roleId )) {
  4767. Doo::loadModel ( 'role' );
  4768. $role = new role ();
  4769. $rolename = $role->getOne ( array (
  4770. 'where' => 'rid=' . $roleId,
  4771. 'asArray' => true
  4772. ) );
  4773. }
  4774. if (! empty ( $verifyStaff ))
  4775. $endStaffArray = end ( $verifyStaff );
  4776. $KOP = false;
  4777. foreach ( $roleArrayCopy as $P => $A ) {
  4778. foreach ( $A as $MKI => $AVL ) {
  4779. if (! empty ( $verifyStaff )) {
  4780. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4781. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4782. $button = 4;
  4783. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4784. }
  4785. foreach ( $verifyStaff as $m => $u ) {
  4786. $AVLFK = $AVL [0] . '_R';
  4787. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4788. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4789. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4790. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4791. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4792. break;
  4793. }
  4794. }
  4795. } else {
  4796. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4797. $button = 4;
  4798. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4799. }
  4800. }
  4801. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4802. $KOP = true;
  4803. }
  4804. }
  4805. foreach ( $roleArrayCopy as $k => $v ) {
  4806. foreach ( $verifyList as $m => $n ) {
  4807. if ($n [0] == $k) {
  4808. array_splice ( $verifyList, $m, 1, $v );
  4809. }
  4810. }
  4811. }
  4812. $loanList [$key] ['verifyList'] = $verifyList;
  4813. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4814. 'where' => 'sid=' . $value ['staff'],
  4815. 'asArray' => true
  4816. ) );
  4817. }
  4818. $data ['loanList'] = $loanList;
  4819. $Locate = 0;
  4820. $roleId = 0;
  4821. $button = 0;
  4822. foreach ( $receiptList as $key => $value ) {
  4823. $button2 = 0;
  4824. $receiptList [$key] ['Locate'] = $Locate;
  4825. $Locate ++;
  4826. $receiptList [$key] ['reviseDetail'] = array ();
  4827. if (! empty ( $value ['reviseDetail'] ))
  4828. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4829. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4830. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4831. $categoryDetil = $Lcategory->getOne ( array (
  4832. 'where' => 'cid=' . $value ['cid'],
  4833. 'asArray' => true
  4834. ) );
  4835. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4836. $executeList = json_decode ( $value ['executeCopy'], true );
  4837. $executeStaff = array ();
  4838. if (! empty ( $value ['executeStaff'] ))
  4839. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4840. if (isset ( $executeList )) {
  4841. foreach ( $executeList as $op => $lo ) {
  4842. $executeList [$op] ['date'] = "";
  4843. $executeList [$op] ['opinion'] = "";
  4844. $executeList [$op] ['status'] = "";
  4845. foreach ( $executeStaff as $m => $u ) {
  4846. if ($lo [0] == $m) {
  4847. $executeList [$op] ['date'] = $u ['date'];
  4848. $executeList [$op] ['opinion'] = $u ['opinion'];
  4849. $executeList [$op] ['status'] = $u ['status'];
  4850. break;
  4851. }
  4852. }
  4853. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  4854. $button2 = 1;
  4855. $executeList [$op] ['status'] = 4;
  4856. }
  4857. }
  4858. }
  4859. // 检测编辑状态
  4860. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4861. $verifyList ['staff'] = $value ['verifyBreakup'];
  4862. } else
  4863. $verifyList = $verify->getOne ( array (
  4864. 'where' => 'vid=' . $value ['verify'],
  4865. 'asArray' => true
  4866. ) );
  4867. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4868. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4869. Doo::loadModel ( 'role' );
  4870. $role = new role ();
  4871. if ($verifyList == NULL)
  4872. $verifyList = array ();
  4873. $flag = true;
  4874. $roleKey = 0;
  4875. $endStaffArray = array ();
  4876. $roleArrayCopy = array ();
  4877. foreach ( $verifyList as $k => $v ) {
  4878. // init verifyStaff
  4879. if ($v [1] == 'ROLE') {
  4880. if (! empty ( $verifyStaff )) {
  4881. $endStaffArray = end ( $verifyStaff );
  4882. // if ($v[0]==$endStaffArray['nextStaff']){
  4883. // $roleId=$v[0];
  4884. // }
  4885. }
  4886. $roleVerify = json_decode ( $v [3], true );
  4887. $roleKey = $k;
  4888. $roleArray = array ();
  4889. $rolename = $role->getOne ( array (
  4890. 'where' => 'rid=' . $v [0],
  4891. 'asArray' => true
  4892. ) );
  4893. foreach ( $roleVerify as $o => $p ) {
  4894. $staffID = explode ( '_', $p );
  4895. $staffInfo = $staff->getOne ( array (
  4896. 'where' => 'sid=' . $staffID [0],
  4897. 'asArray' => true
  4898. ) );
  4899. // print_r($staffID);
  4900. $exp = array (
  4901. 0 => $staffInfo ['sid'],
  4902. 1 => $staffID [1],
  4903. 2 => $staffInfo ['avatar'],
  4904. 'date' => '',
  4905. 'date' => '',
  4906. 'opinion' => '',
  4907. 'status' => '',
  4908. 'rolename' => $rolename ['name']
  4909. );
  4910. array_push ( $roleArray, $exp );
  4911. }
  4912. $roleArrayCopy [$v [0]] = $roleArray;
  4913. // $verifyList[$k]['roleArray']=$roleArray;
  4914. }
  4915. $verifyList [$k] ['date'] = "";
  4916. $verifyList [$k] ['opinion'] = "";
  4917. $verifyList [$k] ['status'] = "";
  4918. if (empty ( $verifyStaff )) {
  4919. $verifyList [$k] ['date'] = "";
  4920. $verifyList [$k] ['opinion'] = "";
  4921. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4922. $verifyList [$k] ['status'] = 4;
  4923. $flag = false;
  4924. }
  4925. } else {
  4926. foreach ( $verifyStaff as $m => $u ) {
  4927. if ($v [0] == $m) {
  4928. $verifyList [$k] ['date'] = $u ['date'];
  4929. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4930. $verifyList [$k] ['status'] = $u ['status'];
  4931. $flag = false;
  4932. break;
  4933. }
  4934. }
  4935. $endStaffArray = end ( $verifyStaff );
  4936. if (isset ( $endStaffArray ['ROLE'] )) {
  4937. } else {
  4938. // $endKey=key($verifyStaff);
  4939. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4940. // $button=4;
  4941. // $verifyList[$k]['status']=4;
  4942. // }
  4943. }
  4944. }
  4945. }
  4946. $rolename ['name'] = '';
  4947. if (! empty ( $roleId )) {
  4948. Doo::loadModel ( 'role' );
  4949. $role = new role ();
  4950. $rolename = $role->getOne ( array (
  4951. 'where' => 'rid=' . $roleId,
  4952. 'asArray' => true
  4953. ) );
  4954. }
  4955. if (! empty ( $verifyStaff ))
  4956. $endStaffArray = end ( $verifyStaff );
  4957. $KOP = false;
  4958. foreach ( $roleArrayCopy as $P => $A ) {
  4959. foreach ( $A as $MKI => $AVL ) {
  4960. if (! empty ( $verifyStaff )) {
  4961. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4962. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4963. $button = 4;
  4964. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4965. }
  4966. foreach ( $verifyStaff as $m => $u ) {
  4967. $AVLFK = $AVL [0] . '_R';
  4968. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4969. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4970. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4971. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4972. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4973. break;
  4974. }
  4975. }
  4976. } else {
  4977. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4978. $button = 4;
  4979. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4980. }
  4981. }
  4982. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4983. $KOP = true;
  4984. }
  4985. }
  4986. foreach ( $roleArrayCopy as $k => $v ) {
  4987. foreach ( $verifyList as $m => $n ) {
  4988. if ($n [0] == $k) {
  4989. array_splice ( $verifyList, $m, 1, $v );
  4990. }
  4991. }
  4992. }
  4993. $receiptList [$key] ['verifyList'] = $verifyList;
  4994. $receiptList [$key] ['executeList'] = $executeList;
  4995. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4996. 'where' => 'sid=' . $value ['staff'],
  4997. 'asArray' => true
  4998. ) );
  4999. $receiptList [$key] ['button2'] = $button2;
  5000. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5001. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5002. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5003. $receiptList [$key] ['relust'] = $relust;
  5004. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5005. }
  5006. // print_r($receiptList[$key]['executeList']);
  5007. $data ['receiptList'] = $receiptList;
  5008. $data ['memu'] = "receipt";
  5009. $data ['staff'] = $this->staff;
  5010. $data ['receiptMemu'] = 'implement';
  5011. $data ['verifyId'] = $this->verifyId;
  5012. $data ['executeId'] = $this->executeId;
  5013. $this->render ( "/admin/implement", $data );
  5014. }
  5015. function implementDo() {
  5016. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5017. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5018. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5019. $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5020. $ab = '';
  5021. if ($accountBank == 'CGBDeposit')
  5022. $ab = '纵横广发';
  5023. elseif ($accountBank == 'ICBCDeposit')
  5024. $ab = '纵横工行';
  5025. elseif ($accountBank == 'HUADeposit')
  5026. $ab = '华润银行';
  5027. elseif ($accountBank == 'PersonalDeposit')
  5028. $ab = '个人广发';
  5029. if (empty ( $ab ))
  5030. die ( 'illegal request' );
  5031. if (! empty ( $rid ) && $amount != '') {
  5032. Doo::loadModel ( 'receipt' );
  5033. $receipt = new receipt ();
  5034. Doo::loadClass ( 'XDeode' );
  5035. $XDeode = new XDeode ( 5 );
  5036. // $rinfo = $receipt->getOne ( array (
  5037. // 'where' => 'rid=' . $rid,
  5038. // 'asArray' => true
  5039. // ) );
  5040. $rinfo = $receipt->getReceiptByRid ( $rid );
  5041. $accountType = '';
  5042. if ($rinfo ['Rtype'] == 1) {
  5043. if ($rinfo ['loanRid'] != 0)
  5044. $accountType = 2;
  5045. else
  5046. $accountType = 1;
  5047. } elseif ($rinfo ['Rtype'] == 2) {
  5048. $accountType = 4;
  5049. } elseif ($rinfo ['Rtype'] == 0)
  5050. $accountType = 3;
  5051. if (empty ( $accountType ))
  5052. die ( 'illegal request' );
  5053. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5054. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5055. if (empty ( $executeStaff )) {
  5056. $executeStaff = array (
  5057. $this->staff [0] ['sid'] => array (
  5058. 'date' => date ( 'Y-m-d' ),
  5059. 'opinion' => $implementOpinions,
  5060. 'status' => 1
  5061. )
  5062. );
  5063. } else {
  5064. $executeStaff [$this->staff [0] ['sid']] = array (
  5065. 'date' => date ( 'Y-m-d' ),
  5066. 'opinion' => $implementOpinions,
  5067. 'status' => 1
  5068. );
  5069. }
  5070. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5071. $receipt->executeStaff = json_encode ( $executeStaff );
  5072. $receipt->status = 8;
  5073. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5074. $receipt->status = 9;
  5075. if ($rinfo ['status'] == 6) {
  5076. $receipt->loanDate = date ( "Y-m-d" );
  5077. }
  5078. $receipt->executeDate = date ( "Y-m-d" );
  5079. } else {
  5080. $receipt->executeStaff = json_encode ( $executeStaff );
  5081. }
  5082. $receipt->amount = $amount;
  5083. $receipt->update ( array (
  5084. 'where' => 'rid=' . $rid
  5085. ) );
  5086. // 公司流水记录
  5087. Doo::loadModel ( 'wasteBook' );
  5088. $wasteBook = new wasteBook ();
  5089. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5090. // 银行
  5091. if (empty ( $abDetail ) && ! empty ( $amount )) {
  5092. $item = array (
  5093. 'dataID' => $rid,
  5094. 'expensesType' => 2,
  5095. 'accountType' => $accountType,
  5096. 'accountPriceShow' => $amount,
  5097. 'accountPrice' => - $amount,
  5098. 'accountBank' => $accountBank,
  5099. 'category' => $rinfo ['category'] [0] ['title'],
  5100. 'cid' => $rinfo ['category'] [0] ['cid'],
  5101. 'name' => $rinfo ['staffDetail'] ['username'],
  5102. 'sid' => $rinfo ['staffDetail'] ['sid'],
  5103. 'inputDate' => date ( "Y-m-d H:i:s" )
  5104. );
  5105. $wasteBook->setAccountBookStatistics ( $item );
  5106. }
  5107. }
  5108. $ridKey = $XDeode->encode ( $rid );
  5109. return "/hisImplement";
  5110. // return "/implement/" . $ridKey . ".html";
  5111. }
  5112. function receiptburEdi() {
  5113. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5114. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5115. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5116. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5117. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5118. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5119. if (empty ( $status ))
  5120. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5121. $vidList = array ();
  5122. $button = 0;
  5123. Doo::loadModel ( 'verify' );
  5124. Doo::loadModel ( 'receipt' );
  5125. Doo::loadModel ( 'staff' );
  5126. $staff = new staff ();
  5127. $receipt = new receipt ();
  5128. $verify = new verify ();
  5129. Doo::loadModel ( 'L_category' );
  5130. $Lcategory = new L_category ();
  5131. Doo::loadModel ( 'enclosur' );
  5132. $enclosur = new enclosur ();
  5133. Doo::loadModel ( 'loanReceipt' );
  5134. $loanReceipt = new loanReceipt ();
  5135. // user verify ID
  5136. $verifyDetail = $verify->find ( array (
  5137. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5138. 'asArray' => true
  5139. ) );
  5140. foreach ( $verifyDetail as $key => $value ) {
  5141. array_push ( $vidList, $value ['vid'] );
  5142. }
  5143. $vid = implode ( ",", $vidList );
  5144. if (empty ( $verifyDetail ))
  5145. $vid = 0;
  5146. $categoryList = $Lcategory->find ( array (
  5147. 'asArray' => true
  5148. ) );
  5149. $staffList = $staff->find ( array (
  5150. 'where' => 'cid=' . $cid,
  5151. 'asArray' => true
  5152. ) );
  5153. $ap = "";
  5154. if ($status == 4) {
  5155. $ap = 4;
  5156. $status = 2;
  5157. }
  5158. // get Receipt By verifyID status 2
  5159. $receiptList = $receipt->find ( array (
  5160. 'where' => 'rid =' . $rid . ' and status=2',
  5161. 'desc' => 'rid',
  5162. 'asArray' => true
  5163. ) );
  5164. if (empty ( $receiptList )) {
  5165. die ( 'illegal request' );
  5166. }
  5167. $loanList = $loanReceipt->find ( array (
  5168. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5169. 'desc' => 'rid',
  5170. 'asArray' => true
  5171. ) );
  5172. $data ['explanation'] = '';
  5173. if (! empty ( $loanList ))
  5174. $data ['explanation'] = $loanList [0] ['explanation'];
  5175. $Locate = 0;
  5176. $roleId = 0;
  5177. $button = 0;
  5178. foreach ( $loanList as $key => $value ) {
  5179. $loanList [$key] ['Locate'] = $Locate;
  5180. $Locate ++;
  5181. $loanList [$key] ['reviseDetail'] = array ();
  5182. if (! empty ( $value ['reviseDetail'] ))
  5183. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5184. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5185. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5186. $categoryDetil = $Lcategory->getOne ( array (
  5187. 'where' => 'cid=' . $value ['cid'],
  5188. 'asArray' => true
  5189. ) );
  5190. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5191. // 检测编辑状态
  5192. $verifyList = $verify->getOne ( array (
  5193. 'where' => 'vid=' . $value ['verify'],
  5194. 'asArray' => true
  5195. ) );
  5196. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5197. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5198. Doo::loadModel ( 'role' );
  5199. $role = new role ();
  5200. $flag = true;
  5201. $roleKey = 0;
  5202. $endStaffArray = array ();
  5203. $roleArrayCopy = array ();
  5204. foreach ( $verifyList as $k => $v ) {
  5205. // init verifyStaff
  5206. if ($v [1] == 'ROLE') {
  5207. if (! empty ( $verifyStaff )) {
  5208. $endStaffArray = end ( $verifyStaff );
  5209. }
  5210. $roleVerify = json_decode ( $v [3], true );
  5211. $roleKey = $k;
  5212. $roleArray = array ();
  5213. $rolename = $role->getOne ( array (
  5214. 'where' => 'rid=' . $v [0],
  5215. 'asArray' => true
  5216. ) );
  5217. foreach ( $roleVerify as $o => $p ) {
  5218. $staffID = explode ( '_', $p );
  5219. $staffInfo = $staff->getOne ( array (
  5220. 'where' => 'sid=' . $staffID [0],
  5221. 'asArray' => true
  5222. ) );
  5223. // print_r($staffID);
  5224. $exp = array (
  5225. 0 => $staffInfo ['sid'],
  5226. 1 => $staffID [1],
  5227. 2 => $staffInfo ['avatar'],
  5228. 'date' => '',
  5229. 'date' => '',
  5230. 'opinion' => '',
  5231. 'status' => '',
  5232. 'rolename' => $rolename ['name']
  5233. );
  5234. array_push ( $roleArray, $exp );
  5235. }
  5236. $roleArrayCopy [$v [0]] = $roleArray;
  5237. // $verifyList[$k]['roleArray']=$roleArray;
  5238. }
  5239. $verifyList [$k] ['date'] = "";
  5240. $verifyList [$k] ['opinion'] = "";
  5241. $verifyList [$k] ['status'] = "";
  5242. if (empty ( $verifyStaff )) {
  5243. $verifyList [$k] ['date'] = "";
  5244. $verifyList [$k] ['opinion'] = "";
  5245. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5246. $verifyList [$k] ['status'] = 4;
  5247. $flag = false;
  5248. }
  5249. } else {
  5250. foreach ( $verifyStaff as $m => $u ) {
  5251. if ($v [0] == $m) {
  5252. $verifyList [$k] ['date'] = $u ['date'];
  5253. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5254. $verifyList [$k] ['status'] = $u ['status'];
  5255. $flag = false;
  5256. break;
  5257. }
  5258. }
  5259. $endStaffArray = end ( $verifyStaff );
  5260. if (isset ( $endStaffArray ['ROLE'] )) {
  5261. } else {
  5262. }
  5263. }
  5264. }
  5265. $rolename ['name'] = '';
  5266. if (! empty ( $roleId )) {
  5267. Doo::loadModel ( 'role' );
  5268. $role = new role ();
  5269. $rolename = $role->getOne ( array (
  5270. 'where' => 'rid=' . $roleId,
  5271. 'asArray' => true
  5272. ) );
  5273. }
  5274. if (! empty ( $verifyStaff ))
  5275. $endStaffArray = end ( $verifyStaff );
  5276. $KOP = false;
  5277. foreach ( $roleArrayCopy as $P => $A ) {
  5278. foreach ( $A as $MKI => $AVL ) {
  5279. if (! empty ( $verifyStaff )) {
  5280. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5281. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5282. $button = 4;
  5283. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5284. }
  5285. foreach ( $verifyStaff as $m => $u ) {
  5286. $AVLFK = $AVL [0] . '_R';
  5287. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5288. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5289. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5290. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5291. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5292. break;
  5293. }
  5294. }
  5295. } else {
  5296. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5297. $button = 4;
  5298. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5299. }
  5300. }
  5301. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5302. $KOP = true;
  5303. }
  5304. }
  5305. foreach ( $roleArrayCopy as $k => $v ) {
  5306. foreach ( $verifyList as $m => $n ) {
  5307. if ($n [0] == $k) {
  5308. array_splice ( $verifyList, $m, 1, $v );
  5309. }
  5310. }
  5311. }
  5312. $loanList [$key] ['verifyList'] = $verifyList;
  5313. }
  5314. $htmlLoan = '';
  5315. $data ['loanReceiptDate'] = '';
  5316. if (isset ( $loanList [0] )) {
  5317. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5318. if ($value ['status'] == 1)
  5319. $htmlLoan .= '<li class="done" >';
  5320. elseif ($value ['status'] == 3)
  5321. $htmlLoan .= '<li class="undone" >';
  5322. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5323. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5324. if (isset ( $value ['rolename'] ))
  5325. $htmlLoan .= $value ['rolename'];
  5326. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5327. }
  5328. $data ['loanDate'] = $loanList [0] ['date'];
  5329. } else {
  5330. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5331. }
  5332. $data ['htmlLoan'] = $htmlLoan;
  5333. // $data ['LoanReceipt']=$loanList[0];
  5334. // print_r($loanList);
  5335. $Locate = 0;
  5336. $roleId = 0;
  5337. $button = 0;
  5338. if ($ap == 4)
  5339. $status = 4;
  5340. Doo::loadClass ( 'XDeode' );
  5341. $XDeode = new XDeode ( 5 );
  5342. foreach ( $receiptList as $key => $value ) {
  5343. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5344. $receiptList [$key] ['Locate'] = $Locate;
  5345. $Locate ++;
  5346. $receiptList [$key] ['reviseDetail'] = array ();
  5347. // 调整金额 代码调整
  5348. if (! empty ( $value ['reviseDetail'] )) {
  5349. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5350. foreach ( $reviseDetail as $ry => $re ) {
  5351. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5352. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5353. }
  5354. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5355. // print_r($reviseDetail);
  5356. }
  5357. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5358. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5359. $categoryDetil = $Lcategory->getOne ( array (
  5360. 'where' => 'cid=' . $value ['cid'],
  5361. 'asArray' => true
  5362. ) );
  5363. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5364. // 检测编辑状态
  5365. $verifyList = $verify->getOne ( array (
  5366. 'where' => 'vid=' . $value ['verify'],
  5367. 'asArray' => true
  5368. ) );
  5369. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5370. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5371. Doo::loadModel ( 'role' );
  5372. $role = new role ();
  5373. // print_r($verifyList);
  5374. $flag = true;
  5375. $roleKey = 0;
  5376. $endStaffArray = array ();
  5377. $roleArrayCopy = array ();
  5378. foreach ( $verifyList as $k => $v ) {
  5379. // init verifyStaff
  5380. if ($v [1] == 'ROLE') {
  5381. if (! empty ( $verifyStaff )) {
  5382. $endStaffArray = end ( $verifyStaff );
  5383. if ($v [0] == $endStaffArray ['nextStaff']) {
  5384. $roleId = $v [0];
  5385. }
  5386. }
  5387. $roleVerify = json_decode ( $v [3], true );
  5388. $roleKey = $k;
  5389. $roleArray = array ();
  5390. $rolename = $role->getOne ( array (
  5391. 'where' => 'rid=' . $v [0],
  5392. 'asArray' => true
  5393. ) );
  5394. foreach ( $roleVerify as $o => $p ) {
  5395. $staffID = explode ( '_', $p );
  5396. $staffInfo = $staff->getOne ( array (
  5397. 'where' => 'sid=' . $staffID [0],
  5398. 'asArray' => true
  5399. ) );
  5400. // print_r($staffID);
  5401. $exp = array (
  5402. 0 => $staffInfo ['sid'],
  5403. 1 => $staffID [1],
  5404. 2 => $staffInfo ['avatar'],
  5405. 'date' => '',
  5406. 'date' => '',
  5407. 'opinion' => '',
  5408. 'status' => '',
  5409. 'rolename' => $rolename ['name']
  5410. );
  5411. array_push ( $roleArray, $exp );
  5412. }
  5413. $roleArrayCopy [$v [0]] = $roleArray;
  5414. // $verifyList[$k]['roleArray']=$roleArray;
  5415. }
  5416. // print_r($roleArray);
  5417. $verifyList [$k] ['date'] = "";
  5418. $verifyList [$k] ['opinion'] = "";
  5419. $verifyList [$k] ['status'] = "";
  5420. if (empty ( $verifyStaff )) {
  5421. $verifyList [$k] ['date'] = "";
  5422. $verifyList [$k] ['opinion'] = "";
  5423. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5424. $verifyList [$k] ['status'] = 4;
  5425. $button = 4;
  5426. $flag = false;
  5427. }
  5428. } else {
  5429. foreach ( $verifyStaff as $m => $u ) {
  5430. if ($v [0] == $m) {
  5431. $verifyList [$k] ['date'] = $u ['date'];
  5432. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5433. $verifyList [$k] ['status'] = $u ['status'];
  5434. $flag = false;
  5435. break;
  5436. }
  5437. }
  5438. $endStaffArray = end ( $verifyStaff );
  5439. if (isset ( $endStaffArray ['ROLE'] )) {
  5440. } else {
  5441. $endKey = key ( $verifyStaff );
  5442. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5443. $button = 4;
  5444. $verifyList [$k] ['status'] = 4;
  5445. }
  5446. }
  5447. }
  5448. }
  5449. $rolename ['name'] = '';
  5450. if (! empty ( $roleId )) {
  5451. Doo::loadModel ( 'role' );
  5452. $role = new role ();
  5453. $rolename = $role->getOne ( array (
  5454. 'where' => 'rid=' . $roleId,
  5455. 'asArray' => true
  5456. ) );
  5457. }
  5458. if (! empty ( $verifyStaff ))
  5459. $endStaffArray = end ( $verifyStaff );
  5460. $KOP = false;
  5461. foreach ( $roleArrayCopy as $P => $A ) {
  5462. foreach ( $A as $MKI => $AVL ) {
  5463. if (! empty ( $verifyStaff )) {
  5464. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5465. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5466. $button = 4;
  5467. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5468. }
  5469. foreach ( $verifyStaff as $m => $u ) {
  5470. $AVLFK = $AVL [0] . '_R';
  5471. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5472. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5473. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5474. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5475. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5476. break;
  5477. }
  5478. }
  5479. } else {
  5480. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5481. $button = 4;
  5482. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5483. }
  5484. }
  5485. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5486. $KOP = true;
  5487. }
  5488. }
  5489. foreach ( $roleArrayCopy as $k => $v ) {
  5490. foreach ( $verifyList as $m => $n ) {
  5491. if ($n [0] == $k) {
  5492. array_splice ( $verifyList, $m, 1, $v );
  5493. }
  5494. }
  5495. }
  5496. // print_r($verifyList);
  5497. $receiptList [$key] ['verifyList'] = $verifyList;
  5498. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5499. 'where' => 'sid=' . $value ['staff'],
  5500. 'asArray' => true
  5501. ) );
  5502. $receiptList [$key] ['button'] = $button;
  5503. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5504. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5505. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5506. $receiptList [$key] ['relust'] = $relust;
  5507. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5508. }
  5509. // print_r($receiptList);die;
  5510. // $data['verifyDetail']=$verifyDetail;
  5511. $mothHtml = "";
  5512. for($i = 1; $i <= 12; $i ++) {
  5513. if ($month == $i)
  5514. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5515. else
  5516. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5517. }
  5518. // 获取审批日志
  5519. Doo::loadModel ( 'receiptLog' );
  5520. $receiptLog = new receiptLog ();
  5521. $rlList = array ();
  5522. $rlInfo = $receiptLog->getOne ( array (
  5523. 'where' => 'rid=' . $rid . ' and status=4',
  5524. 'asArray' => true
  5525. ) );
  5526. $tijdate = $receiptLog->getOne ( array (
  5527. 'where' => 'rid=' . $rid . ' and status=2',
  5528. 'asc' => 'rlid',
  5529. 'asArray' => true
  5530. ) );
  5531. if (! empty ( $rlInfo )) {
  5532. $rlList = $receiptLog->find ( array (
  5533. 'where' => 'rid=' . $rid,
  5534. 'asc' => 'rlid',
  5535. 'asArray' => true
  5536. ) );
  5537. }
  5538. // echo $rid;
  5539. // print_r($receiptList);
  5540. $receiptList [0] ['rlList'] = $rlList;
  5541. // print_r($receiptList);
  5542. $enclosurList = $enclosur->find ( array (
  5543. 'where' => 'rid=' . $rid,
  5544. 'asArray' => true
  5545. ) );
  5546. $enclosurHtml = '';
  5547. foreach ( $enclosurList as $value ) {
  5548. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5549. }
  5550. $data ['enclosurHtml'] = $enclosurHtml;
  5551. $data ['rolename'] = $rolename ['name'];
  5552. $data ['mothHtml'] = $mothHtml;
  5553. // print_r($receiptList);
  5554. $data ['rid'] = $rid;
  5555. $data ['tijdate'] = $tijdate ['date'];
  5556. $data ['receiptList'] = $receiptList;
  5557. $data ['receiptApprovalCount'] = count ( $receiptList );
  5558. $data ['status'] = $status;
  5559. $data ['year'] = $year;
  5560. $data ['categoryList'] = $categoryList;
  5561. $data ['staffList'] = $staffList;
  5562. $data ['cid'] = $cid;
  5563. $data ['sid'] = $sid;
  5564. $data ['ap'] = $ap;
  5565. $data ['memu'] = "receipt";
  5566. $data ['staff'] = $this->staff;
  5567. $data ['receiptMemu'] = 'approvalExpenses';
  5568. $data ['verifyId'] = $this->verifyId;
  5569. $data ['executeId'] = $this->executeId;
  5570. $this->render ( "/admin/receiptburEdi", $data );
  5571. }
  5572. function hisImplement() {
  5573. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5574. if (empty ( $item ))
  5575. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5576. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5577. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5578. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5579. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5580. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5581. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5582. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5583. Doo::loadClass ( 'XDeode' );
  5584. $XDeode = new XDeode ( 5 );
  5585. Doo::loadModel ( 'receipt' );
  5586. $receipt = new receipt ();
  5587. Doo::loadModel ( 'L_category' );
  5588. $Lcategory = new L_category ();
  5589. Doo::loadModel ( 'verify' );
  5590. Doo::loadModel ( 'statistics' );
  5591. $statistics = new statistics ();
  5592. $verify = new verify ();
  5593. Doo::loadModel ( 'staff' );
  5594. $staff = new staff ();
  5595. Doo::loadClass ( 'XDeode' );
  5596. $XDeode = new XDeode ( 5 );
  5597. $cid = $XDeode->decode ( $cidKey );
  5598. $condition = "";
  5599. if ($item == "expenses")
  5600. $condition = " and Rtype=1 ";
  5601. elseif ($item == "receipts")
  5602. $condition = " and Rtype=0 ";
  5603. elseif ($item == "remits")
  5604. $condition = " and Rtype=2 ";
  5605. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5606. $sopString = $cidString = "";
  5607. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5608. if (empty ( $rdate ))
  5609. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5610. else
  5611. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5612. if ($status == 'pendImplement') {
  5613. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5614. } elseif ($status == 'alerpts') {
  5615. $statusCon = '(status=8 or status=9 )';
  5616. if (empty ( $rdate ))
  5617. $dateCondition .= " and Year(date) =" . $year;
  5618. else
  5619. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5620. }
  5621. if ($sop != 'SOP')
  5622. $sopString = " and staff=" . $sop;
  5623. if ($cidKey != 'ALL')
  5624. $cidString = " and cid=" . $cid;
  5625. $receiptList = $receipt->find ( array (
  5626. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5627. 'desc' => 'rid',
  5628. 'asArray' => true
  5629. ) );
  5630. // 员工筛选
  5631. $receiptList2 = $receipt->find ( array (
  5632. 'where' => $statusCon . $condition . $dateCondition,
  5633. 'desc' => 'rid',
  5634. 'asArray' => true
  5635. ) );
  5636. $sopStaff = array ();
  5637. foreach ( $receiptList2 as $key => $value ) {
  5638. $staffDetail = $staff->getOne ( array (
  5639. 'select' => 'username',
  5640. 'where' => 'sid=' . $value ['staff'],
  5641. 'asArray' => true
  5642. ) );
  5643. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5644. }
  5645. // 办事处筛选
  5646. $categoryScreen = array ();
  5647. $categorList = $Lcategory->getCategory ();
  5648. foreach ( $receiptList2 as $key => $value ) {
  5649. foreach ( $categorList as $k => $v ) {
  5650. if ($value ['cid'] == $v ['cid']) {
  5651. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5652. break;
  5653. }
  5654. }
  5655. }
  5656. $categoryScreenHtml = "";
  5657. foreach ( $categoryScreen as $key => $value ) {
  5658. if ($cidKey == $key)
  5659. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5660. else
  5661. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5662. }
  5663. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5664. $data ['cidKey'] = $cidKey;
  5665. $Locate = 0;
  5666. $roleId = 0;
  5667. $button = 0;
  5668. $staffBatchNumber = 100001;
  5669. $remittanceList = array ();
  5670. foreach ( $receiptList as $key => $value ) {
  5671. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5672. $receiptList [$key] ['Texe'] = 'false';
  5673. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5674. $receiptList [$key] ['Texe'] = 'true';
  5675. }
  5676. $receiptList [$key] ['TRexe'] = 'true';
  5677. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5678. $receiptList [$key] ['TRexe'] = 'false';
  5679. }
  5680. $receiptList [$key] ['Locate'] = $Locate;
  5681. $Locate ++;
  5682. $receiptList [$key] ['reviseDetail'] = array ();
  5683. if (! empty ( $value ['reviseDetail'] ))
  5684. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5685. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5686. $categoryDetil = $Lcategory->getOne ( array (
  5687. 'where' => 'cid=' . $value ['cid'],
  5688. 'asArray' => true
  5689. ) );
  5690. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5691. // 检测编辑状态
  5692. $verifyList = $verify->getOne ( array (
  5693. 'where' => 'vid=' . $value ['verify'],
  5694. 'asArray' => true
  5695. ) );
  5696. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5697. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5698. Doo::loadModel ( 'role' );
  5699. $role = new role ();
  5700. $flag = true;
  5701. $roleKey = 0;
  5702. $endStaffArray = array ();
  5703. $roleArrayCopy = array ();
  5704. foreach ( $verifyList as $k => $v ) {
  5705. // init verifyStaff
  5706. if ($v [1] == 'ROLE') {
  5707. if (! empty ( $verifyStaff )) {
  5708. $endStaffArray = end ( $verifyStaff );
  5709. }
  5710. $roleVerify = json_decode ( $v [3], true );
  5711. $roleKey = $k;
  5712. $roleArray = array ();
  5713. $rolename = $role->getOne ( array (
  5714. 'where' => 'rid=' . $v [0],
  5715. 'asArray' => true
  5716. ) );
  5717. foreach ( $roleVerify as $o => $p ) {
  5718. $staffID = explode ( '_', $p );
  5719. $staffInfo = $staff->getOne ( array (
  5720. 'where' => 'sid=' . $staffID [0],
  5721. 'asArray' => true
  5722. ) );
  5723. $exp = array (
  5724. 0 => $staffInfo ['sid'],
  5725. 1 => $staffID [1],
  5726. 2 => $staffInfo ['avatar'],
  5727. 'date' => '',
  5728. 'date' => '',
  5729. 'opinion' => '',
  5730. 'status' => '',
  5731. 'rolename' => $rolename ['name']
  5732. );
  5733. array_push ( $roleArray, $exp );
  5734. }
  5735. $roleArrayCopy [$v [0]] = $roleArray;
  5736. }
  5737. $verifyList [$k] ['date'] = "";
  5738. $verifyList [$k] ['opinion'] = "";
  5739. $verifyList [$k] ['status'] = "";
  5740. if (empty ( $verifyStaff )) {
  5741. $verifyList [$k] ['date'] = "";
  5742. $verifyList [$k] ['opinion'] = "";
  5743. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5744. $verifyList [$k] ['status'] = 4;
  5745. $flag = false;
  5746. }
  5747. } else {
  5748. foreach ( $verifyStaff as $m => $u ) {
  5749. if ($v [0] == $m) {
  5750. $verifyList [$k] ['date'] = $u ['date'];
  5751. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5752. $verifyList [$k] ['status'] = $u ['status'];
  5753. $flag = false;
  5754. break;
  5755. }
  5756. }
  5757. $endStaffArray = end ( $verifyStaff );
  5758. }
  5759. }
  5760. $rolename ['name'] = '';
  5761. if (! empty ( $roleId )) {
  5762. Doo::loadModel ( 'role' );
  5763. $role = new role ();
  5764. $rolename = $role->getOne ( array (
  5765. 'where' => 'rid=' . $roleId,
  5766. 'asArray' => true
  5767. ) );
  5768. }
  5769. if (! empty ( $verifyStaff ))
  5770. $endStaffArray = end ( $verifyStaff );
  5771. $KOP = false;
  5772. foreach ( $roleArrayCopy as $P => $A ) {
  5773. foreach ( $A as $MKI => $AVL ) {
  5774. if (! empty ( $verifyStaff )) {
  5775. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5776. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5777. $button = 4;
  5778. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5779. }
  5780. foreach ( $verifyStaff as $m => $u ) {
  5781. $AVLFK = $AVL [0] . '_R';
  5782. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5783. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5784. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5785. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5786. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5787. break;
  5788. }
  5789. }
  5790. } else {
  5791. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5792. $button = 4;
  5793. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5794. }
  5795. }
  5796. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5797. $KOP = true;
  5798. }
  5799. }
  5800. foreach ( $roleArrayCopy as $k => $v ) {
  5801. foreach ( $verifyList as $m => $n ) {
  5802. if ($n [0] == $k) {
  5803. array_splice ( $verifyList, $m, 1, $v );
  5804. }
  5805. }
  5806. }
  5807. $receiptList [$key] ['verifyList'] = $verifyList;
  5808. $staffDetail = $staff->getOne ( array (
  5809. 'where' => 'sid=' . $value ['staff'],
  5810. 'asArray' => true
  5811. ) );
  5812. $receiptList [$key] ['staffDetail'] = $staffDetail;
  5813. $receiptList [$key] ['button'] = $button;
  5814. // 设置导出汇款execl
  5815. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  5816. $remittanceDetail = array (
  5817. $staffBatchNumber,
  5818. $value ['remittanceName'],
  5819. $value ['bankNumber'],
  5820. $value ['bankName'],
  5821. $value ['remittanceBankType'],
  5822. $value ['coupletNumber'],
  5823. $value ['sum']
  5824. );
  5825. array_push ( $remittanceList, $remittanceDetail );
  5826. $staffBatchNumber ++;
  5827. }
  5828. }
  5829. $data ['remittanceList'] = json_encode ( $remittanceList );
  5830. // print_r($receiptList);
  5831. $mothHtml = "";
  5832. for($i = 1; $i <= 12; $i ++) {
  5833. if ($moth == $i)
  5834. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5835. else
  5836. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5837. }
  5838. $dayHtml = "";
  5839. if ($day != "DAY" || $moth != "MONTH") {
  5840. for($i = 1; $i <= 31; $i ++) {
  5841. if ($day == $i)
  5842. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  5843. else
  5844. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  5845. }
  5846. }
  5847. $sopHtml = "";
  5848. foreach ( $sopStaff as $key => $value ) {
  5849. if ($sop == $key)
  5850. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5851. else
  5852. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5853. }
  5854. $data ['status'] = $status;
  5855. $data ['rdate'] = $rdate;
  5856. $data ['sopHtml'] = $sopHtml;
  5857. $data ['dayHtml'] = $dayHtml;
  5858. $data ['mothHtml'] = $mothHtml;
  5859. $data ['receiptList'] = $receiptList;
  5860. $data ['memu'] = "receipt";
  5861. $data ['staff'] = $this->staff;
  5862. $data ['receiptMemu'] = 'implement';
  5863. $data ['verifyId'] = $this->verifyId;
  5864. $data ['executeId'] = $this->executeId;
  5865. $data ['item'] = $item;
  5866. $data ['year'] = $year;
  5867. $data ['moth'] = $moth;
  5868. $data ['day'] = $day;
  5869. $data ['sop'] = $sop;
  5870. $this->render ( "/admin/hisImplement", $data );
  5871. }
  5872. /**
  5873. * 导出汇款信息的exelc
  5874. */
  5875. function exportRemittance() {
  5876. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  5877. if (empty ( $remittanceInfo ))
  5878. die ( 'illegal request' );
  5879. $title = array (
  5880. '员工编号',
  5881. '姓名',
  5882. '员工账号',
  5883. '员工账户开户行',
  5884. '转账类型',
  5885. '联行号',
  5886. '金额'
  5887. );
  5888. $data = json_decode ( $remittanceInfo, true );
  5889. if (empty ( $data ))
  5890. die ( 'illegal request' );
  5891. Doo::loadClass ( 'receipt.func' );
  5892. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  5893. header ( 'Content-Type:text/html;charset=utf-8' );
  5894. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  5895. }
  5896. function ajaxExamine() {
  5897. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5898. Doo::loadModel ( 'receipt' );
  5899. $receipt = new receipt ();
  5900. if (! empty ( $rid )) {
  5901. $rLRes = $receipt->find ( array (
  5902. '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,
  5903. 'asArray' => true
  5904. ) );
  5905. echo json_encode ( array (
  5906. 'status' => 1,
  5907. 'receipt' => $rLRes [0]
  5908. ) );
  5909. die ();
  5910. }
  5911. echo json_encode ( array (
  5912. 'status' => 0,
  5913. 'receipt' => array ()
  5914. ) );
  5915. die ();
  5916. }
  5917. /*
  5918. * 废弃
  5919. */
  5920. function myReceipt() {
  5921. // all approval past withdraw
  5922. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5923. if (empty ( $item ))
  5924. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  5925. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5926. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  5927. Doo::loadModel ( 'receipt' );
  5928. $receipt = new receipt ();
  5929. // pre-loaded
  5930. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  5931. // have cache
  5932. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  5933. if (! empty ( $moth )) // yearPage
  5934. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  5935. $this->showCache ( $path );
  5936. }
  5937. Doo::loadModel ( 'L_category' );
  5938. $Lcategory = new L_category ();
  5939. Doo::loadModel ( 'verify' );
  5940. Doo::loadModel ( 'statistics' );
  5941. $statistics = new statistics ();
  5942. $verify = new verify ();
  5943. Doo::loadModel ( 'staff' );
  5944. $staff = new staff ();
  5945. $condition = " and status!=0 ";
  5946. if ($item == "approval")
  5947. $condition = " and status=2 ";
  5948. elseif ($item == "withdraw")
  5949. $condition = " and status=3 ";
  5950. elseif ($item == "past")
  5951. $condition = " and status=1 ";
  5952. elseif ($item == "whdw")
  5953. $condition = " and status=4 ";
  5954. $dateCondition = " and Year(date) =" . $year;
  5955. if (! empty ( $moth )) {
  5956. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  5957. $stList = $statistics->getOne ( array (
  5958. 'select' => 'rePrice ,agPrice',
  5959. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  5960. 'asArray' => true
  5961. ) );
  5962. } else
  5963. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  5964. if (empty ( $stList ))
  5965. $stList = array (
  5966. 'rePrice' => 0,
  5967. 'agPrice' => 0
  5968. );
  5969. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  5970. $data ['stList'] = array (
  5971. 'rePrice' => $stList ['rePrice'],
  5972. 'agPrice' => $stList ['agPrice'],
  5973. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  5974. );
  5975. $receiptList = $receipt->find ( array (
  5976. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  5977. 'desc' => 'rid',
  5978. 'asArray' => true
  5979. ) );
  5980. $Locate = 0;
  5981. $roleId = 0;
  5982. $button = 0;
  5983. foreach ( $receiptList as $key => $value ) {
  5984. $receiptList [$key] ['Locate'] = $Locate;
  5985. $Locate ++;
  5986. $receiptList [$key] ['reviseDetail'] = array ();
  5987. if (! empty ( $value ['reviseDetail'] ))
  5988. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5989. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5990. $categoryDetil = $Lcategory->getOne ( array (
  5991. 'where' => 'cid=' . $value ['cid'],
  5992. 'asArray' => true
  5993. ) );
  5994. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5995. // 检测编辑状态
  5996. $verifyList = $verify->getOne ( array (
  5997. 'where' => 'vid=' . $value ['verify'],
  5998. 'asArray' => true
  5999. ) );
  6000. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6001. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6002. Doo::loadModel ( 'role' );
  6003. $role = new role ();
  6004. $flag = true;
  6005. $roleKey = 0;
  6006. $endStaffArray = array ();
  6007. $roleArrayCopy = array ();
  6008. foreach ( $verifyList as $k => $v ) {
  6009. // init verifyStaff
  6010. if ($v [1] == 'ROLE') {
  6011. if (! empty ( $verifyStaff )) {
  6012. $endStaffArray = end ( $verifyStaff );
  6013. // if ($v[0]==$endStaffArray['nextStaff']){
  6014. // $roleId=$v[0];
  6015. // }
  6016. }
  6017. $roleVerify = json_decode ( $v [3], true );
  6018. $roleKey = $k;
  6019. $roleArray = array ();
  6020. $rolename = $role->getOne ( array (
  6021. 'where' => 'rid=' . $v [0],
  6022. 'asArray' => true
  6023. ) );
  6024. foreach ( $roleVerify as $o => $p ) {
  6025. $staffID = explode ( '_', $p );
  6026. $staffInfo = $staff->getOne ( array (
  6027. 'where' => 'sid=' . $staffID [0],
  6028. 'asArray' => true
  6029. ) );
  6030. // print_r($staffID);
  6031. $exp = array (
  6032. 0 => $staffInfo ['sid'],
  6033. 1 => $staffID [1],
  6034. 2 => $staffInfo ['avatar'],
  6035. 'date' => '',
  6036. 'date' => '',
  6037. 'opinion' => '',
  6038. 'status' => '',
  6039. 'rolename' => $rolename ['name']
  6040. );
  6041. array_push ( $roleArray, $exp );
  6042. }
  6043. $roleArrayCopy [$v [0]] = $roleArray;
  6044. // $verifyList[$k]['roleArray']=$roleArray;
  6045. }
  6046. $verifyList [$k] ['date'] = "";
  6047. $verifyList [$k] ['opinion'] = "";
  6048. $verifyList [$k] ['status'] = "";
  6049. if (empty ( $verifyStaff )) {
  6050. $verifyList [$k] ['date'] = "";
  6051. $verifyList [$k] ['opinion'] = "";
  6052. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6053. $verifyList [$k] ['status'] = 4;
  6054. $flag = false;
  6055. }
  6056. } else {
  6057. foreach ( $verifyStaff as $m => $u ) {
  6058. if ($v [0] == $m) {
  6059. $verifyList [$k] ['date'] = $u ['date'];
  6060. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6061. $verifyList [$k] ['status'] = $u ['status'];
  6062. $flag = false;
  6063. break;
  6064. }
  6065. }
  6066. $endStaffArray = end ( $verifyStaff );
  6067. if (isset ( $endStaffArray ['ROLE'] )) {
  6068. } else {
  6069. // $endKey=key($verifyStaff);
  6070. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6071. // $button=4;
  6072. // $verifyList[$k]['status']=4;
  6073. // }
  6074. }
  6075. }
  6076. }
  6077. $rolename ['name'] = '';
  6078. if (! empty ( $roleId )) {
  6079. Doo::loadModel ( 'role' );
  6080. $role = new role ();
  6081. $rolename = $role->getOne ( array (
  6082. 'where' => 'rid=' . $roleId,
  6083. 'asArray' => true
  6084. ) );
  6085. }
  6086. if (! empty ( $verifyStaff ))
  6087. $endStaffArray = end ( $verifyStaff );
  6088. $KOP = false;
  6089. foreach ( $roleArrayCopy as $P => $A ) {
  6090. foreach ( $A as $MKI => $AVL ) {
  6091. if (! empty ( $verifyStaff )) {
  6092. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6093. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6094. $button = 4;
  6095. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6096. }
  6097. foreach ( $verifyStaff as $m => $u ) {
  6098. $AVLFK = $AVL [0] . '_R';
  6099. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6100. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6101. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6102. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6103. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6104. break;
  6105. }
  6106. }
  6107. } else {
  6108. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6109. $button = 4;
  6110. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6111. }
  6112. }
  6113. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6114. $KOP = true;
  6115. }
  6116. }
  6117. foreach ( $roleArrayCopy as $k => $v ) {
  6118. foreach ( $verifyList as $m => $n ) {
  6119. if ($n [0] == $k) {
  6120. array_splice ( $verifyList, $m, 1, $v );
  6121. }
  6122. }
  6123. }
  6124. $receiptList [$key] ['verifyList'] = $verifyList;
  6125. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6126. 'where' => 'sid=' . $value ['staff'],
  6127. 'asArray' => true
  6128. ) );
  6129. $receiptList [$key] ['button'] = $button;
  6130. }
  6131. // print_r($receiptList);die;
  6132. $mothHtml = "";
  6133. for($i = 1; $i <= 12; $i ++) {
  6134. if ($moth == $i)
  6135. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6136. else
  6137. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6138. }
  6139. $data ['mothHtml'] = $mothHtml;
  6140. $data ['receiptList'] = $receiptList;
  6141. $data ['memu'] = "receipt";
  6142. $data ['staff'] = $this->staff;
  6143. $data ['receiptMemu'] = 'receipt';
  6144. $data ['verifyId'] = $this->verifyId;
  6145. $data ['executeId'] = $this->executeId;
  6146. $data ['item'] = $item;
  6147. $data ['year'] = $year;
  6148. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6149. // sufficient condition to generate cache
  6150. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6151. $receiptList = $receipt->find ( array (
  6152. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6153. 'asArray' => true
  6154. ) );
  6155. if (empty ( $receiptList )) { // generated files
  6156. ob_start ();
  6157. $this->render ( "/admin/saea_myList", $data );
  6158. $this->cacheFile ( $path );
  6159. die ();
  6160. // $content = ob_get_contents();
  6161. // $fp = fopen($path, "w");
  6162. // fwrite($fp, $content);
  6163. // fclose($fp);
  6164. }
  6165. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6166. $receiptList = $receipt->find ( array (
  6167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6168. 'asArray' => true
  6169. ) );
  6170. if (empty ( $receiptList )) { // generated files
  6171. ob_start ();
  6172. $this->render ( "/admin/saea_myList", $data );
  6173. $this->cacheFile ( $path );
  6174. die ();
  6175. }
  6176. }
  6177. }
  6178. $this->render ( "/admin/saea_myList", $data );
  6179. }
  6180. function saeaCreate() {
  6181. Doo::loadModel ( 'accountItem' );
  6182. Doo::loadModel ( 'verify' );
  6183. Doo::loadModel ( 'receipt' );
  6184. Doo::loadModel ( 'L_category' );
  6185. $lCategory = new L_category ();
  6186. $receipt = new receipt ();
  6187. $verify = new verify ();
  6188. $accountItem = new accountItem ();
  6189. Doo::loadModel ( "role" );
  6190. $role = new role ();
  6191. $acItem = $accountItem->find ( array (
  6192. 'asArray' => true
  6193. ) );
  6194. $veList = $verify->find ( array (
  6195. 'asArray' => true
  6196. ) );
  6197. foreach ( $veList as $key => $value ) {
  6198. $v = json_decode ( $value ['staff'] );
  6199. $list = array ();
  6200. foreach ( $v as $n => $m ) {
  6201. if ($m ['1'] == 'ROLE') {
  6202. $roleInfo = $role->getOne ( array (
  6203. 'where' => 'rid=' . $m [0],
  6204. 'asArray' => true
  6205. ) );
  6206. $v [$n] [1] = $roleInfo ['name'];
  6207. array_push ( $list, $roleInfo ['name'] );
  6208. } else {
  6209. array_push ( $list, $v [$n] [1] );
  6210. }
  6211. }
  6212. $veList [$key] ['staff'] = implode ( '>', $list );
  6213. }
  6214. $data ['category'] = $lCategory->find ( array (
  6215. 'asArray' => true
  6216. ) );
  6217. $data ['veList'] = $veList;
  6218. $data ['acItem'] = $acItem;
  6219. $data ['memu'] = "receipt";
  6220. $data ['staff'] = $this->staff;
  6221. $data ['receiptMemu'] = 'saeaBorad';
  6222. $data ['verifyId'] = $this->verifyId;
  6223. $data ['executeId'] = $this->executeId;
  6224. $this->render ( "/admin/saea_create", $data );
  6225. }
  6226. function addReceipt() {
  6227. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6228. $agency = $this->get_args ( 'agency' );
  6229. $travel = $this->get_args ( 'travel' );
  6230. $train = $this->get_args ( 'train' );
  6231. $other = $this->get_args ( 'other' );
  6232. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6233. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6234. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6235. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6236. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6237. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6238. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6239. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6240. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6241. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6242. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6243. header ( 'Content-Type:text/html;charset=utf-8' );
  6244. die ( '请填写联行号' );
  6245. }
  6246. Doo::loadModel ( 'receipt' );
  6247. Doo::loadModel ( 'receiptDetail' );
  6248. Doo::loadModel ( 'accountItem' );
  6249. $accountItem = new accountItem ();
  6250. $receipt = new receipt ();
  6251. Doo::loadModel ( 'enclosur' );
  6252. Doo::loadModel ( 'execute' );
  6253. $execute = new execute ();
  6254. $executeDetail = $execute->getOne ( array (
  6255. 'where' => 'mold="报销单执行人"',
  6256. 'asArray' => true
  6257. ) );
  6258. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6259. // if(!empty($receiptDetail))
  6260. // return "/referReceipt/".$receiptDetail['rid'];
  6261. $aItem = $accountItem->find ( array (
  6262. 'asArray' => true
  6263. ) );
  6264. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6265. $ag = $tr = $ta = $ot = 0;
  6266. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  6267. foreach ( $aItem as $key => $value ) {
  6268. if ($value ['category'] == $this->AGENCY) {
  6269. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6270. array_push ( $accountJson [$this->AGENCY], array (
  6271. 'aid' => $value ['aid'],
  6272. 'name' => $value ['name'],
  6273. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6274. ) );
  6275. $sum += $agency [$ag];
  6276. $agencySum += $agency [$ag];
  6277. }
  6278. $ag ++;
  6279. }
  6280. if ($value ['category'] == $this->TRAVEL) {
  6281. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6282. array_push ( $accountJson [$this->TRAVEL], array (
  6283. 'aid' => $value ['aid'],
  6284. 'name' => $value ['name'],
  6285. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6286. ) );
  6287. $sum += $travel [$tr];
  6288. $travelSum += $travel [$tr];
  6289. }
  6290. $tr ++;
  6291. }
  6292. if ($value ['category'] == $this->TRAIN) {
  6293. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6294. array_push ( $accountJson [$this->TRAIN], array (
  6295. 'aid' => $value ['aid'],
  6296. 'name' => $value ['name'],
  6297. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6298. ) );
  6299. $sum += $train [$ta];
  6300. $trainSum += $train [$ta];
  6301. }
  6302. $ta ++;
  6303. }
  6304. if ($value ['category'] == $this->OTHER) {
  6305. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6306. array_push ( $accountJson [$this->OTHER], array (
  6307. 'aid' => $value ['aid'],
  6308. 'name' => $value ['name'],
  6309. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6310. ) );
  6311. $sum += $other [$ot];
  6312. $otherSum += $other [$ot];
  6313. }
  6314. $ot ++;
  6315. }
  6316. }
  6317. $accountJson ['cSum'] = array (
  6318. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6319. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6320. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6321. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6322. );
  6323. // 报销单
  6324. $receipt->accountItem = json_encode ( $accountJson );
  6325. $receipt->staff = $this->staff [0] ['sid'];
  6326. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6327. $receipt->date = date ( "Y-m-d" );
  6328. $receipt->cid = $cid;
  6329. $receipt->status = 5;
  6330. // 修改审批流程加入角色
  6331. $receipt->verify = $verify;
  6332. $receipt->executeCopy = $executeDetail ['staff'];
  6333. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6334. $order = array (
  6335. "\r\n",
  6336. "\n",
  6337. "\r"
  6338. );
  6339. $replace = '<br/>';
  6340. $explanation = str_replace ( $order, $replace, $explanation );
  6341. $receipt->explanation = $explanation;
  6342. $receipt->remittanceName = $remittanceName;
  6343. $receipt->bankName = $bankName;
  6344. $receipt->bankNumber = $bankNumber;
  6345. $receipt->remittanceBankType = $remittanceBankType;
  6346. if ($remittanceBankType == 1)
  6347. $receipt->coupletNumber = $coupletNumber;
  6348. $rid = $receipt->insert ();
  6349. // 附件
  6350. if (! empty ( $enclosurName )) {
  6351. $enclosurArray = explode ( '-', $enclosurName );
  6352. foreach ( $enclosurArray as $value ) {
  6353. $enclosur = new enclosur ();
  6354. $enclosur->name = $value;
  6355. $enclosur->rid = $rid;
  6356. $enclosur->insert ();
  6357. }
  6358. // print_r($enclosurArray);die;
  6359. }
  6360. // 报销详情
  6361. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6362. $receiptDetail = new receiptDetail ();
  6363. $receiptDetail->staff = $this->staff [0] ['sid'];
  6364. $receiptDetail->item = $value ['name'];
  6365. $receiptDetail->itemCategory = $this->AGENCY;
  6366. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6367. $receiptDetail->date = date ( "Y-m-d" );
  6368. $receiptDetail->cid = $cid;
  6369. $receiptDetail->rid = $rid;
  6370. $receiptDetail->status = 4;
  6371. $receiptDetail->insert ();
  6372. }
  6373. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6374. $receiptDetail = new receiptDetail ();
  6375. $receiptDetail->staff = $this->staff [0] ['sid'];
  6376. $receiptDetail->item = $value ['name'];
  6377. $receiptDetail->itemCategory = $this->TRAVEL;
  6378. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6379. $receiptDetail->date = date ( "Y-m-d" );
  6380. $receiptDetail->cid = $cid;
  6381. $receiptDetail->rid = $rid;
  6382. $receiptDetail->status = 4;
  6383. $receiptDetail->insert ();
  6384. }
  6385. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6386. $receiptDetail = new receiptDetail ();
  6387. $receiptDetail->staff = $this->staff [0] ['sid'];
  6388. $receiptDetail->item = $value ['name'];
  6389. $receiptDetail->itemCategory = $this->TRAIN;
  6390. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6391. $receiptDetail->date = date ( "Y-m-d" );
  6392. $receiptDetail->cid = $cid;
  6393. $receiptDetail->rid = $rid;
  6394. $receiptDetail->status = 4;
  6395. $receiptDetail->insert ();
  6396. }
  6397. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6398. $receiptDetail = new receiptDetail ();
  6399. $receiptDetail->staff = $this->staff [0] ['sid'];
  6400. $receiptDetail->item = $value ['name'];
  6401. $receiptDetail->itemCategory = $this->OTHER;
  6402. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6403. $receiptDetail->date = date ( "Y-m-d" );
  6404. $receiptDetail->cid = $cid;
  6405. $receiptDetail->rid = $rid;
  6406. $receiptDetail->status = 4;
  6407. $receiptDetail->insert ();
  6408. }
  6409. return "/saeaBorad";
  6410. } else
  6411. die ( 'illegal request' );
  6412. }
  6413. function referReceipt() {
  6414. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6415. Doo::loadModel ( 'receipt' );
  6416. Doo::loadModel ( 'verify' );
  6417. $verify = new verify ();
  6418. $receipt = new receipt ();
  6419. Doo::loadModel ( 'L_category' );
  6420. $lCategory = new L_category ();
  6421. Doo::loadModel ( "role" );
  6422. $role = new role ();
  6423. $receiptDetail = $receipt->find ( array (
  6424. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6425. 'asArray' => true
  6426. ) );
  6427. if (empty ( $receiptDetail ))
  6428. return "/addReceipt";
  6429. foreach ( $receiptDetail as $key => $value ) {
  6430. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6431. $veList = $verify->getOne ( array (
  6432. 'where' => 'vid=' . $value ['verify'],
  6433. 'asArray' => true
  6434. ) );
  6435. $v = json_decode ( $veList ['staff'] );
  6436. array_push ( $v [0], $veList ['description'] );
  6437. foreach ( $v as $n => $m ) {
  6438. if ($m ['1'] == 'ROLE') {
  6439. $roleInfo = $role->getOne ( array (
  6440. 'where' => 'rid=' . $m [0],
  6441. 'asArray' => true
  6442. ) );
  6443. $v [$n] [1] = $roleInfo ['name'];
  6444. }
  6445. }
  6446. $receiptDetail [$key] ['staff'] = $v;
  6447. $category = $lCategory->getOne ( array (
  6448. 'where' => 'cid=' . $value ['cid'],
  6449. 'asArray' => true
  6450. ) );
  6451. $receiptDetail [$key] ['category'] = $category ['title'];
  6452. }
  6453. // print_r($receiptDetail);
  6454. $data ['receiptDetail'] = $receiptDetail;
  6455. $data ['memu'] = "receipt";
  6456. $data ['staff'] = $this->staff;
  6457. $data ['receiptMemu'] = 'saeaCreate';
  6458. $data ['verifyId'] = $this->verifyId;
  6459. $data ['executeId'] = $this->executeId;
  6460. $this->render ( "/admin/saea_confirm", $data );
  6461. }
  6462. function editReceipt() {
  6463. // edit status 4
  6464. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6465. Doo::loadClass ( 'XDeode' );
  6466. $XDeode = new XDeode ( 7 );
  6467. $rid = $XDeode->decode ( $ridKey );
  6468. if (empty ( $rid ))
  6469. die ( 'illegal request' );
  6470. // echo $rid.'sd';
  6471. Doo::loadModel ( 'accountItem' );
  6472. Doo::loadModel ( 'verify' );
  6473. Doo::loadModel ( 'receipt' );
  6474. $receipt = new receipt ();
  6475. $verify = new verify ();
  6476. $accountItem = new accountItem ();
  6477. Doo::loadModel ( 'L_category' );
  6478. $lCategory = new L_category ();
  6479. Doo::loadModel ( "role" );
  6480. $role = new role ();
  6481. Doo::loadModel ( 'enclosur' );
  6482. $enclosur = new enclosur ();
  6483. $receiptDetail = $receipt->getOne ( array (
  6484. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6485. 'asArray' => true
  6486. ) );
  6487. if (empty ( $receiptDetail ))
  6488. die ( 'illegal request' );
  6489. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6490. $acItem = $accountItem->find ( array (
  6491. 'asArray' => true
  6492. ) );
  6493. $veList = $verify->find ( array (
  6494. 'asArray' => true
  6495. ) );
  6496. foreach ( $veList as $key => $value ) {
  6497. $v = json_decode ( $value ['staff'] );
  6498. $list = array ();
  6499. foreach ( $v as $n => $m ) {
  6500. if ($m ['1'] == 'ROLE') {
  6501. $roleInfo = $role->getOne ( array (
  6502. 'where' => 'rid=' . $m [0],
  6503. 'asArray' => true
  6504. ) );
  6505. $v [$n] [1] = $roleInfo ['name'];
  6506. array_push ( $list, $roleInfo ['name'] );
  6507. } else {
  6508. array_push ( $list, $v [$n] [1] );
  6509. }
  6510. }
  6511. $veList [$key] ['staff'] = implode ( '>', $list );
  6512. }
  6513. // 配置编辑信息
  6514. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6515. foreach ( $acItem as $key => $value ) {
  6516. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6517. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6518. $acItem [$key] ['price'] = $v ['price'];
  6519. }
  6520. }
  6521. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6522. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6523. $acItem [$key] ['price'] = $v ['price'];
  6524. }
  6525. }
  6526. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6527. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6528. $acItem [$key] ['price'] = $v ['price'];
  6529. }
  6530. }
  6531. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6532. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6533. $acItem [$key] ['price'] = $v ['price'];
  6534. }
  6535. }
  6536. }
  6537. $data ['category'] = $lCategory->find ( array (
  6538. 'asArray' => true
  6539. ) );
  6540. $data ['cSum'] = $accountItemList ['cSum'];
  6541. $data ['sum'] = $receiptDetail ['sum'];
  6542. $data ['enclosurList'] = $enclosurList;
  6543. $data ['receiptDetail'] = $receiptDetail;
  6544. $data ['veList'] = $veList;
  6545. $data ['acItem'] = $acItem;
  6546. $data ['memu'] = "receipt";
  6547. $data ['staff'] = $this->staff;
  6548. $data ['receiptMemu'] = 'saeaBorad';
  6549. $data ['verify'] = $receiptDetail ['verify'];
  6550. $data ['verifyId'] = $this->verifyId;
  6551. $data ['executeId'] = $this->executeId;
  6552. $data ['rid'] = $ridKey;
  6553. $this->render ( "/admin/saea_edit", $data );
  6554. }
  6555. function updateReceipt() {
  6556. $agency = $this->get_args ( 'agency' );
  6557. $travel = $this->get_args ( 'travel' );
  6558. $train = $this->get_args ( 'train' );
  6559. $other = $this->get_args ( 'other' );
  6560. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6561. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6562. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6563. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6564. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6565. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6566. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6567. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6568. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6569. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6570. Doo::loadClass ( 'XDeode' );
  6571. $XDeode = new XDeode ( 7 );
  6572. $rid = $XDeode->decode ( $ridKey );
  6573. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6574. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6575. header ( 'Content-Type:text/html;charset=utf-8' );
  6576. die ( '请填写联行号' );
  6577. }
  6578. Doo::loadModel ( 'receipt' );
  6579. Doo::loadModel ( 'receiptDetail' );
  6580. Doo::loadModel ( 'accountItem' );
  6581. $accountItem = new accountItem ();
  6582. $receipt = new receipt ();
  6583. Doo::loadModel ( 'enclosur' );
  6584. Doo::loadModel ( 'execute' );
  6585. $execute = new execute ();
  6586. $receiptDetail = $receipt->getOne ( array (
  6587. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6588. 'asArray' => true
  6589. ) );
  6590. if (empty ( $receiptDetail ))
  6591. return "/saeaBorad";
  6592. if ($receiptDetail ['Rtype'] == 1)
  6593. $executeDetail = $execute->getOne ( array (
  6594. 'where' => 'mold="借款费用执行人"',
  6595. 'asArray' => true
  6596. ) );
  6597. else
  6598. $executeDetail = $execute->getOne ( array (
  6599. 'where' => 'mold="报销单执行人"',
  6600. 'asArray' => true
  6601. ) );
  6602. $aItem = $accountItem->find ( array (
  6603. 'asArray' => true
  6604. ) );
  6605. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6606. $ag = $tr = $ta = $ot = 0;
  6607. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  6608. foreach ( $aItem as $key => $value ) {
  6609. if ($value ['category'] == $this->AGENCY) {
  6610. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6611. array_push ( $accountJson [$this->AGENCY], array (
  6612. 'aid' => $value ['aid'],
  6613. 'name' => $value ['name'],
  6614. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6615. ) );
  6616. $sum += $agency [$ag];
  6617. $agencySum += $agency [$ag];
  6618. }
  6619. $ag ++;
  6620. }
  6621. if ($value ['category'] == $this->TRAVEL) {
  6622. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6623. array_push ( $accountJson [$this->TRAVEL], array (
  6624. 'aid' => $value ['aid'],
  6625. 'name' => $value ['name'],
  6626. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6627. ) );
  6628. $sum += $travel [$tr];
  6629. $travelSum += $travel [$tr];
  6630. }
  6631. $tr ++;
  6632. }
  6633. if ($value ['category'] == $this->TRAIN) {
  6634. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6635. array_push ( $accountJson [$this->TRAIN], array (
  6636. 'aid' => $value ['aid'],
  6637. 'name' => $value ['name'],
  6638. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6639. ) );
  6640. $sum += $train [$ta];
  6641. $trainSum += $train [$ta];
  6642. }
  6643. $ta ++;
  6644. }
  6645. if ($value ['category'] == $this->OTHER) {
  6646. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6647. array_push ( $accountJson [$this->OTHER], array (
  6648. 'aid' => $value ['aid'],
  6649. 'name' => $value ['name'],
  6650. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6651. ) );
  6652. $sum += $other [$ot];
  6653. $otherSum += $other [$ot];
  6654. }
  6655. $ot ++;
  6656. }
  6657. }
  6658. $accountJson ['cSum'] = array (
  6659. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6660. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6661. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6662. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6663. );
  6664. // 报销单
  6665. $rid = $receipt->rid = $receiptDetail ['rid'];
  6666. $receipt->accountItem = json_encode ( $accountJson );
  6667. $receipt->staff = $this->staff [0] ['sid'];
  6668. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6669. $receipt->date = date ( "Y-m-d" );
  6670. $receipt->cid = $cid;
  6671. if (($receiptDetail ['status'] != 4)) {
  6672. if ($receiptDetail ['Rtype'] == 1)
  6673. $receipt->status = 7;
  6674. else
  6675. $receipt->status = 5;
  6676. }
  6677. if ($receiptDetail != 4 && ! empty ( $verify ))
  6678. $receipt->verify = $verify;
  6679. $receipt->executeCopy = $executeDetail ['staff'];
  6680. $order = array (
  6681. "\r\n",
  6682. "\n",
  6683. "\r"
  6684. );
  6685. $replace = '<br/>';
  6686. $explanation = str_replace ( $order, $replace, $explanation );
  6687. $receipt->explanation = $explanation;
  6688. $receipt->remittanceName = $remittanceName;
  6689. $receipt->bankName = $bankName;
  6690. $receipt->bankNumber = $bankNumber;
  6691. $receipt->remittanceBankType = $remittanceBankType;
  6692. if ($remittanceBankType == 1)
  6693. $receipt->coupletNumber = $coupletNumber;
  6694. $receipt->update ();
  6695. $receiptDetail = new receiptDetail ();
  6696. $receiptDetail->delete ( array (
  6697. 'where' => 'rid=' . $rid
  6698. ) );
  6699. // 报销详情
  6700. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6701. $receiptDetail = new receiptDetail ();
  6702. $receiptDetail->staff = $this->staff [0] ['sid'];
  6703. $receiptDetail->item = $value ['name'];
  6704. $receiptDetail->itemCategory = $this->AGENCY;
  6705. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6706. $receiptDetail->date = date ( "Y-m-d" );
  6707. $receiptDetail->cid = $cid;
  6708. $receiptDetail->rid = $rid;
  6709. $receiptDetail->status = 4;
  6710. $receiptDetail->insert ();
  6711. }
  6712. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6713. $receiptDetail = new receiptDetail ();
  6714. $receiptDetail->staff = $this->staff [0] ['sid'];
  6715. $receiptDetail->item = $value ['name'];
  6716. $receiptDetail->itemCategory = $this->TRAVEL;
  6717. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6718. $receiptDetail->date = date ( "Y-m-d" );
  6719. $receiptDetail->cid = $cid;
  6720. $receiptDetail->rid = $rid;
  6721. $receiptDetail->status = 4;
  6722. $receiptDetail->insert ();
  6723. }
  6724. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6725. $receiptDetail = new receiptDetail ();
  6726. $receiptDetail->staff = $this->staff [0] ['sid'];
  6727. $receiptDetail->item = $value ['name'];
  6728. $receiptDetail->itemCategory = $this->TRAIN;
  6729. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6730. $receiptDetail->date = date ( "Y-m-d" );
  6731. $receiptDetail->cid = $cid;
  6732. $receiptDetail->rid = $rid;
  6733. $receiptDetail->status = 4;
  6734. $receiptDetail->insert ();
  6735. }
  6736. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6737. $receiptDetail = new receiptDetail ();
  6738. $receiptDetail->staff = $this->staff [0] ['sid'];
  6739. $receiptDetail->item = $value ['name'];
  6740. $receiptDetail->itemCategory = $this->OTHER;
  6741. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6742. $receiptDetail->date = date ( "Y-m-d" );
  6743. $receiptDetail->cid = $cid;
  6744. $receiptDetail->rid = $rid;
  6745. $receiptDetail->status = 4;
  6746. $receiptDetail->insert ();
  6747. }
  6748. // 附件
  6749. if (! empty ( $enclosurName )) {
  6750. $enclosurArray = explode ( '-', $enclosurName );
  6751. foreach ( $enclosurArray as $value ) {
  6752. $enclosur = new enclosur ();
  6753. $enclosur->name = $value;
  6754. $enclosur->rid = $rid;
  6755. $enclosur->insert ();
  6756. }
  6757. }
  6758. // return "/referReceipt/".$rid;
  6759. }
  6760. return "/saeaBorad";
  6761. }
  6762. function approvedReceipt() {
  6763. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6764. Doo::loadModel ( 'receipt' );
  6765. Doo::loadModel ( 'receiptDetail' );
  6766. $receipt = new receipt ();
  6767. $receiptDetail = new receiptDetail ();
  6768. Doo::loadModel ( 'statistics' );
  6769. Doo::loadModel ( 'itemStatistics' );
  6770. $statistics = new statistics ();
  6771. $itemStatistics = new itemStatistics ();
  6772. Doo::loadModel ( "verify" );
  6773. $verify = new verify ();
  6774. // 审批状态的判定
  6775. $receiptDetailList = $receipt->getOne ( array (
  6776. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  6777. 'asArray' => true
  6778. ) );
  6779. if (empty ( $receiptDetailList ))
  6780. return "/saeaBorad";
  6781. $verifyDetail = $verify->getOne ( array (
  6782. 'where' => ' vid =' . $receiptDetailList ['verify'],
  6783. 'asArray' => true
  6784. ) );
  6785. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  6786. if (empty ( $receiptDetailList ['nowStaff'] )) {
  6787. $nowStaff = "";
  6788. $nowStaffList = array ();
  6789. if ($verifyDetail [0] [1] == 'ROLE') {
  6790. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  6791. foreach ( $vStaffString as $key => $value ) {
  6792. $staffK = explode ( "_", $value );
  6793. array_push ( $nowStaffList, $staffK [0] );
  6794. }
  6795. $nowStaff = implode ( ',', $nowStaffList );
  6796. } else {
  6797. $nowStaff = $verifyDetail [0] [0];
  6798. }
  6799. $receipt->nowStaff = $nowStaff;
  6800. }
  6801. // echo $nowStaff;
  6802. // print_r($verifyDetail);die;
  6803. $receipt->rid = $receiptDetailList ['rid'];
  6804. $receipt->date = date ( "Y-m-d" );
  6805. $receipt->status = 2;
  6806. $receipt->update ();
  6807. $receiptDetail->status = 2;
  6808. $receiptDetail->update ( array (
  6809. 'where' => 'rid=' . $receiptDetailList ['rid']
  6810. ) );
  6811. Doo::loadModel ( "receiptLog" );
  6812. $receiptLog = new receiptLog ();
  6813. Doo::loadModel ( "verify" );
  6814. $verify = new verify ();
  6815. $receiptInfo = $receipt->getOne ( array (
  6816. 'where' => 'rid=' . $rid,
  6817. 'asArray' => true
  6818. ) );
  6819. $vr = $verify->getOne ( array (
  6820. 'where' => 'vid=' . $receiptInfo ['verify'],
  6821. 'asArray' => true
  6822. ) );
  6823. $jd = json_decode ( $vr ['staff'] );
  6824. $roleId = 0;
  6825. foreach ( $jd as $key => $value ) {
  6826. if ($value [1] == 'ROLE') {
  6827. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  6828. if ($pos !== false) {
  6829. $roleId = $value [0];
  6830. }
  6831. }
  6832. }
  6833. // 审批日志
  6834. // echo $roleId;die;
  6835. if (! empty ( $roleId )) {
  6836. Doo::loadModel ( "role" );
  6837. $role = new role ();
  6838. $roleInfo = $role->getOne ( array (
  6839. 'where' => 'rid=' . $roleId,
  6840. 'asArray' => true
  6841. ) );
  6842. // $receiptLog->rolename = $roleInfo ['name'];
  6843. }
  6844. $receiptLog->username = $this->staff [0] ['username'];
  6845. $receiptLog->uid = $this->staff [0] ['sid'];
  6846. $receiptLog->date = date ( "Y-m-d" );
  6847. $receiptLog->opinion = '提交审批';
  6848. $receiptLog->img = $this->staff [0] ['avatar'];
  6849. $receiptLog->status = 2;
  6850. $receiptLog->rid = $rid;
  6851. $receiptLog->insert ();
  6852. // statistics item
  6853. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  6854. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  6855. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  6856. $stat = $statistics->getOne ( array (
  6857. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6858. 'asArray' => true
  6859. ) );
  6860. if (empty ( $stat )) {
  6861. $statistics->date = date ( "Y-m-d" );
  6862. $statistics->cid = $this->staff [0] ['cid'];
  6863. $statistics->staff = $this->staff [0] ['sid'];
  6864. $statistics->agPrice = 0;
  6865. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  6866. $statistics->insert ();
  6867. } else {
  6868. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  6869. $statistics->update ( array (
  6870. 'where' => 'sid=' . $stat ['sid']
  6871. ) );
  6872. }
  6873. return "/expenses";
  6874. }
  6875. function approval() {
  6876. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6877. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6878. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6879. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6880. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6881. if (empty ( $status ))
  6882. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6883. $vidList = array ();
  6884. $button = 0;
  6885. Doo::loadModel ( 'verify' );
  6886. $verify = new verify ();
  6887. Doo::loadModel ( 'receipt' );
  6888. $receipt = new receipt ();
  6889. Doo::loadModel ( 'staff' );
  6890. $staff = new staff ();
  6891. Doo::loadModel ( 'L_category' );
  6892. $Lcategory = new L_category ();
  6893. // user verify ID
  6894. $verifyDetail = $verify->find ( array (
  6895. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6896. 'asArray' => true
  6897. ) );
  6898. foreach ( $verifyDetail as $key => $value ) {
  6899. array_push ( $vidList, $value ['vid'] );
  6900. }
  6901. $vid = implode ( ",", $vidList );
  6902. if (empty ( $verifyDetail ))
  6903. $vid = 0;
  6904. /*
  6905. */
  6906. $dateCondition = " and Year(date) =" . $year;
  6907. if (! empty ( $month ))
  6908. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  6909. $categoryList = $Lcategory->find ( array (
  6910. 'asArray' => true
  6911. ) );
  6912. $staffList = $staff->find ( array (
  6913. 'where' => 'cid=' . $cid,
  6914. 'asArray' => true
  6915. ) );
  6916. $cateCondition = "";
  6917. $staffCondition = "";
  6918. $approvalCondition = "";
  6919. if (! empty ( $cid ))
  6920. $cateCondition = ' and cid=' . $cid;
  6921. if (! empty ( $sid )) {
  6922. $staffCondition = ' and staff=' . $sid;
  6923. $cateCondition = "";
  6924. }
  6925. // elseif($status==1){
  6926. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  6927. // }
  6928. if ($status == 2) {
  6929. // 查找角色审批人
  6930. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  6931. }
  6932. $ap = "";
  6933. if ($status == 4) {
  6934. $ap = 4;
  6935. $status = 2;
  6936. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  6937. }
  6938. if ($status == 5) {
  6939. $status = 4;
  6940. $ap = 5;
  6941. }
  6942. // echo $vid;
  6943. // get Receipt By verifyID status 2 .$approvalCondition
  6944. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  6945. $receiptList = $receipt->find ( array (
  6946. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  6947. 'desc' => 'rid',
  6948. 'asArray' => true
  6949. ) );
  6950. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  6951. $Locate = 0;
  6952. if ($ap == 4)
  6953. $status = 4;
  6954. elseif ($ap == 5)
  6955. $status = 5;
  6956. foreach ( $receiptList as $key => $value ) {
  6957. $receiptList [$key] ['Locate'] = $Locate;
  6958. $Locate ++;
  6959. $receiptList [$key] ['reviseDetail'] = array ();
  6960. if (! empty ( $value ['reviseDetail'] ))
  6961. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6962. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6963. $categoryDetil = $Lcategory->getOne ( array (
  6964. 'where' => 'cid=' . $value ['cid'],
  6965. 'asArray' => true
  6966. ) );
  6967. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6968. $verifyList = $verify->getOne ( array (
  6969. 'where' => 'vid=' . $value ['verify'],
  6970. 'asArray' => true
  6971. ) );
  6972. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6973. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6974. foreach ( $verifyList as $k => $v ) {
  6975. // init verifyStaff
  6976. $verifyList [$k] ['date'] = "";
  6977. $verifyList [$k] ['opinion'] = "";
  6978. $verifyList [$k] ['status'] = "";
  6979. if (empty ( $verifyStaff )) {
  6980. $verifyList [$k] ['date'] = "";
  6981. $verifyList [$k] ['opinion'] = "";
  6982. if ($v [0] == $this->staff [0] ['sid']) {
  6983. $verifyList [$k] ['status'] = 4;
  6984. $button = 4;
  6985. }
  6986. } else {
  6987. $flag = true;
  6988. foreach ( $verifyStaff as $m => $u ) {
  6989. if ($v [0] == $m) {
  6990. $verifyList [$k] ['date'] = $u ['date'];
  6991. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6992. $verifyList [$k] ['status'] = $u ['status'];
  6993. $flag = false;
  6994. break;
  6995. }
  6996. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  6997. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  6998. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  6999. }
  7000. if ($flag) { // 检测可编辑
  7001. if ($v [0] == $this->staff [0] ['sid']) {
  7002. $verifyList [$k] ['status'] = 4;
  7003. $button = 4;
  7004. }
  7005. }
  7006. }
  7007. }
  7008. $receiptList [$key] ['verifyList'] = $verifyList;
  7009. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7010. 'where' => 'sid=' . $value ['staff'],
  7011. 'asArray' => true
  7012. ) );
  7013. $receiptList [$key] ['button'] = $button;
  7014. }
  7015. // print_r($receiptList);die;
  7016. // $data['verifyDetail']=$verifyDetail;
  7017. $mothHtml = "";
  7018. for($i = 1; $i <= 12; $i ++) {
  7019. if ($month == $i)
  7020. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7021. else
  7022. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7023. }
  7024. $data ['mothHtml'] = $mothHtml;
  7025. $data ['receiptList'] = $receiptList;
  7026. $data ['receiptApprovalCount'] = count ( $receiptList );
  7027. $data ['status'] = $status;
  7028. $data ['year'] = $year;
  7029. $data ['categoryList'] = $categoryList;
  7030. $data ['staffList'] = $staffList;
  7031. $data ['cid'] = $cid;
  7032. $data ['sid'] = $sid;
  7033. $data ['ap'] = $ap;
  7034. $data ['memu'] = "receipt";
  7035. $data ['staff'] = $this->staff;
  7036. $data ['receiptMemu'] = 'approval';
  7037. $data ['verifyId'] = $this->verifyId;
  7038. $data ['executeId'] = $this->executeId;
  7039. $this->render ( "/admin/saea_reportList", $data );
  7040. }
  7041. function approvalDetails() {
  7042. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7043. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7044. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7045. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7046. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7047. Doo::loadModel ( 'verify' );
  7048. $verify = new verify ();
  7049. Doo::loadModel ( 'receipt' );
  7050. $receipt = new receipt ();
  7051. Doo::loadModel ( 'staff' );
  7052. $staff = new staff ();
  7053. Doo::loadModel ( 'L_category' );
  7054. $Lcategory = new L_category ();
  7055. Doo::loadModel ( 'enclosur' );
  7056. $enclosur = new enclosur ();
  7057. $vidList = array ();
  7058. $verifyDetail = $verify->find ( array (
  7059. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7060. 'asArray' => true
  7061. ) );
  7062. foreach ( $verifyDetail as $key => $value ) {
  7063. array_push ( $vidList, $value ['vid'] );
  7064. }
  7065. $vid = implode ( ",", $vidList );
  7066. if (empty ( $verifyDetail ))
  7067. $vid = 0;
  7068. $categoryList = $Lcategory->find ( array (
  7069. 'asArray' => true
  7070. ) );
  7071. $staffList = $staff->find ( array (
  7072. 'where' => 'cid=' . $cid,
  7073. 'asArray' => true
  7074. ) );
  7075. $ap = 0;
  7076. $receiptList = $receipt->find ( array (
  7077. 'where' => 'rid =' . $rid,
  7078. 'desc' => 'rid',
  7079. 'asArray' => true
  7080. ) );
  7081. $Locate = 0;
  7082. $roleId = 0;
  7083. $button = 0;
  7084. foreach ( $receiptList as $key => $value ) {
  7085. $receiptList [$key] ['Locate'] = $Locate;
  7086. $Locate ++;
  7087. $receiptList [$key] ['reviseDetail'] = array ();
  7088. if (! empty ( $value ['reviseDetail'] ))
  7089. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7090. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7091. $categoryDetil = $Lcategory->getOne ( array (
  7092. 'where' => 'cid=' . $value ['cid'],
  7093. 'asArray' => true
  7094. ) );
  7095. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7096. // 检测编辑状态
  7097. $verifyList = $verify->getOne ( array (
  7098. 'where' => 'vid=' . $value ['verify'],
  7099. 'asArray' => true
  7100. ) );
  7101. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7102. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7103. Doo::loadModel ( 'role' );
  7104. $role = new role ();
  7105. // print_r($verifyList);
  7106. $flag = true;
  7107. $roleKey = 0;
  7108. $endStaffArray = array ();
  7109. $roleArrayCopy = array ();
  7110. foreach ( $verifyList as $k => $v ) {
  7111. // init verifyStaff
  7112. if ($v [1] == 'ROLE') {
  7113. if (! empty ( $verifyStaff )) {
  7114. $endStaffArray = end ( $verifyStaff );
  7115. if ($v [0] == $endStaffArray ['nextStaff']) {
  7116. $roleId = $v [0];
  7117. }
  7118. }
  7119. $roleVerify = json_decode ( $v [3], true );
  7120. $roleKey = $k;
  7121. $roleArray = array ();
  7122. $rolename = $role->getOne ( array (
  7123. 'where' => 'rid=' . $v [0],
  7124. 'asArray' => true
  7125. ) );
  7126. foreach ( $roleVerify as $o => $p ) {
  7127. $staffID = explode ( '_', $p );
  7128. $staffInfo = $staff->getOne ( array (
  7129. 'where' => 'sid=' . $staffID [0],
  7130. 'asArray' => true
  7131. ) );
  7132. // print_r($staffID);
  7133. $exp = array (
  7134. 0 => $staffInfo ['sid'],
  7135. 1 => $staffID [1],
  7136. 2 => $staffInfo ['avatar'],
  7137. 'date' => '',
  7138. 'date' => '',
  7139. 'opinion' => '',
  7140. 'status' => '',
  7141. 'rolename' => $rolename ['name']
  7142. );
  7143. array_push ( $roleArray, $exp );
  7144. }
  7145. $roleArrayCopy [$v [0]] = $roleArray;
  7146. // $verifyList[$k]['roleArray']=$roleArray;
  7147. }
  7148. // print_r($roleArray);
  7149. $verifyList [$k] ['date'] = "";
  7150. $verifyList [$k] ['opinion'] = "";
  7151. $verifyList [$k] ['status'] = "";
  7152. if (empty ( $verifyStaff )) {
  7153. $verifyList [$k] ['date'] = "";
  7154. $verifyList [$k] ['opinion'] = "";
  7155. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7156. $verifyList [$k] ['status'] = 4;
  7157. $button = 4;
  7158. $flag = false;
  7159. }
  7160. } else {
  7161. foreach ( $verifyStaff as $m => $u ) {
  7162. if ($v [0] == $m) {
  7163. $verifyList [$k] ['date'] = $u ['date'];
  7164. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7165. $verifyList [$k] ['status'] = $u ['status'];
  7166. $flag = false;
  7167. break;
  7168. }
  7169. }
  7170. $endStaffArray = end ( $verifyStaff );
  7171. if (isset ( $endStaffArray ['ROLE'] )) {
  7172. } else {
  7173. $endKey = key ( $verifyStaff );
  7174. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7175. $button = 4;
  7176. $verifyList [$k] ['status'] = 4;
  7177. }
  7178. }
  7179. }
  7180. }
  7181. $rolename ['name'] = '';
  7182. if (! empty ( $roleId )) {
  7183. Doo::loadModel ( 'role' );
  7184. $role = new role ();
  7185. $rolename = $role->getOne ( array (
  7186. 'where' => 'rid=' . $roleId,
  7187. 'asArray' => true
  7188. ) );
  7189. }
  7190. if (! empty ( $verifyStaff ))
  7191. $endStaffArray = end ( $verifyStaff );
  7192. $KOP = false;
  7193. foreach ( $roleArrayCopy as $P => $A ) {
  7194. foreach ( $A as $MKI => $AVL ) {
  7195. if (! empty ( $verifyStaff )) {
  7196. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7197. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7198. $button = 4;
  7199. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7200. }
  7201. foreach ( $verifyStaff as $m => $u ) {
  7202. $AVLFK = $AVL [0] . '_R';
  7203. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7204. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7205. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7206. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7207. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7208. break;
  7209. }
  7210. }
  7211. } else {
  7212. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7213. $button = 4;
  7214. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7215. }
  7216. }
  7217. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7218. $KOP = true;
  7219. }
  7220. }
  7221. foreach ( $roleArrayCopy as $k => $v ) {
  7222. foreach ( $verifyList as $m => $n ) {
  7223. if ($n [0] == $k) {
  7224. array_splice ( $verifyList, $m, 1, $v );
  7225. }
  7226. }
  7227. }
  7228. $receiptList [$key] ['verifyList'] = $verifyList;
  7229. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7230. 'where' => 'sid=' . $value ['staff'],
  7231. 'asArray' => true
  7232. ) );
  7233. $receiptList [$key] ['button'] = $button;
  7234. }
  7235. $mothHtml = "";
  7236. for($i = 1; $i <= 12; $i ++) {
  7237. if ($month == $i)
  7238. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7239. else
  7240. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7241. }
  7242. // 获取审批日志
  7243. Doo::loadModel ( 'receiptLog' );
  7244. $receiptLog = new receiptLog ();
  7245. $rlList = array ();
  7246. $rlInfo = $receiptLog->getOne ( array (
  7247. 'where' => 'rid=' . $rid . ' and status=4',
  7248. 'asArray' => true
  7249. ) );
  7250. $tijdate = $receiptLog->getOne ( array (
  7251. 'where' => 'rid=' . $rid . ' and status=2',
  7252. 'asc' => 'rlid',
  7253. 'asArray' => true
  7254. ) );
  7255. if (! empty ( $rlInfo )) {
  7256. $rlList = $receiptLog->find ( array (
  7257. 'where' => 'rid=' . $rid,
  7258. 'asc' => 'rlid',
  7259. 'asArray' => true
  7260. ) );
  7261. }
  7262. $receiptList [0] ['rlList'] = $rlList;
  7263. $enclosurList = $enclosur->find ( array (
  7264. 'where' => 'rid=' . $rid,
  7265. 'asArray' => true
  7266. ) );
  7267. $enclosurHtml = '';
  7268. foreach ( $enclosurList as $value ) {
  7269. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7270. }
  7271. $data ['enclosurHtml'] = $enclosurHtml;
  7272. $data ['rolename'] = $rolename ['name'];
  7273. $data ['datetij'] = $tijdate ['date'];
  7274. $data ['mothHtml'] = $mothHtml;
  7275. $data ['receiptList'] = $receiptList;
  7276. $data ['receiptApprovalCount'] = count ( $receiptList );
  7277. $data ['year'] = $year;
  7278. $data ['categoryList'] = $categoryList;
  7279. $data ['staffList'] = $staffList;
  7280. $data ['cid'] = $cid;
  7281. $data ['sid'] = $sid;
  7282. $data ['status'] = 0;
  7283. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7284. $ap = 4;
  7285. } else
  7286. $data ['status'] = $receiptList [0] ['status'];
  7287. if ($receiptList [0] ['status'] == 4) {
  7288. $data ['status'] = 5;
  7289. $ap = 0;
  7290. }
  7291. $data ['ap'] = $ap;
  7292. $data ['memu'] = "receipt";
  7293. $data ['staff'] = $this->staff;
  7294. $data ['receiptMemu'] = 'approval';
  7295. $data ['verifyId'] = $this->verifyId;
  7296. $data ['executeId'] = $this->executeId;
  7297. $this->render ( "/admin/saeaReportListReport", $data );
  7298. }
  7299. function approvalEdi() {
  7300. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7301. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7302. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7303. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7304. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7305. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7306. if (empty ( $status ))
  7307. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7308. $vidList = array ();
  7309. $button = 0;
  7310. Doo::loadModel ( 'verify' );
  7311. Doo::loadModel ( 'receipt' );
  7312. Doo::loadModel ( 'staff' );
  7313. $staff = new staff ();
  7314. $receipt = new receipt ();
  7315. $verify = new verify ();
  7316. Doo::loadModel ( 'L_category' );
  7317. $Lcategory = new L_category ();
  7318. Doo::loadModel ( 'enclosur' );
  7319. $enclosur = new enclosur ();
  7320. // user verify ID
  7321. $verifyDetail = $verify->find ( array (
  7322. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7323. 'asArray' => true
  7324. ) );
  7325. foreach ( $verifyDetail as $key => $value ) {
  7326. array_push ( $vidList, $value ['vid'] );
  7327. }
  7328. $vid = implode ( ",", $vidList );
  7329. if (empty ( $verifyDetail ))
  7330. $vid = 0;
  7331. $categoryList = $Lcategory->find ( array (
  7332. 'asArray' => true
  7333. ) );
  7334. $staffList = $staff->find ( array (
  7335. 'where' => 'cid=' . $cid,
  7336. 'asArray' => true
  7337. ) );
  7338. $ap = "";
  7339. if ($status == 4) {
  7340. $ap = 4;
  7341. $status = 2;
  7342. }
  7343. // get Receipt By verifyID status 2
  7344. $receiptList = $receipt->find ( array (
  7345. 'where' => 'rid =' . $rid,
  7346. 'desc' => 'rid',
  7347. 'asArray' => true
  7348. ) );
  7349. $Locate = 0;
  7350. $roleId = 0;
  7351. if ($ap == 4)
  7352. $status = 4;
  7353. foreach ( $receiptList as $key => $value ) {
  7354. $receiptList [$key] ['Locate'] = $Locate;
  7355. $Locate ++;
  7356. $receiptList [$key] ['reviseDetail'] = array ();
  7357. if (! empty ( $value ['reviseDetail'] ))
  7358. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7359. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7360. $categoryDetil = $Lcategory->getOne ( array (
  7361. 'where' => 'cid=' . $value ['cid'],
  7362. 'asArray' => true
  7363. ) );
  7364. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7365. // 检测编辑状态
  7366. $verifyList = $verify->getOne ( array (
  7367. 'where' => 'vid=' . $value ['verify'],
  7368. 'asArray' => true
  7369. ) );
  7370. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7371. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7372. // print_r($verifyList);
  7373. //
  7374. // if (empty($verifyStaff)){
  7375. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7376. // $verifyList[0]['status']=4;$button=4;
  7377. // }
  7378. //
  7379. // }else{
  7380. //
  7381. // }
  7382. // die;
  7383. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7384. // echo array_search("green",$a);
  7385. //
  7386. Doo::loadModel ( 'role' );
  7387. $role = new role ();
  7388. // print_r($verifyList);
  7389. $flag = true;
  7390. $roleKey = 0;
  7391. $endStaffArray = array ();
  7392. $roleArrayCopy = array ();
  7393. foreach ( $verifyList as $k => $v ) {
  7394. // init verifyStaff
  7395. if ($v [1] == 'ROLE') {
  7396. if (! empty ( $verifyStaff )) {
  7397. $endStaffArray = end ( $verifyStaff );
  7398. if ($v [0] == $endStaffArray ['nextStaff']) {
  7399. $roleId = $v [0];
  7400. }
  7401. }
  7402. $roleVerify = json_decode ( $v [3], true );
  7403. $roleKey = $k;
  7404. $roleArray = array ();
  7405. $rolename = $role->getOne ( array (
  7406. 'where' => 'rid=' . $v [0],
  7407. 'asArray' => true
  7408. ) );
  7409. foreach ( $roleVerify as $o => $p ) {
  7410. $staffID = explode ( '_', $p );
  7411. $staffInfo = $staff->getOne ( array (
  7412. 'where' => 'sid=' . $staffID [0],
  7413. 'asArray' => true
  7414. ) );
  7415. // print_r($staffID);
  7416. $exp = array (
  7417. 0 => $staffInfo ['sid'],
  7418. 1 => $staffID [1],
  7419. 2 => $staffInfo ['avatar'],
  7420. 'date' => '',
  7421. 'date' => '',
  7422. 'opinion' => '',
  7423. 'status' => '',
  7424. 'rolename' => $rolename ['name']
  7425. );
  7426. array_push ( $roleArray, $exp );
  7427. }
  7428. $roleArrayCopy [$v [0]] = $roleArray;
  7429. // $verifyList[$k]['roleArray']=$roleArray;
  7430. }
  7431. // print_r($roleArray);
  7432. $verifyList [$k] ['date'] = "";
  7433. $verifyList [$k] ['opinion'] = "";
  7434. $verifyList [$k] ['status'] = "";
  7435. if (empty ( $verifyStaff )) {
  7436. $verifyList [$k] ['date'] = "";
  7437. $verifyList [$k] ['opinion'] = "";
  7438. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7439. $verifyList [$k] ['status'] = 4;
  7440. $button = 4;
  7441. $flag = false;
  7442. }
  7443. } else {
  7444. foreach ( $verifyStaff as $m => $u ) {
  7445. if ($v [0] == $m) {
  7446. $verifyList [$k] ['date'] = $u ['date'];
  7447. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7448. $verifyList [$k] ['status'] = $u ['status'];
  7449. $flag = false;
  7450. break;
  7451. }
  7452. }
  7453. $endStaffArray = end ( $verifyStaff );
  7454. if (isset ( $endStaffArray ['ROLE'] )) {
  7455. } else {
  7456. $endKey = key ( $verifyStaff );
  7457. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7458. $button = 4;
  7459. $verifyList [$k] ['status'] = 4;
  7460. }
  7461. }
  7462. // print_r($endStaffArray);die;
  7463. // if (empty($verifyStaff)){
  7464. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7465. // $verifyList[$k]['status']=4;$button=4;
  7466. // }
  7467. //
  7468. // }else{
  7469. //
  7470. // }
  7471. // if($flag){//检测可编辑
  7472. // if($v[0]==$this->staff[0]['sid']){
  7473. // $verifyList[$k]['status']=4;$button=4;
  7474. // }
  7475. // }
  7476. }
  7477. }
  7478. $rolename ['name'] = '';
  7479. if (! empty ( $roleId )) {
  7480. Doo::loadModel ( 'role' );
  7481. $role = new role ();
  7482. $rolename = $role->getOne ( array (
  7483. 'where' => 'rid=' . $roleId,
  7484. 'asArray' => true
  7485. ) );
  7486. }
  7487. if (! empty ( $verifyStaff ))
  7488. $endStaffArray = end ( $verifyStaff );
  7489. $KOP = false;
  7490. foreach ( $roleArrayCopy as $P => $A ) {
  7491. foreach ( $A as $MKI => $AVL ) {
  7492. if (! empty ( $verifyStaff )) {
  7493. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7494. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7495. $button = 4;
  7496. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7497. }
  7498. foreach ( $verifyStaff as $m => $u ) {
  7499. $AVLFK = $AVL [0] . '_R';
  7500. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7501. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7502. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7503. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7504. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7505. break;
  7506. }
  7507. }
  7508. } else {
  7509. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7510. $button = 4;
  7511. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7512. }
  7513. }
  7514. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7515. $KOP = true;
  7516. }
  7517. }
  7518. // print_r($roleArrayCopy);
  7519. // echo $roleKey;
  7520. foreach ( $roleArrayCopy as $k => $v ) {
  7521. foreach ( $verifyList as $m => $n ) {
  7522. if ($n [0] == $k) {
  7523. array_splice ( $verifyList, $m, 1, $v );
  7524. }
  7525. }
  7526. }
  7527. // if ($KOP)
  7528. // array_splice($verifyList,$roleKey,1,$roleArray);
  7529. // print_r($verifyList);
  7530. $receiptList [$key] ['verifyList'] = $verifyList;
  7531. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7532. 'where' => 'sid=' . $value ['staff'],
  7533. 'asArray' => true
  7534. ) );
  7535. $receiptList [$key] ['button'] = $button;
  7536. }
  7537. // $data['verifyDetail']=$verifyDetail;
  7538. $mothHtml = "";
  7539. for($i = 1; $i <= 12; $i ++) {
  7540. if ($month == $i)
  7541. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7542. else
  7543. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7544. }
  7545. // 获取审批日志
  7546. Doo::loadModel ( 'receiptLog' );
  7547. $receiptLog = new receiptLog ();
  7548. $rlList = array ();
  7549. $rlInfo = $receiptLog->getOne ( array (
  7550. 'where' => 'rid=' . $rid . ' and status=4',
  7551. 'asArray' => true
  7552. ) );
  7553. $tijdate = $receiptLog->getOne ( array (
  7554. 'where' => 'rid=' . $rid . ' and status=2',
  7555. 'asc' => 'rlid',
  7556. 'asArray' => true
  7557. ) );
  7558. if (! empty ( $rlInfo )) {
  7559. $rlList = $receiptLog->find ( array (
  7560. 'where' => 'rid=' . $rid,
  7561. 'asc' => 'rlid',
  7562. 'asArray' => true
  7563. ) );
  7564. }
  7565. $receiptList [0] ['rlList'] = $rlList;
  7566. $enclosurList = $enclosur->find ( array (
  7567. 'where' => 'rid=' . $rid,
  7568. 'asArray' => true
  7569. ) );
  7570. $enclosurHtml = '';
  7571. foreach ( $enclosurList as $value ) {
  7572. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7573. }
  7574. $data ['enclosurHtml'] = $enclosurHtml;
  7575. $data ['rolename'] = $rolename ['name'];
  7576. $data ['datetij'] = $tijdate ['date'];
  7577. $data ['mothHtml'] = $mothHtml;
  7578. $data ['receiptList'] = $receiptList;
  7579. $data ['receiptApprovalCount'] = count ( $receiptList );
  7580. $data ['status'] = $status;
  7581. $data ['year'] = $year;
  7582. $data ['categoryList'] = $categoryList;
  7583. $data ['staffList'] = $staffList;
  7584. $data ['cid'] = $cid;
  7585. $data ['sid'] = $sid;
  7586. $data ['ap'] = $ap;
  7587. $data ['memu'] = "receipt";
  7588. $data ['staff'] = $this->staff;
  7589. $data ['receiptMemu'] = 'approval';
  7590. $data ['verifyId'] = $this->verifyId;
  7591. $data ['executeId'] = $this->executeId;
  7592. $this->render ( "/admin/saeaReportListReport", $data );
  7593. }
  7594. function remittanceHky() {
  7595. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7596. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7597. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7598. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7599. $page_size = 15;
  7600. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7601. Doo::loadModel ( 'receipt' );
  7602. $receipt = new receipt ();
  7603. Doo::loadModel ( 'staff' );
  7604. $staff = new staff ();
  7605. $dateCondition = " and Year(executeDate) =" . $year;
  7606. if ($moth != 'MONTH')
  7607. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7608. if ($day != 'DAY' && $moth != 'MONTH')
  7609. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7610. $sql = ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition;
  7611. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7612. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7613. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7614. $dayList = $receipt->find ( array (
  7615. 'select' => 'executeDate,sum(amount) as amount',
  7616. 'where' => $sql,
  7617. 'desc' => 'executeDate',
  7618. 'groupby' => 'executeDate',
  7619. 'limit' => $limit,
  7620. 'asArray' => true
  7621. ) );
  7622. // print_r($dayList);
  7623. foreach ( $dayList as $key => $value ) {
  7624. $remitString = "";
  7625. $receiptList = $receipt->find ( array (
  7626. 'select' => 'rid,executeDate,amount,staff,cid',
  7627. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7628. 'desc' => 'executeDate',
  7629. 'asArray' => true
  7630. ) );
  7631. foreach ( $receiptList as $k => $v ) {
  7632. $sinfo = $staff->getOne ( array (
  7633. 'select' => 'username,category',
  7634. 'where' => ' sid=' . $v ['staff'],
  7635. 'asArray' => true
  7636. ) );
  7637. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7638. }
  7639. $dayList [$key] ['staff'] = $remitString;
  7640. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7641. }
  7642. // print_r($dayList);
  7643. $mothHtml = "";
  7644. for($i = 1; $i <= 12; $i ++) {
  7645. if ($moth == $i)
  7646. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7647. else
  7648. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7649. }
  7650. $dayHtml = "";
  7651. if ($day != "DAY" || $moth != "MONTH") {
  7652. for($i = 1; $i <= 31; $i ++) {
  7653. if ($day == $i)
  7654. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7655. else
  7656. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7657. }
  7658. }
  7659. $dateHtml = "";
  7660. $now = date ( "Y" );
  7661. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7662. if ($YEARD <= $now) {
  7663. $dateHtml .= '<option ';
  7664. if ($year == $YEARD) {
  7665. $dateHtml .= 'selected ';
  7666. }
  7667. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7668. }
  7669. }
  7670. $data ['dateHtml'] = $dateHtml;
  7671. $data ['page'] = $pageinfo;
  7672. $data ['year'] = $year;
  7673. $data ['moth'] = $moth;
  7674. $data ['day'] = $day;
  7675. $data ['get'] = $get;
  7676. $data ['dayHtml'] = $dayHtml;
  7677. $data ['mothHtml'] = $mothHtml;
  7678. $data ['receiptList'] = $dayList;
  7679. $data ['memu'] = "receipt";
  7680. $data ['staff'] = $this->staff;
  7681. $data ['receiptMemu'] = 'remittanceHky';
  7682. $data ['verifyId'] = $this->verifyId;
  7683. $data ['executeId'] = $this->executeId;
  7684. $this->render ( "/admin/remittanceHky", $data );
  7685. }
  7686. function remittancep() {
  7687. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7688. Doo::loadModel ( 'receipt' );
  7689. $receipt = new receipt ();
  7690. Doo::loadModel ( 'staff' );
  7691. $staff = new staff ();
  7692. Doo::loadClass ( 'XDeode' );
  7693. $XDeode = new XDeode ( 5 );
  7694. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7695. $rplist = $receipt->find ( array (
  7696. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7697. 'asArray' => true
  7698. ) );
  7699. $dayList = $receipt->find ( array (
  7700. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7701. 'desc' => 'executeDate',
  7702. 'groupby' => 'staff',
  7703. 'asArray' => true
  7704. ) );
  7705. $html = '';
  7706. foreach ( $dayList as $key => $value ) {
  7707. $sinfo = $staff->getOne ( array (
  7708. 'select' => 'username,category',
  7709. 'where' => ' sid=' . $value ['staff'],
  7710. 'asArray' => true
  7711. ) );
  7712. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  7713. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  7714. $au = 0;
  7715. foreach ( $rplist as $k => $v ) {
  7716. if ($value ['staff'] == $v ['staff']) {
  7717. $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>';
  7718. $au += $v ['amount'];
  7719. }
  7720. }
  7721. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  7722. }
  7723. $data ['html'] = $html;
  7724. $data ['memu'] = "receipt";
  7725. $data ['staff'] = $this->staff;
  7726. $data ['receiptMemu'] = 'remittanceHky';
  7727. $data ['verifyId'] = $this->verifyId;
  7728. $data ['executeId'] = $this->executeId;
  7729. $this->render ( "/admin/remittancep", $data );
  7730. }
  7731. function ajaxGetReceiptDetails() {
  7732. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  7733. Doo::loadClass ( 'XDeode' );
  7734. $XDeode = new XDeode ( 5 );
  7735. $rid = $XDeode->decode ( $rid );
  7736. if (empty ( $rid )) {
  7737. echo json_encode ( array (
  7738. 'status' => 2,
  7739. 'msg' => 'illegal request'
  7740. ) );
  7741. die ();
  7742. }
  7743. Doo::loadModel ( 'receipt' );
  7744. $receipt = new receipt ();
  7745. Doo::loadModel ( 'staff' );
  7746. $staff = new staff ();
  7747. $rinfo = $receipt->getOne ( array (
  7748. 'where' => 'rid= ' . $rid,
  7749. 'asArray' => true
  7750. ) );
  7751. $sinfo = $staff->getOne ( array (
  7752. 'select' => 'username,category',
  7753. 'where' => ' sid=' . $rinfo ['staff'],
  7754. 'asArray' => true
  7755. ) );
  7756. $rinfo ['reviseDetail'] = array ();
  7757. if (! empty ( $rinfo ['reviseDetail'] ))
  7758. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  7759. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  7760. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  7761. $rinfo ['category'] = $sinfo ['category'];
  7762. $verifyStaff = array ();
  7763. if (! empty ( $rinfo ['verifyStaff'] ))
  7764. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  7765. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  7766. $rinfo ['relust'] = $relust;
  7767. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  7768. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  7769. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  7770. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  7771. // 费用执行人相关数据
  7772. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  7773. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  7774. foreach ( $executeCopy as $k => $v ) {
  7775. $executeCopy [$k] ['date'] = '';
  7776. $executeCopy [$k] ['opinion'] = '';
  7777. $executeCopy [$k] ['status'] = '';
  7778. if (! empty ( $executeStaff ))
  7779. foreach ( $executeStaff as $m => $u ) {
  7780. if ($v [0] == $m) {
  7781. $executeCopy [$k] ['date'] = $u ['date'];
  7782. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  7783. $executeCopy [$k] ['status'] = $u ['status'];
  7784. break;
  7785. }
  7786. }
  7787. }
  7788. $rinfo ['executeCopy'] = $executeCopy;
  7789. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  7790. if ($rinfo ['Rtype'] == 1) { // 借款费用
  7791. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  7792. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  7793. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  7794. $html .= '<tr><th>' . $value ['name'] . '</th>
  7795. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7796. }
  7797. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  7798. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  7799. <tr><th class="taC" colspan="2">费用说明</th>
  7800. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  7801. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  7802. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  7803. </tbody></table>';
  7804. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  7805. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  7806. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  7807. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  7808. $html .= '<tr><th>' . $value ['name'] . '</th>
  7809. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7810. }
  7811. $html .= '<tr><th class="taR">合计</th>
  7812. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  7813. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  7814. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  7815. $html .= '<tr><th>' . $value ['name'] . '</th>
  7816. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7817. }
  7818. $html .= '<tr><th class="taR">合计</th>
  7819. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  7820. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  7821. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  7822. $html .= '<tr><th>' . $value ['name'] . '</th>
  7823. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7824. }
  7825. $html .= '<tr><th class="taR">合计</th>
  7826. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  7827. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  7828. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  7829. $html .= '<tr><th>' . $value ['name'] . '</th>
  7830. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7831. }
  7832. $html .= '<tr><th class="taR">合计</th>
  7833. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  7834. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  7835. foreach ( $rinfo ['reviseDetail'] as $value ) {
  7836. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  7837. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  7838. }
  7839. $html .= '<tr><th class="taR">合计</th>
  7840. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  7841. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  7842. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  7843. <tr><th class="taC" colspan="2">报销说明</th></tr>
  7844. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  7845. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  7846. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  7847. <tr';
  7848. if ($rinfo ['relust'] >= 0) {
  7849. $html .= 'class="success"';
  7850. } else {
  7851. $html .= 'class="error"';
  7852. }
  7853. $html .= '><td class="taR"><b>借款结余</b></td>
  7854. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  7855. </tbody></table>
  7856. ';
  7857. }
  7858. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  7859. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  7860. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  7861. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  7862. $html .= '<tr><th>' . $value ['name'] . '</th>
  7863. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7864. }
  7865. $html .= '<tr><th class="taR">合计</th>
  7866. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  7867. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  7868. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  7869. <tr><th class="taC" colspan="2">费用说明</th>
  7870. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  7871. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  7872. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  7873. </tbody></table>';
  7874. } else {
  7875. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  7876. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  7877. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  7878. $html .= '<tr><th>' . $value ['name'] . '</th>
  7879. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7880. }
  7881. $html .= '<tr><th class="taR">合计</th>
  7882. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  7883. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  7884. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  7885. $html .= '<tr><th>' . $value ['name'] . '</th>
  7886. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7887. }
  7888. $html .= '<tr><th class="taR">合计</th>
  7889. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  7890. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  7891. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  7892. $html .= '<tr><th>' . $value ['name'] . '</th>
  7893. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7894. }
  7895. $html .= '<tr><th class="taR">合计</th>
  7896. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  7897. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  7898. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  7899. $html .= '<tr><th>' . $value ['name'] . '</th>
  7900. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  7901. }
  7902. $html .= '<tr><th class="taR">合计</th>
  7903. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  7904. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  7905. foreach ( $rinfo ['reviseDetail'] as $value ) {
  7906. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  7907. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  7908. }
  7909. $html .= '<tr><th class="taR">合计</th>
  7910. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  7911. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  7912. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  7913. <tr><th class="taC" colspan="2">报销说明</th></tr>
  7914. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  7915. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  7916. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  7917. $html .= '</tbody></table>';
  7918. /*
  7919. * <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>
  7920. */
  7921. }
  7922. // print_r($verifyStaff);die;
  7923. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  7924. foreach ( $verifyStaff as $key => $value ) {
  7925. $key = trim ( strtr ( $key, '_R', ' ' ) );
  7926. $sinfo = $staff->getOne ( array (
  7927. 'select' => 'username',
  7928. 'where' => ' sid=' . $key,
  7929. 'asArray' => true
  7930. ) );
  7931. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  7932. }
  7933. $html .= '</tbody></table>';
  7934. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  7935. foreach ( $rinfo ['executeCopy'] as $value ) {
  7936. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  7937. }
  7938. $html .= '</tbody></table>';
  7939. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  7940. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  7941. </tr></table>';
  7942. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  7943. echo json_encode ( array (
  7944. 'status' => 1,
  7945. 'html' => $html
  7946. ) );
  7947. die ();
  7948. }
  7949. /**
  7950. * 删除附件
  7951. */
  7952. function ajaxRemEnclousur() {
  7953. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  7954. if (empty ( $key ))
  7955. echo json_encode ( array (
  7956. 'status' => 2
  7957. ) );
  7958. Doo::loadModel ( 'enclosur' );
  7959. $enclosur = new enclosur ();
  7960. $enclosur->delEnclosurByEid ( $key );
  7961. echo json_encode ( array (
  7962. 'status' => 1
  7963. ) );
  7964. }
  7965. function remittance() {
  7966. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7967. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7968. Doo::loadModel ( 'receipt' );
  7969. $receipt = new receipt ();
  7970. Doo::loadModel ( 'staff' );
  7971. $staff = new staff ();
  7972. $dateCondition = " and Year(pastDate) =" . $year;
  7973. if (! empty ( $month ))
  7974. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  7975. // get Receipt By verifyID status 1
  7976. $receiptList = $receipt->find ( array (
  7977. 'select' => 'sum(sum) as sum,staff,pastDate',
  7978. 'where' => ' status=1' . $dateCondition,
  7979. 'desc' => 'pastDate',
  7980. 'groupby' => 'staff,pastDate',
  7981. 'asArray' => true
  7982. ) );
  7983. $dateList = $receipt->find ( array (
  7984. 'select' => 'pastDate,verifyStaff',
  7985. 'where' => ' status=1' . $dateCondition,
  7986. 'desc' => 'pastDate',
  7987. 'groupby' => 'pastDate',
  7988. 'asArray' => true
  7989. ) );
  7990. $dataList = array ();
  7991. foreach ( $dateList as $d => $a ) {
  7992. $dataList [$a ['pastDate']] = array ();
  7993. $daySum = 0;
  7994. foreach ( $receiptList as $key => $value ) {
  7995. if ($a ['pastDate'] == $value ['pastDate']) {
  7996. $oderList = $receipt->find ( array (
  7997. 'select' => 'receiptOrder',
  7998. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  7999. 'asArray' => true
  8000. ) );
  8001. $list = array ();
  8002. $html = "";
  8003. foreach ( $oderList as $v ) {
  8004. array_push ( $list, $v ['receiptOrder'] );
  8005. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8006. }
  8007. $receiptList [$key] ['receiptOrder'] = $html;
  8008. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8009. $sinfo = $staff->getOne ( array (
  8010. 'select' => 'username ',
  8011. 'where' => ' sid=' . $value ['staff'],
  8012. 'asArray' => true
  8013. ) );
  8014. $receiptList [$key] ['username'] = $sinfo ['username'];
  8015. $daySum += $value ['sum'];
  8016. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8017. }
  8018. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8019. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8020. }
  8021. }
  8022. // print_r($dataList);
  8023. $data ['dataList'] = $dataList;
  8024. $mothHtml = "";
  8025. for($i = 1; $i <= 12; $i ++) {
  8026. if ($month == $i)
  8027. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8028. else
  8029. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8030. }
  8031. $data ['year'] = $year;
  8032. $data ['mothHtml'] = $mothHtml;
  8033. $data ['memu'] = "receipt";
  8034. $data ['staff'] = $this->staff;
  8035. $data ['receiptMemu'] = 'approval';
  8036. $data ['verifyId'] = $this->verifyId;
  8037. $data ['executeId'] = $this->executeId;
  8038. $this->render ( "/admin/saeaReportListPay", $data );
  8039. }
  8040. /**
  8041. * 金额调整,提高稳定性
  8042. * @return string
  8043. */
  8044. function revocationAdjustment() {
  8045. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8046. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8047. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8048. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8049. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8050. Doo::loadClass ( 'XDeode' );
  8051. $XDeode = new XDeode ( 5 );
  8052. Doo::loadModel ( 'receipt' );
  8053. $receipt = new receipt ();
  8054. $sid = $XDeode->decode ( $sidKey );
  8055. $rid = $XDeode->decode ( $ridKey );
  8056. $reviseKey = $XDeode->decode ( $reviseKey );
  8057. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8058. die ( 'illegal request' );
  8059. $receiptDetail = $receipt->getOne ( array (
  8060. 'where' => 'rid=' . $rid,
  8061. 'asArray' => true
  8062. ) );
  8063. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8064. die ( 'illegal request' );
  8065. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8066. if (! isset ( $reviseDetail [$reviseKey] ))
  8067. die ( 'illegal request' );
  8068. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8069. unset ( $reviseDetail [$reviseKey] );
  8070. $revisePrice = 0;
  8071. foreach ( $reviseDetail as $key => $value ) {
  8072. $revisePrice += $value ['price'];
  8073. }
  8074. $reviseDetailString = json_encode ( $reviseDetail );
  8075. $receipt->reviseDetail = $reviseDetailString;
  8076. $receipt->sum = $receiptDetail ['sum'] - $price;
  8077. $receipt->revisePrice = $revisePrice;
  8078. $receipt->update ( array (
  8079. 'where' => 'rid=' . $rid
  8080. ) );
  8081. return '/receiptburEdi/' . $rid;
  8082. } else
  8083. die ( 'illegal request2' );
  8084. }
  8085. function updateApprovalReceipt() {
  8086. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8087. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8088. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8089. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8090. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8091. if (! empty ( $rid )) {
  8092. Doo::loadModel ( "verify" );
  8093. $verify = new verify ();
  8094. Doo::loadModel ( "receiptDetail" );
  8095. $receiptDetailObj = new receiptDetail ();
  8096. Doo::loadModel ( "itemStatistics" );
  8097. Doo::loadModel ( "statistics" );
  8098. $statistics = new statistics ();
  8099. $itemStatistics = new itemStatistics ();
  8100. Doo::loadModel ( "receipt" );
  8101. $receipt = new receipt ();
  8102. $receiptDetail = $receipt->getOne ( array (
  8103. 'where' => 'rid=' . $rid . ' and status=2 ',
  8104. 'asArray' => true
  8105. ) );
  8106. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8107. $nsflag = true;
  8108. foreach ( $nslist as $value ) {
  8109. if ($value == $this->staff ['0'] ['sid']) {
  8110. $nsflag = false;
  8111. break;
  8112. }
  8113. }
  8114. if (empty ( $receiptDetail ) || $nsflag)
  8115. return "/approval";
  8116. $verifyDetail = $verify->getOne ( array (
  8117. 'where' => ' vid =' . $receiptDetail ['verify'],
  8118. 'asArray' => true
  8119. ) );
  8120. $verifyString = $verifyDetail ['staff'];
  8121. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8122. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8123. if (empty ( $opinion )) {
  8124. if ($status == 3)
  8125. $opinion = "终止";
  8126. else
  8127. $opinion = "同意支付";
  8128. }
  8129. $nowStaff = 0;
  8130. $nowStaffList = array ();
  8131. if (empty ( $verifyStaff )) {
  8132. // 还需加入是否已经进入角色审批
  8133. if ($verifyDetail [0] [1] == 'ROLE') {
  8134. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8135. foreach ( $vStaffString as $key => $value ) {
  8136. $staffK = explode ( "_", $value );
  8137. if ($staffK [0] != $this->staff [0] ['sid'])
  8138. array_push ( $nowStaffList, $staffK [0] );
  8139. }
  8140. // print_r($verifyDetail);
  8141. // die;
  8142. if (! empty ( $nowStaffList )) {
  8143. $nowStaff = implode ( ',', $nowStaffList );
  8144. $verifyStaff = array (
  8145. $this->staff [0] ['sid'] . "_R" => array (
  8146. 'date' => date ( 'Y-m-d' ),
  8147. 'opinion' => $opinion,
  8148. 'status' => $status,
  8149. 'nextStaff' => $verifyDetail [0] [0],
  8150. 'ROLE' => 1
  8151. )
  8152. );
  8153. } else {
  8154. $nowStaff = $verifyDetail [1] [0];
  8155. $verifyStaff = array (
  8156. $this->staff [0] ['sid'] . "_R" => array (
  8157. 'date' => date ( 'Y-m-d' ),
  8158. 'opinion' => $opinion,
  8159. 'status' => $status,
  8160. 'nextStaff' => $verifyDetail [1] [0]
  8161. )
  8162. );
  8163. }
  8164. } else {
  8165. if ($verifyDetail [1] [1] == 'ROLE') {
  8166. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8167. // echo "dd";
  8168. foreach ( $vStaffString as $key => $value ) {
  8169. $staffK = explode ( "_", $value );
  8170. array_push ( $nowStaffList, $staffK [0] );
  8171. }
  8172. $nowStaff = implode ( ',', $nowStaffList );
  8173. $verifyStaff = array (
  8174. $this->staff [0] ['sid'] => array (
  8175. 'date' => date ( 'Y-m-d' ),
  8176. 'opinion' => $opinion,
  8177. 'status' => $status,
  8178. 'nextStaff' => $verifyDetail [1] [0],
  8179. 'ROLE' => 1
  8180. )
  8181. );
  8182. } else {
  8183. $nowStaff = $verifyDetail [1] [0];
  8184. $verifyStaff = array (
  8185. $this->staff [0] ['sid'] => array (
  8186. 'date' => date ( 'Y-m-d' ),
  8187. 'opinion' => $opinion,
  8188. 'status' => $status,
  8189. 'nextStaff' => $verifyDetail [1] [0]
  8190. )
  8191. );
  8192. }
  8193. }
  8194. if ($status == 3)
  8195. $verifyStaff = array (
  8196. 'final' => $status,
  8197. $this->staff [0] ['sid'] => array (
  8198. 'date' => date ( 'Y-m-d' ),
  8199. 'opinion' => $opinion,
  8200. 'status' => $status
  8201. )
  8202. );
  8203. $vStaffString = json_encode ( $verifyStaff );
  8204. $receipt->nowStaff = $nowStaff;
  8205. $receipt->verifyStaff = $vStaffString;
  8206. } else {
  8207. $VS = end ( $verifyStaff );
  8208. // 非角色审批
  8209. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8210. $nextStaff = 0;
  8211. $roleSTF = false;
  8212. foreach ( $verifyDetail as $key => $value ) {
  8213. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8214. if (isset ( $verifyDetail [$key + 1] )) {
  8215. $nextStaff = $verifyDetail [$key + 1] [0];
  8216. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8217. $roleSTF = true;
  8218. }
  8219. break;
  8220. }
  8221. }
  8222. if (! $roleSTF) {
  8223. $nowStaff = $nextStaff;
  8224. $verifyStaff [$this->staff [0] ['sid']] = array (
  8225. 'date' => date ( 'Y-m-d' ),
  8226. 'opinion' => $opinion,
  8227. 'status' => $status,
  8228. 'nextStaff' => $nextStaff
  8229. );
  8230. } else {
  8231. // 获取角色下的所有用户ID
  8232. $nowStaffList = array ();
  8233. foreach ( $verifyDetail as $vfk ) {
  8234. if ($vfk [1] == 'ROLE') {
  8235. $vStaffString = json_decode ( $vfk [3] );
  8236. foreach ( $vStaffString as $key => $value ) {
  8237. $staffK = explode ( "_", $value );
  8238. array_push ( $nowStaffList, $staffK [0] );
  8239. }
  8240. }
  8241. }
  8242. $nowStaff = implode ( ',', $nowStaffList );
  8243. $verifyStaff [$this->staff [0] ['sid']] = array (
  8244. 'date' => date ( 'Y-m-d' ),
  8245. 'opinion' => $opinion,
  8246. 'status' => $status,
  8247. 'nextStaff' => $nextStaff,
  8248. 'ROLE' => 0
  8249. );
  8250. }
  8251. if ($status == 3) {
  8252. $verifyStaff ['final'] = $status;
  8253. $verifyStaff [$this->staff [0] ['sid']] = array (
  8254. 'date' => date ( 'Y-m-d' ),
  8255. 'opinion' => $opinion,
  8256. 'status' => $status
  8257. );
  8258. }
  8259. $vStaffString = json_encode ( $verifyStaff );
  8260. $receipt->nowStaff = $nowStaff;
  8261. $receipt->verifyStaff = $vStaffString;
  8262. }
  8263. // 角色审批
  8264. if (isset ( $VS ['ROLE'] )) {
  8265. // 找出角色人 当前审批角色组
  8266. $verifyJSStaff = array ();
  8267. $nowStaffList2 = array ();
  8268. foreach ( $verifyDetail as $key => $value ) {
  8269. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8270. $verifyJSStaff = json_decode ( $value [3] );
  8271. foreach ( $verifyJSStaff as $m ) {
  8272. $staffK = explode ( "_", $m );
  8273. array_push ( $nowStaffList2, $staffK [0] );
  8274. }
  8275. // print_r($nowStaffList2);
  8276. }
  8277. }
  8278. $RoleVerifyStaff = array ();
  8279. foreach ( $verifyStaff as $key => $value ) {
  8280. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8281. foreach ( $nowStaffList2 as $m ) {
  8282. if ($key == $m . "_R")
  8283. $RoleVerifyStaff [$key] = $value;
  8284. }
  8285. }
  8286. }
  8287. // print_r($verifyStaff);
  8288. // print_r($nowStaffList2);
  8289. // print_r($RoleVerifyStaff);
  8290. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8291. // print_r($verifyJSStaff);
  8292. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8293. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8294. // 下一个审批人ID
  8295. $nextStaff = 0;
  8296. $falg = false;
  8297. foreach ( $verifyDetail as $key => $value ) {
  8298. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8299. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8300. $falg = true;
  8301. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8302. $nowStaffList = array ();
  8303. foreach ( $vStaffString as $v ) {
  8304. $staffK = explode ( "_", $v );
  8305. array_push ( $nowStaffList, $staffK [0] );
  8306. }
  8307. $nowStaff = implode ( ',', $nowStaffList );
  8308. $nextStaff = $verifyDetail [$key + 1] [0];
  8309. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8310. $nextStaff = $verifyDetail [$key + 1] [0];
  8311. $nowStaff = $nextStaff;
  8312. } else
  8313. $nowStaff = '';
  8314. break;
  8315. }
  8316. }
  8317. if ($falg)
  8318. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8319. 'date' => date ( 'Y-m-d' ),
  8320. 'opinion' => $opinion,
  8321. 'status' => $status,
  8322. 'nextStaff' => $nextStaff,
  8323. 'ROLE' => 1
  8324. );
  8325. else
  8326. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8327. 'date' => date ( 'Y-m-d' ),
  8328. 'opinion' => $opinion,
  8329. 'status' => $status,
  8330. 'nextStaff' => $nextStaff
  8331. );
  8332. // print_r($verifyStaff);
  8333. // echo $nowStaff;die;
  8334. } else { // 进入下一个角色或者审批人
  8335. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8336. //
  8337. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8338. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8339. 'date' => date ( 'Y-m-d' ),
  8340. 'opinion' => $opinion,
  8341. 'status' => $status,
  8342. 'nextStaff' => $VS ['nextStaff'],
  8343. 'ROLE' => 1
  8344. );
  8345. // print_r($verifyStaff);
  8346. // die;
  8347. }
  8348. if ($status == 3) {
  8349. $verifyStaff ['final'] = $status;
  8350. $verifyStaff [$this->staff [0] ['sid']] = array (
  8351. 'date' => date ( 'Y-m-d' ),
  8352. 'opinion' => $opinion,
  8353. 'status' => $status
  8354. );
  8355. }
  8356. $vStaffString = json_encode ( $verifyStaff );
  8357. $receipt->verifyStaff = $vStaffString;
  8358. $receipt->nowStaff = $nowStaff;
  8359. // die;
  8360. // }
  8361. // print_r($verifyStaff);
  8362. // die;
  8363. }
  8364. // print_r($verifyStaff);die;
  8365. }
  8366. // print_r($verifyDetail);
  8367. $roleKey = 0;
  8368. $roleId = 0;
  8369. $verifyDetailCopy = array ();
  8370. foreach ( $verifyDetail as $k => $v ) {
  8371. if ($v [1] == 'ROLE') {
  8372. $roleId = $v [0];
  8373. $roleVerify = json_decode ( $v [3], true );
  8374. $roleKey = $k;
  8375. $roleArray = array ();
  8376. foreach ( $roleVerify as $o => $p ) {
  8377. $staffID = explode ( '_', $p );
  8378. $exp = array (
  8379. 0 => $staffID [0],
  8380. 1 => $staffID [1]
  8381. );
  8382. array_push ( $roleArray, $exp );
  8383. }
  8384. $verifyDetailCopy [$v [0]] = $roleArray;
  8385. }
  8386. }
  8387. // print_r($verifyDetail);
  8388. foreach ( $verifyDetailCopy as $k => $v ) {
  8389. foreach ( $verifyDetail as $m => $n ) {
  8390. if ($n [0] == $k) {
  8391. array_splice ( $verifyDetail, $m, 1, $v );
  8392. }
  8393. }
  8394. }
  8395. // die;
  8396. // if (!empty($roleArray))
  8397. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8398. // echo $roleId;
  8399. // print_r($verifyStaff);
  8400. // print_r($verifyDetail);
  8401. // die;
  8402. Doo::loadModel ( "receiptLog" );
  8403. $receiptLog = new receiptLog ();
  8404. // 审批日志
  8405. if (! isset ( $verifyStaff ['final'] )) {
  8406. if (! empty ( $roleId )) {
  8407. Doo::loadModel ( "role" );
  8408. $role = new role ();
  8409. $roleInfo = $role->getOne ( array (
  8410. 'where' => 'rid=' . $roleId,
  8411. 'asArray' => true
  8412. ) );
  8413. $receiptLog->rolename = $roleInfo ['name'];
  8414. }
  8415. $receiptLog->username = $this->staff [0] ['username'];
  8416. $receiptLog->uid = $this->staff [0] ['sid'];
  8417. $receiptLog->date = date ( "Y-m-d" );
  8418. $receiptLog->opinion = $opinion;
  8419. $receiptLog->img = $this->staff [0] ['avatar'];
  8420. $receiptLog->status = 1;
  8421. $receiptLog->rid = $rid;
  8422. $receiptLog->insert ();
  8423. }
  8424. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8425. $receipt->verifyBreakup = $verifyString;
  8426. $receipt->status = 3;
  8427. $receiptDetailObj->status = 3;
  8428. $receiptDetailObj->update ( array (
  8429. 'where' => 'rid=' . $rid
  8430. ) );
  8431. if (! empty ( $roleId )) {
  8432. Doo::loadModel ( "role" );
  8433. $role = new role ();
  8434. $roleInfo = $role->getOne ( array (
  8435. 'where' => 'rid=' . $roleId,
  8436. 'asArray' => true
  8437. ) );
  8438. $receiptLog->rolename = $roleInfo ['name'];
  8439. }
  8440. $receiptLog->username = $this->staff [0] ['username'];
  8441. $receiptLog->uid = $this->staff [0] ['sid'];
  8442. $receiptLog->date = date ( "Y-m-d" );
  8443. $receiptLog->opinion = $opinion;
  8444. $receiptLog->img = $this->staff [0] ['avatar'];
  8445. $receiptLog->status = 3;
  8446. $receiptLog->rid = $rid;
  8447. $receiptLog->insert ();
  8448. // 微信企业号通知
  8449. $this->setWXMsg ( $rid, 3 );
  8450. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8451. $receipt->status = 1;
  8452. $reviseSum = 0;
  8453. $receipt->verifyBreakup = $verifyString;
  8454. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8455. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8456. foreach ( $reviseDetail as $key => $value ) {
  8457. $receiptDetailObj = new receiptDetail ();
  8458. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8459. $receiptDetailObj->item = $value ['description'];
  8460. $receiptDetailObj->itemCategory = "报销金额调整";
  8461. $receiptDetailObj->price = $value ['price'];
  8462. $receiptDetailObj->date = $receiptDetail ['date'];
  8463. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8464. $receiptDetailObj->rid = $rid;
  8465. $receiptDetailObj->status = 1;
  8466. $receiptDetailObj->insert ();
  8467. $reviseSum += $value ['price'];
  8468. }
  8469. $itemStatistics = new itemStatistics ();
  8470. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8471. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8472. $itemStatistics->price = $reviseSum;
  8473. $itemStatistics->itemCategory = "报销金额调整";
  8474. $itemStatistics->date = $receiptDetail ['date'];
  8475. $itemStatistics->insert ();
  8476. }
  8477. $receiptDetailObj = new receiptDetail ();
  8478. $receiptDetailObj->status = 1;
  8479. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8480. $receiptDetailObj->update ( array (
  8481. 'where' => 'rid=' . $rid
  8482. ) );
  8483. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8484. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8485. $stat = $statistics->getOne ( array (
  8486. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8487. 'asArray' => true
  8488. ) );
  8489. if (empty ( $stat )) {
  8490. $statistics->date = $receiptDetail ['date'];
  8491. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8492. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8493. $statistics->agPrice = $receiptDetail ['sum'];
  8494. $statistics->rePrice = $reviseSum;
  8495. $statistics->insert ();
  8496. } else {
  8497. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8498. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8499. $statistics->update ( array (
  8500. 'where' => 'sid=' . $stat ['sid']
  8501. ) );
  8502. }
  8503. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8504. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8505. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8506. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8507. if ($key == "agencySum") {
  8508. $iStatistics = $itemStatistics->getOne ( array (
  8509. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8510. 'asArray' => true
  8511. ) );
  8512. if (empty ( $iStatistics )) {
  8513. $itemStatistics->cid = $receiptDetail ['cid'];
  8514. ;
  8515. $itemStatistics->staff = $receiptDetail ['staff'];
  8516. $itemStatistics->price = $value;
  8517. $itemStatistics->itemCategory = $this->AGENCY;
  8518. $itemStatistics->date = $receiptDetail ['date'];
  8519. $itemStatistics->insert ();
  8520. } else {
  8521. if (! empty ( $value )) {
  8522. $itemStatistics->price = $value + $iStatistics ['price'];
  8523. $itemStatistics->update ( array (
  8524. 'where' => 'sid=' . $iStatistics ['sid']
  8525. ) );
  8526. }
  8527. }
  8528. } elseif ($key == "travelSum") {
  8529. $iStatistics = $itemStatistics->getOne ( array (
  8530. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8531. 'asArray' => true
  8532. ) );
  8533. if (empty ( $iStatistics )) {
  8534. $itemStatistics->cid = $receiptDetail ['cid'];
  8535. $itemStatistics->staff = $receiptDetail ['staff'];
  8536. $itemStatistics->price = $value;
  8537. $itemStatistics->itemCategory = $this->TRAVEL;
  8538. $itemStatistics->date = $receiptDetail ['date'];
  8539. $itemStatistics->insert ();
  8540. } else {
  8541. if (! empty ( $value )) {
  8542. $itemStatistics->price = $value + $iStatistics ['price'];
  8543. $itemStatistics->update ( array (
  8544. 'where' => 'sid=' . $iStatistics ['sid']
  8545. ) );
  8546. }
  8547. }
  8548. } elseif ($key == "trainSum") {
  8549. $iStatistics = $itemStatistics->getOne ( array (
  8550. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8551. 'asArray' => true
  8552. ) );
  8553. if (empty ( $iStatistics )) {
  8554. $itemStatistics->cid = $receiptDetail ['cid'];
  8555. $itemStatistics->staff = $receiptDetail ['staff'];
  8556. $itemStatistics->price = $value;
  8557. $itemStatistics->itemCategory = $this->TRAIN;
  8558. $itemStatistics->date = $receiptDetail ['date'];
  8559. $itemStatistics->insert ();
  8560. } else {
  8561. if (! empty ( $value )) {
  8562. $itemStatistics->price = $value + $iStatistics ['price'];
  8563. $itemStatistics->update ( array (
  8564. 'where' => 'sid=' . $iStatistics ['sid']
  8565. ) );
  8566. }
  8567. }
  8568. } elseif ($key == "otherSum") {
  8569. $iStatistics = $itemStatistics->getOne ( array (
  8570. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8571. 'asArray' => true
  8572. ) );
  8573. if (empty ( $iStatistics )) {
  8574. $itemStatistics->cid = $receiptDetail ['cid'];
  8575. $itemStatistics->staff = $receiptDetail ['staff'];
  8576. $itemStatistics->price = $value;
  8577. $itemStatistics->itemCategory = $this->OTHER;
  8578. $itemStatistics->date = $receiptDetail ['date'];
  8579. $itemStatistics->insert ();
  8580. } else {
  8581. if (! empty ( $value )) {
  8582. $itemStatistics->price = $value + $iStatistics ['price'];
  8583. $itemStatistics->update ( array (
  8584. 'where' => 'sid=' . $iStatistics ['sid']
  8585. ) );
  8586. }
  8587. }
  8588. }
  8589. }
  8590. $receipt->pastDate = date ( "Y-m-d" );
  8591. // 微信企业号通知
  8592. $this->setWXMsg ( $rid, 1 );
  8593. }
  8594. $receipt->amount = $amount;
  8595. $receipt->update ( array (
  8596. 'where' => ' rid = ' . $rid
  8597. ) );
  8598. // 进入下一条审批费用新加需求
  8599. $vidList = array ();
  8600. $verifyDetail = $verify->find ( array (
  8601. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8602. 'asArray' => true
  8603. ) );
  8604. foreach ( $verifyDetail as $key => $value ) {
  8605. array_push ( $vidList, $value ['vid'] );
  8606. }
  8607. $vid = implode ( ",", $vidList );
  8608. if (empty ( $verifyDetail ))
  8609. $vid = 0;
  8610. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8611. $receipt = new receipt ();
  8612. $rd = $receipt->getOne ( array (
  8613. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  8614. 'asc' => 'rid',
  8615. 'asArray' => true
  8616. ) );
  8617. if (empty ( $rd )) {
  8618. return '/approvalExpenses/pendApproval';
  8619. }
  8620. if ($rd ['Rtype'] == 1) {
  8621. if ($rd ['isBK'] == 1) {
  8622. return '/receiptburEdi/' . $rd ['rid'];
  8623. } else {
  8624. return '/expensesEdi/' . $rd ['rid'];
  8625. }
  8626. } elseif ($rd ['Rtype'] == 2) {
  8627. return '/remitApproval/' . $rd ['rid'];
  8628. } else {
  8629. return '/receiptburEdi/' . $rd ['rid'];
  8630. }
  8631. // return "/approvalExpenses/pendApproval";
  8632. }
  8633. }
  8634. function expensesRetreats() {
  8635. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8636. if (! empty ( $rid )) {
  8637. // 操作记录
  8638. Doo::loadModel ( "receipt" );
  8639. $receipt = new receipt ();
  8640. Doo::loadModel ( "receiptLog" );
  8641. $receiptLog = new receiptLog ();
  8642. Doo::loadModel ( "verify" );
  8643. $verify = new verify ();
  8644. $receiptInfo = $receipt->getOne ( array (
  8645. 'where' => 'rid=' . $rid,
  8646. 'asArray' => true
  8647. ) );
  8648. $vr = $verify->getOne ( array (
  8649. 'where' => 'vid=' . $receiptInfo ['verify'],
  8650. 'asArray' => true
  8651. ) );
  8652. $jd = json_decode ( $vr ['staff'] );
  8653. $roleId = 0;
  8654. foreach ( $jd as $key => $value ) {
  8655. if ($value [1] == 'ROLE') {
  8656. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8657. if ($pos !== false) {
  8658. $roleId = $value [0];
  8659. }
  8660. }
  8661. }
  8662. // 审批日志
  8663. // echo $roleId;die;
  8664. if (! empty ( $roleId )) {
  8665. Doo::loadModel ( "role" );
  8666. $role = new role ();
  8667. $roleInfo = $role->getOne ( array (
  8668. 'where' => 'rid=' . $roleId,
  8669. 'asArray' => true
  8670. ) );
  8671. $receiptLog->rolename = $roleInfo ['name'];
  8672. }
  8673. $receiptLog->username = $this->staff [0] ['username'];
  8674. $receiptLog->uid = $this->staff [0] ['sid'];
  8675. $receiptLog->date = date ( "Y-m-d" );
  8676. $receiptLog->opinion = '撤回';
  8677. $receiptLog->img = $this->staff [0] ['avatar'];
  8678. $receiptLog->status = 4;
  8679. $receiptLog->rid = $rid;
  8680. $receiptLog->insert ();
  8681. $receipt->status = 4;
  8682. $receipt->update ( array (
  8683. 'where' => 'rid=' . $rid
  8684. ) );
  8685. // 微信企业号通知
  8686. $this->setWXMsg ( $rid, 2 );
  8687. }
  8688. // echo "ddd";
  8689. return '/approvalExpenses/pendApproval';
  8690. }
  8691. function updateCheReceipt() {
  8692. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8693. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8694. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8695. if (! empty ( $rid )) {
  8696. // 操作记录
  8697. Doo::loadModel ( "receipt" );
  8698. $receipt = new receipt ();
  8699. Doo::loadModel ( "receiptLog" );
  8700. $receiptLog = new receiptLog ();
  8701. Doo::loadModel ( "verify" );
  8702. $verify = new verify ();
  8703. $receiptInfo = $receipt->getOne ( array (
  8704. 'where' => 'rid=' . $rid . ' and status=2',
  8705. 'asArray' => true
  8706. ) );
  8707. if (empty ( $receiptInfo )) {
  8708. echo json_encode ( array (
  8709. 'status' => 2
  8710. ) );
  8711. die ();
  8712. }
  8713. $vr = $verify->getOne ( array (
  8714. 'where' => 'vid=' . $receiptInfo ['verify'],
  8715. 'asArray' => true
  8716. ) );
  8717. $jd = json_decode ( $vr ['staff'] );
  8718. $roleId = 0;
  8719. foreach ( $jd as $key => $value ) {
  8720. if ($value [1] == 'ROLE') {
  8721. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8722. if ($pos !== false) {
  8723. $roleId = $value [0];
  8724. }
  8725. }
  8726. }
  8727. // 审批日志
  8728. // echo $roleId;die;
  8729. if (! empty ( $roleId )) {
  8730. Doo::loadModel ( "role" );
  8731. $role = new role ();
  8732. $roleInfo = $role->getOne ( array (
  8733. 'where' => 'rid=' . $roleId,
  8734. 'asArray' => true
  8735. ) );
  8736. $receiptLog->rolename = $roleInfo ['name'];
  8737. }
  8738. $receiptLog->username = $this->staff [0] ['username'];
  8739. $receiptLog->uid = $this->staff [0] ['sid'];
  8740. $receiptLog->date = date ( "Y-m-d" );
  8741. $receiptLog->opinion = $opinion;
  8742. $receiptLog->img = $this->staff [0] ['avatar'];
  8743. $receiptLog->status = 4;
  8744. $receiptLog->rid = $rid;
  8745. $receiptLog->insert ();
  8746. $receipt->status = 4;
  8747. $receipt->update ( array (
  8748. 'where' => 'rid=' . $rid
  8749. ) );
  8750. // 微信企业号通知
  8751. $this->setWXMsg ( $rid, 2 );
  8752. echo json_encode ( array (
  8753. 'status' => 1
  8754. ) );
  8755. // Header("HTTP/1.1 303 See Other");
  8756. // Header("Location: /approvalExpenses/pendApproval");
  8757. die ();
  8758. }
  8759. echo json_encode ( array (
  8760. 'status' => 2
  8761. ) );
  8762. die ();
  8763. // echo "ddd";
  8764. // return '/saeaBorad';
  8765. }
  8766. function revisePrice() {
  8767. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  8768. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  8769. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8770. // echo $price;die;
  8771. if (! empty ( $rid )) {
  8772. Doo::loadModel ( "receipt" );
  8773. $receipt = new receipt ();
  8774. $receiptDetail = $receipt->getOne ( array (
  8775. 'where' => 'rid=' . $rid . ' and status=2 ',
  8776. 'asArray' => true
  8777. ) );
  8778. if (empty ( $receiptDetail ))
  8779. die ( 'illegal request' );
  8780. $reviseDetail = array ();
  8781. if (empty ( $receiptDetail ['reviseDetail'] )) {
  8782. array_push ( $reviseDetail, array (
  8783. 'sid' => $this->staff [0] ['sid'],
  8784. 'name' => $this->staff [0] ['username'],
  8785. 'description' => $description,
  8786. 'price' => $price
  8787. ) );
  8788. $reviseDetailString = json_encode ( $reviseDetail );
  8789. $receipt->reviseDetail = $reviseDetailString;
  8790. $receipt->revisePrice = $price;
  8791. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  8792. } else {
  8793. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8794. array_push ( $reviseDetail, array (
  8795. 'sid' => $this->staff [0] ['sid'],
  8796. 'name' => $this->staff [0] ['username'],
  8797. 'description' => $description,
  8798. 'price' => $price
  8799. ) );
  8800. $reviseDetailString = json_encode ( $reviseDetail );
  8801. $receipt->reviseDetail = $reviseDetailString;
  8802. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  8803. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  8804. }
  8805. $receipt->update ( array (
  8806. 'where' => 'rid=' . $rid
  8807. ) );
  8808. if ($receiptDetail ['Rtype'] == 1) {
  8809. if ($receiptDetail ['isBK'] == 1) {
  8810. return '/receiptburEdi/' . $receiptDetail ['rid'];
  8811. }
  8812. } elseif ($receiptDetail ['Rtype'] == 2) {
  8813. } else {
  8814. return '/receiptburEdi/' . $receiptDetail ['rid'];
  8815. }
  8816. }
  8817. die ( 'illegal request' );
  8818. }
  8819. function personalCollect() {
  8820. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8821. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  8822. $this->showCache ( $path );
  8823. Doo::loadModel ( "receiptDetail" );
  8824. Doo::loadModel ( "itemStatistics" );
  8825. Doo::loadModel ( 'statistics' );
  8826. $statistics = new statistics ();
  8827. $itemStatistics = new itemStatistics ();
  8828. $receiptDetail = new receiptDetail ();
  8829. $receiptCollectList = $receiptDetail->find ( array (
  8830. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  8831. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  8832. 'groupby' => 'itemCategory,Month(date)',
  8833. 'asArray' => true
  8834. ) );
  8835. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  8836. 'where' => 'staff=' . $this->staff [0] ['sid'],
  8837. 'asArray' => true
  8838. ) );
  8839. // create collect html
  8840. $collectArray = array (
  8841. '日常相关费用' => array (),
  8842. '差旅相关费用' => array (),
  8843. '培训班费用' => array (),
  8844. '其他' => array ()
  8845. );
  8846. $adjustment = array ();
  8847. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  8848. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  8849. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  8850. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  8851. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  8852. array_push ( $collectArray ['培训班费用'], $collectHtml );
  8853. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  8854. array_push ( $collectArray ['其他'], $collectHtml );
  8855. $data ['collectArray'] = $collectArray;
  8856. // statistics html
  8857. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  8858. if (empty ( $stList ))
  8859. $stList = array (
  8860. 'rePrice' => 0,
  8861. 'agPrice' => 0
  8862. );
  8863. $data ['stList'] = array (
  8864. 'rePrice' => $stList ['rePrice'],
  8865. 'agPrice' => $stList ['agPrice'],
  8866. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  8867. );
  8868. // Adjustment price html
  8869. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  8870. array_push ( $adjustment, $collectHtml );
  8871. $data ['adjustment'] = $adjustment;
  8872. // total price html
  8873. $collectHtml = "";
  8874. $total = 0;
  8875. for($i = 1; $i <= 12; $i ++) {
  8876. $sumPrice = 0;
  8877. foreach ( $receiptCollectList as $key => $value ) {
  8878. if ($value ['month'] == $i) {
  8879. $sumPrice += $value ['price'];
  8880. }
  8881. }
  8882. if ($sumPrice == 0)
  8883. $collectHtml .= '<td class="taR">-</td>';
  8884. else
  8885. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  8886. $total += $sumPrice;
  8887. }
  8888. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  8889. $data ['totalPrice'] = $collectHtml;
  8890. $dateHtml = "";
  8891. $now = date ( "Y" );
  8892. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8893. if ($YEARD <= $now) {
  8894. $dateHtml .= '<option ';
  8895. if ($year == $YEARD) {
  8896. $dateHtml .= 'selected ';
  8897. }
  8898. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8899. }
  8900. }
  8901. $data ['dateHtml'] = $dateHtml;
  8902. $data ['year'] = $year;
  8903. $data ['totalYear'] = $total;
  8904. $data ['memu'] = "receipt";
  8905. $data ['staff'] = $this->staff;
  8906. $data ['receiptMemu'] = 'personalCollect';
  8907. $data ['verifyId'] = $this->verifyId;
  8908. $data ['executeId'] = $this->executeId;
  8909. // year staff status 2,4
  8910. if ($year < date ( "Y" )) {
  8911. Doo::loadModel ( 'receipt' );
  8912. $receipt = new receipt ();
  8913. $receiptList = $receipt->find ( array (
  8914. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  8915. 'asArray' => true
  8916. ) );
  8917. if (empty ( $receiptList )) {
  8918. ob_start ();
  8919. $this->render ( "/admin/saea_slist_collect", $data );
  8920. $this->cacheFile ( $path );
  8921. die ();
  8922. }
  8923. }
  8924. $this->render ( "/admin/saea_slist_collect", $data );
  8925. }
  8926. function personalCollectDetail() {
  8927. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8928. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  8929. $this->showCache ( $path );
  8930. Doo::loadModel ( "receiptDetail" );
  8931. Doo::loadModel ( "itemStatistics" );
  8932. Doo::loadModel ( 'statistics' );
  8933. Doo::loadModel ( 'accountItem' );
  8934. $accountItem = new accountItem ();
  8935. $statistics = new statistics ();
  8936. $itemStatistics = new itemStatistics ();
  8937. $receiptDetail = new receiptDetail ();
  8938. $receiptCollectList = $receiptDetail->find ( array (
  8939. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  8940. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  8941. 'groupby' => 'item,Month(date)',
  8942. 'asArray' => true
  8943. ) );
  8944. $accountList = $accountItem->find ( array (
  8945. 'asArray' => true
  8946. ) );
  8947. // create CollectDetail HTML
  8948. $collectHtml = array ();
  8949. foreach ( $accountList as $key => $value ) {
  8950. $html = "";
  8951. $asum = 0;
  8952. for($i = 1; $i <= 12; $i ++) {
  8953. $falg = true;
  8954. foreach ( $receiptCollectList as $v ) {
  8955. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  8956. $asum += $v ['price'];
  8957. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  8958. $falg = false;
  8959. break;
  8960. }
  8961. }
  8962. if ($falg)
  8963. $html .= '<td class="taR">-</td>';
  8964. }
  8965. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  8966. $collectHtml [$value ['category']] [$value ['name']] = $html;
  8967. }
  8968. $data ['collectHtml'] = $collectHtml;
  8969. // create Adjustment price html
  8970. $receiptCollectList = $receiptDetail->find ( array (
  8971. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  8972. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  8973. 'groupby' => 'itemCategory,Month(date)',
  8974. 'asArray' => true
  8975. ) );
  8976. $adjustment = array ();
  8977. $collectArray = array (
  8978. '日常相关费用' => array (),
  8979. '差旅相关费用' => array (),
  8980. '培训班费用' => array (),
  8981. '其他' => array ()
  8982. );
  8983. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  8984. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  8985. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  8986. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  8987. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  8988. array_push ( $collectArray ['培训班费用'], $collectHtml );
  8989. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  8990. array_push ( $collectArray ['其他'], $collectHtml );
  8991. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  8992. array_push ( $adjustment, $collectHtml );
  8993. // total price html
  8994. $collectHtml = "";
  8995. $total = 0;
  8996. for($i = 1; $i <= 12; $i ++) {
  8997. $sumPrice = 0;
  8998. foreach ( $receiptCollectList as $key => $value ) {
  8999. if ($value ['month'] == $i) {
  9000. $sumPrice += $value ['price'];
  9001. }
  9002. }
  9003. if ($sumPrice == 0)
  9004. $collectHtml .= '<td class="taR">-</td>';
  9005. else
  9006. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9007. $total += $sumPrice;
  9008. }
  9009. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9010. // statistics html
  9011. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9012. if (empty ( $stList ))
  9013. $stList = array (
  9014. 'rePrice' => 0,
  9015. 'agPrice' => 0
  9016. );
  9017. $data ['stList'] = array (
  9018. 'rePrice' => $stList ['rePrice'],
  9019. 'agPrice' => $stList ['agPrice'],
  9020. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9021. );
  9022. $data ['collectArray'] = $collectArray;
  9023. $data ['adjustment'] = $adjustment;
  9024. $data ['totalPrice'] = $collectHtml;
  9025. $data ['totalYear'] = $total;
  9026. $data ['year'] = $year;
  9027. $dateHtml = "";
  9028. $now = date ( "Y" );
  9029. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9030. if ($YEARD <= $now) {
  9031. $dateHtml .= '<option ';
  9032. if ($year == $YEARD) {
  9033. $dateHtml .= 'selected ';
  9034. }
  9035. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9036. }
  9037. }
  9038. $data ['dateHtml'] = $dateHtml;
  9039. $data ['memu'] = "receipt";
  9040. $data ['staff'] = $this->staff;
  9041. $data ['receiptMemu'] = 'personalCollect';
  9042. $data ['verifyId'] = $this->verifyId;
  9043. $data ['executeId'] = $this->executeId;
  9044. // year staff status 2,4
  9045. if ($year < date ( "Y" )) {
  9046. Doo::loadModel ( 'receipt' );
  9047. $receipt = new receipt ();
  9048. $receiptList = $receipt->find ( array (
  9049. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9050. 'asArray' => true
  9051. ) );
  9052. if (empty ( $receiptList )) {
  9053. ob_start ();
  9054. $this->render ( "/admin/saeaCollectArticles", $data );
  9055. $this->cacheFile ( $path );
  9056. die ();
  9057. }
  9058. }
  9059. $this->render ( "/admin/saeaCollectArticles", $data );
  9060. }
  9061. function companyCategoryCollect() {
  9062. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9063. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9064. $this->showCache ( $path );
  9065. Doo::loadModel ( 'L_category' );
  9066. Doo::loadModel ( 'itemStatistics' );
  9067. Doo::loadModel ( 'statistics' );
  9068. $statistics = new statistics ();
  9069. $Lcategory = new L_category ();
  9070. $itemStatistics = new itemStatistics ();
  9071. Doo::loadModel ( "receiptAuthorityManage" );
  9072. $receiptAuthorityManage = new receiptAuthorityManage ();
  9073. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9074. $cidList = array ();
  9075. foreach ( $imcStaff as $key => $value ) {
  9076. array_push ( $cidList, $value ['cid'] );
  9077. }
  9078. $cidString = implode ( ',', $cidList );
  9079. $LcategoryList = $Lcategory->find ( array (
  9080. 'where' => ' cid in (' . $cidString . ')',
  9081. 'asArray' => true
  9082. ) ); // 'staff='.$this->staff[0]['sid']." and
  9083. $itemStatisticsList = $itemStatistics->find ( array (
  9084. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9085. 'where' => " Year(date)=" . $year,
  9086. 'groupby' => 'cid,Month(date)',
  9087. 'asArray' => true
  9088. ) );
  9089. // ceatre companyCollectHtml
  9090. foreach ( $LcategoryList as $value ) {
  9091. $html = "";
  9092. $asum = 0;
  9093. for($i = 1; $i <= 12; $i ++) {
  9094. $falg = true;
  9095. foreach ( $itemStatisticsList as $v ) {
  9096. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9097. $asum += $v ['price'];
  9098. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9099. $falg = false;
  9100. break;
  9101. }
  9102. }
  9103. if ($falg)
  9104. $html .= '<td class="taR">-</td>';
  9105. }
  9106. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9107. $collectHtml [$value ['title']] = array (
  9108. 'html' => $html,
  9109. 'cid' => $value ['cid']
  9110. );
  9111. }
  9112. $data ['companyHtml'] = $collectHtml;
  9113. // total price html
  9114. $collectHtml = "";
  9115. $total = 0;
  9116. for($i = 1; $i <= 12; $i ++) {
  9117. $sumPrice = 0;
  9118. foreach ( $itemStatisticsList as $key => $value ) {
  9119. if ($value ['month'] == $i) {
  9120. $sumPrice += $value ['price'];
  9121. }
  9122. }
  9123. if ($sumPrice == 0)
  9124. $collectHtml .= '<td class="taR">-</td>';
  9125. else
  9126. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9127. $total += $sumPrice;
  9128. }
  9129. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9130. $data ['companyTotalHtml'] = $collectHtml;
  9131. $data ['total'] = $total;
  9132. // statistics html
  9133. // echo $cidString;
  9134. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9135. if (empty ( $stList ))
  9136. $stList = array (
  9137. 'rePrice' => 0,
  9138. 'agPrice' => 0
  9139. );
  9140. $data ['stList'] = array (
  9141. 'rePrice' => $stList ['rePrice'],
  9142. 'agPrice' => $stList ['agPrice'],
  9143. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9144. );
  9145. $data ['year'] = $year;
  9146. $data ['memu'] = "receipt";
  9147. $data ['staff'] = $this->staff;
  9148. $data ['receiptMemu'] = 'companyCategoryCollect';
  9149. $data ['verifyId'] = $this->verifyId;
  9150. $data ['executeId'] = $this->executeId;
  9151. $dateHtml = "";
  9152. $now = date ( "Y" );
  9153. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9154. if ($YEARD <= $now) {
  9155. $dateHtml .= '<option ';
  9156. if ($year == $YEARD) {
  9157. $dateHtml .= 'selected ';
  9158. }
  9159. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9160. }
  9161. }
  9162. $data ['dateHtml'] = $dateHtml;
  9163. // year staff status 2,4
  9164. if ($year < date ( "Y" )) {
  9165. Doo::loadModel ( 'receipt' );
  9166. $receipt = new receipt ();
  9167. $receiptList = $receipt->find ( array (
  9168. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9169. 'asArray' => true
  9170. ) );
  9171. if (empty ( $receiptList )) {
  9172. ob_start ();
  9173. $this->render ( "/admin/saeaCompanyCollect", $data );
  9174. $this->cacheFile ( $path );
  9175. die ();
  9176. }
  9177. }
  9178. $this->render ( "/admin/saeaCompanyCollect", $data );
  9179. }
  9180. function categoryCollectDetail() {
  9181. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9182. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9183. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9184. $this->showCache ( $path );
  9185. Doo::loadModel ( 'statistics' );
  9186. $statistics = new statistics ();
  9187. Doo::loadModel ( "receiptDetail" );
  9188. $receiptDetail = new receiptDetail ();
  9189. Doo::loadModel ( 'L_category' );
  9190. $Lcategory = new L_category ();
  9191. Doo::loadModel ( 'accountItem' );
  9192. $accountItem = new accountItem ();
  9193. Doo::loadModel ( "receiptAuthorityManage" );
  9194. $receiptAuthorityManage = new receiptAuthorityManage ();
  9195. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9196. $cidList = array ();
  9197. foreach ( $imcStaff as $key => $value ) {
  9198. array_push ( $cidList, $value ['cid'] );
  9199. }
  9200. $cidString = implode ( ',', $cidList );
  9201. $LcategoryList = $Lcategory->find ( array (
  9202. 'where' => 'cid in (' . $cidString . ')',
  9203. 'asArray' => true
  9204. ) );
  9205. if ($cid == 0) {
  9206. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9207. if ($cid == 0)
  9208. $cid = $LcategoryList [0] ['cid'];
  9209. }
  9210. $data ['LcategoryList'] = $LcategoryList;
  9211. $receiptCollectList = $receiptDetail->find ( array (
  9212. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9213. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9214. 'groupby' => 'item,Month(pastDate)',
  9215. 'asArray' => true
  9216. ) );
  9217. $accountList = $accountItem->find ( array (
  9218. 'asArray' => true
  9219. ) );
  9220. // create CollectDetail HTML
  9221. $collectHtml = array ();
  9222. foreach ( $accountList as $key => $value ) {
  9223. $html = "";
  9224. $asum = 0;
  9225. for($i = 1; $i <= 12; $i ++) {
  9226. $falg = true;
  9227. foreach ( $receiptCollectList as $v ) {
  9228. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9229. $asum += $v ['price'];
  9230. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9231. $falg = false;
  9232. break;
  9233. }
  9234. }
  9235. if ($falg)
  9236. $html .= '<td class="taR">-</td>';
  9237. }
  9238. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9239. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9240. }
  9241. $data ['collectHtml'] = $collectHtml;
  9242. // create Adjustment price html
  9243. $receiptCollectList = $receiptDetail->find ( array (
  9244. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9245. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9246. 'groupby' => 'itemCategory,Month(pastDate)',
  9247. 'asArray' => true
  9248. ) );
  9249. $adjustment = array ();
  9250. $collectArray = array (
  9251. '日常相关费用' => array (),
  9252. '差旅相关费用' => array (),
  9253. '培训班费用' => array (),
  9254. '其他' => array ()
  9255. );
  9256. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9257. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9258. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9259. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9260. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9261. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9262. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9263. array_push ( $collectArray ['其他'], $collectHtml );
  9264. $data ['collectArray'] = $collectArray;
  9265. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9266. array_push ( $adjustment, $collectHtml );
  9267. $data ['adjustment'] = $adjustment;
  9268. // total price html
  9269. $collectHtml = "";
  9270. $total = 0;
  9271. for($i = 1; $i <= 12; $i ++) {
  9272. $sumPrice = 0;
  9273. foreach ( $receiptCollectList as $key => $value ) {
  9274. if ($value ['month'] == $i) {
  9275. $sumPrice += $value ['price'];
  9276. }
  9277. }
  9278. if ($sumPrice == 0)
  9279. $collectHtml .= '<td class="taR">-</td>';
  9280. else
  9281. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9282. $total += $sumPrice;
  9283. }
  9284. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9285. // statistics html
  9286. $stList = $statistics->statisticsByCid ( $year, $cid );
  9287. if (empty ( $stList ))
  9288. $stList = array (
  9289. 'rePrice' => 0,
  9290. 'agPrice' => 0
  9291. );
  9292. $data ['stList'] = array (
  9293. 'rePrice' => $stList ['rePrice'],
  9294. 'agPrice' => $stList ['agPrice'],
  9295. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9296. );
  9297. $data ['totalYear'] = $total;
  9298. $data ['year'] = $year;
  9299. $data ['cid'] = $cid;
  9300. $data ['memu'] = "receipt";
  9301. $data ['staff'] = $this->staff;
  9302. $data ['receiptMemu'] = 'companyCategoryCollect';
  9303. $data ['verifyId'] = $this->verifyId;
  9304. $data ['executeId'] = $this->executeId;
  9305. // year staff status 2,4
  9306. if ($year < date ( "Y" )) {
  9307. Doo::loadModel ( 'receipt' );
  9308. $receipt = new receipt ();
  9309. $receiptList = $receipt->find ( array (
  9310. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9311. 'asArray' => true
  9312. ) );
  9313. if (empty ( $receiptList )) {
  9314. ob_start ();
  9315. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9316. $this->cacheFile ( $path );
  9317. die ();
  9318. }
  9319. }
  9320. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9321. }
  9322. function staffCollect() {
  9323. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9324. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9325. // $this->showCache($path);
  9326. Doo::loadModel ( 'statistics' );
  9327. $statistics = new statistics ();
  9328. Doo::loadModel ( "receiptDetail" );
  9329. $receiptDetail = new receiptDetail ();
  9330. Doo::loadModel ( 'L_category' );
  9331. $Lcategory = new L_category ();
  9332. Doo::loadModel ( 'accountItem' );
  9333. $accountItem = new accountItem ();
  9334. Doo::loadModel ( 'staff' );
  9335. $staff = new staff ();
  9336. Doo::loadModel ( 'itemStatistics' );
  9337. $itemStatistics = new itemStatistics ();
  9338. Doo::loadModel ( "receiptAuthorityManage" );
  9339. $receiptAuthorityManage = new receiptAuthorityManage ();
  9340. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9341. $cidList = array ();
  9342. foreach ( $imcStaff as $key => $value ) {
  9343. array_push ( $cidList, $value ['cid'] );
  9344. }
  9345. $cidString = implode ( ',', $cidList );
  9346. // statistics html
  9347. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9348. if (empty ( $stList ))
  9349. $stList = array (
  9350. 'rePrice' => 0,
  9351. 'agPrice' => 0
  9352. );
  9353. $data ['stList'] = array (
  9354. 'rePrice' => $stList ['rePrice'],
  9355. 'agPrice' => $stList ['agPrice'],
  9356. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9357. );
  9358. // ---
  9359. $staffList = $staff->find ( array (
  9360. 'where' => 'username !="admin"',
  9361. 'asArray' => true
  9362. ) );
  9363. $LcategoryList = $Lcategory->find ( array (
  9364. 'asArray' => true
  9365. ) ); // 'staff='.$this->staff[0]['sid']." and
  9366. $itemStatisticsList = $itemStatistics->find ( array (
  9367. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9368. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9369. 'groupby' => 'staff,Month(date)',
  9370. 'asArray' => true
  9371. ) );
  9372. $categoryList = $staff->find ( array (
  9373. 'select' => 'COUNT(*) as count,cid,category',
  9374. 'where' => 'username !="admin" and cid in (' . $cidString . ')',
  9375. 'groupby' => 'cid',
  9376. 'asArray' => true
  9377. ) );
  9378. // print_r($itemStatisticsList);die;
  9379. // ceatre companyCollectHtml
  9380. foreach ( $categoryList as $vlu ) {
  9381. $count = $vlu ['count'] + 1;
  9382. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9383. $m1 = 0;
  9384. $m2 = 0;
  9385. $m3 = 0;
  9386. $m4 = 0;
  9387. $m5 = 0;
  9388. $m6 = 0;
  9389. $m7 = 0;
  9390. $m8 = 0;
  9391. $m9 = 0;
  9392. $m10 = 0;
  9393. $m11 = 0;
  9394. $m12 = 0;
  9395. $m13 = 0;
  9396. foreach ( $staffList as $value ) {
  9397. if ($vlu ['cid'] == $value ['cid']) {
  9398. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9399. $asum = 0;
  9400. for($i = 1; $i <= 12; $i ++) {
  9401. $falg = true;
  9402. foreach ( $itemStatisticsList as $v ) {
  9403. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9404. if ($v ['month'] == 1)
  9405. $m1 += $v ['price'];
  9406. if ($v ['month'] == 2)
  9407. $m2 += $v ['price'];
  9408. if ($v ['month'] == 3)
  9409. $m3 += $v ['price'];
  9410. if ($v ['month'] == 4)
  9411. $m4 += $v ['price'];
  9412. if ($v ['month'] == 5)
  9413. $m5 += $v ['price'];
  9414. if ($v ['month'] == 6)
  9415. $m6 += $v ['price'];
  9416. if ($v ['month'] == 7)
  9417. $m7 += $v ['price'];
  9418. if ($v ['month'] == 8)
  9419. $m8 += $v ['price'];
  9420. if ($v ['month'] == 9)
  9421. $m9 += $v ['price'];
  9422. if ($v ['month'] == 10)
  9423. $m10 += $v ['price'];
  9424. if ($v ['month'] == 11)
  9425. $m11 += $v ['price'];
  9426. if ($v ['month'] == 12)
  9427. $m12 += $v ['price'];
  9428. $asum += $v ['price'];
  9429. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9430. $falg = false;
  9431. break;
  9432. }
  9433. }
  9434. if ($falg)
  9435. $html .= '<td class="taR">-</td>';
  9436. }
  9437. $m13 += $asum;
  9438. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9439. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9440. 'html' => $html,
  9441. 'sid' => $value ['sid']
  9442. );
  9443. $html = "";
  9444. }
  9445. }
  9446. $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>
  9447. <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>
  9448. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9449. $collectHtml [$vlu ['cid']] = array (
  9450. 'html' => $hl,
  9451. 'sid' => ''
  9452. );
  9453. }
  9454. $data ['companyHtml'] = $collectHtml;
  9455. // total price html
  9456. $collectHtml = "";
  9457. $total = 0;
  9458. for($i = 1; $i <= 12; $i ++) {
  9459. $sumPrice = 0;
  9460. foreach ( $itemStatisticsList as $key => $value ) {
  9461. if ($value ['month'] == $i) {
  9462. $sumPrice += $value ['price'];
  9463. }
  9464. }
  9465. if ($sumPrice == 0)
  9466. $collectHtml .= '<td class="taR">-</td>';
  9467. else
  9468. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9469. $total += $sumPrice;
  9470. }
  9471. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9472. $data ['companyTotalHtml'] = $collectHtml;
  9473. $data ['total'] = $total;
  9474. $data ['year'] = $year;
  9475. $data ['memu'] = "receipt";
  9476. $data ['staff'] = $this->staff;
  9477. $data ['receiptMemu'] = 'companyCategoryCollect';
  9478. $data ['verifyId'] = $this->verifyId;
  9479. $data ['executeId'] = $this->executeId;
  9480. if ($year <= date ( "Y" )) {
  9481. Doo::loadModel ( 'receipt' );
  9482. $receipt = new receipt ();
  9483. $receiptList = $receipt->find ( array (
  9484. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9485. 'asArray' => true
  9486. ) );
  9487. if (empty ( $receiptList )) { // generated files
  9488. ob_start ();
  9489. $this->render ( "/admin/saeaStaffCollectB", $data );
  9490. $this->cacheFile ( $path );
  9491. die ();
  9492. }
  9493. }
  9494. $this->render ( "/admin/saeaStaffCollectB", $data );
  9495. }
  9496. function staffCollectBak() {
  9497. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9498. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9499. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9500. $this->showCache ( $path );
  9501. Doo::loadModel ( 'statistics' );
  9502. $statistics = new statistics ();
  9503. Doo::loadModel ( "receiptDetail" );
  9504. $receiptDetail = new receiptDetail ();
  9505. Doo::loadModel ( 'L_category' );
  9506. $Lcategory = new L_category ();
  9507. Doo::loadModel ( 'accountItem' );
  9508. $accountItem = new accountItem ();
  9509. Doo::loadModel ( 'staff' );
  9510. $staff = new staff ();
  9511. Doo::loadModel ( 'itemStatistics' );
  9512. $itemStatistics = new itemStatistics ();
  9513. $itemStatisticsList = $itemStatistics->find ( array (
  9514. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9515. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9516. 'groupby' => 'staff,itemCategory,Month(date)',
  9517. 'asArray' => true
  9518. ) );
  9519. $itemCategoryList = $itemStatistics->find ( array (
  9520. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9521. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9522. 'groupby' => 'cid,itemCategory,Month(date)',
  9523. 'asArray' => true
  9524. ) );
  9525. $LcategoryList = $Lcategory->find ( array (
  9526. 'asArray' => true
  9527. ) );
  9528. $staffList = $staff->find ( array (
  9529. 'asArray' => true
  9530. ) );
  9531. $htmlArray = array ();
  9532. foreach ( $LcategoryList as $value ) {
  9533. $htmlArray [$value ['title']] = array ();
  9534. foreach ( $staffList as $v ) {
  9535. if ($value ['cid'] == $v ['cid']) {
  9536. $html = "";
  9537. $falg = true;
  9538. $staffSumPrice = 0;
  9539. foreach ( $itemStatisticsList as $a ) {
  9540. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9541. if (empty ( $a ['price'] )) {
  9542. $html .= '<td class="taR">-</td>';
  9543. $falg = false;
  9544. break;
  9545. } else {
  9546. $staffSumPrice += $a ['price'];
  9547. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9548. $falg = false;
  9549. break;
  9550. }
  9551. }
  9552. }
  9553. if ($falg) {
  9554. $html .= '<td class="taR">-</td>';
  9555. $falg = true;
  9556. }
  9557. $falg = true;
  9558. foreach ( $itemStatisticsList as $a ) {
  9559. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9560. if (empty ( $a ['price'] )) {
  9561. $html .= '<td class="taR">-</td>';
  9562. $falg = false;
  9563. break;
  9564. } else {
  9565. $staffSumPrice += $a ['price'];
  9566. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9567. $falg = false;
  9568. break;
  9569. }
  9570. }
  9571. }
  9572. if ($falg) {
  9573. $html .= '<td class="taR">-</td>';
  9574. $falg = true;
  9575. }
  9576. $falg = true;
  9577. foreach ( $itemStatisticsList as $a ) {
  9578. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9579. if (empty ( $a ['price'] )) {
  9580. $html .= '<td class="taR">-</td>';
  9581. $falg = false;
  9582. break;
  9583. } else {
  9584. $staffSumPrice += $a ['price'];
  9585. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9586. $falg = false;
  9587. break;
  9588. }
  9589. }
  9590. }
  9591. if ($falg) {
  9592. $html .= '<td class="taR">-</td>';
  9593. $falg = true;
  9594. }
  9595. $falg = true;
  9596. foreach ( $itemStatisticsList as $a ) {
  9597. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9598. if (! empty ( $a ['price'] )) {
  9599. $staffSumPrice += $a ['price'];
  9600. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9601. $falg = false;
  9602. break;
  9603. } else {
  9604. $html .= '<td class="taR">-</td>';
  9605. $falg = false;
  9606. break;
  9607. }
  9608. }
  9609. }
  9610. if ($falg) {
  9611. $html .= '<td class="taR">-</td>';
  9612. $falg = true;
  9613. }
  9614. $falg = true;
  9615. foreach ( $itemStatisticsList as $a ) {
  9616. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9617. if (! empty ( $a ['price'] )) {
  9618. $staffSumPrice += $a ['price'];
  9619. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9620. $falg = false;
  9621. break;
  9622. } else {
  9623. $html .= '<td class="taR">-</td>';
  9624. $falg = false;
  9625. break;
  9626. }
  9627. }
  9628. }
  9629. if ($falg) {
  9630. $html .= '<td class="taR">-</td>';
  9631. $falg = true;
  9632. }
  9633. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9634. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9635. }
  9636. }
  9637. /* -- --- */
  9638. // 合计费用
  9639. $cateHtml = "";
  9640. $catePrice = 0;
  9641. $cateFalg = true;
  9642. foreach ( $itemCategoryList as $l ) {
  9643. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9644. if (empty ( $l ['price'] )) {
  9645. $cateHtml .= '<td class="colGreen taR">-</td>';
  9646. $cateFalg = false;
  9647. break;
  9648. } else {
  9649. $catePrice += $l ['price'];
  9650. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9651. $cateFalg = false;
  9652. break;
  9653. }
  9654. }
  9655. }
  9656. if ($cateFalg) {
  9657. $cateHtml .= '<td class="colGreen taR">-</td>';
  9658. $cateFalg = true;
  9659. }
  9660. $cateFalg = true;
  9661. foreach ( $itemCategoryList as $l ) {
  9662. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9663. if (empty ( $l ['price'] )) {
  9664. $cateHtml .= '<td class="colGreen taR">-</td>';
  9665. $cateFalg = false;
  9666. break;
  9667. } else {
  9668. $catePrice += $l ['price'];
  9669. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9670. $cateFalg = false;
  9671. break;
  9672. }
  9673. }
  9674. }
  9675. if ($cateFalg) {
  9676. $cateHtml .= '<td class="colGreen taR">-</td>';
  9677. $cateFalg = true;
  9678. }
  9679. $cateFalg = true;
  9680. foreach ( $itemCategoryList as $l ) {
  9681. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9682. if (empty ( $l ['price'] )) {
  9683. $cateHtml .= '<td class="colGreen taR">-</td>';
  9684. $cateFalg = false;
  9685. break;
  9686. } else {
  9687. $catePrice += $l ['price'];
  9688. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9689. $cateFalg = false;
  9690. break;
  9691. }
  9692. }
  9693. }
  9694. if ($cateFalg) {
  9695. $cateHtml .= '<td class="colGreen taR">-</td>';
  9696. $cateFalg = true;
  9697. }
  9698. $cateFalg = true;
  9699. foreach ( $itemCategoryList as $l ) {
  9700. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  9701. if (empty ( $l ['price'] )) {
  9702. $cateHtml .= '<td class="colGreen taR">-</td>';
  9703. $cateFalg = false;
  9704. break;
  9705. } else {
  9706. $catePrice += $l ['price'];
  9707. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9708. $cateFalg = false;
  9709. break;
  9710. }
  9711. }
  9712. }
  9713. if ($cateFalg) {
  9714. $cateHtml .= '<td class="colGreen taR">-</td>';
  9715. $cateFalg = true;
  9716. }
  9717. $cateFalg = true;
  9718. foreach ( $itemCategoryList as $l ) {
  9719. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  9720. if (empty ( $l ['price'] )) {
  9721. $cateHtml .= '<td class="colGreen taR">-</td>';
  9722. $cateFalg = false;
  9723. break;
  9724. } else {
  9725. $catePrice += $l ['price'];
  9726. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9727. $cateFalg = false;
  9728. break;
  9729. }
  9730. }
  9731. }
  9732. if ($cateFalg) {
  9733. $cateHtml .= '<td class="colGreen taR">-</td>';
  9734. $cateFalg = true;
  9735. }
  9736. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  9737. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  9738. /* -- --- */
  9739. }
  9740. // print_r($htmlArray);die;
  9741. $data ['htmlArray'] = $htmlArray;
  9742. // statistics html
  9743. $stList = $statistics->getOne ( array (
  9744. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  9745. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9746. 'groupby' => 'Month(date)',
  9747. 'asArray' => true
  9748. ) );
  9749. if (empty ( $stList ))
  9750. $stList = array (
  9751. 'rePrice' => 0,
  9752. 'agPrice' => 0
  9753. );
  9754. $data ['stList'] = array (
  9755. 'rePrice' => $stList ['rePrice'],
  9756. 'agPrice' => $stList ['agPrice'],
  9757. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9758. );
  9759. $monthHtml = "";
  9760. for($i = 1; $i <= 12; $i ++) {
  9761. if ($i == $month)
  9762. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  9763. else
  9764. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  9765. }
  9766. $data ['monthHtml'] = $monthHtml;
  9767. $data ['year'] = $year;
  9768. $data ['month'] = $month;
  9769. $data ['memu'] = "receipt";
  9770. $data ['staff'] = $this->staff;
  9771. $data ['receiptMemu'] = 'companyCategoryCollect';
  9772. $data ['verifyId'] = $this->verifyId;
  9773. $data ['executeId'] = $this->executeId;
  9774. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  9775. Doo::loadModel ( 'receipt' );
  9776. $receipt = new receipt ();
  9777. $receiptList = $receipt->find ( array (
  9778. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  9779. 'asArray' => true
  9780. ) );
  9781. if (empty ( $receiptList )) { // generated files
  9782. ob_start ();
  9783. $this->render ( "/admin/saeaStaffCollect", $data );
  9784. $this->cacheFile ( $path );
  9785. die ();
  9786. }
  9787. }
  9788. $this->render ( "/admin/saeaStaffCollect", $data );
  9789. }
  9790. /**
  9791. * 日常收支
  9792. */
  9793. function payments() {
  9794. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  9795. Doo::loadModel ( "execute" );
  9796. $execute = new execute ();
  9797. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  9798. die ( 'illegal request' );
  9799. }
  9800. Doo::loadModel ( "accountBook" );
  9801. $accountBook = new accountBook ();
  9802. Doo::loadModel ( "accountBookStatistics" );
  9803. $accountBookStatistics = new accountBookStatistics ();
  9804. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  9805. $list = $accountBook->getAccountBookByLimit ( 10 );
  9806. $data ['date'] = date ( "Y-m-d" );
  9807. $data ['statisticsList'] = $statisticsList;
  9808. $data ['list'] = $list;
  9809. $data ['memu'] = "receipt";
  9810. $data ['staff'] = $this->staff;
  9811. $data ['receiptMemu'] = 'payments';
  9812. $data ['verifyId'] = $this->verifyId;
  9813. $data ['executeId'] = $this->executeId;
  9814. $this->render ( "/expenses/payments", $data );
  9815. }
  9816. function paymentsIncomeDo() {
  9817. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  9818. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  9819. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  9820. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  9821. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  9822. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  9823. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  9824. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  9825. Doo::loadClass ( 'XDeode' );
  9826. $XDeode = new XDeode ( 5 );
  9827. Doo::loadModel ( "accountBook" );
  9828. Doo::loadModel ( "accountBookStatistics" );
  9829. Doo::loadModel ( 'wasteBook' );
  9830. // 记录流水时银行的转换
  9831. $accountBank = '';
  9832. if ($receivedBank == '纵横广发') {
  9833. $accountBank = 'CGBDeposit';
  9834. } elseif ($receivedBank == '纵横工行') {
  9835. $accountBank = 'ICBCDeposit';
  9836. } elseif ($receivedBank == '华润银行') {
  9837. $accountBank = 'HUADeposit';
  9838. } elseif ($receivedBank == '个人广发') {
  9839. $accountBank = 'PersonalDeposit';
  9840. }
  9841. if (empty ( $accountBank ))
  9842. die ( 'illegal request' );
  9843. // 收入为理财时特殊处理
  9844. if ($accountType == 7 || $accountType == 9) {
  9845. if ($receivedBank == '个人广发') {
  9846. die ( '个人广发 illegal request' );
  9847. }
  9848. // 添加一条收入
  9849. $accountBook = new accountBook ();
  9850. $accountBook->accountType = 10;
  9851. $accountBook->accountMsg = $accountMsg;
  9852. $accountBook->receivedPrice = $receivedPrice;
  9853. $accountBook->receivedMsg = $receivedMsg;
  9854. $accountBook->receivedBank = $receivedBank;
  9855. $accountBook->receivedDate = $receivedDate;
  9856. $accountBook->remarks = $remarks;
  9857. $accountBook->expensesType = 1;
  9858. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  9859. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  9860. $accountBook->inputStaff = $this->staff [0] ['sid'];
  9861. $inComeId = $accountBook->insert ();
  9862. // 收支汇总-添加一条收入日常汇总
  9863. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  9864. $accountBookStatistics = new accountBookStatistics ();
  9865. $item = array (
  9866. 'date' => date ( "Y-m-d" ),
  9867. 'accountType' => $abDetail ['accountType'],
  9868. 'accountMsg' => $abDetail ['accountMsg'],
  9869. 'aid' => $abDetail ['aid'],
  9870. 'inComePrice' => $abDetail ['receivedPrice'],
  9871. 'expensesType' => $abDetail ['expensesType']
  9872. );
  9873. $accountBookStatistics->setAccountBookStatistics ( $item );
  9874. // 添加收入流水
  9875. $wasteBook = new wasteBook ();
  9876. $itemWaste = array (
  9877. 'accountPriceShow' => $receivedPrice,
  9878. 'accountPrice' => $receivedPrice,
  9879. 'expensesType' => 1,
  9880. 'accountType' => 6, // 流水类型
  9881. 'dataID' => $inComeId,
  9882. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  9883. 'accountBank' => $accountBank,
  9884. 'category' => $this->staff [0] ['category'],
  9885. 'cid' => $this->staff [0] ['cid'],
  9886. 'name' => $this->staff [0] ['username'],
  9887. 'sid' => $this->staff [0] ['sid'],
  9888. 'inputDate' => date ( "Y-m-d H:i:s" )
  9889. );
  9890. $wasteBook->setAccountBookStatistics ( $itemWaste );
  9891. // 添加一条理财支出
  9892. $accountBank = 'CGBDeposit';
  9893. $expenditureBank = '纵横广发';
  9894. $dailyExpenditureType = 4;
  9895. if ($accountType == 9) {
  9896. $accountBank = 'ICBCDeposit';
  9897. $expenditureBank = '纵横工行';
  9898. $dailyExpenditureType = 6;
  9899. }
  9900. $accountBook = new accountBook ();
  9901. $accountBook->expensesType = 2;
  9902. $accountBook->expenditureType = $dailyExpenditureType;
  9903. $accountBook->expenditureMsg = $accountMsg;
  9904. $accountBook->expenditurePrice = $receivedPrice;
  9905. $accountBook->expenditureBank = $expenditureBank;
  9906. $accountBook->expenditureDate = $receivedDate;
  9907. $accountBook->remarks = $remarks;
  9908. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  9909. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  9910. $accountBook->inputStaff = $this->staff [0] ['sid'];
  9911. $id = $accountBook->insert ();
  9912. // 收支汇总-添加一条理财支出汇总
  9913. $abDetail = $accountBook->getAccountBookByAid ( $id );
  9914. $accountBookStatistics = new accountBookStatistics ();
  9915. $item = array (
  9916. 'date' => date ( "Y-m-d" ),
  9917. 'accountType' => $abDetail ['accountType'],
  9918. 'accountMsg' => $abDetail ['accountMsg'],
  9919. 'aid' => $abDetail ['aid'],
  9920. 'financingPrice' => - $receivedPrice,
  9921. 'expensesType' => 3
  9922. );
  9923. $accountBookStatistics->setAccountBookStatistics ( $item );
  9924. // 添加一条支出理财流水
  9925. $accountTypeWaste = 5;
  9926. if ($accountMsg == '公司固定') {
  9927. $accountTypeWaste = 9;
  9928. } elseif ($accountMsg == '公司活期') {
  9929. $accountTypeWaste = 10;
  9930. } elseif ($accountMsg == '个人(GR)') {
  9931. $accountBank = 'PersonalDeposit';
  9932. }
  9933. $itemWaste = array (
  9934. 'expensesType' => 2,
  9935. 'accountType' => $accountTypeWaste,
  9936. 'accountPriceShow' => $receivedPrice,
  9937. 'accountPrice' => - $receivedPrice,
  9938. 'dataID' => $id,
  9939. 'dailyExpenditureType' => $dailyExpenditureType,
  9940. 'accountBank' => $accountBank,
  9941. 'category' => $this->staff [0] ['category'],
  9942. 'cid' => $this->staff [0] ['cid'],
  9943. 'name' => $this->staff [0] ['username'],
  9944. 'sid' => $this->staff [0] ['sid'],
  9945. 'inputDate' => date ( "Y-m-d H:i:s" )
  9946. );
  9947. $wasteBook->setAccountBookStatistics ( $itemWaste );
  9948. } elseif ($accountType == 1) {
  9949. if ($receivedBank == '个人广发')
  9950. die ( 'illegal request' );
  9951. // 添加一条收入
  9952. $accountBook = new accountBook ();
  9953. $accountBook->accountType = $accountType;
  9954. $accountBook->accountMsg = $accountMsg;
  9955. $accountBook->receivedPrice = $receivedPrice;
  9956. $accountBook->receivedMsg = $receivedMsg;
  9957. $accountBook->receivedBank = $receivedBank;
  9958. $accountBook->receivedDate = $receivedDate;
  9959. $accountBook->remarks = $remarks;
  9960. $accountBook->expensesType = 1;
  9961. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  9962. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  9963. $accountBook->inputStaff = $this->staff [0] ['sid'];
  9964. $id = $accountBook->insert ();
  9965. $abDetail = $accountBook->getAccountBookByAid ( $id );
  9966. // 收支汇总-添加一条收入日常汇总
  9967. $accountBookStatistics = new accountBookStatistics ();
  9968. $item = array (
  9969. 'date' => date ( "Y-m-d" ),
  9970. 'accountType' => $abDetail ['accountType'],
  9971. 'accountMsg' => $abDetail ['accountMsg'],
  9972. 'aid' => $abDetail ['aid'],
  9973. 'expensesType' => $abDetail ['expensesType']
  9974. );
  9975. if ($abDetail ['accountType'] == 8) {
  9976. $item += array (
  9977. 'inComePrice' => $abDetail ['receivedPrice']
  9978. );
  9979. } else {
  9980. $item += array (
  9981. 'inComePrice' => $abDetail ['receivedPrice']
  9982. );
  9983. }
  9984. $accountBookStatistics->setAccountBookStatistics ( $item );
  9985. // 流水存储方向
  9986. $itemWaste = array (
  9987. 'accountType' => 6
  9988. ); // 流水类型
  9989. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  9990. // }else
  9991. if ($accountMsg == '活期理财收益') {
  9992. $itemWaste = array (
  9993. 'accountType' => 10
  9994. ); // 流水类型
  9995. }
  9996. // 添加收入流水
  9997. $wasteBook = new wasteBook ();
  9998. $itemWaste += array (
  9999. 'accountPrice' => $receivedPrice,
  10000. 'accountPriceShow' => $receivedPrice,
  10001. 'expensesType' => 1,
  10002. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10003. 'dataID' => $id,
  10004. 'accountBank' => $accountBank,
  10005. 'category' => $this->staff [0] ['category'],
  10006. 'cid' => $this->staff [0] ['cid'],
  10007. 'name' => $this->staff [0] ['username'],
  10008. 'sid' => $this->staff [0] ['sid'],
  10009. 'inputDate' => date ( "Y-m-d H:i:s" )
  10010. );
  10011. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10012. } else { // 普通日常收入处理
  10013. // 添加一条收入
  10014. $accountBook = new accountBook ();
  10015. $accountBook->accountType = $accountType;
  10016. $accountBook->accountMsg = $accountMsg;
  10017. $accountBook->receivedPrice = $receivedPrice;
  10018. $accountBook->receivedMsg = $receivedMsg;
  10019. $accountBook->receivedBank = $receivedBank;
  10020. $accountBook->receivedDate = $receivedDate;
  10021. $accountBook->remarks = $remarks;
  10022. $accountBook->expensesType = 1;
  10023. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10024. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10025. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10026. $id = $accountBook->insert ();
  10027. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10028. // 收支汇总-添加一条收入日常汇总
  10029. $accountBookStatistics = new accountBookStatistics ();
  10030. $item = array (
  10031. 'date' => date ( "Y-m-d" ),
  10032. 'accountType' => $abDetail ['accountType'],
  10033. 'accountMsg' => $abDetail ['accountMsg'],
  10034. 'aid' => $abDetail ['aid'],
  10035. 'expensesType' => $abDetail ['expensesType']
  10036. );
  10037. if ($abDetail ['accountType'] == 8) {
  10038. $item += array (
  10039. 'inComePrice' => $abDetail ['receivedPrice']
  10040. );
  10041. } else {
  10042. $item += array (
  10043. 'inComePrice' => $abDetail ['receivedPrice']
  10044. );
  10045. }
  10046. $accountBookStatistics->setAccountBookStatistics ( $item );
  10047. // 添加收入流水
  10048. $itemWaste = array (
  10049. 'accountPrice' => $receivedPrice
  10050. );
  10051. if ($receivedBank == '个人广发') {
  10052. $itemWaste = array (
  10053. 'accountPrice' => - $receivedPrice
  10054. );
  10055. }
  10056. $wasteBook = new wasteBook ();
  10057. $itemWaste += array (
  10058. 'accountPriceShow' => $receivedPrice,
  10059. 'expensesType' => 1,
  10060. 'accountType' => 6, // 流水类型
  10061. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10062. 'dataID' => $id,
  10063. 'accountBank' => $accountBank,
  10064. 'category' => $this->staff [0] ['category'],
  10065. 'cid' => $this->staff [0] ['cid'],
  10066. 'name' => $this->staff [0] ['username'],
  10067. 'sid' => $this->staff [0] ['sid'],
  10068. 'inputDate' => date ( "Y-m-d H:i:s" )
  10069. );
  10070. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10071. }
  10072. }
  10073. return '/payments';
  10074. }
  10075. /**
  10076. * 添加收入
  10077. * @return string
  10078. */
  10079. function paymentsIncomeDo_() {
  10080. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10081. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10082. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10083. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10084. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10085. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10086. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10087. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10088. Doo::loadClass ( 'XDeode' );
  10089. $XDeode = new XDeode ( 5 );
  10090. Doo::loadModel ( "accountBook" );
  10091. $accountBook = new accountBook ();
  10092. $accountBank = '';
  10093. $accountTypeWaste = 6;
  10094. if ($receivedBank == '纵横广发') {
  10095. $accountBank = 'CGBDeposit';
  10096. } elseif ($receivedBank == '纵横工行') {
  10097. $accountBank = 'ICBCDeposit';
  10098. } elseif ($receivedBank == '华润银行') {
  10099. $accountBank = 'HUADeposit';
  10100. } elseif ($receivedBank == '个人广发') {
  10101. $accountBank = 'PersonalDeposit';
  10102. }
  10103. if (empty ( $accountBank ))
  10104. die ( 'illegal request' );
  10105. $dailyIncomeType = '';
  10106. $itemWaste = array (
  10107. 'accountPrice' => $receivedPrice,
  10108. 'expensesType' => 1
  10109. );
  10110. if ($receivedBank == '个人广发') {
  10111. $itemWaste = array (
  10112. 'accountPrice' => - $receivedPrice,
  10113. 'expensesType' => 1
  10114. );
  10115. }
  10116. if ($accountType == 4) {
  10117. $dailyIncomeType = 4;
  10118. } elseif ($accountType == 1) {
  10119. $dailyIncomeType = 1;
  10120. } elseif ($accountType == 2) {
  10121. $dailyIncomeType = 2;
  10122. } elseif ($accountType == 3) {
  10123. $dailyIncomeType = 3;
  10124. } elseif ($accountType == 5) {
  10125. $dailyIncomeType = 5;
  10126. } elseif ($accountType == 6) {
  10127. $dailyIncomeType = 6;
  10128. } elseif ($accountType == 7 || $accountType == 9) {
  10129. $dailyIncomeType = 7;
  10130. if ($accountMsg == '公司固定') {
  10131. $accountTypeWaste = 9;
  10132. } elseif ($accountMsg == '公司活期') {
  10133. $accountTypeWaste = 10;
  10134. } elseif ($accountMsg == '个人(GR)') {
  10135. $accountBank = 'PersonalDeposit';
  10136. }
  10137. $itemWaste = array (
  10138. 'accountPrice' => - $receivedPrice,
  10139. 'expensesType' => 2
  10140. );
  10141. } elseif ($accountType == 8) {
  10142. $dailyIncomeType = 8;
  10143. }
  10144. if (empty ( $dailyIncomeType ))
  10145. die ( 'illegal request' );
  10146. $accountBook->accountType = $accountType;
  10147. $accountBook->accountMsg = $accountMsg;
  10148. $accountBook->receivedPrice = $receivedPrice;
  10149. $accountBook->receivedMsg = $receivedMsg;
  10150. $accountBook->receivedBank = $receivedBank;
  10151. $accountBook->receivedDate = $receivedDate;
  10152. $accountBook->remarks = $remarks;
  10153. $accountBook->expensesType = 1;
  10154. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10155. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10156. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10157. $id = $accountBook->insert ();
  10158. //
  10159. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10160. // 收支汇总
  10161. Doo::loadModel ( "accountBookStatistics" );
  10162. $accountBookStatistics = new accountBookStatistics ();
  10163. $item = array (
  10164. 'date' => date ( "Y-m-d" ),
  10165. 'accountType' => $abDetail ['accountType'],
  10166. 'accountMsg' => $abDetail ['accountMsg'],
  10167. 'aid' => $abDetail ['aid']
  10168. );
  10169. if ($abDetail ['expensesType'] == 1) {
  10170. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10171. $item += array (
  10172. 'financingPrice' => - $receivedPrice,
  10173. 'expensesType' => 3
  10174. );
  10175. } else if ($abDetail ['accountType'] == 8) {
  10176. $item += array (
  10177. 'inComePrice' => - $abDetail ['receivedPrice'],
  10178. 'expensesType' => $abDetail ['expensesType']
  10179. );
  10180. } else {
  10181. $item += array (
  10182. 'inComePrice' => $abDetail ['receivedPrice'],
  10183. 'expensesType' => $abDetail ['expensesType']
  10184. );
  10185. }
  10186. }
  10187. $accountBookStatistics->setAccountBookStatistics ( $item );
  10188. // 为理财时需添加一条日常支出
  10189. if ($accountType == 7 || $accountType == 9) {
  10190. }
  10191. // 公司流水记录
  10192. Doo::loadModel ( 'wasteBook' );
  10193. $wasteBook = new wasteBook ();
  10194. // 银行
  10195. // if (empty($abDetail)){
  10196. $itemWaste += array (
  10197. 'accountPriceShow' => $receivedPrice,
  10198. 'dataID' => $id,
  10199. 'accountType' => $accountTypeWaste,
  10200. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10201. 'accountBank' => $accountBank,
  10202. 'category' => $this->staff [0] ['category'],
  10203. 'cid' => $this->staff [0] ['cid'],
  10204. 'name' => $this->staff [0] ['username'],
  10205. 'sid' => $this->staff [0] ['sid'],
  10206. 'inputDate' => date ( "Y-m-d H:i:s" )
  10207. );
  10208. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10209. // }
  10210. // 类型为理财7或者9 要添加一笔理财支出
  10211. if ($accountType == 7 || $accountType == 9) {
  10212. $accountBank = 'CGBDeposit';
  10213. $expenditureBank = '纵横广发';
  10214. $dailyExpenditureType = 4;
  10215. if ($accountType == 9) {
  10216. $accountBank = 'ICBCDeposit';
  10217. $expenditureBank = '纵横工行';
  10218. $dailyExpenditureType = 6;
  10219. }
  10220. // 添加一条支出
  10221. $accountBook = new accountBook ();
  10222. $accountBook->expenditureType = $dailyExpenditureType;
  10223. $accountBook->expenditureMsg = $accountMsg;
  10224. $accountBook->expenditurePrice = $receivedPrice;
  10225. $accountBook->expenditureBank = $expenditureBank;
  10226. $accountBook->expenditureDate = $receivedDate;
  10227. $accountBook->remarks = $remarks;
  10228. $accountBook->expensesType = 2;
  10229. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10230. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10231. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10232. $id = $accountBook->insert ();
  10233. // 添加一条收入流水
  10234. $itemWaste = array (
  10235. 'accountPriceShow' => $receivedPrice,
  10236. 'accountPrice' => $receivedPrice,
  10237. 'dataID' => $id,
  10238. 'expensesType' => 2,
  10239. 'accountType' => $accountTypeWaste,
  10240. 'dailyExpenditureType' => $dailyExpenditureType,
  10241. 'accountBank' => $accountBank,
  10242. 'category' => $this->staff [0] ['category'],
  10243. 'cid' => $this->staff [0] ['cid'],
  10244. 'name' => $this->staff [0] ['username'],
  10245. 'sid' => $this->staff [0] ['sid'],
  10246. 'inputDate' => date ( "Y-m-d H:i:s" )
  10247. );
  10248. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10249. }
  10250. }
  10251. return '/payments';
  10252. }
  10253. function paymentsExpenditureDo() {
  10254. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10255. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10256. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10257. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10258. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10259. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10260. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10261. // 理财支出特殊处理
  10262. Doo::loadModel ( "accountBook" );
  10263. Doo::loadModel ( "accountBookStatistics" );
  10264. Doo::loadModel ( 'wasteBook' );
  10265. $accountBank = '';
  10266. if ($expenditureBank == '纵横广发') {
  10267. $accountBank = 'CGBDeposit';
  10268. } elseif ($expenditureBank == '纵横工行') {
  10269. $accountBank = 'ICBCDeposit';
  10270. } elseif ($expenditureBank == '华润银行') {
  10271. $accountBank = 'HUADeposit';
  10272. } elseif ($expenditureBank == '个人广发') {
  10273. $accountBank = 'PersonalDeposit';
  10274. }
  10275. if (empty ( $accountBank ))
  10276. die ( 'illegal request' );
  10277. if ($expenditureType == 4 || $expenditureType == 6) {
  10278. if ($expenditureBank == '个人广发') {
  10279. die ( '个人广发 illegal request' );
  10280. }
  10281. // 添加一笔日常支出
  10282. $accountBook = new accountBook ();
  10283. $accountBook->expensesType = 2;
  10284. $accountBook->expenditureType = 7;
  10285. $accountBook->expenditureMsg = $expenditureMsg;
  10286. $accountBook->expenditurePrice = $expenditurePrice;
  10287. $accountBook->expenditureBank = $expenditureBank;
  10288. $accountBook->expenditureDate = $expenditureDate;
  10289. $accountBook->remarks = $remarks;
  10290. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10291. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10292. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10293. $expenditureId = $accountBook->insert ();
  10294. // 添加日常支出汇总
  10295. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10296. $accountBookStatistics = new accountBookStatistics ();
  10297. $item = array (
  10298. 'date' => date ( "Y-m-d" ),
  10299. 'expenditureType' => $abDetail ['expenditureType'],
  10300. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10301. 'aid' => $abDetail ['aid'],
  10302. 'payPrice' => $abDetail ['expenditurePrice'],
  10303. 'expensesType' => $abDetail ['expensesType']
  10304. );
  10305. $accountBookStatistics->setAccountBookStatistics ( $item );
  10306. // 公司日常支出流水
  10307. $wasteBook = new wasteBook ();
  10308. $itemWaste = array (
  10309. 'accountPrice' => - $expenditurePrice
  10310. );
  10311. if ($expenditureBank == '个人广发') {
  10312. $itemWaste = array (
  10313. 'accountPrice' => $expenditurePrice
  10314. );
  10315. }
  10316. $itemWaste += array (
  10317. 'expensesType' => 2,
  10318. 'accountType' => 5,
  10319. 'dailyExpenditureType' => $expenditureType,
  10320. 'accountPriceShow' => $expenditurePrice,
  10321. 'accountPrice' => - $expenditurePrice,
  10322. 'dataID' => $expenditureId,
  10323. 'accountBank' => $accountBank,
  10324. 'category' => $this->staff [0] ['category'],
  10325. 'cid' => $this->staff [0] ['cid'],
  10326. 'name' => $this->staff [0] ['username'],
  10327. 'sid' => $this->staff [0] ['sid'],
  10328. 'inputDate' => date ( "Y-m-d H:i:s" )
  10329. );
  10330. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10331. // 添加一笔理财收入
  10332. $accountBank = 'CGBDeposit';
  10333. $dailyIncomeType = 7;
  10334. $receivedBank = '纵横广发';
  10335. if ($expenditureType == 6) {
  10336. $accountBank = 'ICBCDeposit';
  10337. $receivedBank = '纵横工行';
  10338. $dailyIncomeType = 9;
  10339. }
  10340. $accountBook = new accountBook ();
  10341. $accountBook->expensesType = 1;
  10342. $accountBook->accountType = $dailyIncomeType;
  10343. $accountBook->accountMsg = $expenditureMsg;
  10344. $accountBook->receivedPrice = $expenditurePrice;
  10345. $accountBook->receivedBank = $receivedBank;
  10346. $accountBook->receivedDate = $expenditureDate;
  10347. $accountBook->remarks = $remarks;
  10348. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10349. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10350. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10351. $id = $accountBook->insert ();
  10352. // 添加日常理财收入汇总
  10353. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10354. $accountBookStatistics = new accountBookStatistics ();
  10355. $item = array (
  10356. 'date' => date ( "Y-m-d" ),
  10357. 'expenditureType' => $abDetail ['expenditureType'],
  10358. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10359. 'aid' => $abDetail ['aid'],
  10360. 'financingPrice' => $expenditurePrice,
  10361. 'expensesType' => 3
  10362. );
  10363. $accountBookStatistics->setAccountBookStatistics ( $item );
  10364. // 添加一笔收入流水
  10365. if ($expenditureMsg == '公司固定') {
  10366. $accountTypeWaste = 9;
  10367. } elseif ($expenditureMsg == '公司活期') {
  10368. $accountTypeWaste = 10;
  10369. } elseif ($expenditureMsg == '个人(GR)') {
  10370. $accountBank = 'PersonalDeposit';
  10371. }
  10372. $itemWaste = array (
  10373. 'expensesType' => 1,
  10374. 'accountType' => $accountTypeWaste,
  10375. 'accountPriceShow' => $expenditurePrice,
  10376. 'accountPrice' => $expenditurePrice,
  10377. 'dataID' => $id,
  10378. 'dailyIncomeType' => $dailyIncomeType,
  10379. 'accountBank' => $accountBank,
  10380. 'category' => $this->staff [0] ['category'],
  10381. 'cid' => $this->staff [0] ['cid'],
  10382. 'name' => $this->staff [0] ['username'],
  10383. 'sid' => $this->staff [0] ['sid'],
  10384. 'inputDate' => date ( "Y-m-d H:i:s" )
  10385. );
  10386. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10387. } else {
  10388. // 添加一笔日常支出
  10389. $accountBook = new accountBook ();
  10390. $accountBook->expensesType = 2;
  10391. $accountBook->expenditureType = $expenditureType;
  10392. $accountBook->expenditureMsg = $expenditureMsg;
  10393. $accountBook->expenditurePrice = $expenditurePrice;
  10394. $accountBook->expenditureBank = $expenditureBank;
  10395. $accountBook->expenditureDate = $expenditureDate;
  10396. $accountBook->remarks = $remarks;
  10397. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10398. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10399. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10400. $id = $accountBook->insert ();
  10401. // 添加日常支出汇总
  10402. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10403. $accountBookStatistics = new accountBookStatistics ();
  10404. $item = array (
  10405. 'date' => date ( "Y-m-d" ),
  10406. 'expenditureType' => $abDetail ['expenditureType'],
  10407. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10408. 'aid' => $abDetail ['aid'],
  10409. 'expensesType' => $abDetail ['expensesType']
  10410. );
  10411. if ($expenditureType == 5) {
  10412. $item += array (
  10413. 'payPrice' => - $abDetail ['expenditurePrice']
  10414. );
  10415. } else {
  10416. $item += array (
  10417. 'payPrice' => $abDetail ['expenditurePrice']
  10418. );
  10419. }
  10420. $accountBookStatistics->setAccountBookStatistics ( $item );
  10421. // 公司日常支出流水
  10422. $wasteBook = new wasteBook ();
  10423. $itemWaste = array (
  10424. 'accountPrice' => - $expenditurePrice
  10425. );
  10426. if ($expenditureBank == '个人广发') {
  10427. $itemWaste = array (
  10428. 'accountPrice' => $expenditurePrice
  10429. );
  10430. }
  10431. $itemWaste += array (
  10432. 'expensesType' => 2,
  10433. 'accountType' => 5,
  10434. 'accountPriceShow' => $expenditurePrice,
  10435. 'dataID' => $id,
  10436. 'dailyExpenditureType' => $expenditureType,
  10437. 'accountBank' => $accountBank,
  10438. 'category' => $this->staff [0] ['category'],
  10439. 'cid' => $this->staff [0] ['cid'],
  10440. 'name' => $this->staff [0] ['username'],
  10441. 'sid' => $this->staff [0] ['sid'],
  10442. 'inputDate' => date ( "Y-m-d H:i:s" )
  10443. );
  10444. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10445. }
  10446. }
  10447. return '/payments';
  10448. }
  10449. /**
  10450. * 添加支出
  10451. */
  10452. function paymentsExpenditureDo_() {
  10453. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10454. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10455. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10456. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10457. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10458. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10459. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10460. $dailyExpenditureType = '';
  10461. $accountTypeWaste = 5;
  10462. $accountBank = '';
  10463. if ($expenditureBank == '纵横广发') {
  10464. $accountBank = 'CGBDeposit';
  10465. } elseif ($expenditureBank == '纵横工行') {
  10466. $accountBank = 'ICBCDeposit';
  10467. } elseif ($expenditureBank == '华润银行') {
  10468. $accountBank = 'HUADeposit';
  10469. } elseif ($expenditureBank == '个人广发') {
  10470. $accountBank = 'PersonalDeposit';
  10471. }
  10472. if (empty ( $accountBank ))
  10473. die ( 'illegal request' );
  10474. $itemWaste = array (
  10475. 'accountPrice' => - $expenditurePrice
  10476. );
  10477. if ($expenditureBank == '个人广发') {
  10478. $itemWaste = array (
  10479. 'accountPrice' => $expenditurePrice
  10480. );
  10481. }
  10482. if ($expenditureType == 4 || $expenditureType == 6) {
  10483. $dailyExpenditureType = 4;
  10484. if ($expenditureMsg == '公司固定') {
  10485. $accountTypeWaste = 9;
  10486. } elseif ($expenditureMsg == '公司活期') {
  10487. $accountTypeWaste = 10;
  10488. } elseif ($expenditureMsg == '个人(GR)') {
  10489. $accountBank = 'PersonalDeposit';
  10490. }
  10491. $itemWaste = array (
  10492. 'accountPrice' => $expenditurePrice
  10493. );
  10494. } elseif ($expenditureType == 1) {
  10495. $dailyExpenditureType = 1;
  10496. } elseif ($expenditureType == 2) {
  10497. $dailyExpenditureType = 2;
  10498. } elseif ($expenditureType == 3) {
  10499. $dailyExpenditureType = 3;
  10500. } elseif ($expenditureType == 5) {
  10501. $dailyExpenditureType = 5;
  10502. }
  10503. if (empty ( $dailyExpenditureType ))
  10504. die ( 'illegal request' );
  10505. Doo::loadModel ( "accountBook" );
  10506. $accountBook = new accountBook ();
  10507. $accountBook->expenditureType = $expenditureType;
  10508. $accountBook->expenditureMsg = $expenditureMsg;
  10509. $accountBook->expenditurePrice = $expenditurePrice;
  10510. $accountBook->expenditureBank = $expenditureBank;
  10511. $accountBook->expenditureDate = $expenditureDate;
  10512. $accountBook->remarks = $remarks;
  10513. $accountBook->expensesType = 2;
  10514. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10515. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10516. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10517. $id = $accountBook->insert ();
  10518. //
  10519. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10520. Doo::loadModel ( "accountBookStatistics" );
  10521. $accountBookStatistics = new accountBookStatistics ();
  10522. $item = array (
  10523. 'date' => date ( "Y-m-d" ),
  10524. 'expenditureType' => $abDetail ['expenditureType'],
  10525. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10526. 'aid' => $abDetail ['aid']
  10527. );
  10528. if ($abDetail ['expensesType'] == 2) {
  10529. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10530. $item += array (
  10531. 'financingPrice' => $expenditurePrice,
  10532. 'expensesType' => 3
  10533. );
  10534. } elseif ($abDetail ['expenditureType'] == 5) {
  10535. $item += array (
  10536. 'payPrice' => $abDetail ['expenditurePrice'],
  10537. 'expensesType' => $abDetail ['expensesType']
  10538. );
  10539. } else {
  10540. $item += array (
  10541. 'payPrice' => $abDetail ['expenditurePrice'],
  10542. 'expensesType' => $abDetail ['expensesType']
  10543. );
  10544. }
  10545. }
  10546. $accountBookStatistics->setAccountBookStatistics ( $item );
  10547. // 公司流水记录
  10548. Doo::loadModel ( 'wasteBook' );
  10549. $wasteBook = new wasteBook ();
  10550. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10551. // 银行
  10552. if (empty ( $abDetail )) {
  10553. $itemWaste += array (
  10554. 'accountPriceShow' => $expenditurePrice,
  10555. 'dataID' => $id,
  10556. 'expensesType' => 2,
  10557. 'accountType' => $accountTypeWaste,
  10558. 'dailyExpenditureType' => $expenditureType,
  10559. 'accountBank' => $accountBank,
  10560. 'category' => $this->staff [0] ['category'],
  10561. 'cid' => $this->staff [0] ['cid'],
  10562. 'name' => $this->staff [0] ['username'],
  10563. 'sid' => $this->staff [0] ['sid'],
  10564. 'inputDate' => date ( "Y-m-d H:i:s" )
  10565. );
  10566. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10567. }
  10568. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10569. if ($expenditureType == 4 || $expenditureType == 6) {
  10570. $accountBank = 'CGBDeposit';
  10571. $dailyIncomeType = 7;
  10572. $receivedBank = '纵横广发';
  10573. if ($expenditureType == 6) {
  10574. $accountBank = 'ICBCDeposit';
  10575. $receivedBank = '纵横工行';
  10576. $dailyIncomeType = 9;
  10577. }
  10578. // 添加一笔收入
  10579. $accountBook = new accountBook ();
  10580. $accountBook->accountType = $dailyIncomeType;
  10581. $accountBook->accountMsg = $expenditureMsg;
  10582. $accountBook->receivedPrice = $expenditurePrice;
  10583. $accountBook->receivedBank = $receivedBank;
  10584. $accountBook->receivedDate = $expenditureDate;
  10585. $accountBook->remarks = $remarks;
  10586. $accountBook->expensesType = 1;
  10587. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10588. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10589. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10590. $id = $accountBook->insert ();
  10591. // 添加一笔收入流水
  10592. $itemWaste = array (
  10593. 'accountPriceShow' => $expenditurePrice,
  10594. 'accountPrice' => - $expenditurePrice,
  10595. 'dataID' => $id,
  10596. 'expensesType' => 1,
  10597. 'accountType' => $accountTypeWaste,
  10598. 'dailyIncomeType' => $dailyIncomeType,
  10599. 'accountBank' => $accountBank,
  10600. 'category' => $this->staff [0] ['category'],
  10601. 'cid' => $this->staff [0] ['cid'],
  10602. 'name' => $this->staff [0] ['username'],
  10603. 'sid' => $this->staff [0] ['sid'],
  10604. 'inputDate' => date ( "Y-m-d H:i:s" )
  10605. );
  10606. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10607. }
  10608. }
  10609. return '/payments';
  10610. }
  10611. /**
  10612. * 所有收支
  10613. */
  10614. function paymentsAchieve() {
  10615. $page_size = 12;
  10616. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10617. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10618. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10619. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10620. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10621. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10622. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10623. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10624. Doo::loadModel ( "accountBookStatistics" );
  10625. $accountBookStatistics = new accountBookStatistics ();
  10626. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10627. $data ['statisticsList'] = $statisticsList;
  10628. Doo::loadModel ( "accountBook" );
  10629. $accountBook = new accountBook ();
  10630. $con = '';
  10631. if ($expensesType == 'INCOME')
  10632. $con = ' and expensesType=1 ';
  10633. elseif ($expensesType == 'PAY')
  10634. $con = ' and expensesType=2 ';
  10635. $dateArr = explode ( ':', $date );
  10636. $D1 = $dateString = '';
  10637. $D2 = '';
  10638. if (! empty ( $date )) {
  10639. $D1 = $dateArr [0];
  10640. if (isset ( $dateArr [1] ))
  10641. $D2 = $dateArr [1];
  10642. else
  10643. $D2 = '';
  10644. $dateString = $D1 . " : " . $D2;
  10645. }
  10646. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10647. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10648. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10649. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10650. if (! empty ( $price ))
  10651. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10652. if ($submitType == 1) {
  10653. if ($accountType != '') {
  10654. $expenditureType = '';
  10655. $con .= ' and accountType=' . $accountType;
  10656. if (! empty ( $accountMsg ))
  10657. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10658. }
  10659. } elseif ($submitType == 2) {
  10660. if ($expenditureType != '') {
  10661. $accountType = $accountMsg = '';
  10662. $con .= ' and expenditureType=' . $expenditureType;
  10663. }
  10664. } else {
  10665. $accountType = $accountMsg = $expenditureType = '';
  10666. }
  10667. $sql = "" . $con;
  10668. $action = "paymentsAchieve";
  10669. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10670. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10671. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10672. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10673. $data ['expenditureType'] = $expenditureType;
  10674. $data ['accountMsg'] = $accountMsg;
  10675. $data ['accountType'] = $accountType;
  10676. $data ['inputDate'] = $date;
  10677. $data ['price'] = $price;
  10678. $data ['expensesType'] = $expensesType;
  10679. $data ['page'] = $pageinfo;
  10680. $data ['list'] = $list;
  10681. $data ['memu'] = "receipt";
  10682. $data ['staff'] = $this->staff;
  10683. $data ['receiptMemu'] = 'payments';
  10684. $data ['verifyId'] = $this->verifyId;
  10685. $data ['executeId'] = $this->executeId;
  10686. $this->render ( "/expenses/paymentsAchieve", $data );
  10687. }
  10688. function paymentsIncomeUpdateDo() {
  10689. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10690. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10691. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10692. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10693. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10694. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10695. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10696. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10697. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10698. Doo::loadClass ( 'XDeode' );
  10699. $XDeode = new XDeode ( 5 );
  10700. $aid = $XDeode->decode ( $aidKey );
  10701. Doo::loadModel ( "accountBook" );
  10702. $accountBook = new accountBook ();
  10703. //
  10704. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10705. $price = $receivedPrice - $abDetail [inComePrice];
  10706. Doo::loadModel ( "accountBookStatistics" );
  10707. $accountBookStatistics = new accountBookStatistics ();
  10708. if ($abDetail ['accountType'] == 7) {
  10709. $item += array (
  10710. 'date' => date ( "Y-m-d" ),
  10711. 'financingPrice' => - $price,
  10712. 'expensesType' => 3,
  10713. 'aid' => $abDetail ['aid']
  10714. );
  10715. } elseif ($abDetail ['accountType'] == 8) {
  10716. $item += array (
  10717. 'date' => date ( "Y-m-d" ),
  10718. 'expensesType' => $abDetail ['expensesType'],
  10719. 'inComePrice' => - $price,
  10720. 'aid' => $abDetail ['aid']
  10721. );
  10722. } else {
  10723. $item = array (
  10724. 'date' => date ( "Y-m-d" ),
  10725. 'expensesType' => $abDetail ['expensesType'],
  10726. 'inComePrice' => $price,
  10727. 'aid' => $abDetail ['aid']
  10728. );
  10729. }
  10730. $accountBookStatistics->setAccountBookStatistics ( $item );
  10731. $accountBook->accountType = $accountType;
  10732. $accountBook->accountMsg = $accountMsg;
  10733. $accountBook->receivedPrice = $receivedPrice;
  10734. $accountBook->receivedMsg = $receivedMsg;
  10735. $accountBook->receivedBank = $receivedBank;
  10736. $accountBook->receivedDate = $receivedDate;
  10737. $accountBook->remarks = $remarks;
  10738. $accountBook->aid = $aid;
  10739. $accountBook->update ();
  10740. }
  10741. return '/paymentsAchieve';
  10742. }
  10743. function paymentsExpenditureEdiDo() {
  10744. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10745. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10746. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10747. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10748. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10749. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10750. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10751. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10752. Doo::loadClass ( 'XDeode' );
  10753. $XDeode = new XDeode ( 5 );
  10754. $aid = $XDeode->decode ( $aidKey );
  10755. Doo::loadModel ( "accountBook" );
  10756. $accountBook = new accountBook ();
  10757. // 汇总信息
  10758. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10759. $price = $expenditurePrice - $abDetail [expenditurePrice];
  10760. Doo::loadModel ( "accountBookStatistics" );
  10761. $accountBookStatistics = new accountBookStatistics ();
  10762. if ($abDetail ['expenditureType'] == 4) {
  10763. $item += array (
  10764. 'date' => date ( "Y-m-d" ),
  10765. 'financingPrice' => $price,
  10766. 'expensesType' => 3,
  10767. 'aid' => $abDetail ['aid']
  10768. );
  10769. } elseif ($abDetail ['expenditureType'] == 5) {
  10770. $item += array (
  10771. 'date' => date ( "Y-m-d" ),
  10772. 'expensesType' => $abDetail ['expensesType'],
  10773. 'payPrice' => $price,
  10774. 'aid' => $abDetail ['aid']
  10775. );
  10776. } else {
  10777. $item = array (
  10778. 'date' => date ( "Y-m-d" ),
  10779. 'expensesType' => $abDetail ['expensesType'],
  10780. 'payPrice' => $price,
  10781. 'aid' => $abDetail ['aid']
  10782. );
  10783. }
  10784. $accountBookStatistics->setAccountBookStatistics ( $item );
  10785. //
  10786. $accountBook->expenditureType = $expenditureType;
  10787. $accountBook->expenditureMsg = $expenditureMsg;
  10788. $accountBook->expenditurePrice = $expenditurePrice;
  10789. $accountBook->expenditureBank = $expenditureBank;
  10790. $accountBook->remarks = $remarks;
  10791. $accountBook->expenditureDate = $expenditureDate;
  10792. $accountBook->aid = $aid;
  10793. $id = $accountBook->update ();
  10794. }
  10795. return '/paymentsAchieve';
  10796. }
  10797. function paymentsDelDo() {
  10798. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  10799. if (! empty ( $aidKey )) {
  10800. Doo::loadClass ( 'XDeode' );
  10801. $XDeode = new XDeode ( 5 );
  10802. $aid = $XDeode->decode ( $aidKey );
  10803. Doo::loadModel ( "accountBook" );
  10804. $accountBook = new accountBook ();
  10805. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  10806. if (empty ( $abDetail ))
  10807. die ( 'illegal request' );
  10808. // 删除收支
  10809. Doo::loadModel ( "accountBookStatistics" );
  10810. $accountBookStatistics = new accountBookStatistics ();
  10811. $item = array (
  10812. 'date' => date ( "Y-m-d" ),
  10813. 'aid' => $abDetail ['aid']
  10814. );
  10815. $accountType = '';
  10816. if ($abDetail ['expensesType'] == 1) {
  10817. $accountType = 6;
  10818. if ($abDetail ['accountType'] != 7) {
  10819. $item += array (
  10820. 'expensesType' => $abDetail ['expensesType'],
  10821. 'inComePrice' => - $abDetail ['receivedPrice']
  10822. );
  10823. } else {
  10824. $item += array (
  10825. 'financingPrice' => $abDetail ['receivedPrice'],
  10826. 'expensesType' => 3
  10827. );
  10828. }
  10829. } elseif ($abDetail ['expensesType'] == 2) {
  10830. $accountType = 5;
  10831. if ($abDetail ['accountType'] != 7) {
  10832. $item += array (
  10833. 'expensesType' => $abDetail ['expensesType'],
  10834. 'payPrice' => - $abDetail ['expenditurePrice']
  10835. );
  10836. } else {
  10837. $item += array (
  10838. 'financingPrice' => - $abDetail ['expenditurePrice'],
  10839. 'expensesType' => 3
  10840. );
  10841. }
  10842. }
  10843. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  10844. if ($abDetail ['expenditureMsg'] == '公司固定')
  10845. $accountType = 9;
  10846. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  10847. $accountType = 10;
  10848. }
  10849. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  10850. if ($abDetail ['accountMsg'] == '公司固定')
  10851. $accountType = 9;
  10852. elseif ($abDetail ['accountMsg'] == '公司活期')
  10853. $accountType = 10;
  10854. }
  10855. if ($abDetail ['accountMsg'] == '活期理财收益') {
  10856. $accountType = 10;
  10857. }
  10858. $accountBookStatistics->setAccountBookStatistics ( $item );
  10859. $accountBook->delete ( array (
  10860. 'where' => 'aid=' . $aid,
  10861. 'limit' => 1
  10862. ) );
  10863. // 删除收入流水
  10864. if (! empty ( $accountType )) {
  10865. Doo::loadModel ( 'wasteBook' );
  10866. $wasteBook = new wasteBook ();
  10867. $wasteBook->delete ( array (
  10868. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  10869. 'limit' => 1
  10870. ) );
  10871. }
  10872. }
  10873. return '/paymentsAchieve';
  10874. }
  10875. function paymentsCollect() {
  10876. Doo::loadModel ( "execute" );
  10877. $execute = new execute ();
  10878. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10879. die ( 'illegal request' );
  10880. }
  10881. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10882. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  10883. Doo::loadModel ( "accountBookStatistics" );
  10884. $accountBookStatistics = new accountBookStatistics ();
  10885. Doo::loadClass ( 'receipt.func' );
  10886. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  10887. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  10888. $data ['html'] = $html ['html'];
  10889. $data ['inSum'] = $html ['sum'];
  10890. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  10891. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  10892. $data ['payHtml'] = $html ['html'];
  10893. $data ['paySum'] = $html ['sum'];
  10894. // 余额统计
  10895. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  10896. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  10897. include './protected/config/wasteBook.conf.php';
  10898. Doo::loadModel ( 'wasteBook' );
  10899. $wasteBook = new wasteBook ();
  10900. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  10901. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  10902. // 获得年份之前所有金额
  10903. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  10904. // print_r($detail);
  10905. // $waste['total'];
  10906. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  10907. $inComeHtml = '<tr><th colspan="2">收入</th>';
  10908. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  10909. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  10910. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  10911. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  10912. $limitMonth = date ( 'm' ); // 限制显示月份参数
  10913. if (date ( 'Y' ) > $year) {
  10914. $limitMonth = 12;
  10915. }
  10916. for($i = 1; $i <= 12; $i ++) {
  10917. $inComeA = $payB = 0;
  10918. $falg = true;
  10919. foreach ( $inComePay as $key => $value ) {
  10920. if ($value ['month'] == $i) {
  10921. $falg = false;
  10922. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  10923. $inSum += $value ['accountPrice'];
  10924. $showInSum += $value ['accountPriceShow'];
  10925. $inComeA = $value ['accountPrice'];
  10926. break;
  10927. }
  10928. }
  10929. if ($falg)
  10930. $inComeHtml .= '<td class="taR">-</td>';
  10931. $payFalg = true;
  10932. foreach ( $pay as $key => $value ) {
  10933. if ($value ['month'] == $i) {
  10934. $payFalg = false;
  10935. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  10936. $paySum += $value ['accountPrice'];
  10937. $showPaySum += $value ['accountPriceShow'];
  10938. $payB = $value ['accountPrice'];
  10939. break;
  10940. }
  10941. }
  10942. if ($payFalg)
  10943. $payHtml .= '<td class="taR">-</td>';
  10944. if (empty ( $balanceC ) || $limitMonth < $i)
  10945. $lastBalanceHtml .= '<td class="taR">-</td>';
  10946. else
  10947. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  10948. $balanceC = $balanceC + $inComeA + $payB;
  10949. $balanceSum += $balanceC;
  10950. if (empty ( $balanceC ) || $limitMonth < $i)
  10951. $BalanceHtml .= '<td class="taR">-</td>';
  10952. else
  10953. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  10954. // 余额统计
  10955. }
  10956. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  10957. $data ['inComeHtml'] = $inComeHtml;
  10958. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  10959. $data ['payBalanceHtml'] = $payHtml;
  10960. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  10961. $data ['BalanceHtml'] = $BalanceHtml;
  10962. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  10963. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  10964. $mothHtml = "";
  10965. for($i = 1; $i <= 12; $i ++) {
  10966. if ($moth == $i)
  10967. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  10968. else
  10969. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  10970. }
  10971. $data ['mothHtml'] = $mothHtml;
  10972. $dateHtml = "";
  10973. $now = date ( "Y" );
  10974. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  10975. if ($YEARD <= $now) {
  10976. $dateHtml .= '<option ';
  10977. if ($year == $YEARD) {
  10978. $dateHtml .= 'selected ';
  10979. }
  10980. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  10981. }
  10982. }
  10983. $data ['dateHtml'] = $dateHtml;
  10984. $data ['year'] = $year;
  10985. $data ['memu'] = "receipt";
  10986. $data ['staff'] = $this->staff;
  10987. $data ['receiptMemu'] = 'paymentsCollect';
  10988. $data ['verifyId'] = $this->verifyId;
  10989. $data ['executeId'] = $this->executeId;
  10990. $this->render ( "/expenses/paymentsCollect", $data );
  10991. }
  10992. function paymentsCollectDay() {
  10993. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10994. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  10995. if (empty ( $moth ))
  10996. return 'paymentsCollect';
  10997. Doo::loadModel ( "accountBookStatistics" );
  10998. $accountBookStatistics = new accountBookStatistics ();
  10999. $i = 2;
  11000. $y = 2013;
  11001. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11002. Doo::loadClass ( 'receipt.func' );
  11003. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11004. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11005. $data ['html'] = $html ['html'];
  11006. $data ['inSum'] = $html ['sum'];
  11007. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11008. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11009. $data ['payHtml'] = $html ['html'];
  11010. $data ['paySum'] = $html ['sum'];
  11011. $mothHtml = "";
  11012. for($i = 1; $i <= 12; $i ++) {
  11013. if ($moth == $i)
  11014. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11015. else
  11016. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11017. }
  11018. $data ['mothHtml'] = $mothHtml;
  11019. $data ['year'] = $year;
  11020. // 余额
  11021. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11022. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11023. include './protected/config/wasteBook.conf.php';
  11024. Doo::loadModel ( 'wasteBook' );
  11025. $wasteBook = new wasteBook ();
  11026. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11027. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11028. // 获得年份之前所有金额
  11029. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11030. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11031. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11032. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11033. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11034. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11035. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11036. // $balanceC = 0;
  11037. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11038. $limitDay = date ( 'd' );
  11039. $monthLK = ( int ) date ( 'm' );
  11040. if (date ( 'Y' ) > $year) {
  11041. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11042. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11043. $limitDay = 0;
  11044. }
  11045. for($i = 1; $i <= $day; $i ++) {
  11046. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11047. $inComeA = $payB = 0;
  11048. $falg = true;
  11049. foreach ( $inComePay as $key => $value ) {
  11050. if ($value ['day'] == $i) {
  11051. $falg = false;
  11052. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11053. $inSum += $value ['accountPrice'];
  11054. $showInSum += $value ['accountPriceShow'];
  11055. $inComeA = $value ['accountPrice'];
  11056. break;
  11057. }
  11058. }
  11059. if ($falg)
  11060. $inComeHtml .= '<td class="taR">-</td>';
  11061. $payFalg = true;
  11062. foreach ( $pay as $key => $value ) {
  11063. if ($value ['day'] == $i) {
  11064. $payFalg = false;
  11065. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11066. $paySum += $value ['accountPrice'];
  11067. $showPaySum += $value ['accountPriceShow'];
  11068. $payB = $value ['accountPrice'];
  11069. break;
  11070. }
  11071. }
  11072. if ($payFalg)
  11073. $payHtml .= '<td class="taR">-</td>';
  11074. if (empty ( $balanceC ) || $limitDay < $i)
  11075. $lastBalanceHtml .= '<td class="taR">-</td>';
  11076. else
  11077. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11078. $balanceC = $balanceC + $inComeA + $payB;
  11079. $balanceSum += $balanceC;
  11080. if (empty ( $balanceC ) || $limitDay < $i)
  11081. $BalanceHtml .= '<td class="taR">-</td>';
  11082. else
  11083. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11084. }
  11085. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11086. $data ['inComeHtml'] = $inComeHtml;
  11087. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11088. $data ['payBalanceHtml'] = $payHtml;
  11089. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11090. $data ['BalanceHtml'] = $BalanceHtml;
  11091. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11092. $data ['dayHtml'] = $dayHtml;
  11093. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11094. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11095. $dateHtml = "";
  11096. $now = date ( "Y" );
  11097. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11098. if ($YEARD <= $now) {
  11099. $dateHtml .= '<option ';
  11100. if ($year == $YEARD) {
  11101. $dateHtml .= 'selected ';
  11102. }
  11103. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11104. }
  11105. }
  11106. $data ['dateHtml'] = $dateHtml;
  11107. $data ['memu'] = "receipt";
  11108. $data ['staff'] = $this->staff;
  11109. $data ['receiptMemu'] = 'paymentsCollect';
  11110. $data ['verifyId'] = $this->verifyId;
  11111. $data ['executeId'] = $this->executeId;
  11112. $this->render ( "/expenses/paymentsCollectDay", $data );
  11113. }
  11114. function ajaxGetPaymentsByAid() {
  11115. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11116. Doo::loadModel ( "accountBook" );
  11117. $accountBook = new accountBook ();
  11118. $detail = $accountBook->getAccountBookByAid ( $serial );
  11119. echo json_encode ( array (
  11120. 'status' => 1,
  11121. 'detail' => $detail
  11122. ) );
  11123. }
  11124. // 公司流水
  11125. function wasteBook() {
  11126. Doo::loadModel ( "execute" );
  11127. $execute = new execute ();
  11128. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11129. die ( 'illegal request' );
  11130. }
  11131. include './protected/config/wasteBook.conf.php';
  11132. Doo::loadModel ( 'wasteBook' );
  11133. $wasteBook = new wasteBook ();
  11134. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11135. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11136. $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'];
  11137. // print_r($waste);
  11138. $data ['waste'] = $waste;
  11139. $data ['total'] = $total;
  11140. // 月流水数据结构
  11141. $monthStatistics = array ();
  11142. $incomeMothStatistics = array ();
  11143. $expenditureMothStatistics = array ();
  11144. for($i = 1; $i <= 12; $i ++) {
  11145. $month = date ( 'Y' ) . '-' . $i;
  11146. if ($i < 10)
  11147. $month = date ( 'Y' ) . '-0' . $i;
  11148. array_push ( $monthStatistics, $month );
  11149. }
  11150. foreach ( $monthStatistics as $value ) {
  11151. $falg = true;
  11152. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11153. if ($value == $v ['inputDate']) {
  11154. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11155. $falg = false;
  11156. }
  11157. }
  11158. if ($falg) {
  11159. array_push ( $incomeMothStatistics, '' );
  11160. }
  11161. $falgEx = true;
  11162. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11163. if ($value == $v ['inputDate']) {
  11164. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11165. $falg = false;
  11166. }
  11167. }
  11168. if ($falgEx) {
  11169. array_push ( $expenditureMothStatistics, '' );
  11170. }
  11171. }
  11172. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11173. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11174. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11175. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11176. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11177. // print_r($incomeList);
  11178. $data ['expenditureList'] = $expenditureList;
  11179. $data ['incomeList'] = $incomeList;
  11180. $data ['memu'] = "receipt";
  11181. $data ['staff'] = $this->staff;
  11182. $data ['receiptMemu'] = 'wasteBook';
  11183. $data ['verifyId'] = $this->verifyId;
  11184. $data ['executeId'] = $this->executeId;
  11185. $this->render ( "/expenses/wasteBook", $data );
  11186. }
  11187. function wasteBookIncome() {
  11188. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11189. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11190. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11191. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11192. $data ['dailyIncomeType'] = $dailyIncomeType;
  11193. Doo::loadModel ( 'wasteBook' );
  11194. $wasteBook = new wasteBook ();
  11195. Doo::loadModel ( 'L_category' );
  11196. $L_category = new L_category ();
  11197. Doo::loadClass ( 'XDeode' );
  11198. $XDeode = new XDeode ( 5 );
  11199. // echo $XDeode->encode(1).'<br>';
  11200. // echo $XDeode->encode(2).'<br>';
  11201. // echo $XDeode->encode(3).'<br>';
  11202. // echo $XDeode->encode(4).'<br>';
  11203. // echo $XDeode->encode(5).'<br>';
  11204. // echo $XDeode->encode(6).'<br>';
  11205. // echo $XDeode->encode(7).'<br>';
  11206. // echo $XDeode->encode(8).'<br>';
  11207. // echo $XDeode->encode(9).'<br>';
  11208. // echo $XDeode->encode(10).'<br>';
  11209. $dateArr = explode ( ':', $date );
  11210. $D1 = '';
  11211. $D2 = '';
  11212. $con = '';
  11213. if (! empty ( $date )) {
  11214. $D1 = $dateArr [0];
  11215. $D2 = $dateArr [1];
  11216. }
  11217. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11218. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11219. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11220. $con = ' and inputDate = "' . $D1 . '"';
  11221. if ($cid != 'ALL') {
  11222. $cid = $XDeode->decode ( $cid );
  11223. $con .= ' and cid = "' . $cid . '"';
  11224. }
  11225. if ($accountType != 'ALL') {
  11226. if ($accountType == 'INVOICE') {
  11227. $con .= ' and (accountType = 7 or accountType = 8)';
  11228. } elseif ($accountType == 'PAYMENTS') {
  11229. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11230. if ($dailyIncomeType != 'ALL') {
  11231. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11232. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11233. }
  11234. }
  11235. }
  11236. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11237. $sum = 0;
  11238. foreach ( $incomeList as $key => $value ) {
  11239. $sum += $value ['accountPrice'];
  11240. }
  11241. // print_r($incomeList);
  11242. // 获得办事和部门
  11243. $categoryList = $L_category->getCategory ();
  11244. $data ['accountType'] = $accountType;
  11245. $data ['cid'] = $cid;
  11246. $data ['categoryList'] = $categoryList;
  11247. $data ['sum'] = $sum;
  11248. $data ['incomeList'] = $incomeList;
  11249. $data ['inputDate'] = $date;
  11250. $data ['memu'] = "receipt";
  11251. $data ['staff'] = $this->staff;
  11252. $data ['receiptMemu'] = 'wasteBook';
  11253. $data ['verifyId'] = $this->verifyId;
  11254. $data ['executeId'] = $this->executeId;
  11255. $this->render ( "/expenses/wasteBookIncome", $data );
  11256. }
  11257. /**
  11258. * 所有支出
  11259. */
  11260. function wasteBookExpenditure() {
  11261. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11262. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11263. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11264. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11265. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11266. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11267. $data ['receiptType'] = $receiptType;
  11268. Doo::loadModel ( 'wasteBook' );
  11269. $wasteBook = new wasteBook ();
  11270. Doo::loadModel ( 'L_category' );
  11271. $L_category = new L_category ();
  11272. Doo::loadClass ( 'XDeode' );
  11273. $XDeode = new XDeode ( 5 );
  11274. $dateArr = explode ( ':', $date );
  11275. $D1 = '';
  11276. $D2 = '';
  11277. $con = '';
  11278. if (! empty ( $date )) {
  11279. $D1 = $dateArr [0];
  11280. $D2 = $dateArr [1];
  11281. }
  11282. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11283. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11284. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11285. $con = ' and inputDate = "' . $D1 . '"';
  11286. if ($cid != 'ALL') {
  11287. $cid = $XDeode->decode ( $cid );
  11288. $con .= ' and cid = "' . $cid . '"';
  11289. }
  11290. if ($accountType != 'ALL') {
  11291. if ($accountType == 'INVOICE') {
  11292. $con .= ' and accountType = 11';
  11293. } elseif ($accountType == 'PAYMENTS') {
  11294. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11295. if ($dailyExpenditureType != 'ALL') {
  11296. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11297. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11298. }
  11299. } elseif ($accountType == 'RECEIPT') {
  11300. if ($receiptType == 'ALL') {
  11301. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11302. } else {
  11303. $receiptType = $XDeode->decode ( $receiptType );
  11304. echo $receiptType;
  11305. if ($receiptType == 1) {
  11306. $con .= ' and (accountType = 1 or accountType=2)';
  11307. } else {
  11308. $con .= ' and accountType = ' . $receiptType;
  11309. }
  11310. }
  11311. }
  11312. }
  11313. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11314. $sum = 0;
  11315. foreach ( $incomeList as $key => $value ) {
  11316. $sum += $value ['accountPriceShow'];
  11317. }
  11318. // print_r($incomeList);
  11319. // 获得办事和部门
  11320. $categoryList = $L_category->getCategory ();
  11321. $data ['accountType'] = $accountType;
  11322. $data ['cid'] = $cid;
  11323. $data ['categoryList'] = $categoryList;
  11324. $data ['sum'] = $sum;
  11325. $data ['incomeList'] = $incomeList;
  11326. $data ['inputDate'] = $date;
  11327. $data ['memu'] = "receipt";
  11328. $data ['staff'] = $this->staff;
  11329. $data ['receiptMemu'] = 'wasteBook';
  11330. $data ['verifyId'] = $this->verifyId;
  11331. $data ['executeId'] = $this->executeId;
  11332. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11333. }
  11334. function ajaxGetWasteinvoiceReceivables() {
  11335. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11336. Doo::loadClass ( 'XDeode' );
  11337. $XDeode = new XDeode ( 5 );
  11338. $irid = $XDeode->decode ( $serial );
  11339. Doo::loadModel ( 'invoiceReceivables' );
  11340. $invoiceReceivables = new invoiceReceivables ();
  11341. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11342. echo json_encode ( array (
  11343. 'status' => 1,
  11344. 'detail' => $detail
  11345. ) );
  11346. }
  11347. function ajaxGetWasteInvoice() {
  11348. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11349. Doo::loadModel ( 'invoice' );
  11350. $invoice = new invoice ();
  11351. Doo::loadModel ( 'invoiceReceivables' );
  11352. $invoiceReceivables = new invoiceReceivables ();
  11353. $detail = $invoice->getInvoiceByIid ( $serial );
  11354. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11355. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11356. echo json_encode ( array (
  11357. 'status' => 1,
  11358. 'detail' => $detail
  11359. ) );
  11360. }
  11361. /**
  11362. */
  11363. function ajaxGetWasteReceipt() {
  11364. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11365. Doo::loadModel ( 'receipt' );
  11366. $receipt = new receipt ();
  11367. Doo::loadClass ( 'XDeode' );
  11368. $XDeode = new XDeode ( 5 );
  11369. $rid = $XDeode->decode ( $serial );
  11370. // 获得个数据
  11371. $detail = $receipt->getReceiptByRid ( $rid );
  11372. // 初始化
  11373. $detail ['reviseDetail'] = array ();
  11374. if (! empty ( $value ['reviseDetail'] ))
  11375. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11376. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11377. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11378. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11379. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11380. // 获得费用html
  11381. $html = $this->getWasteReceiptHtml ( $detail );
  11382. // 获得费用审批人数据
  11383. $detail = $this->getReceiptApproverHtml ( $detail );
  11384. // 审批执行
  11385. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11386. <th class="taC" width="90">审批人</th>
  11387. <th class="taC">审批意见</th></tr>';
  11388. foreach ( $detail ['verifyList'] as $key => $value ) {
  11389. $html .= '<tr>
  11390. <td>' . $value [1] . '</td>
  11391. <td>' . $value ['opinion'] . '</td>
  11392. </tr>
  11393. ';
  11394. }
  11395. $html .= ' </tbody></table>';
  11396. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11397. <th class="taC" width="90">执行人</th>
  11398. <th class="taC">执行意见</th></tr>';
  11399. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11400. $html .= '<tr>
  11401. <td>' . $value [1] . '</td>
  11402. <td>' . $value ['opinion'] . '</td>
  11403. </tr>
  11404. ';
  11405. }
  11406. $html .= ' </tbody></table>';
  11407. $html .= '<table class="table table-bordered table-condensed">
  11408. <tr class="warning">
  11409. <td class="taR"><b>汇款金额</b></td>
  11410. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11411. </tr>
  11412. </table>';
  11413. // print_r($detail['verifyList']);
  11414. // header ( 'Content-Type:text/html;charset=utf-8' );
  11415. // echo $html;
  11416. echo json_encode ( array (
  11417. 'status' => 1,
  11418. 'html' => $html,
  11419. 'detail' => $detail
  11420. ) );
  11421. }
  11422. function getReceiptApproverHtml($detail = array()) {
  11423. Doo::loadModel ( 'loanReceipt' );
  11424. $loanReceipt = new loanReceipt ();
  11425. Doo::loadModel ( 'verify' );
  11426. $verify = new verify ();
  11427. Doo::loadModel ( 'staff' );
  11428. $staff = new staff ();
  11429. if (empty ( $detail ))
  11430. return array ();
  11431. $loanList = $loanReceipt->getOne ( array (
  11432. 'where' => 'rid=' . $detail ['loanRid'],
  11433. 'desc' => 'rid',
  11434. 'asArray' => true
  11435. ) );
  11436. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11437. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11438. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11439. else
  11440. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11441. } else
  11442. $verifyList = $verify->getOne ( array (
  11443. 'where' => 'vid=' . $detail ['verify'],
  11444. 'asArray' => true
  11445. ) );
  11446. $verifyList = json_decode ( $verifyList ['staff'], true );
  11447. Doo::loadModel ( 'role' );
  11448. $role = new role ();
  11449. $roleId = 0;
  11450. $flag = true;
  11451. $roleKey = 0;
  11452. $endStaffArray = array ();
  11453. $roleArrayCopy = array ();
  11454. foreach ( $verifyList as $k => $v ) {
  11455. // init verifyStaff
  11456. if ($v [1] == 'ROLE') {
  11457. if (! empty ( $verifyStaff )) {
  11458. $endStaffArray = end ( $verifyStaff );
  11459. }
  11460. $roleVerify = json_decode ( $v [3], true );
  11461. $roleKey = $k;
  11462. $roleArray = array ();
  11463. $rolename = $role->getOne ( array (
  11464. 'where' => 'rid=' . $v [0],
  11465. 'asArray' => true
  11466. ) );
  11467. foreach ( $roleVerify as $o => $p ) {
  11468. $staffID = explode ( '_', $p );
  11469. $staffInfo = $staff->getOne ( array (
  11470. 'where' => 'sid=' . $staffID [0],
  11471. 'asArray' => true
  11472. ) );
  11473. // print_r($staffID);
  11474. $exp = array (
  11475. 0 => $staffInfo ['sid'],
  11476. 1 => $staffID [1],
  11477. 2 => $staffInfo ['avatar'],
  11478. 'date' => '',
  11479. 'date' => '',
  11480. 'opinion' => '',
  11481. 'status' => '',
  11482. 'rolename' => $rolename ['name']
  11483. );
  11484. array_push ( $roleArray, $exp );
  11485. }
  11486. $roleArrayCopy [$v [0]] = $roleArray;
  11487. // $verifyList[$k]['roleArray']=$roleArray;
  11488. }
  11489. $verifyList [$k] ['date'] = "";
  11490. $verifyList [$k] ['opinion'] = "";
  11491. $verifyList [$k] ['status'] = "";
  11492. if (empty ( $verifyStaff )) {
  11493. $verifyList [$k] ['date'] = "";
  11494. $verifyList [$k] ['opinion'] = "";
  11495. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11496. $verifyList [$k] ['status'] = 4;
  11497. $flag = false;
  11498. }
  11499. } else {
  11500. foreach ( $verifyStaff as $m => $u ) {
  11501. if ($v [0] == $m) {
  11502. $verifyList [$k] ['date'] = $u ['date'];
  11503. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11504. $verifyList [$k] ['status'] = $u ['status'];
  11505. $flag = false;
  11506. break;
  11507. }
  11508. }
  11509. $endStaffArray = end ( $verifyStaff );
  11510. }
  11511. }
  11512. $rolename ['name'] = '';
  11513. if (! empty ( $roleId )) {
  11514. Doo::loadModel ( 'role' );
  11515. $role = new role ();
  11516. $rolename = $role->getOne ( array (
  11517. 'where' => 'rid=' . $roleId,
  11518. 'asArray' => true
  11519. ) );
  11520. }
  11521. if (! empty ( $verifyStaff ))
  11522. $endStaffArray = end ( $verifyStaff );
  11523. $KOP = false;
  11524. foreach ( $roleArrayCopy as $P => $A ) {
  11525. foreach ( $A as $MKI => $AVL ) {
  11526. if (! empty ( $verifyStaff )) {
  11527. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11528. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11529. $button = 4;
  11530. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11531. }
  11532. foreach ( $verifyStaff as $m => $u ) {
  11533. $AVLFK = $AVL [0] . '_R';
  11534. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11535. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11536. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11537. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11538. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11539. break;
  11540. }
  11541. }
  11542. } else {
  11543. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11544. $button = 4;
  11545. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11546. }
  11547. }
  11548. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11549. $KOP = true;
  11550. }
  11551. }
  11552. foreach ( $roleArrayCopy as $k => $v ) {
  11553. foreach ( $verifyList as $m => $n ) {
  11554. if ($n [0] == $k) {
  11555. array_splice ( $verifyList, $m, 1, $v );
  11556. }
  11557. }
  11558. }
  11559. // 费用执行人相关数据
  11560. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11561. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11562. foreach ( $executeCopy as $k => $v ) {
  11563. $executeCopy [$k] ['date'] = '';
  11564. $executeCopy [$k] ['opinion'] = '';
  11565. $executeCopy [$k] ['status'] = '';
  11566. if (! empty ( $executeStaff ))
  11567. foreach ( $executeStaff as $m => $u ) {
  11568. if ($v [0] == $m) {
  11569. $executeCopy [$k] ['date'] = $u ['date'];
  11570. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11571. $executeCopy [$k] ['status'] = $u ['status'];
  11572. break;
  11573. }
  11574. }
  11575. }
  11576. $detail ['executeCopy'] = $executeCopy;
  11577. $detail ['verifyList'] = $verifyList;
  11578. return $detail;
  11579. }
  11580. function getWasteReceiptHtml($detail = array()) {
  11581. if (empty ( $detail ))
  11582. return '';
  11583. $html = '';
  11584. if ($detail ['Rtype'] == 0) { // 报销单
  11585. $html .= '
  11586. <table class="table table-bordered table-condensed">
  11587. <tbody>
  11588. <tr>
  11589. <th colspan="2" class="taC">日常相关费用</th>
  11590. </tr>';
  11591. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11592. $html .= '
  11593. <tr>
  11594. <th>' . $value ['name'] . '</th>
  11595. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11596. </tr>';
  11597. }
  11598. $html .= '
  11599. <tr>
  11600. <th class="taR">合计</th>
  11601. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11602. </tr>';
  11603. $html .= '<tr>
  11604. <th colspan="2" class="taC">差旅相关费用</th>
  11605. </tr>';
  11606. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11607. $html .= '
  11608. <tr>
  11609. <th>' . $value ['name'] . '</th>
  11610. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11611. </tr>';
  11612. }
  11613. $html .= '
  11614. <tr>
  11615. <th class="taR">合计</th>
  11616. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11617. </tr>';
  11618. $html .= '<tr>
  11619. <th colspan="2" class="taC">培训班费用</th>
  11620. </tr>';
  11621. foreach ( $detail ['accountItem'] ['培训班费用'] as $key => $value ) {
  11622. $html .= '
  11623. <tr>
  11624. <th>' . $value ['name'] . '</th>
  11625. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11626. </tr>';
  11627. }
  11628. $html .= '
  11629. <tr>
  11630. <th class="taR">合计</th>
  11631. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['trainSum'] . '</td>
  11632. </tr>';
  11633. $html .= '<tr>
  11634. <th colspan="2" class="taC">其他</th>
  11635. </tr>';
  11636. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11637. $html .= '
  11638. <tr>
  11639. <th>' . $value ['name'] . '</th>
  11640. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11641. </tr>';
  11642. }
  11643. $html .= '
  11644. <tr>
  11645. <th class="taR">合计</th>
  11646. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11647. </tr>';
  11648. $html .= '<tr>
  11649. <th colspan="2" class="taC">报销金额调整</th>
  11650. </tr>';
  11651. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11652. $html .= '
  11653. <tr>
  11654. <th>' . $value ['name'] . '</th>
  11655. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11656. </tr>';
  11657. }
  11658. $html .= '
  11659. <tr>
  11660. <th class="taR">合计</th>
  11661. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11662. </tr>';
  11663. $html .= '
  11664. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11665. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11666. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11667. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11668. <tr class="warning">
  11669. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11670. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11671. </tr>
  11672. </tbody>
  11673. </table>';
  11674. } elseif ($detail ['Rtype'] == 2) {
  11675. $html .= '
  11676. <table class="table table-bordered table-condensed">
  11677. <tbody>
  11678. <tr>
  11679. <th colspan="2" class="taC">办事处相关费用</th>
  11680. </tr>';
  11681. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11682. $html .= '
  11683. <tr>
  11684. <th>' . $value ['name'] . '</th>
  11685. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11686. </tr>';
  11687. }
  11688. $html .= '
  11689. <tr>
  11690. <th class="taR">合计</th>
  11691. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11692. </tr>';
  11693. $html .= '
  11694. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11695. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11696. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11697. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11698. <tr class="warning">
  11699. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11700. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11701. </tr>
  11702. </tbody>
  11703. </table>';
  11704. } elseif ($detail ['Rtype'] == 1) {
  11705. if ($detail ['loanRid'] != 0 && ! empty ( $detail ['accountItem'] )) {
  11706. $html .= '<table class="table table-bordered table-condensed">
  11707. <tbody>
  11708. <tr>
  11709. <th colspan="2" class="taC">日常相关费用</th>
  11710. </tr>';
  11711. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11712. $html .= '
  11713. <tr>
  11714. <th>' . $value ['name'] . '</th>
  11715. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11716. </tr>';
  11717. }
  11718. $html .= '
  11719. <tr>
  11720. <th class="taR">合计</th>
  11721. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11722. </tr>';
  11723. $html .= '<tr>
  11724. <th colspan="2" class="taC">差旅相关费用</th>
  11725. </tr>';
  11726. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11727. $html .= '
  11728. <tr>
  11729. <th>' . $value ['name'] . '</th>
  11730. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11731. </tr>';
  11732. }
  11733. $html .= '
  11734. <tr>
  11735. <th class="taR">合计</th>
  11736. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11737. </tr>';
  11738. $html .= '<tr>
  11739. <th colspan="2" class="taC">培训班费用</th>
  11740. </tr>';
  11741. foreach ( $detail ['accountItem'] ['培训班费用'] as $key => $value ) {
  11742. $html .= '
  11743. <tr>
  11744. <th>' . $value ['name'] . '</th>
  11745. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11746. </tr>';
  11747. }
  11748. $html .= '
  11749. <tr>
  11750. <th class="taR">合计</th>
  11751. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['trainSum'] . '</td>
  11752. </tr>';
  11753. $html .= '<tr>
  11754. <th colspan="2" class="taC">其他</th>
  11755. </tr>';
  11756. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11757. $html .= '
  11758. <tr>
  11759. <th>' . $value ['name'] . '</th>
  11760. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11761. </tr>';
  11762. }
  11763. $html .= '
  11764. <tr>
  11765. <th class="taR">合计</th>
  11766. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11767. </tr>';
  11768. $html .= '<tr>
  11769. <th colspan="2" class="taC">报销金额调整</th>
  11770. </tr>';
  11771. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11772. $html .= '
  11773. <tr>
  11774. <th>' . $value ['name'] . '</th>
  11775. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11776. </tr>';
  11777. }
  11778. $html .= '
  11779. <tr>
  11780. <th class="taR">合计</th>
  11781. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11782. </tr>';
  11783. $html .= '
  11784. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11785. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  11786. <tr><th class="taC" colspan="2">报销说明</th></tr>
  11787. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  11788. <tr class="warning">
  11789. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  11790. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  11791. </tr>
  11792. </tbody>
  11793. </table>';
  11794. }
  11795. Doo::loadModel ( 'loanReceipt' );
  11796. $loanReceipt = new loanReceipt ();
  11797. $loanList = $loanReceipt->getOne ( array (
  11798. 'where' => 'rid=' . $detail ['loanRid'],
  11799. 'desc' => 'rid',
  11800. 'asArray' => true
  11801. ) );
  11802. // print_r($loanList);
  11803. $html .= '<table class="table table-bordered table-condensed">
  11804. <tbody>
  11805. <tr>
  11806. <th colspan="2" class="taC">借款费用</th>
  11807. </tr>';
  11808. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  11809. $html .= '<tr>
  11810. <th>' . $value ['name'] . '</th>
  11811. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11812. </tr>';
  11813. }
  11814. $html .= '<tr>
  11815. <th class="taC" colspan="2">产生费用所在办事处</th>
  11816. </tr>
  11817. <tr>
  11818. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  11819. </tr>
  11820. <tr>
  11821. <th class="taC" colspan="2">费用说明</th>
  11822. </tr>
  11823. <tr>
  11824. <td colspan="2">' . $loanList ['explanation'] . '</td>
  11825. </tr>
  11826. <tr class="warning">
  11827. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  11828. <td class="taR"><b style="font-size: 24px">¥' . $detail ['loanSum'] . '</b><br>' . $detail ['loanSumCN'] . '</td>
  11829. </tr>
  11830. </tbody>
  11831. </table>
  11832. ';
  11833. }
  11834. return $html;
  11835. }
  11836. /**
  11837. * 计算流水
  11838. */
  11839. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  11840. $bakWaste ['bank'] = array (
  11841. 'CGBDeposit' => 0,
  11842. 'ICBCDeposit' => 0,
  11843. 'HUADeposit' => 0,
  11844. 'PersonalDeposit' => 0
  11845. );
  11846. $bakWaste ['financial'] = array (
  11847. 'current' => array (
  11848. 'CGBDeposit' => 0,
  11849. 'ICBCDeposit' => 0
  11850. ),
  11851. 'fixed' => array (
  11852. 'CGBDeposit' => 0,
  11853. 'ICBCDeposit' => 0
  11854. )
  11855. );
  11856. // 存款
  11857. foreach ( $waste ['bank'] as $key => $value ) {
  11858. // 收入
  11859. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  11860. // 广发
  11861. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  11862. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  11863. }
  11864. // 工商
  11865. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  11866. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  11867. }
  11868. // 华润
  11869. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  11870. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  11871. }
  11872. // 个人
  11873. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  11874. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  11875. }
  11876. }
  11877. }
  11878. foreach ( $waste ['bank'] as $key => $value ) {
  11879. // 支出
  11880. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  11881. // 广发
  11882. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  11883. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  11884. }
  11885. // 工商
  11886. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  11887. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  11888. }
  11889. // 华润
  11890. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  11891. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  11892. }
  11893. // 个人
  11894. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  11895. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  11896. }
  11897. }
  11898. }
  11899. // 活期
  11900. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  11901. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  11902. // 广发
  11903. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  11904. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  11905. }
  11906. // 工商
  11907. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  11908. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  11909. }
  11910. // 个人
  11911. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  11912. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  11913. }
  11914. }
  11915. }
  11916. // print_r($inComeStatistics ['fixedStatistics']);
  11917. // 固期
  11918. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  11919. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  11920. // 广发
  11921. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  11922. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  11923. }
  11924. // 工商
  11925. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  11926. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  11927. }
  11928. // 个人
  11929. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  11930. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  11931. }
  11932. }
  11933. }
  11934. return $waste;
  11935. }
  11936. function lyt() {
  11937. Doo::loadModel ( "receiptDetail" );
  11938. $receiptDetail = new receiptDetail ();
  11939. $receiptCollectList = $receiptDetail->find ( array (
  11940. 'where' => 'status=1 ',
  11941. 'asArray' => true
  11942. ) );
  11943. foreach ( $receiptCollectList as $key => $value ) {
  11944. $receiptDetail = new receiptDetail ();
  11945. $receiptDetail->pastDate = $value ['date'];
  11946. $receiptDetail->update ( array (
  11947. 'where' => "rdid= '" . $value ['rdid'] . "'"
  11948. ) );
  11949. }
  11950. }
  11951. function staffCollectMonthDetail() {
  11952. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  11953. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  11954. if (! $year)
  11955. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  11956. if (! $month)
  11957. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  11958. Doo::loadModel ( 'staff' );
  11959. $staff = new staff ();
  11960. Doo::loadModel ( "receiptDetail" );
  11961. $receiptDetail = new receiptDetail ();
  11962. Doo::loadModel ( 'accountItem' );
  11963. $accountItem = new accountItem ();
  11964. Doo::loadModel ( 'statistics' );
  11965. $statistics = new statistics ();
  11966. Doo::loadModel ( 'L_category' );
  11967. $lCategory = new L_category ();
  11968. Doo::loadModel ( "receiptAuthorityManage" );
  11969. $receiptAuthorityManage = new receiptAuthorityManage ();
  11970. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  11971. $cidList = array ();
  11972. foreach ( $imcStaff as $key => $value ) {
  11973. array_push ( $cidList, $value ['cid'] );
  11974. }
  11975. $cidString = implode ( ',', $cidList );
  11976. $staffList = $staff->find ( array (
  11977. 'where' => 'username!="admin" and cid in (' . $cidString . ')',
  11978. 'asArray' => true
  11979. ) );
  11980. $categoryList = $staff->find ( array (
  11981. 'select' => 'COUNT(*) as count,cid,category',
  11982. 'where' => 'username !="admin" and cid in (' . $cidString . ')',
  11983. 'groupby' => 'cid',
  11984. 'asArray' => true
  11985. ) );
  11986. $list = array ();
  11987. foreach ( $categoryList as $vlu ) {
  11988. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  11989. $r1 = 0;
  11990. $r2 = 0;
  11991. $r3 = 0;
  11992. $r4 = 0;
  11993. $r5 = 0;
  11994. $r6 = 0;
  11995. $r7 = 0;
  11996. $r8 = 0;
  11997. $r9 = 0;
  11998. $r10 = 0;
  11999. $r11 = 0;
  12000. $r12 = 0;
  12001. $r13 = 0;
  12002. $r14 = 0;
  12003. $r15 = 0;
  12004. $r16 = 0;
  12005. $r17 = 0;
  12006. $r18 = 0;
  12007. $c1 = 0;
  12008. $c2 = 0;
  12009. $c3 = 0;
  12010. $c4 = 0;
  12011. $c5 = 0;
  12012. $c6 = 0;
  12013. $p1 = 0;
  12014. $p2 = 0;
  12015. $p3 = 0;
  12016. $p4 = 0;
  12017. $p5 = 0;
  12018. $p6 = 0;
  12019. $p7 = 0;
  12020. $p8 = 0;
  12021. $p9 = 0;
  12022. $p10 = 0;
  12023. $p11 = 0;
  12024. $t1 = 0;
  12025. $t2 = 0;
  12026. $t3 = 0;
  12027. $t4 = 0;
  12028. $t5 = 0;
  12029. $s1 = 0;
  12030. $m1 = 0;
  12031. foreach ( $staffList as $value ) {
  12032. if ($vlu ['cid'] == $value ['cid']) {
  12033. // pastDate
  12034. $receiptCollectList = $receiptDetail->find ( array (
  12035. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12036. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12037. 'groupby' => 'item,Month(pastDate),itemCategory',
  12038. 'asArray' => true
  12039. ) );
  12040. // if ($value['sid']==42){
  12041. // print_r($receiptCollectList);die;
  12042. // }
  12043. if (! empty ( $receiptCollectList )) {
  12044. $receiptL = array (
  12045. '日常相关费用' => array (),
  12046. '差旅相关费用' => array (),
  12047. '培训班费用' => array (),
  12048. '其他' => array ()
  12049. );
  12050. $html = "";
  12051. $psum = 0;
  12052. $item = array (
  12053. '市内交通费',
  12054. '市内出租费',
  12055. '办事处房租',
  12056. '电话费',
  12057. '水费',
  12058. '电费',
  12059. '办公费用',
  12060. '邮寄费',
  12061. '其他费用',
  12062. '车辆费用',
  12063. '广告费',
  12064. '团队建设费',
  12065. '物业管理费',
  12066. '宽带费',
  12067. '人员薪酬',
  12068. '公积金',
  12069. '社保'
  12070. );
  12071. foreach ( $item as $va ) {
  12072. $falg = true;
  12073. foreach ( $receiptCollectList as $v ) {
  12074. if ($v ['itemCategory'] == '日常相关费用') {
  12075. if ($v ['item'] == $va) {
  12076. if ($va == '市内交通费')
  12077. $r1 += $v ['price'];
  12078. if ($va == '市内出租费')
  12079. $r2 += $v ['price'];
  12080. if ($va == '办事处房租')
  12081. $r3 += $v ['price'];
  12082. if ($va == '电话费')
  12083. $r4 += $v ['price'];
  12084. if ($va == '水费')
  12085. $r5 += $v ['price'];
  12086. if ($va == '电费')
  12087. $r6 += $v ['price'];
  12088. if ($va == '办公费用')
  12089. $r7 += $v ['price'];
  12090. if ($va == '邮寄费')
  12091. $r8 += $v ['price'];
  12092. if ($va == '其他费用')
  12093. $r9 += $v ['price'];
  12094. if ($va == '车辆费用')
  12095. $r10 += $v ['price'];
  12096. if ($va == '广告费')
  12097. $r11 += $v ['price'];
  12098. if ($va == '团队建设费')
  12099. $r13 += $v ['price'];
  12100. if ($va == '物业管理费')
  12101. $r14 += $v ['price'];
  12102. if ($va == '宽带费')
  12103. $r15 += $v ['price'];
  12104. if ($va == '公积金')
  12105. $r16 += $v ['price'];
  12106. if ($va == '社保')
  12107. $r17 += $v ['price'];
  12108. if ($va == '人员薪酬')
  12109. $r18 += $v ['price'];
  12110. $psum += $v ['price'];
  12111. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12112. $falg = false;
  12113. break;
  12114. }
  12115. }
  12116. }
  12117. if ($falg)
  12118. $html .= '<td class="taR">-</td>';
  12119. }
  12120. $r12 += $psum;
  12121. if (! empty ( $psum ))
  12122. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12123. else
  12124. $psum = '<td class="colGreen taR">-</td>';
  12125. $receiptL ['日常相关费用'] = $psum . $html;
  12126. /* ----------------------------------- */
  12127. $html = "";
  12128. $psum = 0;
  12129. $item = array (
  12130. '往来交通费',
  12131. '市内交通费',
  12132. '出差住宿费',
  12133. '出差补助',
  12134. '其他费用'
  12135. );
  12136. foreach ( $item as $va ) {
  12137. $falg = true;
  12138. foreach ( $receiptCollectList as $v ) {
  12139. if ($v ['itemCategory'] == '差旅相关费用') {
  12140. if ($v ['item'] == $va) {
  12141. if ($va == '往来交通费')
  12142. $c1 += $v ['price'];
  12143. if ($va == '市内交通费')
  12144. $c2 += $v ['price'];
  12145. if ($va == '出差住宿费')
  12146. $c3 += $v ['price'];
  12147. if ($va == '出差补助')
  12148. $c4 += $v ['price'];
  12149. if ($va == '其他费用')
  12150. $c5 += $v ['price'];
  12151. $psum += $v ['price'];
  12152. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12153. $falg = false;
  12154. break;
  12155. }
  12156. }
  12157. }
  12158. if ($falg)
  12159. $html .= '<td class="taR">-</td>';
  12160. }
  12161. $c6 += $psum;
  12162. if (! empty ( $psum ))
  12163. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12164. else
  12165. $psum = '<td class="colGreen taR">-</td>';
  12166. $receiptL ['差旅相关费用'] = $psum . $html;
  12167. /* ------------------------------------- */
  12168. $html = "";
  12169. $psum = 0;
  12170. $item = array (
  12171. '场租费',
  12172. '薪酬',
  12173. '住宿费',
  12174. '交通费',
  12175. '餐饮费',
  12176. '办公费',
  12177. '公关费',
  12178. '其他',
  12179. '电话费',
  12180. '邮寄费'
  12181. );
  12182. foreach ( $item as $va ) {
  12183. $falg = true;
  12184. foreach ( $receiptCollectList as $v ) {
  12185. if ($v ['itemCategory'] == '培训班费用') {
  12186. if ($v ['item'] == $va) {
  12187. if ($va == '场租费')
  12188. $p1 += $v ['price'];
  12189. if ($va == '薪酬')
  12190. $p2 += $v ['price'];
  12191. if ($va == '住宿费')
  12192. $p3 += $v ['price'];
  12193. if ($va == '交通费')
  12194. $p4 += $v ['price'];
  12195. if ($va == '餐饮费')
  12196. $p5 += $v ['price'];
  12197. if ($va == '办公费')
  12198. $p6 += $v ['price'];
  12199. if ($va == '公关费')
  12200. $p7 += $v ['price'];
  12201. if ($va == '其他')
  12202. $p8 += $v ['price'];
  12203. if ($va == '电话费')
  12204. $p9 += $v ['price'];
  12205. if ($va == '邮寄费')
  12206. $p10 += $v ['price'];
  12207. $psum += $v ['price'];
  12208. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12209. $falg = false;
  12210. break;
  12211. }
  12212. }
  12213. }
  12214. if ($falg)
  12215. $html .= '<td class="taR">-</td>';
  12216. }
  12217. $p11 += $psum;
  12218. if (! empty ( $psum ))
  12219. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12220. else
  12221. $psum = '<td class="colGreen taR">-</td>';
  12222. $receiptL ['培训班费用'] = $psum . $html;
  12223. /* ------------------------------------- */
  12224. $html = "";
  12225. $psum = 0;
  12226. $item = array (
  12227. '公关费',
  12228. '广告费',
  12229. '借款',
  12230. '可自加费用'
  12231. );
  12232. foreach ( $item as $va ) {
  12233. $falg = true;
  12234. foreach ( $receiptCollectList as $v ) {
  12235. if ($v ['itemCategory'] == '其他') {
  12236. // if ($value['sid']==42){
  12237. //
  12238. // echo var_dump($v['item']);
  12239. // echo var_dump($va);
  12240. // echo var_dump($v['item']==" ".$va);
  12241. // echo $v['item']."==".$va."/<br/>";
  12242. // //print_r( $receiptCollectList);//echo $va;
  12243. // }
  12244. if (trim ( $v ['item'] ) == $va) {
  12245. if ($va == '公关费')
  12246. $t1 += $v ['price'];
  12247. if ($va == '广告费') {
  12248. $t2 += $v ['price'];
  12249. }
  12250. if ($va == '借款')
  12251. $t3 += $v ['price'];
  12252. if ($va == '可自加费用')
  12253. $t4 += $v ['price'];
  12254. $psum += $v ['price'];
  12255. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12256. $falg = false;
  12257. break;
  12258. }
  12259. }
  12260. }
  12261. if ($falg)
  12262. $html .= '<td class="taR">-</td>';
  12263. }
  12264. $t5 += $psum;
  12265. if (! empty ( $psum ))
  12266. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12267. else
  12268. $psum = '<td class="colGreen taR">-</td>';
  12269. $receiptL ['其他'] = $psum . $html;
  12270. /* ------------------------------------- */
  12271. $html = "";
  12272. $psum = 0;
  12273. foreach ( $receiptCollectList as $v ) {
  12274. if ($v ['itemCategory'] == '报销金额调整') {
  12275. if (! empty ( $v ['price'] )) {
  12276. $psum += $v ['price'];
  12277. }
  12278. }
  12279. }
  12280. $s1 += $psum;
  12281. if (! empty ( $psum ))
  12282. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12283. else
  12284. $psum = '<td class="taR colOrange">-</td>';
  12285. $receiptL ['报销金额调整'] = $psum . $html;
  12286. } else {
  12287. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12288. <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>
  12289. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12290. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12291. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12292. $receiptL ['培训班费用'] = '<td class="colGreen 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>
  12293. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12294. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12295. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12296. }
  12297. $monthStaffPrice = $receiptDetail->find ( array (
  12298. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12299. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12300. 'groupby' => 'Month(pastDate)',
  12301. 'asArray' => true
  12302. ) );
  12303. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12304. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12305. $m1 += $monthStaffPrice [0] ['price'];
  12306. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12307. } else
  12308. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12309. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12310. $list [$value ['username']] = $receiptL;
  12311. }
  12312. }
  12313. $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>
  12314. <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>
  12315. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td><td class="taR">' . $r18 . '</td> <td class="taR">' . $r16 . '</td><td class="taR">' . $r17 . '</td>';
  12316. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12317. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12318. $receiptL ['培训班费用'] = '<td class="colGreen taR">' . $p11 . '</td><td class="taR">' . $p1 . '</td><td class="taR">' . $p2 . '</td><td class="taR">' . $p3 . '</td><td class="taR">' . $p4 . '</td>
  12319. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td><td class="taR">' . $p9 . '</td><td class="taR">' . $p10 . '</td>';
  12320. $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>';
  12321. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12322. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12323. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12324. }
  12325. $data ['list'] = $list;
  12326. // print_r($list);
  12327. $receiptCollectList = $receiptDetail->find ( array (
  12328. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12329. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12330. 'groupby' => 'item,Month(pastDate),itemCategory',
  12331. 'asArray' => true
  12332. ) );
  12333. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12334. // statistics html
  12335. $stList = $statistics->getOne ( array (
  12336. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12337. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12338. 'groupby' => 'Month(date)',
  12339. 'asArray' => true
  12340. ) );
  12341. if (empty ( $stList ))
  12342. $stList = array (
  12343. 'rePrice' => 0,
  12344. 'agPrice' => 0
  12345. );
  12346. $data ['stList'] = array (
  12347. 'rePrice' => $stList ['rePrice'],
  12348. 'agPrice' => $stList ['agPrice'],
  12349. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12350. );
  12351. $monthHtml = "";
  12352. for($i = 1; $i <= 12; $i ++) {
  12353. if ($i == $month)
  12354. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12355. else
  12356. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12357. }
  12358. $data ['monthHtml'] = $monthHtml;
  12359. $data ['year'] = $year;
  12360. $data ['month'] = $month;
  12361. $data ['memu'] = "receipt";
  12362. $data ['staff'] = $this->staff;
  12363. $data ['receiptMemu'] = 'companyCategoryCollect';
  12364. $data ['verifyId'] = $this->verifyId;
  12365. $data ['executeId'] = $this->executeId;
  12366. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12367. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12368. }
  12369. function staffCollectMonthDetail2() {
  12370. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12371. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12372. if (! $year)
  12373. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12374. if (! $month)
  12375. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12376. Doo::loadModel ( 'staff' );
  12377. $staff = new staff ();
  12378. Doo::loadModel ( "receiptDetail" );
  12379. $receiptDetail = new receiptDetail ();
  12380. Doo::loadModel ( 'accountItem' );
  12381. $accountItem = new accountItem ();
  12382. Doo::loadModel ( 'statistics' );
  12383. $statistics = new statistics ();
  12384. Doo::loadModel ( 'L_category' );
  12385. $lCategory = new L_category ();
  12386. $staffList = $staff->find ( array (
  12387. 'where' => 'username!="admin"',
  12388. 'asArray' => true
  12389. ) );
  12390. $categoryList = $staff->find ( array (
  12391. 'select' => 'COUNT(*) as count,cid,category',
  12392. 'where' => 'username !="admin"',
  12393. 'groupby' => 'cid',
  12394. 'asArray' => true
  12395. ) );
  12396. $list = array ();
  12397. foreach ( $categoryList as $vlu ) {
  12398. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12399. $r1 = 0;
  12400. $r2 = 0;
  12401. $r3 = 0;
  12402. $r4 = 0;
  12403. $r5 = 0;
  12404. $r6 = 0;
  12405. $r7 = 0;
  12406. $r8 = 0;
  12407. $r9 = 0;
  12408. $r10 = 0;
  12409. $r11 = 0;
  12410. $r12 = 0;
  12411. $r13 = 0;
  12412. $r14 = 0;
  12413. $r15 = 0;
  12414. $c1 = 0;
  12415. $c2 = 0;
  12416. $c3 = 0;
  12417. $c4 = 0;
  12418. $c5 = 0;
  12419. $c6 = 0;
  12420. $p1 = 0;
  12421. $p2 = 0;
  12422. $p3 = 0;
  12423. $p4 = 0;
  12424. $p5 = 0;
  12425. $p6 = 0;
  12426. $p7 = 0;
  12427. $p8 = 0;
  12428. $p9 = 0;
  12429. $t1 = 0;
  12430. $t2 = 0;
  12431. $t3 = 0;
  12432. $t4 = 0;
  12433. $t5 = 0;
  12434. $s1 = 0;
  12435. $m1 = 0;
  12436. foreach ( $staffList as $value ) {
  12437. if ($vlu ['cid'] == $value ['cid']) {
  12438. $receiptCollectList = $receiptDetail->find ( array (
  12439. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12440. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12441. 'groupby' => 'item,Month(date),itemCategory',
  12442. 'asArray' => true
  12443. ) );
  12444. if (! empty ( $receiptCollectList )) {
  12445. $receiptL = array (
  12446. '日常相关费用' => array (),
  12447. '差旅相关费用' => array (),
  12448. '培训班费用' => array (),
  12449. '其他' => array ()
  12450. );
  12451. $html = "";
  12452. $psum = 0;
  12453. $item = array (
  12454. '市内交通费',
  12455. '市内出租费',
  12456. '办事处房租',
  12457. '电话费',
  12458. '水费',
  12459. '电费',
  12460. '办公费用',
  12461. '邮寄费',
  12462. '其他费用',
  12463. '车辆费用',
  12464. '广告费',
  12465. '团队建设费',
  12466. '物业管理费',
  12467. '宽带费'
  12468. );
  12469. foreach ( $item as $va ) {
  12470. $falg = true;
  12471. foreach ( $receiptCollectList as $v ) {
  12472. if ($v ['itemCategory'] == '日常相关费用') {
  12473. if ($v ['item'] == $va) {
  12474. if ($va == '市内交通费')
  12475. $r1 += $v ['price'];
  12476. if ($va == '市内出租费')
  12477. $r2 += $v ['price'];
  12478. if ($va == '办事处房租')
  12479. $r3 += $v ['price'];
  12480. if ($va == '电话费')
  12481. $r4 += $v ['price'];
  12482. if ($va == '水费')
  12483. $r5 += $v ['price'];
  12484. if ($va == '电费')
  12485. $r6 += $v ['price'];
  12486. if ($va == '办公费用')
  12487. $r7 += $v ['price'];
  12488. if ($va == '邮寄费')
  12489. $r8 += $v ['price'];
  12490. if ($va == '其他费用')
  12491. $r9 += $v ['price'];
  12492. if ($va == '车辆费用')
  12493. $r10 += $v ['price'];
  12494. if ($va == '广告费')
  12495. $r11 += $v ['price'];
  12496. if ($va == '团队建设费')
  12497. $r13 += $v ['price'];
  12498. if ($va == '物业管理费')
  12499. $r14 += $v ['price'];
  12500. if ($va == '宽带费')
  12501. $r15 += $v ['price'];
  12502. $psum += $v ['price'];
  12503. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12504. $falg = false;
  12505. break;
  12506. }
  12507. }
  12508. }
  12509. if ($falg)
  12510. $html .= '<td class="taR">-</td>';
  12511. }
  12512. $r12 += $psum;
  12513. if (! empty ( $psum ))
  12514. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12515. else
  12516. $psum = '<td class="colGreen taR">-</td>';
  12517. $receiptL ['日常相关费用'] = $psum . $html;
  12518. /* ----------------------------------- */
  12519. $html = "";
  12520. $psum = 0;
  12521. $item = array (
  12522. '往来交通费',
  12523. '市内交通费',
  12524. '出差住宿费',
  12525. '出差补助',
  12526. '其他费用'
  12527. );
  12528. foreach ( $item as $va ) {
  12529. $falg = true;
  12530. foreach ( $receiptCollectList as $v ) {
  12531. if ($v ['itemCategory'] == '差旅相关费用') {
  12532. if ($v ['item'] == $va) {
  12533. if ($va == '往来交通费')
  12534. $c1 += $v ['price'];
  12535. if ($va == '市内交通费')
  12536. $c2 += $v ['price'];
  12537. if ($va == '出差住宿费')
  12538. $c3 += $v ['price'];
  12539. if ($va == '出差补助')
  12540. $c4 += $v ['price'];
  12541. if ($va == '其他费用')
  12542. $c5 += $v ['price'];
  12543. $psum += $v ['price'];
  12544. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12545. $falg = false;
  12546. break;
  12547. }
  12548. }
  12549. }
  12550. if ($falg)
  12551. $html .= '<td class="taR">-</td>';
  12552. }
  12553. $c6 += $psum;
  12554. if (! empty ( $psum ))
  12555. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12556. else
  12557. $psum = '<td class="colGreen taR">-</td>';
  12558. $receiptL ['差旅相关费用'] = $psum . $html;
  12559. /* ------------------------------------- */
  12560. $html = "";
  12561. $psum = 0;
  12562. $item = array (
  12563. '场租费',
  12564. '薪酬',
  12565. '住宿费',
  12566. '交通费',
  12567. '餐饮费',
  12568. '办公费',
  12569. '公关费',
  12570. '其他'
  12571. );
  12572. foreach ( $item as $va ) {
  12573. $falg = true;
  12574. foreach ( $receiptCollectList as $v ) {
  12575. if ($v ['itemCategory'] == '培训班费用') {
  12576. if ($v ['item'] == $va) {
  12577. if ($va == '场租费')
  12578. $p1 += $v ['price'];
  12579. if ($va == '薪酬')
  12580. $p2 += $v ['price'];
  12581. if ($va == '住宿费')
  12582. $p3 += $v ['price'];
  12583. if ($va == '交通费')
  12584. $p4 += $v ['price'];
  12585. if ($va == '餐饮费')
  12586. $p5 += $v ['price'];
  12587. if ($va == '办公费')
  12588. $p6 += $v ['price'];
  12589. if ($va == '公关费')
  12590. $p7 += $v ['price'];
  12591. if ($va == '其他')
  12592. $p8 += $v ['price'];
  12593. $psum += $v ['price'];
  12594. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12595. $falg = false;
  12596. break;
  12597. }
  12598. }
  12599. }
  12600. if ($falg)
  12601. $html .= '<td class="taR">-</td>';
  12602. }
  12603. $p9 += $psum;
  12604. if (! empty ( $psum ))
  12605. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12606. else
  12607. $psum = '<td class="colGreen taR">-</td>';
  12608. $receiptL ['培训班费用'] = $psum . $html;
  12609. /* ------------------------------------- */
  12610. $html = "";
  12611. $psum = 0;
  12612. $item = array (
  12613. '公关费',
  12614. '广告费',
  12615. '借款',
  12616. '可自加费用'
  12617. );
  12618. foreach ( $item as $va ) {
  12619. $falg = true;
  12620. foreach ( $receiptCollectList as $v ) {
  12621. if ($v ['itemCategory'] == '其他') {
  12622. if ($v ['item'] == $va) {
  12623. if ($va == '公关费')
  12624. $t1 += $v ['price'];
  12625. if ($va == '广告费')
  12626. $t2 += $v ['price'];
  12627. if ($va == '借款')
  12628. $t3 += $v ['price'];
  12629. if ($va == '可自加费用')
  12630. $t4 += $v ['price'];
  12631. $psum += $v ['price'];
  12632. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12633. $falg = false;
  12634. break;
  12635. }
  12636. }
  12637. }
  12638. if ($falg)
  12639. $html .= '<td class="taR">-</td>';
  12640. }
  12641. $t5 += $psum;
  12642. if (! empty ( $psum ))
  12643. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12644. else
  12645. $psum = '<td class="colGreen taR">-</td>';
  12646. $receiptL ['其他'] = $psum . $html;
  12647. /* ------------------------------------- */
  12648. $html = "";
  12649. $psum = 0;
  12650. foreach ( $receiptCollectList as $v ) {
  12651. if ($v ['itemCategory'] == '报销金额调整') {
  12652. if (! empty ( $v ['price'] )) {
  12653. $psum += $v ['price'];
  12654. }
  12655. }
  12656. }
  12657. $s1 += $psum;
  12658. if (! empty ( $psum ))
  12659. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12660. else
  12661. $psum = '<td class="taR colOrange">-</td>';
  12662. $receiptL ['报销金额调整'] = $psum . $html;
  12663. } else {
  12664. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12665. <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>';
  12666. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12667. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12668. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12669. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12670. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12671. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12672. }
  12673. $monthStaffPrice = $receiptDetail->find ( array (
  12674. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12675. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12676. 'asArray' => true
  12677. ) );
  12678. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12679. $m1 += $monthStaffPrice [0] ['price'];
  12680. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12681. } else
  12682. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12683. $list [$value ['username']] = $receiptL;
  12684. }
  12685. }
  12686. $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>
  12687. <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>
  12688. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12689. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12690. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12691. $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>
  12692. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12693. $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>';
  12694. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12695. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12696. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12697. }
  12698. $data ['list'] = $list;
  12699. $receiptCollectList = $receiptDetail->find ( array (
  12700. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12701. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12702. 'groupby' => 'item,Month(date),itemCategory',
  12703. 'asArray' => true
  12704. ) );
  12705. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12706. // statistics html
  12707. $stList = $statistics->getOne ( array (
  12708. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12709. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12710. 'groupby' => 'Month(date)',
  12711. 'asArray' => true
  12712. ) );
  12713. if (empty ( $stList ))
  12714. $stList = array (
  12715. 'rePrice' => 0,
  12716. 'agPrice' => 0
  12717. );
  12718. $data ['stList'] = array (
  12719. 'rePrice' => $stList ['rePrice'],
  12720. 'agPrice' => $stList ['agPrice'],
  12721. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12722. );
  12723. $monthHtml = "";
  12724. for($i = 1; $i <= 12; $i ++) {
  12725. if ($i == $month)
  12726. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12727. else
  12728. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12729. }
  12730. $data ['monthHtml'] = $monthHtml;
  12731. $data ['year'] = $year;
  12732. $data ['month'] = $month;
  12733. $data ['memu'] = "receipt";
  12734. $data ['staff'] = $this->staff;
  12735. $data ['receiptMemu'] = 'companyCategoryCollect';
  12736. $data ['verifyId'] = $this->verifyId;
  12737. $data ['executeId'] = $this->executeId;
  12738. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12739. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12740. }
  12741. /**
  12742. * 用户报销单列表
  12743. */
  12744. function receiptStatisticsStaffDetail() {
  12745. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12746. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12747. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  12748. Doo::loadModel ( "receipt" );
  12749. $receipt = new receipt ();
  12750. Doo::loadModel ( "receiptDetail" );
  12751. $receiptDetail = new receiptDetail ();
  12752. Doo::loadModel ( 'staff' );
  12753. $staff = new staff ();
  12754. Doo::loadModel ( 'accountItem' );
  12755. $accountItem = new accountItem ();
  12756. Doo::loadModel ( 'statistics' );
  12757. $statistics = new statistics ();
  12758. if (! empty ( $username )) {
  12759. $username = addslashes ( urldecode ( $username ) );
  12760. $staffDetail = $staff->getStaffByName ( $username );
  12761. if (empty ( $staffDetail ))
  12762. die ( 'illegal request' );
  12763. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  12764. $itemList = $accountItem->getAccountItem ();
  12765. $itemHtml = '';
  12766. $categoryHtml = '';
  12767. $itemKeyList = array_keys ( $itemList );
  12768. $revisePrice = 0;
  12769. // 报销单内容详情
  12770. foreach ( $list as $key => $value ) {
  12771. $accountItemList = json_decode ( $value ['accountItem'], true );
  12772. $list [$key] ['accountItemList'] = $accountItemList;
  12773. $receiptItemHtml = '';
  12774. foreach ( $itemKeyList as $v ) {
  12775. if ($v == '日常相关费用')
  12776. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  12777. elseif ($v == '差旅相关费用')
  12778. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  12779. elseif ($v == '培训班费用')
  12780. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  12781. elseif ($v == '其他')
  12782. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  12783. foreach ( $itemList [$v] as $ke => $va ) {
  12784. $falg = true;
  12785. if (! empty ( $accountItemList [$v] )) {
  12786. foreach ( $accountItemList [$v] as $ve ) {
  12787. if ($va ['name'] == $ve ['name']) {
  12788. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  12789. $falg = false;
  12790. break;
  12791. }
  12792. }
  12793. }
  12794. if ($falg)
  12795. $receiptItemHtml .= '<td class="taR"></td>';
  12796. }
  12797. }
  12798. // 金额调整和费用查看
  12799. $revisePrice += $value ['revisePrice'];
  12800. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  12801. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" onclick=showExplanation("' . $value ['explanation'] . '")>查看</a></td>';
  12802. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  12803. }
  12804. // 报销单合计
  12805. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  12806. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  12807. $receiptTotalHtml = '';
  12808. // 报销单项目抬头
  12809. foreach ( $itemKeyList as $value ) {
  12810. $count = count ( $itemList [$value] ) + 1;
  12811. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  12812. $categoryHtml .= '<th class="taC">合计</th>';
  12813. foreach ( $rtl as $rtlValue ) {
  12814. if ($rtlValue ['itemCategory'] == $value) {
  12815. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  12816. break;
  12817. }
  12818. }
  12819. foreach ( $itemList [$value] as $k => $v ) {
  12820. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  12821. // 合计
  12822. $falg = true;
  12823. foreach ( $receiptTotalList as $ve ) {
  12824. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  12825. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  12826. $falg = false;
  12827. break;
  12828. }
  12829. }
  12830. if ($falg)
  12831. $receiptTotalHtml .= '<th></th>';
  12832. }
  12833. }
  12834. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  12835. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  12836. if (empty ( $stList ))
  12837. $stList = array (
  12838. 'rePrice' => 0,
  12839. 'agPrice' => 0
  12840. );
  12841. $data ['stList'] = array (
  12842. 'rePrice' => $stList ['rePrice'],
  12843. 'agPrice' => $stList ['agPrice'],
  12844. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12845. );
  12846. $monthHtml = "";
  12847. for($i = 1; $i <= 12; $i ++) {
  12848. if ($i == $month)
  12849. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12850. else
  12851. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12852. }
  12853. $data ['username'] = urlencode ( $username );
  12854. $data ['usernameEN'] = $username;
  12855. $data ['monthHtml'] = $monthHtml;
  12856. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  12857. $data ['list'] = $list;
  12858. $data ['categoryHtml'] = $categoryHtml;
  12859. $data ['itemHtml'] = $itemHtml;
  12860. $data ['itemList'] = $itemList;
  12861. $data ['year'] = $year;
  12862. $data ['month'] = $month;
  12863. $data ['memu'] = "receipt";
  12864. $data ['staff'] = $this->staff;
  12865. $data ['receiptMemu'] = 'companyCategoryCollect';
  12866. $data ['verifyId'] = $this->verifyId;
  12867. $data ['executeId'] = $this->executeId;
  12868. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  12869. }
  12870. die ( 'illegal request' );
  12871. }
  12872. function companyMonthCollectDetail() {
  12873. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12874. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12875. if (! $year)
  12876. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12877. if (! $month)
  12878. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12879. Doo::loadModel ( 'staff' );
  12880. $staff = new staff ();
  12881. Doo::loadModel ( "receiptDetail" );
  12882. $receiptDetail = new receiptDetail ();
  12883. Doo::loadModel ( 'accountItem' );
  12884. $accountItem = new accountItem ();
  12885. Doo::loadModel ( 'statistics' );
  12886. $statistics = new statistics ();
  12887. Doo::loadModel ( 'L_category' );
  12888. $lCategory = new L_category ();
  12889. $staffList = $staff->find ( array (
  12890. 'where' => 'username!="admin"',
  12891. 'asArray' => true
  12892. ) );
  12893. $categoryList = $lCategory->find ( array (
  12894. 'asArray' => true
  12895. ) );
  12896. $list = array ();
  12897. foreach ( $categoryList as $value ) {
  12898. $receiptCollectList = $receiptDetail->find ( array (
  12899. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12900. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12901. 'groupby' => 'item,Month(pastDate),itemCategory',
  12902. 'asArray' => true
  12903. ) );
  12904. if (! empty ( $receiptCollectList )) {
  12905. $receiptL = array (
  12906. '日常相关费用' => array (),
  12907. '差旅相关费用' => array (),
  12908. '培训班费用' => array (),
  12909. '其他' => array ()
  12910. );
  12911. $html = "";
  12912. $psum = 0;
  12913. $item = array (
  12914. '市内交通费',
  12915. '市内出租费',
  12916. '办事处房租',
  12917. '电话费',
  12918. '水费',
  12919. '电费',
  12920. '办公费用',
  12921. '邮寄费',
  12922. '其他费用',
  12923. '车辆费用',
  12924. '广告费',
  12925. '团队建设费'
  12926. );
  12927. foreach ( $item as $va ) {
  12928. $falg = true;
  12929. foreach ( $receiptCollectList as $v ) {
  12930. if ($v ['itemCategory'] == '日常相关费用') {
  12931. if ($v ['item'] == $va) {
  12932. $psum += $v ['price'];
  12933. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12934. $falg = false;
  12935. break;
  12936. }
  12937. }
  12938. }
  12939. if ($falg)
  12940. $html .= '<td class="taR">-</td>';
  12941. }
  12942. if (! empty ( $psum ))
  12943. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  12944. else
  12945. $psum = '<td class="colGreen taR">-</td>';
  12946. $receiptL ['日常相关费用'] = $psum . $html;
  12947. /* ----------------------------------- */
  12948. $html = "";
  12949. $psum = 0;
  12950. $item = array (
  12951. '往来交通费',
  12952. '市内交通费',
  12953. '出差住宿费',
  12954. '出差补助',
  12955. '其他费用'
  12956. );
  12957. foreach ( $item as $va ) {
  12958. $falg = true;
  12959. foreach ( $receiptCollectList as $v ) {
  12960. if ($v ['itemCategory'] == '差旅相关费用') {
  12961. if ($v ['item'] == $va) {
  12962. $psum += $v ['price'];
  12963. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12964. $falg = false;
  12965. break;
  12966. }
  12967. }
  12968. }
  12969. if ($falg)
  12970. $html .= '<td class="taR">-</td>';
  12971. }
  12972. if (! empty ( $psum ))
  12973. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  12974. else
  12975. $psum = '<td class="colGreen taR">-</td>';
  12976. $receiptL ['差旅相关费用'] = $psum . $html;
  12977. /* ------------------------------------- */
  12978. $html = "";
  12979. $psum = 0;
  12980. $item = array (
  12981. '场租费',
  12982. '薪酬',
  12983. '住宿费',
  12984. '交通费',
  12985. '餐饮费',
  12986. '办公费',
  12987. '公关费',
  12988. '其他'
  12989. );
  12990. foreach ( $item as $va ) {
  12991. $falg = true;
  12992. foreach ( $receiptCollectList as $v ) {
  12993. if ($v ['itemCategory'] == '培训班费用') {
  12994. if ($v ['item'] == $va) {
  12995. $psum += $v ['price'];
  12996. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12997. $falg = false;
  12998. break;
  12999. }
  13000. }
  13001. }
  13002. if ($falg)
  13003. $html .= '<td class="taR">-</td>';
  13004. }
  13005. if (! empty ( $psum ))
  13006. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13007. else
  13008. $psum = '<td class="colGreen taR">-</td>';
  13009. $receiptL ['培训班费用'] = $psum . $html;
  13010. /* ------------------------------------- */
  13011. $html = "";
  13012. $psum = 0;
  13013. $item = array (
  13014. '公关费',
  13015. '广告费',
  13016. '借款',
  13017. '可自加费用'
  13018. );
  13019. foreach ( $item as $va ) {
  13020. $falg = true;
  13021. foreach ( $receiptCollectList as $v ) {
  13022. if ($v ['itemCategory'] == '其他') {
  13023. if ($v ['item'] == $va) {
  13024. $psum += $v ['price'];
  13025. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13026. $falg = false;
  13027. break;
  13028. }
  13029. }
  13030. }
  13031. if ($falg)
  13032. $html .= '<td class="taR">-</td>';
  13033. }
  13034. if (! empty ( $psum ))
  13035. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13036. else
  13037. $psum = '<td class="colGreen taR">-</td>';
  13038. $receiptL ['其他'] = $psum . $html;
  13039. /* ------------------------------------- */
  13040. $html = "";
  13041. $psum = 0;
  13042. foreach ( $receiptCollectList as $v ) {
  13043. if ($v ['itemCategory'] == '报销金额调整') {
  13044. if (! empty ( $v ['price'] ))
  13045. $psum += $v ['price'];
  13046. }
  13047. }
  13048. if (! empty ( $psum ))
  13049. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13050. else
  13051. $psum = '<td class="taR colOrange">-</td>';
  13052. $receiptL ['报销金额调整'] = $psum . $html;
  13053. } else {
  13054. $receiptL ['日常相关费用'] = '<td class="colGreen 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>
  13055. <td class="taR">-</td><td class="taR">-</td><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>
  13057. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13058. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13059. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13060. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13061. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13062. }
  13063. $monthStaffPrice = $receiptDetail->find ( array (
  13064. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13065. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13066. 'asArray' => true
  13067. ) );
  13068. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13069. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13070. else
  13071. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13072. $list [$value ['title']] = $receiptL;
  13073. }
  13074. $data ['list'] = $list;
  13075. $receiptCollectList = $receiptDetail->find ( array (
  13076. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13077. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13078. 'groupby' => 'item,Month(pastDate),itemCategory',
  13079. 'asArray' => true
  13080. ) );
  13081. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13082. // print_r($data['monthPriceHtml']);
  13083. // foreach ($data['monthPriceHtml'] as $value){
  13084. // echo $value;
  13085. // }
  13086. // die;
  13087. // statistics html
  13088. $stList = $statistics->getOne ( array (
  13089. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13090. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13091. 'groupby' => 'Month(date)',
  13092. 'asArray' => true
  13093. ) );
  13094. if (empty ( $stList ))
  13095. $stList = array (
  13096. 'rePrice' => 0,
  13097. 'agPrice' => 0
  13098. );
  13099. $data ['stList'] = array (
  13100. 'rePrice' => $stList ['rePrice'],
  13101. 'agPrice' => $stList ['agPrice'],
  13102. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13103. );
  13104. $monthHtml = "";
  13105. for($i = 1; $i <= 12; $i ++) {
  13106. if ($i == $month)
  13107. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13108. else
  13109. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13110. }
  13111. $data ['monthHtml'] = $monthHtml;
  13112. $data ['year'] = $year;
  13113. $data ['month'] = $month;
  13114. $data ['memu'] = "receipt";
  13115. $data ['staff'] = $this->staff;
  13116. $data ['receiptMemu'] = 'companyCategoryCollect';
  13117. $data ['verifyId'] = $this->verifyId;
  13118. $data ['executeId'] = $this->executeId;
  13119. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13120. }
  13121. function staffCollectDetail() {
  13122. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13123. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13124. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13125. if (! $staffname) {
  13126. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13127. $staffname = urldecode ( $staffname );
  13128. }
  13129. Doo::loadModel ( 'staff' );
  13130. $staff = new staff ();
  13131. Doo::loadModel ( "receiptDetail" );
  13132. $receiptDetail = new receiptDetail ();
  13133. Doo::loadModel ( 'accountItem' );
  13134. $accountItem = new accountItem ();
  13135. Doo::loadModel ( 'statistics' );
  13136. $statistics = new statistics ();
  13137. Doo::loadModel ( 'L_category' );
  13138. $lCategory = new L_category ();
  13139. Doo::loadModel ( "receiptAuthorityManage" );
  13140. $receiptAuthorityManage = new receiptAuthorityManage ();
  13141. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13142. $cidList = array ();
  13143. foreach ( $imcStaff as $key => $value ) {
  13144. array_push ( $cidList, $value ['cid'] );
  13145. }
  13146. $cidString = implode ( ',', $cidList );
  13147. $staffList = $staff->find ( array (
  13148. 'where' => ' cid in (' . $cidString . ')',
  13149. 'asArray' => true
  13150. ) );
  13151. $stHtml = '';
  13152. $stTitle = "";
  13153. $staffId = 0;
  13154. $cid = 0;
  13155. $ocid = 0;
  13156. foreach ( $staffList as $value ) {
  13157. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13158. $stTitle = $value ['category'] . '-' . $value ['username'];
  13159. $staffId = $value ['sid'];
  13160. $cid = $value ['cid'];
  13161. $ocid = $value ['cid'];
  13162. if (! empty ( $value ['othercid'] ))
  13163. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13164. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13165. } elseif ($value ['username'] != 'admin')
  13166. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13167. }
  13168. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13169. 'where' => 'cid in(' . $cid . ')',
  13170. 'asArray' => true
  13171. ) );
  13172. if (empty ( $pcid ))
  13173. $pcid = $ocid;
  13174. $data ['ocid'] = $pcid;
  13175. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13176. $this->showCache ( $path );
  13177. //
  13178. $receiptCollectList = $receiptDetail->find ( array (
  13179. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13180. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13181. 'groupby' => 'item,Month(pastDate),itemCategory',
  13182. 'asArray' => true
  13183. ) );
  13184. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13185. // print_r($receiptCollectList);
  13186. $accountList = $accountItem->find ( array (
  13187. 'asArray' => true
  13188. ) );
  13189. // create CollectDetail HTML
  13190. $collectHtml = array ();
  13191. foreach ( $accountList as $key => $value ) {
  13192. $html = "";
  13193. $asum = 0;
  13194. for($i = 1; $i <= 12; $i ++) {
  13195. $falg = true;
  13196. foreach ( $receiptCollectList as $v ) {
  13197. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13198. if ($v ['item'] == '可自加费用') {
  13199. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13200. }
  13201. $asum += $v ['price'];
  13202. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13203. $falg = false;
  13204. break;
  13205. }
  13206. }
  13207. if ($falg)
  13208. $html .= '<td class="taR">-</td>';
  13209. }
  13210. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13211. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13212. }
  13213. $data ['collectHtml'] = $collectHtml;
  13214. // print_r($collectHtml);
  13215. // create Adjustment price html
  13216. $receiptCollectList = $receiptDetail->find ( array (
  13217. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13218. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13219. 'groupby' => 'itemCategory,Month(pastDate)',
  13220. 'asArray' => true
  13221. ) );
  13222. $adjustment = array ();
  13223. $collectArray = array (
  13224. '日常相关费用' => array (),
  13225. '差旅相关费用' => array (),
  13226. '培训班费用' => array (),
  13227. '其他' => array ()
  13228. );
  13229. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13230. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13231. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13232. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13233. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13234. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13235. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13236. array_push ( $collectArray ['其他'], $collectHtml );
  13237. $data ['collectArray'] = $collectArray;
  13238. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13239. array_push ( $adjustment, $collectHtml );
  13240. $data ['adjustment'] = $adjustment;
  13241. // total price html
  13242. $collectHtml = "";
  13243. $total = 0;
  13244. for($i = 1; $i <= 12; $i ++) {
  13245. $sumPrice = 0;
  13246. foreach ( $receiptCollectList as $key => $value ) {
  13247. if ($value ['month'] == $i) {
  13248. $sumPrice += $value ['price'];
  13249. }
  13250. }
  13251. if ($sumPrice == 0)
  13252. $collectHtml .= '<td class="taR">-</td>';
  13253. else
  13254. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13255. $total += $sumPrice;
  13256. }
  13257. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13258. // statistics html
  13259. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13260. if (empty ( $stList ))
  13261. $stList = array (
  13262. 'rePrice' => 0,
  13263. 'agPrice' => 0
  13264. );
  13265. $data ['stList'] = array (
  13266. 'rePrice' => $stList ['rePrice'],
  13267. 'agPrice' => $stList ['agPrice'],
  13268. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13269. );
  13270. $data ['totalPrice'] = $collectHtml;
  13271. $data ['totalYear'] = $total;
  13272. $data ['stHtml'] = $stHtml;
  13273. $data ['year'] = $year;
  13274. $data ['stTitle'] = $stTitle;
  13275. $data ['staffname'] = urlencode ( $staffname );
  13276. $data ['memu'] = "receipt";
  13277. $data ['staff'] = $this->staff;
  13278. $data ['receiptMemu'] = 'companyCategoryCollect';
  13279. $data ['verifyId'] = $this->verifyId;
  13280. $data ['executeId'] = $this->executeId;
  13281. if ($year < date ( "Y" )) {
  13282. Doo::loadModel ( 'receipt' );
  13283. $receipt = new receipt ();
  13284. $receiptList = $receipt->find ( array (
  13285. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13286. 'asArray' => true
  13287. ) );
  13288. if (empty ( $receiptList )) { // generated files
  13289. ob_start ();
  13290. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13291. $this->cacheFile ( $path );
  13292. die ();
  13293. }
  13294. }
  13295. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13296. }
  13297. function BUGFLAG() {
  13298. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13299. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13300. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13301. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13302. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13303. if (empty ( $status ))
  13304. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13305. $page_size = 12;
  13306. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13307. $vidList = array ();
  13308. $button = 0;
  13309. Doo::loadModel ( 'verify' );
  13310. $verify = new verify ();
  13311. Doo::loadModel ( 'receipt' );
  13312. $receipt = new receipt ();
  13313. Doo::loadModel ( 'staff' );
  13314. $staff = new staff ();
  13315. Doo::loadModel ( 'L_category' );
  13316. $Lcategory = new L_category ();
  13317. $dateCondition = " and Year(date) =" . $year;
  13318. if (! empty ( $month ))
  13319. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13320. $categoryList = $Lcategory->find ( array (
  13321. 'asArray' => true
  13322. ) );
  13323. $staffList = $staff->find ( array (
  13324. 'where' => 'cid=' . $cid,
  13325. 'asArray' => true
  13326. ) );
  13327. $cateCondition = "";
  13328. $staffCondition = "";
  13329. $approvalCondition = "";
  13330. if (! empty ( $cid ))
  13331. $cateCondition = ' and cid=' . $cid;
  13332. if (! empty ( $sid )) {
  13333. $staffCondition = ' and staff=' . $sid;
  13334. $cateCondition = "";
  13335. }
  13336. $approvalCondition = " and status=" . $status;
  13337. if ($status == 2) {
  13338. // 查找角色审批人
  13339. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13340. }
  13341. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13342. $approvalCondition = ' and status=2 ';
  13343. }
  13344. if ($status == 1) {
  13345. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13346. }
  13347. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13348. $pageinfo ['page'] = array (
  13349. 'previous' => ''
  13350. );
  13351. if ($status == 0) {
  13352. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13353. $receiptList = $receipt->find ( array (
  13354. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13355. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13356. 'desc' => 'rid',
  13357. 'asArray' => true
  13358. ) );
  13359. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13360. } else
  13361. $receiptList = $receipt->find ( array (
  13362. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13363. 'desc' => 'rid',
  13364. 'asArray' => true
  13365. ) );
  13366. $rLRes = $receipt->find ( array (
  13367. '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,
  13368. 'desc' => 'rid',
  13369. 'asArray' => true
  13370. ) );
  13371. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13372. // print_r($pageinfo);
  13373. $Locate = 0;
  13374. foreach ( $receiptList as $key => $value ) {
  13375. $receiptList [$key] ['Locate'] = $Locate;
  13376. $Locate ++;
  13377. $receiptList [$key] ['reviseDetail'] = array ();
  13378. if (! empty ( $value ['reviseDetail'] ))
  13379. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13380. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13381. $categoryDetil = $Lcategory->getOne ( array (
  13382. 'where' => 'cid=' . $value ['cid'],
  13383. 'asArray' => true
  13384. ) );
  13385. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13386. $verifyList = $verify->getOne ( array (
  13387. 'where' => 'vid=' . $value ['verify'],
  13388. 'asArray' => true
  13389. ) );
  13390. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13391. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13392. foreach ( $verifyList as $k => $v ) {
  13393. // init verifyStaff
  13394. $verifyList [$k] ['date'] = "";
  13395. $verifyList [$k] ['opinion'] = "";
  13396. $verifyList [$k] ['status'] = "";
  13397. if (empty ( $verifyStaff )) {
  13398. $verifyList [$k] ['date'] = "";
  13399. $verifyList [$k] ['opinion'] = "";
  13400. if ($v [0] == $this->staff [0] ['sid']) {
  13401. $verifyList [$k] ['status'] = 4;
  13402. $button = 4;
  13403. }
  13404. } else {
  13405. $flag = true;
  13406. foreach ( $verifyStaff as $m => $u ) {
  13407. if ($v [0] == $m) {
  13408. $verifyList [$k] ['date'] = $u ['date'];
  13409. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13410. $verifyList [$k] ['status'] = $u ['status'];
  13411. $flag = false;
  13412. break;
  13413. }
  13414. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13415. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13416. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13417. }
  13418. if ($flag) { // 检测可编辑
  13419. if ($v [0] == $this->staff [0] ['sid']) {
  13420. $verifyList [$k] ['status'] = 4;
  13421. $button = 4;
  13422. }
  13423. }
  13424. }
  13425. }
  13426. $receiptList [$key] ['verifyList'] = $verifyList;
  13427. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13428. 'where' => 'sid=' . $value ['staff'],
  13429. 'asArray' => true
  13430. ) );
  13431. $receiptList [$key] ['button'] = $button;
  13432. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13433. }
  13434. // print_r($receiptList);die;
  13435. // $data['verifyDetail']=$verifyDetail;
  13436. $mothHtml = "";
  13437. for($i = 1; $i <= 12; $i ++) {
  13438. if ($month == $i)
  13439. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13440. else
  13441. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13442. }
  13443. $data ['mothHtml'] = $mothHtml;
  13444. $data ['page'] = $pageinfo;
  13445. $data ['receiptList'] = $receiptList;
  13446. $data ['receiptApprovalCount'] = count ( $rLRes );
  13447. $data ['status'] = $status;
  13448. $data ['year'] = $year;
  13449. $data ['categoryList'] = $categoryList;
  13450. $data ['staffList'] = $staffList;
  13451. $data ['cid'] = $cid;
  13452. $data ['sid'] = $sid;
  13453. // print_r($receiptList);
  13454. $data ['memu'] = "receipt";
  13455. $data ['staff'] = $this->staff;
  13456. $data ['receiptMemu'] = 'approvalExpenses';
  13457. $data ['verifyId'] = $this->verifyId;
  13458. $data ['executeId'] = $this->executeId;
  13459. $this->render ( "/admin/FALG", $data );
  13460. }
  13461. function ajaxGetReceiptOrder() {
  13462. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13463. if (! empty ( $receiptOrder )) {
  13464. Doo::loadModel ( 'receipt' );
  13465. $receipt = new receipt ();
  13466. Doo::loadModel ( 'staff' );
  13467. $staff = new staff ();
  13468. $receiptInfo = $receipt->getOne ( array (
  13469. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13470. 'asArray' => true
  13471. ) );
  13472. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13473. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13474. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13475. </tbody></table><table class="table table table-bordered"><tbody>';
  13476. foreach ( $verifyStaff as $key => $value ) {
  13477. $staffInfo = $staff->getOne ( array (
  13478. 'select' => 'username',
  13479. 'where' => ' sid="' . $key . '"',
  13480. 'asArray' => true
  13481. ) );
  13482. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13483. }
  13484. $html .= '</tbody></table></div></div>';
  13485. echo json_encode ( array (
  13486. 'status' => 1,
  13487. 'receiptHtml' => $html
  13488. ) );
  13489. die ();
  13490. }
  13491. echo json_encode ( array (
  13492. 'status' => 2,
  13493. 'receiptHtml' => ''
  13494. ) );
  13495. die ();
  13496. }
  13497. function _getMonthCollectDetail($receiptCollectList) {
  13498. if (! empty ( $receiptCollectList )) {
  13499. $receiptL = array (
  13500. '日常相关费用' => array (),
  13501. '差旅相关费用' => array (),
  13502. '培训班费用' => array (),
  13503. '其他' => array ()
  13504. );
  13505. $html = "";
  13506. $psum = 0;
  13507. $item = array (
  13508. '市内交通费',
  13509. '市内出租费',
  13510. '办事处房租',
  13511. '电话费',
  13512. '水费',
  13513. '电费',
  13514. '办公费用',
  13515. '邮寄费',
  13516. '其他费用',
  13517. '车辆费用',
  13518. '广告费',
  13519. '团队建设费',
  13520. '物业管理费',
  13521. '宽带费',
  13522. '人员薪酬',
  13523. '公积金',
  13524. '社保'
  13525. );
  13526. foreach ( $item as $value ) {
  13527. $falg = true;
  13528. foreach ( $receiptCollectList as $v ) {
  13529. if ($v ['itemCategory'] == '日常相关费用') {
  13530. if ($v ['item'] == $value) {
  13531. $psum += $v ['price'];
  13532. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13533. $falg = false;
  13534. break;
  13535. }
  13536. }
  13537. }
  13538. if ($falg)
  13539. $html .= '<td class="taR">-</td>';
  13540. }
  13541. if (! empty ( $psum ))
  13542. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13543. else
  13544. $psum = '<td class="colGreen taR">-</td>';
  13545. $receiptL ['日常相关费用'] = $psum . $html;
  13546. /* ----------------------------------- */
  13547. $html = "";
  13548. $psum = 0;
  13549. $item = array (
  13550. '往来交通费',
  13551. '市内交通费',
  13552. '出差住宿费',
  13553. '出差补助',
  13554. '其他费用'
  13555. );
  13556. foreach ( $item as $value ) {
  13557. $falg = true;
  13558. foreach ( $receiptCollectList as $v ) {
  13559. if ($v ['itemCategory'] == '差旅相关费用') {
  13560. if ($v ['item'] == $value) {
  13561. $psum += $v ['price'];
  13562. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13563. $falg = false;
  13564. break;
  13565. }
  13566. }
  13567. }
  13568. if ($falg)
  13569. $html .= '<td class="taR">-</td>';
  13570. }
  13571. if (! empty ( $psum ))
  13572. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13573. else
  13574. $psum = '<td class="colGreen taR">-</td>';
  13575. $receiptL ['差旅相关费用'] = $psum . $html;
  13576. /* ------------------------------------- */
  13577. $html = "";
  13578. $psum = 0;
  13579. $item = array (
  13580. '场租费',
  13581. '薪酬',
  13582. '住宿费',
  13583. '交通费',
  13584. '餐饮费',
  13585. '办公费',
  13586. '公关费',
  13587. '其他',
  13588. '电话费',
  13589. '邮寄费'
  13590. );
  13591. foreach ( $item as $value ) {
  13592. $falg = true;
  13593. foreach ( $receiptCollectList as $v ) {
  13594. if ($v ['itemCategory'] == '培训班费用') {
  13595. if ($v ['item'] == $value) {
  13596. $psum += $v ['price'];
  13597. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13598. $falg = false;
  13599. break;
  13600. }
  13601. }
  13602. }
  13603. if ($falg)
  13604. $html .= '<td class="taR">-</td>';
  13605. }
  13606. if (! empty ( $psum ))
  13607. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13608. else
  13609. $psum = '<td class="colGreen taR">-</td>';
  13610. $receiptL ['培训班费用'] = $psum . $html;
  13611. /* ------------------------------------- */
  13612. $html = "";
  13613. $psum = 0;
  13614. $item = array (
  13615. '公关费',
  13616. '广告费',
  13617. '借款',
  13618. '可自加费用'
  13619. );
  13620. foreach ( $item as $value ) {
  13621. $falg = true;
  13622. foreach ( $receiptCollectList as $v ) {
  13623. if ($v ['itemCategory'] == '其他') {
  13624. if ($v ['item'] == $value) {
  13625. $psum += $v ['price'];
  13626. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13627. $falg = false;
  13628. break;
  13629. }
  13630. }
  13631. }
  13632. if ($falg)
  13633. $html .= '<td class="taR">-</td>';
  13634. }
  13635. if (! empty ( $psum ))
  13636. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13637. else
  13638. $psum = '<td class="colGreen taR">-</td>';
  13639. $receiptL ['其他'] = $psum . $html;
  13640. /* ------------------------------------- */
  13641. $html = "";
  13642. $psum = 0;
  13643. foreach ( $receiptCollectList as $v ) {
  13644. if ($v ['itemCategory'] == '报销金额调整') {
  13645. if (! empty ( $v ['price'] ))
  13646. $psum += $v ['price'];
  13647. }
  13648. }
  13649. if (! empty ( $psum ))
  13650. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13651. else
  13652. $psum = '<td class="taR colOrange">-</td>';
  13653. $receiptL ['报销金额调整'] = $psum . $html;
  13654. } else {
  13655. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td>
  13656. <td class="taR">-</td>
  13657. <td class="taR">-</td>
  13658. <td class="taR">-</td>
  13659. <td class="taR">-</td>
  13660. <td class="taR">-</td>
  13661. <td class="taR">-</td>
  13662. <td class="taR">-</td>
  13663. <td class="taR">-</td>
  13664. <td class="taR">-</td>
  13665. <td class="taR">-</td>
  13666. <td class="taR">-</td>
  13667. <td class="taR">-</td>';
  13668. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13669. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13670. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td>
  13671. <td class="taR">-</td>
  13672. <td class="taR">-</td>
  13673. <td class="taR">-</td>
  13674. <td class="taR">-</td>
  13675. <td class="taR">-</td>
  13676. <td class="taR">-</td>
  13677. <td class="taR">-</td>
  13678. <td class="taR">-</td>';
  13679. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13680. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13681. }
  13682. return $receiptL;
  13683. }
  13684. function eMail() {
  13685. Doo::loadModel ( 'staff' );
  13686. $staff = new staff ();
  13687. Doo::loadModel ( 'receipt' );
  13688. $receipt = new receipt ();
  13689. Doo::loadModel ( 'L_category' );
  13690. $Lcategory = new L_category ();
  13691. Doo::loadModel ( "verify" );
  13692. $verify = new verify ();
  13693. $staffList = $staff->find ( array (
  13694. 'asArray' => true
  13695. ) );
  13696. foreach ( $staffList as $key => $value ) {
  13697. if ($value ['username'] != 'admin') {
  13698. // 提交人
  13699. $receiptList = $receipt->find ( array (
  13700. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13701. 'asArray' => true
  13702. ) );
  13703. if (! empty ( $receiptList )) {
  13704. $html = '<br><div><style></style>
  13705. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13706. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13707. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13708. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13709. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13710. <tbody><tr>
  13711. <td style="padding: 0 40px;" align="left">
  13712. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13713. </td></tr><tr>
  13714. <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>
  13715. </tr>
  13716. </tbody> </table></td> </tr> <tr><td>
  13717. <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">
  13718. <tbody> <tr><td>
  13719. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13720. 以下报销单完成了审批,等着收款吧:</p>
  13721. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13722. foreach ( $receiptList as $k => $v ) {
  13723. $category = $Lcategory->getOne ( array (
  13724. 'where' => 'cid=' . $v ['cid'],
  13725. 'asArray' => true
  13726. ) );
  13727. $html .= '
  13728. <tr>
  13729. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13730. <td align="left">
  13731. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13732. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13733. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13734. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13735. </tr>';
  13736. }
  13737. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13738. <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>
  13739. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13740. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13741. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13742. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13743. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13744. $receipt = new receipt ();
  13745. $receipt->notice = 1;
  13746. $receipt->update ( array (
  13747. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13748. ) );
  13749. }
  13750. }
  13751. // 审批人
  13752. $verifyList = $verify->find ( array (
  13753. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13754. 'asArray' => true
  13755. ) );
  13756. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  13757. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  13758. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13759. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  13760. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13761. <tbody><tr><td style="padding: 0 40px;" align="left">
  13762. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13763. </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>
  13764. </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">
  13765. <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>
  13766. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  13767. foreach ( $verifyList as $k => $v ) {
  13768. $receiptList = $receipt->find ( array (
  13769. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  13770. 'asArray' => true
  13771. ) );
  13772. foreach ( $receiptList as $r => $l ) {
  13773. $category = $Lcategory->getOne ( array (
  13774. 'where' => 'cid=' . $l ['cid'],
  13775. 'asArray' => true
  13776. ) );
  13777. $staffDetile = $staff->getOne ( array (
  13778. 'where' => 'sid=' . $l ['staff'],
  13779. 'asArray' => true
  13780. ) );
  13781. $html .= '
  13782. <tr>
  13783. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13784. <td align="left">
  13785. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  13786. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  13787. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  13788. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  13789. </tr>';
  13790. }
  13791. }
  13792. $html .= '
  13793. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  13794. <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>
  13795. </tr></tbody></table></td></tr></tbody></table></div><br>';
  13796. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  13797. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  13798. // $receipt=new receipt();
  13799. // $receipt->notice=1;
  13800. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  13801. }
  13802. }
  13803. }
  13804. }
  13805. function setWXMsg($rid, $type) {
  13806. Doo::loadModel ( "receipt" );
  13807. $receipt = new receipt ();
  13808. $receiptDetail = $receipt->getOne ( array (
  13809. 'where' => 'rid=' . $rid,
  13810. 'asArray' => true
  13811. ) );
  13812. if (! empty ( $receiptDetail )) {
  13813. Doo::loadModel ( 'staff' );
  13814. $staff = new staff ();
  13815. $staffmsg = $staff->getOne ( array (
  13816. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  13817. 'asArray' => TRUE
  13818. ) );
  13819. if (! empty ( $staffmsg ['wxid'] )) {
  13820. require_once (SITE_PATH . '/protected/class/client.php');
  13821. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  13822. $user = $staffmsg ['wxid'];
  13823. $receiptName = '';
  13824. $msg = '';
  13825. switch ($receiptDetail ['Rtype']) {
  13826. case 0 :
  13827. $receiptName = '报销';
  13828. break;
  13829. case 1 :
  13830. $receiptName = '借款';
  13831. break;
  13832. case 2 :
  13833. $receiptName = '对公汇款';
  13834. break;
  13835. }
  13836. switch ($type) {
  13837. case 1 :
  13838. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  13839. break;
  13840. case 2 :
  13841. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  13842. break;
  13843. case 3 :
  13844. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  13845. break;
  13846. }
  13847. // $result = $client->SendMsg ( $user, $msg, 'text' );
  13848. }
  13849. }
  13850. }
  13851. // Email发送函数
  13852. function SMail($toemail, $subject, $contents) {
  13853. Doo::loadClass ( 'class.phpmailer' );
  13854. $mail = new PHPMailer ();
  13855. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  13856. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  13857. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  13858. $mail->Password = "cDO1GjtY1seH"; // 密码
  13859. $mail->CharSet = "UTF8";
  13860. $mail->SMTPAuth = true;
  13861. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  13862. $mail->Mailer = "smtp";
  13863. $mail->Port = 25;
  13864. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  13865. $mail->MsgHTML ( $contents );
  13866. $mail->AddAddress ( $toemail );
  13867. $mail->CharSet = "UTF-8";
  13868. return $mail->Send ();
  13869. }
  13870. function h5Upload() {
  13871. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  13872. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  13873. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  13874. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  13875. header ( "HTTP/1.1 500 Internal Server Error" );
  13876. echo "POST exceeded maximum allowed size.";
  13877. exit ( 0 );
  13878. }
  13879. // Settings
  13880. $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)
  13881. $upload_name = "Filedata";
  13882. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  13883. $extension_whitelist = array (
  13884. "doc",
  13885. "txt",
  13886. "jpg",
  13887. "gif",
  13888. "png"
  13889. ); // Allowed file extensions
  13890. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  13891. // Other variables
  13892. $MAX_FILENAME_LENGTH = 260;
  13893. $file_name = "";
  13894. $file_extension = "";
  13895. $uploadErrors = array (
  13896. 0 => "文件上传成功",
  13897. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  13898. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  13899. 3 => "上传的文件仅为部分文件",
  13900. 4 => "没有文件上传",
  13901. 6 => "缺少临时文件夹"
  13902. );
  13903. $nk = time ();
  13904. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  13905. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  13906. echo "文件无法保存.";
  13907. exit ( 0 );
  13908. }
  13909. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  13910. echo json_encode ( array (
  13911. 'filename' => $file_name,
  13912. 'id' => $nk
  13913. ) );
  13914. exit ( 0 );
  13915. }
  13916. function swfupload() {
  13917. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  13918. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  13919. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  13920. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  13921. header ( "HTTP/1.1 500 Internal Server Error" );
  13922. echo "POST exceeded maximum allowed size.";
  13923. exit ( 0 );
  13924. }
  13925. // Settings
  13926. $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)
  13927. $upload_name = "Filedata";
  13928. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  13929. $extension_whitelist = array (
  13930. "doc",
  13931. "txt",
  13932. "jpg",
  13933. "gif",
  13934. "png"
  13935. ); // Allowed file extensions
  13936. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  13937. // Other variables
  13938. $MAX_FILENAME_LENGTH = 260;
  13939. $file_name = "";
  13940. $file_extension = "";
  13941. $uploadErrors = array (
  13942. 0 => "文件上传成功",
  13943. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  13944. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  13945. 3 => "上传的文件仅为部分文件",
  13946. 4 => "没有文件上传",
  13947. 6 => "缺少临时文件夹"
  13948. );
  13949. $nk = time ();
  13950. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  13951. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  13952. echo "文件无法保存.";
  13953. exit ( 0 );
  13954. }
  13955. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  13956. echo json_encode ( array (
  13957. 'filename' => $file_name,
  13958. 'id' => $nk
  13959. ) );
  13960. exit ( 0 );
  13961. }
  13962. function _GetFileEXT($filename) {
  13963. $pics = explode ( '.', $filename );
  13964. $num = count ( $pics );
  13965. return $pics [$num - 1];
  13966. }
  13967. /**
  13968. * 获取get或者POST值
  13969. * @param string $name 属性名称
  13970. * @return fixed 值
  13971. */
  13972. function get_args($name) {
  13973. if (isset ( $_GET [$name] )) {
  13974. if (is_array ( $_GET [$name] ))
  13975. return $_GET [$name];
  13976. else
  13977. return addslashes ( $_GET [$name] );
  13978. } elseif (isset ( $_POST [$name] )) {
  13979. if (is_array ( $_POST [$name] ))
  13980. return $_POST [$name];
  13981. else
  13982. return addslashes ( $_POST [$name] );
  13983. } else
  13984. return false;
  13985. }
  13986. function num_to_rmb($num) {
  13987. $c1 = "零壹贰叁肆伍陆柒捌玖";
  13988. $c2 = "分角元拾佰仟万拾佰仟亿";
  13989. // 精确到分后面就不要了,所以只留两个小数位
  13990. $num = round ( $num, 2 );
  13991. // 将数字转化为整数
  13992. $num = $num * 100;
  13993. if (strlen ( $num ) > 10) {
  13994. return "金额太大,请检查";
  13995. }
  13996. $i = 0;
  13997. $c = "";
  13998. while ( 1 ) {
  13999. if ($i == 0) {
  14000. // 获取最后一位数字
  14001. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14002. } else {
  14003. $n = $num % 10;
  14004. }
  14005. // 每次将最后一位数字转化为中文
  14006. $p1 = substr ( $c1, 3 * $n, 3 );
  14007. $p2 = substr ( $c2, 3 * $i, 3 );
  14008. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14009. $c = $p1 . $p2 . $c;
  14010. } else {
  14011. $c = $p1 . $c;
  14012. }
  14013. $i = $i + 1;
  14014. // 去掉数字最后一位了
  14015. $num = $num / 10;
  14016. // echo $num.'</br>';
  14017. $num = ( int ) $num;
  14018. // $num =floor($num);
  14019. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14020. // echo $num.'</br>';
  14021. // 结束循环
  14022. if ($num == 0) {
  14023. break;
  14024. }
  14025. }
  14026. // echo $c.'</br>';
  14027. $j = 0;
  14028. $slen = strlen ( $c );
  14029. while ( $j < $slen ) {
  14030. // utf8一个汉字相当3个字符
  14031. $m = substr ( $c, $j, 6 );
  14032. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14033. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14034. $left = substr ( $c, 0, $j );
  14035. $right = substr ( $c, $j + 3 );
  14036. $c = $left . $right;
  14037. $j = $j - 3;
  14038. $slen = $slen - 3;
  14039. }
  14040. $j = $j + 3;
  14041. }
  14042. // 这个是为了去掉类似23.0中最后一个“零”字
  14043. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14044. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14045. }
  14046. // 将处理的汉字加上“整”
  14047. if (empty ( $c )) {
  14048. return "零元整";
  14049. } else {
  14050. return $c . "整";
  14051. }
  14052. }
  14053. /**
  14054. * 获得分页数据
  14055. * @param unknown_type $table
  14056. * @param unknown_type $condition
  14057. * @param unknown_type $on_page
  14058. * @param unknown_type $page_size
  14059. */
  14060. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14061. $page_c = "";
  14062. $page ['previous'] = $this->get_previous ( $on_page );
  14063. $page ['on_page'] = $on_page;
  14064. $total_count = $this->get_table_count ( $table, $condition );
  14065. $total = intval ( $total_count / $page_size );
  14066. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14067. $page ['total_data'] = $total_count;
  14068. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14069. $i = 1;
  14070. $page_max = 1;
  14071. $page_width = 3;
  14072. if ($on_page >= $page_width) {
  14073. $page_max = intval ( $on_page / $page_width ) + 1;
  14074. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14075. }
  14076. for(; $i <= $page ['total_page']; $i ++) {
  14077. if ($i == $on_page)
  14078. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14079. else
  14080. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14081. if ($i == ($page_width * $page_max))
  14082. break;
  14083. }
  14084. $page ['page'] = $page_c;
  14085. $page ['lower'] = (-- $on_page) * $page_size;
  14086. return $page;
  14087. }
  14088. /**
  14089. * 获取总页数
  14090. * @param unknown_type $table
  14091. * @param unknown_type $condition
  14092. */
  14093. public function get_table_count($table = "", $condition = "") {
  14094. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14095. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14096. // echo $sql;die;
  14097. $query = Doo::db ()->query ( $sql );
  14098. $result = $query->fetch ();
  14099. return $result ['count'];
  14100. }
  14101. /**
  14102. * 获取上一页
  14103. * @param unknown_type $on_page
  14104. */
  14105. function get_previous($on_page = 1) {
  14106. return $on_page != 0 ? $on_page - 1 : $on_page;
  14107. }
  14108. }
  14109. ?>