ReceiptController.php 542 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. public function beforeRun($resource, $action) {
  58. Doo::loadClass ( 'XDeode' );
  59. $XDeode = new XDeode ( 5 );
  60. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  61. // 单独判断公司汇总的访问权限
  62. if ($action == 'companyCategoryCollect') {
  63. Doo::loadModel ( "receiptAuthorityManage" );
  64. $invoiceCompanyManage = new receiptAuthorityManage ();
  65. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  66. if (empty ( $icm ))
  67. die ( 'illegal request' );
  68. }
  69. Doo::loadModel ( 'staff' );
  70. $staff = new staff ();
  71. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  72. $accessModular = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'where'=>'mold !="日常收支"',
  121. 'select' => 'staff',
  122. 'asArray' => true
  123. ) );
  124. $list2 = array ();
  125. foreach ( $executeList as $key => $value ) {
  126. $ver = json_decode ( $value ['staff'] );
  127. foreach ( $ver as $k => $v ) {
  128. array_push ( $list2, $v [0] );
  129. }
  130. }
  131. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  132. $eidList = array_filter ( explode ( ",", $eidList ) );
  133. $this->executeId = array_merge ( $list2, $eidList );
  134. $this->verifyId = $list;
  135. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  136. // 检测用户信息完成
  137. $this->data ['isStaffCompleteMsg'] = false;
  138. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  139. if (! empty ( $detail ))
  140. $this->data ['isStaffCompleteMsg'] = true;
  141. return "/";
  142. }
  143. }
  144. Doo::loadCore ( 'uri/DooUriRouter' );
  145. $router = new DooUriRouter ();
  146. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  147. if ($routeRs ['1'] != "login") {
  148. header ( 'Content-Type:text/html;charset=utf-8' );
  149. @header ( "Location: /login" );
  150. }
  151. }
  152. function saeaBorad() {
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'verify' );
  156. $verify = new verify ();
  157. Doo::loadModel ( 'L_category' );
  158. $lCategory = new L_category ();
  159. Doo::loadModel ( "role" );
  160. $role = new role ();
  161. Doo::loadModel ( "receiptLog" );
  162. $receiptLog = new receiptLog ();
  163. Doo::loadClass ( 'XDeode' );
  164. $XDeode = new XDeode ( 7 );
  165. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  166. $receiptDetail = $receipt->find ( array (
  167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  168. 'desc' => 'rid',
  169. 'asArray' => true
  170. ) );
  171. foreach ( $receiptDetail as $key => $value ) {
  172. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  173. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  174. $veList = $verify->getOne ( array (
  175. 'where' => 'vid=' . $value ['verify'],
  176. 'asArray' => true
  177. ) );
  178. $v = json_decode ( $veList ['staff'] );
  179. array_push ( $v [0], $veList ['description'] );
  180. foreach ( $v as $n => $m ) {
  181. if ($m ['1'] == 'ROLE') {
  182. $roleInfo = $role->getOne ( array (
  183. 'where' => 'rid=' . $m [0],
  184. 'asArray' => true
  185. ) );
  186. $v [$n] [1] = $roleInfo ['name'];
  187. }
  188. }
  189. $receiptDetail [$key] ['staff'] = $v;
  190. $category = $lCategory->getOne ( array (
  191. 'where' => 'cid=' . $value ['cid'],
  192. 'asArray' => true
  193. ) );
  194. $receiptDetail [$key] ['category'] = $category ['title'];
  195. }
  196. // print_r($receiptLogList);
  197. Doo::loadModel ( 'RAssist' );
  198. $RAssist = new RAssist ();
  199. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  200. $data ['receiptExtendList'] = $receiptExtendList;
  201. $data ['receiptLogList'] = $receiptLogList;
  202. $data ['receiptDetail'] = $receiptDetail;
  203. $data ['memu'] = "receipt";
  204. $data ['staff'] = $this->staff;
  205. $data ['receiptMemu'] = 'saeaBorad';
  206. $data ['verifyId'] = $this->verifyId;
  207. $data ['executeId'] = $this->executeId;
  208. $this->render ( "/admin/saeaBorad", $data );
  209. }
  210. function remitAdd() {
  211. Doo::loadModel ( 'accountItem' );
  212. Doo::loadModel ( 'verify' );
  213. Doo::loadModel ( 'receipt' );
  214. Doo::loadModel ( 'L_category' );
  215. $lCategory = new L_category ();
  216. $receipt = new receipt ();
  217. $verify = new verify ();
  218. $accountItem = new accountItem ();
  219. Doo::loadModel ( "role" );
  220. $role = new role ();
  221. $acItem = $accountItem->find ( array (
  222. 'asArray' => true
  223. ) );
  224. $veList = $verify->getVerifyBySubordinate('REMIT');
  225. $data ['category'] = $lCategory->find ( array (
  226. 'asArray' => true
  227. ) );
  228. $data ['veList'] = $veList;
  229. $data ['acItem'] = $acItem;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/admin/remitAdd", $data );
  236. }
  237. function remitAddDo() {
  238. $agency = $this->get_args ( 'agency' );
  239. $travel = $this->get_args ( 'travel' );
  240. $train = $this->get_args ( 'train' );
  241. $other = $this->get_args ( 'other' );
  242. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  243. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  244. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  245. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  246. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  247. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  248. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  249. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  250. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  251. // print_r($agency);die;
  252. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  253. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  254. header ( 'Content-Type:text/html;charset=utf-8' );
  255. die ( '请填写联行号' );
  256. }
  257. Doo::loadModel ( 'receipt' );
  258. Doo::loadModel ( 'receiptDetail' );
  259. Doo::loadModel ( 'accountItem' );
  260. $accountItem = new accountItem ();
  261. $receipt = new receipt ();
  262. Doo::loadModel ( 'enclosur' );
  263. Doo::loadModel ( 'execute' );
  264. $execute = new execute ();
  265. $executeDetail = $execute->getOne ( array (
  266. 'where' => 'mold="对公汇款执行人"',
  267. 'asArray' => true
  268. ) );
  269. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  270. $aItem = $accountItem->find ( array (
  271. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  272. 'asArray' => true
  273. ) );
  274. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  275. $ag = $tr = $ta = $ot = 0;
  276. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  277. print_r($aItem);
  278. foreach ( $aItem as $key => $value ) {
  279. if ($value ['category'] == $this->AGENCY) {
  280. if (isset ( $agency [$ag] )) {
  281. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  282. array_push ( $accountJson [$this->AGENCY], array (
  283. 'aid' => $value ['aid'],
  284. 'name' => $value ['name'],
  285. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  286. ) );
  287. $sum += $agency [$ag];
  288. $agencySum += $agency [$ag];
  289. }
  290. }
  291. $ag ++;
  292. }
  293. }
  294. $accountJson ['cSum'] = array (
  295. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  296. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  297. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  298. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  299. );
  300. //die;
  301. // 报销单
  302. $receipt->accountItem = json_encode ( $accountJson );
  303. $receipt->staff = $this->staff [0] ['sid'];
  304. $receipt->sum = number_format ( $sum, 2, '.', '' );
  305. $receipt->date = date ( "Y-m-d" );
  306. $receipt->cid = $cid;
  307. $receipt->status = 5;
  308. $receipt->Rtype = 2;
  309. // 修改审批流程加入角色
  310. $receipt->verify = $verify;
  311. $receipt->executeCopy = $executeDetail ['staff'];
  312. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  313. $order = array (
  314. "\r\n",
  315. "\n",
  316. "\r"
  317. );
  318. $replace = '<br/>';
  319. $explanation = str_replace ( $order, $replace, $explanation );
  320. $receipt->explanation = $explanation;
  321. $receipt->remittanceName = $remittanceName;
  322. $receipt->bankName = $bankName;
  323. $receipt->bankNumber = $bankNumber;
  324. $receipt->remittanceBankType = $remittanceBankType;
  325. if ($remittanceBankType == 1)
  326. $receipt->coupletNumber = $coupletNumber;
  327. $rid = $receipt->insert ();
  328. // 附件
  329. if (! empty ( $enclosurName )) {
  330. $enclosurArray = explode ( '-', $enclosurName );
  331. foreach ( $enclosurArray as $value ) {
  332. $enclosur = new enclosur ();
  333. $enclosur->name = $value;
  334. $enclosur->rid = $rid;
  335. $enclosur->insert ();
  336. }
  337. // print_r($enclosurArray);die;
  338. }
  339. // 报销详情
  340. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  341. $receiptDetail = new receiptDetail ();
  342. $receiptDetail->staff = $this->staff [0] ['sid'];
  343. $receiptDetail->item = $value ['name'];
  344. $receiptDetail->itemCategory = $this->AGENCY;
  345. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  346. $receiptDetail->date = date ( "Y-m-d" );
  347. $receiptDetail->cid = $cid;
  348. $receiptDetail->rid = $rid;
  349. $receiptDetail->status = 4;
  350. $receiptDetail->insert ();
  351. }
  352. return "/saeaBorad";
  353. } else
  354. die ( 'illegal request' );
  355. }
  356. function remitEdit() {
  357. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  358. Doo::loadClass ( 'XDeode' );
  359. $XDeode = new XDeode ( 7 );
  360. $rid = $XDeode->decode ( $ridKey );
  361. if (! is_numeric ( $rid ))
  362. die ( 'illegal request' );
  363. Doo::loadModel ( 'accountItem' );
  364. Doo::loadModel ( 'verify' );
  365. Doo::loadModel ( 'receipt' );
  366. $receipt = new receipt ();
  367. $verify = new verify ();
  368. $accountItem = new accountItem ();
  369. Doo::loadModel ( 'L_category' );
  370. $lCategory = new L_category ();
  371. Doo::loadModel ( "role" );
  372. $role = new role ();
  373. Doo::loadModel ( 'enclosur' );
  374. $enclosur = new enclosur ();
  375. $receiptDetail = $receipt->getOne ( array (
  376. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  377. 'asArray' => true
  378. ) );
  379. if (empty ( $receiptDetail ))
  380. return "/saeaCreate";
  381. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  382. $acItem = $accountItem->find ( array (
  383. 'asArray' => true
  384. ) );
  385. $veList = $verify->getVerifyBySubordinate('REMIT');
  386. // 配置编辑信息
  387. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  388. foreach ( $acItem as $key => $value ) {
  389. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  390. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  391. $acItem [$key] ['price'] = $v ['price'];
  392. }
  393. }
  394. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  395. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  396. $acItem [$key] ['price'] = $v ['price'];
  397. }
  398. }
  399. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  400. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  401. $acItem [$key] ['price'] = $v ['price'];
  402. }
  403. }
  404. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  405. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  406. $acItem [$key] ['price'] = $v ['price'];
  407. }
  408. }
  409. }
  410. $data ['category'] = $lCategory->find ( array (
  411. 'asArray' => true
  412. ) );
  413. $data ['enclosurList'] = $enclosurList;
  414. $data ['cSum'] = $accountItemList ['cSum'];
  415. $data ['sum'] = $receiptDetail ['sum'];
  416. $data ['receiptDetail'] = $receiptDetail;
  417. $data ['veList'] = $veList;
  418. $data ['acItem'] = $acItem;
  419. $data ['memu'] = "receipt";
  420. $data ['staff'] = $this->staff;
  421. $data ['receiptMemu'] = 'saeaBorad';
  422. $data ['verify'] = $receiptDetail ['verify'];
  423. $data ['verifyId'] = $this->verifyId;
  424. $data ['executeId'] = $this->executeId;
  425. $data ['rid'] = $rid;
  426. $data ['ridKey'] = $ridKey;
  427. $this->render ( "/admin/remitEdit", $data );
  428. }
  429. function remitEdiDo() {
  430. $agency = $this->get_args ( 'agency' );
  431. $travel = $this->get_args ( 'travel' );
  432. $train = $this->get_args ( 'train' );
  433. $other = $this->get_args ( 'other' );
  434. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  435. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  436. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  437. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  438. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  439. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  440. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  441. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  442. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  443. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  444. Doo::loadClass ( 'XDeode' );
  445. $XDeode = new XDeode ( 7 );
  446. $rid = $XDeode->decode ( $ridKey );
  447. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  448. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  449. header ( 'Content-Type:text/html;charset=utf-8' );
  450. die ( '请填写联行号' );
  451. }
  452. Doo::loadModel ( 'receipt' );
  453. Doo::loadModel ( 'receiptDetail' );
  454. Doo::loadModel ( 'accountItem' );
  455. $accountItem = new accountItem ();
  456. $receipt = new receipt ();
  457. Doo::loadModel ( 'enclosur' );
  458. $enclosur = new enclosur ();
  459. Doo::loadModel ( 'execute' );
  460. $execute = new execute ();
  461. $executeDetail = $execute->getOne ( array (
  462. 'where' => 'mold="对公汇款执行人"',
  463. 'asArray' => true
  464. ) );
  465. $receiptDetail = $receipt->getOne ( array (
  466. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  467. 'asArray' => true
  468. ) );
  469. if (empty ( $receiptDetail ))
  470. return "/saeaBorad";
  471. $aItem = $accountItem->find ( array (
  472. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  473. 'asArray' => true
  474. ) );
  475. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  476. $ag = $tr = $ta = $ot = 0;
  477. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  478. foreach ( $aItem as $key => $value ) {
  479. if ($value ['category'] == $this->AGENCY) {
  480. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  481. array_push ( $accountJson [$this->AGENCY], array (
  482. 'aid' => $value ['aid'],
  483. 'name' => $value ['name'],
  484. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  485. ) );
  486. $sum += $agency [$ag];
  487. $agencySum += $agency [$ag];
  488. }
  489. $ag ++;
  490. }
  491. }
  492. $accountJson ['cSum'] = array (
  493. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  494. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  495. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  496. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  497. );
  498. // 报销单
  499. $rid = $receipt->rid = $receiptDetail ['rid'];
  500. $receipt->accountItem = json_encode ( $accountJson );
  501. $receipt->staff = $this->staff [0] ['sid'];
  502. $receipt->sum = number_format ( $sum, 2, '.', '' );
  503. $receipt->date = date ( "Y-m-d" );
  504. $receipt->cid = $cid;
  505. if ($receiptDetail ['Rtype'] == 1)
  506. $receipt->status = 7;
  507. else
  508. $receipt->status = 5;
  509. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  510. $receipt->verify = $verify;
  511. $receipt->executeCopy = $executeDetail ['staff'];
  512. $order = array (
  513. "\r\n",
  514. "\n",
  515. "\r"
  516. );
  517. $replace = '<br/>';
  518. $explanation = str_replace ( $order, $replace, $explanation );
  519. $receipt->explanation = $explanation;
  520. $receipt->remittanceName = $remittanceName;
  521. $receipt->bankName = $bankName;
  522. $receipt->bankNumber = $bankNumber;
  523. $receipt->remittanceBankType = $remittanceBankType;
  524. if ($remittanceBankType == 1)
  525. $receipt->coupletNumber = $coupletNumber;
  526. $receipt->update ();
  527. $receiptDetail = new receiptDetail ();
  528. $receiptDetail->delete ( array (
  529. 'where' => 'rid=' . $rid
  530. ) );
  531. // 报销详情
  532. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  533. $receiptDetail = new receiptDetail ();
  534. $receiptDetail->staff = $this->staff [0] ['sid'];
  535. $receiptDetail->item = $value ['name'];
  536. $receiptDetail->itemCategory = $this->AGENCY;
  537. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  538. $receiptDetail->date = date ( "Y-m-d" );
  539. $receiptDetail->cid = $cid;
  540. $receiptDetail->rid = $rid;
  541. $receiptDetail->status = 4;
  542. $receiptDetail->insert ();
  543. }
  544. // 附件
  545. if (! empty ( $enclosurName )) {
  546. $enclosurArray = explode ( '-', $enclosurName );
  547. foreach ( $enclosurArray as $value ) {
  548. $enclosur = new enclosur ();
  549. $enclosur->name = $value;
  550. $enclosur->rid = $rid;
  551. $enclosur->insert ();
  552. }
  553. }
  554. }
  555. return "/saeaBorad";
  556. }
  557. function remitApproval() {
  558. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  559. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  561. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  562. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  563. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  564. if (empty ( $status ))
  565. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  566. $vidList = array ();
  567. $button = 0;
  568. Doo::loadModel ( 'verify' );
  569. Doo::loadModel ( 'receipt' );
  570. Doo::loadModel ( 'staff' );
  571. $staff = new staff ();
  572. $receipt = new receipt ();
  573. $verify = new verify ();
  574. Doo::loadModel ( 'L_category' );
  575. $Lcategory = new L_category ();
  576. Doo::loadModel ( 'enclosur' );
  577. $enclosur = new enclosur ();
  578. // user verify ID
  579. $verifyDetail = $verify->find ( array (
  580. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  581. 'asArray' => true
  582. ) );
  583. foreach ( $verifyDetail as $key => $value ) {
  584. array_push ( $vidList, $value ['vid'] );
  585. }
  586. $vid = implode ( ",", $vidList );
  587. if (empty ( $verifyDetail ))
  588. $vid = 0;
  589. $categoryList = $Lcategory->find ( array (
  590. 'asArray' => true
  591. ) );
  592. $staffList = $staff->find ( array (
  593. 'where' => 'cid=' . $cid,
  594. 'asArray' => true
  595. ) );
  596. $ap = "";
  597. if ($status == 4) {
  598. $ap = 4;
  599. $status = 2;
  600. }
  601. // get Receipt By verifyID status 2
  602. $receiptList = $receipt->find ( array (
  603. 'where' => 'rid =' . $rid . ' and status=2',
  604. 'desc' => 'rid',
  605. 'asArray' => true
  606. ) );
  607. if (empty ( $receiptList )) {
  608. die ( 'illegal request' );
  609. }
  610. $Locate = 0;
  611. $roleId = 0;
  612. if ($ap == 4)
  613. $status = 4;
  614. foreach ( $receiptList as $key => $value ) {
  615. $receiptList [$key] ['Locate'] = $Locate;
  616. $Locate ++;
  617. $receiptList [$key] ['reviseDetail'] = array ();
  618. if (! empty ( $value ['reviseDetail'] ))
  619. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  620. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  621. $categoryDetil = $Lcategory->getOne ( array (
  622. 'where' => 'cid=' . $value ['cid'],
  623. 'asArray' => true
  624. ) );
  625. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  626. // 检测编辑状态
  627. $verifyList = $verify->getOne ( array (
  628. 'where' => 'vid=' . $value ['verify'],
  629. 'asArray' => true
  630. ) );
  631. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  632. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  633. Doo::loadModel ( 'role' );
  634. $role = new role ();
  635. // print_r($verifyList);
  636. $flag = true;
  637. $roleKey = 0;
  638. $endStaffArray = array ();
  639. $roleArrayCopy = array ();
  640. foreach ( $verifyList as $k => $v ) {
  641. // init verifyStaff
  642. if ($v [1] == 'ROLE') {
  643. if (! empty ( $verifyStaff )) {
  644. $endStaffArray = end ( $verifyStaff );
  645. if ($v [0] == $endStaffArray ['nextStaff']) {
  646. $roleId = $v [0];
  647. }
  648. }
  649. $roleVerify = json_decode ( $v [3], true );
  650. $roleKey = $k;
  651. $roleArray = array ();
  652. $rolename = $role->getOne ( array (
  653. 'where' => 'rid=' . $v [0],
  654. 'asArray' => true
  655. ) );
  656. foreach ( $roleVerify as $o => $p ) {
  657. $staffID = explode ( '_', $p );
  658. $staffInfo = $staff->getOne ( array (
  659. 'where' => 'sid=' . $staffID [0],
  660. 'asArray' => true
  661. ) );
  662. // print_r($staffID);
  663. $exp = array (
  664. 0 => $staffInfo ['sid'],
  665. 1 => $staffID [1],
  666. 2 => $staffInfo ['avatar'],
  667. 'date' => '',
  668. 'date' => '',
  669. 'opinion' => '',
  670. 'status' => '',
  671. 'rolename' => $rolename ['name']
  672. );
  673. array_push ( $roleArray, $exp );
  674. }
  675. $roleArrayCopy [$v [0]] = $roleArray;
  676. // $verifyList[$k]['roleArray']=$roleArray;
  677. }
  678. // print_r($roleArray);
  679. $verifyList [$k] ['date'] = "";
  680. $verifyList [$k] ['opinion'] = "";
  681. $verifyList [$k] ['status'] = "";
  682. if (empty ( $verifyStaff )) {
  683. $verifyList [$k] ['date'] = "";
  684. $verifyList [$k] ['opinion'] = "";
  685. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  686. $verifyList [$k] ['status'] = 4;
  687. $button = 4;
  688. $flag = false;
  689. }
  690. } else {
  691. foreach ( $verifyStaff as $m => $u ) {
  692. if ($v [0] == $m) {
  693. $verifyList [$k] ['date'] = $u ['date'];
  694. $verifyList [$k] ['opinion'] = $u ['opinion'];
  695. $verifyList [$k] ['status'] = $u ['status'];
  696. $flag = false;
  697. break;
  698. }
  699. }
  700. $endStaffArray = end ( $verifyStaff );
  701. if (isset ( $endStaffArray ['ROLE'] )) {
  702. } else {
  703. $endKey = key ( $verifyStaff );
  704. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  705. $button = 4;
  706. $verifyList [$k] ['status'] = 4;
  707. }
  708. }
  709. }
  710. }
  711. $rolename ['name'] = '';
  712. if (! empty ( $roleId )) {
  713. Doo::loadModel ( 'role' );
  714. $role = new role ();
  715. $rolename = $role->getOne ( array (
  716. 'where' => 'rid=' . $roleId,
  717. 'asArray' => true
  718. ) );
  719. }
  720. if (! empty ( $verifyStaff ))
  721. $endStaffArray = end ( $verifyStaff );
  722. $KOP = false;
  723. foreach ( $roleArrayCopy as $P => $A ) {
  724. foreach ( $A as $MKI => $AVL ) {
  725. if (! empty ( $verifyStaff )) {
  726. // &&$rolename['rid']==$endStaffArray['nextStaff']
  727. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  728. $button = 4;
  729. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  730. }
  731. foreach ( $verifyStaff as $m => $u ) {
  732. $AVLFK = $AVL [0] . '_R';
  733. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  734. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  735. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  736. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  737. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  738. break;
  739. }
  740. }
  741. } else {
  742. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  743. $button = 4;
  744. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  745. }
  746. }
  747. // $roleArray[$MKI]['rolename']=$rolename['name'];
  748. $KOP = true;
  749. }
  750. }
  751. foreach ( $roleArrayCopy as $k => $v ) {
  752. foreach ( $verifyList as $m => $n ) {
  753. if ($n [0] == $k) {
  754. array_splice ( $verifyList, $m, 1, $v );
  755. }
  756. }
  757. }
  758. $receiptList [$key] ['verifyList'] = $verifyList;
  759. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  760. 'where' => 'sid=' . $value ['staff'],
  761. 'asArray' => true
  762. ) );
  763. $receiptList [$key] ['button'] = $button;
  764. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  765. }
  766. $mothHtml = "";
  767. for($i = 1; $i <= 12; $i ++) {
  768. if ($month == $i)
  769. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  770. else
  771. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  772. }
  773. // 获取审批日志
  774. Doo::loadModel ( 'receiptLog' );
  775. $receiptLog = new receiptLog ();
  776. $rlList = array ();
  777. $rlInfo = $receiptLog->getOne ( array (
  778. 'where' => 'rid=' . $rid . ' and status=4',
  779. 'asArray' => true
  780. ) );
  781. $tijdate = $receiptLog->getOne ( array (
  782. 'where' => 'rid=' . $rid . ' and status=2',
  783. 'asc' => 'rlid',
  784. 'asArray' => true
  785. ) );
  786. if (! empty ( $rlInfo )) {
  787. $rlList = $receiptLog->find ( array (
  788. 'where' => 'rid=' . $rid,
  789. 'asc' => 'rlid',
  790. 'asArray' => true
  791. ) );
  792. }
  793. $receiptList [0] ['rlList'] = $rlList;
  794. $enclosurList = $enclosur->find ( array (
  795. 'where' => 'rid=' . $rid,
  796. 'asArray' => true
  797. ) );
  798. $enclosurHtml = '';
  799. foreach ( $enclosurList as $value ) {
  800. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  801. }
  802. // print_r($receiptList);
  803. $data ['enclosurHtml'] = $enclosurHtml;
  804. $data ['rolename'] = $rolename ['name'];
  805. $data ['datetij'] = $tijdate ['date'];
  806. $data ['mothHtml'] = $mothHtml;
  807. $data ['rid'] = $rid;
  808. $data ['receiptList'] = $receiptList;
  809. $data ['receiptApprovalCount'] = count ( $receiptList );
  810. $data ['status'] = $status;
  811. $data ['year'] = $year;
  812. $data ['categoryList'] = $categoryList;
  813. $data ['staffList'] = $staffList;
  814. $data ['cid'] = $cid;
  815. $data ['sid'] = $sid;
  816. $data ['ap'] = $ap;
  817. $data ['memu'] = "receipt";
  818. $data ['staff'] = $this->staff;
  819. $data ['receiptMemu'] = 'approvalExpenses';
  820. $data ['verifyId'] = $this->verifyId;
  821. $data ['executeId'] = $this->executeId;
  822. $this->render ( "/admin/remitApproval", $data );
  823. }
  824. function saeaLoanAdd() {
  825. Doo::loadModel ( 'verify' );
  826. $verify = new verify ();
  827. Doo::loadModel ( "role" );
  828. $role = new role ();
  829. Doo::loadModel ( 'L_category' );
  830. $lCategory = new L_category ();
  831. $veList = $verify->getVerifyBySubordinate('LOAN');
  832. $data ['category'] = $lCategory->find ( array (
  833. 'asArray' => true
  834. ) );
  835. $data ['veList'] = $veList;
  836. $data ['memu'] = "receipt";
  837. $data ['staff'] = $this->staff;
  838. $data ['receiptMemu'] = 'saeaBorad';
  839. $data ['verifyId'] = $this->verifyId;
  840. $data ['executeId'] = $this->executeId;
  841. $this->render ( "/admin/saeaLoanAdd", $data );
  842. }
  843. function saeaLoanAddDo() {
  844. $agency = $this->get_args ( 'agency' );
  845. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  846. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  847. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  848. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  849. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  850. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  851. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  852. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  853. // die;
  854. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  855. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  856. header ( 'Content-Type:text/html;charset=utf-8' );
  857. die ( '请填写联行号' );
  858. }
  859. Doo::loadModel ( 'receipt' );
  860. Doo::loadModel ( 'receiptDetail' );
  861. Doo::loadModel ( 'accountItem' );
  862. $accountItem = new accountItem ();
  863. $receipt = new receipt ();
  864. Doo::loadModel ( 'loanReceipt' );
  865. $loanReceipt = new loanReceipt ();
  866. Doo::loadModel ( 'execute' );
  867. $execute = new execute ();
  868. Doo::loadModel ( 'enclosur' );
  869. $executeDetail = $execute->getOne ( array (
  870. 'where' => 'mold="借款执行人"',
  871. 'asArray' => true
  872. ) );
  873. $aItem = $accountItem->find ( array (
  874. 'asArray' => true
  875. ) );
  876. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  877. $ag = $tr = $ta = $ot = 0;
  878. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  879. array_push ( $accountJson ['借款费用'], array (
  880. 'aid' => 0,
  881. 'name' => '申请金额',
  882. 'price' => number_format ( $agency, 2, '.', '' )
  883. ) );
  884. $sum += $agency;
  885. $agencySum += $agency;
  886. $accountJson ['cSum'] = array (
  887. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  888. 'agencySum' => number_format ( 0, 2, '.', '' ),
  889. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  890. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  891. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  892. );
  893. // 借款数据备份
  894. $loanReceipt->loanItem = json_encode ( $accountJson );
  895. $loanReceipt->staff = $this->staff [0] ['sid'];
  896. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  897. $loanReceipt->date = date ( "Y-m-d" );
  898. $loanReceipt->cid = $cid;
  899. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  900. $loanReceipt->status = 5;
  901. $loanReceipt->Rtype = 1;
  902. $loanReceipt->verify = $verify;
  903. $receipt->receiptOrder = $receipt->receiptOrder;
  904. // 添加HTML换行符
  905. // var_dump($explanation);
  906. $order = array (
  907. "\r\n",
  908. "\n",
  909. "\r"
  910. );
  911. $replace = '<br/>';
  912. $explanation = str_replace ( $order, $replace, $explanation );
  913. // $explanation=str_replace('\r',"<br/>",$explanation);
  914. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  915. $loanReceipt->explanation = $explanation;
  916. $loanRid = $loanReceipt->insert ();
  917. // 报销单
  918. $receipt->loanItem = json_encode ( $accountJson );
  919. $receipt->staff = $this->staff [0] ['sid'];
  920. $receipt->sum = number_format ( $sum, 2, '.', '' );
  921. $receipt->date = date ( "Y-m-d" );
  922. $receipt->cid = $cid;
  923. // 特殊状态
  924. $receipt->status = 5;
  925. $receipt->Rtype = 1;
  926. $receipt->loanRid = $loanRid;
  927. // 修改审批流程加入角色
  928. $receipt->verify = $verify;
  929. $receipt->executeCopy = $executeDetail ['staff'];
  930. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  931. $receipt->explanation = $explanation;
  932. $receipt->remittanceName = $remittanceName;
  933. $receipt->bankName = $bankName;
  934. $receipt->bankNumber = $bankNumber;
  935. $receipt->remittanceBankType = $remittanceBankType;
  936. if ($remittanceBankType == 1)
  937. $receipt->coupletNumber = $coupletNumber;
  938. $rid = $receipt->insert ();
  939. return "/saeaBorad";
  940. } else
  941. die ( 'illegal request' );
  942. }
  943. function saeaLoanEdi() {
  944. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  945. Doo::loadClass ( 'XDeode' );
  946. $XDeode = new XDeode ( 7 );
  947. $rid = $XDeode->decode ( $ridKey );
  948. if (! is_numeric ( $rid ))
  949. die ( 'illegal request' );
  950. Doo::loadModel ( 'verify' );
  951. $verify = new verify ();
  952. Doo::loadModel ( "role" );
  953. $role = new role ();
  954. Doo::loadModel ( 'L_category' );
  955. $lCategory = new L_category ();
  956. Doo::loadModel ( 'receipt' );
  957. $receipt = new receipt ();
  958. $receiptInfo = $receipt->getOne ( array (
  959. 'where' => 'rid=' . $rid,
  960. 'asArray' => true
  961. ) );
  962. $veList = $verify->find ( array (
  963. 'where'=>'subordinate like "%LOAN%"',
  964. 'asArray' => true
  965. ) );
  966. foreach ( $veList as $key => $value ) {
  967. $v = json_decode ( $value ['staff'] );
  968. $list = array ();
  969. foreach ( $v as $n => $m ) {
  970. if ($m ['1'] == 'ROLE') {
  971. $roleInfo = $role->getOne ( array (
  972. 'where' => 'rid=' . $m [0],
  973. 'asArray' => true
  974. ) );
  975. $v [$n] [1] = $roleInfo ['name'];
  976. array_push ( $list, $roleInfo ['name'] );
  977. } else {
  978. array_push ( $list, $v [$n] [1] );
  979. }
  980. }
  981. $veList [$key] ['staff'] = implode ( '>', $list );
  982. }
  983. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  984. // print_r($receiptInfo);
  985. $data ['receiptInfo'] = $receiptInfo;
  986. $data ['category'] = $lCategory->find ( array (
  987. 'asArray' => true
  988. ) );
  989. $data ['veList'] = $veList;
  990. $data ['ridKey'] = $ridKey;
  991. $data ['memu'] = "receipt";
  992. $data ['staff'] = $this->staff;
  993. $data ['receiptMemu'] = 'saeaBorad';
  994. $data ['verifyId'] = $this->verifyId;
  995. $data ['executeId'] = $this->executeId;
  996. $this->render ( "/admin/saeaLoanEdi", $data );
  997. }
  998. function saeaLoanEdiDo() {
  999. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1000. $agency = $this->get_args ( 'agency' );
  1001. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1002. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1003. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1004. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1005. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1006. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1007. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1008. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1009. // die;
  1010. Doo::loadClass ( 'XDeode' );
  1011. $XDeode = new XDeode ( 7 );
  1012. $rid = $XDeode->decode ( $ridKey );
  1013. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1014. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1015. header ( 'Content-Type:text/html;charset=utf-8' );
  1016. die ( '请填写联行号' );
  1017. }
  1018. Doo::loadModel ( 'receipt' );
  1019. Doo::loadModel ( 'receiptDetail' );
  1020. Doo::loadModel ( 'accountItem' );
  1021. $accountItem = new accountItem ();
  1022. $receipt = new receipt ();
  1023. Doo::loadModel ( 'loanReceipt' );
  1024. $loanReceipt = new loanReceipt ();
  1025. Doo::loadModel ( 'enclosur' );
  1026. Doo::loadModel ( 'execute' );
  1027. $execute = new execute ();
  1028. $executeDetail = $execute->getOne ( array (
  1029. 'where' => 'mold="借款执行人"',
  1030. 'asArray' => true
  1031. ) );
  1032. $receiptDetail = $receipt->getOne ( array (
  1033. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1034. 'asArray' => true
  1035. ) );
  1036. if (empty ( $receiptDetail ))
  1037. die ( '参数错误' );
  1038. $aItem = $accountItem->find ( array (
  1039. 'asArray' => true
  1040. ) );
  1041. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1042. $ag = $tr = $ta = $ot = 0;
  1043. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1044. array_push ( $accountJson ['借款费用'], array (
  1045. 'aid' => 0,
  1046. 'name' => '申请金额',
  1047. 'price' => number_format ( $agency, 2, '.', '' )
  1048. ) );
  1049. $sum += $agency;
  1050. $agencySum += $agency;
  1051. $accountJson ['cSum'] = array (
  1052. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1053. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1054. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1055. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1056. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1057. );
  1058. // 报销单
  1059. $receipt->loanItem = json_encode ( $accountJson );
  1060. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1061. $receipt->cid = $cid;
  1062. // 特殊状态
  1063. // 修改审批流程加入角色
  1064. if ($receiptDetail ['status'] != 4)
  1065. $receipt->verify = $verify;
  1066. $order = array (
  1067. "\r\n",
  1068. "\n",
  1069. "\r"
  1070. );
  1071. $replace = '<br/>';
  1072. $explanation = str_replace ( $order, $replace, $explanation );
  1073. $receipt->explanation = $explanation;
  1074. $receipt->remittanceName = $remittanceName;
  1075. $receipt->bankName = $bankName;
  1076. $receipt->bankNumber = $bankNumber;
  1077. $receipt->remittanceBankType = $remittanceBankType;
  1078. if ($remittanceBankType == 1)
  1079. $receipt->coupletNumber = $coupletNumber;
  1080. $receipt->update ( array (
  1081. 'where' => 'rid=' . $rid
  1082. ) );
  1083. // 借款数据更新
  1084. $loanReceipt->loanItem = json_encode ( $accountJson );
  1085. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1086. $loanReceipt->cid = $cid;
  1087. if ($receiptDetail ['status'] != 4)
  1088. $loanReceipt->verify = $verify;
  1089. $loanReceipt->explanation = $explanation;
  1090. $receipt->executeCopy = $executeDetail ['staff'];
  1091. $loanReceipt->update ( array (
  1092. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1093. ) );
  1094. }
  1095. return "/saeaBorad";
  1096. }
  1097. function saeaLoanReceiptAdd() {
  1098. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. Doo::loadModel ( 'loanReceipt' );
  1102. $loanReceipt = new loanReceipt ();
  1103. Doo::loadModel ( 'L_category' );
  1104. $Lcategory = new L_category ();
  1105. Doo::loadModel ( 'verify' );
  1106. Doo::loadModel ( 'statistics' );
  1107. $statistics = new statistics ();
  1108. $verify = new verify ();
  1109. Doo::loadModel ( 'staff' );
  1110. $staff = new staff ();
  1111. $receiptDetail = $receipt->getOne ( array (
  1112. 'where' => 'rid=' . $rid,
  1113. 'desc' => 'rid',
  1114. 'asArray' => true
  1115. ) );
  1116. $receiptList = $loanReceipt->find ( array (
  1117. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1118. 'desc' => 'rid',
  1119. 'asArray' => true
  1120. ) );
  1121. $Locate = 0;
  1122. $roleId = 0;
  1123. $button = 0;
  1124. foreach ( $receiptList as $key => $value ) {
  1125. $receiptList [$key] ['Locate'] = $Locate;
  1126. $Locate ++;
  1127. $receiptList [$key] ['reviseDetail'] = array ();
  1128. if (! empty ( $value ['reviseDetail'] ))
  1129. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1130. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1131. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1132. $categoryDetil = $Lcategory->getOne ( array (
  1133. 'where' => 'cid=' . $value ['cid'],
  1134. 'asArray' => true
  1135. ) );
  1136. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1137. // 检测编辑状态
  1138. $verifyList = $verify->getOne ( array (
  1139. 'where' => 'vid=' . $value ['verify'],
  1140. 'asArray' => true
  1141. ) );
  1142. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1143. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1144. Doo::loadModel ( 'role' );
  1145. $role = new role ();
  1146. $flag = true;
  1147. $roleKey = 0;
  1148. $endStaffArray = array ();
  1149. $roleArrayCopy = array ();
  1150. foreach ( $verifyList as $k => $v ) {
  1151. // init verifyStaff
  1152. if ($v [1] == 'ROLE') {
  1153. if (! empty ( $verifyStaff )) {
  1154. $endStaffArray = end ( $verifyStaff );
  1155. // if ($v[0]==$endStaffArray['nextStaff']){
  1156. // $roleId=$v[0];
  1157. // }
  1158. }
  1159. $roleVerify = json_decode ( $v [3], true );
  1160. $roleKey = $k;
  1161. $roleArray = array ();
  1162. $rolename = $role->getOne ( array (
  1163. 'where' => 'rid=' . $v [0],
  1164. 'asArray' => true
  1165. ) );
  1166. foreach ( $roleVerify as $o => $p ) {
  1167. $staffID = explode ( '_', $p );
  1168. $staffInfo = $staff->getOne ( array (
  1169. 'where' => 'sid=' . $staffID [0],
  1170. 'asArray' => true
  1171. ) );
  1172. // print_r($staffID);
  1173. $exp = array (
  1174. 0 => $staffInfo ['sid'],
  1175. 1 => $staffID [1],
  1176. 2 => $staffInfo ['avatar'],
  1177. 'date' => '',
  1178. 'date' => '',
  1179. 'opinion' => '',
  1180. 'status' => '',
  1181. 'rolename' => $rolename ['name']
  1182. );
  1183. array_push ( $roleArray, $exp );
  1184. }
  1185. $roleArrayCopy [$v [0]] = $roleArray;
  1186. // $verifyList[$k]['roleArray']=$roleArray;
  1187. }
  1188. $verifyList [$k] ['date'] = "";
  1189. $verifyList [$k] ['opinion'] = "";
  1190. $verifyList [$k] ['status'] = "";
  1191. if (empty ( $verifyStaff )) {
  1192. $verifyList [$k] ['date'] = "";
  1193. $verifyList [$k] ['opinion'] = "";
  1194. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1195. $verifyList [$k] ['status'] = 4;
  1196. $flag = false;
  1197. }
  1198. } else {
  1199. foreach ( $verifyStaff as $m => $u ) {
  1200. if ($v [0] == $m) {
  1201. $verifyList [$k] ['date'] = $u ['date'];
  1202. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1203. $verifyList [$k] ['status'] = $u ['status'];
  1204. $flag = false;
  1205. break;
  1206. }
  1207. }
  1208. $endStaffArray = end ( $verifyStaff );
  1209. if (isset ( $endStaffArray ['ROLE'] )) {
  1210. } else {
  1211. // $endKey=key($verifyStaff);
  1212. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1213. // $button=4;
  1214. // $verifyList[$k]['status']=4;
  1215. // }
  1216. }
  1217. }
  1218. }
  1219. $rolename ['name'] = '';
  1220. if (! empty ( $roleId )) {
  1221. Doo::loadModel ( 'role' );
  1222. $role = new role ();
  1223. $rolename = $role->getOne ( array (
  1224. 'where' => 'rid=' . $roleId,
  1225. 'asArray' => true
  1226. ) );
  1227. }
  1228. if (! empty ( $verifyStaff ))
  1229. $endStaffArray = end ( $verifyStaff );
  1230. $KOP = false;
  1231. foreach ( $roleArrayCopy as $P => $A ) {
  1232. foreach ( $A as $MKI => $AVL ) {
  1233. if (! empty ( $verifyStaff )) {
  1234. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1235. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1236. $button = 4;
  1237. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1238. }
  1239. foreach ( $verifyStaff as $m => $u ) {
  1240. $AVLFK = $AVL [0] . '_R';
  1241. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1242. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1243. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1244. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1245. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1246. break;
  1247. }
  1248. }
  1249. } else {
  1250. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1251. $button = 4;
  1252. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1253. }
  1254. }
  1255. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1256. $KOP = true;
  1257. }
  1258. }
  1259. foreach ( $roleArrayCopy as $k => $v ) {
  1260. foreach ( $verifyList as $m => $n ) {
  1261. if ($n [0] == $k) {
  1262. array_splice ( $verifyList, $m, 1, $v );
  1263. }
  1264. }
  1265. }
  1266. $receiptList [$key] ['verifyList'] = $verifyList;
  1267. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1268. 'where' => 'sid=' . $value ['staff'],
  1269. 'asArray' => true
  1270. ) );
  1271. $receiptList [$key] ['button'] = $button;
  1272. //
  1273. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1274. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1275. }
  1276. $data ['receiptList'] = $receiptList;
  1277. $data ['receiptDetail'] = $receiptDetail;
  1278. Doo::loadModel ( 'L_category' );
  1279. $lCategory = new L_category ();
  1280. Doo::loadModel ( 'accountItem' );
  1281. $accountItem = new accountItem ();
  1282. $acItem = $accountItem->find ( array (
  1283. 'asArray' => true
  1284. ) );
  1285. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1286. $data ['rid'] = $rid;
  1287. $data ['category'] = $lCategory->find ( array (
  1288. 'asArray' => true
  1289. ) );
  1290. $data ['veList'] = $veList;
  1291. $data ['acItem'] = $acItem;
  1292. $data ['memu'] = "receipt";
  1293. $data ['staff'] = $this->staff;
  1294. $data ['receiptMemu'] = 'saeaBorad';
  1295. $data ['verifyId'] = $this->verifyId;
  1296. $data ['executeId'] = $this->executeId;
  1297. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1298. }
  1299. function saeaLoanReceiptAddDo() {
  1300. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1301. $agency = $this->get_args ( 'agency' );
  1302. $travel = $this->get_args ( 'travel' );
  1303. $train = $this->get_args ( 'train' );
  1304. $other = $this->get_args ( 'other' );
  1305. $inttrain = $this->get_args ( 'inttrain' );
  1306. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1307. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1308. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1309. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1310. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1311. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1312. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1313. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1314. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1315. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1316. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1317. header ( 'Content-Type:text/html;charset=utf-8' );
  1318. die ( '请填写联行号' );
  1319. }
  1320. Doo::loadModel ( 'receipt' );
  1321. Doo::loadModel ( 'receiptDetail' );
  1322. Doo::loadModel ( 'accountItem' );
  1323. $accountItem = new accountItem ();
  1324. $receipt = new receipt ();
  1325. Doo::loadModel ( 'enclosur' );
  1326. Doo::loadModel ( 'execute' );
  1327. $execute = new execute ();
  1328. $executeDetail = $execute->getOne ( array (
  1329. 'where' => 'mold="借款费用执行人"',
  1330. 'asArray' => true
  1331. ) );
  1332. $receiptDet = $receipt->getOne ( array (
  1333. 'where' => 'rid=' . $rid,
  1334. 'asArray' => true
  1335. ) );
  1336. // if(!empty($receiptDetail))
  1337. // return "/referReceipt/".$receiptDetail['rid'];
  1338. $aItem = $accountItem->find ( array (
  1339. 'asArray' => true
  1340. ) );
  1341. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1342. $ag = $tr = $ta = $ot =$it = 0;
  1343. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1344. foreach ( $aItem as $key => $value ) {
  1345. if ($value ['category'] == $this->AGENCY) {
  1346. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1347. array_push ( $accountJson [$this->AGENCY], array (
  1348. 'aid' => $value ['aid'],
  1349. 'name' => $value ['name'],
  1350. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1351. ) );
  1352. $sum += $agency [$ag];
  1353. $agencySum += $agency [$ag];
  1354. }
  1355. $ag ++;
  1356. }
  1357. if ($value ['category'] == $this->TRAVEL) {
  1358. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1359. array_push ( $accountJson [$this->TRAVEL], array (
  1360. 'aid' => $value ['aid'],
  1361. 'name' => $value ['name'],
  1362. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1363. ) );
  1364. $sum += $travel [$tr];
  1365. $travelSum += $travel [$tr];
  1366. }
  1367. $tr ++;
  1368. }
  1369. if ($value ['category'] == $this->INTTRAIN) {
  1370. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1371. array_push ( $accountJson [$this->INTTRAIN], array (
  1372. 'aid' => $value ['aid'],
  1373. 'name' => $value ['name'],
  1374. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1375. ) );
  1376. $sum += $inttrain [$it];
  1377. $inttrainSum += $inttrain [$it];
  1378. }
  1379. $it ++;
  1380. }
  1381. if ($value ['category'] == $this->TRAIN) {
  1382. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1383. array_push ( $accountJson [$this->TRAIN], array (
  1384. 'aid' => $value ['aid'],
  1385. 'name' => $value ['name'],
  1386. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1387. ) );
  1388. $sum += $train [$ta];
  1389. $trainSum += $train [$ta];
  1390. }
  1391. $ta ++;
  1392. }
  1393. if ($value ['category'] == $this->OTHER) {
  1394. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1395. array_push ( $accountJson [$this->OTHER], array (
  1396. 'aid' => $value ['aid'],
  1397. 'name' => $value ['name'],
  1398. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1399. ) );
  1400. $sum += $other [$ot];
  1401. $otherSum += $other [$ot];
  1402. }
  1403. $ot ++;
  1404. }
  1405. }
  1406. $accountJson ['cSum'] = array (
  1407. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1408. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1409. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1410. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1411. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1412. );
  1413. // 报销单
  1414. $receipt->accountItem = json_encode ( $accountJson );
  1415. $receipt->staff = $this->staff [0] ['sid'];
  1416. $receipt->loanSum = $receiptDet ['sum'];
  1417. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1418. $receipt->date = date ( "Y-m-d" );
  1419. $receipt->pastDate = '';
  1420. $receipt->cid = $cid;
  1421. $receipt->status = 7;
  1422. // 修改审批流程加入角色
  1423. $receipt->verify = $verify;
  1424. $receipt->verifyStaff = '';
  1425. $receipt->executeStaff = '';
  1426. $receipt->executeCopy = $executeDetail ['staff'];
  1427. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1428. $receipt->explanation = $explanation;
  1429. $receipt->remittanceName = $remittanceName;
  1430. $receipt->bankName = $bankName;
  1431. $receipt->bankNumber = $bankNumber;
  1432. $receipt->remittanceBankType = $remittanceBankType;
  1433. if ($remittanceBankType == 1)
  1434. $receipt->coupletNumber = $coupletNumber;
  1435. $receipt->update ( array (
  1436. 'where' => 'rid=' . $rid
  1437. ) );
  1438. // 附件
  1439. if (! empty ( $enclosurName )) {
  1440. $enclosurArray = explode ( '-', $enclosurName );
  1441. foreach ( $enclosurArray as $value ) {
  1442. $enclosur = new enclosur ();
  1443. $enclosur->name = $value;
  1444. $enclosur->rid = $rid;
  1445. $enclosur->insert ();
  1446. }
  1447. // print_r($enclosurArray);die;
  1448. }
  1449. // 报销详情
  1450. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1451. $receiptDetail = new receiptDetail ();
  1452. $receiptDetail->staff = $this->staff [0] ['sid'];
  1453. $receiptDetail->item = $value ['name'];
  1454. $receiptDetail->itemCategory = $this->AGENCY;
  1455. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1456. $receiptDetail->date = date ( "Y-m-d" );
  1457. $receiptDetail->cid = $cid;
  1458. $receiptDetail->rid = $rid;
  1459. $receiptDetail->status = 4;
  1460. $receiptDetail->insert ();
  1461. }
  1462. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1463. $receiptDetail = new receiptDetail ();
  1464. $receiptDetail->staff = $this->staff [0] ['sid'];
  1465. $receiptDetail->item = $value ['name'];
  1466. $receiptDetail->itemCategory = $this->TRAVEL;
  1467. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1468. $receiptDetail->date = date ( "Y-m-d" );
  1469. $receiptDetail->cid = $cid;
  1470. $receiptDetail->rid = $rid;
  1471. $receiptDetail->status = 4;
  1472. $receiptDetail->insert ();
  1473. }
  1474. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1475. $receiptDetail = new receiptDetail ();
  1476. $receiptDetail->staff = $this->staff [0] ['sid'];
  1477. $receiptDetail->item = $value ['name'];
  1478. $receiptDetail->itemCategory = $this->TRAIN;
  1479. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1480. $receiptDetail->date = date ( "Y-m-d" );
  1481. $receiptDetail->cid = $cid;
  1482. $receiptDetail->rid = $rid;
  1483. $receiptDetail->status = 4;
  1484. $receiptDetail->insert ();
  1485. }
  1486. //内训
  1487. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1488. $receiptDetail = new receiptDetail ();
  1489. $receiptDetail->staff = $this->staff [0] ['sid'];
  1490. $receiptDetail->item = $value ['name'];
  1491. $receiptDetail->itemCategory = $this->INTTRAIN;
  1492. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1493. $receiptDetail->date = date ( "Y-m-d" );
  1494. $receiptDetail->cid = $cid;
  1495. $receiptDetail->rid = $rid;
  1496. $receiptDetail->status = 4;
  1497. $receiptDetail->insert ();
  1498. }
  1499. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1500. $receiptDetail = new receiptDetail ();
  1501. $receiptDetail->staff = $this->staff [0] ['sid'];
  1502. $receiptDetail->item = $value ['name'];
  1503. $receiptDetail->itemCategory = $this->OTHER;
  1504. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1505. $receiptDetail->date = date ( "Y-m-d" );
  1506. $receiptDetail->cid = $cid;
  1507. $receiptDetail->rid = $rid;
  1508. $receiptDetail->status = 4;
  1509. $receiptDetail->insert ();
  1510. }
  1511. return "/saeaBorad";
  1512. }
  1513. return "/saeaLoanReceiptAdd/" . $rid;
  1514. }
  1515. function saeaLoanReceiptEdi() {
  1516. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1517. Doo::loadClass ( 'XDeode' );
  1518. $XDeode = new XDeode ( 7 );
  1519. $rid = $XDeode->decode ( $ridKey );
  1520. if (! is_numeric ( $rid ))
  1521. die ( 'illegal request' );
  1522. Doo::loadModel ( 'accountItem' );
  1523. Doo::loadModel ( 'verify' );
  1524. Doo::loadModel ( 'receipt' );
  1525. $receipt = new receipt ();
  1526. $verify = new verify ();
  1527. $accountItem = new accountItem ();
  1528. Doo::loadModel ( 'L_category' );
  1529. $Lcategory = new L_category ();
  1530. Doo::loadModel ( "role" );
  1531. $role = new role ();
  1532. Doo::loadModel ( 'loanReceipt' );
  1533. $loanReceipt = new loanReceipt ();
  1534. Doo::loadModel ( 'staff' );
  1535. $staff = new staff ();
  1536. $receiptDetail = $receipt->getOne ( array (
  1537. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1538. 'asArray' => true
  1539. ) );
  1540. if (empty ( $receiptDetail ))
  1541. return "/saeaBorad";
  1542. $receiptList = $loanReceipt->find ( array (
  1543. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1544. 'desc' => 'rid',
  1545. 'asArray' => true
  1546. ) );
  1547. $Locate = 0;
  1548. $roleId = 0;
  1549. $button = 0;
  1550. foreach ( $receiptList as $key => $value ) {
  1551. $receiptList [$key] ['Locate'] = $Locate;
  1552. $Locate ++;
  1553. $receiptList [$key] ['reviseDetail'] = array ();
  1554. if (! empty ( $value ['reviseDetail'] ))
  1555. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1556. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1557. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1558. $categoryDetil = $Lcategory->getOne ( array (
  1559. 'where' => 'cid=' . $value ['cid'],
  1560. 'asArray' => true
  1561. ) );
  1562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1563. // 检测编辑状态
  1564. $verifyList = $verify->getOne ( array (
  1565. 'where' => 'vid=' . $value ['verify'],
  1566. 'asArray' => true
  1567. ) );
  1568. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1569. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1570. Doo::loadModel ( 'role' );
  1571. $role = new role ();
  1572. $flag = true;
  1573. $roleKey = 0;
  1574. $endStaffArray = array ();
  1575. $roleArrayCopy = array ();
  1576. foreach ( $verifyList as $k => $v ) {
  1577. // init verifyStaff
  1578. if ($v [1] == 'ROLE') {
  1579. if (! empty ( $verifyStaff )) {
  1580. $endStaffArray = end ( $verifyStaff );
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify = json_decode ( $v [3], true );
  1586. $roleKey = $k;
  1587. $roleArray = array ();
  1588. $rolename = $role->getOne ( array (
  1589. 'where' => 'rid=' . $v [0],
  1590. 'asArray' => true
  1591. ) );
  1592. foreach ( $roleVerify as $o => $p ) {
  1593. $staffID = explode ( '_', $p );
  1594. $staffInfo = $staff->getOne ( array (
  1595. 'where' => 'sid=' . $staffID [0],
  1596. 'asArray' => true
  1597. ) );
  1598. // print_r($staffID);
  1599. $exp = array (
  1600. 0 => $staffInfo ['sid'],
  1601. 1 => $staffID [1],
  1602. 2 => $staffInfo ['avatar'],
  1603. 'date' => '',
  1604. 'date' => '',
  1605. 'opinion' => '',
  1606. 'status' => '',
  1607. 'rolename' => $rolename ['name']
  1608. );
  1609. array_push ( $roleArray, $exp );
  1610. }
  1611. $roleArrayCopy [$v [0]] = $roleArray;
  1612. // $verifyList[$k]['roleArray']=$roleArray;
  1613. }
  1614. $verifyList [$k] ['date'] = "";
  1615. $verifyList [$k] ['opinion'] = "";
  1616. $verifyList [$k] ['status'] = "";
  1617. if (empty ( $verifyStaff )) {
  1618. $verifyList [$k] ['date'] = "";
  1619. $verifyList [$k] ['opinion'] = "";
  1620. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1621. $verifyList [$k] ['status'] = 4;
  1622. $flag = false;
  1623. }
  1624. } else {
  1625. foreach ( $verifyStaff as $m => $u ) {
  1626. if ($v [0] == $m) {
  1627. $verifyList [$k] ['date'] = $u ['date'];
  1628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1629. $verifyList [$k] ['status'] = $u ['status'];
  1630. $flag = false;
  1631. break;
  1632. }
  1633. }
  1634. $endStaffArray = end ( $verifyStaff );
  1635. if (isset ( $endStaffArray ['ROLE'] )) {
  1636. } else {
  1637. // $endKey=key($verifyStaff);
  1638. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1639. // $button=4;
  1640. // $verifyList[$k]['status']=4;
  1641. // }
  1642. }
  1643. }
  1644. }
  1645. $rolename ['name'] = '';
  1646. if (! empty ( $roleId )) {
  1647. Doo::loadModel ( 'role' );
  1648. $role = new role ();
  1649. $rolename = $role->getOne ( array (
  1650. 'where' => 'rid=' . $roleId,
  1651. 'asArray' => true
  1652. ) );
  1653. }
  1654. if (! empty ( $verifyStaff ))
  1655. $endStaffArray = end ( $verifyStaff );
  1656. $KOP = false;
  1657. foreach ( $roleArrayCopy as $P => $A ) {
  1658. foreach ( $A as $MKI => $AVL ) {
  1659. if (! empty ( $verifyStaff )) {
  1660. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. foreach ( $verifyStaff as $m => $u ) {
  1666. $AVLFK = $AVL [0] . '_R';
  1667. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1668. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1669. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1670. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1671. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1672. break;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1677. $button = 4;
  1678. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1679. }
  1680. }
  1681. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1682. $KOP = true;
  1683. }
  1684. }
  1685. foreach ( $roleArrayCopy as $k => $v ) {
  1686. foreach ( $verifyList as $m => $n ) {
  1687. if ($n [0] == $k) {
  1688. array_splice ( $verifyList, $m, 1, $v );
  1689. }
  1690. }
  1691. }
  1692. $receiptList [$key] ['verifyList'] = $verifyList;
  1693. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1694. 'where' => 'sid=' . $value ['staff'],
  1695. 'asArray' => true
  1696. ) );
  1697. $receiptList [$key] ['button'] = $button;
  1698. //
  1699. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1700. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1701. }
  1702. $data ['receiptList'] = $receiptList;
  1703. $acItem = $accountItem->find ( array (
  1704. 'asArray' => true
  1705. ) );
  1706. $veList = $verify->find ( array (
  1707. 'asArray' => true
  1708. ) );
  1709. foreach ( $veList as $key => $value ) {
  1710. $v = json_decode ( $value ['staff'] );
  1711. $list = array ();
  1712. foreach ( $v as $n => $m ) {
  1713. if ($m ['1'] == 'ROLE') {
  1714. $roleInfo = $role->getOne ( array (
  1715. 'where' => 'rid=' . $m [0],
  1716. 'asArray' => true
  1717. ) );
  1718. $v [$n] [1] = $roleInfo ['name'];
  1719. array_push ( $list, $roleInfo ['name'] );
  1720. } else {
  1721. array_push ( $list, $v [$n] [1] );
  1722. }
  1723. }
  1724. $veList [$key] ['staff'] = implode ( '>', $list );
  1725. }
  1726. // 配置编辑信息
  1727. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1728. foreach ( $acItem as $key => $value ) {
  1729. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1730. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1731. $acItem [$key] ['price'] = $v ['price'];
  1732. }
  1733. }
  1734. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1735. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1736. $acItem [$key] ['price'] = $v ['price'];
  1737. }
  1738. }
  1739. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1740. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1741. $acItem [$key] ['price'] = $v ['price'];
  1742. }
  1743. }
  1744. //内训
  1745. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1746. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1747. $acItem [$key] ['price'] = $v ['price'];
  1748. }
  1749. }
  1750. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1751. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1752. $acItem [$key] ['price'] = $v ['price'];
  1753. }
  1754. }
  1755. }
  1756. $data ['category'] = $Lcategory->find ( array (
  1757. 'asArray' => true
  1758. ) );
  1759. $data ['ridKey'] = $ridKey;
  1760. $data ['cSum'] = $accountItemList ['cSum'];
  1761. $data ['sum'] = $receiptDetail ['sum'];
  1762. $data ['receiptDetail'] = $receiptDetail;
  1763. $data ['veList'] = $veList;
  1764. $data ['acItem'] = $acItem;
  1765. $data ['memu'] = "receipt";
  1766. $data ['staff'] = $this->staff;
  1767. $data ['receiptMemu'] = 'saeaBorad';
  1768. $data ['verify'] = $receiptDetail ['verify'];
  1769. $data ['verifyId'] = $this->verifyId;
  1770. $data ['executeId'] = $this->executeId;
  1771. $data ['rid'] = $rid;
  1772. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1773. }
  1774. /**
  1775. * 培训班结算
  1776. */
  1777. function receiptTrainAdd() {
  1778. Doo::loadModel ( 'accountItem' );
  1779. $accountItem = new accountItem ();
  1780. $acItem = $accountItem->find ( array (
  1781. 'asArray' => true
  1782. ) );
  1783. // 审批组
  1784. Doo::loadModel ( 'verify' );
  1785. $verify = new verify ();
  1786. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1787. // 办事处
  1788. Doo::loadModel ( 'L_category' );
  1789. $lCategory = new L_category ();
  1790. $data ['category'] = $lCategory->getCategory ();
  1791. $data ['veList'] = $veList;
  1792. $data ['memu'] = "receipt";
  1793. $data ['staff'] = $this->staff;
  1794. $data ['acItem'] = $acItem;
  1795. $data ['receiptMemu'] = 'saeaBorad';
  1796. $data ['verifyId'] = $this->verifyId;
  1797. $data ['executeId'] = $this->executeId;
  1798. $this->render ( "/receipt/receiptTrainAdd", $data );
  1799. }
  1800. /**
  1801. * 添加培训班结算
  1802. */
  1803. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1804. // 培训班信息
  1805. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1806. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1807. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1808. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1809. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  1810. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1811. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1812. // 发票信息
  1813. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1814. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1815. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1816. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1817. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1818. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1819. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1820. //&&! empty ( $participants )
  1821. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  1822. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1823. header ( 'Content-Type:text/html;charset=utf-8' );
  1824. die ( '请填写联行号' );
  1825. }
  1826. Doo::loadModel ( 'execute' );
  1827. $execute = new execute ();
  1828. $executeDetail = $execute->getOne ( array (
  1829. 'where' => 'mold="培训班结算"',
  1830. 'asArray' => true
  1831. ) );
  1832. if (empty ( $executeDetail )) {
  1833. header ( 'Content-Type:text/html;charset=utf-8' );
  1834. die ( '未设置执行人' );
  1835. }
  1836. Doo::loadClass ( 'XDeode' );
  1837. $XDeode = new XDeode ( 5 );
  1838. $cid = $XDeode->decode ( $cid );
  1839. Doo::loadModel ( 'receipt' );
  1840. $receipt = new receipt ();
  1841. Doo::loadModel ( 'receiptTraining' );
  1842. $receiptTraining = new receiptTraining ();
  1843. // 创建费用培训班
  1844. $item = array (
  1845. 'cid' => $this->staff [0] ['cid'],
  1846. 'categoryName' => $this->staff [0] ['category'],
  1847. 'trainName' => $trainName,
  1848. 'trainStartDate' => $trainStartDate,
  1849. 'trainEndDate' => $trainEndDate,
  1850. 'participants' => $participants,
  1851. 'freeParticipants'=>$freeParticipants,
  1852. 'trainAddress' => $trainAddress,
  1853. 'trainRemarks' => $trainRemarks,
  1854. 'creator' => $this->staff [0] ['sid'],
  1855. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1856. );
  1857. $irid = $receiptTraining->addReceiptTraining ( $item );
  1858. // 报销单
  1859. $receipt->status = 5;
  1860. $receipt->trainId = $irid;
  1861. $receipt->Rtype = 3;
  1862. $receipt->staff = $this->staff [0] ['sid'];
  1863. $receipt->cid = $cid;
  1864. $receipt->verify = $verify;
  1865. $receipt->date = date ( "Y-m-d" );
  1866. $receipt->executeCopy = $executeDetail ['staff'];
  1867. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1868. $receipt->remittanceName = $remittanceName;
  1869. $receipt->bankName = $bankName;
  1870. $receipt->bankNumber = $bankNumber;
  1871. $receipt->remittanceBankType = $remittanceBankType;
  1872. if ($remittanceBankType == 1)
  1873. $receipt->coupletNumber = $coupletNumber;
  1874. $rid = $receipt->insert ();
  1875. $XDeode = new XDeode ( 7 );
  1876. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1877. } else
  1878. die ( 'illegal request' );
  1879. }
  1880. /**
  1881. * 培训班编辑
  1882. */
  1883. function receiptTrainEdi() {
  1884. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1885. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1886. Doo::loadClass ( 'XDeode' );
  1887. $XDeode = new XDeode ( 7 );
  1888. $rid = $XDeode->decode ( $ridKey );
  1889. if (! is_numeric ( $rid ))
  1890. die ( 'illegal request' );
  1891. Doo::loadModel ( 'receipt' );
  1892. $receipt = new receipt ();
  1893. Doo::loadModel ( 'receiptTraining' );
  1894. $receiptTraining = new receiptTraining ();
  1895. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1896. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1897. die ('illegal request--status');
  1898. }
  1899. //如有已入账已收款的发票,自动取消办事处已收款
  1900. // Doo::loadModel ( 'RIExtend' );
  1901. // $RIExtend = new RIExtend ();
  1902. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1903. // if (!empty($RIExtendList)){
  1904. // foreach ($RIExtendList as $key=>$value){
  1905. // $RIExtend = new RIExtend ();
  1906. // $RIExtend->delete(array (
  1907. // 'where' => 'iid=' . $value['iid'],
  1908. // 'limit' => 1
  1909. // ));
  1910. // }
  1911. // }
  1912. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1913. // 汇总表合计
  1914. // 收入合计--加入开票合计
  1915. Doo::loadModel ( 'invoiceTraining' );
  1916. $invoiceTraining = new invoiceTraining ();
  1917. $invoiceTrainingDetail = array (
  1918. 'invoiceArriveAmount' => 0,
  1919. 'RIAmount' => 0,
  1920. 'invoiceTotalAmount' => 0,
  1921. 'invoiceCompanyAmount'=>0
  1922. );
  1923. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1924. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1925. }
  1926. // print_r($invoiceTrainingDetail);
  1927. $invoiceArriveAmount = $RIAmount = 0;
  1928. if (! empty ( $invoiceTrainingDetail )) {
  1929. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1930. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1931. }
  1932. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1933. //print_r($invoiceTrainingDetail);
  1934. // 支出项目
  1935. Doo::loadModel ( 'accountItem' );
  1936. $accountItem = new accountItem ();
  1937. // 项目金额合计
  1938. Doo::loadModel ( 'RItem' );
  1939. $RItem = new RItem ();
  1940. // 讲师获得
  1941. Doo::loadModel ( 'RILecturer' );
  1942. $RILecturer = new RILecturer ();
  1943. $RItemList = $RItem->getRItemByRid ( $rid );
  1944. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1945. // 支出项金额详情
  1946. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1947. // print_r($aiData);
  1948. // 利润
  1949. $profit=$invoiceArriveAmount - $aiData ['total'];
  1950. $companyProfit=$profit * 0.6;
  1951. $categoryProfit=$profit * 0.4;
  1952. $data ['profit'] = sprintf("%.2f",$profit);
  1953. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1954. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1955. //发票利润
  1956. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1957. //发票公司利润
  1958. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1959. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1960. //办事处利润
  1961. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1962. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1963. // print_r($aiData['dataList']);
  1964. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1965. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1966. // 备用金
  1967. $sum = 0;
  1968. $data ['receiptLoanDetail'] = array (
  1969. 'sum' => '0.00'
  1970. );
  1971. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1972. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  1973. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  1974. $sum=0;
  1975. foreach ($receiptLoanList as $key=>$value){
  1976. $sum+=$value['sum'];
  1977. }
  1978. $data ['receiptLoanDetail'] = array (
  1979. 'sum' => $sum
  1980. );
  1981. //$sum = $data ['receiptLoanDetail'] ['sum'];
  1982. }
  1983. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1984. $data ['payment'] = sprintf("%.2f",$payment);
  1985. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1986. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1987. $data ['aiList'] = $aiData ['dataList'];
  1988. // 占比计算
  1989. if ($invoiceArriveAmount != 0) {
  1990. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1991. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1992. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1993. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1994. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1995. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1996. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1997. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1998. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1999. } else {
  2000. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2001. }
  2002. //发票金额占比计算
  2003. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2004. //支出
  2005. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2006. //利润
  2007. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2008. //公司利润
  2009. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2010. //办事处利润
  2011. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2012. //公司收款
  2013. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2014. //备用金
  2015. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2016. //办事处收款
  2017. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2018. //办事处实际支出
  2019. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2020. //付总部款
  2021. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2022. }else{
  2023. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2024. }
  2025. //讲师人数
  2026. Doo::loadModel ( 'RILecturer' );
  2027. $RILecturer = new RILecturer ();
  2028. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2029. $data['lectureCount']=count($RILecturerList);
  2030. // 审批组
  2031. Doo::loadModel ( 'verify' );
  2032. $verify = new verify ();
  2033. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2034. // 办事处
  2035. Doo::loadModel ( 'L_category' );
  2036. $lCategory = new L_category ();
  2037. $data ['category'] = $lCategory->getCategory ();
  2038. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2039. $data ['receiptDetail'] = $receiptDetail;
  2040. $data ['veList'] = $veList;
  2041. $data ['trainEdiType'] = $trainEdiType;
  2042. $data ['ridKey'] = $ridKey;
  2043. $data ['memu'] = "receipt";
  2044. $data ['staff'] = $this->staff;
  2045. $data ['receiptMemu'] = 'saeaBorad';
  2046. $data ['verifyId'] = $this->verifyId;
  2047. $data ['executeId'] = $this->executeId;
  2048. $this->render ( "/receipt/receiptTrainEdi", $data );
  2049. }
  2050. /**
  2051. * 培训班借款编辑
  2052. */
  2053. function receiptTrainLoanEdi() {
  2054. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2055. Doo::loadClass ( 'XDeode' );
  2056. $XDeode = new XDeode ( 7 );
  2057. $rid = $XDeode->decode ( $ridKey );
  2058. if (! is_numeric ( $rid ))
  2059. die ( 'illegal request' );
  2060. Doo::loadModel ( 'receipt' );
  2061. $receipt = new receipt ();
  2062. Doo::loadModel ( 'receiptTraining' );
  2063. $receiptTraining = new receiptTraining ();
  2064. Doo::loadModel ( 'verify' );
  2065. $verify = new verify ();
  2066. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2067. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2068. die ();
  2069. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2070. // 借款详情HTML
  2071. // 获得借款信息
  2072. $receiptLoanHtml = '';
  2073. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2074. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2075. foreach ($receiptLoanList as $key=>$value){
  2076. // 获得某费用单审批信息
  2077. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  2078. Doo::loadClass ( 'receipt.func' );
  2079. $extendHtml = '<p><a class="button"
  2080. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2081. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  2082. }
  2083. }
  2084. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2085. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2086. $data ['receiptDetail'] = $receiptDetail;
  2087. $data ['trainEdiType'] = "LOAN";
  2088. $data ['ridKey'] = $ridKey;
  2089. $data ['memu'] = "receipt";
  2090. $data ['staff'] = $this->staff;
  2091. $data ['receiptMemu'] = 'saeaBorad';
  2092. $data ['verifyId'] = $this->verifyId;
  2093. $data ['executeId'] = $this->executeId;
  2094. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2095. }
  2096. /**
  2097. * 更新培训班结算基本信息
  2098. */
  2099. function receiptTrainInfoEdiDo() {
  2100. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2101. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2102. // 培训班信息
  2103. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2104. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2105. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2106. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2107. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2108. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2109. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2110. // 发票信息
  2111. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2112. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2113. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2114. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2115. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2116. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2117. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2118. //&& ! empty ( $participants )
  2119. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2120. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2121. header ( 'Content-Type:text/html;charset=utf-8' );
  2122. die ( '请填写联行号' );
  2123. }
  2124. Doo::loadClass ( 'XDeode' );
  2125. $XDeode = new XDeode ( 5 );
  2126. $cid = $XDeode->decode ( $cid );
  2127. $rtid = $XDeode->decode ( $rtid );
  2128. $rid = $XDeode->decode ( $rid );
  2129. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2130. die ( 'illegal request-IdError' );
  2131. }
  2132. Doo::loadModel ( 'receipt' );
  2133. $receipt = new receipt ();
  2134. Doo::loadModel ( 'receiptTraining' );
  2135. $receiptTraining = new receiptTraining ();
  2136. // 更新费用培训班
  2137. $item = array (
  2138. 'rtid' => $rtid,
  2139. 'trainName' => $trainName,
  2140. 'trainStartDate' => $trainStartDate,
  2141. 'trainEndDate' => $trainEndDate,
  2142. 'participants' => $participants,
  2143. 'freeParticipants'=>$freeParticipants,
  2144. 'trainAddress' => $trainAddress,
  2145. 'trainRemarks' => $trainRemarks
  2146. );
  2147. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2148. // 报销单
  2149. $receipt->rid = $rid;
  2150. $receipt->cid = $cid;
  2151. $receipt->verify = $verify;
  2152. $receipt->remittanceName = $remittanceName;
  2153. $receipt->bankName = $bankName;
  2154. $receipt->bankNumber = $bankNumber;
  2155. $receipt->remittanceBankType = $remittanceBankType;
  2156. if ($remittanceBankType == 1)
  2157. $receipt->coupletNumber = $coupletNumber;
  2158. $receipt->update ();
  2159. $XDeode = new XDeode ( 7 );
  2160. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2161. } else
  2162. die ( 'illegal request' );
  2163. }
  2164. /**
  2165. * 编辑培训班结算---更新借款
  2166. */
  2167. function receiptTrainLoanEdiDo() {
  2168. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2169. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2170. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2171. Doo::loadModel ( 'receipt' );
  2172. $receipt = new receipt ();
  2173. Doo::loadClass ( 'XDeode' );
  2174. $XDeode = new XDeode ( 5 );
  2175. $rid = $XDeode->decode ( $ridKey );
  2176. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2177. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2178. die ( 'illegal request-ridError' );
  2179. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2180. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2181. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2182. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2183. die ( 'illegal request-receiptError' );
  2184. }
  2185. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2186. die ( 'illegal request-receipLoantError' );
  2187. }
  2188. // 培训班结算挂钩借款
  2189. $receipt = new receipt ();
  2190. $trainLoanRid=$ridLoan;
  2191. if (!empty($receiptDetail['trainLoanRid'])){
  2192. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  2193. }
  2194. $item = array (
  2195. 'rid' => $rid,
  2196. 'trainLoanRid' => $trainLoanRid
  2197. );
  2198. $receipt->setReceiptByCondition ( $item );
  2199. // 更新借款状态变成已挂钩
  2200. $receipt = new receipt ();
  2201. $item = array (
  2202. 'rid' => $ridLoan,
  2203. 'status' => 10,
  2204. 'statusTrain' => 1
  2205. );
  2206. $receipt->setReceiptByCondition ( $item );
  2207. $XDeode = new XDeode ( 7 );
  2208. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2209. } else
  2210. die ( 'illegal request' );
  2211. }
  2212. /**
  2213. * 编辑培训班结算--移除借款
  2214. */
  2215. function receiptTrainLoanRemoveDo() {
  2216. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2217. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2218. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2219. Doo::loadModel ( 'receipt' );
  2220. $receipt = new receipt ();
  2221. Doo::loadClass ( 'XDeode' );
  2222. $XDeode = new XDeode ( 5 );
  2223. $rid = $XDeode->decode ( $ridKey );
  2224. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2225. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2226. die ( 'illegal request-ridError' );
  2227. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2228. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2229. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2230. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2231. die ( 'illegal request-receiptError' );
  2232. }
  2233. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2234. die ( 'illegal request-receipLoantError' );
  2235. }
  2236. // 培训班结算挂钩借款
  2237. $receipt = new receipt ();
  2238. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  2239. foreach ($trainLoanRidArray as $key=>$value){
  2240. if($value==$ridLoan){
  2241. unset($trainLoanRidArray[$key]);
  2242. }
  2243. }
  2244. $trainLoanRidString=implode(",", $trainLoanRidArray);
  2245. $item = array (
  2246. 'rid' => $rid,
  2247. 'trainLoanRid' => $trainLoanRidString
  2248. );
  2249. $receipt->setReceiptByCondition ( $item );
  2250. // 更新借款状态变成已挂钩
  2251. $receipt = new receipt ();
  2252. $item = array (
  2253. 'rid' => $ridLoan,
  2254. 'status' => 8,
  2255. 'statusTrain' => 0
  2256. );
  2257. $receipt->setReceiptByCondition ( $item );
  2258. $XDeode = new XDeode ( 7 );
  2259. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2260. } else
  2261. die ( 'illegal request' );
  2262. }
  2263. /**
  2264. * 编辑培训班结算 ---开票
  2265. */
  2266. function receiptTrainInvoiceEdi() {
  2267. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2268. Doo::loadClass ( 'XDeode' );
  2269. $XDeode = new XDeode ( 7 );
  2270. $rid = $XDeode->decode ( $ridKey );
  2271. if (! is_numeric ( $rid ))
  2272. die ( 'illegal request' );
  2273. Doo::loadModel ( 'receipt' );
  2274. $receipt = new receipt ();
  2275. Doo::loadModel ( 'receiptTraining' );
  2276. $receiptTraining = new receiptTraining ();
  2277. Doo::loadModel ( 'invoice' );
  2278. $invoice = new invoice ();
  2279. Doo::loadModel ( 'invoiceTraining' );
  2280. $invoiceTraining = new invoiceTraining ();
  2281. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2282. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2283. die ();
  2284. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2285. $invoiceList = $invoiceTrainingDetail = array ();
  2286. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2287. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2288. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2289. }
  2290. //print_r($invoiceList);
  2291. $data ['invoiceList'] = $invoiceList;
  2292. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2293. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2294. $data ['receiptDetail'] = $receiptDetail;
  2295. $data ['trainEdiType'] = "INVOICE";
  2296. $data ['ridKey'] = $ridKey;
  2297. $data ['memu'] = "receipt";
  2298. $data ['staff'] = $this->staff;
  2299. $data ['receiptMemu'] = 'saeaBorad';
  2300. $data ['verifyId'] = $this->verifyId;
  2301. $data ['executeId'] = $this->executeId;
  2302. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2303. }
  2304. /**
  2305. * 编辑培训班结算---更新开票
  2306. */
  2307. function receiptTrainInvoiceEdiDo() {
  2308. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2309. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2310. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2311. Doo::loadModel ( 'receipt' );
  2312. $receipt = new receipt ();
  2313. Doo::loadModel ( 'invoiceTraining' );
  2314. $invoiceTraining = new invoiceTraining ();
  2315. Doo::loadClass ( 'XDeode' );
  2316. $XDeode = new XDeode ( 5 );
  2317. $rid = $XDeode->decode ( $ridKey );
  2318. $itid = $XDeode->decode ( $itidKey );
  2319. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2320. die ( 'illegal request-idError' );
  2321. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2322. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2323. // 不合法的数据
  2324. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2325. die ( 'illegal request-receiptError' );
  2326. }
  2327. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2328. die ( 'illegal request-receipLoantError' );
  2329. }
  2330. // 培训班结算挂钩借款
  2331. $receipt = new receipt ();
  2332. $item = array (
  2333. 'rid' => $rid,
  2334. 'invoiceTrainId' => $itid
  2335. );
  2336. $receipt->setReceiptByCondition ( $item );
  2337. $invoiceTraining = new invoiceTraining ();
  2338. $item = array (
  2339. 'bindReceipt' => 1,
  2340. 'itid' => $itid
  2341. );
  2342. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2343. $XDeode = new XDeode ( 7 );
  2344. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2345. } else
  2346. die ( 'illegal request' );
  2347. }
  2348. /**
  2349. * 更新培训班结算 收款和取消收款
  2350. */
  2351. function receiptTrainReceivables() {
  2352. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2353. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2354. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2355. Doo::loadClass ( 'XDeode' );
  2356. $XDeode = new XDeode ( 5 );
  2357. $rid = $XDeode->decode ( $ridKey );
  2358. $iid = $XDeode->decode ( $iidKey );
  2359. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2360. die ( 'illegal request-iid' );
  2361. Doo::loadModel ( 'RIExtend' );
  2362. $RIExtend = new RIExtend ();
  2363. if ($doType == 'CONFIRM') {
  2364. $RIExtend->rid = $rid;
  2365. $RIExtend->iid = $iid;
  2366. $RIExtend->RIstatus = 1;
  2367. $RIExtend->insert ();
  2368. echo json_encode ( array (
  2369. 'status' => 1,
  2370. ) );
  2371. die ( );
  2372. } elseif ($doType == 'CANCEL') {
  2373. $RIExtend->delete ( array (
  2374. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2375. 'limit' => 1
  2376. ) );
  2377. echo json_encode ( array (
  2378. 'status' => 1,
  2379. ) );
  2380. die ( );
  2381. } else {
  2382. echo json_encode ( array (
  2383. 'status' => 2,
  2384. ) );
  2385. die ( );
  2386. }
  2387. }
  2388. /**
  2389. * 移除挂钩的培训班发票
  2390. */
  2391. function receiptTrainReceivablesDelDo() {
  2392. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2393. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2394. Doo::loadModel ( 'receipt' );
  2395. $receipt = new receipt ();
  2396. Doo::loadModel ( 'RIExtend' );
  2397. $RIExtend = new RIExtend ();
  2398. Doo::loadClass ( 'XDeode' );
  2399. $XDeode = new XDeode ( 5 );
  2400. $rid = $XDeode->decode ( $ridKey );
  2401. $itid = $XDeode->decode ( $itidKey );
  2402. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2403. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2404. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2405. die ( 'illegal request-status' );
  2406. }
  2407. $receipt = new receipt ();
  2408. $receipt->rid = $rid;
  2409. $receipt->invoiceTrainId = 0;
  2410. $receipt->update ();
  2411. Doo::loadModel ( 'invoiceTraining' );
  2412. $invoiceTraining = new invoiceTraining ();
  2413. $item = array (
  2414. 'bindReceipt' => 0,
  2415. 'itid' => $itid
  2416. );
  2417. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2418. $RIExtend->delete ( array (
  2419. 'where' => 'rid=' . $rid
  2420. ) );
  2421. $XDeode = new XDeode ( 7 );
  2422. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2423. } else
  2424. die ( 'illegal request-iid' );
  2425. }
  2426. /**
  2427. * 编辑培训班结算
  2428. */
  2429. function receiptTrainItemEdi() {
  2430. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2431. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2432. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2433. Doo::loadClass ( 'XDeode' );
  2434. $XDeode = new XDeode ( 7 );
  2435. $rid = $XDeode->decode ( $ridKey );
  2436. if (! is_numeric ( $rid ))
  2437. die ( 'illegal request' );
  2438. Doo::loadModel ( 'receipt' );
  2439. $receipt = new receipt ();
  2440. Doo::loadModel ( 'receiptTraining' );
  2441. $receiptTraining = new receiptTraining ();
  2442. Doo::loadModel ( 'RItem' );
  2443. $RItem = new RItem ();
  2444. Doo::loadModel ( 'accountItem' );
  2445. $accountItem = new accountItem ();
  2446. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2447. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2448. die ();
  2449. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2450. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2451. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2452. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2453. // if($value['name']=='税款'){
  2454. // unset($aiList[$key]);break;
  2455. // }
  2456. // }
  2457. //print_r($RItemList);
  2458. $data ['name'] = $name;
  2459. $data ['RItemList'] = $RItemList;
  2460. $data ['aiList'] = $aiList;
  2461. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2462. $data ['receiptDetail'] = $receiptDetail;
  2463. $data ['trainEdiType'] = "ITEM";
  2464. $data ['ridKey'] = $ridKey;
  2465. $data ['memu'] = "receipt";
  2466. $data ['staff'] = $this->staff;
  2467. $data ['receiptMemu'] = 'saeaBorad';
  2468. $data ['verifyId'] = $this->verifyId;
  2469. $data ['executeId'] = $this->executeId;
  2470. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2471. }
  2472. /**
  2473. * 添加支出项 需要修改 费用金额合计
  2474. */
  2475. function receiptTrainItemAddDo() {
  2476. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2477. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2478. // 支出项信息
  2479. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2480. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2481. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2482. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2483. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2484. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2485. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2486. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2487. Doo::loadClass ( 'XDeode' );
  2488. $XDeode = new XDeode ( 5 );
  2489. Doo::loadModel ( 'RItem' );
  2490. $RItem = new RItem ();
  2491. $rid = $XDeode->decode ( $ridKey );
  2492. $rtid= $XDeode->decode ( $rtidKey );
  2493. if (! is_numeric ( $rid )){
  2494. die ( 'illegal request' );
  2495. }
  2496. Doo::loadModel ( 'receiptDetail' );
  2497. $receiptDetail = new receiptDetail ();
  2498. Doo::loadModel ( 'receipt' );
  2499. $receipt = new receipt ();
  2500. Doo::loadModel ( 'receiptTraining' );
  2501. $receiptTraining = new receiptTraining ();
  2502. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2503. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2504. $order = array (
  2505. "\r\n",
  2506. "\n",
  2507. "\r"
  2508. );
  2509. $replace = '<br/>';
  2510. $describe = str_replace ( $order, $replace, $describe );
  2511. $itemData = array (
  2512. 'rid' => $rid,
  2513. 'item' => $item,
  2514. 'price' => $price,
  2515. 'date' => $date,
  2516. 'inputer' => $inputer,
  2517. 'describe' => $describe,
  2518. 'creater' => $this->staff['0']['username'],
  2519. 'createrId' => $this->staff['0']['sid'],
  2520. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2521. 'identifying'=>$identifyingTotal
  2522. );
  2523. if($payType=='company'){
  2524. $itemData += array (
  2525. 'payType' => 1
  2526. );
  2527. }
  2528. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2529. //更新支出项标识总数
  2530. $itemData = array (
  2531. 'rtid'=>$rtid,
  2532. 'identifyingTotal'=>$identifyingTotal
  2533. );
  2534. $receiptTraining->setReceiptTrainByCondition($itemData);
  2535. $XDeode = new XDeode ( 7 );
  2536. if($payType=='company'){
  2537. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2538. }else{
  2539. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2540. }
  2541. } else
  2542. die ( 'illegal request-dataError' );
  2543. }
  2544. /**
  2545. * 培训班结算-讲师
  2546. */
  2547. function receiptTrainLecturerEdi() {
  2548. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2549. Doo::loadClass ( 'XDeode' );
  2550. $XDeode = new XDeode ( 7 );
  2551. $rid = $XDeode->decode ( $ridKey );
  2552. if (! is_numeric ( $rid ))
  2553. die ( 'illegal request' );
  2554. Doo::loadModel ( 'receipt' );
  2555. $receipt = new receipt ();
  2556. Doo::loadModel ( 'receiptTraining' );
  2557. $receiptTraining = new receiptTraining ();
  2558. Doo::loadModel ( 'RILecturer' );
  2559. $RILecturer = new RILecturer ();
  2560. Doo::loadModel ( 'lecturer' );
  2561. $lecturer = new lecturer ();
  2562. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2563. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2564. die ();
  2565. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2566. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2567. $lecturerList = $lecturer->getLecturerAll ();
  2568. $INSIDEhtml = $OUTSIDEhtml = '';
  2569. foreach ( $lecturerList as $key => $value ) {
  2570. if ($value ['ltype'] == 'INSIDE') {
  2571. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2572. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2573. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2574. }
  2575. }
  2576. $data ['INSIDEhtml'] = $INSIDEhtml;
  2577. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2578. // print_r($RItemList);
  2579. $data ['RILecturerList'] = $RILecturerList;
  2580. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2581. $data ['receiptDetail'] = $receiptDetail;
  2582. $data ['trainEdiType'] = "LECTURER";
  2583. $data ['ridKey'] = $ridKey;
  2584. $data ['memu'] = "receipt";
  2585. $data ['staff'] = $this->staff;
  2586. $data ['receiptMemu'] = 'saeaBorad';
  2587. $data ['verifyId'] = $this->verifyId;
  2588. $data ['executeId'] = $this->executeId;
  2589. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2590. }
  2591. /**
  2592. * 添加讲师
  2593. */
  2594. function receiptTrainLecturerAddDo() {
  2595. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2596. // 支出项信息
  2597. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2598. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2599. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2600. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2601. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2602. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2603. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2604. Doo::loadClass ( 'XDeode' );
  2605. $XDeode = new XDeode ( 5 );
  2606. Doo::loadModel ( 'RILecturer' );
  2607. $RILecturer = new RILecturer ();
  2608. $rid = $XDeode->decode ( $ridKey );
  2609. if (! is_numeric ( $rid ))
  2610. die ( 'illegal request' );
  2611. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2612. die ( 'illegal request-taxationError' );
  2613. $RILecturer->rid = $rid;
  2614. $RILecturer->ltype = $ltype;
  2615. if ($ltype == 'OUTSIDE') {
  2616. if ($taxation == 'TAXATION') {
  2617. $RILecturer->taxation = 1;
  2618. } elseif ($taxation == 'NOTAXATION') {
  2619. $RILecturer->taxation = 0;
  2620. }
  2621. }
  2622. $RILecturer->lecturerName = $lecturerName;
  2623. $RILecturer->schoolDay = $schoolDay;
  2624. $RILecturer->price = $price;
  2625. $RILecturer->fees=$fees;
  2626. $RILecturer->insert ();
  2627. // 添加公司汇总
  2628. // 报销详情
  2629. Doo::loadModel ( 'receiptDetail' );
  2630. $receiptDetail = new receiptDetail ();
  2631. Doo::loadModel ( 'receipt' );
  2632. $receipt = new receipt ();
  2633. // 金额总计
  2634. $price = $price * $schoolDay;
  2635. $rInfo = $receipt->getReceiptByRid ( $rid );
  2636. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2637. if (empty ( $rdInfo )) {
  2638. $receiptDetail = new receiptDetail ();
  2639. $receiptDetail->staff = $rInfo ['staff'];
  2640. $receiptDetail->item = '讲课费';
  2641. $receiptDetail->itemCategory = '培训班费用';
  2642. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2643. $receiptDetail->date = date ( "Y-m-d" );
  2644. $receiptDetail->cid = $rInfo ['cid'];
  2645. $receiptDetail->rid = $rid;
  2646. $receiptDetail->status = 4;
  2647. $receiptDetail->insert ();
  2648. } else {
  2649. $receiptDetail = new receiptDetail ();
  2650. $rdInfo ['price'] += $fees;
  2651. $receiptDetail->price = $rdInfo ['price'];
  2652. $receiptDetail->update ( array (
  2653. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2654. ) );
  2655. }
  2656. $receipt = new receipt ();
  2657. $receipt->sum=$rInfo['sum']+$fees;
  2658. $receipt->update ( array (
  2659. 'where' => 'rid=' . $rid
  2660. ) );
  2661. $XDeode = new XDeode ( 7 );
  2662. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2663. } else
  2664. die ( 'illegal request' );
  2665. }
  2666. /**
  2667. * 移除讲师
  2668. */
  2669. function receiptTrainLecturerDelDo() {
  2670. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2671. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2672. Doo::loadModel ( 'receipt' );
  2673. $receipt = new receipt ();
  2674. Doo::loadModel ( 'RILecturer' );
  2675. $RILecturer = new RILecturer ();
  2676. Doo::loadClass ( 'XDeode' );
  2677. $XDeode = new XDeode ( 5 );
  2678. $rid = $XDeode->decode ( $ridKey );
  2679. $rlid = $XDeode->decode ( $rlidKey );
  2680. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2681. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2682. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2683. die ( 'illegal request-status' );
  2684. }
  2685. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2686. if (empty($detail)){
  2687. die ( 'illegal request-data' );
  2688. }
  2689. $RILecturer->delete ( array (
  2690. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2691. ) );
  2692. //更新费用合计金额
  2693. $rInfo = $receipt->getReceiptByRid ( $rid );
  2694. $receipt = new receipt ();
  2695. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2696. $receipt->update ( array (
  2697. 'where' => 'rid=' . $rid
  2698. ) );
  2699. Doo::loadModel ( 'receiptDetail' );
  2700. $receiptDetail = new receiptDetail ();
  2701. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2702. $receiptDetail = new receiptDetail ();
  2703. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2704. $receiptDetail->price = $rdInfo ['price'];
  2705. $receiptDetail->update ( array (
  2706. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2707. ) );
  2708. $XDeode = new XDeode ( 7 );
  2709. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2710. } else
  2711. die ( 'illegal request-iid' );
  2712. }
  2713. /**
  2714. * 培训班提交审批
  2715. */
  2716. function receiptTrainDo() {
  2717. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2718. Doo::loadClass ( 'XDeode' );
  2719. $XDeode = new XDeode ( 7 );
  2720. $rid = $XDeode->decode ( $ridKey );
  2721. Doo::loadModel ( 'receipt' );
  2722. $receipt = new receipt ();
  2723. Doo::loadModel ( 'receiptDetail' );
  2724. $receiptDetail = new receiptDetail ();
  2725. Doo::loadModel ( 'statistics' );
  2726. $statistics = new statistics ();
  2727. Doo::loadModel ( "verify" );
  2728. $verify = new verify ();
  2729. // 审批状态的判定
  2730. $receiptDetailList = $receipt->getOne ( array (
  2731. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2732. 'asArray' => true
  2733. ) );
  2734. if (empty ( $receiptDetailList ))
  2735. return "/saeaBorad";
  2736. $verifyDetail = $verify->getOne ( array (
  2737. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2738. 'asArray' => true
  2739. ) );
  2740. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2741. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2742. $nowStaff = "";
  2743. $nowStaffList = array ();
  2744. if ($verifyDetail [0] [1] == 'ROLE') {
  2745. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2746. foreach ( $vStaffString as $key => $value ) {
  2747. $staffK = explode ( "_", $value );
  2748. array_push ( $nowStaffList, $staffK [0] );
  2749. }
  2750. $nowStaff = implode ( ',', $nowStaffList );
  2751. } else {
  2752. $nowStaff = $verifyDetail [0] [0];
  2753. }
  2754. $receipt->nowStaff = $nowStaff;
  2755. }
  2756. // echo $nowStaff;
  2757. // print_r($verifyDetail);die;
  2758. $receipt->rid = $receiptDetailList ['rid'];
  2759. $receipt->date = date ( "Y-m-d" );
  2760. $receipt->status = 2;
  2761. $receipt->update ();
  2762. $receiptDetail->status = 2;
  2763. $receiptDetail->update ( array (
  2764. 'where' => 'rid=' . $receiptDetailList ['rid']
  2765. ) );
  2766. Doo::loadModel ( "receiptLog" );
  2767. $receiptLog = new receiptLog ();
  2768. Doo::loadModel ( "verify" );
  2769. $verify = new verify ();
  2770. $vr = $verify->getOne ( array (
  2771. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2772. 'asArray' => true
  2773. ) );
  2774. $jd = json_decode ( $vr ['staff'] );
  2775. $roleId = 0;
  2776. foreach ( $jd as $key => $value ) {
  2777. if ($value [1] == 'ROLE') {
  2778. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2779. if ($pos !== false) {
  2780. $roleId = $value [0];
  2781. }
  2782. }
  2783. }
  2784. // 审批日志
  2785. // echo $roleId;die;
  2786. if (! empty ( $roleId )) {
  2787. Doo::loadModel ( "role" );
  2788. $role = new role ();
  2789. $roleInfo = $role->getOne ( array (
  2790. 'where' => 'rid=' . $roleId,
  2791. 'asArray' => true
  2792. ) );
  2793. // $receiptLog->rolename = $roleInfo ['name'];
  2794. }
  2795. $receiptLog->username = $this->staff [0] ['username'];
  2796. $receiptLog->uid = $this->staff [0] ['sid'];
  2797. $receiptLog->date = date ( "Y-m-d" );
  2798. $receiptLog->opinion = '提交审批';
  2799. $receiptLog->img = $this->staff [0] ['avatar'];
  2800. $receiptLog->status = 2;
  2801. $receiptLog->rid = $rid;
  2802. $receiptLog->insert ();
  2803. // 写入列表项
  2804. Doo::loadModel ( 'accountItem' );
  2805. $accountItem = new accountItem ();
  2806. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2807. // 项目金额合计
  2808. Doo::loadModel ( 'RItem' );
  2809. $RItem = new RItem ();
  2810. // 讲师获得
  2811. Doo::loadModel ( 'RILecturer' );
  2812. $RILecturer = new RILecturer ();
  2813. $RItemList = $RItem->getRItemByRid ( $rid );
  2814. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2815. // 支出项金额详情
  2816. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2817. // print_r($aItem);
  2818. // print_r($aiData);
  2819. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2820. $ag = $tr = $ta = $ot = 0;
  2821. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2822. foreach ( $aItem as $key => $value ) {
  2823. if ($value ['category'] == $this->TRAIN) {
  2824. foreach ( $aiData ['dataList'] as $k => $v ) {
  2825. if ($value ['name'] == $v ['name']) {
  2826. array_push ( $accountJson [$this->TRAIN], array (
  2827. 'aid' => $value ['aid'],
  2828. 'name' => $value ['name'],
  2829. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2830. ) );
  2831. $sum += $v ['price'];
  2832. $trainSum += $v ['price'];
  2833. unset ( $aiData ['dataList'] [$k] );
  2834. break;
  2835. }
  2836. }
  2837. }
  2838. }
  2839. $accountJson ['cSum'] = array (
  2840. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2841. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2842. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2843. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2844. );
  2845. // 报销单
  2846. $receipt = new receipt ();
  2847. $receipt->accountItem = json_encode ( $accountJson );
  2848. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2849. $receipt->update ( array (
  2850. 'where' => 'rid=' . $rid
  2851. ) );
  2852. // print_r($accountJson);
  2853. // statistics item 统计写入
  2854. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2855. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2856. $accountItem = $accountJson;
  2857. $stat = $statistics->getOne ( array (
  2858. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2859. 'asArray' => true
  2860. ) );
  2861. if (empty ( $stat )) {
  2862. $statistics->date = date ( "Y-m-d" );
  2863. $statistics->cid = $this->staff [0] ['cid'];
  2864. $statistics->staff = $this->staff [0] ['sid'];
  2865. $statistics->agPrice = 0;
  2866. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2867. $statistics->insert ();
  2868. } else {
  2869. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2870. $statistics->update ( array (
  2871. 'where' => 'sid=' . $stat ['sid']
  2872. ) );
  2873. }
  2874. return "/saeaBorad";
  2875. }
  2876. function confirmation() {
  2877. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2878. Doo::loadModel ( 'receipt' );
  2879. Doo::loadModel ( 'receiptDetail' );
  2880. $receipt = new receipt ();
  2881. $receiptDetail = new receiptDetail ();
  2882. Doo::loadModel ( 'statistics' );
  2883. Doo::loadModel ( 'itemStatistics' );
  2884. $statistics = new statistics ();
  2885. $itemStatistics = new itemStatistics ();
  2886. Doo::loadModel ( "verify" );
  2887. $verify = new verify ();
  2888. $receiptDetailList = $receipt->getOne ( array (
  2889. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2890. 'asArray' => true
  2891. ) );
  2892. if (empty ( $receiptDetailList ))
  2893. return "/saeaBorad";
  2894. $verifyDetail = $verify->getOne ( array (
  2895. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2896. 'asArray' => true
  2897. ) );
  2898. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2899. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2900. $nowStaff = "";
  2901. $nowStaffList = array ();
  2902. if ($verifyDetail [0] [1] == 'ROLE') {
  2903. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2904. foreach ( $vStaffString as $key => $value ) {
  2905. $staffK = explode ( "_", $value );
  2906. array_push ( $nowStaffList, $staffK [0] );
  2907. }
  2908. $nowStaff = implode ( ',', $nowStaffList );
  2909. } else {
  2910. $nowStaff = $verifyDetail [0] [0];
  2911. }
  2912. $receipt->nowStaff = $nowStaff;
  2913. }
  2914. // echo $nowStaff;
  2915. // print_r($verifyDetail);die;
  2916. $receipt->rid = $receiptDetailList ['rid'];
  2917. $receipt->status = 2;
  2918. $receipt->update ();
  2919. // 操作日志
  2920. Doo::loadModel ( "receiptLog" );
  2921. $receiptLog = new receiptLog ();
  2922. $verify = new verify ();
  2923. $receiptInfo = $receipt->getOne ( array (
  2924. 'where' => 'rid=' . $rid,
  2925. 'asArray' => true
  2926. ) );
  2927. $vr = $verify->getOne ( array (
  2928. 'where' => 'vid=' . $receiptInfo ['verify'],
  2929. 'asArray' => true
  2930. ) );
  2931. $jd = json_decode ( $vr ['staff'] );
  2932. $roleId = 0;
  2933. foreach ( $jd as $key => $value ) {
  2934. if ($value [1] == 'ROLE') {
  2935. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2936. if ($pos !== false) {
  2937. $roleId = $value [0];
  2938. }
  2939. }
  2940. }
  2941. // 审批日志
  2942. // echo $roleId;die;
  2943. if (! empty ( $roleId )) {
  2944. Doo::loadModel ( "role" );
  2945. $role = new role ();
  2946. $roleInfo = $role->getOne ( array (
  2947. 'where' => 'rid=' . $roleId,
  2948. 'asArray' => true
  2949. ) );
  2950. // $receiptLog->rolename = $roleInfo ['name'];
  2951. }
  2952. $receiptLog->username = $this->staff [0] ['username'];
  2953. $receiptLog->uid = $this->staff [0] ['sid'];
  2954. $receiptLog->date = date ( "Y-m-d" );
  2955. $receiptLog->opinion = '提交审批';
  2956. $receiptLog->img = $this->staff [0] ['avatar'];
  2957. $receiptLog->status = 2;
  2958. $receiptLog->rid = $rid;
  2959. $receiptLog->insert ();
  2960. return "/expenses";
  2961. }
  2962. function expenses() {
  2963. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2964. if (empty ( $item ))
  2965. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2966. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2967. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2968. Doo::loadClass ( 'XDeode' );
  2969. $XDeode = new XDeode ( 7 );
  2970. Doo::loadModel ( 'receipt' );
  2971. $receipt = new receipt ();
  2972. Doo::loadModel ( 'L_category' );
  2973. $Lcategory = new L_category ();
  2974. Doo::loadModel ( 'verify' );
  2975. Doo::loadModel ( 'statistics' );
  2976. $statistics = new statistics ();
  2977. $verify = new verify ();
  2978. Doo::loadModel ( 'staff' );
  2979. $staff = new staff ();
  2980. $condition = "";
  2981. if ($item == "expenses")
  2982. $condition = " and Rtype=1 ";
  2983. elseif ($item == "receipts")
  2984. $condition = " and Rtype=0 ";
  2985. elseif ($item == "remits")
  2986. $condition = " and Rtype=2 ";
  2987. elseif ($item == "train")
  2988. $condition = " and Rtype=3 ";
  2989. $dateCondition = " and Year(date) =" . $year;
  2990. if (! empty ( $moth )) {
  2991. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2992. $stList = $statistics->getOne ( array (
  2993. 'select' => 'rePrice ,agPrice',
  2994. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2995. 'asArray' => true
  2996. ) );
  2997. } else
  2998. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2999. if (empty ( $stList ))
  3000. $stList = array (
  3001. 'rePrice' => 0,
  3002. 'agPrice' => 0
  3003. );
  3004. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3005. if (! isset ( $noPassSum ['sum'] ))
  3006. $noPassSum ['sum'] = 0;
  3007. $data ['stList'] = array (
  3008. 'rePrice' => $stList ['rePrice'],
  3009. 'agPrice' => $stList ['agPrice'],
  3010. 'skPrice' => ($noPassSum ['sum'])
  3011. );
  3012. $receiptList = $receipt->find ( array (
  3013. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3014. 'desc' => 'rid',
  3015. 'asArray' => true
  3016. ) );
  3017. $Locate = 0;
  3018. $roleId = 0;
  3019. $button = 0;
  3020. foreach ( $receiptList as $key => $value ) {
  3021. $receiptList[$key]['balance']='';
  3022. if($value['Rtype']==1){
  3023. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3024. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3025. }elseif($value['Rtype']==3){
  3026. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3027. $receiptList[$key]['payment']=$payment;
  3028. $receiptList[$key]['paymentABS']=abs($payment);
  3029. }
  3030. $receiptList [$key] ['Locate'] = $Locate;
  3031. $Locate ++;
  3032. $receiptList [$key] ['reviseDetail'] = array ();
  3033. if (! empty ( $value ['reviseDetail'] ))
  3034. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3035. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3036. $categoryDetil = $Lcategory->getOne ( array (
  3037. 'where' => 'cid=' . $value ['cid'],
  3038. 'asArray' => true
  3039. ) );
  3040. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3041. // 检测编辑状态
  3042. $verifyList = $verify->getOne ( array (
  3043. 'where' => 'vid=' . $value ['verify'],
  3044. 'asArray' => true
  3045. ) );
  3046. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3047. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3048. Doo::loadModel ( 'role' );
  3049. $role = new role ();
  3050. $flag = true;
  3051. $roleKey = 0;
  3052. $endStaffArray = array ();
  3053. $roleArrayCopy = array ();
  3054. foreach ( $verifyList as $k => $v ) {
  3055. // init verifyStaff
  3056. if ($v [1] == 'ROLE') {
  3057. if (! empty ( $verifyStaff )) {
  3058. $endStaffArray = end ( $verifyStaff );
  3059. // if ($v[0]==$endStaffArray['nextStaff']){
  3060. // $roleId=$v[0];
  3061. // }
  3062. }
  3063. $roleVerify = json_decode ( $v [3], true );
  3064. $roleKey = $k;
  3065. $roleArray = array ();
  3066. $rolename = $role->getOne ( array (
  3067. 'where' => 'rid=' . $v [0],
  3068. 'asArray' => true
  3069. ) );
  3070. foreach ( $roleVerify as $o => $p ) {
  3071. $staffID = explode ( '_', $p );
  3072. $staffInfo = $staff->getOne ( array (
  3073. 'where' => 'sid=' . $staffID [0],
  3074. 'asArray' => true
  3075. ) );
  3076. // print_r($staffID);
  3077. $exp = array (
  3078. 0 => $staffInfo ['sid'],
  3079. 1 => $staffID [1],
  3080. 2 => $staffInfo ['avatar'],
  3081. 'date' => '',
  3082. 'date' => '',
  3083. 'opinion' => '',
  3084. 'status' => '',
  3085. 'rolename' => $rolename ['name']
  3086. );
  3087. array_push ( $roleArray, $exp );
  3088. }
  3089. $roleArrayCopy [$v [0]] = $roleArray;
  3090. // $verifyList[$k]['roleArray']=$roleArray;
  3091. }
  3092. $verifyList [$k] ['date'] = "";
  3093. $verifyList [$k] ['opinion'] = "";
  3094. $verifyList [$k] ['status'] = "";
  3095. if (empty ( $verifyStaff )) {
  3096. $verifyList [$k] ['date'] = "";
  3097. $verifyList [$k] ['opinion'] = "";
  3098. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3099. $verifyList [$k] ['status'] = 4;
  3100. $flag = false;
  3101. }
  3102. } else {
  3103. foreach ( $verifyStaff as $m => $u ) {
  3104. if ($v [0] == $m) {
  3105. $verifyList [$k] ['date'] = $u ['date'];
  3106. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3107. $verifyList [$k] ['status'] = $u ['status'];
  3108. $flag = false;
  3109. break;
  3110. }
  3111. }
  3112. $endStaffArray = end ( $verifyStaff );
  3113. if (isset ( $endStaffArray ['ROLE'] )) {
  3114. } else {
  3115. // $endKey=key($verifyStaff);
  3116. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3117. // $button=4;
  3118. // $verifyList[$k]['status']=4;
  3119. // }
  3120. }
  3121. }
  3122. }
  3123. $rolename ['name'] = '';
  3124. if (! empty ( $roleId )) {
  3125. Doo::loadModel ( 'role' );
  3126. $role = new role ();
  3127. $rolename = $role->getOne ( array (
  3128. 'where' => 'rid=' . $roleId,
  3129. 'asArray' => true
  3130. ) );
  3131. }
  3132. if (! empty ( $verifyStaff ))
  3133. $endStaffArray = end ( $verifyStaff );
  3134. $KOP = false;
  3135. foreach ( $roleArrayCopy as $P => $A ) {
  3136. foreach ( $A as $MKI => $AVL ) {
  3137. if (! empty ( $verifyStaff )) {
  3138. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3139. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3140. $button = 4;
  3141. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3142. }
  3143. foreach ( $verifyStaff as $m => $u ) {
  3144. $AVLFK = $AVL [0] . '_R';
  3145. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3146. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3147. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3148. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3149. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3150. break;
  3151. }
  3152. }
  3153. } else {
  3154. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3155. $button = 4;
  3156. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3157. }
  3158. }
  3159. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3160. $KOP = true;
  3161. }
  3162. }
  3163. foreach ( $roleArrayCopy as $k => $v ) {
  3164. foreach ( $verifyList as $m => $n ) {
  3165. if ($n [0] == $k) {
  3166. array_splice ( $verifyList, $m, 1, $v );
  3167. }
  3168. }
  3169. }
  3170. $receiptList [$key] ['verifyList'] = $verifyList;
  3171. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3172. 'where' => 'sid=' . $value ['staff'],
  3173. 'asArray' => true
  3174. ) );
  3175. $receiptList [$key] ['button'] = $button;
  3176. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3177. }
  3178. // print_r($receiptList);die;
  3179. $mothHtml = "";
  3180. for($i = 1; $i <= 12; $i ++) {
  3181. if ($moth == $i)
  3182. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3183. else
  3184. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3185. }
  3186. $dateHtml = "";
  3187. $now = date ( "Y" );
  3188. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3189. if ($YEARD <= $now) {
  3190. $dateHtml .= '<option ';
  3191. if ($year == $YEARD) {
  3192. $dateHtml .= 'selected ';
  3193. }
  3194. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3195. }
  3196. }
  3197. $data ['dateHtml'] = $dateHtml;
  3198. $data ['mothHtml'] = $mothHtml;
  3199. $data ['receiptList'] = $receiptList;
  3200. $data ['memu'] = "receipt";
  3201. $data ['staff'] = $this->staff;
  3202. $data ['receiptMemu'] = 'expenses';
  3203. $data ['verifyId'] = $this->verifyId;
  3204. $data ['executeId'] = $this->executeId;
  3205. $data ['item'] = $item;
  3206. $data ['year'] = $year;
  3207. $this->render ( "/admin/expenses", $data );
  3208. }
  3209. function expensesCollect() {
  3210. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3211. Doo::loadModel ( 'receipt' );
  3212. $receipt = new receipt ();
  3213. Doo::loadModel ( 'L_category' );
  3214. $Lcategory = new L_category ();
  3215. Doo::loadModel ( 'verify' );
  3216. Doo::loadModel ( 'statistics' );
  3217. $statistics = new statistics ();
  3218. $verify = new verify ();
  3219. Doo::loadModel ( 'staff' );
  3220. $staff = new staff ();
  3221. Doo::loadModel ( 'loanReceipt' );
  3222. $loanReceipt = new loanReceipt ();
  3223. $receiptList = $receipt->find ( array (//去掉
  3224. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3225. 'desc' => 'rid',
  3226. 'asArray' => true
  3227. ) );
  3228. $loanList = $loanReceipt->find ( array (
  3229. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3230. 'desc' => 'rid',
  3231. 'asArray' => true
  3232. ) );
  3233. /*
  3234. * $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;
  3235. */
  3236. $data ['explanation'] = '';
  3237. if (! empty ( $loanList ))
  3238. $data ['explanation'] = $loanList [0] ['explanation'];
  3239. $Locate = 0;
  3240. $roleId = 0;
  3241. $button = 0;
  3242. foreach ( $receiptList as $key => $value ) {
  3243. $receiptList [$key] ['Locate'] = $Locate;
  3244. $Locate ++;
  3245. $receiptList [$key] ['reviseDetail'] = array ();
  3246. if (! empty ( $value ['reviseDetail'] ))
  3247. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3248. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3249. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3250. $categoryDetil = $Lcategory->getOne ( array (
  3251. 'where' => 'cid=' . $value ['cid'],
  3252. 'asArray' => true
  3253. ) );
  3254. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3255. // 检测编辑状态
  3256. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3257. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3258. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3259. else
  3260. $verifyList ['staff'] = $value ['verifyBreakup'];
  3261. } else
  3262. $verifyList = $verify->getOne ( array (
  3263. 'where' => 'vid=' . $value ['verify'],
  3264. 'asArray' => true
  3265. ) );
  3266. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3267. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3268. Doo::loadModel ( 'role' );
  3269. $role = new role ();
  3270. $flag = true;
  3271. $roleKey = 0;
  3272. $endStaffArray = array ();
  3273. $roleArrayCopy = array ();
  3274. foreach ( $verifyList as $k => $v ) {
  3275. // init verifyStaff
  3276. if ($v [1] == 'ROLE') {
  3277. if (! empty ( $verifyStaff )) {
  3278. $endStaffArray = end ( $verifyStaff );
  3279. // if ($v[0]==$endStaffArray['nextStaff']){
  3280. // $roleId=$v[0];
  3281. // }
  3282. }
  3283. $roleVerify = json_decode ( $v [3], true );
  3284. $roleKey = $k;
  3285. $roleArray = array ();
  3286. $rolename = $role->getOne ( array (
  3287. 'where' => 'rid=' . $v [0],
  3288. 'asArray' => true
  3289. ) );
  3290. foreach ( $roleVerify as $o => $p ) {
  3291. $staffID = explode ( '_', $p );
  3292. $staffInfo = $staff->getOne ( array (
  3293. 'where' => 'sid=' . $staffID [0],
  3294. 'asArray' => true
  3295. ) );
  3296. // print_r($staffID);
  3297. $exp = array (
  3298. 0 => $staffInfo ['sid'],
  3299. 1 => $staffID [1],
  3300. 2 => $staffInfo ['avatar'],
  3301. 'date' => '',
  3302. 'date' => '',
  3303. 'opinion' => '',
  3304. 'status' => '',
  3305. 'rolename' => $rolename ['name']
  3306. );
  3307. array_push ( $roleArray, $exp );
  3308. }
  3309. $roleArrayCopy [$v [0]] = $roleArray;
  3310. // $verifyList[$k]['roleArray']=$roleArray;
  3311. }
  3312. $verifyList [$k] ['date'] = "";
  3313. $verifyList [$k] ['opinion'] = "";
  3314. $verifyList [$k] ['status'] = "";
  3315. if (empty ( $verifyStaff )) {
  3316. $verifyList [$k] ['date'] = "";
  3317. $verifyList [$k] ['opinion'] = "";
  3318. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3319. $verifyList [$k] ['status'] = 4;
  3320. $flag = false;
  3321. }
  3322. } else {
  3323. foreach ( $verifyStaff as $m => $u ) {
  3324. if ($v [0] == $m) {
  3325. $verifyList [$k] ['date'] = $u ['date'];
  3326. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3327. $verifyList [$k] ['status'] = $u ['status'];
  3328. $flag = false;
  3329. break;
  3330. }
  3331. }
  3332. $endStaffArray = end ( $verifyStaff );
  3333. if (isset ( $endStaffArray ['ROLE'] )) {
  3334. } else {
  3335. // $endKey=key($verifyStaff);
  3336. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3337. // $button=4;
  3338. // $verifyList[$k]['status']=4;
  3339. // }
  3340. }
  3341. }
  3342. }
  3343. $rolename ['name'] = '';
  3344. if (! empty ( $roleId )) {
  3345. Doo::loadModel ( 'role' );
  3346. $role = new role ();
  3347. $rolename = $role->getOne ( array (
  3348. 'where' => 'rid=' . $roleId,
  3349. 'asArray' => true
  3350. ) );
  3351. }
  3352. if (! empty ( $verifyStaff ))
  3353. $endStaffArray = end ( $verifyStaff );
  3354. $KOP = false;
  3355. foreach ( $roleArrayCopy as $P => $A ) {
  3356. foreach ( $A as $MKI => $AVL ) {
  3357. if (! empty ( $verifyStaff )) {
  3358. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3359. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3360. $button = 4;
  3361. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3362. }
  3363. foreach ( $verifyStaff as $m => $u ) {
  3364. $AVLFK = $AVL [0] . '_R';
  3365. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3366. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3367. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3368. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3369. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3370. break;
  3371. }
  3372. }
  3373. } else {
  3374. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3375. $button = 4;
  3376. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3377. }
  3378. }
  3379. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3380. $KOP = true;
  3381. }
  3382. }
  3383. foreach ( $roleArrayCopy as $k => $v ) {
  3384. foreach ( $verifyList as $m => $n ) {
  3385. if ($n [0] == $k) {
  3386. array_splice ( $verifyList, $m, 1, $v );
  3387. }
  3388. }
  3389. }
  3390. // 费用执行人相关数据
  3391. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3392. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3393. foreach ( $executeCopy as $k => $v ) {
  3394. $executeCopy [$k] ['date'] = '';
  3395. $executeCopy [$k] ['opinion'] = '';
  3396. $executeCopy [$k] ['status'] = '';
  3397. if (! empty ( $executeStaff ))
  3398. foreach ( $executeStaff as $m => $u ) {
  3399. if ($v [0] == $m) {
  3400. $executeCopy [$k] ['date'] = $u ['date'];
  3401. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3402. $executeCopy [$k] ['status'] = $u ['status'];
  3403. break;
  3404. }
  3405. }
  3406. }
  3407. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3408. $receiptList [$key] ['verifyList'] = $verifyList;
  3409. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3410. 'where' => 'sid=' . $value ['staff'],
  3411. 'asArray' => true
  3412. ) );
  3413. $receiptList [$key] ['button'] = $button;
  3414. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3415. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3416. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3417. $receiptList [$key] ['relust'] = $relust;
  3418. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3419. }
  3420. Doo::loadModel ( 'enclosur' );
  3421. $enclosur = new enclosur ();
  3422. $enclosurList = $enclosur->find ( array (
  3423. 'where' => 'rid=' . $rid,
  3424. 'asArray' => true
  3425. ) );
  3426. $enclosurHtml = '';
  3427. foreach ( $enclosurList as $value ) {
  3428. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3429. }
  3430. $data ['enclosurHtml'] = $enclosurHtml;
  3431. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3432. $data ['receiptList'] = $receiptList;
  3433. $data ['memu'] = "receipt";
  3434. $data ['staff'] = $this->staff;
  3435. $data ['receiptMemu'] = 'expenses';
  3436. $data ['verifyId'] = $this->verifyId;
  3437. $data ['executeId'] = $this->executeId;
  3438. $this->render ( "/admin/expensesCollect", $data );
  3439. }
  3440. function approvalExpenses() {
  3441. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3442. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3443. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3444. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3445. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3446. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3447. // echo $rdate;
  3448. if (empty ( $status ))
  3449. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3450. $page_size = 8;
  3451. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3452. $vidList = array ();
  3453. $button = 0;
  3454. Doo::loadModel ( 'verify' );
  3455. $verify = new verify ();
  3456. Doo::loadModel ( 'receipt' );
  3457. $receipt = new receipt ();
  3458. Doo::loadModel ( 'staff' );
  3459. $staff = new staff ();
  3460. Doo::loadModel ( 'L_category' );
  3461. $Lcategory = new L_category ();
  3462. // user verify ID
  3463. $verifyDetail = $verify->find ( array (
  3464. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3465. 'asArray' => true
  3466. ) );
  3467. foreach ( $verifyDetail as $key => $value ) {
  3468. array_push ( $vidList, $value ['vid'] );
  3469. }
  3470. $vid = implode ( ",", $vidList );
  3471. if (empty ( $verifyDetail ))
  3472. $vid = 0;
  3473. // if ($status==0)
  3474. // $dateCondition="";
  3475. // else
  3476. $dateCondition = " ";
  3477. // if (! empty ( $month ))
  3478. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3479. if ($status == 'done' || $status == 'termination') {
  3480. if (! empty ( $year )) {
  3481. $dateCondition = " and Year(pastDate) =" . $year;
  3482. if (! empty ( $month ))
  3483. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3484. }
  3485. } elseif ($status == 'finish') {
  3486. if (! empty ( $year )) {
  3487. $dateCondition = " and Year(pastDate) =" . $year;
  3488. if (! empty ( $month ))
  3489. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3490. }
  3491. }
  3492. // date ( 'Y-m' )
  3493. // if (! empty ( $rdate ) && $status == 'done')
  3494. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3495. // elseif (! empty ( $rdate ))
  3496. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3497. $categoryList = $Lcategory->find ( array (
  3498. 'asArray' => true
  3499. ) );
  3500. $staffList = $staff->find ( array (
  3501. 'where' => 'cid=' . $cid,
  3502. 'asArray' => true
  3503. ) );
  3504. $cateCondition = "";
  3505. $staffCondition = "";
  3506. $approvalCondition = "";
  3507. if (! empty ( $cid )) {
  3508. $cateCondition = ' and cid=' . $cid;
  3509. }
  3510. if (! empty ( $sid )) {
  3511. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3512. $cateCondition = "";
  3513. }
  3514. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3515. if ($status == 'pendApproval') {
  3516. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3517. }
  3518. if ($status == 'ongoing') {
  3519. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3520. }
  3521. if ($status == 'done') {
  3522. $approvalCondition = ' and (status=8 or status=9 ) ';
  3523. }
  3524. if ($status == 'termination') {
  3525. $approvalCondition = " and status=3";
  3526. }
  3527. if ($status == 'finish') {
  3528. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  3529. }
  3530. $pageinfo ['page'] = array (
  3531. 'previous' => ''
  3532. );
  3533. if(!empty($receiptOrder)){
  3534. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3535. $receiptList = $receipt->find ( array ( // $dateCondition
  3536. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3537. 'desc' => 'rid',
  3538. 'asArray' => true
  3539. ) );
  3540. }else{
  3541. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3542. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3543. $receiptList = $receipt->find ( array ( // $dateCondition.
  3544. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3545. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3546. 'desc' => 'rid',
  3547. 'asArray' => true
  3548. ) );
  3549. } else {
  3550. $receiptList = $receipt->find ( array ( // $dateCondition
  3551. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3552. 'desc' => 'rid',
  3553. 'asArray' => true
  3554. ) );
  3555. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3556. }
  3557. }
  3558. $rLRes = $receipt->find ( array (
  3559. '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 . ')',
  3560. 'desc' => 'rid',
  3561. 'asArray' => true
  3562. ) );
  3563. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3564. // print_r($receiptList);
  3565. Doo::loadClass ( 'XDeode' );
  3566. $XDeode = new XDeode ( 7 );
  3567. $Locate = 0;
  3568. $reportList = $reportCateList = array ();
  3569. foreach ( $receiptList as $key => $value ) {
  3570. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3571. $receiptList [$key] ['Locate'] = $Locate;
  3572. $Locate ++;
  3573. $receiptList [$key] ['reviseDetail'] = array ();
  3574. if (! empty ( $value ['reviseDetail'] ))
  3575. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3576. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3577. $categoryDetil = $Lcategory->getOne ( array (
  3578. 'where' => 'cid=' . $value ['cid'],
  3579. 'asArray' => true
  3580. ) );
  3581. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3582. $verifyList = $verify->getOne ( array (
  3583. 'where' => 'vid=' . $value ['verify'],
  3584. 'asArray' => true
  3585. ) );
  3586. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3587. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3588. foreach ( $verifyList as $k => $v ) {
  3589. // init verifyStaff
  3590. $verifyList [$k] ['date'] = "";
  3591. $verifyList [$k] ['opinion'] = "";
  3592. $verifyList [$k] ['status'] = "";
  3593. if (empty ( $verifyStaff )) {
  3594. $verifyList [$k] ['date'] = "";
  3595. $verifyList [$k] ['opinion'] = "";
  3596. if ($v [0] == $this->staff [0] ['sid']) {
  3597. $verifyList [$k] ['status'] = 4;
  3598. $button = 4;
  3599. }
  3600. } else {
  3601. $flag = true;
  3602. foreach ( $verifyStaff as $m => $u ) {
  3603. if ($v [0] == $m) {
  3604. $verifyList [$k] ['date'] = $u ['date'];
  3605. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3606. $verifyList [$k] ['status'] = $u ['status'];
  3607. $flag = false;
  3608. break;
  3609. }
  3610. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3611. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3612. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3613. }
  3614. if ($flag) { // 检测可编辑
  3615. if ($v [0] == $this->staff [0] ['sid']) {
  3616. $verifyList [$k] ['status'] = 4;
  3617. $button = 4;
  3618. }
  3619. }
  3620. }
  3621. }
  3622. $receiptList [$key] ['verifyList'] = $verifyList;
  3623. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3624. 'where' => 'sid=' . $value ['staff'],
  3625. 'asArray' => true
  3626. ) );
  3627. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3628. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3629. $receiptList [$key] ['button'] = $button;
  3630. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3631. //获得培训班结算RID 借款费用--已经锁定
  3632. if($value['status']==10){
  3633. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  3634. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  3635. }
  3636. }
  3637. $reportList = array_unique ( $reportList );
  3638. $reportHtml = '';
  3639. foreach ( $reportList as $key => $value ) {
  3640. $v = explode ( "-", $value );
  3641. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3642. }
  3643. // print_r($reportList)
  3644. $data ['reportHtml'] = $reportHtml;
  3645. $reportCateList = array_unique ( $reportCateList );
  3646. $reportCateHtml = '';
  3647. foreach ( $reportCateList as $key => $value ) {
  3648. $v = explode ( "-", $value );
  3649. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3650. }
  3651. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3652. $data ['reportCateHtml'] = $reportCateHtml;
  3653. // print_r($receiptList);die;
  3654. // $data['verifyDetail']=$verifyDetail;
  3655. $mothHtml = "";
  3656. for($i = 1; $i <= 12; $i ++) {
  3657. if ($month == $i)
  3658. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3659. else
  3660. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3661. }
  3662. $data ['mothHtml'] = $mothHtml;
  3663. $dateHtml = "";
  3664. $now = date ( "Y" );
  3665. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3666. if ($YEARD <= $now) {
  3667. $dateHtml .= '<option ';
  3668. if ($year == $YEARD) {
  3669. $dateHtml .= 'selected ';
  3670. }
  3671. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3672. }
  3673. }
  3674. $data ['dateHtml'] = $dateHtml;
  3675. $data ['page'] = $pageinfo;
  3676. $data ['receiptList'] = $receiptList;
  3677. $data ['receiptApprovalCount'] = count ( $rLRes );
  3678. $data ['status'] = $status;
  3679. $data ['year'] = $year;
  3680. $data ['month'] = $month;
  3681. $data ['categoryList'] = $categoryList;
  3682. $data ['staffList'] = $staffList;
  3683. $data ['cid'] = $cid;
  3684. $data ['sid'] = $sid;
  3685. // print_r($receiptList);
  3686. $data['receiptOrder']=$receiptOrder;
  3687. $data ['memu'] = "receipt";
  3688. $data ['staff'] = $this->staff;
  3689. $data ['receiptMemu'] = 'approvalExpenses';
  3690. $data ['verifyId'] = $this->verifyId;
  3691. $data ['executeId'] = $this->executeId;
  3692. $this->render ( "/admin/approvalExpenses", $data );
  3693. }
  3694. function expensesDoc() {
  3695. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3696. Doo::loadClass ( 'XDeode' );
  3697. $XDeode = new XDeode ( 5 );
  3698. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3699. $rid = $XDeode->decode ( $rid );
  3700. if (! is_numeric ( $rid ))
  3701. die ( 'illegal request' );
  3702. Doo::loadModel ( 'receipt' );
  3703. $receipt = new receipt ();
  3704. Doo::loadModel ( 'L_category' );
  3705. $Lcategory = new L_category ();
  3706. Doo::loadModel ( 'verify' );
  3707. Doo::loadModel ( 'statistics' );
  3708. $statistics = new statistics ();
  3709. $verify = new verify ();
  3710. Doo::loadModel ( 'staff' );
  3711. $staff = new staff ();
  3712. Doo::loadModel ( 'loanReceipt' );
  3713. $loanReceipt = new loanReceipt ();
  3714. $receiptList = $receipt->find ( array (
  3715. 'where' => ' rid=' . $rid,
  3716. 'desc' => 'rid',
  3717. 'asArray' => true
  3718. ) );
  3719. $loanList = array ();
  3720. if (! empty ( $receiptList ))
  3721. $loanList = $loanReceipt->find ( array (
  3722. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3723. 'desc' => 'rid',
  3724. 'asArray' => true
  3725. ) );
  3726. $Locate = 0;
  3727. $roleId = 0;
  3728. $button = 0;
  3729. foreach ( $loanList as $key => $value ) {
  3730. $loanList [$key] ['Locate'] = $Locate;
  3731. $Locate ++;
  3732. $loanList [$key] ['reviseDetail'] = array ();
  3733. if (! empty ( $value ['reviseDetail'] ))
  3734. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3735. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3736. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3737. $categoryDetil = $Lcategory->getOne ( array (
  3738. 'where' => 'cid=' . $value ['cid'],
  3739. 'asArray' => true
  3740. ) );
  3741. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3742. // 检测编辑状态
  3743. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3744. $verifyList ['staff'] = $value ['verifyBreakup'];
  3745. else
  3746. $verifyList = $verify->getOne ( array (
  3747. 'where' => 'vid=' . $value ['verify'],
  3748. 'asArray' => true
  3749. ) );
  3750. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3751. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3752. Doo::loadModel ( 'role' );
  3753. $role = new role ();
  3754. $flag = true;
  3755. $roleKey = 0;
  3756. $endStaffArray = array ();
  3757. $roleArrayCopy = array ();
  3758. foreach ( $verifyList as $k => $v ) {
  3759. // init verifyStaff
  3760. if ($v [1] == 'ROLE') {
  3761. if (! empty ( $verifyStaff )) {
  3762. $endStaffArray = end ( $verifyStaff );
  3763. // if ($v[0]==$endStaffArray['nextStaff']){
  3764. // $roleId=$v[0];
  3765. // }
  3766. }
  3767. $roleVerify = json_decode ( $v [3], true );
  3768. $roleKey = $k;
  3769. $roleArray = array ();
  3770. $rolename = $role->getOne ( array (
  3771. 'where' => 'rid=' . $v [0],
  3772. 'asArray' => true
  3773. ) );
  3774. foreach ( $roleVerify as $o => $p ) {
  3775. $staffID = explode ( '_', $p );
  3776. $staffInfo = $staff->getOne ( array (
  3777. 'where' => 'sid=' . $staffID [0],
  3778. 'asArray' => true
  3779. ) );
  3780. // print_r($staffID);
  3781. $exp = array (
  3782. 0 => $staffInfo ['sid'],
  3783. 1 => $staffID [1],
  3784. 2 => $staffInfo ['avatar'],
  3785. 'date' => '',
  3786. 'date' => '',
  3787. 'opinion' => '',
  3788. 'status' => '',
  3789. 'rolename' => $rolename ['name']
  3790. );
  3791. array_push ( $roleArray, $exp );
  3792. }
  3793. $roleArrayCopy [$v [0]] = $roleArray;
  3794. // $verifyList[$k]['roleArray']=$roleArray;
  3795. }
  3796. $verifyList [$k] ['date'] = "";
  3797. $verifyList [$k] ['opinion'] = "";
  3798. $verifyList [$k] ['status'] = "";
  3799. if (empty ( $verifyStaff )) {
  3800. $verifyList [$k] ['date'] = "";
  3801. $verifyList [$k] ['opinion'] = "";
  3802. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3803. $verifyList [$k] ['status'] = 4;
  3804. $flag = false;
  3805. }
  3806. } else {
  3807. foreach ( $verifyStaff as $m => $u ) {
  3808. if ($v [0] == $m) {
  3809. $verifyList [$k] ['date'] = $u ['date'];
  3810. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3811. $verifyList [$k] ['status'] = $u ['status'];
  3812. $flag = false;
  3813. break;
  3814. }
  3815. }
  3816. $endStaffArray = end ( $verifyStaff );
  3817. if (isset ( $endStaffArray ['ROLE'] )) {
  3818. } else {
  3819. // $endKey=key($verifyStaff);
  3820. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3821. // $button=4;
  3822. // $verifyList[$k]['status']=4;
  3823. // }
  3824. }
  3825. }
  3826. }
  3827. $rolename ['name'] = '';
  3828. if (! empty ( $roleId )) {
  3829. Doo::loadModel ( 'role' );
  3830. $role = new role ();
  3831. $rolename = $role->getOne ( array (
  3832. 'where' => 'rid=' . $roleId,
  3833. 'asArray' => true
  3834. ) );
  3835. }
  3836. if (! empty ( $verifyStaff ))
  3837. $endStaffArray = end ( $verifyStaff );
  3838. $KOP = false;
  3839. foreach ( $roleArrayCopy as $P => $A ) {
  3840. foreach ( $A as $MKI => $AVL ) {
  3841. if (! empty ( $verifyStaff )) {
  3842. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3843. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3844. $button = 4;
  3845. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3846. }
  3847. foreach ( $verifyStaff as $m => $u ) {
  3848. $AVLFK = $AVL [0] . '_R';
  3849. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3850. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3851. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3852. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3853. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3854. break;
  3855. }
  3856. }
  3857. } else {
  3858. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3859. $button = 4;
  3860. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3861. }
  3862. }
  3863. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3864. $KOP = true;
  3865. }
  3866. }
  3867. foreach ( $roleArrayCopy as $k => $v ) {
  3868. foreach ( $verifyList as $m => $n ) {
  3869. if ($n [0] == $k) {
  3870. array_splice ( $verifyList, $m, 1, $v );
  3871. }
  3872. }
  3873. }
  3874. $loanList [$key] ['verifyList'] = $verifyList;
  3875. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3876. 'where' => 'sid=' . $value ['staff'],
  3877. 'asArray' => true
  3878. ) );
  3879. $loanList [$key] ['button'] = $button;
  3880. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3881. }
  3882. $data ['loanList'] = $loanList;
  3883. //print_r($loanList);
  3884. $Locate = 0;
  3885. $roleId = 0;
  3886. $button = 0;
  3887. foreach ( $receiptList as $key => $value ) {
  3888. $receiptList [$key] ['Locate'] = $Locate;
  3889. $Locate ++;
  3890. $receiptList [$key] ['reviseDetail'] = array ();
  3891. if (! empty ( $value ['reviseDetail'] ))
  3892. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3893. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3894. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3895. $categoryDetil = $Lcategory->getOne ( array (
  3896. 'where' => 'cid=' . $value ['cid'],
  3897. 'asArray' => true
  3898. ) );
  3899. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3900. // 检测编辑状态
  3901. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3902. $verifyList ['staff'] = $value ['verifyBreakup'];
  3903. } else
  3904. $verifyList = $verify->getOne ( array (
  3905. 'where' => 'vid=' . $value ['verify'],
  3906. 'asArray' => true
  3907. ) );
  3908. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3909. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3910. Doo::loadModel ( 'role' );
  3911. $role = new role ();
  3912. if ($verifyList == NULL)
  3913. $verifyList = array ();
  3914. $flag = true;
  3915. $roleKey = 0;
  3916. $endStaffArray = array ();
  3917. $roleArrayCopy = array ();
  3918. foreach ( $verifyList as $k => $v ) {
  3919. // init verifyStaff
  3920. if ($v [1] == 'ROLE') {
  3921. if (! empty ( $verifyStaff )) {
  3922. $endStaffArray = end ( $verifyStaff );
  3923. // if ($v[0]==$endStaffArray['nextStaff']){
  3924. // $roleId=$v[0];
  3925. // }
  3926. }
  3927. $roleVerify = json_decode ( $v [3], true );
  3928. $roleKey = $k;
  3929. $roleArray = array ();
  3930. $rolename = $role->getOne ( array (
  3931. 'where' => 'rid=' . $v [0],
  3932. 'asArray' => true
  3933. ) );
  3934. foreach ( $roleVerify as $o => $p ) {
  3935. $staffID = explode ( '_', $p );
  3936. $staffInfo = $staff->getOne ( array (
  3937. 'where' => 'sid=' . $staffID [0],
  3938. 'asArray' => true
  3939. ) );
  3940. // print_r($staffID);
  3941. $exp = array (
  3942. 0 => $staffInfo ['sid'],
  3943. 1 => $staffID [1],
  3944. 2 => $staffInfo ['avatar'],
  3945. 'date' => '',
  3946. 'date' => '',
  3947. 'opinion' => '',
  3948. 'status' => '',
  3949. 'rolename' => $rolename ['name']
  3950. );
  3951. array_push ( $roleArray, $exp );
  3952. }
  3953. $roleArrayCopy [$v [0]] = $roleArray;
  3954. // $verifyList[$k]['roleArray']=$roleArray;
  3955. }
  3956. $verifyList [$k] ['date'] = "";
  3957. $verifyList [$k] ['opinion'] = "";
  3958. $verifyList [$k] ['status'] = "";
  3959. if (empty ( $verifyStaff )) {
  3960. $verifyList [$k] ['date'] = "";
  3961. $verifyList [$k] ['opinion'] = "";
  3962. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3963. $verifyList [$k] ['status'] = 4;
  3964. $flag = false;
  3965. }
  3966. } else {
  3967. foreach ( $verifyStaff as $m => $u ) {
  3968. if ($v [0] == $m) {
  3969. $verifyList [$k] ['date'] = $u ['date'];
  3970. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3971. $verifyList [$k] ['status'] = $u ['status'];
  3972. $flag = false;
  3973. break;
  3974. }
  3975. }
  3976. $endStaffArray = end ( $verifyStaff );
  3977. if (isset ( $endStaffArray ['ROLE'] )) {
  3978. } else {
  3979. // $endKey=key($verifyStaff);
  3980. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3981. // $button=4;
  3982. // $verifyList[$k]['status']=4;
  3983. // }
  3984. }
  3985. }
  3986. }
  3987. $FC = @$rolename ['name'];
  3988. $rolename ['name'] = '';
  3989. if (! empty ( $roleId )) {
  3990. Doo::loadModel ( 'role' );
  3991. $role = new role ();
  3992. $rolename = $role->getOne ( array (
  3993. 'where' => 'rid=' . $roleId,
  3994. 'asArray' => true
  3995. ) );
  3996. }
  3997. if (! empty ( $verifyStaff ))
  3998. $endStaffArray = end ( $verifyStaff );
  3999. $KOP = false;
  4000. foreach ( $roleArrayCopy as $P => $A ) {
  4001. foreach ( $A as $MKI => $AVL ) {
  4002. if (! empty ( $verifyStaff )) {
  4003. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4004. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4005. $button = 4;
  4006. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4007. }
  4008. foreach ( $verifyStaff as $m => $u ) {
  4009. $AVLFK = $AVL [0] . '_R';
  4010. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4011. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4012. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4013. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4014. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4015. break;
  4016. }
  4017. }
  4018. } else {
  4019. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4020. $button = 4;
  4021. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4022. }
  4023. }
  4024. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4025. $KOP = true;
  4026. }
  4027. }
  4028. foreach ( $roleArrayCopy as $k => $v ) {
  4029. foreach ( $verifyList as $m => $n ) {
  4030. if ($n [0] == $k) {
  4031. array_splice ( $verifyList, $m, 1, $v );
  4032. }
  4033. }
  4034. }
  4035. // 费用执行人相关数据
  4036. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4037. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4038. foreach ( $executeCopy as $k => $v ) {
  4039. $executeCopy [$k] ['date'] = '';
  4040. $executeCopy [$k] ['opinion'] = '';
  4041. $executeCopy [$k] ['status'] = '';
  4042. if (! empty ( $executeStaff ))
  4043. foreach ( $executeStaff as $m => $u ) {
  4044. if ($v [0] == $m) {
  4045. $executeCopy [$k] ['date'] = $u ['date'];
  4046. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4047. $executeCopy [$k] ['status'] = $u ['status'];
  4048. break;
  4049. }
  4050. }
  4051. }
  4052. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4053. // print_r($verifyList);
  4054. $receiptList [$key] ['verifyList'] = $verifyList;
  4055. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4056. 'where' => 'sid=' . $value ['staff'],
  4057. 'asArray' => true
  4058. ) );
  4059. $receiptList [$key] ['button'] = $button;
  4060. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4061. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4062. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4063. $receiptList [$key] ['relust'] = $relust;
  4064. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4065. }
  4066. // print_r($receiptList);
  4067. // 获取审批日志
  4068. Doo::loadModel ( 'receiptLog' );
  4069. $receiptLog = new receiptLog ();
  4070. $rlList = array ();
  4071. $rlInfo = $receiptLog->getOne ( array (
  4072. 'where' => 'rid=' . $rid . ' and status=4',
  4073. 'asArray' => true
  4074. ) );
  4075. // $tijdate = $receiptLog->getOne ( array (
  4076. // 'where' => 'rid=' . $rid . ' and status=2',
  4077. // 'asc' => 'rlid',
  4078. // 'asArray' => true
  4079. // ) );
  4080. if (! empty ( $rlInfo )) {
  4081. $rlList = $receiptLog->find ( array (
  4082. 'where' => 'rid=' . $rid,
  4083. 'asc' => 'rlid',
  4084. 'asArray' => true
  4085. ) );
  4086. }
  4087. $RN=array();
  4088. if (!empty( $rolename ['staff'])){
  4089. $RN = @json_decode ( $rolename ['staff'] );
  4090. }
  4091. //
  4092. foreach ( $rlList as $key => $value ) {
  4093. $rlList [$key] ['rolename'] = '';
  4094. foreach ( $RN as $k => $v ) {
  4095. $id = explode ( "_", $v );
  4096. if ($id [0] == $value ['uid']) {
  4097. $rlList [$key] ['rolename'] = $FC;
  4098. break;
  4099. }
  4100. }
  4101. }
  4102. Doo::loadModel ( 'enclosur' );
  4103. $enclosur = new enclosur ();
  4104. $enclosurList = $enclosur->find ( array (
  4105. 'where' => 'rid=' . $rid,
  4106. 'asArray' => true
  4107. ) );
  4108. $enclosurHtml = '';
  4109. foreach ( $enclosurList as $value ) {
  4110. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4111. }
  4112. $data ['enclosurHtml'] = $enclosurHtml;
  4113. $receiptList [0] ['rlList'] = $rlList;
  4114. $data ['receiptList'] = $receiptList;
  4115. // print_r($receiptList);
  4116. $data ['memu'] = "receipt";
  4117. $data ['staff'] = $this->staff;
  4118. $data ['receiptMemu'] = 'approvalExpenses';
  4119. $data ['verifyId'] = $this->verifyId;
  4120. $data ['executeId'] = $this->executeId;
  4121. $this->render ( "/admin/expensesDoc", $data );
  4122. }
  4123. function expensesEdi() {
  4124. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4125. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4126. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4127. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4128. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4129. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4130. if (empty ( $status ))
  4131. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4132. $vidList = array ();
  4133. $button = 0;
  4134. Doo::loadModel ( 'verify' );
  4135. Doo::loadModel ( 'receipt' );
  4136. Doo::loadModel ( 'staff' );
  4137. $staff = new staff ();
  4138. $receipt = new receipt ();
  4139. $verify = new verify ();
  4140. Doo::loadModel ( 'L_category' );
  4141. $Lcategory = new L_category ();
  4142. Doo::loadModel ( 'enclosur' );
  4143. $enclosur = new enclosur ();
  4144. // user verify ID
  4145. $verifyDetail = $verify->find ( array (
  4146. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4147. 'asArray' => true
  4148. ) );
  4149. foreach ( $verifyDetail as $key => $value ) {
  4150. array_push ( $vidList, $value ['vid'] );
  4151. }
  4152. $vid = implode ( ",", $vidList );
  4153. if (empty ( $verifyDetail ))
  4154. $vid = 0;
  4155. $categoryList = $Lcategory->find ( array (
  4156. 'asArray' => true
  4157. ) );
  4158. $staffList = $staff->find ( array (
  4159. 'where' => 'cid=' . $cid,
  4160. 'asArray' => true
  4161. ) );
  4162. $ap = "";
  4163. if ($status == 4) {
  4164. $ap = 4;
  4165. $status = 2;
  4166. }
  4167. // get Receipt By verifyID status 2
  4168. $receiptList = $receipt->find ( array (
  4169. 'where' => 'rid =' . $rid . ' and status=2',
  4170. 'desc' => 'rid',
  4171. 'asArray' => true
  4172. ) );
  4173. if (empty ( $receiptList )) {
  4174. die ( 'illegal request' );
  4175. }
  4176. $Locate = 0;
  4177. $roleId = 0;
  4178. if ($ap == 4)
  4179. $status = 4;
  4180. foreach ( $receiptList as $key => $value ) {
  4181. $receiptList [$key] ['Locate'] = $Locate;
  4182. $Locate ++;
  4183. $receiptList [$key] ['reviseDetail'] = array ();
  4184. if (! empty ( $value ['reviseDetail'] ))
  4185. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4186. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4187. $categoryDetil = $Lcategory->getOne ( array (
  4188. 'where' => 'cid=' . $value ['cid'],
  4189. 'asArray' => true
  4190. ) );
  4191. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4192. // 检测编辑状态
  4193. $verifyList = $verify->getOne ( array (
  4194. 'where' => 'vid=' . $value ['verify'],
  4195. 'asArray' => true
  4196. ) );
  4197. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4198. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4199. Doo::loadModel ( 'role' );
  4200. $role = new role ();
  4201. // print_r($verifyList);
  4202. $flag = true;
  4203. $roleKey = 0;
  4204. $endStaffArray = array ();
  4205. $roleArrayCopy = array ();
  4206. foreach ( $verifyList as $k => $v ) {
  4207. // init verifyStaff
  4208. if ($v [1] == 'ROLE') {
  4209. if (! empty ( $verifyStaff )) {
  4210. $endStaffArray = end ( $verifyStaff );
  4211. if ($v [0] == $endStaffArray ['nextStaff']) {
  4212. $roleId = $v [0];
  4213. }
  4214. }
  4215. $roleVerify = json_decode ( $v [3], true );
  4216. $roleKey = $k;
  4217. $roleArray = array ();
  4218. $rolename = $role->getOne ( array (
  4219. 'where' => 'rid=' . $v [0],
  4220. 'asArray' => true
  4221. ) );
  4222. foreach ( $roleVerify as $o => $p ) {
  4223. $staffID = explode ( '_', $p );
  4224. $staffInfo = $staff->getOne ( array (
  4225. 'where' => 'sid=' . $staffID [0],
  4226. 'asArray' => true
  4227. ) );
  4228. // print_r($staffID);
  4229. $exp = array (
  4230. 0 => $staffInfo ['sid'],
  4231. 1 => $staffID [1],
  4232. 2 => $staffInfo ['avatar'],
  4233. 'date' => '',
  4234. 'date' => '',
  4235. 'opinion' => '',
  4236. 'status' => '',
  4237. 'rolename' => $rolename ['name']
  4238. );
  4239. array_push ( $roleArray, $exp );
  4240. }
  4241. $roleArrayCopy [$v [0]] = $roleArray;
  4242. // $verifyList[$k]['roleArray']=$roleArray;
  4243. }
  4244. // print_r($roleArray);
  4245. $verifyList [$k] ['date'] = "";
  4246. $verifyList [$k] ['opinion'] = "";
  4247. $verifyList [$k] ['status'] = "";
  4248. if (empty ( $verifyStaff )) {
  4249. $verifyList [$k] ['date'] = "";
  4250. $verifyList [$k] ['opinion'] = "";
  4251. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4252. $verifyList [$k] ['status'] = 4;
  4253. $button = 4;
  4254. $flag = false;
  4255. }
  4256. } else {
  4257. foreach ( $verifyStaff as $m => $u ) {
  4258. if ($v [0] == $m) {
  4259. $verifyList [$k] ['date'] = $u ['date'];
  4260. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4261. $verifyList [$k] ['status'] = $u ['status'];
  4262. $flag = false;
  4263. break;
  4264. }
  4265. }
  4266. $endStaffArray = end ( $verifyStaff );
  4267. if (isset ( $endStaffArray ['ROLE'] )) {
  4268. } else {
  4269. $endKey = key ( $verifyStaff );
  4270. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4271. $button = 4;
  4272. $verifyList [$k] ['status'] = 4;
  4273. }
  4274. }
  4275. }
  4276. }
  4277. $rolename ['name'] = '';
  4278. if (! empty ( $roleId )) {
  4279. Doo::loadModel ( 'role' );
  4280. $role = new role ();
  4281. $rolename = $role->getOne ( array (
  4282. 'where' => 'rid=' . $roleId,
  4283. 'asArray' => true
  4284. ) );
  4285. }
  4286. if (! empty ( $verifyStaff ))
  4287. $endStaffArray = end ( $verifyStaff );
  4288. $KOP = false;
  4289. foreach ( $roleArrayCopy as $P => $A ) {
  4290. foreach ( $A as $MKI => $AVL ) {
  4291. if (! empty ( $verifyStaff )) {
  4292. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4293. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4294. $button = 4;
  4295. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4296. }
  4297. foreach ( $verifyStaff as $m => $u ) {
  4298. $AVLFK = $AVL [0] . '_R';
  4299. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4300. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4301. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4302. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4303. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4304. break;
  4305. }
  4306. }
  4307. } else {
  4308. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4309. $button = 4;
  4310. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4311. }
  4312. }
  4313. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4314. $KOP = true;
  4315. }
  4316. }
  4317. // print_r($roleArrayCopy);
  4318. // echo $roleKey;
  4319. foreach ( $roleArrayCopy as $k => $v ) {
  4320. foreach ( $verifyList as $m => $n ) {
  4321. if ($n [0] == $k) {
  4322. array_splice ( $verifyList, $m, 1, $v );
  4323. }
  4324. }
  4325. }
  4326. $receiptList [$key] ['verifyList'] = $verifyList;
  4327. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4328. 'where' => 'sid=' . $value ['staff'],
  4329. 'asArray' => true
  4330. ) );
  4331. $receiptList [$key] ['button'] = $button;
  4332. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4333. }
  4334. // $data['verifyDetail']=$verifyDetail;
  4335. $mothHtml = "";
  4336. for($i = 1; $i <= 12; $i ++) {
  4337. if ($month == $i)
  4338. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4339. else
  4340. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4341. }
  4342. // 获取审批日志
  4343. Doo::loadModel ( 'receiptLog' );
  4344. $receiptLog = new receiptLog ();
  4345. $rlList = array ();
  4346. $rlInfo = $receiptLog->getOne ( array (
  4347. 'where' => 'rid=' . $rid . ' and status=4',
  4348. 'asArray' => true
  4349. ) );
  4350. $tijdate = $receiptLog->getOne ( array (
  4351. 'where' => 'rid=' . $rid . ' and status=2',
  4352. 'asc' => 'rlid',
  4353. 'asArray' => true
  4354. ) );
  4355. if (! empty ( $rlInfo )) {
  4356. $rlList = $receiptLog->find ( array (
  4357. 'where' => 'rid=' . $rid,
  4358. 'asc' => 'rlid',
  4359. 'asArray' => true
  4360. ) );
  4361. }
  4362. $receiptList [0] ['rlList'] = $rlList;
  4363. $enclosurList = $enclosur->find ( array (
  4364. 'where' => 'rid=' . $rid,
  4365. 'asArray' => true
  4366. ) );
  4367. $enclosurHtml = '';
  4368. foreach ( $enclosurList as $value ) {
  4369. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4370. }
  4371. // print_r($receiptList);
  4372. $data ['rid'] = $rid;
  4373. $data ['enclosurHtml'] = $enclosurHtml;
  4374. $data ['rolename'] = $rolename ['name'];
  4375. $data ['datetij'] = $tijdate ['date'];
  4376. $data ['mothHtml'] = $mothHtml;
  4377. $data ['receiptList'] = $receiptList;
  4378. $data ['receiptApprovalCount'] = count ( $receiptList );
  4379. $data ['status'] = $status;
  4380. $data ['year'] = $year;
  4381. $data ['categoryList'] = $categoryList;
  4382. $data ['staffList'] = $staffList;
  4383. $data ['cid'] = $cid;
  4384. $data ['sid'] = $sid;
  4385. $data ['ap'] = $ap;
  4386. $data ['memu'] = "receipt";
  4387. $data ['staff'] = $this->staff;
  4388. $data ['receiptMemu'] = 'approvalExpenses';
  4389. $data ['verifyId'] = $this->verifyId;
  4390. $data ['executeId'] = $this->executeId;
  4391. $this->render ( "/admin/expensesEdi", $data );
  4392. }
  4393. function expensesDefray() {
  4394. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4395. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4396. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4397. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4398. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4399. if (! empty ( $rid )) {
  4400. Doo::loadModel ( "verify" );
  4401. $verify = new verify ();
  4402. Doo::loadModel ( "receiptDetail" );
  4403. $receiptDetailObj = new receiptDetail ();
  4404. Doo::loadModel ( "itemStatistics" );
  4405. Doo::loadModel ( "statistics" );
  4406. $statistics = new statistics ();
  4407. $itemStatistics = new itemStatistics ();
  4408. Doo::loadModel ( "receipt" );
  4409. $receipt = new receipt ();
  4410. Doo::loadModel ( "loanReceipt" );
  4411. $loanReceipt = new loanReceipt ();
  4412. $receiptDetail = $receipt->getOne ( array (
  4413. 'where' => 'rid=' . $rid . ' and status=2 ',
  4414. 'asArray' => true
  4415. ) );
  4416. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4417. $nsflag = true;
  4418. foreach ( $nslist as $value ) {
  4419. if ($value == $this->staff ['0'] ['sid']) {
  4420. $nsflag = false;
  4421. break;
  4422. }
  4423. }
  4424. // print_r($nslist);die;
  4425. if (empty ( $receiptDetail ) || $nsflag)
  4426. return "/approvalExpenses/pendApproval";
  4427. $verifyDetail = $verify->getOne ( array (
  4428. 'where' => ' vid =' . $receiptDetail ['verify'],
  4429. 'asArray' => true
  4430. ) );
  4431. $verifyString = $verifyDetail ['staff'];
  4432. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4433. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4434. if (empty ( $opinion )) {
  4435. if ($status == 3)
  4436. $opinion = "终止";
  4437. else
  4438. $opinion = "同意支付";
  4439. }
  4440. $nowStaff = 0;
  4441. $nowStaffList = array ();
  4442. if (empty ( $verifyStaff )) {
  4443. // 还需加入是否已经进入角色审批
  4444. if ($verifyDetail [0] [1] == 'ROLE') {
  4445. // print_r($verifyDetail);echo "ddd";
  4446. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4447. foreach ( $vStaffString as $key => $value ) {
  4448. $staffK = explode ( "_", $value );
  4449. if ($staffK [0] != $this->staff [0] ['sid'])
  4450. array_push ( $nowStaffList, $staffK [0] );
  4451. }
  4452. // print_r($verifyDetail);
  4453. // die;
  4454. if (! empty ( $nowStaffList )) {
  4455. $nowStaff = implode ( ',', $nowStaffList );
  4456. $verifyStaff = array (
  4457. $this->staff [0] ['sid'] . "_R" => array (
  4458. 'date' => date ( 'Y-m-d' ),
  4459. 'opinion' => $opinion,
  4460. 'status' => $status,
  4461. 'nextStaff' => $verifyDetail [0] [0],
  4462. 'ROLE' => 1
  4463. )
  4464. );
  4465. } else {
  4466. $nowStaff = $verifyDetail [1] [0];
  4467. $verifyStaff = array (
  4468. $this->staff [0] ['sid'] . "_R" => array (
  4469. 'date' => date ( 'Y-m-d' ),
  4470. 'opinion' => $opinion,
  4471. 'status' => $status,
  4472. 'nextStaff' => $verifyDetail [1] [0]
  4473. )
  4474. );
  4475. }
  4476. } else {
  4477. if ($verifyDetail [1] [1] == 'ROLE') {
  4478. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4479. // echo "dd";
  4480. foreach ( $vStaffString as $key => $value ) {
  4481. $staffK = explode ( "_", $value );
  4482. array_push ( $nowStaffList, $staffK [0] );
  4483. }
  4484. $nowStaff = implode ( ',', $nowStaffList );
  4485. $verifyStaff = array (
  4486. $this->staff [0] ['sid'] => array (
  4487. 'date' => date ( 'Y-m-d' ),
  4488. 'opinion' => $opinion,
  4489. 'status' => $status,
  4490. 'nextStaff' => $verifyDetail [1] [0],
  4491. 'ROLE' => 1
  4492. )
  4493. );
  4494. } else {
  4495. $nowStaff = $verifyDetail [1] [0];
  4496. $verifyStaff = array (
  4497. $this->staff [0] ['sid'] => array (
  4498. 'date' => date ( 'Y-m-d' ),
  4499. 'opinion' => $opinion,
  4500. 'status' => $status,
  4501. 'nextStaff' => $verifyDetail [1] [0]
  4502. )
  4503. );
  4504. }
  4505. }
  4506. if ($status == 3)
  4507. $verifyStaff = array (
  4508. 'final' => $status,
  4509. $this->staff [0] ['sid'] => array (
  4510. 'date' => date ( 'Y-m-d' ),
  4511. 'opinion' => $opinion,
  4512. 'status' => $status
  4513. )
  4514. );
  4515. $vStaffString = json_encode ( $verifyStaff );
  4516. $receipt->nowStaff = $nowStaff;
  4517. $receipt->verifyStaff = $vStaffString;
  4518. $loanReceipt->nowStaff = $nowStaff;
  4519. $loanReceipt->verifyStaff = $vStaffString;
  4520. } else {
  4521. $VS = end ( $verifyStaff );
  4522. // 非角色审批
  4523. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4524. $nextStaff = 0;
  4525. $roleSTF = false;
  4526. foreach ( $verifyDetail as $key => $value ) {
  4527. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4528. if (isset ( $verifyDetail [$key + 1] )) {
  4529. $nextStaff = $verifyDetail [$key + 1] [0];
  4530. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4531. $roleSTF = true;
  4532. }
  4533. break;
  4534. }
  4535. }
  4536. if (! $roleSTF) {
  4537. $nowStaff = $nextStaff;
  4538. $verifyStaff [$this->staff [0] ['sid']] = array (
  4539. 'date' => date ( 'Y-m-d' ),
  4540. 'opinion' => $opinion,
  4541. 'status' => $status,
  4542. 'nextStaff' => $nextStaff
  4543. );
  4544. } else {
  4545. // 获取角色下的所有用户ID
  4546. $nowStaffList = array ();
  4547. foreach ( $verifyDetail as $vfk ) {
  4548. if ($vfk [1] == 'ROLE') {
  4549. $vStaffString = json_decode ( $vfk [3] );
  4550. foreach ( $vStaffString as $key => $value ) {
  4551. $staffK = explode ( "_", $value );
  4552. array_push ( $nowStaffList, $staffK [0] );
  4553. }
  4554. }
  4555. }
  4556. $nowStaff = implode ( ',', $nowStaffList );
  4557. $verifyStaff [$this->staff [0] ['sid']] = array (
  4558. 'date' => date ( 'Y-m-d' ),
  4559. 'opinion' => $opinion,
  4560. 'status' => $status,
  4561. 'nextStaff' => $nextStaff,
  4562. 'ROLE' => 0
  4563. );
  4564. }
  4565. if ($status == 3) {
  4566. $verifyStaff ['final'] = $status;
  4567. $verifyStaff [$this->staff [0] ['sid']] = array (
  4568. 'date' => date ( 'Y-m-d' ),
  4569. 'opinion' => $opinion,
  4570. 'status' => $status
  4571. );
  4572. }
  4573. $vStaffString = json_encode ( $verifyStaff );
  4574. $receipt->nowStaff = $nowStaff;
  4575. $receipt->verifyStaff = $vStaffString;
  4576. $loanReceipt->nowStaff = $nowStaff;
  4577. $loanReceipt->verifyStaff = $vStaffString;
  4578. }
  4579. // 角色审批
  4580. if (isset ( $VS ['ROLE'] )) {
  4581. // 找出角色人 当前审批角色组
  4582. $verifyJSStaff = array ();
  4583. $nowStaffList2 = array ();
  4584. foreach ( $verifyDetail as $key => $value ) {
  4585. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4586. $verifyJSStaff = json_decode ( $value [3] );
  4587. foreach ( $verifyJSStaff as $m ) {
  4588. $staffK = explode ( "_", $m );
  4589. array_push ( $nowStaffList2, $staffK [0] );
  4590. }
  4591. // print_r($nowStaffList2);
  4592. }
  4593. }
  4594. $RoleVerifyStaff = array ();
  4595. foreach ( $verifyStaff as $key => $value ) {
  4596. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4597. foreach ( $nowStaffList2 as $m ) {
  4598. if ($key == $m . "_R")
  4599. $RoleVerifyStaff [$key] = $value;
  4600. }
  4601. }
  4602. }
  4603. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4604. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4605. // 下一个审批人ID
  4606. $nextStaff = 0;
  4607. $falg = false;
  4608. foreach ( $verifyDetail as $key => $value ) {
  4609. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4610. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4611. $falg = true;
  4612. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4613. $nowStaffList = array ();
  4614. foreach ( $vStaffString as $v ) {
  4615. $staffK = explode ( "_", $v );
  4616. array_push ( $nowStaffList, $staffK [0] );
  4617. }
  4618. $nowStaff = implode ( ',', $nowStaffList );
  4619. $nextStaff = $verifyDetail [$key + 1] [0];
  4620. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4621. $nextStaff = $verifyDetail [$key + 1] [0];
  4622. $nowStaff = $nextStaff;
  4623. } else
  4624. $nowStaff = '';
  4625. break;
  4626. }
  4627. }
  4628. if ($falg)
  4629. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4630. 'date' => date ( 'Y-m-d' ),
  4631. 'opinion' => $opinion,
  4632. 'status' => $status,
  4633. 'nextStaff' => $nextStaff,
  4634. 'ROLE' => 1
  4635. );
  4636. else
  4637. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4638. 'date' => date ( 'Y-m-d' ),
  4639. 'opinion' => $opinion,
  4640. 'status' => $status,
  4641. 'nextStaff' => $nextStaff
  4642. );
  4643. // print_r($verifyStaff);
  4644. // echo $nowStaff;die;
  4645. } else { // 进入下一个角色或者审批人
  4646. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4647. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4648. 'date' => date ( 'Y-m-d' ),
  4649. 'opinion' => $opinion,
  4650. 'status' => $status,
  4651. 'nextStaff' => $VS ['nextStaff'],
  4652. 'ROLE' => 1
  4653. );
  4654. }
  4655. if ($status == 3) {
  4656. $verifyStaff ['final'] = $status;
  4657. $verifyStaff [$this->staff [0] ['sid']] = array (
  4658. 'date' => date ( 'Y-m-d' ),
  4659. 'opinion' => $opinion,
  4660. 'status' => $status
  4661. );
  4662. }
  4663. $vStaffString = json_encode ( $verifyStaff );
  4664. $receipt->verifyStaff = $vStaffString;
  4665. $receipt->nowStaff = $nowStaff;
  4666. $loanReceipt->nowStaff = $nowStaff;
  4667. $loanReceipt->verifyStaff = $vStaffString;
  4668. }
  4669. // print_r($verifyStaff);die;
  4670. }
  4671. $roleKey = 0;
  4672. $roleId = 0;
  4673. $verifyDetailCopy = array ();
  4674. foreach ( $verifyDetail as $k => $v ) {
  4675. if ($v [1] == 'ROLE') {
  4676. $roleId = $v [0];
  4677. $roleVerify = json_decode ( $v [3], true );
  4678. $roleKey = $k;
  4679. $roleArray = array ();
  4680. foreach ( $roleVerify as $o => $p ) {
  4681. $staffID = explode ( '_', $p );
  4682. $exp = array (
  4683. 0 => $staffID [0],
  4684. 1 => $staffID [1]
  4685. );
  4686. array_push ( $roleArray, $exp );
  4687. }
  4688. $verifyDetailCopy [$v [0]] = $roleArray;
  4689. }
  4690. }
  4691. // print_r($verifyDetail);
  4692. foreach ( $verifyDetailCopy as $k => $v ) {
  4693. foreach ( $verifyDetail as $m => $n ) {
  4694. if ($n [0] == $k) {
  4695. array_splice ( $verifyDetail, $m, 1, $v );
  4696. }
  4697. }
  4698. }
  4699. // 审批日志
  4700. if (! isset ( $verifyStaff ['final'] )) {
  4701. Doo::loadModel ( "receiptLog" );
  4702. $receiptLog = new receiptLog ();
  4703. if (! empty ( $roleId )) {
  4704. Doo::loadModel ( "role" );
  4705. $role = new role ();
  4706. $roleInfo = $role->getOne ( array (
  4707. 'where' => 'rid=' . $roleId,
  4708. 'asArray' => true
  4709. ) );
  4710. $receiptLog->rolename = $roleInfo ['name'];
  4711. }
  4712. $receiptLog->username = $this->staff [0] ['username'];
  4713. $receiptLog->uid = $this->staff [0] ['sid'];
  4714. $receiptLog->date = date ( "Y-m-d" );
  4715. $receiptLog->opinion = $opinion;
  4716. $receiptLog->img = $this->staff [0] ['avatar'];
  4717. $receiptLog->status = 1;
  4718. $receiptLog->rid = $rid;
  4719. $receiptLog->insert ();
  4720. }
  4721. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4722. $receipt->status = 3;
  4723. $receipt->verifyBreakup = $verifyString;
  4724. $receiptDetailObj->status = 3;
  4725. $receiptDetailObj->update ( array (
  4726. 'where' => 'rid=' . $rid
  4727. ) );
  4728. // 微信企业号通知
  4729. $this->setWXMsg ( $rid, 3 );
  4730. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4731. $receipt->status = 6;
  4732. $receipt->pastDate = date ( "Y-m-d" );
  4733. $receipt->isBK = 1;
  4734. $loanReceipt->verifyBreakup = $verifyString;
  4735. $loanReceipt->status = 1;
  4736. $loanReceipt->pastDate = date ( "Y-m-d" );
  4737. //生成流水后 不更新汇款金额
  4738. Doo::loadModel ( 'wasteBook' );
  4739. $wasteBook = new wasteBook ();
  4740. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4741. if (empty($wbDetail)){
  4742. $loanReceipt->amount = $receiptDetail ['amount'];
  4743. }
  4744. $loanReceipt->update ( array (
  4745. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4746. ) );
  4747. // 微信企业号通知
  4748. $this->setWXMsg ( $rid, 1 );
  4749. }
  4750. $receipt->amount = $receiptDetail['sum'];
  4751. $receipt->update ( array (
  4752. 'where' => ' rid = ' . $rid
  4753. ) );
  4754. // 进入下一条审批费用新加需求
  4755. $vidList = array ();
  4756. $verifyDetail = $verify->find ( array (
  4757. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4758. 'asArray' => true
  4759. ) );
  4760. foreach ( $verifyDetail as $key => $value ) {
  4761. array_push ( $vidList, $value ['vid'] );
  4762. }
  4763. $vid = implode ( ",", $vidList );
  4764. if (empty ( $verifyDetail ))
  4765. $vid = 0;
  4766. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4767. $receipt = new receipt ();
  4768. $rd = $receipt->getOne ( array (
  4769. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4770. 'asc' => 'rid',
  4771. 'asArray' => true
  4772. ) );
  4773. if (empty ( $rd )) {
  4774. return '/approvalExpenses/pendApproval';
  4775. }
  4776. if ($rd ['Rtype'] == 1) {
  4777. if ($rd ['isBK'] == 1) {
  4778. return '/receiptburEdi/' . $rd ['rid'];
  4779. } else {
  4780. return '/expensesEdi/' . $rd ['rid'];
  4781. }
  4782. } elseif ($rd ['Rtype'] == 2) {
  4783. return '/remitApproval/' . $rd ['rid'];
  4784. } else {
  4785. return '/receiptburEdi/' . $rd ['rid'];
  4786. }
  4787. // return "/approvalExpenses/pendApproval";
  4788. }
  4789. }
  4790. function ajaxExamineExe() {
  4791. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4792. Doo::loadModel ( 'receipt' );
  4793. $receipt = new receipt ();
  4794. Doo::loadClass ( 'XDeode' );
  4795. $XDeode = new XDeode ( 5 );
  4796. if (! empty ( $rid )) {
  4797. $rLRes = $receipt->find ( array (
  4798. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4799. 'asArray' => true
  4800. ) );
  4801. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4802. echo json_encode ( array (
  4803. 'status' => 1,
  4804. 'receipt' => $rLRes [0]
  4805. ) );
  4806. die ();
  4807. }
  4808. echo json_encode ( array (
  4809. 'status' => 0,
  4810. 'receipt' => array ()
  4811. ) );
  4812. die ();
  4813. }
  4814. function implement() {
  4815. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4816. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  4817. Doo::loadClass ( 'XDeode' );
  4818. $XDeode = new XDeode ( 5 );
  4819. Doo::loadModel ( 'receipt' );
  4820. $receipt = new receipt ();
  4821. Doo::loadModel ( 'L_category' );
  4822. $Lcategory = new L_category ();
  4823. Doo::loadModel ( 'verify' );
  4824. $verify = new verify ();
  4825. Doo::loadModel ( 'staff' );
  4826. $staff = new staff ();
  4827. Doo::loadModel ( "execute" );
  4828. $execute = new execute ();
  4829. $rid = $XDeode->decode ( $rid );
  4830. $receiptList = $receipt->find ( array (
  4831. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4832. 'desc' => 'rid',
  4833. 'asArray' => true
  4834. ) );
  4835. Doo::loadModel ( 'loanReceipt' );
  4836. $loanReceipt = new loanReceipt ();
  4837. // print_r($receiptList);
  4838. $loanList = array ();
  4839. if (! isset ( $receiptList ))
  4840. $loanList = $loanReceipt->find ( array (
  4841. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4842. 'desc' => 'rid',
  4843. 'asArray' => true
  4844. ) );
  4845. $Locate = 0;
  4846. $roleId = 0;
  4847. $button = 0;
  4848. foreach ( $loanList as $key => $value ) {
  4849. $loanList [$key] ['Locate'] = $Locate;
  4850. $Locate ++;
  4851. $loanList [$key] ['reviseDetail'] = array ();
  4852. if (! empty ( $value ['reviseDetail'] ))
  4853. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4854. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4855. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4856. $categoryDetil = $Lcategory->getOne ( array (
  4857. 'where' => 'cid=' . $value ['cid'],
  4858. 'asArray' => true
  4859. ) );
  4860. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4861. // 检测编辑状态
  4862. $verifyList = $verify->getOne ( array (
  4863. 'where' => 'vid=' . $value ['verify'],
  4864. 'asArray' => true
  4865. ) );
  4866. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4867. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4868. Doo::loadModel ( 'role' );
  4869. $role = new role ();
  4870. $flag = true;
  4871. $roleKey = 0;
  4872. $endStaffArray = array ();
  4873. $roleArrayCopy = array ();
  4874. foreach ( $verifyList as $k => $v ) {
  4875. // init verifyStaff
  4876. if ($v [1] == 'ROLE') {
  4877. if (! empty ( $verifyStaff )) {
  4878. $endStaffArray = end ( $verifyStaff );
  4879. // if ($v[0]==$endStaffArray['nextStaff']){
  4880. // $roleId=$v[0];
  4881. // }
  4882. }
  4883. $roleVerify = json_decode ( $v [3], true );
  4884. $roleKey = $k;
  4885. $roleArray = array ();
  4886. $rolename = $role->getOne ( array (
  4887. 'where' => 'rid=' . $v [0],
  4888. 'asArray' => true
  4889. ) );
  4890. foreach ( $roleVerify as $o => $p ) {
  4891. $staffID = explode ( '_', $p );
  4892. $staffInfo = $staff->getOne ( array (
  4893. 'where' => 'sid=' . $staffID [0],
  4894. 'asArray' => true
  4895. ) );
  4896. // print_r($staffID);
  4897. $exp = array (
  4898. 0 => $staffInfo ['sid'],
  4899. 1 => $staffID [1],
  4900. 2 => $staffInfo ['avatar'],
  4901. 'date' => '',
  4902. 'date' => '',
  4903. 'opinion' => '',
  4904. 'status' => '',
  4905. 'rolename' => $rolename ['name']
  4906. );
  4907. array_push ( $roleArray, $exp );
  4908. }
  4909. $roleArrayCopy [$v [0]] = $roleArray;
  4910. // $verifyList[$k]['roleArray']=$roleArray;
  4911. }
  4912. $verifyList [$k] ['date'] = "";
  4913. $verifyList [$k] ['opinion'] = "";
  4914. $verifyList [$k] ['status'] = "";
  4915. if (empty ( $verifyStaff )) {
  4916. $verifyList [$k] ['date'] = "";
  4917. $verifyList [$k] ['opinion'] = "";
  4918. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4919. $verifyList [$k] ['status'] = 4;
  4920. $flag = false;
  4921. }
  4922. } else {
  4923. foreach ( $verifyStaff as $m => $u ) {
  4924. if ($v [0] == $m) {
  4925. $verifyList [$k] ['date'] = $u ['date'];
  4926. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4927. $verifyList [$k] ['status'] = $u ['status'];
  4928. $flag = false;
  4929. break;
  4930. }
  4931. }
  4932. $endStaffArray = end ( $verifyStaff );
  4933. if (isset ( $endStaffArray ['ROLE'] )) {
  4934. } else {
  4935. // $endKey=key($verifyStaff);
  4936. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4937. // $button=4;
  4938. // $verifyList[$k]['status']=4;
  4939. // }
  4940. }
  4941. }
  4942. }
  4943. $rolename ['name'] = '';
  4944. if (! empty ( $roleId )) {
  4945. Doo::loadModel ( 'role' );
  4946. $role = new role ();
  4947. $rolename = $role->getOne ( array (
  4948. 'where' => 'rid=' . $roleId,
  4949. 'asArray' => true
  4950. ) );
  4951. }
  4952. if (! empty ( $verifyStaff ))
  4953. $endStaffArray = end ( $verifyStaff );
  4954. $KOP = false;
  4955. foreach ( $roleArrayCopy as $P => $A ) {
  4956. foreach ( $A as $MKI => $AVL ) {
  4957. if (! empty ( $verifyStaff )) {
  4958. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4959. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4960. $button = 4;
  4961. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4962. }
  4963. foreach ( $verifyStaff as $m => $u ) {
  4964. $AVLFK = $AVL [0] . '_R';
  4965. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4966. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4967. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4968. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4969. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4970. break;
  4971. }
  4972. }
  4973. } else {
  4974. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4975. $button = 4;
  4976. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4977. }
  4978. }
  4979. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4980. $KOP = true;
  4981. }
  4982. }
  4983. foreach ( $roleArrayCopy as $k => $v ) {
  4984. foreach ( $verifyList as $m => $n ) {
  4985. if ($n [0] == $k) {
  4986. array_splice ( $verifyList, $m, 1, $v );
  4987. }
  4988. }
  4989. }
  4990. $loanList [$key] ['verifyList'] = $verifyList;
  4991. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4992. 'where' => 'sid=' . $value ['staff'],
  4993. 'asArray' => true
  4994. ) );
  4995. }
  4996. $data ['loanList'] = $loanList;
  4997. $Locate = 0;
  4998. $roleId = 0;
  4999. $button = 0;
  5000. Doo::loadClass ( 'XDeode' );
  5001. $XDeode = new XDeode ( 5 );
  5002. foreach ( $receiptList as $key => $value ) {
  5003. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  5004. $button2 = 0;
  5005. $receiptList [$key] ['Locate'] = $Locate;
  5006. $Locate ++;
  5007. $receiptList [$key] ['reviseDetail'] = array ();
  5008. if (! empty ( $value ['reviseDetail'] ))
  5009. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5010. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5011. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5012. $categoryDetil = $Lcategory->getOne ( array (
  5013. 'where' => 'cid=' . $value ['cid'],
  5014. 'asArray' => true
  5015. ) );
  5016. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5017. $executeList = json_decode ( $value ['executeCopy'], true );
  5018. $executeStaff = array ();
  5019. if (! empty ( $value ['executeStaff'] ))
  5020. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5021. if (isset ( $executeList )) {
  5022. foreach ( $executeList as $op => $lo ) {
  5023. $executeList [$op] ['date'] = "";
  5024. $executeList [$op] ['opinion'] = "";
  5025. $executeList [$op] ['status'] = "";
  5026. foreach ( $executeStaff as $m => $u ) {
  5027. if ($lo [0] == $m) {
  5028. $executeList [$op] ['date'] = $u ['date'];
  5029. $executeList [$op] ['opinion'] = $u ['opinion'];
  5030. $executeList [$op] ['status'] = $u ['status'];
  5031. break;
  5032. }
  5033. }
  5034. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5035. $button2 = 1;
  5036. $executeList [$op] ['status'] = 4;
  5037. }
  5038. }
  5039. }
  5040. // 检测编辑状态
  5041. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5042. $verifyList ['staff'] = $value ['verifyBreakup'];
  5043. } else
  5044. $verifyList = $verify->getOne ( array (
  5045. 'where' => 'vid=' . $value ['verify'],
  5046. 'asArray' => true
  5047. ) );
  5048. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5049. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5050. Doo::loadModel ( 'role' );
  5051. $role = new role ();
  5052. if ($verifyList == NULL)
  5053. $verifyList = array ();
  5054. $flag = true;
  5055. $roleKey = 0;
  5056. $endStaffArray = array ();
  5057. $roleArrayCopy = array ();
  5058. foreach ( $verifyList as $k => $v ) {
  5059. // init verifyStaff
  5060. if ($v [1] == 'ROLE') {
  5061. if (! empty ( $verifyStaff )) {
  5062. $endStaffArray = end ( $verifyStaff );
  5063. // if ($v[0]==$endStaffArray['nextStaff']){
  5064. // $roleId=$v[0];
  5065. // }
  5066. }
  5067. $roleVerify = json_decode ( $v [3], true );
  5068. $roleKey = $k;
  5069. $roleArray = array ();
  5070. $rolename = $role->getOne ( array (
  5071. 'where' => 'rid=' . $v [0],
  5072. 'asArray' => true
  5073. ) );
  5074. foreach ( $roleVerify as $o => $p ) {
  5075. $staffID = explode ( '_', $p );
  5076. $staffInfo = $staff->getOne ( array (
  5077. 'where' => 'sid=' . $staffID [0],
  5078. 'asArray' => true
  5079. ) );
  5080. // print_r($staffID);
  5081. $exp = array (
  5082. 0 => $staffInfo ['sid'],
  5083. 1 => $staffID [1],
  5084. 2 => $staffInfo ['avatar'],
  5085. 'date' => '',
  5086. 'date' => '',
  5087. 'opinion' => '',
  5088. 'status' => '',
  5089. 'rolename' => $rolename ['name']
  5090. );
  5091. array_push ( $roleArray, $exp );
  5092. }
  5093. $roleArrayCopy [$v [0]] = $roleArray;
  5094. // $verifyList[$k]['roleArray']=$roleArray;
  5095. }
  5096. $verifyList [$k] ['date'] = "";
  5097. $verifyList [$k] ['opinion'] = "";
  5098. $verifyList [$k] ['status'] = "";
  5099. if (empty ( $verifyStaff )) {
  5100. $verifyList [$k] ['date'] = "";
  5101. $verifyList [$k] ['opinion'] = "";
  5102. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5103. $verifyList [$k] ['status'] = 4;
  5104. $flag = false;
  5105. }
  5106. } else {
  5107. foreach ( $verifyStaff as $m => $u ) {
  5108. if ($v [0] == $m) {
  5109. $verifyList [$k] ['date'] = $u ['date'];
  5110. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5111. $verifyList [$k] ['status'] = $u ['status'];
  5112. $flag = false;
  5113. break;
  5114. }
  5115. }
  5116. $endStaffArray = end ( $verifyStaff );
  5117. if (isset ( $endStaffArray ['ROLE'] )) {
  5118. } else {
  5119. // $endKey=key($verifyStaff);
  5120. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5121. // $button=4;
  5122. // $verifyList[$k]['status']=4;
  5123. // }
  5124. }
  5125. }
  5126. }
  5127. $rolename ['name'] = '';
  5128. if (! empty ( $roleId )) {
  5129. Doo::loadModel ( 'role' );
  5130. $role = new role ();
  5131. $rolename = $role->getOne ( array (
  5132. 'where' => 'rid=' . $roleId,
  5133. 'asArray' => true
  5134. ) );
  5135. }
  5136. if (! empty ( $verifyStaff ))
  5137. $endStaffArray = end ( $verifyStaff );
  5138. $KOP = false;
  5139. foreach ( $roleArrayCopy as $P => $A ) {
  5140. foreach ( $A as $MKI => $AVL ) {
  5141. if (! empty ( $verifyStaff )) {
  5142. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5143. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5144. $button = 4;
  5145. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5146. }
  5147. foreach ( $verifyStaff as $m => $u ) {
  5148. $AVLFK = $AVL [0] . '_R';
  5149. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5150. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5151. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5152. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5153. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5154. break;
  5155. }
  5156. }
  5157. } else {
  5158. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5159. $button = 4;
  5160. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5161. }
  5162. }
  5163. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5164. $KOP = true;
  5165. }
  5166. }
  5167. foreach ( $roleArrayCopy as $k => $v ) {
  5168. foreach ( $verifyList as $m => $n ) {
  5169. if ($n [0] == $k) {
  5170. array_splice ( $verifyList, $m, 1, $v );
  5171. }
  5172. }
  5173. }
  5174. $receiptList [$key] ['verifyList'] = $verifyList;
  5175. $receiptList [$key] ['executeList'] = $executeList;
  5176. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5177. 'where' => 'sid=' . $value ['staff'],
  5178. 'asArray' => true
  5179. ) );
  5180. $receiptList [$key] ['button2'] = $button2;
  5181. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5182. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5183. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5184. $receiptList [$key] ['relust'] = $relust;
  5185. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5186. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  5187. }
  5188. //执行人是否是最后一位
  5189. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  5190. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  5191. $executePrimary=count($executeCopy)-1;
  5192. $lastOne=true;
  5193. if($executePrimary!=count($executeStaff)){
  5194. $lastOne=false;
  5195. }
  5196. $data['lastOne']=$lastOne;
  5197. // 是否写入过流水
  5198. $accountType = 0;
  5199. if ($receiptList [0] ['Rtype'] == 0) {
  5200. $accountType = 3;
  5201. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5202. if (!empty($receiptList [0]['accountItem']) )
  5203. $accountType = 2;
  5204. else
  5205. $accountType = 1;
  5206. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5207. $accountType = 4;
  5208. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5209. $accountType = 12;
  5210. }
  5211. Doo::loadModel ( 'wasteBook' );
  5212. $wasteBook = new wasteBook ();
  5213. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5214. $data ['wbDetail'] = $wbDetail;
  5215. $wbDetailLoan=array();
  5216. if ($accountType==2){
  5217. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5218. }
  5219. $data ['wbDetailLoan'] = $wbDetailLoan;
  5220. $data['inputDate']=date ( "Y-m-d H:i:s" );
  5221. //print_r($wbDetail);
  5222. $data ['receiptList'] = $receiptList;
  5223. $data ['memu'] = "receipt";
  5224. $data ['staff'] = $this->staff;
  5225. $data ['receiptMemu'] = 'implement';
  5226. $data ['verifyId'] = $this->verifyId;
  5227. $data ['executeId'] = $this->executeId;
  5228. if ($Rtype=="loan"){
  5229. $this->render ( "/receipt/receiptImplementLoan", $data );
  5230. }elseif($Rtype=="receipt"){
  5231. $this->render ( "/receipt/receiptImplement", $data );
  5232. }elseif($Rtype=="public"){
  5233. $this->render ( "/receipt/receiptImplementPublic", $data );
  5234. }else{
  5235. //$this->render ( "/admin/implement", $data );
  5236. }
  5237. }
  5238. function implementDo() {
  5239. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  5240. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5241. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5242. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5243. // $ab = '';
  5244. // if ($accountBank == 'CGBDeposit')
  5245. // $ab = '纵横广发';
  5246. // elseif ($accountBank == 'ICBCDeposit')
  5247. // $ab = '纵横工行';
  5248. // elseif ($accountBank == 'HUADeposit')
  5249. // $ab = '华润银行';
  5250. // elseif ($accountBank == 'PersonalDeposit')
  5251. // $ab = '个人广发';
  5252. // if (empty ( $ab ))
  5253. // die ( 'illegal request--22' );
  5254. if (! empty ( $rid )) {
  5255. Doo::loadModel ( 'receipt' );
  5256. $receipt = new receipt ();
  5257. Doo::loadClass ( 'XDeode' );
  5258. $XDeode = new XDeode ( 5 );
  5259. $rid=$XDeode->decode($rid);
  5260. if (!is_numeric($rid)){
  5261. die;
  5262. }
  5263. // $rinfo = $receipt->getOne ( array (
  5264. // 'where' => 'rid=' . $rid,
  5265. // 'asArray' => true
  5266. // ) );
  5267. $rinfo = $receipt->getReceiptByRid ( $rid );
  5268. // $accountType = '';
  5269. // if ($rinfo ['Rtype'] == 1) {
  5270. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5271. // $accountType = 2;
  5272. // else
  5273. // $accountType = 1;
  5274. // } elseif ($rinfo ['Rtype'] == 2) {
  5275. // $accountType = 4;
  5276. // } elseif ($rinfo ['Rtype'] == 0)
  5277. // $accountType = 3;
  5278. // if (empty ( $accountType ))
  5279. // die ( 'illegal request' );
  5280. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5281. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5282. if (empty ( $executeStaff )) {
  5283. $executeStaff = array (
  5284. $this->staff [0] ['sid'] => array (
  5285. 'date' => date ( 'Y-m-d' ),
  5286. 'opinion' => $implementOpinions,
  5287. 'status' => 1
  5288. )
  5289. );
  5290. } else {
  5291. $executeStaff [$this->staff [0] ['sid']] = array (
  5292. 'date' => date ( 'Y-m-d' ),
  5293. 'opinion' => $implementOpinions,
  5294. 'status' => 1
  5295. );
  5296. }
  5297. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5298. $receipt->executeStaff = json_encode ( $executeStaff );
  5299. $receipt->status = 8;
  5300. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5301. $receipt->status = 9;
  5302. if ($rinfo ['status'] == 6) {
  5303. $receipt->loanDate = date ( "Y-m-d" );
  5304. }
  5305. $receipt->executeDate = date ( "Y-m-d" );
  5306. } else {
  5307. $receipt->executeStaff = json_encode ( $executeStaff );
  5308. }
  5309. //$receipt->amount = $amount;
  5310. $receipt->update ( array (
  5311. 'where' => 'rid=' . $rid
  5312. ) );
  5313. // 公司流水记录
  5314. // Doo::loadModel ( 'wasteBook' );
  5315. // $wasteBook = new wasteBook ();
  5316. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5317. // // 银行
  5318. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5319. // $item = array (
  5320. // 'dataID' => $rid,
  5321. // 'expensesType' => 2,
  5322. // 'accountType' => $accountType,
  5323. // 'accountPriceShow' => $amount,
  5324. // 'accountPrice' => - $amount,
  5325. // 'accountBank' => $accountBank,
  5326. // 'category' => $rinfo ['category'] [0] ['title'],
  5327. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5328. // 'name' => $rinfo ['staffDetail'] ['username'],
  5329. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5330. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5331. // );
  5332. // $wasteBook->setAccountBookStatistics ( $item );
  5333. // }
  5334. }
  5335. //$ridKey = $XDeode->encode ( $rid );
  5336. return "/hisImplement";
  5337. // return "/implement/" . $ridKey . ".html";
  5338. }
  5339. function receiptburEdi() {
  5340. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5341. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5342. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5343. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5344. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5345. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5346. if (empty ( $status ))
  5347. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5348. $vidList = array ();
  5349. $button = 0;
  5350. Doo::loadModel ( 'verify' );
  5351. Doo::loadModel ( 'receipt' );
  5352. Doo::loadModel ( 'staff' );
  5353. $staff = new staff ();
  5354. $receipt = new receipt ();
  5355. $verify = new verify ();
  5356. Doo::loadModel ( 'L_category' );
  5357. $Lcategory = new L_category ();
  5358. Doo::loadModel ( 'enclosur' );
  5359. $enclosur = new enclosur ();
  5360. Doo::loadModel ( 'loanReceipt' );
  5361. $loanReceipt = new loanReceipt ();
  5362. // user verify ID
  5363. $verifyDetail = $verify->find ( array (
  5364. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5365. 'asArray' => true
  5366. ) );
  5367. foreach ( $verifyDetail as $key => $value ) {
  5368. array_push ( $vidList, $value ['vid'] );
  5369. }
  5370. $vid = implode ( ",", $vidList );
  5371. if (empty ( $verifyDetail ))
  5372. $vid = 0;
  5373. $categoryList = $Lcategory->find ( array (
  5374. 'asArray' => true
  5375. ) );
  5376. $staffList = $staff->find ( array (
  5377. 'where' => 'cid=' . $cid,
  5378. 'asArray' => true
  5379. ) );
  5380. $ap = "";
  5381. if ($status == 4) {
  5382. $ap = 4;
  5383. $status = 2;
  5384. }
  5385. // get Receipt By verifyID status 2
  5386. $receiptList = $receipt->find ( array (
  5387. 'where' => 'rid =' . $rid . ' and status=2',
  5388. 'desc' => 'rid',
  5389. 'asArray' => true
  5390. ) );
  5391. if (empty ( $receiptList )) {
  5392. die ( 'illegal request' );
  5393. }
  5394. $loanList = $loanReceipt->find ( array (
  5395. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5396. 'desc' => 'rid',
  5397. 'asArray' => true
  5398. ) );
  5399. $data ['explanation'] = '';
  5400. if (! empty ( $loanList ))
  5401. $data ['explanation'] = $loanList [0] ['explanation'];
  5402. $Locate = 0;
  5403. $roleId = 0;
  5404. $button = 0;
  5405. foreach ( $loanList as $key => $value ) {
  5406. $loanList [$key] ['Locate'] = $Locate;
  5407. $Locate ++;
  5408. $loanList [$key] ['reviseDetail'] = array ();
  5409. if (! empty ( $value ['reviseDetail'] ))
  5410. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5411. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5412. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5413. $categoryDetil = $Lcategory->getOne ( array (
  5414. 'where' => 'cid=' . $value ['cid'],
  5415. 'asArray' => true
  5416. ) );
  5417. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5418. // 检测编辑状态
  5419. $verifyList = $verify->getOne ( array (
  5420. 'where' => 'vid=' . $value ['verify'],
  5421. 'asArray' => true
  5422. ) );
  5423. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5424. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5425. Doo::loadModel ( 'role' );
  5426. $role = new role ();
  5427. $flag = true;
  5428. $roleKey = 0;
  5429. $endStaffArray = array ();
  5430. $roleArrayCopy = array ();
  5431. foreach ( $verifyList as $k => $v ) {
  5432. // init verifyStaff
  5433. if ($v [1] == 'ROLE') {
  5434. if (! empty ( $verifyStaff )) {
  5435. $endStaffArray = end ( $verifyStaff );
  5436. }
  5437. $roleVerify = json_decode ( $v [3], true );
  5438. $roleKey = $k;
  5439. $roleArray = array ();
  5440. $rolename = $role->getOne ( array (
  5441. 'where' => 'rid=' . $v [0],
  5442. 'asArray' => true
  5443. ) );
  5444. foreach ( $roleVerify as $o => $p ) {
  5445. $staffID = explode ( '_', $p );
  5446. $staffInfo = $staff->getOne ( array (
  5447. 'where' => 'sid=' . $staffID [0],
  5448. 'asArray' => true
  5449. ) );
  5450. // print_r($staffID);
  5451. $exp = array (
  5452. 0 => $staffInfo ['sid'],
  5453. 1 => $staffID [1],
  5454. 2 => $staffInfo ['avatar'],
  5455. 'date' => '',
  5456. 'date' => '',
  5457. 'opinion' => '',
  5458. 'status' => '',
  5459. 'rolename' => $rolename ['name']
  5460. );
  5461. array_push ( $roleArray, $exp );
  5462. }
  5463. $roleArrayCopy [$v [0]] = $roleArray;
  5464. // $verifyList[$k]['roleArray']=$roleArray;
  5465. }
  5466. $verifyList [$k] ['date'] = "";
  5467. $verifyList [$k] ['opinion'] = "";
  5468. $verifyList [$k] ['status'] = "";
  5469. if (empty ( $verifyStaff )) {
  5470. $verifyList [$k] ['date'] = "";
  5471. $verifyList [$k] ['opinion'] = "";
  5472. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5473. $verifyList [$k] ['status'] = 4;
  5474. $flag = false;
  5475. }
  5476. } else {
  5477. foreach ( $verifyStaff as $m => $u ) {
  5478. if ($v [0] == $m) {
  5479. $verifyList [$k] ['date'] = $u ['date'];
  5480. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5481. $verifyList [$k] ['status'] = $u ['status'];
  5482. $flag = false;
  5483. break;
  5484. }
  5485. }
  5486. $endStaffArray = end ( $verifyStaff );
  5487. if (isset ( $endStaffArray ['ROLE'] )) {
  5488. } else {
  5489. }
  5490. }
  5491. }
  5492. $rolename ['name'] = '';
  5493. if (! empty ( $roleId )) {
  5494. Doo::loadModel ( 'role' );
  5495. $role = new role ();
  5496. $rolename = $role->getOne ( array (
  5497. 'where' => 'rid=' . $roleId,
  5498. 'asArray' => true
  5499. ) );
  5500. }
  5501. if (! empty ( $verifyStaff ))
  5502. $endStaffArray = end ( $verifyStaff );
  5503. $KOP = false;
  5504. foreach ( $roleArrayCopy as $P => $A ) {
  5505. foreach ( $A as $MKI => $AVL ) {
  5506. if (! empty ( $verifyStaff )) {
  5507. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5508. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5509. $button = 4;
  5510. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5511. }
  5512. foreach ( $verifyStaff as $m => $u ) {
  5513. $AVLFK = $AVL [0] . '_R';
  5514. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5515. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5516. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5517. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5518. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5519. break;
  5520. }
  5521. }
  5522. } else {
  5523. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5524. $button = 4;
  5525. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5526. }
  5527. }
  5528. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5529. $KOP = true;
  5530. }
  5531. }
  5532. foreach ( $roleArrayCopy as $k => $v ) {
  5533. foreach ( $verifyList as $m => $n ) {
  5534. if ($n [0] == $k) {
  5535. array_splice ( $verifyList, $m, 1, $v );
  5536. }
  5537. }
  5538. }
  5539. $loanList [$key] ['verifyList'] = $verifyList;
  5540. }
  5541. $htmlLoan = '';
  5542. $data ['loanReceiptDate'] = '';
  5543. if (isset ( $loanList [0] )) {
  5544. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5545. if ($value ['status'] == 1)
  5546. $htmlLoan .= '<li class="done" >';
  5547. elseif ($value ['status'] == 3)
  5548. $htmlLoan .= '<li class="undone" >';
  5549. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5550. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5551. if (isset ( $value ['rolename'] ))
  5552. $htmlLoan .= $value ['rolename'];
  5553. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5554. }
  5555. $data ['loanDate'] = $loanList [0] ['date'];
  5556. } else {
  5557. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5558. }
  5559. $data ['htmlLoan'] = $htmlLoan;
  5560. // $data ['LoanReceipt']=$loanList[0];
  5561. // print_r($loanList);
  5562. $Locate = 0;
  5563. $roleId = 0;
  5564. $button = 0;
  5565. if ($ap == 4)
  5566. $status = 4;
  5567. Doo::loadClass ( 'XDeode' );
  5568. $XDeode = new XDeode ( 5 );
  5569. foreach ( $receiptList as $key => $value ) {
  5570. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5571. $receiptList [$key] ['Locate'] = $Locate;
  5572. $Locate ++;
  5573. $receiptList [$key] ['reviseDetail'] = array ();
  5574. // 调整金额 代码调整
  5575. if (! empty ( $value ['reviseDetail'] )) {
  5576. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5577. foreach ( $reviseDetail as $ry => $re ) {
  5578. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5579. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5580. }
  5581. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5582. // print_r($reviseDetail);
  5583. }
  5584. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5585. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5586. $categoryDetil = $Lcategory->getOne ( array (
  5587. 'where' => 'cid=' . $value ['cid'],
  5588. 'asArray' => true
  5589. ) );
  5590. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5591. // 检测编辑状态
  5592. $verifyList = $verify->getOne ( array (
  5593. 'where' => 'vid=' . $value ['verify'],
  5594. 'asArray' => true
  5595. ) );
  5596. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5597. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5598. Doo::loadModel ( 'role' );
  5599. $role = new role ();
  5600. // print_r($verifyList);
  5601. $flag = true;
  5602. $roleKey = 0;
  5603. $endStaffArray = array ();
  5604. $roleArrayCopy = array ();
  5605. foreach ( $verifyList as $k => $v ) {
  5606. // init verifyStaff
  5607. if ($v [1] == 'ROLE') {
  5608. if (! empty ( $verifyStaff )) {
  5609. $endStaffArray = end ( $verifyStaff );
  5610. if ($v [0] == $endStaffArray ['nextStaff']) {
  5611. $roleId = $v [0];
  5612. }
  5613. }
  5614. $roleVerify = json_decode ( $v [3], true );
  5615. $roleKey = $k;
  5616. $roleArray = array ();
  5617. $rolename = $role->getOne ( array (
  5618. 'where' => 'rid=' . $v [0],
  5619. 'asArray' => true
  5620. ) );
  5621. foreach ( $roleVerify as $o => $p ) {
  5622. $staffID = explode ( '_', $p );
  5623. $staffInfo = $staff->getOne ( array (
  5624. 'where' => 'sid=' . $staffID [0],
  5625. 'asArray' => true
  5626. ) );
  5627. // print_r($staffID);
  5628. $exp = array (
  5629. 0 => $staffInfo ['sid'],
  5630. 1 => $staffID [1],
  5631. 2 => $staffInfo ['avatar'],
  5632. 'date' => '',
  5633. 'date' => '',
  5634. 'opinion' => '',
  5635. 'status' => '',
  5636. 'rolename' => $rolename ['name']
  5637. );
  5638. array_push ( $roleArray, $exp );
  5639. }
  5640. $roleArrayCopy [$v [0]] = $roleArray;
  5641. // $verifyList[$k]['roleArray']=$roleArray;
  5642. }
  5643. // print_r($roleArray);
  5644. $verifyList [$k] ['date'] = "";
  5645. $verifyList [$k] ['opinion'] = "";
  5646. $verifyList [$k] ['status'] = "";
  5647. if (empty ( $verifyStaff )) {
  5648. $verifyList [$k] ['date'] = "";
  5649. $verifyList [$k] ['opinion'] = "";
  5650. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5651. $verifyList [$k] ['status'] = 4;
  5652. $button = 4;
  5653. $flag = false;
  5654. }
  5655. } else {
  5656. foreach ( $verifyStaff as $m => $u ) {
  5657. if ($v [0] == $m) {
  5658. $verifyList [$k] ['date'] = $u ['date'];
  5659. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5660. $verifyList [$k] ['status'] = $u ['status'];
  5661. $flag = false;
  5662. break;
  5663. }
  5664. }
  5665. $endStaffArray = end ( $verifyStaff );
  5666. if (isset ( $endStaffArray ['ROLE'] )) {
  5667. } else {
  5668. $endKey = key ( $verifyStaff );
  5669. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5670. $button = 4;
  5671. $verifyList [$k] ['status'] = 4;
  5672. }
  5673. }
  5674. }
  5675. }
  5676. $rolename ['name'] = '';
  5677. if (! empty ( $roleId )) {
  5678. Doo::loadModel ( 'role' );
  5679. $role = new role ();
  5680. $rolename = $role->getOne ( array (
  5681. 'where' => 'rid=' . $roleId,
  5682. 'asArray' => true
  5683. ) );
  5684. }
  5685. if (! empty ( $verifyStaff ))
  5686. $endStaffArray = end ( $verifyStaff );
  5687. $KOP = false;
  5688. foreach ( $roleArrayCopy as $P => $A ) {
  5689. foreach ( $A as $MKI => $AVL ) {
  5690. if (! empty ( $verifyStaff )) {
  5691. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5692. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5693. $button = 4;
  5694. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5695. }
  5696. foreach ( $verifyStaff as $m => $u ) {
  5697. $AVLFK = $AVL [0] . '_R';
  5698. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5699. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5700. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5701. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5702. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5703. break;
  5704. }
  5705. }
  5706. } else {
  5707. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5708. $button = 4;
  5709. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5710. }
  5711. }
  5712. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5713. $KOP = true;
  5714. }
  5715. }
  5716. foreach ( $roleArrayCopy as $k => $v ) {
  5717. foreach ( $verifyList as $m => $n ) {
  5718. if ($n [0] == $k) {
  5719. array_splice ( $verifyList, $m, 1, $v );
  5720. }
  5721. }
  5722. }
  5723. // print_r($verifyList);
  5724. $receiptList [$key] ['verifyList'] = $verifyList;
  5725. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5726. 'where' => 'sid=' . $value ['staff'],
  5727. 'asArray' => true
  5728. ) );
  5729. $receiptList [$key] ['button'] = $button;
  5730. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5731. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5732. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5733. $receiptList [$key] ['relust'] = $relust;
  5734. $receiptList [$key] ['relustABS'] = abs ( $relust );
  5735. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5736. }
  5737. //print_r($receiptList);die;
  5738. // $data['verifyDetail']=$verifyDetail;
  5739. $mothHtml = "";
  5740. for($i = 1; $i <= 12; $i ++) {
  5741. if ($month == $i)
  5742. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5743. else
  5744. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5745. }
  5746. // 获取审批日志
  5747. Doo::loadModel ( 'receiptLog' );
  5748. $receiptLog = new receiptLog ();
  5749. $rlList = array ();
  5750. $rlInfo = $receiptLog->getOne ( array (
  5751. 'where' => 'rid=' . $rid . ' and status=4',
  5752. 'asArray' => true
  5753. ) );
  5754. $tijdate = $receiptLog->getOne ( array (
  5755. 'where' => 'rid=' . $rid . ' and status=2',
  5756. 'asc' => 'rlid',
  5757. 'asArray' => true
  5758. ) );
  5759. if (! empty ( $rlInfo )) {
  5760. $rlList = $receiptLog->find ( array (
  5761. 'where' => 'rid=' . $rid,
  5762. 'asc' => 'rlid',
  5763. 'asArray' => true
  5764. ) );
  5765. }
  5766. // echo $rid;
  5767. // print_r($receiptList);
  5768. $receiptList [0] ['rlList'] = $rlList;
  5769. // print_r($receiptList);
  5770. $enclosurList = $enclosur->find ( array (
  5771. 'where' => 'rid=' . $rid,
  5772. 'asArray' => true
  5773. ) );
  5774. $enclosurHtml = '';
  5775. foreach ( $enclosurList as $value ) {
  5776. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5777. }
  5778. $data ['enclosurHtml'] = $enclosurHtml;
  5779. $data ['rolename'] = $rolename ['name'];
  5780. $data ['mothHtml'] = $mothHtml;
  5781. // print_r($receiptList);
  5782. $data ['rid'] = $rid;
  5783. $data ['tijdate'] = $tijdate ['date'];
  5784. $data ['receiptList'] = $receiptList;
  5785. $data ['receiptApprovalCount'] = count ( $receiptList );
  5786. $data ['status'] = $status;
  5787. $data ['year'] = $year;
  5788. $data ['categoryList'] = $categoryList;
  5789. $data ['staffList'] = $staffList;
  5790. $data ['cid'] = $cid;
  5791. $data ['sid'] = $sid;
  5792. $data ['ap'] = $ap;
  5793. $data ['memu'] = "receipt";
  5794. $data ['staff'] = $this->staff;
  5795. $data ['receiptMemu'] = 'approvalExpenses';
  5796. $data ['verifyId'] = $this->verifyId;
  5797. $data ['executeId'] = $this->executeId;
  5798. $this->render ( "/admin/receiptburEdi", $data );
  5799. }
  5800. function hisImplement() {
  5801. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5802. if (empty ( $item ))
  5803. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5804. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5805. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5806. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5807. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5808. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5809. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5810. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5811. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5812. Doo::loadClass ( 'XDeode' );
  5813. $XDeode = new XDeode ( 5 );
  5814. Doo::loadModel ( 'receipt' );
  5815. $receipt = new receipt ();
  5816. Doo::loadModel ( 'L_category' );
  5817. $Lcategory = new L_category ();
  5818. Doo::loadModel ( 'verify' );
  5819. Doo::loadModel ( 'statistics' );
  5820. $statistics = new statistics ();
  5821. $verify = new verify ();
  5822. Doo::loadModel ( 'staff' );
  5823. $staff = new staff ();
  5824. Doo::loadClass ( 'XDeode' );
  5825. $XDeode = new XDeode ( 5 );
  5826. $XDeode7 = new XDeode ( 7 );
  5827. $cid = $XDeode->decode ( $cidKey );
  5828. $condition = "";
  5829. if ($item == "expenses")
  5830. $condition = " and Rtype=1 ";
  5831. elseif ($item == "receipts")
  5832. $condition = " and Rtype=0 ";
  5833. elseif ($item == "remits")
  5834. $condition = " and Rtype=2 ";
  5835. elseif($item == "train")
  5836. $condition = " and Rtype=3 ";
  5837. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5838. $sopString = $cidString = "";
  5839. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5840. if (empty ( $rdate ))
  5841. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5842. else
  5843. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5844. if ($status == 'pendImplement') {
  5845. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5846. } elseif ($status == 'alerpts') {
  5847. $statusCon = '(status=8 or status=9 )';
  5848. if (empty ( $rdate ))
  5849. $dateCondition .= " and Year(date) =" . $year;
  5850. else
  5851. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5852. }
  5853. if ($sop != 'SOP')
  5854. $sopString = " and staff=" . $sop;
  5855. if ($cidKey != 'ALL')
  5856. $cidString = " and cid=" . $cid;
  5857. //汇款信息需要提取出来
  5858. if(!empty($receiptOrder)){
  5859. $receiptList = $receipt->find ( array (
  5860. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5861. 'desc' => 'rid',
  5862. 'asArray' => true
  5863. ) );
  5864. // 员工筛选
  5865. $receiptList2 = $receipt->find ( array (
  5866. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5867. 'desc' => 'rid',
  5868. 'asArray' => true
  5869. ) );
  5870. }else{
  5871. $receiptList = $receipt->find ( array (
  5872. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5873. 'desc' => 'rid',
  5874. 'asArray' => true
  5875. ) );
  5876. // 员工筛选
  5877. $receiptList2 = $receipt->find ( array (
  5878. 'where' => $statusCon . $condition . $dateCondition,
  5879. 'desc' => 'rid',
  5880. 'asArray' => true
  5881. ) );
  5882. }
  5883. $sopStaff = array ();
  5884. foreach ( $receiptList2 as $key => $value ) {
  5885. $staffDetail = $staff->getOne ( array (
  5886. 'select' => 'username',
  5887. 'where' => 'sid=' . $value ['staff'],
  5888. 'asArray' => true
  5889. ) );
  5890. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5891. }
  5892. // 办事处筛选
  5893. $categoryScreen = array ();
  5894. $categorList = $Lcategory->getCategory ();
  5895. foreach ( $receiptList2 as $key => $value ) {
  5896. foreach ( $categorList as $k => $v ) {
  5897. if ($value ['cid'] == $v ['cid']) {
  5898. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5899. break;
  5900. }
  5901. }
  5902. }
  5903. $categoryScreenHtml = "";
  5904. foreach ( $categoryScreen as $key => $value ) {
  5905. if ($cidKey == $key)
  5906. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5907. else
  5908. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5909. }
  5910. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5911. $data ['cidKey'] = $cidKey;
  5912. $Locate = 0;
  5913. $roleId = 0;
  5914. $button = 0;
  5915. $staffBatchNumber = 100001;
  5916. $remittanceList = array ();
  5917. foreach ( $receiptList as $key => $value ) {
  5918. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5919. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5920. $receiptList [$key] ['Texe'] = 'false';
  5921. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5922. $receiptList [$key] ['Texe'] = 'true';
  5923. }
  5924. $receiptList [$key] ['TRexe'] = 'true';
  5925. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5926. $receiptList [$key] ['TRexe'] = 'false';
  5927. }
  5928. $receiptList [$key] ['Locate'] = $Locate;
  5929. $Locate ++;
  5930. $receiptList [$key] ['reviseDetail'] = array ();
  5931. if (! empty ( $value ['reviseDetail'] ))
  5932. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5933. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5934. $categoryDetil = $Lcategory->getOne ( array (
  5935. 'where' => 'cid=' . $value ['cid'],
  5936. 'asArray' => true
  5937. ) );
  5938. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5939. // 检测编辑状态
  5940. $verifyList = $verify->getOne ( array (
  5941. 'where' => 'vid=' . $value ['verify'],
  5942. 'asArray' => true
  5943. ) );
  5944. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5945. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5946. Doo::loadModel ( 'role' );
  5947. $role = new role ();
  5948. $flag = true;
  5949. $roleKey = 0;
  5950. $endStaffArray = array ();
  5951. $roleArrayCopy = array ();
  5952. foreach ( $verifyList as $k => $v ) {
  5953. // init verifyStaff
  5954. if ($v [1] == 'ROLE') {
  5955. if (! empty ( $verifyStaff )) {
  5956. $endStaffArray = end ( $verifyStaff );
  5957. }
  5958. $roleVerify = json_decode ( $v [3], true );
  5959. $roleKey = $k;
  5960. $roleArray = array ();
  5961. $rolename = $role->getOne ( array (
  5962. 'where' => 'rid=' . $v [0],
  5963. 'asArray' => true
  5964. ) );
  5965. foreach ( $roleVerify as $o => $p ) {
  5966. $staffID = explode ( '_', $p );
  5967. $staffInfo = $staff->getOne ( array (
  5968. 'where' => 'sid=' . $staffID [0],
  5969. 'asArray' => true
  5970. ) );
  5971. $exp = array (
  5972. 0 => $staffInfo ['sid'],
  5973. 1 => $staffID [1],
  5974. 2 => $staffInfo ['avatar'],
  5975. 'date' => '',
  5976. 'date' => '',
  5977. 'opinion' => '',
  5978. 'status' => '',
  5979. 'rolename' => $rolename ['name']
  5980. );
  5981. array_push ( $roleArray, $exp );
  5982. }
  5983. $roleArrayCopy [$v [0]] = $roleArray;
  5984. }
  5985. $verifyList [$k] ['date'] = "";
  5986. $verifyList [$k] ['opinion'] = "";
  5987. $verifyList [$k] ['status'] = "";
  5988. if (empty ( $verifyStaff )) {
  5989. $verifyList [$k] ['date'] = "";
  5990. $verifyList [$k] ['opinion'] = "";
  5991. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5992. $verifyList [$k] ['status'] = 4;
  5993. $flag = false;
  5994. }
  5995. } else {
  5996. foreach ( $verifyStaff as $m => $u ) {
  5997. if ($v [0] == $m) {
  5998. $verifyList [$k] ['date'] = $u ['date'];
  5999. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6000. $verifyList [$k] ['status'] = $u ['status'];
  6001. $flag = false;
  6002. break;
  6003. }
  6004. }
  6005. $endStaffArray = end ( $verifyStaff );
  6006. }
  6007. }
  6008. $rolename ['name'] = '';
  6009. if (! empty ( $roleId )) {
  6010. Doo::loadModel ( 'role' );
  6011. $role = new role ();
  6012. $rolename = $role->getOne ( array (
  6013. 'where' => 'rid=' . $roleId,
  6014. 'asArray' => true
  6015. ) );
  6016. }
  6017. if (! empty ( $verifyStaff ))
  6018. $endStaffArray = end ( $verifyStaff );
  6019. $KOP = false;
  6020. foreach ( $roleArrayCopy as $P => $A ) {
  6021. foreach ( $A as $MKI => $AVL ) {
  6022. if (! empty ( $verifyStaff )) {
  6023. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6024. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6025. $button = 4;
  6026. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6027. }
  6028. foreach ( $verifyStaff as $m => $u ) {
  6029. $AVLFK = $AVL [0] . '_R';
  6030. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6031. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6032. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6033. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6034. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6035. break;
  6036. }
  6037. }
  6038. } else {
  6039. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6040. $button = 4;
  6041. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6042. }
  6043. }
  6044. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6045. $KOP = true;
  6046. }
  6047. }
  6048. foreach ( $roleArrayCopy as $k => $v ) {
  6049. foreach ( $verifyList as $m => $n ) {
  6050. if ($n [0] == $k) {
  6051. array_splice ( $verifyList, $m, 1, $v );
  6052. }
  6053. }
  6054. }
  6055. $receiptList [$key] ['verifyList'] = $verifyList;
  6056. $staffDetail = $staff->getOne ( array (
  6057. 'where' => 'sid=' . $value ['staff'],
  6058. 'asArray' => true
  6059. ) );
  6060. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6061. $receiptList [$key] ['button'] = $button;
  6062. if ($value['Rtype']==1){
  6063. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  6064. $receiptList [$key] ['relustABS'] = abs($receiptList [$key] ['relust']);
  6065. }elseif($value['Rtype']==3){
  6066. // 收入合计
  6067. Doo::loadModel ( 'invoiceTraining' );
  6068. $invoiceTraining = new invoiceTraining ();
  6069. $invoiceTrainingDetail = array (
  6070. 'invoiceArriveAmount' => '0.00',
  6071. 'RIAmount' => '0.00',
  6072. 'invoiceTotalAmount' => '0.00',
  6073. 'invoiceCompanyAmount' => '0.00',
  6074. 'invoiceArriveAmountM'=>'0.00',
  6075. 'invoiceCompanyAmountM'=>'0.00'
  6076. );
  6077. if ($value ['invoiceTrainId'] != 0) {
  6078. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  6079. }
  6080. $invoiceArriveAmount = $RIAmount = 0;
  6081. if (! empty ( $invoiceTrainingDetail )) {
  6082. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  6083. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  6084. }
  6085. // 备用金
  6086. $sum = 0;
  6087. if (! empty ( $value ['trainLoanRid'] )) {
  6088. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  6089. foreach ($receiptLoanList as $kll=>$vll){
  6090. $sum+=$vll['sum'];
  6091. }
  6092. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  6093. // $sum = $receiptLoanDetailBak ['sum'];
  6094. }
  6095. // 支出项金额详情
  6096. // 项目金额合计
  6097. Doo::loadModel ( 'RItem' );
  6098. $RItem = new RItem ();
  6099. Doo::loadModel ( 'accountItem' );
  6100. $accountItem = new accountItem ();
  6101. // 讲师获得
  6102. Doo::loadModel ( 'RILecturer' );
  6103. $RILecturer = new RILecturer ();
  6104. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  6105. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  6106. // 支出项金额详情
  6107. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  6108. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  6109. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  6110. $receiptList [$key] ['payment'] =$payment;
  6111. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  6112. }
  6113. // 设置导出汇款execl
  6114. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6115. $remittanceDetail = array (
  6116. $staffBatchNumber,
  6117. $value ['remittanceName'],
  6118. $value ['bankNumber'],
  6119. $value ['bankName'],
  6120. $value ['remittanceBankType'],
  6121. $value ['coupletNumber'],
  6122. $value ['sum']
  6123. );
  6124. array_push ( $remittanceList, $remittanceDetail );
  6125. $staffBatchNumber ++;
  6126. }
  6127. }
  6128. $data ['remittanceList'] = json_encode ( $remittanceList );
  6129. // print_r($receiptList);
  6130. $mothHtml = "";
  6131. for($i = 1; $i <= 12; $i ++) {
  6132. if ($moth == $i)
  6133. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6134. else
  6135. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6136. }
  6137. $dayHtml = "";
  6138. if ($day != "DAY" || $moth != "MONTH") {
  6139. for($i = 1; $i <= 31; $i ++) {
  6140. if ($day == $i)
  6141. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6142. else
  6143. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6144. }
  6145. }
  6146. $sopHtml = "";
  6147. foreach ( $sopStaff as $key => $value ) {
  6148. if ($sop == $key)
  6149. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6150. else
  6151. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6152. }
  6153. $data ['status'] = $status;
  6154. $data ['rdate'] = $rdate;
  6155. $data ['sopHtml'] = $sopHtml;
  6156. $data ['dayHtml'] = $dayHtml;
  6157. $data ['mothHtml'] = $mothHtml;
  6158. $data ['receiptList'] = $receiptList;
  6159. $data ['memu'] = "receipt";
  6160. $data ['staff'] = $this->staff;
  6161. $data ['receiptMemu'] = 'implement';
  6162. $data ['verifyId'] = $this->verifyId;
  6163. $data ['executeId'] = $this->executeId;
  6164. $data ['item'] = $item;
  6165. $data ['year'] = $year;
  6166. $data ['moth'] = $moth;
  6167. $data['receiptOrder']=$receiptOrder;
  6168. $data ['day'] = $day;
  6169. $data ['sop'] = $sop;
  6170. $this->render ( "/admin/hisImplement", $data );
  6171. }
  6172. /**
  6173. * 导出汇款信息的exelc
  6174. */
  6175. function exportRemittance() {
  6176. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6177. if (empty ( $remittanceInfo ))
  6178. die ( 'illegal request' );
  6179. $title = array (
  6180. '员工编号',
  6181. '姓名',
  6182. '员工账号',
  6183. '员工账户开户行',
  6184. '转账类型',
  6185. '联行号',
  6186. '金额'
  6187. );
  6188. $data = json_decode ( $remittanceInfo, true );
  6189. if (empty ( $data ))
  6190. die ( 'illegal request' );
  6191. Doo::loadClass ( 'receipt.func' );
  6192. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6193. header ( 'Content-Type:text/html;charset=utf-8' );
  6194. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6195. }
  6196. function ajaxExamine() {
  6197. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6198. Doo::loadModel ( 'receipt' );
  6199. $receipt = new receipt ();
  6200. if (! empty ( $rid )) {
  6201. $rLRes = $receipt->find ( array (
  6202. '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,
  6203. 'asArray' => true
  6204. ) );
  6205. echo json_encode ( array (
  6206. 'status' => 1,
  6207. 'receipt' => $rLRes [0]
  6208. ) );
  6209. die ();
  6210. }
  6211. echo json_encode ( array (
  6212. 'status' => 0,
  6213. 'receipt' => array ()
  6214. ) );
  6215. die ();
  6216. }
  6217. /*
  6218. * 废弃
  6219. */
  6220. function myReceipt() {
  6221. // all approval past withdraw
  6222. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6223. if (empty ( $item ))
  6224. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6225. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6226. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6227. Doo::loadModel ( 'receipt' );
  6228. $receipt = new receipt ();
  6229. // pre-loaded
  6230. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6231. // have cache
  6232. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6233. if (! empty ( $moth )) // yearPage
  6234. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6235. $this->showCache ( $path );
  6236. }
  6237. Doo::loadModel ( 'L_category' );
  6238. $Lcategory = new L_category ();
  6239. Doo::loadModel ( 'verify' );
  6240. Doo::loadModel ( 'statistics' );
  6241. $statistics = new statistics ();
  6242. $verify = new verify ();
  6243. Doo::loadModel ( 'staff' );
  6244. $staff = new staff ();
  6245. $condition = " and status!=0 ";
  6246. if ($item == "approval")
  6247. $condition = " and status=2 ";
  6248. elseif ($item == "withdraw")
  6249. $condition = " and status=3 ";
  6250. elseif ($item == "past")
  6251. $condition = " and status=1 ";
  6252. elseif ($item == "whdw")
  6253. $condition = " and status=4 ";
  6254. $dateCondition = " and Year(date) =" . $year;
  6255. if (! empty ( $moth )) {
  6256. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6257. $stList = $statistics->getOne ( array (
  6258. 'select' => 'rePrice ,agPrice',
  6259. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6260. 'asArray' => true
  6261. ) );
  6262. } else
  6263. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6264. if (empty ( $stList ))
  6265. $stList = array (
  6266. 'rePrice' => 0,
  6267. 'agPrice' => 0
  6268. );
  6269. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6270. $data ['stList'] = array (
  6271. 'rePrice' => $stList ['rePrice'],
  6272. 'agPrice' => $stList ['agPrice'],
  6273. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6274. );
  6275. $receiptList = $receipt->find ( array (
  6276. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6277. 'desc' => 'rid',
  6278. 'asArray' => true
  6279. ) );
  6280. $Locate = 0;
  6281. $roleId = 0;
  6282. $button = 0;
  6283. foreach ( $receiptList as $key => $value ) {
  6284. $receiptList [$key] ['Locate'] = $Locate;
  6285. $Locate ++;
  6286. $receiptList [$key] ['reviseDetail'] = array ();
  6287. if (! empty ( $value ['reviseDetail'] ))
  6288. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6289. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6290. $categoryDetil = $Lcategory->getOne ( array (
  6291. 'where' => 'cid=' . $value ['cid'],
  6292. 'asArray' => true
  6293. ) );
  6294. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6295. // 检测编辑状态
  6296. $verifyList = $verify->getOne ( array (
  6297. 'where' => 'vid=' . $value ['verify'],
  6298. 'asArray' => true
  6299. ) );
  6300. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6301. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6302. Doo::loadModel ( 'role' );
  6303. $role = new role ();
  6304. $flag = true;
  6305. $roleKey = 0;
  6306. $endStaffArray = array ();
  6307. $roleArrayCopy = array ();
  6308. foreach ( $verifyList as $k => $v ) {
  6309. // init verifyStaff
  6310. if ($v [1] == 'ROLE') {
  6311. if (! empty ( $verifyStaff )) {
  6312. $endStaffArray = end ( $verifyStaff );
  6313. // if ($v[0]==$endStaffArray['nextStaff']){
  6314. // $roleId=$v[0];
  6315. // }
  6316. }
  6317. $roleVerify = json_decode ( $v [3], true );
  6318. $roleKey = $k;
  6319. $roleArray = array ();
  6320. $rolename = $role->getOne ( array (
  6321. 'where' => 'rid=' . $v [0],
  6322. 'asArray' => true
  6323. ) );
  6324. foreach ( $roleVerify as $o => $p ) {
  6325. $staffID = explode ( '_', $p );
  6326. $staffInfo = $staff->getOne ( array (
  6327. 'where' => 'sid=' . $staffID [0],
  6328. 'asArray' => true
  6329. ) );
  6330. // print_r($staffID);
  6331. $exp = array (
  6332. 0 => $staffInfo ['sid'],
  6333. 1 => $staffID [1],
  6334. 2 => $staffInfo ['avatar'],
  6335. 'date' => '',
  6336. 'date' => '',
  6337. 'opinion' => '',
  6338. 'status' => '',
  6339. 'rolename' => $rolename ['name']
  6340. );
  6341. array_push ( $roleArray, $exp );
  6342. }
  6343. $roleArrayCopy [$v [0]] = $roleArray;
  6344. // $verifyList[$k]['roleArray']=$roleArray;
  6345. }
  6346. $verifyList [$k] ['date'] = "";
  6347. $verifyList [$k] ['opinion'] = "";
  6348. $verifyList [$k] ['status'] = "";
  6349. if (empty ( $verifyStaff )) {
  6350. $verifyList [$k] ['date'] = "";
  6351. $verifyList [$k] ['opinion'] = "";
  6352. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6353. $verifyList [$k] ['status'] = 4;
  6354. $flag = false;
  6355. }
  6356. } else {
  6357. foreach ( $verifyStaff as $m => $u ) {
  6358. if ($v [0] == $m) {
  6359. $verifyList [$k] ['date'] = $u ['date'];
  6360. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6361. $verifyList [$k] ['status'] = $u ['status'];
  6362. $flag = false;
  6363. break;
  6364. }
  6365. }
  6366. $endStaffArray = end ( $verifyStaff );
  6367. if (isset ( $endStaffArray ['ROLE'] )) {
  6368. } else {
  6369. // $endKey=key($verifyStaff);
  6370. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6371. // $button=4;
  6372. // $verifyList[$k]['status']=4;
  6373. // }
  6374. }
  6375. }
  6376. }
  6377. $rolename ['name'] = '';
  6378. if (! empty ( $roleId )) {
  6379. Doo::loadModel ( 'role' );
  6380. $role = new role ();
  6381. $rolename = $role->getOne ( array (
  6382. 'where' => 'rid=' . $roleId,
  6383. 'asArray' => true
  6384. ) );
  6385. }
  6386. if (! empty ( $verifyStaff ))
  6387. $endStaffArray = end ( $verifyStaff );
  6388. $KOP = false;
  6389. foreach ( $roleArrayCopy as $P => $A ) {
  6390. foreach ( $A as $MKI => $AVL ) {
  6391. if (! empty ( $verifyStaff )) {
  6392. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6393. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6394. $button = 4;
  6395. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6396. }
  6397. foreach ( $verifyStaff as $m => $u ) {
  6398. $AVLFK = $AVL [0] . '_R';
  6399. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6400. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6401. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6402. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6403. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6404. break;
  6405. }
  6406. }
  6407. } else {
  6408. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6409. $button = 4;
  6410. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6411. }
  6412. }
  6413. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6414. $KOP = true;
  6415. }
  6416. }
  6417. foreach ( $roleArrayCopy as $k => $v ) {
  6418. foreach ( $verifyList as $m => $n ) {
  6419. if ($n [0] == $k) {
  6420. array_splice ( $verifyList, $m, 1, $v );
  6421. }
  6422. }
  6423. }
  6424. $receiptList [$key] ['verifyList'] = $verifyList;
  6425. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6426. 'where' => 'sid=' . $value ['staff'],
  6427. 'asArray' => true
  6428. ) );
  6429. $receiptList [$key] ['button'] = $button;
  6430. }
  6431. // print_r($receiptList);die;
  6432. $mothHtml = "";
  6433. for($i = 1; $i <= 12; $i ++) {
  6434. if ($moth == $i)
  6435. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6436. else
  6437. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6438. }
  6439. $data ['mothHtml'] = $mothHtml;
  6440. $data ['receiptList'] = $receiptList;
  6441. $data ['memu'] = "receipt";
  6442. $data ['staff'] = $this->staff;
  6443. $data ['receiptMemu'] = 'receipt';
  6444. $data ['verifyId'] = $this->verifyId;
  6445. $data ['executeId'] = $this->executeId;
  6446. $data ['item'] = $item;
  6447. $data ['year'] = $year;
  6448. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6449. // sufficient condition to generate cache
  6450. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6451. $receiptList = $receipt->find ( array (
  6452. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6453. 'asArray' => true
  6454. ) );
  6455. if (empty ( $receiptList )) { // generated files
  6456. ob_start ();
  6457. $this->render ( "/admin/saea_myList", $data );
  6458. $this->cacheFile ( $path );
  6459. die ();
  6460. // $content = ob_get_contents();
  6461. // $fp = fopen($path, "w");
  6462. // fwrite($fp, $content);
  6463. // fclose($fp);
  6464. }
  6465. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6466. $receiptList = $receipt->find ( array (
  6467. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6468. 'asArray' => true
  6469. ) );
  6470. if (empty ( $receiptList )) { // generated files
  6471. ob_start ();
  6472. $this->render ( "/admin/saea_myList", $data );
  6473. $this->cacheFile ( $path );
  6474. die ();
  6475. }
  6476. }
  6477. }
  6478. $this->render ( "/admin/saea_myList", $data );
  6479. }
  6480. function saeaCreate() {
  6481. Doo::loadModel ( 'accountItem' );
  6482. Doo::loadModel ( 'verify' );
  6483. Doo::loadModel ( 'receipt' );
  6484. Doo::loadModel ( 'L_category' );
  6485. $lCategory = new L_category ();
  6486. $receipt = new receipt ();
  6487. $verify = new verify ();
  6488. $accountItem = new accountItem ();
  6489. Doo::loadModel ( "role" );
  6490. $role = new role ();
  6491. $acItem = $accountItem->find ( array (
  6492. 'asArray' => true
  6493. ) );
  6494. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6495. $data ['category'] = $lCategory->find ( array (
  6496. 'asArray' => true
  6497. ) );
  6498. $data ['veList'] = $veList;
  6499. $data ['acItem'] = $acItem;
  6500. $data ['memu'] = "receipt";
  6501. $data ['staff'] = $this->staff;
  6502. $data ['receiptMemu'] = 'saeaBorad';
  6503. $data ['verifyId'] = $this->verifyId;
  6504. $data ['executeId'] = $this->executeId;
  6505. $this->render ( "/admin/saea_create", $data );
  6506. }
  6507. function addReceipt() {
  6508. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6509. $agency = $this->get_args ( 'agency' );
  6510. $travel = $this->get_args ( 'travel' );
  6511. $train = $this->get_args ( 'train' );
  6512. $other = $this->get_args ( 'other' );
  6513. $inttrain = $this->get_args ( 'inttrain' );
  6514. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6515. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6516. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6517. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6518. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6519. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6520. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6521. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6522. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6523. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6524. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6525. header ( 'Content-Type:text/html;charset=utf-8' );
  6526. die ( '请填写联行号' );
  6527. }
  6528. Doo::loadModel ( 'receipt' );
  6529. Doo::loadModel ( 'receiptDetail' );
  6530. Doo::loadModel ( 'accountItem' );
  6531. $accountItem = new accountItem ();
  6532. $receipt = new receipt ();
  6533. Doo::loadModel ( 'enclosur' );
  6534. Doo::loadModel ( 'execute' );
  6535. $execute = new execute ();
  6536. $executeDetail = $execute->getOne ( array (
  6537. 'where' => 'mold="报销单执行人"',
  6538. 'asArray' => true
  6539. ) );
  6540. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6541. // if(!empty($receiptDetail))
  6542. // return "/referReceipt/".$receiptDetail['rid'];
  6543. $aItem = $accountItem->find ( array (
  6544. 'asArray' => true
  6545. ) );
  6546. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6547. $ag = $tr = $ta = $ot= $it = 0;
  6548. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6549. foreach ( $aItem as $key => $value ) {
  6550. if ($value ['category'] == $this->AGENCY) {
  6551. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6552. array_push ( $accountJson [$this->AGENCY], array (
  6553. 'aid' => $value ['aid'],
  6554. 'name' => $value ['name'],
  6555. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6556. ) );
  6557. $sum += $agency [$ag];
  6558. $agencySum += $agency [$ag];
  6559. }
  6560. $ag ++;
  6561. }
  6562. if ($value ['category'] == $this->TRAVEL) {
  6563. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6564. array_push ( $accountJson [$this->TRAVEL], array (
  6565. 'aid' => $value ['aid'],
  6566. 'name' => $value ['name'],
  6567. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6568. ) );
  6569. $sum += $travel [$tr];
  6570. $travelSum += $travel [$tr];
  6571. }
  6572. $tr ++;
  6573. }
  6574. if ($value ['category'] == $this->TRAIN) {
  6575. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6576. array_push ( $accountJson [$this->TRAIN], array (
  6577. 'aid' => $value ['aid'],
  6578. 'name' => $value ['name'],
  6579. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6580. ) );
  6581. $sum += $train [$ta];
  6582. $trainSum += $train [$ta];
  6583. }
  6584. $ta ++;
  6585. }
  6586. if ($value ['category'] == $this->INTTRAIN) {
  6587. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6588. array_push ( $accountJson [$this->INTTRAIN], array (
  6589. 'aid' => $value ['aid'],
  6590. 'name' => $value ['name'],
  6591. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6592. ) );
  6593. $sum += $inttrain [$it];
  6594. $inttrainSum += $inttrain [$it];
  6595. }
  6596. $it ++;
  6597. }
  6598. if ($value ['category'] == $this->OTHER) {
  6599. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6600. array_push ( $accountJson [$this->OTHER], array (
  6601. 'aid' => $value ['aid'],
  6602. 'name' => $value ['name'],
  6603. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6604. ) );
  6605. $sum += $other [$ot];
  6606. $otherSum += $other [$ot];
  6607. }
  6608. $ot ++;
  6609. }
  6610. }
  6611. $accountJson ['cSum'] = array (
  6612. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6613. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6614. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6615. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6616. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6617. );
  6618. // 报销单
  6619. $receipt->accountItem = json_encode ( $accountJson );
  6620. $receipt->staff = $this->staff [0] ['sid'];
  6621. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6622. $receipt->date = date ( "Y-m-d" );
  6623. $receipt->cid = $cid;
  6624. $receipt->status = 5;
  6625. // 修改审批流程加入角色
  6626. $receipt->verify = $verify;
  6627. $receipt->executeCopy = $executeDetail ['staff'];
  6628. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6629. $order = array (
  6630. "\r\n",
  6631. "\n",
  6632. "\r"
  6633. );
  6634. $replace = '<br/>';
  6635. $explanation = str_replace ( $order, $replace, $explanation );
  6636. $receipt->explanation = $explanation;
  6637. $receipt->remittanceName = $remittanceName;
  6638. $receipt->bankName = $bankName;
  6639. $receipt->bankNumber = $bankNumber;
  6640. $receipt->remittanceBankType = $remittanceBankType;
  6641. if ($remittanceBankType == 1)
  6642. $receipt->coupletNumber = $coupletNumber;
  6643. $rid = $receipt->insert ();
  6644. // 附件
  6645. if (! empty ( $enclosurName )) {
  6646. $enclosurArray = explode ( '-', $enclosurName );
  6647. foreach ( $enclosurArray as $value ) {
  6648. $enclosur = new enclosur ();
  6649. $enclosur->name = $value;
  6650. $enclosur->rid = $rid;
  6651. $enclosur->insert ();
  6652. }
  6653. // print_r($enclosurArray);die;
  6654. }
  6655. // 报销详情
  6656. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6657. $receiptDetail = new receiptDetail ();
  6658. $receiptDetail->staff = $this->staff [0] ['sid'];
  6659. $receiptDetail->item = $value ['name'];
  6660. $receiptDetail->itemCategory = $this->AGENCY;
  6661. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6662. $receiptDetail->date = date ( "Y-m-d" );
  6663. $receiptDetail->cid = $cid;
  6664. $receiptDetail->rid = $rid;
  6665. $receiptDetail->status = 4;
  6666. $receiptDetail->insert ();
  6667. }
  6668. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6669. $receiptDetail = new receiptDetail ();
  6670. $receiptDetail->staff = $this->staff [0] ['sid'];
  6671. $receiptDetail->item = $value ['name'];
  6672. $receiptDetail->itemCategory = $this->TRAVEL;
  6673. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6674. $receiptDetail->date = date ( "Y-m-d" );
  6675. $receiptDetail->cid = $cid;
  6676. $receiptDetail->rid = $rid;
  6677. $receiptDetail->status = 4;
  6678. $receiptDetail->insert ();
  6679. }
  6680. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6681. $receiptDetail = new receiptDetail ();
  6682. $receiptDetail->staff = $this->staff [0] ['sid'];
  6683. $receiptDetail->item = $value ['name'];
  6684. $receiptDetail->itemCategory = $this->TRAIN;
  6685. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6686. $receiptDetail->date = date ( "Y-m-d" );
  6687. $receiptDetail->cid = $cid;
  6688. $receiptDetail->rid = $rid;
  6689. $receiptDetail->status = 4;
  6690. $receiptDetail->insert ();
  6691. }
  6692. //内训
  6693. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6694. $receiptDetail = new receiptDetail ();
  6695. $receiptDetail->staff = $this->staff [0] ['sid'];
  6696. $receiptDetail->item = $value ['name'];
  6697. $receiptDetail->itemCategory = $this->INTTRAIN;
  6698. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6699. $receiptDetail->date = date ( "Y-m-d" );
  6700. $receiptDetail->cid = $cid;
  6701. $receiptDetail->rid = $rid;
  6702. $receiptDetail->status = 4;
  6703. $receiptDetail->insert ();
  6704. }
  6705. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6706. $receiptDetail = new receiptDetail ();
  6707. $receiptDetail->staff = $this->staff [0] ['sid'];
  6708. $receiptDetail->item = $value ['name'];
  6709. $receiptDetail->itemCategory = $this->OTHER;
  6710. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6711. $receiptDetail->date = date ( "Y-m-d" );
  6712. $receiptDetail->cid = $cid;
  6713. $receiptDetail->rid = $rid;
  6714. $receiptDetail->status = 4;
  6715. $receiptDetail->insert ();
  6716. }
  6717. return "/saeaBorad";
  6718. } else
  6719. die ( 'illegal request' );
  6720. }
  6721. function referReceipt() {
  6722. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6723. Doo::loadModel ( 'receipt' );
  6724. Doo::loadModel ( 'verify' );
  6725. $verify = new verify ();
  6726. $receipt = new receipt ();
  6727. Doo::loadModel ( 'L_category' );
  6728. $lCategory = new L_category ();
  6729. Doo::loadModel ( "role" );
  6730. $role = new role ();
  6731. $receiptDetail = $receipt->find ( array (
  6732. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6733. 'asArray' => true
  6734. ) );
  6735. if (empty ( $receiptDetail ))
  6736. return "/addReceipt";
  6737. foreach ( $receiptDetail as $key => $value ) {
  6738. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6739. $veList = $verify->getOne ( array (
  6740. 'where' => 'vid=' . $value ['verify'],
  6741. 'asArray' => true
  6742. ) );
  6743. $v = json_decode ( $veList ['staff'] );
  6744. array_push ( $v [0], $veList ['description'] );
  6745. foreach ( $v as $n => $m ) {
  6746. if ($m ['1'] == 'ROLE') {
  6747. $roleInfo = $role->getOne ( array (
  6748. 'where' => 'rid=' . $m [0],
  6749. 'asArray' => true
  6750. ) );
  6751. $v [$n] [1] = $roleInfo ['name'];
  6752. }
  6753. }
  6754. $receiptDetail [$key] ['staff'] = $v;
  6755. $category = $lCategory->getOne ( array (
  6756. 'where' => 'cid=' . $value ['cid'],
  6757. 'asArray' => true
  6758. ) );
  6759. $receiptDetail [$key] ['category'] = $category ['title'];
  6760. }
  6761. // print_r($receiptDetail);
  6762. $data ['receiptDetail'] = $receiptDetail;
  6763. $data ['memu'] = "receipt";
  6764. $data ['staff'] = $this->staff;
  6765. $data ['receiptMemu'] = 'saeaCreate';
  6766. $data ['verifyId'] = $this->verifyId;
  6767. $data ['executeId'] = $this->executeId;
  6768. $this->render ( "/admin/saea_confirm", $data );
  6769. }
  6770. function editReceipt() {
  6771. // edit status 4
  6772. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6773. Doo::loadClass ( 'XDeode' );
  6774. $XDeode = new XDeode ( 7 );
  6775. $rid = $XDeode->decode ( $ridKey );
  6776. if (empty ( $rid ))
  6777. die ( 'illegal request' );
  6778. // echo $rid.'sd';
  6779. Doo::loadModel ( 'accountItem' );
  6780. Doo::loadModel ( 'verify' );
  6781. Doo::loadModel ( 'receipt' );
  6782. $receipt = new receipt ();
  6783. $verify = new verify ();
  6784. $accountItem = new accountItem ();
  6785. Doo::loadModel ( 'L_category' );
  6786. $lCategory = new L_category ();
  6787. Doo::loadModel ( "role" );
  6788. $role = new role ();
  6789. Doo::loadModel ( 'enclosur' );
  6790. $enclosur = new enclosur ();
  6791. $receiptDetail = $receipt->getOne ( array (
  6792. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6793. 'asArray' => true
  6794. ) );
  6795. if (empty ( $receiptDetail ))
  6796. die ( 'illegal request' );
  6797. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6798. $acItem = $accountItem->find ( array (
  6799. 'asArray' => true
  6800. ) );
  6801. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6802. // 配置编辑信息
  6803. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6804. foreach ( $acItem as $key => $value ) {
  6805. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6806. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6807. $acItem [$key] ['price'] = $v ['price'];
  6808. }
  6809. }
  6810. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6811. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6812. $acItem [$key] ['price'] = $v ['price'];
  6813. }
  6814. }
  6815. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6816. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6817. $acItem [$key] ['price'] = $v ['price'];
  6818. }
  6819. }
  6820. //内训
  6821. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6822. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6823. $acItem [$key] ['price'] = $v ['price'];
  6824. }
  6825. }
  6826. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6827. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6828. $acItem [$key] ['price'] = $v ['price'];
  6829. }
  6830. }
  6831. }
  6832. $data ['category'] = $lCategory->find ( array (
  6833. 'asArray' => true
  6834. ) );
  6835. $data ['cSum'] = $accountItemList ['cSum'];
  6836. $data ['sum'] = $receiptDetail ['sum'];
  6837. $data ['enclosurList'] = $enclosurList;
  6838. $data ['receiptDetail'] = $receiptDetail;
  6839. $data ['veList'] = $veList;
  6840. $data ['acItem'] = $acItem;
  6841. $data ['memu'] = "receipt";
  6842. $data ['staff'] = $this->staff;
  6843. $data ['receiptMemu'] = 'saeaBorad';
  6844. $data ['verify'] = $receiptDetail ['verify'];
  6845. $data ['verifyId'] = $this->verifyId;
  6846. $data ['executeId'] = $this->executeId;
  6847. $data ['rid'] = $ridKey;
  6848. $this->render ( "/admin/saea_edit", $data );
  6849. }
  6850. function updateReceipt() {
  6851. $agency = $this->get_args ( 'agency' );
  6852. $travel = $this->get_args ( 'travel' );
  6853. $train = $this->get_args ( 'train' );
  6854. $other = $this->get_args ( 'other' );
  6855. $inttrain = $this->get_args ( 'inttrain' );
  6856. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6857. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6858. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6859. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6860. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6861. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6862. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6863. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6864. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6865. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6866. Doo::loadClass ( 'XDeode' );
  6867. $XDeode = new XDeode ( 7 );
  6868. $rid = $XDeode->decode ( $ridKey );
  6869. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6870. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6871. header ( 'Content-Type:text/html;charset=utf-8' );
  6872. die ( '请填写联行号' );
  6873. }
  6874. Doo::loadModel ( 'receipt' );
  6875. Doo::loadModel ( 'receiptDetail' );
  6876. Doo::loadModel ( 'accountItem' );
  6877. $accountItem = new accountItem ();
  6878. $receipt = new receipt ();
  6879. Doo::loadModel ( 'enclosur' );
  6880. Doo::loadModel ( 'execute' );
  6881. $execute = new execute ();
  6882. $receiptDetail = $receipt->getOne ( array (
  6883. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6884. 'asArray' => true
  6885. ) );
  6886. if (empty ( $receiptDetail ))
  6887. return "/saeaBorad";
  6888. if ($receiptDetail ['Rtype'] == 1)
  6889. $executeDetail = $execute->getOne ( array (
  6890. 'where' => 'mold="借款费用执行人"',
  6891. 'asArray' => true
  6892. ) );
  6893. else
  6894. $executeDetail = $execute->getOne ( array (
  6895. 'where' => 'mold="报销单执行人"',
  6896. 'asArray' => true
  6897. ) );
  6898. $aItem = $accountItem->find ( array (
  6899. 'asArray' => true
  6900. ) );
  6901. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6902. $ag = $tr = $ta = $ot = $it = 0 ;
  6903. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6904. foreach ( $aItem as $key => $value ) {
  6905. if ($value ['category'] == $this->AGENCY) {
  6906. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6907. array_push ( $accountJson [$this->AGENCY], array (
  6908. 'aid' => $value ['aid'],
  6909. 'name' => $value ['name'],
  6910. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6911. ) );
  6912. $sum += $agency [$ag];
  6913. $agencySum += $agency [$ag];
  6914. }
  6915. $ag ++;
  6916. }
  6917. if ($value ['category'] == $this->TRAVEL) {
  6918. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6919. array_push ( $accountJson [$this->TRAVEL], array (
  6920. 'aid' => $value ['aid'],
  6921. 'name' => $value ['name'],
  6922. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6923. ) );
  6924. $sum += $travel [$tr];
  6925. $travelSum += $travel [$tr];
  6926. }
  6927. $tr ++;
  6928. }
  6929. if ($value ['category'] == $this->TRAIN) {
  6930. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6931. array_push ( $accountJson [$this->TRAIN], array (
  6932. 'aid' => $value ['aid'],
  6933. 'name' => $value ['name'],
  6934. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6935. ) );
  6936. $sum += $train [$ta];
  6937. $trainSum += $train [$ta];
  6938. }
  6939. $ta ++;
  6940. }
  6941. if ($value ['category'] == $this->INTTRAIN) {
  6942. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6943. array_push ( $accountJson [$this->INTTRAIN], array (
  6944. 'aid' => $value ['aid'],
  6945. 'name' => $value ['name'],
  6946. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6947. ) );
  6948. $sum += $inttrain [$it];
  6949. $inttrainSum += $inttrain [$it];
  6950. }
  6951. $it ++;
  6952. }
  6953. if ($value ['category'] == $this->OTHER) {
  6954. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6955. array_push ( $accountJson [$this->OTHER], array (
  6956. 'aid' => $value ['aid'],
  6957. 'name' => $value ['name'],
  6958. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6959. ) );
  6960. $sum += $other [$ot];
  6961. $otherSum += $other [$ot];
  6962. }
  6963. $ot ++;
  6964. }
  6965. }
  6966. $accountJson ['cSum'] = array (
  6967. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6968. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6969. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6970. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6971. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6972. );
  6973. // 报销单
  6974. $rid = $receipt->rid = $receiptDetail ['rid'];
  6975. $receipt->accountItem = json_encode ( $accountJson );
  6976. $receipt->staff = $this->staff [0] ['sid'];
  6977. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6978. $receipt->date = date ( "Y-m-d" );
  6979. $receipt->cid = $cid;
  6980. if (($receiptDetail ['status'] != 4)) {
  6981. if ($receiptDetail ['Rtype'] == 1)
  6982. $receipt->status = 7;
  6983. else
  6984. $receipt->status = 5;
  6985. }
  6986. if ($receiptDetail != 4 && ! empty ( $verify ))
  6987. $receipt->verify = $verify;
  6988. $receipt->executeCopy = $executeDetail ['staff'];
  6989. $order = array (
  6990. "\r\n",
  6991. "\n",
  6992. "\r"
  6993. );
  6994. $replace = '<br/>';
  6995. $explanation = str_replace ( $order, $replace, $explanation );
  6996. $receipt->explanation = $explanation;
  6997. $receipt->remittanceName = $remittanceName;
  6998. $receipt->bankName = $bankName;
  6999. $receipt->bankNumber = $bankNumber;
  7000. $receipt->remittanceBankType = $remittanceBankType;
  7001. if ($remittanceBankType == 1)
  7002. $receipt->coupletNumber = $coupletNumber;
  7003. $receipt->update ();
  7004. $receiptDetail = new receiptDetail ();
  7005. $receiptDetail->delete ( array (
  7006. 'where' => 'rid=' . $rid
  7007. ) );
  7008. // 报销详情
  7009. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  7010. $receiptDetail = new receiptDetail ();
  7011. $receiptDetail->staff = $this->staff [0] ['sid'];
  7012. $receiptDetail->item = $value ['name'];
  7013. $receiptDetail->itemCategory = $this->AGENCY;
  7014. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7015. $receiptDetail->date = date ( "Y-m-d" );
  7016. $receiptDetail->cid = $cid;
  7017. $receiptDetail->rid = $rid;
  7018. $receiptDetail->status = 4;
  7019. $receiptDetail->insert ();
  7020. }
  7021. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  7022. $receiptDetail = new receiptDetail ();
  7023. $receiptDetail->staff = $this->staff [0] ['sid'];
  7024. $receiptDetail->item = $value ['name'];
  7025. $receiptDetail->itemCategory = $this->TRAVEL;
  7026. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7027. $receiptDetail->date = date ( "Y-m-d" );
  7028. $receiptDetail->cid = $cid;
  7029. $receiptDetail->rid = $rid;
  7030. $receiptDetail->status = 4;
  7031. $receiptDetail->insert ();
  7032. }
  7033. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  7034. $receiptDetail = new receiptDetail ();
  7035. $receiptDetail->staff = $this->staff [0] ['sid'];
  7036. $receiptDetail->item = $value ['name'];
  7037. $receiptDetail->itemCategory = $this->TRAIN;
  7038. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7039. $receiptDetail->date = date ( "Y-m-d" );
  7040. $receiptDetail->cid = $cid;
  7041. $receiptDetail->rid = $rid;
  7042. $receiptDetail->status = 4;
  7043. $receiptDetail->insert ();
  7044. }
  7045. //内训
  7046. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  7047. $receiptDetail = new receiptDetail ();
  7048. $receiptDetail->staff = $this->staff [0] ['sid'];
  7049. $receiptDetail->item = $value ['name'];
  7050. $receiptDetail->itemCategory = $this->INTTRAIN;
  7051. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7052. $receiptDetail->date = date ( "Y-m-d" );
  7053. $receiptDetail->cid = $cid;
  7054. $receiptDetail->rid = $rid;
  7055. $receiptDetail->status = 4;
  7056. $receiptDetail->insert ();
  7057. }
  7058. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  7059. $receiptDetail = new receiptDetail ();
  7060. $receiptDetail->staff = $this->staff [0] ['sid'];
  7061. $receiptDetail->item = $value ['name'];
  7062. $receiptDetail->itemCategory = $this->OTHER;
  7063. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7064. $receiptDetail->date = date ( "Y-m-d" );
  7065. $receiptDetail->cid = $cid;
  7066. $receiptDetail->rid = $rid;
  7067. $receiptDetail->status = 4;
  7068. $receiptDetail->insert ();
  7069. }
  7070. // 附件
  7071. if (! empty ( $enclosurName )) {
  7072. $enclosurArray = explode ( '-', $enclosurName );
  7073. foreach ( $enclosurArray as $value ) {
  7074. $enclosur = new enclosur ();
  7075. $enclosur->name = $value;
  7076. $enclosur->rid = $rid;
  7077. $enclosur->insert ();
  7078. }
  7079. }
  7080. // return "/referReceipt/".$rid;
  7081. }
  7082. return "/saeaBorad";
  7083. }
  7084. function approvedReceipt() {
  7085. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7086. Doo::loadModel ( 'receipt' );
  7087. Doo::loadModel ( 'receiptDetail' );
  7088. $receipt = new receipt ();
  7089. $receiptDetail = new receiptDetail ();
  7090. Doo::loadModel ( 'statistics' );
  7091. Doo::loadModel ( 'itemStatistics' );
  7092. $statistics = new statistics ();
  7093. $itemStatistics = new itemStatistics ();
  7094. Doo::loadModel ( "verify" );
  7095. $verify = new verify ();
  7096. // 审批状态的判定
  7097. $receiptDetailList = $receipt->getOne ( array (
  7098. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7099. 'asArray' => true
  7100. ) );
  7101. if (empty ( $receiptDetailList ))
  7102. return "/saeaBorad";
  7103. $verifyDetail = $verify->getOne ( array (
  7104. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7105. 'asArray' => true
  7106. ) );
  7107. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7108. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7109. $nowStaff = "";
  7110. $nowStaffList = array ();
  7111. if ($verifyDetail [0] [1] == 'ROLE') {
  7112. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7113. foreach ( $vStaffString as $key => $value ) {
  7114. $staffK = explode ( "_", $value );
  7115. array_push ( $nowStaffList, $staffK [0] );
  7116. }
  7117. $nowStaff = implode ( ',', $nowStaffList );
  7118. } else {
  7119. $nowStaff = $verifyDetail [0] [0];
  7120. }
  7121. $receipt->nowStaff = $nowStaff;
  7122. }
  7123. // echo $nowStaff;
  7124. // print_r($verifyDetail);die;
  7125. $receipt->rid = $receiptDetailList ['rid'];
  7126. $receipt->date = date ( "Y-m-d" );
  7127. $receipt->status = 2;
  7128. $receipt->update ();
  7129. $receiptDetail->status = 2;
  7130. $receiptDetail->update ( array (
  7131. 'where' => 'rid=' . $receiptDetailList ['rid']
  7132. ) );
  7133. Doo::loadModel ( "receiptLog" );
  7134. $receiptLog = new receiptLog ();
  7135. Doo::loadModel ( "verify" );
  7136. $verify = new verify ();
  7137. $receiptInfo = $receipt->getOne ( array (
  7138. 'where' => 'rid=' . $rid,
  7139. 'asArray' => true
  7140. ) );
  7141. $vr = $verify->getOne ( array (
  7142. 'where' => 'vid=' . $receiptInfo ['verify'],
  7143. 'asArray' => true
  7144. ) );
  7145. $jd = json_decode ( $vr ['staff'] );
  7146. $roleId = 0;
  7147. foreach ( $jd as $key => $value ) {
  7148. if ($value [1] == 'ROLE') {
  7149. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7150. if ($pos !== false) {
  7151. $roleId = $value [0];
  7152. }
  7153. }
  7154. }
  7155. // 审批日志
  7156. // echo $roleId;die;
  7157. if (! empty ( $roleId )) {
  7158. Doo::loadModel ( "role" );
  7159. $role = new role ();
  7160. $roleInfo = $role->getOne ( array (
  7161. 'where' => 'rid=' . $roleId,
  7162. 'asArray' => true
  7163. ) );
  7164. // $receiptLog->rolename = $roleInfo ['name'];
  7165. }
  7166. $receiptLog->username = $this->staff [0] ['username'];
  7167. $receiptLog->uid = $this->staff [0] ['sid'];
  7168. $receiptLog->date = date ( "Y-m-d" );
  7169. $receiptLog->opinion = '提交审批';
  7170. $receiptLog->img = $this->staff [0] ['avatar'];
  7171. $receiptLog->status = 2;
  7172. $receiptLog->rid = $rid;
  7173. $receiptLog->insert ();
  7174. // statistics item
  7175. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7176. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7177. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7178. $stat = $statistics->getOne ( array (
  7179. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7180. 'asArray' => true
  7181. ) );
  7182. if (empty ( $stat )) {
  7183. $statistics->date = date ( "Y-m-d" );
  7184. $statistics->cid = $this->staff [0] ['cid'];
  7185. $statistics->staff = $this->staff [0] ['sid'];
  7186. $statistics->agPrice = 0;
  7187. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7188. $statistics->insert ();
  7189. } else {
  7190. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7191. $statistics->update ( array (
  7192. 'where' => 'sid=' . $stat ['sid']
  7193. ) );
  7194. }
  7195. return "/expenses";
  7196. }
  7197. function approval() {
  7198. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7199. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7200. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7201. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7202. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7203. if (empty ( $status ))
  7204. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7205. $vidList = array ();
  7206. $button = 0;
  7207. Doo::loadModel ( 'verify' );
  7208. $verify = new verify ();
  7209. Doo::loadModel ( 'receipt' );
  7210. $receipt = new receipt ();
  7211. Doo::loadModel ( 'staff' );
  7212. $staff = new staff ();
  7213. Doo::loadModel ( 'L_category' );
  7214. $Lcategory = new L_category ();
  7215. // user verify ID
  7216. $verifyDetail = $verify->find ( array (
  7217. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7218. 'asArray' => true
  7219. ) );
  7220. foreach ( $verifyDetail as $key => $value ) {
  7221. array_push ( $vidList, $value ['vid'] );
  7222. }
  7223. $vid = implode ( ",", $vidList );
  7224. if (empty ( $verifyDetail ))
  7225. $vid = 0;
  7226. /*
  7227. */
  7228. $dateCondition = " and Year(date) =" . $year;
  7229. if (! empty ( $month ))
  7230. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7231. $categoryList = $Lcategory->find ( array (
  7232. 'asArray' => true
  7233. ) );
  7234. $staffList = $staff->find ( array (
  7235. 'where' => 'cid=' . $cid,
  7236. 'asArray' => true
  7237. ) );
  7238. $cateCondition = "";
  7239. $staffCondition = "";
  7240. $approvalCondition = "";
  7241. if (! empty ( $cid ))
  7242. $cateCondition = ' and cid=' . $cid;
  7243. if (! empty ( $sid )) {
  7244. $staffCondition = ' and staff=' . $sid;
  7245. $cateCondition = "";
  7246. }
  7247. // elseif($status==1){
  7248. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7249. // }
  7250. if ($status == 2) {
  7251. // 查找角色审批人
  7252. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7253. }
  7254. $ap = "";
  7255. if ($status == 4) {
  7256. $ap = 4;
  7257. $status = 2;
  7258. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7259. }
  7260. if ($status == 5) {
  7261. $status = 4;
  7262. $ap = 5;
  7263. }
  7264. // echo $vid;
  7265. // get Receipt By verifyID status 2 .$approvalCondition
  7266. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7267. $receiptList = $receipt->find ( array (
  7268. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7269. 'desc' => 'rid',
  7270. 'asArray' => true
  7271. ) );
  7272. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7273. $Locate = 0;
  7274. if ($ap == 4)
  7275. $status = 4;
  7276. elseif ($ap == 5)
  7277. $status = 5;
  7278. foreach ( $receiptList as $key => $value ) {
  7279. $receiptList [$key] ['Locate'] = $Locate;
  7280. $Locate ++;
  7281. $receiptList [$key] ['reviseDetail'] = array ();
  7282. if (! empty ( $value ['reviseDetail'] ))
  7283. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7284. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7285. $categoryDetil = $Lcategory->getOne ( array (
  7286. 'where' => 'cid=' . $value ['cid'],
  7287. 'asArray' => true
  7288. ) );
  7289. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7290. $verifyList = $verify->getOne ( array (
  7291. 'where' => 'vid=' . $value ['verify'],
  7292. 'asArray' => true
  7293. ) );
  7294. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7295. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7296. foreach ( $verifyList as $k => $v ) {
  7297. // init verifyStaff
  7298. $verifyList [$k] ['date'] = "";
  7299. $verifyList [$k] ['opinion'] = "";
  7300. $verifyList [$k] ['status'] = "";
  7301. if (empty ( $verifyStaff )) {
  7302. $verifyList [$k] ['date'] = "";
  7303. $verifyList [$k] ['opinion'] = "";
  7304. if ($v [0] == $this->staff [0] ['sid']) {
  7305. $verifyList [$k] ['status'] = 4;
  7306. $button = 4;
  7307. }
  7308. } else {
  7309. $flag = true;
  7310. foreach ( $verifyStaff as $m => $u ) {
  7311. if ($v [0] == $m) {
  7312. $verifyList [$k] ['date'] = $u ['date'];
  7313. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7314. $verifyList [$k] ['status'] = $u ['status'];
  7315. $flag = false;
  7316. break;
  7317. }
  7318. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7319. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7320. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7321. }
  7322. if ($flag) { // 检测可编辑
  7323. if ($v [0] == $this->staff [0] ['sid']) {
  7324. $verifyList [$k] ['status'] = 4;
  7325. $button = 4;
  7326. }
  7327. }
  7328. }
  7329. }
  7330. $receiptList [$key] ['verifyList'] = $verifyList;
  7331. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7332. 'where' => 'sid=' . $value ['staff'],
  7333. 'asArray' => true
  7334. ) );
  7335. $receiptList [$key] ['button'] = $button;
  7336. }
  7337. // print_r($receiptList);die;
  7338. // $data['verifyDetail']=$verifyDetail;
  7339. $mothHtml = "";
  7340. for($i = 1; $i <= 12; $i ++) {
  7341. if ($month == $i)
  7342. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7343. else
  7344. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7345. }
  7346. $data ['mothHtml'] = $mothHtml;
  7347. $data ['receiptList'] = $receiptList;
  7348. $data ['receiptApprovalCount'] = count ( $receiptList );
  7349. $data ['status'] = $status;
  7350. $data ['year'] = $year;
  7351. $data ['categoryList'] = $categoryList;
  7352. $data ['staffList'] = $staffList;
  7353. $data ['cid'] = $cid;
  7354. $data ['sid'] = $sid;
  7355. $data ['ap'] = $ap;
  7356. $data ['memu'] = "receipt";
  7357. $data ['staff'] = $this->staff;
  7358. $data ['receiptMemu'] = 'approval';
  7359. $data ['verifyId'] = $this->verifyId;
  7360. $data ['executeId'] = $this->executeId;
  7361. $this->render ( "/admin/saea_reportList", $data );
  7362. }
  7363. function approvalDetails() {
  7364. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7365. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7366. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7367. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7368. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7369. Doo::loadModel ( 'verify' );
  7370. $verify = new verify ();
  7371. Doo::loadModel ( 'receipt' );
  7372. $receipt = new receipt ();
  7373. Doo::loadModel ( 'staff' );
  7374. $staff = new staff ();
  7375. Doo::loadModel ( 'L_category' );
  7376. $Lcategory = new L_category ();
  7377. Doo::loadModel ( 'enclosur' );
  7378. $enclosur = new enclosur ();
  7379. $vidList = array ();
  7380. $verifyDetail = $verify->find ( array (
  7381. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7382. 'asArray' => true
  7383. ) );
  7384. foreach ( $verifyDetail as $key => $value ) {
  7385. array_push ( $vidList, $value ['vid'] );
  7386. }
  7387. $vid = implode ( ",", $vidList );
  7388. if (empty ( $verifyDetail ))
  7389. $vid = 0;
  7390. $categoryList = $Lcategory->find ( array (
  7391. 'asArray' => true
  7392. ) );
  7393. $staffList = $staff->find ( array (
  7394. 'where' => 'cid=' . $cid,
  7395. 'asArray' => true
  7396. ) );
  7397. $ap = 0;
  7398. $receiptList = $receipt->find ( array (
  7399. 'where' => 'rid =' . $rid,
  7400. 'desc' => 'rid',
  7401. 'asArray' => true
  7402. ) );
  7403. $Locate = 0;
  7404. $roleId = 0;
  7405. $button = 0;
  7406. foreach ( $receiptList as $key => $value ) {
  7407. $receiptList [$key] ['Locate'] = $Locate;
  7408. $Locate ++;
  7409. $receiptList [$key] ['reviseDetail'] = array ();
  7410. if (! empty ( $value ['reviseDetail'] ))
  7411. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7412. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7413. $categoryDetil = $Lcategory->getOne ( array (
  7414. 'where' => 'cid=' . $value ['cid'],
  7415. 'asArray' => true
  7416. ) );
  7417. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7418. // 检测编辑状态
  7419. $verifyList = $verify->getOne ( array (
  7420. 'where' => 'vid=' . $value ['verify'],
  7421. 'asArray' => true
  7422. ) );
  7423. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7424. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7425. Doo::loadModel ( 'role' );
  7426. $role = new role ();
  7427. // print_r($verifyList);
  7428. $flag = true;
  7429. $roleKey = 0;
  7430. $endStaffArray = array ();
  7431. $roleArrayCopy = array ();
  7432. foreach ( $verifyList as $k => $v ) {
  7433. // init verifyStaff
  7434. if ($v [1] == 'ROLE') {
  7435. if (! empty ( $verifyStaff )) {
  7436. $endStaffArray = end ( $verifyStaff );
  7437. if ($v [0] == $endStaffArray ['nextStaff']) {
  7438. $roleId = $v [0];
  7439. }
  7440. }
  7441. $roleVerify = json_decode ( $v [3], true );
  7442. $roleKey = $k;
  7443. $roleArray = array ();
  7444. $rolename = $role->getOne ( array (
  7445. 'where' => 'rid=' . $v [0],
  7446. 'asArray' => true
  7447. ) );
  7448. foreach ( $roleVerify as $o => $p ) {
  7449. $staffID = explode ( '_', $p );
  7450. $staffInfo = $staff->getOne ( array (
  7451. 'where' => 'sid=' . $staffID [0],
  7452. 'asArray' => true
  7453. ) );
  7454. // print_r($staffID);
  7455. $exp = array (
  7456. 0 => $staffInfo ['sid'],
  7457. 1 => $staffID [1],
  7458. 2 => $staffInfo ['avatar'],
  7459. 'date' => '',
  7460. 'date' => '',
  7461. 'opinion' => '',
  7462. 'status' => '',
  7463. 'rolename' => $rolename ['name']
  7464. );
  7465. array_push ( $roleArray, $exp );
  7466. }
  7467. $roleArrayCopy [$v [0]] = $roleArray;
  7468. // $verifyList[$k]['roleArray']=$roleArray;
  7469. }
  7470. // print_r($roleArray);
  7471. $verifyList [$k] ['date'] = "";
  7472. $verifyList [$k] ['opinion'] = "";
  7473. $verifyList [$k] ['status'] = "";
  7474. if (empty ( $verifyStaff )) {
  7475. $verifyList [$k] ['date'] = "";
  7476. $verifyList [$k] ['opinion'] = "";
  7477. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7478. $verifyList [$k] ['status'] = 4;
  7479. $button = 4;
  7480. $flag = false;
  7481. }
  7482. } else {
  7483. foreach ( $verifyStaff as $m => $u ) {
  7484. if ($v [0] == $m) {
  7485. $verifyList [$k] ['date'] = $u ['date'];
  7486. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7487. $verifyList [$k] ['status'] = $u ['status'];
  7488. $flag = false;
  7489. break;
  7490. }
  7491. }
  7492. $endStaffArray = end ( $verifyStaff );
  7493. if (isset ( $endStaffArray ['ROLE'] )) {
  7494. } else {
  7495. $endKey = key ( $verifyStaff );
  7496. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7497. $button = 4;
  7498. $verifyList [$k] ['status'] = 4;
  7499. }
  7500. }
  7501. }
  7502. }
  7503. $rolename ['name'] = '';
  7504. if (! empty ( $roleId )) {
  7505. Doo::loadModel ( 'role' );
  7506. $role = new role ();
  7507. $rolename = $role->getOne ( array (
  7508. 'where' => 'rid=' . $roleId,
  7509. 'asArray' => true
  7510. ) );
  7511. }
  7512. if (! empty ( $verifyStaff ))
  7513. $endStaffArray = end ( $verifyStaff );
  7514. $KOP = false;
  7515. foreach ( $roleArrayCopy as $P => $A ) {
  7516. foreach ( $A as $MKI => $AVL ) {
  7517. if (! empty ( $verifyStaff )) {
  7518. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7519. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7520. $button = 4;
  7521. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7522. }
  7523. foreach ( $verifyStaff as $m => $u ) {
  7524. $AVLFK = $AVL [0] . '_R';
  7525. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7526. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7527. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7528. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7529. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7530. break;
  7531. }
  7532. }
  7533. } else {
  7534. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7535. $button = 4;
  7536. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7537. }
  7538. }
  7539. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7540. $KOP = true;
  7541. }
  7542. }
  7543. foreach ( $roleArrayCopy as $k => $v ) {
  7544. foreach ( $verifyList as $m => $n ) {
  7545. if ($n [0] == $k) {
  7546. array_splice ( $verifyList, $m, 1, $v );
  7547. }
  7548. }
  7549. }
  7550. $receiptList [$key] ['verifyList'] = $verifyList;
  7551. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7552. 'where' => 'sid=' . $value ['staff'],
  7553. 'asArray' => true
  7554. ) );
  7555. $receiptList [$key] ['button'] = $button;
  7556. }
  7557. $mothHtml = "";
  7558. for($i = 1; $i <= 12; $i ++) {
  7559. if ($month == $i)
  7560. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7561. else
  7562. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7563. }
  7564. // 获取审批日志
  7565. Doo::loadModel ( 'receiptLog' );
  7566. $receiptLog = new receiptLog ();
  7567. $rlList = array ();
  7568. $rlInfo = $receiptLog->getOne ( array (
  7569. 'where' => 'rid=' . $rid . ' and status=4',
  7570. 'asArray' => true
  7571. ) );
  7572. $tijdate = $receiptLog->getOne ( array (
  7573. 'where' => 'rid=' . $rid . ' and status=2',
  7574. 'asc' => 'rlid',
  7575. 'asArray' => true
  7576. ) );
  7577. if (! empty ( $rlInfo )) {
  7578. $rlList = $receiptLog->find ( array (
  7579. 'where' => 'rid=' . $rid,
  7580. 'asc' => 'rlid',
  7581. 'asArray' => true
  7582. ) );
  7583. }
  7584. $receiptList [0] ['rlList'] = $rlList;
  7585. $enclosurList = $enclosur->find ( array (
  7586. 'where' => 'rid=' . $rid,
  7587. 'asArray' => true
  7588. ) );
  7589. $enclosurHtml = '';
  7590. foreach ( $enclosurList as $value ) {
  7591. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7592. }
  7593. $data ['enclosurHtml'] = $enclosurHtml;
  7594. $data ['rolename'] = $rolename ['name'];
  7595. $data ['datetij'] = $tijdate ['date'];
  7596. $data ['mothHtml'] = $mothHtml;
  7597. $data ['receiptList'] = $receiptList;
  7598. $data ['receiptApprovalCount'] = count ( $receiptList );
  7599. $data ['year'] = $year;
  7600. $data ['categoryList'] = $categoryList;
  7601. $data ['staffList'] = $staffList;
  7602. $data ['cid'] = $cid;
  7603. $data ['sid'] = $sid;
  7604. $data ['status'] = 0;
  7605. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7606. $ap = 4;
  7607. } else
  7608. $data ['status'] = $receiptList [0] ['status'];
  7609. if ($receiptList [0] ['status'] == 4) {
  7610. $data ['status'] = 5;
  7611. $ap = 0;
  7612. }
  7613. $data ['ap'] = $ap;
  7614. $data ['memu'] = "receipt";
  7615. $data ['staff'] = $this->staff;
  7616. $data ['receiptMemu'] = 'approval';
  7617. $data ['verifyId'] = $this->verifyId;
  7618. $data ['executeId'] = $this->executeId;
  7619. $this->render ( "/admin/saeaReportListReport", $data );
  7620. }
  7621. function approvalEdi() {
  7622. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7623. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7624. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7625. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7626. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7627. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7628. if (empty ( $status ))
  7629. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7630. $vidList = array ();
  7631. $button = 0;
  7632. Doo::loadModel ( 'verify' );
  7633. Doo::loadModel ( 'receipt' );
  7634. Doo::loadModel ( 'staff' );
  7635. $staff = new staff ();
  7636. $receipt = new receipt ();
  7637. $verify = new verify ();
  7638. Doo::loadModel ( 'L_category' );
  7639. $Lcategory = new L_category ();
  7640. Doo::loadModel ( 'enclosur' );
  7641. $enclosur = new enclosur ();
  7642. // user verify ID
  7643. $verifyDetail = $verify->find ( array (
  7644. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7645. 'asArray' => true
  7646. ) );
  7647. foreach ( $verifyDetail as $key => $value ) {
  7648. array_push ( $vidList, $value ['vid'] );
  7649. }
  7650. $vid = implode ( ",", $vidList );
  7651. if (empty ( $verifyDetail ))
  7652. $vid = 0;
  7653. $categoryList = $Lcategory->find ( array (
  7654. 'asArray' => true
  7655. ) );
  7656. $staffList = $staff->find ( array (
  7657. 'where' => 'cid=' . $cid,
  7658. 'asArray' => true
  7659. ) );
  7660. $ap = "";
  7661. if ($status == 4) {
  7662. $ap = 4;
  7663. $status = 2;
  7664. }
  7665. // get Receipt By verifyID status 2
  7666. $receiptList = $receipt->find ( array (
  7667. 'where' => 'rid =' . $rid,
  7668. 'desc' => 'rid',
  7669. 'asArray' => true
  7670. ) );
  7671. $Locate = 0;
  7672. $roleId = 0;
  7673. if ($ap == 4)
  7674. $status = 4;
  7675. foreach ( $receiptList as $key => $value ) {
  7676. $receiptList [$key] ['Locate'] = $Locate;
  7677. $Locate ++;
  7678. $receiptList [$key] ['reviseDetail'] = array ();
  7679. if (! empty ( $value ['reviseDetail'] ))
  7680. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7681. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7682. $categoryDetil = $Lcategory->getOne ( array (
  7683. 'where' => 'cid=' . $value ['cid'],
  7684. 'asArray' => true
  7685. ) );
  7686. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7687. // 检测编辑状态
  7688. $verifyList = $verify->getOne ( array (
  7689. 'where' => 'vid=' . $value ['verify'],
  7690. 'asArray' => true
  7691. ) );
  7692. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7693. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7694. // print_r($verifyList);
  7695. //
  7696. // if (empty($verifyStaff)){
  7697. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7698. // $verifyList[0]['status']=4;$button=4;
  7699. // }
  7700. //
  7701. // }else{
  7702. //
  7703. // }
  7704. // die;
  7705. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7706. // echo array_search("green",$a);
  7707. //
  7708. Doo::loadModel ( 'role' );
  7709. $role = new role ();
  7710. // print_r($verifyList);
  7711. $flag = true;
  7712. $roleKey = 0;
  7713. $endStaffArray = array ();
  7714. $roleArrayCopy = array ();
  7715. foreach ( $verifyList as $k => $v ) {
  7716. // init verifyStaff
  7717. if ($v [1] == 'ROLE') {
  7718. if (! empty ( $verifyStaff )) {
  7719. $endStaffArray = end ( $verifyStaff );
  7720. if ($v [0] == $endStaffArray ['nextStaff']) {
  7721. $roleId = $v [0];
  7722. }
  7723. }
  7724. $roleVerify = json_decode ( $v [3], true );
  7725. $roleKey = $k;
  7726. $roleArray = array ();
  7727. $rolename = $role->getOne ( array (
  7728. 'where' => 'rid=' . $v [0],
  7729. 'asArray' => true
  7730. ) );
  7731. foreach ( $roleVerify as $o => $p ) {
  7732. $staffID = explode ( '_', $p );
  7733. $staffInfo = $staff->getOne ( array (
  7734. 'where' => 'sid=' . $staffID [0],
  7735. 'asArray' => true
  7736. ) );
  7737. // print_r($staffID);
  7738. $exp = array (
  7739. 0 => $staffInfo ['sid'],
  7740. 1 => $staffID [1],
  7741. 2 => $staffInfo ['avatar'],
  7742. 'date' => '',
  7743. 'date' => '',
  7744. 'opinion' => '',
  7745. 'status' => '',
  7746. 'rolename' => $rolename ['name']
  7747. );
  7748. array_push ( $roleArray, $exp );
  7749. }
  7750. $roleArrayCopy [$v [0]] = $roleArray;
  7751. // $verifyList[$k]['roleArray']=$roleArray;
  7752. }
  7753. // print_r($roleArray);
  7754. $verifyList [$k] ['date'] = "";
  7755. $verifyList [$k] ['opinion'] = "";
  7756. $verifyList [$k] ['status'] = "";
  7757. if (empty ( $verifyStaff )) {
  7758. $verifyList [$k] ['date'] = "";
  7759. $verifyList [$k] ['opinion'] = "";
  7760. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7761. $verifyList [$k] ['status'] = 4;
  7762. $button = 4;
  7763. $flag = false;
  7764. }
  7765. } else {
  7766. foreach ( $verifyStaff as $m => $u ) {
  7767. if ($v [0] == $m) {
  7768. $verifyList [$k] ['date'] = $u ['date'];
  7769. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7770. $verifyList [$k] ['status'] = $u ['status'];
  7771. $flag = false;
  7772. break;
  7773. }
  7774. }
  7775. $endStaffArray = end ( $verifyStaff );
  7776. if (isset ( $endStaffArray ['ROLE'] )) {
  7777. } else {
  7778. $endKey = key ( $verifyStaff );
  7779. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7780. $button = 4;
  7781. $verifyList [$k] ['status'] = 4;
  7782. }
  7783. }
  7784. // print_r($endStaffArray);die;
  7785. // if (empty($verifyStaff)){
  7786. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7787. // $verifyList[$k]['status']=4;$button=4;
  7788. // }
  7789. //
  7790. // }else{
  7791. //
  7792. // }
  7793. // if($flag){//检测可编辑
  7794. // if($v[0]==$this->staff[0]['sid']){
  7795. // $verifyList[$k]['status']=4;$button=4;
  7796. // }
  7797. // }
  7798. }
  7799. }
  7800. $rolename ['name'] = '';
  7801. if (! empty ( $roleId )) {
  7802. Doo::loadModel ( 'role' );
  7803. $role = new role ();
  7804. $rolename = $role->getOne ( array (
  7805. 'where' => 'rid=' . $roleId,
  7806. 'asArray' => true
  7807. ) );
  7808. }
  7809. if (! empty ( $verifyStaff ))
  7810. $endStaffArray = end ( $verifyStaff );
  7811. $KOP = false;
  7812. foreach ( $roleArrayCopy as $P => $A ) {
  7813. foreach ( $A as $MKI => $AVL ) {
  7814. if (! empty ( $verifyStaff )) {
  7815. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7816. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7817. $button = 4;
  7818. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7819. }
  7820. foreach ( $verifyStaff as $m => $u ) {
  7821. $AVLFK = $AVL [0] . '_R';
  7822. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7823. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7824. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7825. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7826. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7827. break;
  7828. }
  7829. }
  7830. } else {
  7831. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7832. $button = 4;
  7833. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7834. }
  7835. }
  7836. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7837. $KOP = true;
  7838. }
  7839. }
  7840. // print_r($roleArrayCopy);
  7841. // echo $roleKey;
  7842. foreach ( $roleArrayCopy as $k => $v ) {
  7843. foreach ( $verifyList as $m => $n ) {
  7844. if ($n [0] == $k) {
  7845. array_splice ( $verifyList, $m, 1, $v );
  7846. }
  7847. }
  7848. }
  7849. // if ($KOP)
  7850. // array_splice($verifyList,$roleKey,1,$roleArray);
  7851. // print_r($verifyList);
  7852. $receiptList [$key] ['verifyList'] = $verifyList;
  7853. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7854. 'where' => 'sid=' . $value ['staff'],
  7855. 'asArray' => true
  7856. ) );
  7857. $receiptList [$key] ['button'] = $button;
  7858. }
  7859. // $data['verifyDetail']=$verifyDetail;
  7860. $mothHtml = "";
  7861. for($i = 1; $i <= 12; $i ++) {
  7862. if ($month == $i)
  7863. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7864. else
  7865. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7866. }
  7867. // 获取审批日志
  7868. Doo::loadModel ( 'receiptLog' );
  7869. $receiptLog = new receiptLog ();
  7870. $rlList = array ();
  7871. $rlInfo = $receiptLog->getOne ( array (
  7872. 'where' => 'rid=' . $rid . ' and status=4',
  7873. 'asArray' => true
  7874. ) );
  7875. $tijdate = $receiptLog->getOne ( array (
  7876. 'where' => 'rid=' . $rid . ' and status=2',
  7877. 'asc' => 'rlid',
  7878. 'asArray' => true
  7879. ) );
  7880. if (! empty ( $rlInfo )) {
  7881. $rlList = $receiptLog->find ( array (
  7882. 'where' => 'rid=' . $rid,
  7883. 'asc' => 'rlid',
  7884. 'asArray' => true
  7885. ) );
  7886. }
  7887. $receiptList [0] ['rlList'] = $rlList;
  7888. $enclosurList = $enclosur->find ( array (
  7889. 'where' => 'rid=' . $rid,
  7890. 'asArray' => true
  7891. ) );
  7892. $enclosurHtml = '';
  7893. foreach ( $enclosurList as $value ) {
  7894. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7895. }
  7896. $data ['enclosurHtml'] = $enclosurHtml;
  7897. $data ['rolename'] = $rolename ['name'];
  7898. $data ['datetij'] = $tijdate ['date'];
  7899. $data ['mothHtml'] = $mothHtml;
  7900. $data ['receiptList'] = $receiptList;
  7901. $data ['receiptApprovalCount'] = count ( $receiptList );
  7902. $data ['status'] = $status;
  7903. $data ['year'] = $year;
  7904. $data ['categoryList'] = $categoryList;
  7905. $data ['staffList'] = $staffList;
  7906. $data ['cid'] = $cid;
  7907. $data ['sid'] = $sid;
  7908. $data ['ap'] = $ap;
  7909. $data ['memu'] = "receipt";
  7910. $data ['staff'] = $this->staff;
  7911. $data ['receiptMemu'] = 'approval';
  7912. $data ['verifyId'] = $this->verifyId;
  7913. $data ['executeId'] = $this->executeId;
  7914. $this->render ( "/admin/saeaReportListReport", $data );
  7915. }
  7916. function remittanceHky() {
  7917. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7918. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7919. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7920. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7921. $page_size = 15;
  7922. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7923. Doo::loadModel ( 'receipt' );
  7924. $receipt = new receipt ();
  7925. Doo::loadModel ( 'staff' );
  7926. $staff = new staff ();
  7927. $dateCondition = " and Year(executeDate) =" . $year;
  7928. if ($moth != 'MONTH')
  7929. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7930. if ($day != 'DAY' && $moth != 'MONTH')
  7931. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7932. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  7933. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7934. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7935. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7936. $dayList = $receipt->find ( array (
  7937. 'select' => 'executeDate,sum(amount) as amount',
  7938. 'where' => $sql,
  7939. 'desc' => 'executeDate',
  7940. 'groupby' => 'executeDate',
  7941. 'limit' => $limit,
  7942. 'asArray' => true
  7943. ) );
  7944. // print_r($dayList);
  7945. foreach ( $dayList as $key => $value ) {
  7946. $remitString = "";
  7947. $receiptList = $receipt->find ( array (
  7948. 'select' => 'rid,executeDate,amount,staff,cid',
  7949. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7950. 'desc' => 'executeDate',
  7951. 'asArray' => true
  7952. ) );
  7953. foreach ( $receiptList as $k => $v ) {
  7954. $sinfo = $staff->getOne ( array (
  7955. 'select' => 'username,category',
  7956. 'where' => ' sid=' . $v ['staff'],
  7957. 'asArray' => true
  7958. ) );
  7959. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7960. }
  7961. $dayList [$key] ['staff'] = $remitString;
  7962. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7963. }
  7964. // print_r($dayList);
  7965. $mothHtml = "";
  7966. for($i = 1; $i <= 12; $i ++) {
  7967. if ($moth == $i)
  7968. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7969. else
  7970. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7971. }
  7972. $dayHtml = "";
  7973. if ($day != "DAY" || $moth != "MONTH") {
  7974. for($i = 1; $i <= 31; $i ++) {
  7975. if ($day == $i)
  7976. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7977. else
  7978. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7979. }
  7980. }
  7981. $dateHtml = "";
  7982. $now = date ( "Y" );
  7983. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7984. if ($YEARD <= $now) {
  7985. $dateHtml .= '<option ';
  7986. if ($year == $YEARD) {
  7987. $dateHtml .= 'selected ';
  7988. }
  7989. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7990. }
  7991. }
  7992. $data ['dateHtml'] = $dateHtml;
  7993. $data ['page'] = $pageinfo;
  7994. $data ['year'] = $year;
  7995. $data ['moth'] = $moth;
  7996. $data ['day'] = $day;
  7997. $data ['get'] = $get;
  7998. $data ['dayHtml'] = $dayHtml;
  7999. $data ['mothHtml'] = $mothHtml;
  8000. $data ['receiptList'] = $dayList;
  8001. $data ['memu'] = "receipt";
  8002. $data ['staff'] = $this->staff;
  8003. $data ['receiptMemu'] = 'remittanceHky';
  8004. $data ['verifyId'] = $this->verifyId;
  8005. $data ['executeId'] = $this->executeId;
  8006. $this->render ( "/admin/remittanceHky", $data );
  8007. }
  8008. function remittancep() {
  8009. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8010. Doo::loadModel ( 'receipt' );
  8011. $receipt = new receipt ();
  8012. Doo::loadModel ( 'staff' );
  8013. $staff = new staff ();
  8014. Doo::loadClass ( 'XDeode' );
  8015. $XDeode = new XDeode ( 5 );
  8016. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8017. $rplist = $receipt->find ( array (
  8018. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8019. 'asArray' => true
  8020. ) );
  8021. $dayList = $receipt->find ( array (
  8022. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8023. 'desc' => 'executeDate',
  8024. 'groupby' => 'staff',
  8025. 'asArray' => true
  8026. ) );
  8027. $html = '';
  8028. foreach ( $dayList as $key => $value ) {
  8029. $sinfo = $staff->getOne ( array (
  8030. 'select' => 'username,category',
  8031. 'where' => ' sid=' . $value ['staff'],
  8032. 'asArray' => true
  8033. ) );
  8034. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8035. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8036. $au = 0;
  8037. foreach ( $rplist as $k => $v ) {
  8038. if ($value ['staff'] == $v ['staff']) {
  8039. $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>';
  8040. $au += $v ['amount'];
  8041. }
  8042. }
  8043. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8044. }
  8045. $data ['html'] = $html;
  8046. $data ['memu'] = "receipt";
  8047. $data ['staff'] = $this->staff;
  8048. $data ['receiptMemu'] = 'remittanceHky';
  8049. $data ['verifyId'] = $this->verifyId;
  8050. $data ['executeId'] = $this->executeId;
  8051. $this->render ( "/admin/remittancep", $data );
  8052. }
  8053. function ajaxGetReceiptDetails() {
  8054. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8055. Doo::loadClass ( 'XDeode' );
  8056. $XDeode = new XDeode ( 5 );
  8057. $rid = $XDeode->decode ( $rid );
  8058. if (empty ( $rid )) {
  8059. echo json_encode ( array (
  8060. 'status' => 2,
  8061. 'msg' => 'illegal request'
  8062. ) );
  8063. die ();
  8064. }
  8065. Doo::loadModel ( 'receipt' );
  8066. $receipt = new receipt ();
  8067. Doo::loadModel ( 'staff' );
  8068. $staff = new staff ();
  8069. $rinfo = $receipt->getOne ( array (
  8070. 'where' => 'rid= ' . $rid,
  8071. 'asArray' => true
  8072. ) );
  8073. $sinfo = $staff->getOne ( array (
  8074. 'select' => 'username,category',
  8075. 'where' => ' sid=' . $rinfo ['staff'],
  8076. 'asArray' => true
  8077. ) );
  8078. $rinfo ['reviseDetail'] = array ();
  8079. if (! empty ( $rinfo ['reviseDetail'] ))
  8080. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8081. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8082. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8083. $rinfo ['category'] = $sinfo ['category'];
  8084. $verifyStaff = array ();
  8085. if (! empty ( $rinfo ['verifyStaff'] ))
  8086. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8087. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8088. $rinfo ['relust'] = $relust;
  8089. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8090. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8091. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8092. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8093. // 费用执行人相关数据
  8094. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8095. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8096. foreach ( $executeCopy as $k => $v ) {
  8097. $executeCopy [$k] ['date'] = '';
  8098. $executeCopy [$k] ['opinion'] = '';
  8099. $executeCopy [$k] ['status'] = '';
  8100. if (! empty ( $executeStaff ))
  8101. foreach ( $executeStaff as $m => $u ) {
  8102. if ($v [0] == $m) {
  8103. $executeCopy [$k] ['date'] = $u ['date'];
  8104. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8105. $executeCopy [$k] ['status'] = $u ['status'];
  8106. break;
  8107. }
  8108. }
  8109. }
  8110. $rinfo ['executeCopy'] = $executeCopy;
  8111. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8112. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8113. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8114. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8115. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8116. $html .= '<tr><th>' . $value ['name'] . '</th>
  8117. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8118. }
  8119. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8120. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8121. <tr><th class="taC" colspan="2">费用说明</th>
  8122. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8123. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8124. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8125. </tbody></table>';
  8126. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8127. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8128. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8129. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8130. $html .= '<tr><th>' . $value ['name'] . '</th>
  8131. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8132. }
  8133. $html .= '<tr><th class="taR">合计</th>
  8134. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8135. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8136. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8137. $html .= '<tr><th>' . $value ['name'] . '</th>
  8138. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8139. }
  8140. $html .= '<tr><th class="taR">合计</th>
  8141. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8142. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8143. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8144. $html .= '<tr><th>' . $value ['name'] . '</th>
  8145. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8146. }
  8147. $html .= '<tr><th class="taR">合计</th>
  8148. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8149. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8150. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8151. $html .= '<tr><th>' . $value ['name'] . '</th>
  8152. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8153. }
  8154. $html .= '<tr><th class="taR">合计</th>
  8155. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8156. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8157. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8158. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8159. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8160. }
  8161. $html .= '<tr><th class="taR">合计</th>
  8162. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8163. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8164. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8165. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8166. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8167. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8168. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8169. <tr';
  8170. if ($rinfo ['relust'] >= 0) {
  8171. $html .= 'class="success"';
  8172. } else {
  8173. $html .= 'class="error"';
  8174. }
  8175. $html .= '><td class="taR"><b>借款结余</b></td>
  8176. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8177. </tbody></table>
  8178. ';
  8179. }
  8180. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8181. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8182. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8183. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8184. $html .= '<tr><th>' . $value ['name'] . '</th>
  8185. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8186. }
  8187. $html .= '<tr><th class="taR">合计</th>
  8188. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8189. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8190. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8191. <tr><th class="taC" colspan="2">费用说明</th>
  8192. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8193. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8194. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8195. </tbody></table>';
  8196. } else {
  8197. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8198. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8199. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8200. $html .= '<tr><th>' . $value ['name'] . '</th>
  8201. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8202. }
  8203. $html .= '<tr><th class="taR">合计</th>
  8204. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8205. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8206. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8207. $html .= '<tr><th>' . $value ['name'] . '</th>
  8208. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8209. }
  8210. $html .= '<tr><th class="taR">合计</th>
  8211. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8212. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8213. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8214. $html .= '<tr><th>' . $value ['name'] . '</th>
  8215. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8216. }
  8217. $html .= '<tr><th class="taR">合计</th>
  8218. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8219. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8220. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8221. $html .= '<tr><th>' . $value ['name'] . '</th>
  8222. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8223. }
  8224. $html .= '<tr><th class="taR">合计</th>
  8225. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8226. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8227. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8228. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8229. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8230. }
  8231. $html .= '<tr><th class="taR">合计</th>
  8232. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8233. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8234. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8235. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8236. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8237. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8238. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8239. $html .= '</tbody></table>';
  8240. /*
  8241. * <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>
  8242. */
  8243. }
  8244. // print_r($verifyStaff);die;
  8245. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8246. foreach ( $verifyStaff as $key => $value ) {
  8247. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8248. $sinfo = $staff->getOne ( array (
  8249. 'select' => 'username',
  8250. 'where' => ' sid=' . $key,
  8251. 'asArray' => true
  8252. ) );
  8253. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8254. }
  8255. $html .= '</tbody></table>';
  8256. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8257. foreach ( $rinfo ['executeCopy'] as $value ) {
  8258. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8259. }
  8260. $html .= '</tbody></table>';
  8261. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8262. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8263. </tr></table>';
  8264. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8265. echo json_encode ( array (
  8266. 'status' => 1,
  8267. 'html' => $html
  8268. ) );
  8269. die ();
  8270. }
  8271. /**
  8272. * 删除附件
  8273. */
  8274. function ajaxRemEnclousur() {
  8275. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8276. if (empty ( $key ))
  8277. echo json_encode ( array (
  8278. 'status' => 2
  8279. ) );
  8280. Doo::loadModel ( 'enclosur' );
  8281. $enclosur = new enclosur ();
  8282. $enclosur->delEnclosurByEid ( $key );
  8283. echo json_encode ( array (
  8284. 'status' => 1
  8285. ) );
  8286. }
  8287. function remittance() {
  8288. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8289. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8290. Doo::loadModel ( 'receipt' );
  8291. $receipt = new receipt ();
  8292. Doo::loadModel ( 'staff' );
  8293. $staff = new staff ();
  8294. $dateCondition = " and Year(pastDate) =" . $year;
  8295. if (! empty ( $month ))
  8296. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8297. // get Receipt By verifyID status 1
  8298. $receiptList = $receipt->find ( array (
  8299. 'select' => 'sum(sum) as sum,staff,pastDate',
  8300. 'where' => ' status=1' . $dateCondition,
  8301. 'desc' => 'pastDate',
  8302. 'groupby' => 'staff,pastDate',
  8303. 'asArray' => true
  8304. ) );
  8305. $dateList = $receipt->find ( array (
  8306. 'select' => 'pastDate,verifyStaff',
  8307. 'where' => ' status=1' . $dateCondition,
  8308. 'desc' => 'pastDate',
  8309. 'groupby' => 'pastDate',
  8310. 'asArray' => true
  8311. ) );
  8312. $dataList = array ();
  8313. foreach ( $dateList as $d => $a ) {
  8314. $dataList [$a ['pastDate']] = array ();
  8315. $daySum = 0;
  8316. foreach ( $receiptList as $key => $value ) {
  8317. if ($a ['pastDate'] == $value ['pastDate']) {
  8318. $oderList = $receipt->find ( array (
  8319. 'select' => 'receiptOrder',
  8320. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8321. 'asArray' => true
  8322. ) );
  8323. $list = array ();
  8324. $html = "";
  8325. foreach ( $oderList as $v ) {
  8326. array_push ( $list, $v ['receiptOrder'] );
  8327. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8328. }
  8329. $receiptList [$key] ['receiptOrder'] = $html;
  8330. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8331. $sinfo = $staff->getOne ( array (
  8332. 'select' => 'username ',
  8333. 'where' => ' sid=' . $value ['staff'],
  8334. 'asArray' => true
  8335. ) );
  8336. $receiptList [$key] ['username'] = $sinfo ['username'];
  8337. $daySum += $value ['sum'];
  8338. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8339. }
  8340. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8341. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8342. }
  8343. }
  8344. // print_r($dataList);
  8345. $data ['dataList'] = $dataList;
  8346. $mothHtml = "";
  8347. for($i = 1; $i <= 12; $i ++) {
  8348. if ($month == $i)
  8349. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8350. else
  8351. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8352. }
  8353. $data ['year'] = $year;
  8354. $data ['mothHtml'] = $mothHtml;
  8355. $data ['memu'] = "receipt";
  8356. $data ['staff'] = $this->staff;
  8357. $data ['receiptMemu'] = 'approval';
  8358. $data ['verifyId'] = $this->verifyId;
  8359. $data ['executeId'] = $this->executeId;
  8360. $this->render ( "/admin/saeaReportListPay", $data );
  8361. }
  8362. /**
  8363. * 金额调整,提高稳定性
  8364. * @return string
  8365. */
  8366. function revocationAdjustment() {
  8367. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8368. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8369. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8370. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8371. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8372. Doo::loadClass ( 'XDeode' );
  8373. $XDeode = new XDeode ( 5 );
  8374. Doo::loadModel ( 'receipt' );
  8375. $receipt = new receipt ();
  8376. $sid = $XDeode->decode ( $sidKey );
  8377. $rid = $XDeode->decode ( $ridKey );
  8378. $reviseKey = $XDeode->decode ( $reviseKey );
  8379. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8380. die ( 'illegal request' );
  8381. $receiptDetail = $receipt->getOne ( array (
  8382. 'where' => 'rid=' . $rid,
  8383. 'asArray' => true
  8384. ) );
  8385. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8386. die ( 'illegal request' );
  8387. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8388. if (! isset ( $reviseDetail [$reviseKey] ))
  8389. die ( 'illegal request' );
  8390. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8391. unset ( $reviseDetail [$reviseKey] );
  8392. $revisePrice = 0;
  8393. foreach ( $reviseDetail as $key => $value ) {
  8394. $revisePrice += $value ['price'];
  8395. }
  8396. $reviseDetailString = json_encode ( $reviseDetail );
  8397. $receipt->reviseDetail = $reviseDetailString;
  8398. $receipt->sum = $receiptDetail ['sum'] - $price;
  8399. $receipt->revisePrice = $revisePrice;
  8400. $receipt->update ( array (
  8401. 'where' => 'rid=' . $rid
  8402. ) );
  8403. return '/receiptburEdi/' . $rid;
  8404. } else
  8405. die ( 'illegal request2' );
  8406. }
  8407. function updateApprovalReceipt() {
  8408. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8409. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8410. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8411. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8412. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8413. if (! empty ( $rid )) {
  8414. Doo::loadModel ( "verify" );
  8415. $verify = new verify ();
  8416. Doo::loadModel ( "receiptDetail" );
  8417. $receiptDetailObj = new receiptDetail ();
  8418. Doo::loadModel ( "itemStatistics" );
  8419. Doo::loadModel ( "statistics" );
  8420. $statistics = new statistics ();
  8421. $itemStatistics = new itemStatistics ();
  8422. Doo::loadModel ( "receipt" );
  8423. $receipt = new receipt ();
  8424. $receiptDetail = $receipt->getOne ( array (
  8425. 'where' => 'rid=' . $rid . ' and status=2 ',
  8426. 'asArray' => true
  8427. ) );
  8428. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8429. $nsflag = true;
  8430. foreach ( $nslist as $value ) {
  8431. if ($value == $this->staff ['0'] ['sid']) {
  8432. $nsflag = false;
  8433. break;
  8434. }
  8435. }
  8436. if (empty ( $receiptDetail ) || $nsflag)
  8437. return "/approvalExpenses/pendApproval";
  8438. $verifyDetail = $verify->getOne ( array (
  8439. 'where' => ' vid =' . $receiptDetail ['verify'],
  8440. 'asArray' => true
  8441. ) );
  8442. $verifyString = $verifyDetail ['staff'];
  8443. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8444. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8445. if (empty ( $opinion )) {
  8446. if ($status == 3)
  8447. $opinion = "终止";
  8448. else
  8449. $opinion = "同意支付";
  8450. }
  8451. $nowStaff = 0;
  8452. $nowStaffList = array ();
  8453. if (empty ( $verifyStaff )) {
  8454. // 还需加入是否已经进入角色审批
  8455. if ($verifyDetail [0] [1] == 'ROLE') {
  8456. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8457. foreach ( $vStaffString as $key => $value ) {
  8458. $staffK = explode ( "_", $value );
  8459. if ($staffK [0] != $this->staff [0] ['sid'])
  8460. array_push ( $nowStaffList, $staffK [0] );
  8461. }
  8462. // print_r($verifyDetail);
  8463. // die;
  8464. if (! empty ( $nowStaffList )) {
  8465. $nowStaff = implode ( ',', $nowStaffList );
  8466. $verifyStaff = array (
  8467. $this->staff [0] ['sid'] . "_R" => array (
  8468. 'date' => date ( 'Y-m-d' ),
  8469. 'opinion' => $opinion,
  8470. 'status' => $status,
  8471. 'nextStaff' => $verifyDetail [0] [0],
  8472. 'ROLE' => 1
  8473. )
  8474. );
  8475. } else {
  8476. $nowStaff = $verifyDetail [1] [0];
  8477. $verifyStaff = array (
  8478. $this->staff [0] ['sid'] . "_R" => array (
  8479. 'date' => date ( 'Y-m-d' ),
  8480. 'opinion' => $opinion,
  8481. 'status' => $status,
  8482. 'nextStaff' => $verifyDetail [1] [0]
  8483. )
  8484. );
  8485. }
  8486. } else {
  8487. if ($verifyDetail [1] [1] == 'ROLE') {
  8488. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8489. // echo "dd";
  8490. foreach ( $vStaffString as $key => $value ) {
  8491. $staffK = explode ( "_", $value );
  8492. array_push ( $nowStaffList, $staffK [0] );
  8493. }
  8494. $nowStaff = implode ( ',', $nowStaffList );
  8495. $verifyStaff = array (
  8496. $this->staff [0] ['sid'] => array (
  8497. 'date' => date ( 'Y-m-d' ),
  8498. 'opinion' => $opinion,
  8499. 'status' => $status,
  8500. 'nextStaff' => $verifyDetail [1] [0],
  8501. 'ROLE' => 1
  8502. )
  8503. );
  8504. } else {
  8505. $nowStaff = $verifyDetail [1] [0];
  8506. $verifyStaff = array (
  8507. $this->staff [0] ['sid'] => array (
  8508. 'date' => date ( 'Y-m-d' ),
  8509. 'opinion' => $opinion,
  8510. 'status' => $status,
  8511. 'nextStaff' => $verifyDetail [1] [0]
  8512. )
  8513. );
  8514. }
  8515. }
  8516. if ($status == 3)
  8517. $verifyStaff = array (
  8518. 'final' => $status,
  8519. $this->staff [0] ['sid'] => array (
  8520. 'date' => date ( 'Y-m-d' ),
  8521. 'opinion' => $opinion,
  8522. 'status' => $status
  8523. )
  8524. );
  8525. $vStaffString = json_encode ( $verifyStaff );
  8526. $receipt->nowStaff = $nowStaff;
  8527. $receipt->verifyStaff = $vStaffString;
  8528. } else {
  8529. $VS = end ( $verifyStaff );
  8530. // 非角色审批
  8531. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8532. $nextStaff = 0;
  8533. $roleSTF = false;
  8534. foreach ( $verifyDetail as $key => $value ) {
  8535. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8536. if (isset ( $verifyDetail [$key + 1] )) {
  8537. $nextStaff = $verifyDetail [$key + 1] [0];
  8538. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8539. $roleSTF = true;
  8540. }
  8541. break;
  8542. }
  8543. }
  8544. if (! $roleSTF) {
  8545. $nowStaff = $nextStaff;
  8546. $verifyStaff [$this->staff [0] ['sid']] = array (
  8547. 'date' => date ( 'Y-m-d' ),
  8548. 'opinion' => $opinion,
  8549. 'status' => $status,
  8550. 'nextStaff' => $nextStaff
  8551. );
  8552. } else {
  8553. // 获取角色下的所有用户ID
  8554. $nowStaffList = array ();
  8555. foreach ( $verifyDetail as $vfk ) {
  8556. if ($vfk [1] == 'ROLE') {
  8557. $vStaffString = json_decode ( $vfk [3] );
  8558. foreach ( $vStaffString as $key => $value ) {
  8559. $staffK = explode ( "_", $value );
  8560. array_push ( $nowStaffList, $staffK [0] );
  8561. }
  8562. }
  8563. }
  8564. $nowStaff = implode ( ',', $nowStaffList );
  8565. $verifyStaff [$this->staff [0] ['sid']] = array (
  8566. 'date' => date ( 'Y-m-d' ),
  8567. 'opinion' => $opinion,
  8568. 'status' => $status,
  8569. 'nextStaff' => $nextStaff,
  8570. 'ROLE' => 0
  8571. );
  8572. }
  8573. if ($status == 3) {
  8574. $verifyStaff ['final'] = $status;
  8575. $verifyStaff [$this->staff [0] ['sid']] = array (
  8576. 'date' => date ( 'Y-m-d' ),
  8577. 'opinion' => $opinion,
  8578. 'status' => $status
  8579. );
  8580. }
  8581. $vStaffString = json_encode ( $verifyStaff );
  8582. $receipt->nowStaff = $nowStaff;
  8583. $receipt->verifyStaff = $vStaffString;
  8584. }
  8585. // 角色审批
  8586. if (isset ( $VS ['ROLE'] )) {
  8587. // 找出角色人 当前审批角色组
  8588. $verifyJSStaff = array ();
  8589. $nowStaffList2 = array ();
  8590. foreach ( $verifyDetail as $key => $value ) {
  8591. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8592. $verifyJSStaff = json_decode ( $value [3] );
  8593. foreach ( $verifyJSStaff as $m ) {
  8594. $staffK = explode ( "_", $m );
  8595. array_push ( $nowStaffList2, $staffK [0] );
  8596. }
  8597. // print_r($nowStaffList2);
  8598. }
  8599. }
  8600. $RoleVerifyStaff = array ();
  8601. foreach ( $verifyStaff as $key => $value ) {
  8602. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8603. foreach ( $nowStaffList2 as $m ) {
  8604. if ($key == $m . "_R")
  8605. $RoleVerifyStaff [$key] = $value;
  8606. }
  8607. }
  8608. }
  8609. // print_r($verifyStaff);
  8610. // print_r($nowStaffList2);
  8611. // print_r($RoleVerifyStaff);
  8612. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8613. // print_r($verifyJSStaff);
  8614. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8615. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8616. // 下一个审批人ID
  8617. $nextStaff = 0;
  8618. $falg = false;
  8619. foreach ( $verifyDetail as $key => $value ) {
  8620. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8621. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8622. $falg = true;
  8623. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8624. $nowStaffList = array ();
  8625. foreach ( $vStaffString as $v ) {
  8626. $staffK = explode ( "_", $v );
  8627. array_push ( $nowStaffList, $staffK [0] );
  8628. }
  8629. $nowStaff = implode ( ',', $nowStaffList );
  8630. $nextStaff = $verifyDetail [$key + 1] [0];
  8631. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8632. $nextStaff = $verifyDetail [$key + 1] [0];
  8633. $nowStaff = $nextStaff;
  8634. } else
  8635. $nowStaff = '';
  8636. break;
  8637. }
  8638. }
  8639. if ($falg)
  8640. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8641. 'date' => date ( 'Y-m-d' ),
  8642. 'opinion' => $opinion,
  8643. 'status' => $status,
  8644. 'nextStaff' => $nextStaff,
  8645. 'ROLE' => 1
  8646. );
  8647. else
  8648. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8649. 'date' => date ( 'Y-m-d' ),
  8650. 'opinion' => $opinion,
  8651. 'status' => $status,
  8652. 'nextStaff' => $nextStaff
  8653. );
  8654. // print_r($verifyStaff);
  8655. // echo $nowStaff;die;
  8656. } else { // 进入下一个角色或者审批人
  8657. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8658. //
  8659. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8660. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8661. 'date' => date ( 'Y-m-d' ),
  8662. 'opinion' => $opinion,
  8663. 'status' => $status,
  8664. 'nextStaff' => $VS ['nextStaff'],
  8665. 'ROLE' => 1
  8666. );
  8667. // print_r($verifyStaff);
  8668. // die;
  8669. }
  8670. if ($status == 3) {
  8671. $verifyStaff ['final'] = $status;
  8672. $verifyStaff [$this->staff [0] ['sid']] = array (
  8673. 'date' => date ( 'Y-m-d' ),
  8674. 'opinion' => $opinion,
  8675. 'status' => $status
  8676. );
  8677. }
  8678. $vStaffString = json_encode ( $verifyStaff );
  8679. $receipt->verifyStaff = $vStaffString;
  8680. $receipt->nowStaff = $nowStaff;
  8681. // die;
  8682. // }
  8683. // print_r($verifyStaff);
  8684. // die;
  8685. }
  8686. // print_r($verifyStaff);die;
  8687. }
  8688. // print_r($verifyDetail);
  8689. $roleKey = 0;
  8690. $roleId = 0;
  8691. $verifyDetailCopy = array ();
  8692. foreach ( $verifyDetail as $k => $v ) {
  8693. if ($v [1] == 'ROLE') {
  8694. $roleId = $v [0];
  8695. $roleVerify = json_decode ( $v [3], true );
  8696. $roleKey = $k;
  8697. $roleArray = array ();
  8698. foreach ( $roleVerify as $o => $p ) {
  8699. $staffID = explode ( '_', $p );
  8700. $exp = array (
  8701. 0 => $staffID [0],
  8702. 1 => $staffID [1]
  8703. );
  8704. array_push ( $roleArray, $exp );
  8705. }
  8706. $verifyDetailCopy [$v [0]] = $roleArray;
  8707. }
  8708. }
  8709. // print_r($verifyDetail);
  8710. foreach ( $verifyDetailCopy as $k => $v ) {
  8711. foreach ( $verifyDetail as $m => $n ) {
  8712. if ($n [0] == $k) {
  8713. array_splice ( $verifyDetail, $m, 1, $v );
  8714. }
  8715. }
  8716. }
  8717. // die;
  8718. // if (!empty($roleArray))
  8719. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8720. // echo $roleId;
  8721. // print_r($verifyStaff);
  8722. // print_r($verifyDetail);
  8723. // die;
  8724. Doo::loadModel ( "receiptLog" );
  8725. $receiptLog = new receiptLog ();
  8726. // 审批日志
  8727. if (! isset ( $verifyStaff ['final'] )) {
  8728. if (! empty ( $roleId )) {
  8729. Doo::loadModel ( "role" );
  8730. $role = new role ();
  8731. $roleInfo = $role->getOne ( array (
  8732. 'where' => 'rid=' . $roleId,
  8733. 'asArray' => true
  8734. ) );
  8735. $receiptLog->rolename = $roleInfo ['name'];
  8736. }
  8737. $receiptLog->username = $this->staff [0] ['username'];
  8738. $receiptLog->uid = $this->staff [0] ['sid'];
  8739. $receiptLog->date = date ( "Y-m-d" );
  8740. $receiptLog->opinion = $opinion;
  8741. $receiptLog->img = $this->staff [0] ['avatar'];
  8742. $receiptLog->status = 1;
  8743. $receiptLog->rid = $rid;
  8744. $receiptLog->insert ();
  8745. }
  8746. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8747. $receipt->verifyBreakup = $verifyString;
  8748. $receipt->status = 3;
  8749. $receiptDetailObj->status = 3;
  8750. $receiptDetailObj->update ( array (
  8751. 'where' => 'rid=' . $rid
  8752. ) );
  8753. if (! empty ( $roleId )) {
  8754. Doo::loadModel ( "role" );
  8755. $role = new role ();
  8756. $roleInfo = $role->getOne ( array (
  8757. 'where' => 'rid=' . $roleId,
  8758. 'asArray' => true
  8759. ) );
  8760. $receiptLog->rolename = $roleInfo ['name'];
  8761. }
  8762. $receiptLog->username = $this->staff [0] ['username'];
  8763. $receiptLog->uid = $this->staff [0] ['sid'];
  8764. $receiptLog->date = date ( "Y-m-d" );
  8765. $receiptLog->opinion = $opinion;
  8766. $receiptLog->img = $this->staff [0] ['avatar'];
  8767. $receiptLog->status = 3;
  8768. $receiptLog->rid = $rid;
  8769. $receiptLog->insert ();
  8770. // 微信企业号通知
  8771. $this->setWXMsg ( $rid, 3 );
  8772. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8773. $receipt->status = 1;
  8774. $reviseSum = 0;
  8775. $receipt->verifyBreakup = $verifyString;
  8776. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8777. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8778. foreach ( $reviseDetail as $key => $value ) {
  8779. $receiptDetailObj = new receiptDetail ();
  8780. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8781. $receiptDetailObj->item = $value ['description'];
  8782. $receiptDetailObj->itemCategory = "报销金额调整";
  8783. $receiptDetailObj->price = $value ['price'];
  8784. $receiptDetailObj->date = $receiptDetail ['date'];
  8785. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8786. $receiptDetailObj->rid = $rid;
  8787. $receiptDetailObj->status = 1;
  8788. $receiptDetailObj->insert ();
  8789. $reviseSum += $value ['price'];
  8790. }
  8791. $itemStatistics = new itemStatistics ();
  8792. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8793. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8794. $itemStatistics->price = $reviseSum;
  8795. $itemStatistics->itemCategory = "报销金额调整";
  8796. $itemStatistics->date = $receiptDetail ['date'];
  8797. $itemStatistics->insert ();
  8798. }
  8799. $receiptDetailObj = new receiptDetail ();
  8800. $receiptDetailObj->status = 1;
  8801. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8802. $receiptDetailObj->update ( array (
  8803. 'where' => 'rid=' . $rid
  8804. ) );
  8805. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8806. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8807. $stat = $statistics->getOne ( array (
  8808. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8809. 'asArray' => true
  8810. ) );
  8811. if (empty ( $stat )) {
  8812. $statistics->date = $receiptDetail ['date'];
  8813. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8814. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8815. $statistics->agPrice = $receiptDetail ['sum'];
  8816. $statistics->rePrice = $reviseSum;
  8817. $statistics->insert ();
  8818. } else {
  8819. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8820. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8821. $statistics->update ( array (
  8822. 'where' => 'sid=' . $stat ['sid']
  8823. ) );
  8824. }
  8825. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8826. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8827. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8828. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8829. if ($key == "agencySum") {
  8830. $iStatistics = $itemStatistics->getOne ( array (
  8831. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8832. 'asArray' => true
  8833. ) );
  8834. if (empty ( $iStatistics )) {
  8835. $itemStatistics->cid = $receiptDetail ['cid'];
  8836. ;
  8837. $itemStatistics->staff = $receiptDetail ['staff'];
  8838. $itemStatistics->price = $value;
  8839. $itemStatistics->itemCategory = $this->AGENCY;
  8840. $itemStatistics->date = $receiptDetail ['date'];
  8841. $itemStatistics->insert ();
  8842. } else {
  8843. if (! empty ( $value )) {
  8844. $itemStatistics->price = $value + $iStatistics ['price'];
  8845. $itemStatistics->update ( array (
  8846. 'where' => 'sid=' . $iStatistics ['sid']
  8847. ) );
  8848. }
  8849. }
  8850. } elseif ($key == "travelSum") {
  8851. $iStatistics = $itemStatistics->getOne ( array (
  8852. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8853. 'asArray' => true
  8854. ) );
  8855. if (empty ( $iStatistics )) {
  8856. $itemStatistics->cid = $receiptDetail ['cid'];
  8857. $itemStatistics->staff = $receiptDetail ['staff'];
  8858. $itemStatistics->price = $value;
  8859. $itemStatistics->itemCategory = $this->TRAVEL;
  8860. $itemStatistics->date = $receiptDetail ['date'];
  8861. $itemStatistics->insert ();
  8862. } else {
  8863. if (! empty ( $value )) {
  8864. $itemStatistics->price = $value + $iStatistics ['price'];
  8865. $itemStatistics->update ( array (
  8866. 'where' => 'sid=' . $iStatistics ['sid']
  8867. ) );
  8868. }
  8869. }
  8870. } elseif ($key == "trainSum") {
  8871. $iStatistics = $itemStatistics->getOne ( array (
  8872. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8873. 'asArray' => true
  8874. ) );
  8875. if (empty ( $iStatistics )) {
  8876. $itemStatistics->cid = $receiptDetail ['cid'];
  8877. $itemStatistics->staff = $receiptDetail ['staff'];
  8878. $itemStatistics->price = $value;
  8879. $itemStatistics->itemCategory = $this->TRAIN;
  8880. $itemStatistics->date = $receiptDetail ['date'];
  8881. $itemStatistics->insert ();
  8882. } else {
  8883. if (! empty ( $value )) {
  8884. $itemStatistics->price = $value + $iStatistics ['price'];
  8885. $itemStatistics->update ( array (
  8886. 'where' => 'sid=' . $iStatistics ['sid']
  8887. ) );
  8888. }
  8889. }
  8890. } elseif ($key == "otherSum") {
  8891. $iStatistics = $itemStatistics->getOne ( array (
  8892. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8893. 'asArray' => true
  8894. ) );
  8895. if (empty ( $iStatistics )) {
  8896. $itemStatistics->cid = $receiptDetail ['cid'];
  8897. $itemStatistics->staff = $receiptDetail ['staff'];
  8898. $itemStatistics->price = $value;
  8899. $itemStatistics->itemCategory = $this->OTHER;
  8900. $itemStatistics->date = $receiptDetail ['date'];
  8901. $itemStatistics->insert ();
  8902. } else {
  8903. if (! empty ( $value )) {
  8904. $itemStatistics->price = $value + $iStatistics ['price'];
  8905. $itemStatistics->update ( array (
  8906. 'where' => 'sid=' . $iStatistics ['sid']
  8907. ) );
  8908. }
  8909. }
  8910. }
  8911. }
  8912. $receipt->pastDate = date ( "Y-m-d" );
  8913. // 微信企业号通知
  8914. $this->setWXMsg ( $rid, 1 );
  8915. }
  8916. //是否有流水
  8917. Doo::loadModel ( 'wasteBook' );
  8918. $wasteBook = new wasteBook ();
  8919. $accountType=3;
  8920. if ($receiptDetail['Rtype']==1){
  8921. $accountType=2;
  8922. }elseif($receiptDetail['Rtype']==2){
  8923. $accountType=4;
  8924. }
  8925. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8926. if (empty($wbDetail)){
  8927. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  8928. $receipt->amount = $rsum;//$amount;
  8929. }
  8930. $receipt->update ( array (
  8931. 'where' => ' rid = ' . $rid
  8932. ) );
  8933. // 进入下一条审批费用新加需求
  8934. $vidList = array ();
  8935. $verifyDetail = $verify->find ( array (
  8936. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8937. 'asArray' => true
  8938. ) );
  8939. foreach ( $verifyDetail as $key => $value ) {
  8940. array_push ( $vidList, $value ['vid'] );
  8941. }
  8942. $vid = implode ( ",", $vidList );
  8943. if (empty ( $verifyDetail ))
  8944. $vid = 0;
  8945. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8946. $receipt = new receipt ();
  8947. $rd = $receipt->getOne ( array (
  8948. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8949. 'asc' => 'rid',
  8950. 'asArray' => true
  8951. ) );
  8952. if (empty ( $rd )) {
  8953. return '/approvalExpenses/pendApproval';
  8954. }
  8955. if ($rd ['Rtype'] == 1) {
  8956. if ($rd ['isBK'] == 1) {
  8957. return '/receiptburEdi/' . $rd ['rid'];
  8958. } else {
  8959. return '/expensesEdi/' . $rd ['rid'];
  8960. }
  8961. } elseif ($rd ['Rtype'] == 2) {
  8962. return '/remitApproval/' . $rd ['rid'];
  8963. } else {
  8964. return '/receiptburEdi/' . $rd ['rid'];
  8965. }
  8966. // return "/approvalExpenses/pendApproval";
  8967. }
  8968. }
  8969. function expensesRetreats() {
  8970. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8971. if (! empty ( $rid )) {
  8972. // 操作记录
  8973. Doo::loadModel ( "receipt" );
  8974. $receipt = new receipt ();
  8975. Doo::loadModel ( "receiptLog" );
  8976. $receiptLog = new receiptLog ();
  8977. Doo::loadModel ( "verify" );
  8978. $verify = new verify ();
  8979. $receiptInfo = $receipt->getOne ( array (
  8980. 'where' => 'rid=' . $rid,
  8981. 'asArray' => true
  8982. ) );
  8983. $vr = $verify->getOne ( array (
  8984. 'where' => 'vid=' . $receiptInfo ['verify'],
  8985. 'asArray' => true
  8986. ) );
  8987. $jd = json_decode ( $vr ['staff'] );
  8988. $roleId = 0;
  8989. foreach ( $jd as $key => $value ) {
  8990. if ($value [1] == 'ROLE') {
  8991. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8992. if ($pos !== false) {
  8993. $roleId = $value [0];
  8994. }
  8995. }
  8996. }
  8997. // 审批日志
  8998. // echo $roleId;die;
  8999. if (! empty ( $roleId )) {
  9000. Doo::loadModel ( "role" );
  9001. $role = new role ();
  9002. $roleInfo = $role->getOne ( array (
  9003. 'where' => 'rid=' . $roleId,
  9004. 'asArray' => true
  9005. ) );
  9006. $receiptLog->rolename = $roleInfo ['name'];
  9007. }
  9008. $receiptLog->username = $this->staff [0] ['username'];
  9009. $receiptLog->uid = $this->staff [0] ['sid'];
  9010. $receiptLog->date = date ( "Y-m-d" );
  9011. $receiptLog->opinion = '撤回';
  9012. $receiptLog->img = $this->staff [0] ['avatar'];
  9013. $receiptLog->status = 4;
  9014. $receiptLog->rid = $rid;
  9015. $receiptLog->insert ();
  9016. $receipt->status = 4;
  9017. $receipt->update ( array (
  9018. 'where' => 'rid=' . $rid
  9019. ) );
  9020. // 微信企业号通知
  9021. $this->setWXMsg ( $rid, 2 );
  9022. }
  9023. // echo "ddd";
  9024. return '/approvalExpenses/pendApproval';
  9025. }
  9026. function updateCheReceipt() {
  9027. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9028. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9029. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9030. if (! empty ( $rid )) {
  9031. // 操作记录
  9032. Doo::loadModel ( "receipt" );
  9033. $receipt = new receipt ();
  9034. Doo::loadModel ( "receiptLog" );
  9035. $receiptLog = new receiptLog ();
  9036. Doo::loadModel ( "verify" );
  9037. $verify = new verify ();
  9038. $receiptInfo = $receipt->getOne ( array (
  9039. 'where' => 'rid=' . $rid . ' and status=2',
  9040. 'asArray' => true
  9041. ) );
  9042. if (empty ( $receiptInfo )) {
  9043. echo json_encode ( array (
  9044. 'status' => 2
  9045. ) );
  9046. die ();
  9047. }
  9048. $vr = $verify->getOne ( array (
  9049. 'where' => 'vid=' . $receiptInfo ['verify'],
  9050. 'asArray' => true
  9051. ) );
  9052. $jd = json_decode ( $vr ['staff'] );
  9053. $roleId = 0;
  9054. foreach ( $jd as $key => $value ) {
  9055. if ($value [1] == 'ROLE') {
  9056. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9057. if ($pos !== false) {
  9058. $roleId = $value [0];
  9059. }
  9060. }
  9061. }
  9062. // 审批日志
  9063. // echo $roleId;die;
  9064. if (! empty ( $roleId )) {
  9065. Doo::loadModel ( "role" );
  9066. $role = new role ();
  9067. $roleInfo = $role->getOne ( array (
  9068. 'where' => 'rid=' . $roleId,
  9069. 'asArray' => true
  9070. ) );
  9071. $receiptLog->rolename = $roleInfo ['name'];
  9072. }
  9073. $receiptLog->username = $this->staff [0] ['username'];
  9074. $receiptLog->uid = $this->staff [0] ['sid'];
  9075. $receiptLog->date = date ( "Y-m-d" );
  9076. $receiptLog->opinion = $opinion;
  9077. $receiptLog->img = $this->staff [0] ['avatar'];
  9078. $receiptLog->status = 4;
  9079. $receiptLog->rid = $rid;
  9080. $receiptLog->insert ();
  9081. $receipt->status = 4;
  9082. $receipt->update ( array (
  9083. 'where' => 'rid=' . $rid
  9084. ) );
  9085. // 微信企业号通知
  9086. $this->setWXMsg ( $rid, 2 );
  9087. echo json_encode ( array (
  9088. 'status' => 1
  9089. ) );
  9090. // Header("HTTP/1.1 303 See Other");
  9091. // Header("Location: /approvalExpenses/pendApproval");
  9092. die ();
  9093. }
  9094. echo json_encode ( array (
  9095. 'status' => 2
  9096. ) );
  9097. die ();
  9098. // echo "ddd";
  9099. // return '/saeaBorad';
  9100. }
  9101. function revisePrice() {
  9102. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9103. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9104. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9105. // echo $price;die;
  9106. if (! empty ( $rid )) {
  9107. Doo::loadModel ( "receipt" );
  9108. $receipt = new receipt ();
  9109. $receiptDetail = $receipt->getOne ( array (
  9110. 'where' => 'rid=' . $rid . ' and status=2 ',
  9111. 'asArray' => true
  9112. ) );
  9113. if (empty ( $receiptDetail ))
  9114. die ( 'illegal request' );
  9115. $reviseDetail = array ();
  9116. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9117. array_push ( $reviseDetail, array (
  9118. 'sid' => $this->staff [0] ['sid'],
  9119. 'name' => $this->staff [0] ['username'],
  9120. 'description' => $description,
  9121. 'price' => $price
  9122. ) );
  9123. $reviseDetailString = json_encode ( $reviseDetail );
  9124. $receipt->reviseDetail = $reviseDetailString;
  9125. $receipt->revisePrice = $price;
  9126. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9127. } else {
  9128. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9129. array_push ( $reviseDetail, array (
  9130. 'sid' => $this->staff [0] ['sid'],
  9131. 'name' => $this->staff [0] ['username'],
  9132. 'description' => $description,
  9133. 'price' => $price
  9134. ) );
  9135. $reviseDetailString = json_encode ( $reviseDetail );
  9136. $receipt->reviseDetail = $reviseDetailString;
  9137. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9138. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9139. }
  9140. $receipt->update ( array (
  9141. 'where' => 'rid=' . $rid
  9142. ) );
  9143. if ($receiptDetail ['Rtype'] == 1) {
  9144. if ($receiptDetail ['isBK'] == 1) {
  9145. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9146. }
  9147. } elseif ($receiptDetail ['Rtype'] == 2) {
  9148. } else {
  9149. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9150. }
  9151. }
  9152. die ( 'illegal request' );
  9153. }
  9154. function personalCollect() {
  9155. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9156. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9157. $this->showCache ( $path );
  9158. Doo::loadModel ( "receiptDetail" );
  9159. Doo::loadModel ( "itemStatistics" );
  9160. Doo::loadModel ( 'statistics' );
  9161. $statistics = new statistics ();
  9162. $itemStatistics = new itemStatistics ();
  9163. $receiptDetail = new receiptDetail ();
  9164. $receiptCollectList = $receiptDetail->find ( array (
  9165. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9166. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9167. 'groupby' => 'itemCategory,Month(date)',
  9168. 'asArray' => true
  9169. ) );
  9170. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9171. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9172. 'asArray' => true
  9173. ) );
  9174. // create collect html
  9175. $collectArray = array (
  9176. '日常相关费用' => array (),
  9177. '差旅相关费用' => array (),
  9178. '培训班费用' => array (),
  9179. '其他' => array ()
  9180. );
  9181. $adjustment = array ();
  9182. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9183. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9184. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9185. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9186. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9187. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9188. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9189. array_push ( $collectArray ['其他'], $collectHtml );
  9190. $data ['collectArray'] = $collectArray;
  9191. // statistics html
  9192. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9193. if (empty ( $stList ))
  9194. $stList = array (
  9195. 'rePrice' => 0,
  9196. 'agPrice' => 0
  9197. );
  9198. $data ['stList'] = array (
  9199. 'rePrice' => $stList ['rePrice'],
  9200. 'agPrice' => $stList ['agPrice'],
  9201. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9202. );
  9203. // Adjustment price html
  9204. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9205. array_push ( $adjustment, $collectHtml );
  9206. $data ['adjustment'] = $adjustment;
  9207. // total price html
  9208. $collectHtml = "";
  9209. $total = 0;
  9210. for($i = 1; $i <= 12; $i ++) {
  9211. $sumPrice = 0;
  9212. foreach ( $receiptCollectList as $key => $value ) {
  9213. if ($value ['month'] == $i) {
  9214. $sumPrice += $value ['price'];
  9215. }
  9216. }
  9217. if ($sumPrice == 0)
  9218. $collectHtml .= '<td class="taR">-</td>';
  9219. else
  9220. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9221. $total += $sumPrice;
  9222. }
  9223. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9224. $data ['totalPrice'] = $collectHtml;
  9225. $dateHtml = "";
  9226. $now = date ( "Y" );
  9227. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9228. if ($YEARD <= $now) {
  9229. $dateHtml .= '<option ';
  9230. if ($year == $YEARD) {
  9231. $dateHtml .= 'selected ';
  9232. }
  9233. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9234. }
  9235. }
  9236. $data ['dateHtml'] = $dateHtml;
  9237. $data ['year'] = $year;
  9238. $data ['totalYear'] = $total;
  9239. $data ['memu'] = "receipt";
  9240. $data ['staff'] = $this->staff;
  9241. $data ['receiptMemu'] = 'personalCollect';
  9242. $data ['verifyId'] = $this->verifyId;
  9243. $data ['executeId'] = $this->executeId;
  9244. // year staff status 2,4
  9245. if ($year < date ( "Y" )) {
  9246. Doo::loadModel ( 'receipt' );
  9247. $receipt = new receipt ();
  9248. $receiptList = $receipt->find ( array (
  9249. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9250. 'asArray' => true
  9251. ) );
  9252. if (empty ( $receiptList )) {
  9253. ob_start ();
  9254. $this->render ( "/admin/saea_slist_collect", $data );
  9255. $this->cacheFile ( $path );
  9256. die ();
  9257. }
  9258. }
  9259. $this->render ( "/admin/saea_slist_collect", $data );
  9260. }
  9261. function personalCollectDetail() {
  9262. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9263. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9264. $this->showCache ( $path );
  9265. Doo::loadModel ( "receiptDetail" );
  9266. Doo::loadModel ( "itemStatistics" );
  9267. Doo::loadModel ( 'statistics' );
  9268. Doo::loadModel ( 'accountItem' );
  9269. $accountItem = new accountItem ();
  9270. $statistics = new statistics ();
  9271. $itemStatistics = new itemStatistics ();
  9272. $receiptDetail = new receiptDetail ();
  9273. $receiptCollectList = $receiptDetail->find ( array (
  9274. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9275. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9276. 'groupby' => 'item,Month(date)',
  9277. 'asArray' => true
  9278. ) );
  9279. $accountList = $accountItem->find ( array (
  9280. 'asArray' => true
  9281. ) );
  9282. // create CollectDetail HTML
  9283. $collectHtml = array ();
  9284. foreach ( $accountList as $key => $value ) {
  9285. $html = "";
  9286. $asum = 0;
  9287. for($i = 1; $i <= 12; $i ++) {
  9288. $falg = true;
  9289. foreach ( $receiptCollectList as $v ) {
  9290. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9291. $asum += $v ['price'];
  9292. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9293. $falg = false;
  9294. break;
  9295. }
  9296. }
  9297. if ($falg)
  9298. $html .= '<td class="taR">-</td>';
  9299. }
  9300. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9301. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9302. }
  9303. $data ['collectHtml'] = $collectHtml;
  9304. // create Adjustment price html
  9305. $receiptCollectList = $receiptDetail->find ( array (
  9306. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9307. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9308. 'groupby' => 'itemCategory,Month(date)',
  9309. 'asArray' => true
  9310. ) );
  9311. $adjustment = array ();
  9312. $collectArray = array (
  9313. '日常相关费用' => array (),
  9314. '差旅相关费用' => array (),
  9315. '培训班费用' => array (),
  9316. '其他' => array ()
  9317. );
  9318. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9319. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9320. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9321. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9322. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9323. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9324. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9325. array_push ( $collectArray ['其他'], $collectHtml );
  9326. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9327. array_push ( $adjustment, $collectHtml );
  9328. // total price html
  9329. $collectHtml = "";
  9330. $total = 0;
  9331. for($i = 1; $i <= 12; $i ++) {
  9332. $sumPrice = 0;
  9333. foreach ( $receiptCollectList as $key => $value ) {
  9334. if ($value ['month'] == $i) {
  9335. $sumPrice += $value ['price'];
  9336. }
  9337. }
  9338. if ($sumPrice == 0)
  9339. $collectHtml .= '<td class="taR">-</td>';
  9340. else
  9341. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9342. $total += $sumPrice;
  9343. }
  9344. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9345. // statistics html
  9346. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9347. if (empty ( $stList ))
  9348. $stList = array (
  9349. 'rePrice' => 0,
  9350. 'agPrice' => 0
  9351. );
  9352. $data ['stList'] = array (
  9353. 'rePrice' => $stList ['rePrice'],
  9354. 'agPrice' => $stList ['agPrice'],
  9355. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9356. );
  9357. $data ['collectArray'] = $collectArray;
  9358. $data ['adjustment'] = $adjustment;
  9359. $data ['totalPrice'] = $collectHtml;
  9360. $data ['totalYear'] = $total;
  9361. $data ['year'] = $year;
  9362. $dateHtml = "";
  9363. $now = date ( "Y" );
  9364. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9365. if ($YEARD <= $now) {
  9366. $dateHtml .= '<option ';
  9367. if ($year == $YEARD) {
  9368. $dateHtml .= 'selected ';
  9369. }
  9370. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9371. }
  9372. }
  9373. $data ['dateHtml'] = $dateHtml;
  9374. $data ['memu'] = "receipt";
  9375. $data ['staff'] = $this->staff;
  9376. $data ['receiptMemu'] = 'personalCollect';
  9377. $data ['verifyId'] = $this->verifyId;
  9378. $data ['executeId'] = $this->executeId;
  9379. // year staff status 2,4
  9380. if ($year < date ( "Y" )) {
  9381. Doo::loadModel ( 'receipt' );
  9382. $receipt = new receipt ();
  9383. $receiptList = $receipt->find ( array (
  9384. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9385. 'asArray' => true
  9386. ) );
  9387. if (empty ( $receiptList )) {
  9388. ob_start ();
  9389. $this->render ( "/admin/saeaCollectArticles", $data );
  9390. $this->cacheFile ( $path );
  9391. die ();
  9392. }
  9393. }
  9394. $this->render ( "/admin/saeaCollectArticles", $data );
  9395. }
  9396. function companyCategoryCollect() {
  9397. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9398. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9399. $this->showCache ( $path );
  9400. Doo::loadModel ( 'L_category' );
  9401. Doo::loadModel ( 'itemStatistics' );
  9402. Doo::loadModel ( 'statistics' );
  9403. $statistics = new statistics ();
  9404. $Lcategory = new L_category ();
  9405. $itemStatistics = new itemStatistics ();
  9406. Doo::loadModel ( "receiptAuthorityManage" );
  9407. $receiptAuthorityManage = new receiptAuthorityManage ();
  9408. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9409. $cidList = array ();
  9410. foreach ( $imcStaff as $key => $value ) {
  9411. array_push ( $cidList, $value ['cid'] );
  9412. }
  9413. $cidString = implode ( ',', $cidList );
  9414. $LcategoryList = $Lcategory->find ( array (
  9415. 'where' => ' cid in (' . $cidString . ')',
  9416. 'asArray' => true
  9417. ) ); // 'staff='.$this->staff[0]['sid']." and
  9418. $itemStatisticsList = $itemStatistics->find ( array (
  9419. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9420. 'where' => " Year(date)=" . $year,
  9421. 'groupby' => 'cid,Month(date)',
  9422. 'asArray' => true
  9423. ) );
  9424. // ceatre companyCollectHtml
  9425. foreach ( $LcategoryList as $value ) {
  9426. $html = "";
  9427. $asum = 0;
  9428. for($i = 1; $i <= 12; $i ++) {
  9429. $falg = true;
  9430. foreach ( $itemStatisticsList as $v ) {
  9431. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9432. $asum += $v ['price'];
  9433. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9434. $falg = false;
  9435. break;
  9436. }
  9437. }
  9438. if ($falg)
  9439. $html .= '<td class="taR">-</td>';
  9440. }
  9441. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9442. $collectHtml [$value ['title']] = array (
  9443. 'html' => $html,
  9444. 'cid' => $value ['cid']
  9445. );
  9446. }
  9447. $data ['companyHtml'] = $collectHtml;
  9448. // total price html
  9449. $collectHtml = "";
  9450. $total = 0;
  9451. for($i = 1; $i <= 12; $i ++) {
  9452. $sumPrice = 0;
  9453. foreach ( $itemStatisticsList as $key => $value ) {
  9454. if ($value ['month'] == $i) {
  9455. $sumPrice += $value ['price'];
  9456. }
  9457. }
  9458. if ($sumPrice == 0)
  9459. $collectHtml .= '<td class="taR">-</td>';
  9460. else
  9461. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9462. $total += $sumPrice;
  9463. }
  9464. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9465. $data ['companyTotalHtml'] = $collectHtml;
  9466. $data ['total'] = $total;
  9467. // statistics html
  9468. // echo $cidString;
  9469. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9470. if (empty ( $stList ))
  9471. $stList = array (
  9472. 'rePrice' => 0,
  9473. 'agPrice' => 0
  9474. );
  9475. $data ['stList'] = array (
  9476. 'rePrice' => $stList ['rePrice'],
  9477. 'agPrice' => $stList ['agPrice'],
  9478. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9479. );
  9480. $data ['year'] = $year;
  9481. $data ['memu'] = "receipt";
  9482. $data ['staff'] = $this->staff;
  9483. $data ['receiptMemu'] = 'companyCategoryCollect';
  9484. $data ['verifyId'] = $this->verifyId;
  9485. $data ['executeId'] = $this->executeId;
  9486. $dateHtml = "";
  9487. $now = date ( "Y" );
  9488. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9489. if ($YEARD <= $now) {
  9490. $dateHtml .= '<option ';
  9491. if ($year == $YEARD) {
  9492. $dateHtml .= 'selected ';
  9493. }
  9494. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9495. }
  9496. }
  9497. $data ['dateHtml'] = $dateHtml;
  9498. // year staff status 2,4
  9499. if ($year < date ( "Y" )) {
  9500. Doo::loadModel ( 'receipt' );
  9501. $receipt = new receipt ();
  9502. $receiptList = $receipt->find ( array (
  9503. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9504. 'asArray' => true
  9505. ) );
  9506. if (empty ( $receiptList )) {
  9507. ob_start ();
  9508. $this->render ( "/admin/saeaCompanyCollect", $data );
  9509. $this->cacheFile ( $path );
  9510. die ();
  9511. }
  9512. }
  9513. $this->render ( "/admin/saeaCompanyCollect", $data );
  9514. }
  9515. function categoryCollectDetail() {
  9516. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9517. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9518. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9519. $this->showCache ( $path ); */
  9520. Doo::loadModel ( 'statistics' );
  9521. $statistics = new statistics ();
  9522. Doo::loadModel ( "receiptDetail" );
  9523. $receiptDetail = new receiptDetail ();
  9524. Doo::loadModel ( 'L_category' );
  9525. $Lcategory = new L_category ();
  9526. Doo::loadModel ( 'accountItem' );
  9527. $accountItem = new accountItem ();
  9528. Doo::loadModel ( "receiptAuthorityManage" );
  9529. $receiptAuthorityManage = new receiptAuthorityManage ();
  9530. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9531. $cidList = array ();
  9532. foreach ( $imcStaff as $key => $value ) {
  9533. array_push ( $cidList, $value ['cid'] );
  9534. }
  9535. $cidString = implode ( ',', $cidList );
  9536. $LcategoryList = $Lcategory->find ( array (
  9537. 'where' => 'cid in (' . $cidString . ')',
  9538. 'asArray' => true
  9539. ) );
  9540. if ($cid == 0) {
  9541. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9542. if ($cid == 0)
  9543. $cid = $LcategoryList [0] ['cid'];
  9544. }
  9545. $data ['LcategoryList'] = $LcategoryList;
  9546. $receiptCollectList = $receiptDetail->find ( array (
  9547. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9548. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9549. 'groupby' => 'item,Month(pastDate)',
  9550. 'asArray' => true
  9551. ) );
  9552. $accountList = $accountItem->find ( array (
  9553. 'asArray' => true
  9554. ) );
  9555. // create CollectDetail HTML
  9556. $collectHtml = array ();
  9557. foreach ( $accountList as $key => $value ) {
  9558. $html = "";
  9559. $asum = 0;
  9560. for($i = 1; $i <= 12; $i ++) {
  9561. $falg = true;
  9562. foreach ( $receiptCollectList as $v ) {
  9563. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9564. $asum += $v ['price'];
  9565. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9566. $falg = false;
  9567. break;
  9568. }
  9569. }
  9570. if ($falg)
  9571. $html .= '<td class="taR">-</td>';
  9572. }
  9573. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9574. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9575. }
  9576. $data ['collectHtml'] = $collectHtml;
  9577. // create Adjustment price html
  9578. $receiptCollectList = $receiptDetail->find ( array (
  9579. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9580. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9581. 'groupby' => 'itemCategory,Month(pastDate)',
  9582. 'asArray' => true
  9583. ) );
  9584. $adjustment = array ();
  9585. $collectArray = array (
  9586. '日常相关费用' => array (),
  9587. '差旅相关费用' => array (),
  9588. '培训班费用' => array (),
  9589. '内部培训费用'=>array(),
  9590. '其他' => array ()
  9591. );
  9592. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9593. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9594. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9595. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9596. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9597. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9598. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9599. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9600. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9601. array_push ( $collectArray ['其他'], $collectHtml );
  9602. $data ['collectArray'] = $collectArray;
  9603. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9604. array_push ( $adjustment, $collectHtml );
  9605. $data ['adjustment'] = $adjustment;
  9606. // total price html
  9607. $collectHtml = "";
  9608. $total = 0;
  9609. for($i = 1; $i <= 12; $i ++) {
  9610. $sumPrice = 0;
  9611. foreach ( $receiptCollectList as $key => $value ) {
  9612. if ($value ['month'] == $i) {
  9613. $sumPrice += $value ['price'];
  9614. }
  9615. }
  9616. if ($sumPrice == 0)
  9617. $collectHtml .= '<td class="taR">-</td>';
  9618. else
  9619. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9620. $total += $sumPrice;
  9621. }
  9622. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9623. // statistics html
  9624. $stList = $statistics->statisticsByCid ( $year, $cid );
  9625. if (empty ( $stList ))
  9626. $stList = array (
  9627. 'rePrice' => 0,
  9628. 'agPrice' => 0
  9629. );
  9630. $data ['stList'] = array (
  9631. 'rePrice' => $stList ['rePrice'],
  9632. 'agPrice' => $stList ['agPrice'],
  9633. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9634. );
  9635. $data ['totalYear'] = $total;
  9636. $data ['year'] = $year;
  9637. $data ['cid'] = $cid;
  9638. $data ['memu'] = "receipt";
  9639. $data ['staff'] = $this->staff;
  9640. $data ['receiptMemu'] = 'companyCategoryCollect';
  9641. $data ['verifyId'] = $this->verifyId;
  9642. $data ['executeId'] = $this->executeId;
  9643. // year staff status 2,4
  9644. /* if ($year < date ( "Y" )) {
  9645. Doo::loadModel ( 'receipt' );
  9646. $receipt = new receipt ();
  9647. $receiptList = $receipt->find ( array (
  9648. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9649. 'asArray' => true
  9650. ) );
  9651. if (empty ( $receiptList )) {
  9652. ob_start ();
  9653. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9654. $this->cacheFile ( $path );
  9655. die ();
  9656. }
  9657. } */
  9658. $dateHtml = "";
  9659. $now = date ( "Y" );
  9660. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9661. if ($YEARD <= $now) {
  9662. $dateHtml .= '<option ';
  9663. if ($year == $YEARD) {
  9664. $dateHtml .= 'selected ';
  9665. }
  9666. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9667. }
  9668. }
  9669. $data ['dateHtml'] = $dateHtml;
  9670. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9671. }
  9672. function staffCollect() {
  9673. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9674. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9675. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9676. // $this->showCache($path);
  9677. Doo::loadModel ( 'statistics' );
  9678. $statistics = new statistics ();
  9679. Doo::loadModel ( "receiptDetail" );
  9680. $receiptDetail = new receiptDetail ();
  9681. Doo::loadModel ( 'L_category' );
  9682. $Lcategory = new L_category ();
  9683. Doo::loadModel ( 'accountItem' );
  9684. $accountItem = new accountItem ();
  9685. Doo::loadModel ( 'staff' );
  9686. $staff = new staff ();
  9687. Doo::loadModel ( 'itemStatistics' );
  9688. $itemStatistics = new itemStatistics ();
  9689. Doo::loadModel ( "receiptAuthorityManage" );
  9690. $receiptAuthorityManage = new receiptAuthorityManage ();
  9691. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9692. $cidList = array ();
  9693. foreach ( $imcStaff as $key => $value ) {
  9694. array_push ( $cidList, $value ['cid'] );
  9695. }
  9696. $cidString = implode ( ',', $cidList );
  9697. $naturecon='';
  9698. if ($nature=='ONJOB'){
  9699. $naturecon=' and (nature!=4 )';
  9700. }elseif($nature=='LEAVEJOB'){
  9701. $naturecon=' and (nature=4 )';
  9702. }else{
  9703. die ( 'illegal request--nature' );
  9704. }
  9705. // statistics html
  9706. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9707. if (empty ( $stList ))
  9708. $stList = array (
  9709. 'rePrice' => 0,
  9710. 'agPrice' => 0
  9711. );
  9712. $data ['stList'] = array (
  9713. 'rePrice' => $stList ['rePrice'],
  9714. 'agPrice' => $stList ['agPrice'],
  9715. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9716. );
  9717. // ---
  9718. $staffList = $staff->find ( array (
  9719. 'where' => 'username !="admin" '.$naturecon,
  9720. 'asArray' => true
  9721. ) );
  9722. $LcategoryList = $Lcategory->find ( array (
  9723. 'asArray' => true
  9724. ) ); // 'staff='.$this->staff[0]['sid']." and
  9725. $itemStatisticsList = $itemStatistics->find ( array (
  9726. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9727. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9728. 'groupby' => 'staff,Month(date)',
  9729. 'asArray' => true
  9730. ) );
  9731. $categoryList = $staff->find ( array (
  9732. 'select' => 'COUNT(*) as count,cid,category',
  9733. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9734. 'groupby' => 'cid',
  9735. 'asArray' => true
  9736. ) );
  9737. // print_r($itemStatisticsList);die;
  9738. // ceatre companyCollectHtml
  9739. foreach ( $categoryList as $vlu ) {
  9740. $count = $vlu ['count'] + 1;
  9741. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9742. $m1 = 0;
  9743. $m2 = 0;
  9744. $m3 = 0;
  9745. $m4 = 0;
  9746. $m5 = 0;
  9747. $m6 = 0;
  9748. $m7 = 0;
  9749. $m8 = 0;
  9750. $m9 = 0;
  9751. $m10 = 0;
  9752. $m11 = 0;
  9753. $m12 = 0;
  9754. $m13 = 0;
  9755. foreach ( $staffList as $value ) {
  9756. if ($vlu ['cid'] == $value ['cid']) {
  9757. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9758. $asum = 0;
  9759. for($i = 1; $i <= 12; $i ++) {
  9760. $falg = true;
  9761. foreach ( $itemStatisticsList as $v ) {
  9762. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9763. if ($v ['month'] == 1)
  9764. $m1 += $v ['price'];
  9765. if ($v ['month'] == 2)
  9766. $m2 += $v ['price'];
  9767. if ($v ['month'] == 3)
  9768. $m3 += $v ['price'];
  9769. if ($v ['month'] == 4)
  9770. $m4 += $v ['price'];
  9771. if ($v ['month'] == 5)
  9772. $m5 += $v ['price'];
  9773. if ($v ['month'] == 6)
  9774. $m6 += $v ['price'];
  9775. if ($v ['month'] == 7)
  9776. $m7 += $v ['price'];
  9777. if ($v ['month'] == 8)
  9778. $m8 += $v ['price'];
  9779. if ($v ['month'] == 9)
  9780. $m9 += $v ['price'];
  9781. if ($v ['month'] == 10)
  9782. $m10 += $v ['price'];
  9783. if ($v ['month'] == 11)
  9784. $m11 += $v ['price'];
  9785. if ($v ['month'] == 12)
  9786. $m12 += $v ['price'];
  9787. $asum += $v ['price'];
  9788. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9789. $falg = false;
  9790. break;
  9791. }
  9792. }
  9793. if ($falg)
  9794. $html .= '<td class="taR">-</td>';
  9795. }
  9796. $m13 += $asum;
  9797. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9798. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9799. 'html' => $html,
  9800. 'sid' => $value ['sid']
  9801. );
  9802. $html = "";
  9803. }
  9804. }
  9805. $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>
  9806. <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>
  9807. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9808. $collectHtml [$vlu ['cid']] = array (
  9809. 'html' => $hl,
  9810. 'sid' => ''
  9811. );
  9812. }
  9813. $data ['companyHtml'] = $collectHtml;
  9814. // total price html
  9815. $collectHtml = "";
  9816. $total = 0;
  9817. for($i = 1; $i <= 12; $i ++) {
  9818. $sumPrice = 0;
  9819. foreach ( $itemStatisticsList as $key => $value ) {
  9820. if ($value ['month'] == $i) {
  9821. $sumPrice += $value ['price'];
  9822. }
  9823. }
  9824. if ($sumPrice == 0)
  9825. $collectHtml .= '<td class="taR">-</td>';
  9826. else
  9827. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9828. $total += $sumPrice;
  9829. }
  9830. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9831. $data ['companyTotalHtml'] = $collectHtml;
  9832. $data ['total'] = $total;
  9833. $data ['nature'] =$nature;
  9834. $data ['year'] = $year;
  9835. $data ['memu'] = "receipt";
  9836. $data ['staff'] = $this->staff;
  9837. $data ['receiptMemu'] = 'companyCategoryCollect';
  9838. $data ['verifyId'] = $this->verifyId;
  9839. $data ['executeId'] = $this->executeId;
  9840. if ($year <= date ( "Y" )) {
  9841. Doo::loadModel ( 'receipt' );
  9842. $receipt = new receipt ();
  9843. $receiptList = $receipt->find ( array (
  9844. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9845. 'asArray' => true
  9846. ) );
  9847. if (empty ( $receiptList )) { // generated files
  9848. ob_start ();
  9849. $this->render ( "/admin/saeaStaffCollectB", $data );
  9850. $this->cacheFile ( $path );
  9851. die ();
  9852. }
  9853. }
  9854. $this->render ( "/admin/saeaStaffCollectB", $data );
  9855. }
  9856. function staffCollectBak() {
  9857. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9858. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9859. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9860. $this->showCache ( $path );
  9861. Doo::loadModel ( 'statistics' );
  9862. $statistics = new statistics ();
  9863. Doo::loadModel ( "receiptDetail" );
  9864. $receiptDetail = new receiptDetail ();
  9865. Doo::loadModel ( 'L_category' );
  9866. $Lcategory = new L_category ();
  9867. Doo::loadModel ( 'accountItem' );
  9868. $accountItem = new accountItem ();
  9869. Doo::loadModel ( 'staff' );
  9870. $staff = new staff ();
  9871. Doo::loadModel ( 'itemStatistics' );
  9872. $itemStatistics = new itemStatistics ();
  9873. $itemStatisticsList = $itemStatistics->find ( array (
  9874. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9875. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9876. 'groupby' => 'staff,itemCategory,Month(date)',
  9877. 'asArray' => true
  9878. ) );
  9879. $itemCategoryList = $itemStatistics->find ( array (
  9880. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9881. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9882. 'groupby' => 'cid,itemCategory,Month(date)',
  9883. 'asArray' => true
  9884. ) );
  9885. $LcategoryList = $Lcategory->find ( array (
  9886. 'asArray' => true
  9887. ) );
  9888. $staffList = $staff->find ( array (
  9889. 'asArray' => true
  9890. ) );
  9891. $htmlArray = array ();
  9892. foreach ( $LcategoryList as $value ) {
  9893. $htmlArray [$value ['title']] = array ();
  9894. foreach ( $staffList as $v ) {
  9895. if ($value ['cid'] == $v ['cid']) {
  9896. $html = "";
  9897. $falg = true;
  9898. $staffSumPrice = 0;
  9899. foreach ( $itemStatisticsList as $a ) {
  9900. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9901. if (empty ( $a ['price'] )) {
  9902. $html .= '<td class="taR">-</td>';
  9903. $falg = false;
  9904. break;
  9905. } else {
  9906. $staffSumPrice += $a ['price'];
  9907. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9908. $falg = false;
  9909. break;
  9910. }
  9911. }
  9912. }
  9913. if ($falg) {
  9914. $html .= '<td class="taR">-</td>';
  9915. $falg = true;
  9916. }
  9917. $falg = true;
  9918. foreach ( $itemStatisticsList as $a ) {
  9919. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9920. if (empty ( $a ['price'] )) {
  9921. $html .= '<td class="taR">-</td>';
  9922. $falg = false;
  9923. break;
  9924. } else {
  9925. $staffSumPrice += $a ['price'];
  9926. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9927. $falg = false;
  9928. break;
  9929. }
  9930. }
  9931. }
  9932. if ($falg) {
  9933. $html .= '<td class="taR">-</td>';
  9934. $falg = true;
  9935. }
  9936. $falg = true;
  9937. foreach ( $itemStatisticsList as $a ) {
  9938. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9939. if (empty ( $a ['price'] )) {
  9940. $html .= '<td class="taR">-</td>';
  9941. $falg = false;
  9942. break;
  9943. } else {
  9944. $staffSumPrice += $a ['price'];
  9945. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9946. $falg = false;
  9947. break;
  9948. }
  9949. }
  9950. }
  9951. if ($falg) {
  9952. $html .= '<td class="taR">-</td>';
  9953. $falg = true;
  9954. }
  9955. $falg = true;
  9956. foreach ( $itemStatisticsList as $a ) {
  9957. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9958. if (! empty ( $a ['price'] )) {
  9959. $staffSumPrice += $a ['price'];
  9960. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9961. $falg = false;
  9962. break;
  9963. } else {
  9964. $html .= '<td class="taR">-</td>';
  9965. $falg = false;
  9966. break;
  9967. }
  9968. }
  9969. }
  9970. if ($falg) {
  9971. $html .= '<td class="taR">-</td>';
  9972. $falg = true;
  9973. }
  9974. $falg = true;
  9975. foreach ( $itemStatisticsList as $a ) {
  9976. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9977. if (! empty ( $a ['price'] )) {
  9978. $staffSumPrice += $a ['price'];
  9979. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9980. $falg = false;
  9981. break;
  9982. } else {
  9983. $html .= '<td class="taR">-</td>';
  9984. $falg = false;
  9985. break;
  9986. }
  9987. }
  9988. }
  9989. if ($falg) {
  9990. $html .= '<td class="taR">-</td>';
  9991. $falg = true;
  9992. }
  9993. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9994. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9995. }
  9996. }
  9997. /* -- --- */
  9998. // 合计费用
  9999. $cateHtml = "";
  10000. $catePrice = 0;
  10001. $cateFalg = true;
  10002. foreach ( $itemCategoryList as $l ) {
  10003. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10004. if (empty ( $l ['price'] )) {
  10005. $cateHtml .= '<td class="colGreen taR">-</td>';
  10006. $cateFalg = false;
  10007. break;
  10008. } else {
  10009. $catePrice += $l ['price'];
  10010. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10011. $cateFalg = false;
  10012. break;
  10013. }
  10014. }
  10015. }
  10016. if ($cateFalg) {
  10017. $cateHtml .= '<td class="colGreen taR">-</td>';
  10018. $cateFalg = true;
  10019. }
  10020. $cateFalg = true;
  10021. foreach ( $itemCategoryList as $l ) {
  10022. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10023. if (empty ( $l ['price'] )) {
  10024. $cateHtml .= '<td class="colGreen taR">-</td>';
  10025. $cateFalg = false;
  10026. break;
  10027. } else {
  10028. $catePrice += $l ['price'];
  10029. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10030. $cateFalg = false;
  10031. break;
  10032. }
  10033. }
  10034. }
  10035. if ($cateFalg) {
  10036. $cateHtml .= '<td class="colGreen taR">-</td>';
  10037. $cateFalg = true;
  10038. }
  10039. $cateFalg = true;
  10040. foreach ( $itemCategoryList as $l ) {
  10041. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10042. if (empty ( $l ['price'] )) {
  10043. $cateHtml .= '<td class="colGreen taR">-</td>';
  10044. $cateFalg = false;
  10045. break;
  10046. } else {
  10047. $catePrice += $l ['price'];
  10048. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10049. $cateFalg = false;
  10050. break;
  10051. }
  10052. }
  10053. }
  10054. if ($cateFalg) {
  10055. $cateHtml .= '<td class="colGreen taR">-</td>';
  10056. $cateFalg = true;
  10057. }
  10058. $cateFalg = true;
  10059. foreach ( $itemCategoryList as $l ) {
  10060. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10061. if (empty ( $l ['price'] )) {
  10062. $cateHtml .= '<td class="colGreen taR">-</td>';
  10063. $cateFalg = false;
  10064. break;
  10065. } else {
  10066. $catePrice += $l ['price'];
  10067. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10068. $cateFalg = false;
  10069. break;
  10070. }
  10071. }
  10072. }
  10073. if ($cateFalg) {
  10074. $cateHtml .= '<td class="colGreen taR">-</td>';
  10075. $cateFalg = true;
  10076. }
  10077. $cateFalg = true;
  10078. foreach ( $itemCategoryList as $l ) {
  10079. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10080. if (empty ( $l ['price'] )) {
  10081. $cateHtml .= '<td class="colGreen taR">-</td>';
  10082. $cateFalg = false;
  10083. break;
  10084. } else {
  10085. $catePrice += $l ['price'];
  10086. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10087. $cateFalg = false;
  10088. break;
  10089. }
  10090. }
  10091. }
  10092. if ($cateFalg) {
  10093. $cateHtml .= '<td class="colGreen taR">-</td>';
  10094. $cateFalg = true;
  10095. }
  10096. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10097. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10098. /* -- --- */
  10099. }
  10100. // print_r($htmlArray);die;
  10101. $data ['htmlArray'] = $htmlArray;
  10102. // statistics html
  10103. $stList = $statistics->getOne ( array (
  10104. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10105. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10106. 'groupby' => 'Month(date)',
  10107. 'asArray' => true
  10108. ) );
  10109. if (empty ( $stList ))
  10110. $stList = array (
  10111. 'rePrice' => 0,
  10112. 'agPrice' => 0
  10113. );
  10114. $data ['stList'] = array (
  10115. 'rePrice' => $stList ['rePrice'],
  10116. 'agPrice' => $stList ['agPrice'],
  10117. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10118. );
  10119. $monthHtml = "";
  10120. for($i = 1; $i <= 12; $i ++) {
  10121. if ($i == $month)
  10122. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10123. else
  10124. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10125. }
  10126. $data ['monthHtml'] = $monthHtml;
  10127. $data ['year'] = $year;
  10128. $data ['month'] = $month;
  10129. $data ['memu'] = "receipt";
  10130. $data ['staff'] = $this->staff;
  10131. $data ['receiptMemu'] = 'companyCategoryCollect';
  10132. $data ['verifyId'] = $this->verifyId;
  10133. $data ['executeId'] = $this->executeId;
  10134. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10135. Doo::loadModel ( 'receipt' );
  10136. $receipt = new receipt ();
  10137. $receiptList = $receipt->find ( array (
  10138. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10139. 'asArray' => true
  10140. ) );
  10141. if (empty ( $receiptList )) { // generated files
  10142. ob_start ();
  10143. $this->render ( "/admin/saeaStaffCollect", $data );
  10144. $this->cacheFile ( $path );
  10145. die ();
  10146. }
  10147. }
  10148. $this->render ( "/admin/saeaStaffCollect", $data );
  10149. }
  10150. /**
  10151. * 日常收支
  10152. */
  10153. function payments() {
  10154. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10155. Doo::loadModel ( "execute" );
  10156. $execute = new execute ();
  10157. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10158. die ( 'illegal request' );
  10159. }
  10160. Doo::loadModel ( "accountBook" );
  10161. $accountBook = new accountBook ();
  10162. Doo::loadModel ( "accountBookStatistics" );
  10163. $accountBookStatistics = new accountBookStatistics ();
  10164. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10165. $list = $accountBook->getAccountBookByLimit ( 10 );
  10166. $data ['date'] = date ( "Y-m-d" );
  10167. $data ['statisticsList'] = $statisticsList;
  10168. $data ['list'] = $list;
  10169. $data ['memu'] = "receipt";
  10170. $data ['staff'] = $this->staff;
  10171. $data ['receiptMemu'] = 'payments';
  10172. $data ['verifyId'] = $this->verifyId;
  10173. $data ['executeId'] = $this->executeId;
  10174. $this->render ( "/expenses/payments", $data );
  10175. }
  10176. function paymentsIncomeDo() {
  10177. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10178. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10179. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10180. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10181. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10182. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10183. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10184. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10185. Doo::loadClass ( 'XDeode' );
  10186. $XDeode = new XDeode ( 5 );
  10187. Doo::loadModel ( "accountBook" );
  10188. Doo::loadModel ( "accountBookStatistics" );
  10189. Doo::loadModel ( 'wasteBook' );
  10190. // 记录流水时银行的转换
  10191. $accountBank = '';
  10192. if ($receivedBank == '纵横广发') {
  10193. $accountBank = 'CGBDeposit';
  10194. } elseif ($receivedBank == '纵横工行') {
  10195. $accountBank = 'ICBCDeposit';
  10196. } elseif ($receivedBank == '华润银行') {
  10197. $accountBank = 'HUADeposit';
  10198. } elseif ($receivedBank == '个人广发') {
  10199. $accountBank = 'PersonalDeposit';
  10200. }
  10201. if (empty ( $accountBank ))
  10202. die ( 'illegal request' );
  10203. // 收入为理财时特殊处理
  10204. if ($accountType == 7 || $accountType == 9) {
  10205. if ($receivedBank == '个人广发') {
  10206. die ( '个人广发 illegal request' );
  10207. }
  10208. // 添加一条收入
  10209. $accountBook = new accountBook ();
  10210. $accountBook->accountType = 10;
  10211. $accountBook->accountMsg = $accountMsg;
  10212. $accountBook->receivedPrice = $receivedPrice;
  10213. $accountBook->receivedMsg = $receivedMsg;
  10214. $accountBook->receivedBank = $receivedBank;
  10215. $accountBook->receivedDate = $receivedDate;
  10216. $accountBook->remarks = $remarks;
  10217. $accountBook->expensesType = 1;
  10218. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10219. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10220. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10221. $inComeId = $accountBook->insert ();
  10222. // 收支汇总-添加一条收入日常汇总
  10223. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10224. $accountBookStatistics = new accountBookStatistics ();
  10225. $item = array (
  10226. 'date' => date ( "Y-m-d" ),
  10227. 'accountType' => $abDetail ['accountType'],
  10228. 'accountMsg' => $abDetail ['accountMsg'],
  10229. 'aid' => $abDetail ['aid'],
  10230. 'inComePrice' => $abDetail ['receivedPrice'],
  10231. 'expensesType' => $abDetail ['expensesType']
  10232. );
  10233. $accountBookStatistics->setAccountBookStatistics ( $item );
  10234. // 添加收入流水
  10235. $wasteBook = new wasteBook ();
  10236. $itemWaste = array (
  10237. 'accountPriceShow' => $receivedPrice,
  10238. 'accountPrice' => $receivedPrice,
  10239. 'expensesType' => 1,
  10240. 'accountType' => 6, // 流水类型
  10241. 'dataID' => $inComeId,
  10242. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10243. 'accountBank' => $accountBank,
  10244. 'category' => $this->staff [0] ['category'],
  10245. 'cid' => $this->staff [0] ['cid'],
  10246. 'name' => $this->staff [0] ['username'],
  10247. 'sid' => $this->staff [0] ['sid'],
  10248. 'inputDate' => date ( "Y-m-d H:i:s" )
  10249. );
  10250. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10251. // 添加一条理财支出
  10252. $accountBank = 'CGBDeposit';
  10253. $expenditureBank = '纵横广发';
  10254. $dailyExpenditureType = 4;
  10255. if ($accountType == 9) {
  10256. $accountBank = 'ICBCDeposit';
  10257. $expenditureBank = '纵横工行';
  10258. $dailyExpenditureType = 6;
  10259. }
  10260. $accountBook = new accountBook ();
  10261. $accountBook->expensesType = 2;
  10262. $accountBook->expenditureType = $dailyExpenditureType;
  10263. $accountBook->expenditureMsg = $accountMsg;
  10264. $accountBook->expenditurePrice = $receivedPrice;
  10265. $accountBook->expenditureBank = $expenditureBank;
  10266. $accountBook->expenditureDate = $receivedDate;
  10267. $accountBook->remarks = $remarks;
  10268. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10269. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10270. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10271. $id = $accountBook->insert ();
  10272. // 收支汇总-添加一条理财支出汇总
  10273. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10274. $accountBookStatistics = new accountBookStatistics ();
  10275. $item = array (
  10276. 'date' => date ( "Y-m-d" ),
  10277. 'accountType' => $abDetail ['accountType'],
  10278. 'accountMsg' => $abDetail ['accountMsg'],
  10279. 'aid' => $abDetail ['aid'],
  10280. 'financingPrice' => - $receivedPrice,
  10281. 'expensesType' => 3
  10282. );
  10283. $accountBookStatistics->setAccountBookStatistics ( $item );
  10284. // 添加一条支出理财流水
  10285. $accountTypeWaste = 5;
  10286. if ($accountMsg == '公司固定') {
  10287. $accountTypeWaste = 9;
  10288. } elseif ($accountMsg == '公司活期') {
  10289. $accountTypeWaste = 10;
  10290. } elseif ($accountMsg == '个人(GR)') {
  10291. $accountBank = 'PersonalDeposit';
  10292. }
  10293. $itemWaste = array (
  10294. 'expensesType' => 2,
  10295. 'accountType' => $accountTypeWaste,
  10296. 'accountPriceShow' => $receivedPrice,
  10297. 'accountPrice' => - $receivedPrice,
  10298. 'dataID' => $id,
  10299. 'dailyExpenditureType' => $dailyExpenditureType,
  10300. 'accountBank' => $accountBank,
  10301. 'category' => $this->staff [0] ['category'],
  10302. 'cid' => $this->staff [0] ['cid'],
  10303. 'name' => $this->staff [0] ['username'],
  10304. 'sid' => $this->staff [0] ['sid'],
  10305. 'inputDate' => date ( "Y-m-d H:i:s" )
  10306. );
  10307. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10308. } elseif ($accountType == 1) {
  10309. if ($receivedBank == '个人广发')
  10310. die ( 'illegal request' );
  10311. // 添加一条收入
  10312. $accountBook = new accountBook ();
  10313. $accountBook->accountType = $accountType;
  10314. $accountBook->accountMsg = $accountMsg;
  10315. $accountBook->receivedPrice = $receivedPrice;
  10316. $accountBook->receivedMsg = $receivedMsg;
  10317. $accountBook->receivedBank = $receivedBank;
  10318. $accountBook->receivedDate = $receivedDate;
  10319. $accountBook->remarks = $remarks;
  10320. $accountBook->expensesType = 1;
  10321. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10322. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10323. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10324. $id = $accountBook->insert ();
  10325. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10326. // 收支汇总-添加一条收入日常汇总
  10327. $accountBookStatistics = new accountBookStatistics ();
  10328. $item = array (
  10329. 'date' => date ( "Y-m-d" ),
  10330. 'accountType' => $abDetail ['accountType'],
  10331. 'accountMsg' => $abDetail ['accountMsg'],
  10332. 'aid' => $abDetail ['aid'],
  10333. 'expensesType' => $abDetail ['expensesType']
  10334. );
  10335. if ($abDetail ['accountType'] == 8) {
  10336. $item += array (
  10337. 'inComePrice' => $abDetail ['receivedPrice']
  10338. );
  10339. } else {
  10340. $item += array (
  10341. 'inComePrice' => $abDetail ['receivedPrice']
  10342. );
  10343. }
  10344. $accountBookStatistics->setAccountBookStatistics ( $item );
  10345. // 流水存储方向
  10346. $itemWaste = array (
  10347. 'accountType' => 6
  10348. ); // 流水类型
  10349. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10350. // }else
  10351. if ($accountMsg == '活期理财收益') {
  10352. $itemWaste = array (
  10353. 'accountType' => 10
  10354. ); // 流水类型
  10355. }
  10356. // 添加收入流水
  10357. $wasteBook = new wasteBook ();
  10358. $itemWaste += array (
  10359. 'accountPrice' => $receivedPrice,
  10360. 'accountPriceShow' => $receivedPrice,
  10361. 'expensesType' => 1,
  10362. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10363. 'dataID' => $id,
  10364. 'accountBank' => $accountBank,
  10365. 'category' => $this->staff [0] ['category'],
  10366. 'cid' => $this->staff [0] ['cid'],
  10367. 'name' => $this->staff [0] ['username'],
  10368. 'sid' => $this->staff [0] ['sid'],
  10369. 'inputDate' => date ( "Y-m-d H:i:s" )
  10370. );
  10371. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10372. } else { // 普通日常收入处理
  10373. // 添加一条收入
  10374. $accountBook = new accountBook ();
  10375. $accountBook->accountType = $accountType;
  10376. $accountBook->accountMsg = $accountMsg;
  10377. $accountBook->receivedPrice = $receivedPrice;
  10378. $accountBook->receivedMsg = $receivedMsg;
  10379. $accountBook->receivedBank = $receivedBank;
  10380. $accountBook->receivedDate = $receivedDate;
  10381. $accountBook->remarks = $remarks;
  10382. $accountBook->expensesType = 1;
  10383. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10384. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10385. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10386. $id = $accountBook->insert ();
  10387. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10388. // 收支汇总-添加一条收入日常汇总
  10389. $accountBookStatistics = new accountBookStatistics ();
  10390. $item = array (
  10391. 'date' => date ( "Y-m-d" ),
  10392. 'accountType' => $abDetail ['accountType'],
  10393. 'accountMsg' => $abDetail ['accountMsg'],
  10394. 'aid' => $abDetail ['aid'],
  10395. 'expensesType' => $abDetail ['expensesType']
  10396. );
  10397. if ($abDetail ['accountType'] == 8) {
  10398. $item += array (
  10399. 'inComePrice' => $abDetail ['receivedPrice']
  10400. );
  10401. } else {
  10402. $item += array (
  10403. 'inComePrice' => $abDetail ['receivedPrice']
  10404. );
  10405. }
  10406. $accountBookStatistics->setAccountBookStatistics ( $item );
  10407. // 添加收入流水
  10408. $itemWaste = array (
  10409. 'accountPrice' => $receivedPrice
  10410. );
  10411. if ($receivedBank == '个人广发') {
  10412. $itemWaste = array (
  10413. 'accountPrice' => - $receivedPrice
  10414. );
  10415. }
  10416. $wasteBook = new wasteBook ();
  10417. $itemWaste += array (
  10418. 'accountPriceShow' => $receivedPrice,
  10419. 'expensesType' => 1,
  10420. 'accountType' => 6, // 流水类型
  10421. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10422. 'dataID' => $id,
  10423. 'accountBank' => $accountBank,
  10424. 'category' => $this->staff [0] ['category'],
  10425. 'cid' => $this->staff [0] ['cid'],
  10426. 'name' => $this->staff [0] ['username'],
  10427. 'sid' => $this->staff [0] ['sid'],
  10428. 'inputDate' => date ( "Y-m-d H:i:s" )
  10429. );
  10430. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10431. }
  10432. }
  10433. return '/payments';
  10434. }
  10435. /**
  10436. * 添加收入
  10437. * @return string
  10438. */
  10439. function paymentsIncomeDo_() {
  10440. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10441. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10442. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10443. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10444. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10445. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10446. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10447. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10448. Doo::loadClass ( 'XDeode' );
  10449. $XDeode = new XDeode ( 5 );
  10450. Doo::loadModel ( "accountBook" );
  10451. $accountBook = new accountBook ();
  10452. $accountBank = '';
  10453. $accountTypeWaste = 6;
  10454. if ($receivedBank == '纵横广发') {
  10455. $accountBank = 'CGBDeposit';
  10456. } elseif ($receivedBank == '纵横工行') {
  10457. $accountBank = 'ICBCDeposit';
  10458. } elseif ($receivedBank == '华润银行') {
  10459. $accountBank = 'HUADeposit';
  10460. } elseif ($receivedBank == '个人广发') {
  10461. $accountBank = 'PersonalDeposit';
  10462. }
  10463. if (empty ( $accountBank ))
  10464. die ( 'illegal request' );
  10465. $dailyIncomeType = '';
  10466. $itemWaste = array (
  10467. 'accountPrice' => $receivedPrice,
  10468. 'expensesType' => 1
  10469. );
  10470. if ($receivedBank == '个人广发') {
  10471. $itemWaste = array (
  10472. 'accountPrice' => - $receivedPrice,
  10473. 'expensesType' => 1
  10474. );
  10475. }
  10476. if ($accountType == 4) {
  10477. $dailyIncomeType = 4;
  10478. } elseif ($accountType == 1) {
  10479. $dailyIncomeType = 1;
  10480. } elseif ($accountType == 2) {
  10481. $dailyIncomeType = 2;
  10482. } elseif ($accountType == 3) {
  10483. $dailyIncomeType = 3;
  10484. } elseif ($accountType == 5) {
  10485. $dailyIncomeType = 5;
  10486. } elseif ($accountType == 6) {
  10487. $dailyIncomeType = 6;
  10488. } elseif ($accountType == 7 || $accountType == 9) {
  10489. $dailyIncomeType = 7;
  10490. if ($accountMsg == '公司固定') {
  10491. $accountTypeWaste = 9;
  10492. } elseif ($accountMsg == '公司活期') {
  10493. $accountTypeWaste = 10;
  10494. } elseif ($accountMsg == '个人(GR)') {
  10495. $accountBank = 'PersonalDeposit';
  10496. }
  10497. $itemWaste = array (
  10498. 'accountPrice' => - $receivedPrice,
  10499. 'expensesType' => 2
  10500. );
  10501. } elseif ($accountType == 8) {
  10502. $dailyIncomeType = 8;
  10503. }
  10504. if (empty ( $dailyIncomeType ))
  10505. die ( 'illegal request' );
  10506. $accountBook->accountType = $accountType;
  10507. $accountBook->accountMsg = $accountMsg;
  10508. $accountBook->receivedPrice = $receivedPrice;
  10509. $accountBook->receivedMsg = $receivedMsg;
  10510. $accountBook->receivedBank = $receivedBank;
  10511. $accountBook->receivedDate = $receivedDate;
  10512. $accountBook->remarks = $remarks;
  10513. $accountBook->expensesType = 1;
  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. // 收支汇总
  10521. Doo::loadModel ( "accountBookStatistics" );
  10522. $accountBookStatistics = new accountBookStatistics ();
  10523. $item = array (
  10524. 'date' => date ( "Y-m-d" ),
  10525. 'accountType' => $abDetail ['accountType'],
  10526. 'accountMsg' => $abDetail ['accountMsg'],
  10527. 'aid' => $abDetail ['aid']
  10528. );
  10529. if ($abDetail ['expensesType'] == 1) {
  10530. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10531. $item += array (
  10532. 'financingPrice' => - $receivedPrice,
  10533. 'expensesType' => 3
  10534. );
  10535. } else if ($abDetail ['accountType'] == 8) {
  10536. $item += array (
  10537. 'inComePrice' => - $abDetail ['receivedPrice'],
  10538. 'expensesType' => $abDetail ['expensesType']
  10539. );
  10540. } else {
  10541. $item += array (
  10542. 'inComePrice' => $abDetail ['receivedPrice'],
  10543. 'expensesType' => $abDetail ['expensesType']
  10544. );
  10545. }
  10546. }
  10547. $accountBookStatistics->setAccountBookStatistics ( $item );
  10548. // 为理财时需添加一条日常支出
  10549. if ($accountType == 7 || $accountType == 9) {
  10550. }
  10551. // 公司流水记录
  10552. Doo::loadModel ( 'wasteBook' );
  10553. $wasteBook = new wasteBook ();
  10554. // 银行
  10555. // if (empty($abDetail)){
  10556. $itemWaste += array (
  10557. 'accountPriceShow' => $receivedPrice,
  10558. 'dataID' => $id,
  10559. 'accountType' => $accountTypeWaste,
  10560. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10561. 'accountBank' => $accountBank,
  10562. 'category' => $this->staff [0] ['category'],
  10563. 'cid' => $this->staff [0] ['cid'],
  10564. 'name' => $this->staff [0] ['username'],
  10565. 'sid' => $this->staff [0] ['sid'],
  10566. 'inputDate' => date ( "Y-m-d H:i:s" )
  10567. );
  10568. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10569. // }
  10570. // 类型为理财7或者9 要添加一笔理财支出
  10571. if ($accountType == 7 || $accountType == 9) {
  10572. $accountBank = 'CGBDeposit';
  10573. $expenditureBank = '纵横广发';
  10574. $dailyExpenditureType = 4;
  10575. if ($accountType == 9) {
  10576. $accountBank = 'ICBCDeposit';
  10577. $expenditureBank = '纵横工行';
  10578. $dailyExpenditureType = 6;
  10579. }
  10580. // 添加一条支出
  10581. $accountBook = new accountBook ();
  10582. $accountBook->expenditureType = $dailyExpenditureType;
  10583. $accountBook->expenditureMsg = $accountMsg;
  10584. $accountBook->expenditurePrice = $receivedPrice;
  10585. $accountBook->expenditureBank = $expenditureBank;
  10586. $accountBook->expenditureDate = $receivedDate;
  10587. $accountBook->remarks = $remarks;
  10588. $accountBook->expensesType = 2;
  10589. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10590. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10591. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10592. $id = $accountBook->insert ();
  10593. // 添加一条收入流水
  10594. $itemWaste = array (
  10595. 'accountPriceShow' => $receivedPrice,
  10596. 'accountPrice' => $receivedPrice,
  10597. 'dataID' => $id,
  10598. 'expensesType' => 2,
  10599. 'accountType' => $accountTypeWaste,
  10600. 'dailyExpenditureType' => $dailyExpenditureType,
  10601. 'accountBank' => $accountBank,
  10602. 'category' => $this->staff [0] ['category'],
  10603. 'cid' => $this->staff [0] ['cid'],
  10604. 'name' => $this->staff [0] ['username'],
  10605. 'sid' => $this->staff [0] ['sid'],
  10606. 'inputDate' => date ( "Y-m-d H:i:s" )
  10607. );
  10608. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10609. }
  10610. }
  10611. return '/payments';
  10612. }
  10613. function paymentsExpenditureDo() {
  10614. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10615. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10616. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10617. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10618. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10619. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10620. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10621. // 理财支出特殊处理
  10622. Doo::loadModel ( "accountBook" );
  10623. Doo::loadModel ( "accountBookStatistics" );
  10624. Doo::loadModel ( 'wasteBook' );
  10625. $accountBank = '';
  10626. if ($expenditureBank == '纵横广发') {
  10627. $accountBank = 'CGBDeposit';
  10628. } elseif ($expenditureBank == '纵横工行') {
  10629. $accountBank = 'ICBCDeposit';
  10630. } elseif ($expenditureBank == '华润银行') {
  10631. $accountBank = 'HUADeposit';
  10632. } elseif ($expenditureBank == '个人广发') {
  10633. $accountBank = 'PersonalDeposit';
  10634. }
  10635. if (empty ( $accountBank ))
  10636. die ( 'illegal request' );
  10637. if ($expenditureType == 4 || $expenditureType == 6) {
  10638. if ($expenditureBank == '个人广发') {
  10639. die ( '个人广发 illegal request' );
  10640. }
  10641. // 添加一笔日常支出
  10642. $accountBook = new accountBook ();
  10643. $accountBook->expensesType = 2;
  10644. $accountBook->expenditureType = 7;
  10645. $accountBook->expenditureMsg = $expenditureMsg;
  10646. $accountBook->expenditurePrice = $expenditurePrice;
  10647. $accountBook->expenditureBank = $expenditureBank;
  10648. $accountBook->expenditureDate = $expenditureDate;
  10649. $accountBook->remarks = $remarks;
  10650. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10651. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10652. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10653. $expenditureId = $accountBook->insert ();
  10654. // 添加日常支出汇总
  10655. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10656. $accountBookStatistics = new accountBookStatistics ();
  10657. $item = array (
  10658. 'date' => date ( "Y-m-d" ),
  10659. 'expenditureType' => $abDetail ['expenditureType'],
  10660. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10661. 'aid' => $abDetail ['aid'],
  10662. 'payPrice' => $abDetail ['expenditurePrice'],
  10663. 'expensesType' => $abDetail ['expensesType']
  10664. );
  10665. $accountBookStatistics->setAccountBookStatistics ( $item );
  10666. // 公司日常支出流水
  10667. $wasteBook = new wasteBook ();
  10668. $itemWaste = array (
  10669. 'accountPrice' => - $expenditurePrice
  10670. );
  10671. if ($expenditureBank == '个人广发') {
  10672. $itemWaste = array (
  10673. 'accountPrice' => $expenditurePrice
  10674. );
  10675. }
  10676. $itemWaste += array (
  10677. 'expensesType' => 2,
  10678. 'accountType' => 5,
  10679. 'dailyExpenditureType' => $expenditureType,
  10680. 'accountPriceShow' => $expenditurePrice,
  10681. 'accountPrice' => - $expenditurePrice,
  10682. 'dataID' => $expenditureId,
  10683. 'accountBank' => $accountBank,
  10684. 'category' => $this->staff [0] ['category'],
  10685. 'cid' => $this->staff [0] ['cid'],
  10686. 'name' => $this->staff [0] ['username'],
  10687. 'sid' => $this->staff [0] ['sid'],
  10688. 'inputDate' => date ( "Y-m-d H:i:s" )
  10689. );
  10690. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10691. // 添加一笔理财收入
  10692. $accountBank = 'CGBDeposit';
  10693. $dailyIncomeType = 7;
  10694. $receivedBank = '纵横广发';
  10695. if ($expenditureType == 6) {
  10696. $accountBank = 'ICBCDeposit';
  10697. $receivedBank = '纵横工行';
  10698. $dailyIncomeType = 9;
  10699. }
  10700. $accountBook = new accountBook ();
  10701. $accountBook->expensesType = 1;
  10702. $accountBook->accountType = $dailyIncomeType;
  10703. $accountBook->accountMsg = $expenditureMsg;
  10704. $accountBook->receivedPrice = $expenditurePrice;
  10705. $accountBook->receivedBank = $receivedBank;
  10706. $accountBook->receivedDate = $expenditureDate;
  10707. $accountBook->remarks = $remarks;
  10708. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10709. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10710. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10711. $id = $accountBook->insert ();
  10712. // 添加日常理财收入汇总
  10713. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10714. $accountBookStatistics = new accountBookStatistics ();
  10715. $item = array (
  10716. 'date' => date ( "Y-m-d" ),
  10717. 'expenditureType' => $abDetail ['expenditureType'],
  10718. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10719. 'aid' => $abDetail ['aid'],
  10720. 'financingPrice' => $expenditurePrice,
  10721. 'expensesType' => 3
  10722. );
  10723. $accountBookStatistics->setAccountBookStatistics ( $item );
  10724. // 添加一笔收入流水
  10725. if ($expenditureMsg == '公司固定') {
  10726. $accountTypeWaste = 9;
  10727. } elseif ($expenditureMsg == '公司活期') {
  10728. $accountTypeWaste = 10;
  10729. } elseif ($expenditureMsg == '个人(GR)') {
  10730. $accountBank = 'PersonalDeposit';
  10731. }
  10732. $itemWaste = array (
  10733. 'expensesType' => 1,
  10734. 'accountType' => $accountTypeWaste,
  10735. 'accountPriceShow' => $expenditurePrice,
  10736. 'accountPrice' => $expenditurePrice,
  10737. 'dataID' => $id,
  10738. 'dailyIncomeType' => $dailyIncomeType,
  10739. 'accountBank' => $accountBank,
  10740. 'category' => $this->staff [0] ['category'],
  10741. 'cid' => $this->staff [0] ['cid'],
  10742. 'name' => $this->staff [0] ['username'],
  10743. 'sid' => $this->staff [0] ['sid'],
  10744. 'inputDate' => date ( "Y-m-d H:i:s" )
  10745. );
  10746. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10747. } else {
  10748. // 添加一笔日常支出
  10749. $accountBook = new accountBook ();
  10750. $accountBook->expensesType = 2;
  10751. $accountBook->expenditureType = $expenditureType;
  10752. $accountBook->expenditureMsg = $expenditureMsg;
  10753. $accountBook->expenditurePrice = $expenditurePrice;
  10754. $accountBook->expenditureBank = $expenditureBank;
  10755. $accountBook->expenditureDate = $expenditureDate;
  10756. $accountBook->remarks = $remarks;
  10757. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10758. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10759. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10760. $id = $accountBook->insert ();
  10761. // 添加日常支出汇总
  10762. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10763. $accountBookStatistics = new accountBookStatistics ();
  10764. $item = array (
  10765. 'date' => date ( "Y-m-d" ),
  10766. 'expenditureType' => $abDetail ['expenditureType'],
  10767. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10768. 'aid' => $abDetail ['aid'],
  10769. 'expensesType' => $abDetail ['expensesType']
  10770. );
  10771. if ($expenditureType == 5) {
  10772. $item += array (
  10773. 'payPrice' => - $abDetail ['expenditurePrice']
  10774. );
  10775. } else {
  10776. $item += array (
  10777. 'payPrice' => $abDetail ['expenditurePrice']
  10778. );
  10779. }
  10780. $accountBookStatistics->setAccountBookStatistics ( $item );
  10781. // 公司日常支出流水
  10782. $wasteBook = new wasteBook ();
  10783. $itemWaste = array (
  10784. 'accountPrice' => - $expenditurePrice
  10785. );
  10786. if ($expenditureBank == '个人广发') {
  10787. $itemWaste = array (
  10788. 'accountPrice' => $expenditurePrice
  10789. );
  10790. }
  10791. $itemWaste += array (
  10792. 'expensesType' => 2,
  10793. 'accountType' => 5,
  10794. 'accountPriceShow' => $expenditurePrice,
  10795. 'dataID' => $id,
  10796. 'dailyExpenditureType' => $expenditureType,
  10797. 'accountBank' => $accountBank,
  10798. 'category' => $this->staff [0] ['category'],
  10799. 'cid' => $this->staff [0] ['cid'],
  10800. 'name' => $this->staff [0] ['username'],
  10801. 'sid' => $this->staff [0] ['sid'],
  10802. 'inputDate' => date ( "Y-m-d H:i:s" )
  10803. );
  10804. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10805. }
  10806. }
  10807. return '/payments';
  10808. }
  10809. /**
  10810. * 添加支出
  10811. */
  10812. function paymentsExpenditureDo_() {
  10813. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10814. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10815. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10816. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10817. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10818. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10819. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10820. $dailyExpenditureType = '';
  10821. $accountTypeWaste = 5;
  10822. $accountBank = '';
  10823. if ($expenditureBank == '纵横广发') {
  10824. $accountBank = 'CGBDeposit';
  10825. } elseif ($expenditureBank == '纵横工行') {
  10826. $accountBank = 'ICBCDeposit';
  10827. } elseif ($expenditureBank == '华润银行') {
  10828. $accountBank = 'HUADeposit';
  10829. } elseif ($expenditureBank == '个人广发') {
  10830. $accountBank = 'PersonalDeposit';
  10831. }
  10832. if (empty ( $accountBank ))
  10833. die ( 'illegal request' );
  10834. $itemWaste = array (
  10835. 'accountPrice' => - $expenditurePrice
  10836. );
  10837. if ($expenditureBank == '个人广发') {
  10838. $itemWaste = array (
  10839. 'accountPrice' => $expenditurePrice
  10840. );
  10841. }
  10842. if ($expenditureType == 4 || $expenditureType == 6) {
  10843. $dailyExpenditureType = 4;
  10844. if ($expenditureMsg == '公司固定') {
  10845. $accountTypeWaste = 9;
  10846. } elseif ($expenditureMsg == '公司活期') {
  10847. $accountTypeWaste = 10;
  10848. } elseif ($expenditureMsg == '个人(GR)') {
  10849. $accountBank = 'PersonalDeposit';
  10850. }
  10851. $itemWaste = array (
  10852. 'accountPrice' => $expenditurePrice
  10853. );
  10854. } elseif ($expenditureType == 1) {
  10855. $dailyExpenditureType = 1;
  10856. } elseif ($expenditureType == 2) {
  10857. $dailyExpenditureType = 2;
  10858. } elseif ($expenditureType == 3) {
  10859. $dailyExpenditureType = 3;
  10860. } elseif ($expenditureType == 5) {
  10861. $dailyExpenditureType = 5;
  10862. }
  10863. if (empty ( $dailyExpenditureType ))
  10864. die ( 'illegal request' );
  10865. Doo::loadModel ( "accountBook" );
  10866. $accountBook = new accountBook ();
  10867. $accountBook->expenditureType = $expenditureType;
  10868. $accountBook->expenditureMsg = $expenditureMsg;
  10869. $accountBook->expenditurePrice = $expenditurePrice;
  10870. $accountBook->expenditureBank = $expenditureBank;
  10871. $accountBook->expenditureDate = $expenditureDate;
  10872. $accountBook->remarks = $remarks;
  10873. $accountBook->expensesType = 2;
  10874. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10875. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10876. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10877. $id = $accountBook->insert ();
  10878. //
  10879. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10880. Doo::loadModel ( "accountBookStatistics" );
  10881. $accountBookStatistics = new accountBookStatistics ();
  10882. $item = array (
  10883. 'date' => date ( "Y-m-d" ),
  10884. 'expenditureType' => $abDetail ['expenditureType'],
  10885. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10886. 'aid' => $abDetail ['aid']
  10887. );
  10888. if ($abDetail ['expensesType'] == 2) {
  10889. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10890. $item += array (
  10891. 'financingPrice' => $expenditurePrice,
  10892. 'expensesType' => 3
  10893. );
  10894. } elseif ($abDetail ['expenditureType'] == 5) {
  10895. $item += array (
  10896. 'payPrice' => $abDetail ['expenditurePrice'],
  10897. 'expensesType' => $abDetail ['expensesType']
  10898. );
  10899. } else {
  10900. $item += array (
  10901. 'payPrice' => $abDetail ['expenditurePrice'],
  10902. 'expensesType' => $abDetail ['expensesType']
  10903. );
  10904. }
  10905. }
  10906. $accountBookStatistics->setAccountBookStatistics ( $item );
  10907. // 公司流水记录
  10908. Doo::loadModel ( 'wasteBook' );
  10909. $wasteBook = new wasteBook ();
  10910. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10911. // 银行
  10912. if (empty ( $abDetail )) {
  10913. $itemWaste += array (
  10914. 'accountPriceShow' => $expenditurePrice,
  10915. 'dataID' => $id,
  10916. 'expensesType' => 2,
  10917. 'accountType' => $accountTypeWaste,
  10918. 'dailyExpenditureType' => $expenditureType,
  10919. 'accountBank' => $accountBank,
  10920. 'category' => $this->staff [0] ['category'],
  10921. 'cid' => $this->staff [0] ['cid'],
  10922. 'name' => $this->staff [0] ['username'],
  10923. 'sid' => $this->staff [0] ['sid'],
  10924. 'inputDate' => date ( "Y-m-d H:i:s" )
  10925. );
  10926. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10927. }
  10928. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10929. if ($expenditureType == 4 || $expenditureType == 6) {
  10930. $accountBank = 'CGBDeposit';
  10931. $dailyIncomeType = 7;
  10932. $receivedBank = '纵横广发';
  10933. if ($expenditureType == 6) {
  10934. $accountBank = 'ICBCDeposit';
  10935. $receivedBank = '纵横工行';
  10936. $dailyIncomeType = 9;
  10937. }
  10938. // 添加一笔收入
  10939. $accountBook = new accountBook ();
  10940. $accountBook->accountType = $dailyIncomeType;
  10941. $accountBook->accountMsg = $expenditureMsg;
  10942. $accountBook->receivedPrice = $expenditurePrice;
  10943. $accountBook->receivedBank = $receivedBank;
  10944. $accountBook->receivedDate = $expenditureDate;
  10945. $accountBook->remarks = $remarks;
  10946. $accountBook->expensesType = 1;
  10947. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10948. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10949. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10950. $id = $accountBook->insert ();
  10951. // 添加一笔收入流水
  10952. $itemWaste = array (
  10953. 'accountPriceShow' => $expenditurePrice,
  10954. 'accountPrice' => - $expenditurePrice,
  10955. 'dataID' => $id,
  10956. 'expensesType' => 1,
  10957. 'accountType' => $accountTypeWaste,
  10958. 'dailyIncomeType' => $dailyIncomeType,
  10959. 'accountBank' => $accountBank,
  10960. 'category' => $this->staff [0] ['category'],
  10961. 'cid' => $this->staff [0] ['cid'],
  10962. 'name' => $this->staff [0] ['username'],
  10963. 'sid' => $this->staff [0] ['sid'],
  10964. 'inputDate' => date ( "Y-m-d H:i:s" )
  10965. );
  10966. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10967. }
  10968. }
  10969. return '/payments';
  10970. }
  10971. /**
  10972. * 所有收支
  10973. */
  10974. function paymentsAchieve() {
  10975. $page_size = 12;
  10976. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10977. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10978. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10979. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10980. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10981. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10982. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10983. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10984. Doo::loadModel ( "accountBookStatistics" );
  10985. $accountBookStatistics = new accountBookStatistics ();
  10986. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10987. $data ['statisticsList'] = $statisticsList;
  10988. Doo::loadModel ( "accountBook" );
  10989. $accountBook = new accountBook ();
  10990. $con = '';
  10991. if ($expensesType == 'INCOME')
  10992. $con = ' and expensesType=1 ';
  10993. elseif ($expensesType == 'PAY')
  10994. $con = ' and expensesType=2 ';
  10995. $dateArr = explode ( ':', $date );
  10996. $D1 = $dateString = '';
  10997. $D2 = '';
  10998. if (! empty ( $date )) {
  10999. $D1 = $dateArr [0];
  11000. if (isset ( $dateArr [1] ))
  11001. $D2 = $dateArr [1];
  11002. else
  11003. $D2 = '';
  11004. $dateString = $D1 . " : " . $D2;
  11005. }
  11006. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11007. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11008. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11009. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11010. if (! empty ( $price ))
  11011. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11012. if ($submitType == 1) {
  11013. if ($accountType != '') {
  11014. $expenditureType = '';
  11015. $con .= ' and accountType=' . $accountType;
  11016. if (! empty ( $accountMsg ))
  11017. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11018. }
  11019. } elseif ($submitType == 2) {
  11020. if ($expenditureType != '') {
  11021. $accountType = $accountMsg = '';
  11022. $con .= ' and expenditureType=' . $expenditureType;
  11023. }
  11024. } else {
  11025. $accountType = $accountMsg = $expenditureType = '';
  11026. }
  11027. $sql = "" . $con;
  11028. $action = "paymentsAchieve";
  11029. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11030. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11031. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11032. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11033. $data ['expenditureType'] = $expenditureType;
  11034. $data ['accountMsg'] = $accountMsg;
  11035. $data ['accountType'] = $accountType;
  11036. $data ['inputDate'] = $date;
  11037. $data ['price'] = $price;
  11038. $data ['expensesType'] = $expensesType;
  11039. $data ['page'] = $pageinfo;
  11040. $data ['list'] = $list;
  11041. $data ['memu'] = "receipt";
  11042. $data ['staff'] = $this->staff;
  11043. $data ['receiptMemu'] = 'payments';
  11044. $data ['verifyId'] = $this->verifyId;
  11045. $data ['executeId'] = $this->executeId;
  11046. $this->render ( "/expenses/paymentsAchieve", $data );
  11047. }
  11048. function paymentsIncomeUpdateDo() {
  11049. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11050. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11051. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11052. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11053. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11054. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11055. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11056. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11057. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11058. Doo::loadClass ( 'XDeode' );
  11059. $XDeode = new XDeode ( 5 );
  11060. $aid = $XDeode->decode ( $aidKey );
  11061. Doo::loadModel ( "accountBook" );
  11062. $accountBook = new accountBook ();
  11063. //
  11064. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11065. $price = $receivedPrice - $abDetail [inComePrice];
  11066. Doo::loadModel ( "accountBookStatistics" );
  11067. $accountBookStatistics = new accountBookStatistics ();
  11068. if ($abDetail ['accountType'] == 7) {
  11069. $item += array (
  11070. 'date' => date ( "Y-m-d" ),
  11071. 'financingPrice' => - $price,
  11072. 'expensesType' => 3,
  11073. 'aid' => $abDetail ['aid']
  11074. );
  11075. } elseif ($abDetail ['accountType'] == 8) {
  11076. $item += array (
  11077. 'date' => date ( "Y-m-d" ),
  11078. 'expensesType' => $abDetail ['expensesType'],
  11079. 'inComePrice' => - $price,
  11080. 'aid' => $abDetail ['aid']
  11081. );
  11082. } else {
  11083. $item = array (
  11084. 'date' => date ( "Y-m-d" ),
  11085. 'expensesType' => $abDetail ['expensesType'],
  11086. 'inComePrice' => $price,
  11087. 'aid' => $abDetail ['aid']
  11088. );
  11089. }
  11090. $accountBookStatistics->setAccountBookStatistics ( $item );
  11091. $accountBook->accountType = $accountType;
  11092. $accountBook->accountMsg = $accountMsg;
  11093. $accountBook->receivedPrice = $receivedPrice;
  11094. $accountBook->receivedMsg = $receivedMsg;
  11095. $accountBook->receivedBank = $receivedBank;
  11096. $accountBook->receivedDate = $receivedDate;
  11097. $accountBook->remarks = $remarks;
  11098. $accountBook->aid = $aid;
  11099. $accountBook->update ();
  11100. }
  11101. return '/paymentsAchieve';
  11102. }
  11103. function paymentsExpenditureEdiDo() {
  11104. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11105. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11106. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11107. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11108. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11109. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11110. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11111. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11112. Doo::loadClass ( 'XDeode' );
  11113. $XDeode = new XDeode ( 5 );
  11114. $aid = $XDeode->decode ( $aidKey );
  11115. Doo::loadModel ( "accountBook" );
  11116. $accountBook = new accountBook ();
  11117. // 汇总信息
  11118. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11119. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11120. Doo::loadModel ( "accountBookStatistics" );
  11121. $accountBookStatistics = new accountBookStatistics ();
  11122. if ($abDetail ['expenditureType'] == 4) {
  11123. $item += array (
  11124. 'date' => date ( "Y-m-d" ),
  11125. 'financingPrice' => $price,
  11126. 'expensesType' => 3,
  11127. 'aid' => $abDetail ['aid']
  11128. );
  11129. } elseif ($abDetail ['expenditureType'] == 5) {
  11130. $item += array (
  11131. 'date' => date ( "Y-m-d" ),
  11132. 'expensesType' => $abDetail ['expensesType'],
  11133. 'payPrice' => $price,
  11134. 'aid' => $abDetail ['aid']
  11135. );
  11136. } else {
  11137. $item = array (
  11138. 'date' => date ( "Y-m-d" ),
  11139. 'expensesType' => $abDetail ['expensesType'],
  11140. 'payPrice' => $price,
  11141. 'aid' => $abDetail ['aid']
  11142. );
  11143. }
  11144. $accountBookStatistics->setAccountBookStatistics ( $item );
  11145. //
  11146. $accountBook->expenditureType = $expenditureType;
  11147. $accountBook->expenditureMsg = $expenditureMsg;
  11148. $accountBook->expenditurePrice = $expenditurePrice;
  11149. $accountBook->expenditureBank = $expenditureBank;
  11150. $accountBook->remarks = $remarks;
  11151. $accountBook->expenditureDate = $expenditureDate;
  11152. $accountBook->aid = $aid;
  11153. $id = $accountBook->update ();
  11154. }
  11155. return '/paymentsAchieve';
  11156. }
  11157. function paymentsDelDo() {
  11158. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11159. if (! empty ( $aidKey )) {
  11160. Doo::loadClass ( 'XDeode' );
  11161. $XDeode = new XDeode ( 5 );
  11162. $aid = $XDeode->decode ( $aidKey );
  11163. Doo::loadModel ( "accountBook" );
  11164. $accountBook = new accountBook ();
  11165. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11166. if (empty ( $abDetail ))
  11167. die ( 'illegal request' );
  11168. // 删除收支
  11169. Doo::loadModel ( "accountBookStatistics" );
  11170. $accountBookStatistics = new accountBookStatistics ();
  11171. $item = array (
  11172. 'date' => date ( "Y-m-d" ),
  11173. 'aid' => $abDetail ['aid']
  11174. );
  11175. $accountType = '';
  11176. if ($abDetail ['expensesType'] == 1) {
  11177. $accountType = 6;
  11178. if ($abDetail ['accountType'] != 7) {
  11179. $item += array (
  11180. 'expensesType' => $abDetail ['expensesType'],
  11181. 'inComePrice' => - $abDetail ['receivedPrice']
  11182. );
  11183. } else {
  11184. $item += array (
  11185. 'financingPrice' => $abDetail ['receivedPrice'],
  11186. 'expensesType' => 3
  11187. );
  11188. }
  11189. } elseif ($abDetail ['expensesType'] == 2) {
  11190. $accountType = 5;
  11191. if ($abDetail ['accountType'] != 7) {
  11192. $item += array (
  11193. 'expensesType' => $abDetail ['expensesType'],
  11194. 'payPrice' => - $abDetail ['expenditurePrice']
  11195. );
  11196. } else {
  11197. $item += array (
  11198. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11199. 'expensesType' => 3
  11200. );
  11201. }
  11202. }
  11203. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11204. if ($abDetail ['expenditureMsg'] == '公司固定')
  11205. $accountType = 9;
  11206. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11207. $accountType = 10;
  11208. }
  11209. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11210. if ($abDetail ['accountMsg'] == '公司固定')
  11211. $accountType = 9;
  11212. elseif ($abDetail ['accountMsg'] == '公司活期')
  11213. $accountType = 10;
  11214. }
  11215. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11216. $accountType = 10;
  11217. }
  11218. $accountBookStatistics->setAccountBookStatistics ( $item );
  11219. $accountBook->delete ( array (
  11220. 'where' => 'aid=' . $aid,
  11221. 'limit' => 1
  11222. ) );
  11223. // 删除收入流水
  11224. if (! empty ( $accountType )) {
  11225. Doo::loadModel ( 'wasteBook' );
  11226. $wasteBook = new wasteBook ();
  11227. $wasteBook->delete ( array (
  11228. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11229. 'limit' => 1
  11230. ) );
  11231. }
  11232. }
  11233. return '/paymentsAchieve';
  11234. }
  11235. function paymentsCollect() {
  11236. Doo::loadModel ( "execute" );
  11237. $execute = new execute ();
  11238. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11239. die ( 'illegal request' );
  11240. }
  11241. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11242. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11243. Doo::loadModel ( "accountBookStatistics" );
  11244. $accountBookStatistics = new accountBookStatistics ();
  11245. Doo::loadClass ( 'receipt.func' );
  11246. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11247. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11248. $data ['html'] = $html ['html'];
  11249. $data ['inSum'] = $html ['sum'];
  11250. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11251. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11252. $data ['payHtml'] = $html ['html'];
  11253. $data ['paySum'] = $html ['sum'];
  11254. // 余额统计
  11255. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11256. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11257. include './protected/config/wasteBook.conf.php';
  11258. Doo::loadModel ( 'wasteBook' );
  11259. $wasteBook = new wasteBook ();
  11260. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11261. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11262. // 获得年份之前所有金额
  11263. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11264. // print_r($detail);
  11265. // $waste['total'];
  11266. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11267. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11268. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11269. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11270. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11271. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11272. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11273. if (date ( 'Y' ) > $year) {
  11274. $limitMonth = 12;
  11275. }
  11276. for($i = 1; $i <= 12; $i ++) {
  11277. $inComeA = $payB = 0;
  11278. $falg = true;
  11279. foreach ( $inComePay as $key => $value ) {
  11280. if ($value ['month'] == $i) {
  11281. $falg = false;
  11282. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11283. $inSum += $value ['accountPrice'];
  11284. $showInSum += $value ['accountPriceShow'];
  11285. $inComeA = $value ['accountPrice'];
  11286. break;
  11287. }
  11288. }
  11289. if ($falg)
  11290. $inComeHtml .= '<td class="taR">-</td>';
  11291. $payFalg = true;
  11292. foreach ( $pay as $key => $value ) {
  11293. if ($value ['month'] == $i) {
  11294. $payFalg = false;
  11295. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11296. $paySum += $value ['accountPrice'];
  11297. $showPaySum += $value ['accountPriceShow'];
  11298. $payB = $value ['accountPrice'];
  11299. break;
  11300. }
  11301. }
  11302. if ($payFalg)
  11303. $payHtml .= '<td class="taR">-</td>';
  11304. if (empty ( $balanceC ) || $limitMonth < $i)
  11305. $lastBalanceHtml .= '<td class="taR">-</td>';
  11306. else
  11307. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11308. $balanceC = $balanceC + $inComeA + $payB;
  11309. $balanceSum += $balanceC;
  11310. if (empty ( $balanceC ) || $limitMonth < $i)
  11311. $BalanceHtml .= '<td class="taR">-</td>';
  11312. else
  11313. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11314. // 余额统计
  11315. }
  11316. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11317. $data ['inComeHtml'] = $inComeHtml;
  11318. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11319. $data ['payBalanceHtml'] = $payHtml;
  11320. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11321. $data ['BalanceHtml'] = $BalanceHtml;
  11322. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11323. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11324. $mothHtml = "";
  11325. for($i = 1; $i <= 12; $i ++) {
  11326. if ($moth == $i)
  11327. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11328. else
  11329. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11330. }
  11331. $data ['mothHtml'] = $mothHtml;
  11332. $dateHtml = "";
  11333. $now = date ( "Y" );
  11334. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11335. if ($YEARD <= $now) {
  11336. $dateHtml .= '<option ';
  11337. if ($year == $YEARD) {
  11338. $dateHtml .= 'selected ';
  11339. }
  11340. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11341. }
  11342. }
  11343. $data ['dateHtml'] = $dateHtml;
  11344. $data ['year'] = $year;
  11345. $data ['memu'] = "receipt";
  11346. $data ['staff'] = $this->staff;
  11347. $data ['receiptMemu'] = 'paymentsCollect';
  11348. $data ['verifyId'] = $this->verifyId;
  11349. $data ['executeId'] = $this->executeId;
  11350. $this->render ( "/expenses/paymentsCollect", $data );
  11351. }
  11352. function paymentsCollectDay() {
  11353. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11354. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11355. if (empty ( $moth ))
  11356. return 'paymentsCollect';
  11357. Doo::loadModel ( "accountBookStatistics" );
  11358. $accountBookStatistics = new accountBookStatistics ();
  11359. $i = 2;
  11360. $y = 2013;
  11361. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11362. Doo::loadClass ( 'receipt.func' );
  11363. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11364. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11365. $data ['html'] = $html ['html'];
  11366. $data ['inSum'] = $html ['sum'];
  11367. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11368. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11369. $data ['payHtml'] = $html ['html'];
  11370. $data ['paySum'] = $html ['sum'];
  11371. $mothHtml = "";
  11372. for($i = 1; $i <= 12; $i ++) {
  11373. if ($moth == $i)
  11374. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11375. else
  11376. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11377. }
  11378. $data ['mothHtml'] = $mothHtml;
  11379. $data ['year'] = $year;
  11380. // 余额
  11381. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11382. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11383. include './protected/config/wasteBook.conf.php';
  11384. Doo::loadModel ( 'wasteBook' );
  11385. $wasteBook = new wasteBook ();
  11386. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11387. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11388. // 获得年份之前所有金额
  11389. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11390. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11391. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11392. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11393. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11394. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11395. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11396. // $balanceC = 0;
  11397. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11398. $limitDay = date ( 'd' );
  11399. $monthLK = ( int ) date ( 'm' );
  11400. if (date ( 'Y' ) > $year) {
  11401. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11402. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11403. $limitDay = 0;
  11404. }
  11405. for($i = 1; $i <= $day; $i ++) {
  11406. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11407. $inComeA = $payB = 0;
  11408. $falg = true;
  11409. foreach ( $inComePay as $key => $value ) {
  11410. if ($value ['day'] == $i) {
  11411. $falg = false;
  11412. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11413. $inSum += $value ['accountPrice'];
  11414. $showInSum += $value ['accountPriceShow'];
  11415. $inComeA = $value ['accountPrice'];
  11416. break;
  11417. }
  11418. }
  11419. if ($falg)
  11420. $inComeHtml .= '<td class="taR">-</td>';
  11421. $payFalg = true;
  11422. foreach ( $pay as $key => $value ) {
  11423. if ($value ['day'] == $i) {
  11424. $payFalg = false;
  11425. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11426. $paySum += $value ['accountPrice'];
  11427. $showPaySum += $value ['accountPriceShow'];
  11428. $payB = $value ['accountPrice'];
  11429. break;
  11430. }
  11431. }
  11432. if ($payFalg)
  11433. $payHtml .= '<td class="taR">-</td>';
  11434. if (empty ( $balanceC ) || $limitDay < $i)
  11435. $lastBalanceHtml .= '<td class="taR">-</td>';
  11436. else
  11437. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11438. $balanceC = $balanceC + $inComeA + $payB;
  11439. $balanceSum += $balanceC;
  11440. if (empty ( $balanceC ) || $limitDay < $i)
  11441. $BalanceHtml .= '<td class="taR">-</td>';
  11442. else
  11443. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11444. }
  11445. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11446. $data ['inComeHtml'] = $inComeHtml;
  11447. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11448. $data ['payBalanceHtml'] = $payHtml;
  11449. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11450. $data ['BalanceHtml'] = $BalanceHtml;
  11451. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11452. $data ['dayHtml'] = $dayHtml;
  11453. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11454. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11455. $dateHtml = "";
  11456. $now = date ( "Y" );
  11457. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11458. if ($YEARD <= $now) {
  11459. $dateHtml .= '<option ';
  11460. if ($year == $YEARD) {
  11461. $dateHtml .= 'selected ';
  11462. }
  11463. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11464. }
  11465. }
  11466. $data ['dateHtml'] = $dateHtml;
  11467. $data ['memu'] = "receipt";
  11468. $data ['staff'] = $this->staff;
  11469. $data ['receiptMemu'] = 'paymentsCollect';
  11470. $data ['verifyId'] = $this->verifyId;
  11471. $data ['executeId'] = $this->executeId;
  11472. $this->render ( "/expenses/paymentsCollectDay", $data );
  11473. }
  11474. // 公司流水
  11475. function wasteBook() {
  11476. Doo::loadModel ( "execute" );
  11477. $execute = new execute ();
  11478. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11479. die ( 'illegal request' );
  11480. }
  11481. include './protected/config/wasteBook.conf.php';
  11482. Doo::loadModel ( 'wasteBook' );
  11483. $wasteBook = new wasteBook ();
  11484. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11485. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11486. $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'];
  11487. // print_r($waste);
  11488. $data ['waste'] = $waste;
  11489. $data ['total'] = $total;
  11490. // 月流水数据结构
  11491. $monthStatistics = array ();
  11492. $incomeMothStatistics = array ();
  11493. $expenditureMothStatistics = array ();
  11494. for($i = 1; $i <= 12; $i ++) {
  11495. $month = date ( 'Y' ) . '-' . $i;
  11496. if ($i < 10)
  11497. $month = date ( 'Y' ) . '-0' . $i;
  11498. array_push ( $monthStatistics, $month );
  11499. }
  11500. foreach ( $monthStatistics as $value ) {
  11501. $falg = true;
  11502. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11503. if ($value == $v ['inputDate']) {
  11504. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11505. $falg = false;
  11506. }
  11507. }
  11508. if ($falg) {
  11509. array_push ( $incomeMothStatistics, '' );
  11510. }
  11511. $falgEx = true;
  11512. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11513. if ($value == $v ['inputDate']) {
  11514. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11515. $falg = false;
  11516. }
  11517. }
  11518. if ($falgEx) {
  11519. array_push ( $expenditureMothStatistics, '' );
  11520. }
  11521. }
  11522. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11523. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11524. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11525. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11526. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11527. // print_r($incomeList);
  11528. $data ['expenditureList'] = $expenditureList;
  11529. $data ['incomeList'] = $incomeList;
  11530. $data ['memu'] = "receipt";
  11531. $data ['staff'] = $this->staff;
  11532. $data ['receiptMemu'] = 'wasteBook';
  11533. $data ['verifyId'] = $this->verifyId;
  11534. $data ['executeId'] = $this->executeId;
  11535. $this->render ( "/expenses/wasteBook", $data );
  11536. }
  11537. function wasteBookIncome() {
  11538. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11539. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11540. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11541. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11542. $data ['dailyIncomeType'] = $dailyIncomeType;
  11543. Doo::loadModel ( 'wasteBook' );
  11544. $wasteBook = new wasteBook ();
  11545. Doo::loadModel ( 'L_category' );
  11546. $L_category = new L_category ();
  11547. Doo::loadClass ( 'XDeode' );
  11548. $XDeode = new XDeode ( 5 );
  11549. // echo $XDeode->encode(1).'<br>';
  11550. // echo $XDeode->encode(2).'<br>';
  11551. // echo $XDeode->encode(3).'<br>';
  11552. // echo $XDeode->encode(4).'<br>';
  11553. // echo $XDeode->encode(5).'<br>';
  11554. // echo $XDeode->encode(6).'<br>';
  11555. // echo $XDeode->encode(7).'<br>';
  11556. // echo $XDeode->encode(8).'<br>';
  11557. // echo $XDeode->encode(9).'<br>';
  11558. // echo $XDeode->encode(10).'<br>';
  11559. $year=date("Y");
  11560. $theDay=date("Y-m-d");
  11561. $dateArr = explode ( ':', $date );
  11562. $D1 = '';
  11563. $D2 = '';
  11564. $con = '';
  11565. if (! empty ( $date )) {
  11566. $D1 = $dateArr [0];
  11567. $D2 = $dateArr [1];
  11568. }
  11569. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11570. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11571. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11572. $con = ' and inputDate = "' . $D1 . '"';
  11573. else{
  11574. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11575. }
  11576. if ($cid != 'ALL') {
  11577. $cid = $XDeode->decode ( $cid );
  11578. $con .= ' and cid = "' . $cid . '"';
  11579. }
  11580. if ($accountType != 'ALL') {
  11581. if ($accountType == 'INVOICE') {
  11582. $con .= ' and (accountType = 7 or accountType = 8)';
  11583. } elseif ($accountType == 'PAYMENTS') {
  11584. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11585. if ($dailyIncomeType != 'ALL') {
  11586. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11587. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11588. }
  11589. }
  11590. }
  11591. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11592. $sum = 0;$thsDaySum=0;
  11593. foreach ( $incomeList as $key => $value ) {
  11594. $sum += $value ['accountPrice'];
  11595. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11596. $thsDaySum+=$value ['accountPrice'];
  11597. }
  11598. }
  11599. // print_r($incomeList);
  11600. // 获得办事和部门
  11601. $categoryList = $L_category->getCategory ();
  11602. $data ['accountType'] = $accountType;
  11603. $data ['cid'] = $cid;
  11604. $data ['categoryList'] = $categoryList;
  11605. $data ['sum'] = $sum;
  11606. $data ['incomeList'] = $incomeList;
  11607. $data ['inputDate'] = $date;
  11608. $data['year']=$year;
  11609. $data ['thsDay'] =$theDay;
  11610. $data ['thsDaySum'] =$thsDaySum;
  11611. $data ['memu'] = "receipt";
  11612. $data ['staff'] = $this->staff;
  11613. $data ['receiptMemu'] = 'wasteBook';
  11614. $data ['verifyId'] = $this->verifyId;
  11615. $data ['executeId'] = $this->executeId;
  11616. $this->render ( "/expenses/wasteBookIncome", $data );
  11617. }
  11618. /**
  11619. * 所有支出
  11620. */
  11621. function wasteBookExpenditure() {
  11622. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11623. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11624. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11625. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11626. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11627. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11628. $data ['receiptType'] = $receiptType;
  11629. Doo::loadModel ( 'wasteBook' );
  11630. $wasteBook = new wasteBook ();
  11631. Doo::loadModel ( 'L_category' );
  11632. $L_category = new L_category ();
  11633. Doo::loadClass ( 'XDeode' );
  11634. $XDeode = new XDeode ( 5 );
  11635. $year=date("Y");
  11636. $theDay=date("Y-m-d");
  11637. $dateArr = explode ( ':', $date );
  11638. $D1 = '';
  11639. $D2 = '';
  11640. $con = '';
  11641. if (! empty ( $date )) {
  11642. $D1 = $dateArr [0];
  11643. $D2 = $dateArr [1];
  11644. }
  11645. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11646. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11647. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11648. $con = ' and inputDate = "' . $D1 . '"';
  11649. else{
  11650. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11651. }
  11652. if ($cid != 'ALL') {
  11653. $cid = $XDeode->decode ( $cid );
  11654. $con .= ' and cid = "' . $cid . '"';
  11655. }
  11656. if ($accountType != 'ALL') {
  11657. if ($accountType == 'INVOICE') {
  11658. $con .= ' and accountType = 11';
  11659. } elseif ($accountType == 'PAYMENTS') {
  11660. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11661. if ($dailyExpenditureType != 'ALL') {
  11662. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11663. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11664. }
  11665. } elseif ($accountType == 'RECEIPT') {
  11666. if ($receiptType == 'ALL') {
  11667. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11668. } else {
  11669. $receiptType = $XDeode->decode ( $receiptType );
  11670. echo $receiptType;
  11671. if ($receiptType == 1) {
  11672. $con .= ' and (accountType = 1 or accountType=2)';
  11673. } else {
  11674. $con .= ' and accountType = ' . $receiptType;
  11675. }
  11676. }
  11677. }
  11678. }
  11679. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11680. $sum = 0;$thsDaySum=0;
  11681. foreach ( $incomeList as $key => $value ) {
  11682. $sum += $value ['accountPriceShow'];
  11683. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11684. $thsDaySum+=$value ['accountPriceShow'];
  11685. }
  11686. }
  11687. // print_r($incomeList);
  11688. // 获得办事和部门
  11689. $categoryList = $L_category->getCategory ();
  11690. $data ['accountType'] = $accountType;
  11691. $data ['cid'] = $cid;
  11692. $data ['categoryList'] = $categoryList;
  11693. $data ['sum'] = $sum;
  11694. $data ['incomeList'] = $incomeList;
  11695. $data ['inputDate'] = $date;
  11696. $data['year']=$year;
  11697. $data ['thsDay'] =$theDay;
  11698. $data ['thsDaySum'] =$thsDaySum;
  11699. $data ['memu'] = "receipt";
  11700. $data ['staff'] = $this->staff;
  11701. $data ['receiptMemu'] = 'wasteBook';
  11702. $data ['verifyId'] = $this->verifyId;
  11703. $data ['executeId'] = $this->executeId;
  11704. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11705. }
  11706. function ajaxGetWasteinvoiceReceivables() {
  11707. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11708. Doo::loadClass ( 'XDeode' );
  11709. $XDeode = new XDeode ( 5 );
  11710. $irid = $XDeode->decode ( $serial );
  11711. Doo::loadModel ( 'invoiceReceivables' );
  11712. $invoiceReceivables = new invoiceReceivables ();
  11713. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11714. echo json_encode ( array (
  11715. 'status' => 1,
  11716. 'detail' => $detail
  11717. ) );
  11718. }
  11719. function ajaxGetPaymentsByAid() {
  11720. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11721. Doo::loadModel ( "accountBook" );
  11722. $accountBook = new accountBook ();
  11723. $detail = $accountBook->getAccountBookByAid ( $serial );
  11724. echo json_encode ( array (
  11725. 'status' => 1,
  11726. 'detail' => $detail
  11727. ) );
  11728. }
  11729. function ajaxGetWasteInvoice() {
  11730. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11731. Doo::loadModel ( 'invoice' );
  11732. $invoice = new invoice ();
  11733. Doo::loadModel ( 'invoiceReceivables' );
  11734. $invoiceReceivables = new invoiceReceivables ();
  11735. $detail = $invoice->getInvoiceByIid ( $serial );
  11736. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11737. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11738. echo json_encode ( array (
  11739. 'status' => 1,
  11740. 'detail' => $detail
  11741. ) );
  11742. }
  11743. /**
  11744. */
  11745. function ajaxGetWasteReceipt() {
  11746. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11747. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11748. Doo::loadModel ( 'receipt' );
  11749. $receipt = new receipt ();
  11750. Doo::loadClass ( 'XDeode' );
  11751. $XDeode = new XDeode ( 5 );
  11752. $rid = $XDeode->decode ( $serial );
  11753. $accountType= $XDeode->decode ( $accountTypeKey );
  11754. // 获得个数据
  11755. $detail = $receipt->getReceiptByRid ( $rid );
  11756. // 初始化
  11757. $detail ['reviseDetail'] = array ();
  11758. if (! empty ( $value ['reviseDetail'] ))
  11759. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11760. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11761. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11762. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11763. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11764. // 获得费用html
  11765. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11766. // 获得费用审批人数据
  11767. $detail = $this->getReceiptApproverHtml ( $detail );
  11768. // 审批执行
  11769. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11770. <th class="taC" width="90">审批人</th>
  11771. <th class="taC">审批意见</th></tr>';
  11772. foreach ( $detail ['verifyList'] as $key => $value ) {
  11773. $html .= '<tr>
  11774. <td>' . $value [1] . '</td>
  11775. <td>' . $value ['opinion'] . '</td>
  11776. </tr>
  11777. ';
  11778. }
  11779. $html .= ' </tbody></table>';
  11780. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11781. <th class="taC" width="90">执行人</th>
  11782. <th class="taC">执行意见</th></tr>';
  11783. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11784. $html .= '<tr>
  11785. <td>' . $value [1] . '</td>
  11786. <td>' . $value ['opinion'] . '</td>
  11787. </tr>
  11788. ';
  11789. }
  11790. $html .= ' </tbody></table>';
  11791. if($accountType==1){
  11792. Doo::loadModel ( 'loanReceipt' );
  11793. $loanReceipt = new loanReceipt ();
  11794. $loanList = $loanReceipt->getOne ( array (
  11795. 'where' => 'rid=' . $detail ['loanRid'],
  11796. 'desc' => 'rid',
  11797. 'asArray' => true
  11798. ) );
  11799. $html .= '<table class="table table-bordered table-condensed">
  11800. <tr class="warning">
  11801. <td class="taR"><b>汇款金额</b></td>
  11802. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11803. </tr>
  11804. </table>';
  11805. }else{
  11806. $html .= '<table class="table table-bordered table-condensed">
  11807. <tr class="warning">
  11808. <td class="taR"><b>汇款金额</b></td>
  11809. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11810. </tr>
  11811. </table>';
  11812. }
  11813. // print_r($detail['verifyList']);
  11814. // header ( 'Content-Type:text/html;charset=utf-8' );
  11815. // echo $html;
  11816. echo json_encode ( array (
  11817. 'status' => 1,
  11818. 'html' => $html,
  11819. 'detail' => $detail
  11820. ) );
  11821. }
  11822. function getReceiptApproverHtml($detail = array()) {
  11823. Doo::loadModel ( 'loanReceipt' );
  11824. $loanReceipt = new loanReceipt ();
  11825. Doo::loadModel ( 'verify' );
  11826. $verify = new verify ();
  11827. Doo::loadModel ( 'staff' );
  11828. $staff = new staff ();
  11829. if (empty ( $detail ))
  11830. return array ();
  11831. $loanList = $loanReceipt->getOne ( array (
  11832. 'where' => 'rid=' . $detail ['loanRid'],
  11833. 'desc' => 'rid',
  11834. 'asArray' => true
  11835. ) );
  11836. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11837. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11838. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11839. else
  11840. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11841. } else
  11842. $verifyList = $verify->getOne ( array (
  11843. 'where' => 'vid=' . $detail ['verify'],
  11844. 'asArray' => true
  11845. ) );
  11846. $verifyList = json_decode ( $verifyList ['staff'], true );
  11847. Doo::loadModel ( 'role' );
  11848. $role = new role ();
  11849. $roleId = 0;
  11850. $flag = true;
  11851. $roleKey = 0;
  11852. $endStaffArray = array ();
  11853. $roleArrayCopy = array ();
  11854. foreach ( $verifyList as $k => $v ) {
  11855. // init verifyStaff
  11856. if ($v [1] == 'ROLE') {
  11857. if (! empty ( $verifyStaff )) {
  11858. $endStaffArray = end ( $verifyStaff );
  11859. }
  11860. $roleVerify = json_decode ( $v [3], true );
  11861. $roleKey = $k;
  11862. $roleArray = array ();
  11863. $rolename = $role->getOne ( array (
  11864. 'where' => 'rid=' . $v [0],
  11865. 'asArray' => true
  11866. ) );
  11867. foreach ( $roleVerify as $o => $p ) {
  11868. $staffID = explode ( '_', $p );
  11869. $staffInfo = $staff->getOne ( array (
  11870. 'where' => 'sid=' . $staffID [0],
  11871. 'asArray' => true
  11872. ) );
  11873. // print_r($staffID);
  11874. $exp = array (
  11875. 0 => $staffInfo ['sid'],
  11876. 1 => $staffID [1],
  11877. 2 => $staffInfo ['avatar'],
  11878. 'date' => '',
  11879. 'date' => '',
  11880. 'opinion' => '',
  11881. 'status' => '',
  11882. 'rolename' => $rolename ['name']
  11883. );
  11884. array_push ( $roleArray, $exp );
  11885. }
  11886. $roleArrayCopy [$v [0]] = $roleArray;
  11887. // $verifyList[$k]['roleArray']=$roleArray;
  11888. }
  11889. $verifyList [$k] ['date'] = "";
  11890. $verifyList [$k] ['opinion'] = "";
  11891. $verifyList [$k] ['status'] = "";
  11892. if (empty ( $verifyStaff )) {
  11893. $verifyList [$k] ['date'] = "";
  11894. $verifyList [$k] ['opinion'] = "";
  11895. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11896. $verifyList [$k] ['status'] = 4;
  11897. $flag = false;
  11898. }
  11899. } else {
  11900. foreach ( $verifyStaff as $m => $u ) {
  11901. if ($v [0] == $m) {
  11902. $verifyList [$k] ['date'] = $u ['date'];
  11903. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11904. $verifyList [$k] ['status'] = $u ['status'];
  11905. $flag = false;
  11906. break;
  11907. }
  11908. }
  11909. $endStaffArray = end ( $verifyStaff );
  11910. }
  11911. }
  11912. $rolename ['name'] = '';
  11913. if (! empty ( $roleId )) {
  11914. Doo::loadModel ( 'role' );
  11915. $role = new role ();
  11916. $rolename = $role->getOne ( array (
  11917. 'where' => 'rid=' . $roleId,
  11918. 'asArray' => true
  11919. ) );
  11920. }
  11921. if (! empty ( $verifyStaff ))
  11922. $endStaffArray = end ( $verifyStaff );
  11923. $KOP = false;
  11924. foreach ( $roleArrayCopy as $P => $A ) {
  11925. foreach ( $A as $MKI => $AVL ) {
  11926. if (! empty ( $verifyStaff )) {
  11927. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11928. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11929. $button = 4;
  11930. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11931. }
  11932. foreach ( $verifyStaff as $m => $u ) {
  11933. $AVLFK = $AVL [0] . '_R';
  11934. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11935. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11936. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11937. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11938. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11939. break;
  11940. }
  11941. }
  11942. } else {
  11943. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11944. $button = 4;
  11945. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11946. }
  11947. }
  11948. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11949. $KOP = true;
  11950. }
  11951. }
  11952. foreach ( $roleArrayCopy as $k => $v ) {
  11953. foreach ( $verifyList as $m => $n ) {
  11954. if ($n [0] == $k) {
  11955. array_splice ( $verifyList, $m, 1, $v );
  11956. }
  11957. }
  11958. }
  11959. // 费用执行人相关数据
  11960. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11961. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11962. foreach ( $executeCopy as $k => $v ) {
  11963. $executeCopy [$k] ['date'] = '';
  11964. $executeCopy [$k] ['opinion'] = '';
  11965. $executeCopy [$k] ['status'] = '';
  11966. if (! empty ( $executeStaff ))
  11967. foreach ( $executeStaff as $m => $u ) {
  11968. if ($v [0] == $m) {
  11969. $executeCopy [$k] ['date'] = $u ['date'];
  11970. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11971. $executeCopy [$k] ['status'] = $u ['status'];
  11972. break;
  11973. }
  11974. }
  11975. }
  11976. $detail ['executeCopy'] = $executeCopy;
  11977. $detail ['verifyList'] = $verifyList;
  11978. return $detail;
  11979. }
  11980. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11981. if (empty ( $detail ))
  11982. return '';
  11983. $html = '';
  11984. if ($detail ['Rtype'] == 0) { // 报销单
  11985. $html .= '<table class="table table-bordered table-condensed">
  11986. <tbody>
  11987. <tr>
  11988. <th colspan="2" class="taC">日常相关费用</th>
  11989. </tr>';
  11990. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11991. $html .= '
  11992. <tr>
  11993. <th>' . $value ['name'] . '</th>
  11994. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11995. </tr>';
  11996. }
  11997. $html .= '
  11998. <tr>
  11999. <th class="taR">合计</th>
  12000. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12001. </tr>';
  12002. $html .= '<tr>
  12003. <th colspan="2" class="taC">差旅相关费用</th>
  12004. </tr>';
  12005. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12006. $html .= '
  12007. <tr>
  12008. <th>' . $value ['name'] . '</th>
  12009. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12010. </tr>';
  12011. }
  12012. $html .= '
  12013. <tr>
  12014. <th class="taR">合计</th>
  12015. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12016. </tr>';
  12017. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12018. $html .= '<tr>
  12019. <th colspan="2" class="taC">内部培训费用</th>
  12020. </tr>';
  12021. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12022. $html .= '
  12023. <tr>
  12024. <th>' . $value ['name'] . '</th>
  12025. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12026. </tr>';
  12027. }
  12028. $html .= '
  12029. <tr>
  12030. <th class="taR">合计</th>
  12031. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12032. </tr>';
  12033. }
  12034. $html .= '<tr>
  12035. <th colspan="2" class="taC">其他</th>
  12036. </tr>';
  12037. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12038. $html .= '
  12039. <tr>
  12040. <th>' . $value ['name'] . '</th>
  12041. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12042. </tr>';
  12043. }
  12044. $html .= '
  12045. <tr>
  12046. <th class="taR">合计</th>
  12047. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12048. </tr>';
  12049. $html .= '<tr>
  12050. <th colspan="2" class="taC">报销金额调整</th>
  12051. </tr>';
  12052. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12053. $html .= '
  12054. <tr>
  12055. <th>' . $value ['name'] . '</th>
  12056. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12057. </tr>';
  12058. }
  12059. $html .= '
  12060. <tr>
  12061. <th class="taR">合计</th>
  12062. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12063. </tr>';
  12064. $html .= '
  12065. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12066. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12067. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12068. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12069. <tr class="warning">
  12070. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12071. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12072. </tr>
  12073. </tbody>
  12074. </table>';
  12075. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12076. $html .= '
  12077. <table class="table table-bordered table-condensed">
  12078. <tbody>
  12079. <tr>
  12080. <th colspan="2" class="taC">办事处相关费用</th>
  12081. </tr>';
  12082. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12083. $html .= '
  12084. <tr>
  12085. <th>' . $value ['name'] . '</th>
  12086. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12087. </tr>';
  12088. }
  12089. $html .= '
  12090. <tr>
  12091. <th class="taR">合计</th>
  12092. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12093. </tr>';
  12094. $html .= '
  12095. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12096. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12097. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12098. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12099. <tr class="warning">
  12100. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12101. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12102. </tr>
  12103. </tbody>
  12104. </table>';
  12105. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12106. Doo::loadModel ( 'loanReceipt' );
  12107. $loanReceipt = new loanReceipt ();
  12108. $loanList = $loanReceipt->getOne ( array (
  12109. 'where' => 'rid=' . $detail ['loanRid'],
  12110. 'desc' => 'rid',
  12111. 'asArray' => true
  12112. ) );
  12113. // print_r($loanList);
  12114. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12115. $html .= '<table class="table table-bordered table-condensed">
  12116. <tbody>
  12117. <tr>
  12118. <th colspan="2" class="taC">借款费用</th>
  12119. </tr>';
  12120. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12121. $html .= '<tr>
  12122. <th>' . $value ['name'] . '</th>
  12123. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12124. </tr>';
  12125. }
  12126. $html .= '<tr>
  12127. <th class="taC" colspan="2">产生费用所在办事处</th>
  12128. </tr>
  12129. <tr>
  12130. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12131. </tr>
  12132. <tr>
  12133. <th class="taC" colspan="2">费用说明</th>
  12134. </tr>
  12135. <tr>
  12136. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12137. </tr>
  12138. <tr class="warning">
  12139. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12140. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12141. </tr>
  12142. </tbody>
  12143. </table>
  12144. ';
  12145. if ( $accountType==2) {
  12146. $balance=$detail ['sum']-$loanList ['sum'];
  12147. $balanceCN=$this->num_to_rmb($balance);
  12148. $html .= '<table class="table table-bordered table-condensed">
  12149. <tbody>
  12150. <tr>
  12151. <th colspan="2" class="taC">日常相关费用</th>
  12152. </tr>';
  12153. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12154. $html .= '
  12155. <tr>
  12156. <th>' . $value ['name'] . '</th>
  12157. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12158. </tr>';
  12159. }
  12160. $html .= '
  12161. <tr>
  12162. <th class="taR">合计</th>
  12163. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12164. </tr>';
  12165. $html .= '<tr>
  12166. <th colspan="2" class="taC">差旅相关费用</th>
  12167. </tr>';
  12168. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12169. $html .= '
  12170. <tr>
  12171. <th>' . $value ['name'] . '</th>
  12172. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12173. </tr>';
  12174. }
  12175. $html .= '
  12176. <tr>
  12177. <th class="taR">合计</th>
  12178. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12179. </tr>';
  12180. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12181. $html .= '<tr>
  12182. <th colspan="2" class="taC">内部培训费用</th>
  12183. </tr>';
  12184. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12185. $html .= '
  12186. <tr>
  12187. <th>' . $value ['name'] . '</th>
  12188. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12189. </tr>';
  12190. }
  12191. $html .= '
  12192. <tr>
  12193. <th class="taR">合计</th>
  12194. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12195. </tr>';
  12196. }
  12197. $html .= '<tr>
  12198. <th colspan="2" class="taC">其他</th>
  12199. </tr>';
  12200. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12201. $html .= '
  12202. <tr>
  12203. <th>' . $value ['name'] . '</th>
  12204. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12205. </tr>';
  12206. }
  12207. $html .= '
  12208. <tr>
  12209. <th class="taR">合计</th>
  12210. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12211. </tr>';
  12212. $html .= '<tr>
  12213. <th colspan="2" class="taC">报销金额调整</th>
  12214. </tr>';
  12215. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12216. $html .= '
  12217. <tr>
  12218. <th>' . $value ['name'] . '</th>
  12219. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12220. </tr>';
  12221. }
  12222. $html .= '
  12223. <tr>
  12224. <th class="taR">合计</th>
  12225. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12226. </tr>';
  12227. $html .= '
  12228. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12229. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12230. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12231. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12232. <tr class="warning">
  12233. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12234. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12235. </tr>
  12236. <tr class="success">
  12237. <td class="taR"><b>借款结余</b></td>
  12238. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12239. </tr>
  12240. </tbody>
  12241. </table>';
  12242. }
  12243. }
  12244. return $html;
  12245. }
  12246. /**
  12247. * 计算流水
  12248. */
  12249. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12250. $bakWaste ['bank'] = array (
  12251. 'CGBDeposit' => 0,
  12252. 'ICBCDeposit' => 0,
  12253. 'HUADeposit' => 0,
  12254. 'PersonalDeposit' => 0
  12255. );
  12256. $bakWaste ['financial'] = array (
  12257. 'current' => array (
  12258. 'CGBDeposit' => 0,
  12259. 'ICBCDeposit' => 0
  12260. ),
  12261. 'fixed' => array (
  12262. 'CGBDeposit' => 0,
  12263. 'ICBCDeposit' => 0
  12264. )
  12265. );
  12266. // 存款
  12267. foreach ( $waste ['bank'] as $key => $value ) {
  12268. // 收入
  12269. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12270. // 广发
  12271. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12272. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12273. }
  12274. // 工商
  12275. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12276. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12277. }
  12278. // 华润
  12279. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12280. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12281. }
  12282. // 个人
  12283. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12284. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12285. }
  12286. }
  12287. }
  12288. foreach ( $waste ['bank'] as $key => $value ) {
  12289. // 支出
  12290. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12291. // 广发
  12292. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12293. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12294. }
  12295. // 工商
  12296. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12297. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12298. }
  12299. // 华润
  12300. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12301. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12302. }
  12303. // 个人
  12304. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12305. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12306. }
  12307. }
  12308. }
  12309. // 活期
  12310. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12311. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12312. // 广发
  12313. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12314. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12315. }
  12316. // 工商
  12317. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12318. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12319. }
  12320. // 个人
  12321. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12322. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12323. }
  12324. }
  12325. }
  12326. // print_r($inComeStatistics ['fixedStatistics']);
  12327. // 固期
  12328. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12329. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12330. // 广发
  12331. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12332. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12333. }
  12334. // 工商
  12335. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12336. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12337. }
  12338. // 个人
  12339. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12340. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12341. }
  12342. }
  12343. }
  12344. return $waste;
  12345. }
  12346. function lyt() {
  12347. Doo::loadModel ( "receiptDetail" );
  12348. $receiptDetail = new receiptDetail ();
  12349. $receiptCollectList = $receiptDetail->find ( array (
  12350. 'where' => 'status=1 ',
  12351. 'asArray' => true
  12352. ) );
  12353. foreach ( $receiptCollectList as $key => $value ) {
  12354. $receiptDetail = new receiptDetail ();
  12355. $receiptDetail->pastDate = $value ['date'];
  12356. $receiptDetail->update ( array (
  12357. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12358. ) );
  12359. }
  12360. }
  12361. function staffCollectMonthDetail() {
  12362. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12363. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12364. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12365. if (! $year)
  12366. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12367. if (! $month)
  12368. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12369. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12370. if (! $nature){
  12371. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12372. }
  12373. Doo::loadModel ( 'staff' );
  12374. $staff = new staff ();
  12375. Doo::loadModel ( "receiptDetail" );
  12376. $receiptDetail = new receiptDetail ();
  12377. Doo::loadModel ( 'accountItem' );
  12378. $accountItem = new accountItem ();
  12379. Doo::loadModel ( 'statistics' );
  12380. $statistics = new statistics ();
  12381. Doo::loadModel ( "receiptAuthorityManage" );
  12382. $receiptAuthorityManage = new receiptAuthorityManage ();
  12383. $aiList=$accountItem->getAccountItem();
  12384. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12385. $cidList = array ();
  12386. foreach ( $imcStaff as $key => $value ) {
  12387. array_push ( $cidList, $value ['cid'] );
  12388. }
  12389. $cidString = implode ( ',', $cidList );
  12390. $naturecon='';
  12391. if ($nature=='ONJOB'){
  12392. $naturecon=' and (nature!=4 )';
  12393. }elseif($nature=='LEAVEJOB'){
  12394. $naturecon=' and (nature=4 )';
  12395. }else{
  12396. die ( 'illegal request--nature' );
  12397. }
  12398. $staffList = $staff->find ( array (
  12399. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12400. 'asArray' => true
  12401. ) );
  12402. $categoryList = $staff->find ( array (
  12403. 'select' => 'COUNT(*) as count,cid,category',
  12404. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12405. 'groupby' => 'cid',
  12406. 'asArray' => true
  12407. ) );
  12408. $list = array ();
  12409. foreach($aiList as $key=>$value){
  12410. foreach ($value as $v){
  12411. $subtotal[$key][$v['name']]=0;
  12412. }
  12413. }
  12414. foreach ( $categoryList as $vlu ) {
  12415. $s1 = 0;
  12416. $m1 = 0;
  12417. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12418. foreach ( $staffList as $value ) {
  12419. if ($vlu ['cid'] == $value ['cid']) {
  12420. // pastDate
  12421. $receiptCollectList = $receiptDetail->find ( array (
  12422. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12423. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12424. 'groupby' => 'item,Month(pastDate),itemCategory',
  12425. 'asArray' => true
  12426. ) );
  12427. if (! empty ( $receiptCollectList )) {
  12428. $receiptL = array (
  12429. '日常相关费用' => array (),
  12430. '差旅相关费用' => array (),
  12431. '内部培训费用' => array (),
  12432. '培训班费用' => array (),
  12433. '其他' => array ()
  12434. );
  12435. $html = "";
  12436. $psum = 0;
  12437. foreach ( $aiList[$this->AGENCY] as $va ) {
  12438. $falg = true;
  12439. foreach ( $receiptCollectList as $v ) {
  12440. if ($v ['itemCategory'] == '日常相关费用') {
  12441. if ($v ['item'] == $va['name']) {
  12442. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12443. $psum += $v ['price'];
  12444. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12445. $falg = false;
  12446. break;
  12447. }
  12448. }
  12449. }
  12450. if ($falg)
  12451. $html .= '<td class="taR">-</td>';
  12452. }
  12453. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12454. if (! empty ( $psum ))
  12455. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12456. else
  12457. $psum = '<td class="colGreen taR">-</td>';
  12458. $receiptL ['日常相关费用'] = $psum . $html;
  12459. /* ----------------------------------- */
  12460. $html = "";
  12461. $psum = 0;
  12462. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12463. $falg = true;
  12464. foreach ( $receiptCollectList as $v ) {
  12465. if ($v ['itemCategory'] == '差旅相关费用') {
  12466. if ($v ['item'] == $va['name']) {
  12467. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12468. $psum += $v ['price'];
  12469. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12470. $falg = false;
  12471. break;
  12472. }
  12473. }
  12474. }
  12475. if ($falg)
  12476. $html .= '<td class="taR">-</td>';
  12477. }
  12478. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12479. if (! empty ( $psum ))
  12480. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12481. else
  12482. $psum = '<td class="colGreen taR">-</td>';
  12483. $receiptL ['差旅相关费用'] = $psum . $html;
  12484. /* ------------------------------------- */
  12485. $html = "";
  12486. $psum = 0;
  12487. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12488. $falg = true;
  12489. foreach ( $receiptCollectList as $v ) {
  12490. if ($v ['itemCategory'] == '内部培训费用') {
  12491. if ($v ['item'] == $va['name']) {
  12492. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12493. $psum += $v ['price'];
  12494. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12495. $falg = false;
  12496. break;
  12497. }
  12498. }
  12499. }
  12500. if ($falg)
  12501. $html .= '<td class="taR">-</td>';
  12502. }
  12503. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12504. if (! empty ( $psum ))
  12505. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12506. else
  12507. $psum = '<td class="colGreen taR">-</td>';
  12508. $receiptL ['内部培训费用'] = $psum . $html;
  12509. /* ----------------------------------- */
  12510. $html = "";
  12511. $psum = 0;
  12512. foreach ( $aiList[$this->TRAIN] as $va ) {
  12513. $falg = true;
  12514. foreach ( $receiptCollectList as $v ) {
  12515. if ($v ['itemCategory'] == '培训班费用') {
  12516. if ($v ['item'] == $va['name']) {
  12517. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12518. $psum += $v ['price'];
  12519. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12520. $falg = false;
  12521. break;
  12522. }
  12523. }
  12524. }
  12525. if ($falg)
  12526. $html .= '<td class="taR">-</td>';
  12527. }
  12528. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12529. if (! empty ( $psum ))
  12530. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12531. else
  12532. $psum = '<td class="colGreen taR">-</td>';
  12533. $receiptL ['培训班费用'] = $psum . $html;
  12534. /* ------------------------------------- */
  12535. $html = "";
  12536. $psum = 0;
  12537. foreach ( $aiList[$this->OTHER] as $va ) {
  12538. $falg = true;
  12539. foreach ( $receiptCollectList as $v ) {
  12540. if ($v ['itemCategory'] == '其他') {
  12541. if (trim ( $v ['item'] ) == $va['name']) {
  12542. $subtotal[$this->OTHER][$va['name']]+=$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. $subtotal[$this->OTHER]['OTHER'] += $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. foreach ( $receiptCollectList as $v ) {
  12563. if ($v ['itemCategory'] == '报销金额调整') {
  12564. if (! empty ( $v ['price'] )) {
  12565. $psum += $v ['price'];
  12566. }
  12567. }
  12568. }
  12569. $s1 += $psum;
  12570. if (! empty ( $psum ))
  12571. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12572. else
  12573. $psum = '<td class="taR colOrange">-</td>';
  12574. $receiptL ['报销金额调整'] = $psum . $html;
  12575. } else {
  12576. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12577. foreach ( $aiList[$this->AGENCY] as $va ) {
  12578. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12579. }
  12580. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12581. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12582. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12583. }
  12584. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12585. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12586. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12587. }
  12588. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12589. foreach ( $aiList[$this->TRAIN] as $va ) {
  12590. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12591. }
  12592. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12593. foreach ( $aiList[$this->OTHER] as $va ) {
  12594. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12595. }
  12596. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12597. }
  12598. $monthStaffPrice = $receiptDetail->find ( array (
  12599. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12600. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12601. 'groupby' => 'Month(pastDate)',
  12602. 'asArray' => true
  12603. ) );
  12604. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12605. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12606. $m1 += $monthStaffPrice [0] ['price'];
  12607. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12608. } else
  12609. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12610. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12611. $list [$value ['username']] = $receiptL;
  12612. }
  12613. }
  12614. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12615. foreach ( $aiList[$this->AGENCY] as $va ) {
  12616. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12617. $subtotal[$this->AGENCY][$va['name']]=0;
  12618. }
  12619. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12620. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12621. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12622. $subtotal[$this->TRAVEL][$va['name']]=0;
  12623. }
  12624. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12625. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12626. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12627. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12628. }
  12629. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12630. foreach ( $aiList[$this->TRAIN] as $va ) {
  12631. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12632. $subtotal[$this->TRAIN][$va['name']]=0;
  12633. }
  12634. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12635. foreach ( $aiList[$this->OTHER] as $va ) {
  12636. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12637. $subtotal[$this->OTHER][$va['name']]=0;
  12638. }
  12639. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12640. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12641. $receiptL ['usernameEn'] =false;
  12642. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12643. }
  12644. $data ['list'] = $list;
  12645. // print_r($list);
  12646. $receiptCollectList = $receiptDetail->find ( array (
  12647. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12648. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12649. 'groupby' => 'item,Month(pastDate),itemCategory',
  12650. 'asArray' => true
  12651. ) );
  12652. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12653. // statistics html
  12654. $stList = $statistics->getOne ( array (
  12655. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12656. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12657. 'groupby' => 'Month(date)',
  12658. 'asArray' => true
  12659. ) );
  12660. if (empty ( $stList ))
  12661. $stList = array (
  12662. 'rePrice' => 0,
  12663. 'agPrice' => 0
  12664. );
  12665. $data ['stList'] = array (
  12666. 'rePrice' => $stList ['rePrice'],
  12667. 'agPrice' => $stList ['agPrice'],
  12668. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12669. );
  12670. $monthHtml = "";
  12671. for($i = 1; $i <= 12; $i ++) {
  12672. if ($i == $month)
  12673. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12674. else
  12675. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12676. }
  12677. $data ['monthHtml'] = $monthHtml;
  12678. $data ['year'] = $year;
  12679. $data ['month'] = $month;
  12680. $data ['nature'] = $nature;
  12681. $data ['aiList'] = $aiList;
  12682. $data ['memu'] = "receipt";
  12683. $data ['staff'] = $this->staff;
  12684. $data ['receiptMemu'] = 'companyCategoryCollect';
  12685. $data ['verifyId'] = $this->verifyId;
  12686. $data ['executeId'] = $this->executeId;
  12687. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12688. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12689. }
  12690. function staffCollectMonthDetail2() {
  12691. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12692. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12693. if (! $year)
  12694. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12695. if (! $month)
  12696. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12697. Doo::loadModel ( 'staff' );
  12698. $staff = new staff ();
  12699. Doo::loadModel ( "receiptDetail" );
  12700. $receiptDetail = new receiptDetail ();
  12701. Doo::loadModel ( 'accountItem' );
  12702. $accountItem = new accountItem ();
  12703. Doo::loadModel ( 'statistics' );
  12704. $statistics = new statistics ();
  12705. Doo::loadModel ( 'L_category' );
  12706. $lCategory = new L_category ();
  12707. $staffList = $staff->find ( array (
  12708. 'where' => 'username!="admin"',
  12709. 'asArray' => true
  12710. ) );
  12711. $categoryList = $staff->find ( array (
  12712. 'select' => 'COUNT(*) as count,cid,category',
  12713. 'where' => 'username !="admin"',
  12714. 'groupby' => 'cid',
  12715. 'asArray' => true
  12716. ) );
  12717. $list = array ();
  12718. foreach ( $categoryList as $vlu ) {
  12719. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12720. $r1 = 0;
  12721. $r2 = 0;
  12722. $r3 = 0;
  12723. $r4 = 0;
  12724. $r5 = 0;
  12725. $r6 = 0;
  12726. $r7 = 0;
  12727. $r8 = 0;
  12728. $r9 = 0;
  12729. $r10 = 0;
  12730. $r11 = 0;
  12731. $r12 = 0;
  12732. $r13 = 0;
  12733. $r14 = 0;
  12734. $r15 = 0;
  12735. $c1 = 0;
  12736. $c2 = 0;
  12737. $c3 = 0;
  12738. $c4 = 0;
  12739. $c5 = 0;
  12740. $c6 = 0;
  12741. $p1 = 0;
  12742. $p2 = 0;
  12743. $p3 = 0;
  12744. $p4 = 0;
  12745. $p5 = 0;
  12746. $p6 = 0;
  12747. $p7 = 0;
  12748. $p8 = 0;
  12749. $p9 = 0;
  12750. $t1 = 0;
  12751. $t2 = 0;
  12752. $t3 = 0;
  12753. $t4 = 0;
  12754. $t5 = 0;
  12755. $s1 = 0;
  12756. $m1 = 0;
  12757. foreach ( $staffList as $value ) {
  12758. if ($vlu ['cid'] == $value ['cid']) {
  12759. $receiptCollectList = $receiptDetail->find ( array (
  12760. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12761. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12762. 'groupby' => 'item,Month(date),itemCategory',
  12763. 'asArray' => true
  12764. ) );
  12765. if (! empty ( $receiptCollectList )) {
  12766. $receiptL = array (
  12767. '日常相关费用' => array (),
  12768. '差旅相关费用' => array (),
  12769. '培训班费用' => array (),
  12770. '其他' => array ()
  12771. );
  12772. $html = "";
  12773. $psum = 0;
  12774. $item = array (
  12775. '市内交通费',
  12776. '市内出租费',
  12777. '办事处房租',
  12778. '电话费',
  12779. '水费',
  12780. '电费',
  12781. '办公费用',
  12782. '邮寄费',
  12783. '其他费用',
  12784. '车辆费用',
  12785. '广告费',
  12786. '团队建设费',
  12787. '物业管理费',
  12788. '宽带费'
  12789. );
  12790. foreach ( $item as $va ) {
  12791. $falg = true;
  12792. foreach ( $receiptCollectList as $v ) {
  12793. if ($v ['itemCategory'] == '日常相关费用') {
  12794. if ($v ['item'] == $va) {
  12795. if ($va == '市内交通费')
  12796. $r1 += $v ['price'];
  12797. if ($va == '市内出租费')
  12798. $r2 += $v ['price'];
  12799. if ($va == '办事处房租')
  12800. $r3 += $v ['price'];
  12801. if ($va == '电话费')
  12802. $r4 += $v ['price'];
  12803. if ($va == '水费')
  12804. $r5 += $v ['price'];
  12805. if ($va == '电费')
  12806. $r6 += $v ['price'];
  12807. if ($va == '办公费用')
  12808. $r7 += $v ['price'];
  12809. if ($va == '邮寄费')
  12810. $r8 += $v ['price'];
  12811. if ($va == '其他费用')
  12812. $r9 += $v ['price'];
  12813. if ($va == '车辆费用')
  12814. $r10 += $v ['price'];
  12815. if ($va == '广告费')
  12816. $r11 += $v ['price'];
  12817. if ($va == '团队建设费')
  12818. $r13 += $v ['price'];
  12819. if ($va == '物业管理费')
  12820. $r14 += $v ['price'];
  12821. if ($va == '宽带费')
  12822. $r15 += $v ['price'];
  12823. $psum += $v ['price'];
  12824. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12825. $falg = false;
  12826. break;
  12827. }
  12828. }
  12829. }
  12830. if ($falg)
  12831. $html .= '<td class="taR">-</td>';
  12832. }
  12833. $r12 += $psum;
  12834. if (! empty ( $psum ))
  12835. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12836. else
  12837. $psum = '<td class="colGreen taR">-</td>';
  12838. $receiptL ['日常相关费用'] = $psum . $html;
  12839. /* ----------------------------------- */
  12840. $html = "";
  12841. $psum = 0;
  12842. $item = array (
  12843. '往来交通费',
  12844. '市内交通费',
  12845. '出差住宿费',
  12846. '出差补助',
  12847. '其他费用'
  12848. );
  12849. foreach ( $item as $va ) {
  12850. $falg = true;
  12851. foreach ( $receiptCollectList as $v ) {
  12852. if ($v ['itemCategory'] == '差旅相关费用') {
  12853. if ($v ['item'] == $va) {
  12854. if ($va == '往来交通费')
  12855. $c1 += $v ['price'];
  12856. if ($va == '市内交通费')
  12857. $c2 += $v ['price'];
  12858. if ($va == '出差住宿费')
  12859. $c3 += $v ['price'];
  12860. if ($va == '出差补助')
  12861. $c4 += $v ['price'];
  12862. if ($va == '其他费用')
  12863. $c5 += $v ['price'];
  12864. $psum += $v ['price'];
  12865. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12866. $falg = false;
  12867. break;
  12868. }
  12869. }
  12870. }
  12871. if ($falg)
  12872. $html .= '<td class="taR">-</td>';
  12873. }
  12874. $c6 += $psum;
  12875. if (! empty ( $psum ))
  12876. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12877. else
  12878. $psum = '<td class="colGreen taR">-</td>';
  12879. $receiptL ['差旅相关费用'] = $psum . $html;
  12880. /* ------------------------------------- */
  12881. $html = "";
  12882. $psum = 0;
  12883. $item = array (
  12884. '场租费',
  12885. '薪酬',
  12886. '住宿费',
  12887. '交通费',
  12888. '餐饮费',
  12889. '办公费',
  12890. '公关费',
  12891. '其他'
  12892. );
  12893. foreach ( $item as $va ) {
  12894. $falg = true;
  12895. foreach ( $receiptCollectList as $v ) {
  12896. if ($v ['itemCategory'] == '培训班费用') {
  12897. if ($v ['item'] == $va) {
  12898. if ($va == '场租费')
  12899. $p1 += $v ['price'];
  12900. if ($va == '薪酬')
  12901. $p2 += $v ['price'];
  12902. if ($va == '住宿费')
  12903. $p3 += $v ['price'];
  12904. if ($va == '交通费')
  12905. $p4 += $v ['price'];
  12906. if ($va == '餐饮费')
  12907. $p5 += $v ['price'];
  12908. if ($va == '办公费')
  12909. $p6 += $v ['price'];
  12910. if ($va == '公关费')
  12911. $p7 += $v ['price'];
  12912. if ($va == '其他')
  12913. $p8 += $v ['price'];
  12914. $psum += $v ['price'];
  12915. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12916. $falg = false;
  12917. break;
  12918. }
  12919. }
  12920. }
  12921. if ($falg)
  12922. $html .= '<td class="taR">-</td>';
  12923. }
  12924. $p9 += $psum;
  12925. if (! empty ( $psum ))
  12926. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12927. else
  12928. $psum = '<td class="colGreen taR">-</td>';
  12929. $receiptL ['培训班费用'] = $psum . $html;
  12930. /* ------------------------------------- */
  12931. $html = "";
  12932. $psum = 0;
  12933. $item = array (
  12934. '公关费',
  12935. '广告费',
  12936. '借款',
  12937. '可自加费用'
  12938. );
  12939. foreach ( $item as $va ) {
  12940. $falg = true;
  12941. foreach ( $receiptCollectList as $v ) {
  12942. if ($v ['itemCategory'] == '其他') {
  12943. if ($v ['item'] == $va) {
  12944. if ($va == '公关费')
  12945. $t1 += $v ['price'];
  12946. if ($va == '广告费')
  12947. $t2 += $v ['price'];
  12948. if ($va == '借款')
  12949. $t3 += $v ['price'];
  12950. if ($va == '可自加费用')
  12951. $t4 += $v ['price'];
  12952. $psum += $v ['price'];
  12953. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12954. $falg = false;
  12955. break;
  12956. }
  12957. }
  12958. }
  12959. if ($falg)
  12960. $html .= '<td class="taR">-</td>';
  12961. }
  12962. $t5 += $psum;
  12963. if (! empty ( $psum ))
  12964. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12965. else
  12966. $psum = '<td class="colGreen taR">-</td>';
  12967. $receiptL ['其他'] = $psum . $html;
  12968. /* ------------------------------------- */
  12969. $html = "";
  12970. $psum = 0;
  12971. foreach ( $receiptCollectList as $v ) {
  12972. if ($v ['itemCategory'] == '报销金额调整') {
  12973. if (! empty ( $v ['price'] )) {
  12974. $psum += $v ['price'];
  12975. }
  12976. }
  12977. }
  12978. $s1 += $psum;
  12979. if (! empty ( $psum ))
  12980. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12981. else
  12982. $psum = '<td class="taR colOrange">-</td>';
  12983. $receiptL ['报销金额调整'] = $psum . $html;
  12984. } else {
  12985. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12986. <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>';
  12987. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12988. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12989. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12990. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12991. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12992. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12993. }
  12994. $monthStaffPrice = $receiptDetail->find ( array (
  12995. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12996. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12997. 'asArray' => true
  12998. ) );
  12999. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13000. $m1 += $monthStaffPrice [0] ['price'];
  13001. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13002. } else
  13003. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13004. $list [$value ['username']] = $receiptL;
  13005. }
  13006. }
  13007. $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>
  13008. <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>
  13009. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13010. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13011. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13012. $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>
  13013. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13014. $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>';
  13015. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13016. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13017. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13018. }
  13019. $data ['list'] = $list;
  13020. $receiptCollectList = $receiptDetail->find ( array (
  13021. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13022. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13023. 'groupby' => 'item,Month(date),itemCategory',
  13024. 'asArray' => true
  13025. ) );
  13026. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13027. // statistics html
  13028. $stList = $statistics->getOne ( array (
  13029. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13030. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13031. 'groupby' => 'Month(date)',
  13032. 'asArray' => true
  13033. ) );
  13034. if (empty ( $stList ))
  13035. $stList = array (
  13036. 'rePrice' => 0,
  13037. 'agPrice' => 0
  13038. );
  13039. $data ['stList'] = array (
  13040. 'rePrice' => $stList ['rePrice'],
  13041. 'agPrice' => $stList ['agPrice'],
  13042. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13043. );
  13044. $monthHtml = "";
  13045. for($i = 1; $i <= 12; $i ++) {
  13046. if ($i == $month)
  13047. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13048. else
  13049. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13050. }
  13051. $data ['monthHtml'] = $monthHtml;
  13052. $data ['year'] = $year;
  13053. $data ['month'] = $month;
  13054. $data ['memu'] = "receipt";
  13055. $data ['staff'] = $this->staff;
  13056. $data ['receiptMemu'] = 'companyCategoryCollect';
  13057. $data ['verifyId'] = $this->verifyId;
  13058. $data ['executeId'] = $this->executeId;
  13059. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13060. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13061. }
  13062. /**
  13063. * 用户报销单列表
  13064. */
  13065. function receiptStatisticsStaffDetail() {
  13066. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13067. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13068. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13069. Doo::loadModel ( "receipt" );
  13070. $receipt = new receipt ();
  13071. Doo::loadModel ( "receiptDetail" );
  13072. $receiptDetail = new receiptDetail ();
  13073. Doo::loadModel ( 'staff' );
  13074. $staff = new staff ();
  13075. Doo::loadModel ( 'accountItem' );
  13076. $accountItem = new accountItem ();
  13077. Doo::loadModel ( 'statistics' );
  13078. $statistics = new statistics ();
  13079. if (! empty ( $username )) {
  13080. $username = addslashes ( urldecode ( $username ) );
  13081. $staffDetail = $staff->getStaffByName ( $username );
  13082. if (empty ( $staffDetail ))
  13083. die ( 'illegal request' );
  13084. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13085. $itemList = $accountItem->getAccountItem ();
  13086. $itemHtml = '';
  13087. $categoryHtml = '';
  13088. $itemKeyList = array_keys ( $itemList );
  13089. $revisePrice = 0;
  13090. // 报销单内容详情
  13091. foreach ( $list as $key => $value ) {
  13092. $accountItemList = json_decode ( $value ['accountItem'], true );
  13093. $list [$key] ['accountItemList'] = $accountItemList;
  13094. $receiptItemHtml = '';
  13095. foreach ( $itemKeyList as $v ) {
  13096. if ($v == '日常相关费用')
  13097. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13098. elseif ($v == '差旅相关费用')
  13099. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13100. elseif ($v == '培训班费用')
  13101. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13102. elseif ($v == '内部培训费用'){
  13103. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13104. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13105. }else{
  13106. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13107. }
  13108. }elseif ($v == '其他')
  13109. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13110. foreach ( $itemList [$v] as $ke => $va ) {
  13111. $falg = true;
  13112. if (! empty ( $accountItemList [$v] )) {
  13113. foreach ( $accountItemList [$v] as $ve ) {
  13114. if ($va ['name'] == $ve ['name']) {
  13115. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13116. $falg = false;
  13117. break;
  13118. }
  13119. }
  13120. }
  13121. if ($falg)
  13122. $receiptItemHtml .= '<td class="taR"></td>';
  13123. }
  13124. }
  13125. // 金额调整和费用查看
  13126. $revisePrice += $value ['revisePrice'];
  13127. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13128. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13129. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13130. }
  13131. // 报销单合计
  13132. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13133. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13134. $receiptTotalHtml = '';
  13135. // 报销单项目抬头
  13136. foreach ( $itemKeyList as $value ) {
  13137. $count = count ( $itemList [$value] ) + 1;
  13138. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13139. $categoryHtml .= '<th class="taC">合计</th>';
  13140. $sumfalg=true;
  13141. foreach ( $rtl as $rtlValue ) {
  13142. if ($rtlValue ['itemCategory'] == $value) {
  13143. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13144. $sumfalg=false;
  13145. break;
  13146. }
  13147. }
  13148. if ($sumfalg)
  13149. $receiptTotalHtml .= '<th></th>';
  13150. foreach ( $itemList [$value] as $k => $v ) {
  13151. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13152. // 合计
  13153. $falg = true;
  13154. foreach ( $receiptTotalList as $ve ) {
  13155. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13156. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13157. $falg = false;
  13158. break;
  13159. }
  13160. }
  13161. if ($falg)
  13162. $receiptTotalHtml .= '<th></th>';
  13163. }
  13164. }
  13165. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13166. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13167. if (empty ( $stList ))
  13168. $stList = array (
  13169. 'rePrice' => 0,
  13170. 'agPrice' => 0
  13171. );
  13172. $data ['stList'] = array (
  13173. 'rePrice' => $stList ['rePrice'],
  13174. 'agPrice' => $stList ['agPrice'],
  13175. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13176. );
  13177. $monthHtml = "";
  13178. for($i = 1; $i <= 12; $i ++) {
  13179. if ($i == $month)
  13180. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13181. else
  13182. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13183. }
  13184. $data ['username'] = urlencode ( $username );
  13185. $data ['usernameEN'] = $username;
  13186. $data ['monthHtml'] = $monthHtml;
  13187. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13188. $data ['list'] = $list;
  13189. $data ['categoryHtml'] = $categoryHtml;
  13190. $data ['itemHtml'] = $itemHtml;
  13191. $data ['itemList'] = $itemList;
  13192. $data ['year'] = $year;
  13193. $data ['month'] = $month;
  13194. $data ['memu'] = "receipt";
  13195. $data ['staff'] = $this->staff;
  13196. $data ['receiptMemu'] = 'companyCategoryCollect';
  13197. $data ['verifyId'] = $this->verifyId;
  13198. $data ['executeId'] = $this->executeId;
  13199. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13200. }
  13201. die ( 'illegal request' );
  13202. }
  13203. function companyMonthCollectDetail() {
  13204. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13205. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13206. if (! $year)
  13207. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13208. if (! $month)
  13209. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13210. Doo::loadModel ( 'staff' );
  13211. $staff = new staff ();
  13212. Doo::loadModel ( "receiptDetail" );
  13213. $receiptDetail = new receiptDetail ();
  13214. Doo::loadModel ( 'accountItem' );
  13215. $accountItem = new accountItem ();
  13216. Doo::loadModel ( 'statistics' );
  13217. $statistics = new statistics ();
  13218. Doo::loadModel ( 'L_category' );
  13219. $lCategory = new L_category ();
  13220. $staffList = $staff->find ( array (
  13221. 'where' => 'username!="admin"',
  13222. 'asArray' => true
  13223. ) );
  13224. $categoryList = $lCategory->find ( array (
  13225. 'asArray' => true
  13226. ) );
  13227. $aiList=$accountItem->getAccountItem();
  13228. $list = array ();
  13229. foreach ( $categoryList as $value ) {
  13230. $receiptCollectList = $receiptDetail->find ( array (
  13231. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13232. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13233. 'groupby' => 'item,Month(pastDate),itemCategory',
  13234. 'asArray' => true
  13235. ) );
  13236. if (! empty ( $receiptCollectList )) {
  13237. $receiptL = array (
  13238. '日常相关费用' => array (),
  13239. '差旅相关费用' => array (),
  13240. '内部培训费用' => array (),
  13241. '培训班费用' => array (),
  13242. '其他' => array ()
  13243. );
  13244. $html = "";
  13245. $psum = 0;
  13246. foreach ( $aiList[$this->AGENCY] as $va ) {
  13247. $falg = true;
  13248. foreach ( $receiptCollectList as $v ) {
  13249. if ($v ['itemCategory'] == $this->AGENCY) {
  13250. if ($v ['item'] == $va['name']) {
  13251. $psum += $v ['price'];
  13252. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13253. $falg = false;
  13254. break;
  13255. }
  13256. }
  13257. }
  13258. if ($falg)
  13259. $html .= '<td class="taR">-</td>';
  13260. }
  13261. if (! empty ( $psum ))
  13262. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13263. else
  13264. $psum = '<td class="colGreen taR">-</td>';
  13265. $receiptL [$this->AGENCY] = $psum . $html;
  13266. /* ----------------------------------- */
  13267. $html = "";
  13268. $psum = 0;
  13269. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13270. $falg = true;
  13271. foreach ( $receiptCollectList as $v ) {
  13272. if ($v ['itemCategory'] == $this->TRAVEL) {
  13273. if ($v ['item'] == $va['name']) {
  13274. $psum += $v ['price'];
  13275. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13276. $falg = false;
  13277. break;
  13278. }
  13279. }
  13280. }
  13281. if ($falg)
  13282. $html .= '<td class="taR">-</td>';
  13283. }
  13284. if (! empty ( $psum ))
  13285. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13286. else
  13287. $psum = '<td class="colGreen taR">-</td>';
  13288. $receiptL [$this->TRAVEL] = $psum . $html;
  13289. /* ------------------------------------- */
  13290. $html = "";
  13291. $psum = 0;
  13292. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13293. $falg = true;
  13294. foreach ( $receiptCollectList as $v ) {
  13295. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13296. if ($v ['item'] == $va['name']) {
  13297. $psum += $v ['price'];
  13298. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13299. $falg = false;
  13300. break;
  13301. }
  13302. }
  13303. }
  13304. if ($falg)
  13305. $html .= '<td class="taR">-</td>';
  13306. }
  13307. if (! empty ( $psum ))
  13308. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13309. else
  13310. $psum = '<td class="colGreen taR">-</td>';
  13311. $receiptL [$this->INTTRAIN] = $psum . $html;
  13312. /* ------------------------------------- */
  13313. $html = "";
  13314. $psum = 0;
  13315. foreach ( $aiList[$this->TRAIN] as $va ) {
  13316. $falg = true;
  13317. foreach ( $receiptCollectList as $v ) {
  13318. if ($v ['itemCategory'] == $this->TRAIN) {
  13319. if ($v ['item'] == $va['name']) {
  13320. $psum += $v ['price'];
  13321. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13322. $falg = false;
  13323. break;
  13324. }
  13325. }
  13326. }
  13327. if ($falg)
  13328. $html .= '<td class="taR">-</td>';
  13329. }
  13330. if (! empty ( $psum ))
  13331. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13332. else
  13333. $psum = '<td class="colGreen taR">-</td>';
  13334. $receiptL [$this->TRAIN] = $psum . $html;
  13335. /* ------------------------------------- */
  13336. $html = "";
  13337. $psum = 0;
  13338. foreach ( $aiList[$this->OTHER] as $va ) {
  13339. $falg = true;
  13340. foreach ( $receiptCollectList as $v ) {
  13341. if ($v ['itemCategory'] == $this->OTHER) {
  13342. if ($v ['item'] == $va['name']) {
  13343. $psum += $v ['price'];
  13344. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13345. $falg = false;
  13346. break;
  13347. }
  13348. }
  13349. }
  13350. if ($falg)
  13351. $html .= '<td class="taR">-</td>';
  13352. }
  13353. if (! empty ( $psum ))
  13354. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13355. else
  13356. $psum = '<td class="colGreen taR">-</td>';
  13357. $receiptL [$this->OTHER] = $psum . $html;
  13358. /* ------------------------------------- */
  13359. $html = "";
  13360. $psum = 0;
  13361. foreach ( $receiptCollectList as $v ) {
  13362. if ($v ['itemCategory'] == '报销金额调整') {
  13363. if (! empty ( $v ['price'] ))
  13364. $psum += $v ['price'];
  13365. }
  13366. }
  13367. if (! empty ( $psum ))
  13368. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13369. else
  13370. $psum = '<td class="taR colOrange">-</td>';
  13371. $receiptL ['报销金额调整'] = $psum . $html;
  13372. } else {
  13373. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13374. foreach ( $aiList[$this->AGENCY] as $va ) {
  13375. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13376. }
  13377. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13378. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13379. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13380. }
  13381. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13382. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13383. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13384. }
  13385. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13386. foreach ( $aiList[$this->TRAIN] as $va ) {
  13387. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13388. }
  13389. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13390. foreach ( $aiList[$this->OTHER] as $va ) {
  13391. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13392. }
  13393. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13394. }
  13395. $monthStaffPrice = $receiptDetail->find ( array (
  13396. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13397. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13398. 'asArray' => true
  13399. ) );
  13400. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13401. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13402. else
  13403. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13404. $list [$value ['title']] = $receiptL;
  13405. }
  13406. $data ['list'] = $list;
  13407. $receiptCollectList = $receiptDetail->find ( array (
  13408. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13409. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13410. 'groupby' => 'item,Month(pastDate),itemCategory',
  13411. 'asArray' => true
  13412. ) );
  13413. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13414. //print_r($data['monthPriceHtml']);
  13415. // foreach ($data['monthPriceHtml'] as $value){
  13416. // echo $value;
  13417. // }
  13418. // die;
  13419. // statistics html
  13420. $stList = $statistics->getOne ( array (
  13421. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13422. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13423. 'groupby' => 'Month(date)',
  13424. 'asArray' => true
  13425. ) );
  13426. if (empty ( $stList ))
  13427. $stList = array (
  13428. 'rePrice' => 0,
  13429. 'agPrice' => 0
  13430. );
  13431. $data ['stList'] = array (
  13432. 'rePrice' => $stList ['rePrice'],
  13433. 'agPrice' => $stList ['agPrice'],
  13434. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13435. );
  13436. $monthHtml = "";
  13437. for($i = 1; $i <= 12; $i ++) {
  13438. if ($i == $month)
  13439. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13440. else
  13441. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13442. }
  13443. $data ['aiList'] = $aiList;
  13444. $dateHtml = "";
  13445. $now = date ( "Y" );
  13446. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13447. if ($YEARD <= $now) {
  13448. $dateHtml .= '<option ';
  13449. if ($year == $YEARD) {
  13450. $dateHtml .= 'selected ';
  13451. }
  13452. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13453. }
  13454. }
  13455. $data ['dateHtml'] = $dateHtml;
  13456. $data ['monthHtml'] = $monthHtml;
  13457. $data ['year'] = $year;
  13458. $data ['month'] = $month;
  13459. $data ['memu'] = "receipt";
  13460. $data ['staff'] = $this->staff;
  13461. $data ['receiptMemu'] = 'companyCategoryCollect';
  13462. $data ['verifyId'] = $this->verifyId;
  13463. $data ['executeId'] = $this->executeId;
  13464. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13465. }
  13466. function staffCollectDetail() {
  13467. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13468. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13469. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13470. if (! $staffname) {
  13471. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13472. $staffname = urldecode ( $staffname );
  13473. }
  13474. Doo::loadModel ( 'staff' );
  13475. $staff = new staff ();
  13476. Doo::loadModel ( "receiptDetail" );
  13477. $receiptDetail = new receiptDetail ();
  13478. Doo::loadModel ( 'accountItem' );
  13479. $accountItem = new accountItem ();
  13480. Doo::loadModel ( 'statistics' );
  13481. $statistics = new statistics ();
  13482. Doo::loadModel ( 'L_category' );
  13483. $lCategory = new L_category ();
  13484. Doo::loadModel ( "receiptAuthorityManage" );
  13485. $receiptAuthorityManage = new receiptAuthorityManage ();
  13486. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13487. $cidList = array ();
  13488. foreach ( $imcStaff as $key => $value ) {
  13489. array_push ( $cidList, $value ['cid'] );
  13490. }
  13491. $cidString = implode ( ',', $cidList );
  13492. $staffList = $staff->find ( array (
  13493. 'where' => ' cid in (' . $cidString . ')',
  13494. 'asArray' => true
  13495. ) );
  13496. $stHtml = '';
  13497. $stTitle = "";
  13498. $staffId = 0;
  13499. $cid = 0;
  13500. $ocid = 0;
  13501. foreach ( $staffList as $value ) {
  13502. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13503. $stTitle = $value ['category'] . '-' . $value ['username'];
  13504. $staffId = $value ['sid'];
  13505. $cid = $value ['cid'];
  13506. $ocid = $value ['cid'];
  13507. if (! empty ( $value ['othercid'] ))
  13508. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13509. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13510. } elseif ($value ['username'] != 'admin')
  13511. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13512. }
  13513. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13514. 'where' => 'cid in(' . $cid . ')',
  13515. 'asArray' => true
  13516. ) );
  13517. if (empty ( $pcid ))
  13518. $pcid = $ocid;
  13519. $data ['ocid'] = $pcid;
  13520. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13521. $this->showCache ( $path );
  13522. //
  13523. $receiptCollectList = $receiptDetail->find ( array (
  13524. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13525. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13526. 'groupby' => 'item,Month(pastDate),itemCategory',
  13527. 'asArray' => true
  13528. ) );
  13529. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13530. // print_r($receiptCollectList);
  13531. $accountList = $accountItem->find ( array (
  13532. 'asArray' => true
  13533. ) );
  13534. // create CollectDetail HTML
  13535. $collectHtml = array ();
  13536. foreach ( $accountList as $key => $value ) {
  13537. $html = "";
  13538. $asum = 0;
  13539. for($i = 1; $i <= 12; $i ++) {
  13540. $falg = true;
  13541. foreach ( $receiptCollectList as $v ) {
  13542. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13543. if ($v ['item'] == '可自加费用') {
  13544. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13545. }
  13546. $asum += $v ['price'];
  13547. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13548. $falg = false;
  13549. break;
  13550. }
  13551. }
  13552. if ($falg)
  13553. $html .= '<td class="taR">-</td>';
  13554. }
  13555. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13556. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13557. }
  13558. $data ['collectHtml'] = $collectHtml;
  13559. // print_r($collectHtml);
  13560. // create Adjustment price html
  13561. $receiptCollectList = $receiptDetail->find ( array (
  13562. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13563. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13564. 'groupby' => 'itemCategory,Month(pastDate)',
  13565. 'asArray' => true
  13566. ) );
  13567. $adjustment = array ();
  13568. $collectArray = array (
  13569. '日常相关费用' => array (),
  13570. '差旅相关费用' => array (),
  13571. '培训班费用' => array (),
  13572. '内部培训费用'=>array(),
  13573. '其他' => array ()
  13574. );
  13575. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13576. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13577. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13578. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13579. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13580. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13581. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13582. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13583. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13584. array_push ( $collectArray ['其他'], $collectHtml );
  13585. $data ['collectArray'] = $collectArray;
  13586. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13587. array_push ( $adjustment, $collectHtml );
  13588. $data ['adjustment'] = $adjustment;
  13589. // total price html
  13590. $collectHtml = "";
  13591. $total = 0;
  13592. for($i = 1; $i <= 12; $i ++) {
  13593. $sumPrice = 0;
  13594. foreach ( $receiptCollectList as $key => $value ) {
  13595. if ($value ['month'] == $i) {
  13596. $sumPrice += $value ['price'];
  13597. }
  13598. }
  13599. if ($sumPrice == 0)
  13600. $collectHtml .= '<td class="taR">-</td>';
  13601. else
  13602. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13603. $total += $sumPrice;
  13604. }
  13605. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13606. // statistics html
  13607. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13608. if (empty ( $stList ))
  13609. $stList = array (
  13610. 'rePrice' => 0,
  13611. 'agPrice' => 0
  13612. );
  13613. $data ['stList'] = array (
  13614. 'rePrice' => $stList ['rePrice'],
  13615. 'agPrice' => $stList ['agPrice'],
  13616. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13617. );
  13618. $data ['totalPrice'] = $collectHtml;
  13619. $data ['totalYear'] = $total;
  13620. $data ['stHtml'] = $stHtml;
  13621. $data ['year'] = $year;
  13622. $data ['stTitle'] = $stTitle;
  13623. $data ['staffname'] = urlencode ( $staffname );
  13624. $data ['memu'] = "receipt";
  13625. $data ['staff'] = $this->staff;
  13626. $data ['receiptMemu'] = 'companyCategoryCollect';
  13627. $data ['verifyId'] = $this->verifyId;
  13628. $data ['executeId'] = $this->executeId;
  13629. if ($year < date ( "Y" )) {
  13630. Doo::loadModel ( 'receipt' );
  13631. $receipt = new receipt ();
  13632. $receiptList = $receipt->find ( array (
  13633. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13634. 'asArray' => true
  13635. ) );
  13636. if (empty ( $receiptList )) { // generated files
  13637. ob_start ();
  13638. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13639. $this->cacheFile ( $path );
  13640. die ();
  13641. }
  13642. }
  13643. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13644. }
  13645. function BUGFLAG() {
  13646. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13647. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13648. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13649. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13650. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13651. if (empty ( $status ))
  13652. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13653. $page_size = 12;
  13654. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13655. $vidList = array ();
  13656. $button = 0;
  13657. Doo::loadModel ( 'verify' );
  13658. $verify = new verify ();
  13659. Doo::loadModel ( 'receipt' );
  13660. $receipt = new receipt ();
  13661. Doo::loadModel ( 'staff' );
  13662. $staff = new staff ();
  13663. Doo::loadModel ( 'L_category' );
  13664. $Lcategory = new L_category ();
  13665. $dateCondition = " and Year(date) =" . $year;
  13666. if (! empty ( $month ))
  13667. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13668. $categoryList = $Lcategory->find ( array (
  13669. 'asArray' => true
  13670. ) );
  13671. $staffList = $staff->find ( array (
  13672. 'where' => 'cid=' . $cid,
  13673. 'asArray' => true
  13674. ) );
  13675. $cateCondition = "";
  13676. $staffCondition = "";
  13677. $approvalCondition = "";
  13678. if (! empty ( $cid ))
  13679. $cateCondition = ' and cid=' . $cid;
  13680. if (! empty ( $sid )) {
  13681. $staffCondition = ' and staff=' . $sid;
  13682. $cateCondition = "";
  13683. }
  13684. $approvalCondition = " and status=" . $status;
  13685. if ($status == 2) {
  13686. // 查找角色审批人
  13687. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13688. }
  13689. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13690. $approvalCondition = ' and status=2 ';
  13691. }
  13692. if ($status == 1) {
  13693. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13694. }
  13695. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13696. $pageinfo ['page'] = array (
  13697. 'previous' => ''
  13698. );
  13699. if ($status == 0) {
  13700. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13701. $receiptList = $receipt->find ( array (
  13702. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13703. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13704. 'desc' => 'rid',
  13705. 'asArray' => true
  13706. ) );
  13707. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13708. } else
  13709. $receiptList = $receipt->find ( array (
  13710. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13711. 'desc' => 'rid',
  13712. 'asArray' => true
  13713. ) );
  13714. $rLRes = $receipt->find ( array (
  13715. '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,
  13716. 'desc' => 'rid',
  13717. 'asArray' => true
  13718. ) );
  13719. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13720. // print_r($pageinfo);
  13721. $Locate = 0;
  13722. foreach ( $receiptList as $key => $value ) {
  13723. $receiptList [$key] ['Locate'] = $Locate;
  13724. $Locate ++;
  13725. $receiptList [$key] ['reviseDetail'] = array ();
  13726. if (! empty ( $value ['reviseDetail'] ))
  13727. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13728. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13729. $categoryDetil = $Lcategory->getOne ( array (
  13730. 'where' => 'cid=' . $value ['cid'],
  13731. 'asArray' => true
  13732. ) );
  13733. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13734. $verifyList = $verify->getOne ( array (
  13735. 'where' => 'vid=' . $value ['verify'],
  13736. 'asArray' => true
  13737. ) );
  13738. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13739. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13740. foreach ( $verifyList as $k => $v ) {
  13741. // init verifyStaff
  13742. $verifyList [$k] ['date'] = "";
  13743. $verifyList [$k] ['opinion'] = "";
  13744. $verifyList [$k] ['status'] = "";
  13745. if (empty ( $verifyStaff )) {
  13746. $verifyList [$k] ['date'] = "";
  13747. $verifyList [$k] ['opinion'] = "";
  13748. if ($v [0] == $this->staff [0] ['sid']) {
  13749. $verifyList [$k] ['status'] = 4;
  13750. $button = 4;
  13751. }
  13752. } else {
  13753. $flag = true;
  13754. foreach ( $verifyStaff as $m => $u ) {
  13755. if ($v [0] == $m) {
  13756. $verifyList [$k] ['date'] = $u ['date'];
  13757. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13758. $verifyList [$k] ['status'] = $u ['status'];
  13759. $flag = false;
  13760. break;
  13761. }
  13762. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13763. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13764. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13765. }
  13766. if ($flag) { // 检测可编辑
  13767. if ($v [0] == $this->staff [0] ['sid']) {
  13768. $verifyList [$k] ['status'] = 4;
  13769. $button = 4;
  13770. }
  13771. }
  13772. }
  13773. }
  13774. $receiptList [$key] ['verifyList'] = $verifyList;
  13775. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13776. 'where' => 'sid=' . $value ['staff'],
  13777. 'asArray' => true
  13778. ) );
  13779. $receiptList [$key] ['button'] = $button;
  13780. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13781. }
  13782. // print_r($receiptList);die;
  13783. // $data['verifyDetail']=$verifyDetail;
  13784. $mothHtml = "";
  13785. for($i = 1; $i <= 12; $i ++) {
  13786. if ($month == $i)
  13787. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13788. else
  13789. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13790. }
  13791. $data ['mothHtml'] = $mothHtml;
  13792. $data ['page'] = $pageinfo;
  13793. $data ['receiptList'] = $receiptList;
  13794. $data ['receiptApprovalCount'] = count ( $rLRes );
  13795. $data ['status'] = $status;
  13796. $data ['year'] = $year;
  13797. $data ['categoryList'] = $categoryList;
  13798. $data ['staffList'] = $staffList;
  13799. $data ['cid'] = $cid;
  13800. $data ['sid'] = $sid;
  13801. // print_r($receiptList);
  13802. $data ['memu'] = "receipt";
  13803. $data ['staff'] = $this->staff;
  13804. $data ['receiptMemu'] = 'approvalExpenses';
  13805. $data ['verifyId'] = $this->verifyId;
  13806. $data ['executeId'] = $this->executeId;
  13807. $this->render ( "/admin/FALG", $data );
  13808. }
  13809. function ajaxGetReceiptOrder() {
  13810. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13811. if (! empty ( $receiptOrder )) {
  13812. Doo::loadModel ( 'receipt' );
  13813. $receipt = new receipt ();
  13814. Doo::loadModel ( 'staff' );
  13815. $staff = new staff ();
  13816. $receiptInfo = $receipt->getOne ( array (
  13817. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13818. 'asArray' => true
  13819. ) );
  13820. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13821. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13822. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13823. </tbody></table><table class="table table table-bordered"><tbody>';
  13824. foreach ( $verifyStaff as $key => $value ) {
  13825. $staffInfo = $staff->getOne ( array (
  13826. 'select' => 'username',
  13827. 'where' => ' sid="' . $key . '"',
  13828. 'asArray' => true
  13829. ) );
  13830. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13831. }
  13832. $html .= '</tbody></table></div></div>';
  13833. echo json_encode ( array (
  13834. 'status' => 1,
  13835. 'receiptHtml' => $html
  13836. ) );
  13837. die ();
  13838. }
  13839. echo json_encode ( array (
  13840. 'status' => 2,
  13841. 'receiptHtml' => ''
  13842. ) );
  13843. die ();
  13844. }
  13845. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13846. if (! empty ( $receiptCollectList )) {
  13847. $receiptL = array (
  13848. '日常相关费用' => array (),
  13849. '差旅相关费用' => array (),
  13850. '内部培训费用'=>array(),
  13851. '培训班费用' => array (),
  13852. '其他' => array ()
  13853. );
  13854. $html = "";
  13855. $psum = 0;
  13856. foreach ( $aiList[$this->AGENCY] as $value ) {
  13857. $falg = true;
  13858. foreach ( $receiptCollectList as $v ) {
  13859. if ($v ['itemCategory'] == '日常相关费用') {
  13860. if ($v ['item'] == $value['name']) {
  13861. $psum += $v ['price'];
  13862. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13863. $falg = false;
  13864. break;
  13865. }
  13866. }
  13867. }
  13868. if ($falg)
  13869. $html .= '<td class="taR">-</td>';
  13870. }
  13871. if (! empty ( $psum ))
  13872. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13873. else
  13874. $psum = '<td class="colGreen taR">-</td>';
  13875. $receiptL ['日常相关费用'] = $psum . $html;
  13876. /* ----------------------------------- */
  13877. $html = "";
  13878. $psum = 0;
  13879. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13880. $falg = true;
  13881. foreach ( $receiptCollectList as $v ) {
  13882. if ($v ['itemCategory'] == '差旅相关费用') {
  13883. if ($v ['item'] == $value['name']) {
  13884. $psum += $v ['price'];
  13885. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13886. $falg = false;
  13887. break;
  13888. }
  13889. }
  13890. }
  13891. if ($falg)
  13892. $html .= '<td class="taR">-</td>';
  13893. }
  13894. if (! empty ( $psum ))
  13895. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13896. else
  13897. $psum = '<td class="colGreen taR">-</td>';
  13898. $receiptL ['差旅相关费用'] = $psum . $html;
  13899. /* ----------------------------------- */
  13900. $html = "";
  13901. $psum = 0;
  13902. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13903. $falg = true;
  13904. foreach ( $receiptCollectList as $v ) {
  13905. if ($v ['itemCategory'] == '内部培训费用') {
  13906. if ($v ['item'] == $value['name']) {
  13907. $psum += $v ['price'];
  13908. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13909. $falg = false;
  13910. break;
  13911. }
  13912. }
  13913. }
  13914. if ($falg)
  13915. $html .= '<td class="taR">-</td>';
  13916. }
  13917. if (! empty ( $psum ))
  13918. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13919. else
  13920. $psum = '<td class="colGreen taR">-</td>';
  13921. $receiptL ['内部培训费用'] = $psum . $html;
  13922. /* ------------------------------------- */
  13923. $html = "";
  13924. $psum = 0;
  13925. foreach ( $aiList[$this->TRAIN] as $value ) {
  13926. $falg = true;
  13927. foreach ( $receiptCollectList as $v ) {
  13928. if ($v ['itemCategory'] == '培训班费用') {
  13929. if ($v ['item'] == $value['name']) {
  13930. $psum += $v ['price'];
  13931. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13932. $falg = false;
  13933. break;
  13934. }
  13935. }
  13936. }
  13937. if ($falg)
  13938. $html .= '<td class="taR">-</td>';
  13939. }
  13940. if (! empty ( $psum ))
  13941. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13942. else
  13943. $psum = '<td class="colGreen taR">-</td>';
  13944. $receiptL ['培训班费用'] = $psum . $html;
  13945. /* ------------------------------------- */
  13946. $html = "";
  13947. $psum = 0;
  13948. foreach ( $aiList[$this->OTHER] as $value ) {
  13949. $falg = true;
  13950. foreach ( $receiptCollectList as $v ) {
  13951. if ($v ['itemCategory'] == '其他') {
  13952. if ($v ['item'] == $value['name']) {
  13953. $psum += $v ['price'];
  13954. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13955. $falg = false;
  13956. break;
  13957. }
  13958. }
  13959. }
  13960. if ($falg)
  13961. $html .= '<td class="taR">-</td>';
  13962. }
  13963. if (! empty ( $psum ))
  13964. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13965. else
  13966. $psum = '<td class="colGreen taR">-</td>';
  13967. $receiptL ['其他'] = $psum . $html;
  13968. /* ------------------------------------- */
  13969. $html = "";
  13970. $psum = 0;
  13971. foreach ( $receiptCollectList as $v ) {
  13972. if ($v ['itemCategory'] == '报销金额调整') {
  13973. if (! empty ( $v ['price'] ))
  13974. $psum += $v ['price'];
  13975. }
  13976. }
  13977. if (! empty ( $psum ))
  13978. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13979. else
  13980. $psum = '<td class="taR colOrange">-</td>';
  13981. $receiptL ['报销金额调整'] = $psum . $html;
  13982. } else {
  13983. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13984. foreach ( $aiList[$this->AGENCY] as $va ) {
  13985. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13986. }
  13987. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13988. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13989. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13990. }
  13991. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13992. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13993. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13994. }
  13995. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13996. foreach ( $aiList[$this->TRAIN] as $va ) {
  13997. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13998. }
  13999. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14000. foreach ( $aiList[$this->OTHER] as $va ) {
  14001. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14002. }
  14003. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14004. }
  14005. return $receiptL;
  14006. }
  14007. function eMail() {
  14008. Doo::loadModel ( 'staff' );
  14009. $staff = new staff ();
  14010. Doo::loadModel ( 'receipt' );
  14011. $receipt = new receipt ();
  14012. Doo::loadModel ( 'L_category' );
  14013. $Lcategory = new L_category ();
  14014. Doo::loadModel ( "verify" );
  14015. $verify = new verify ();
  14016. $staffList = $staff->find ( array (
  14017. 'asArray' => true
  14018. ) );
  14019. foreach ( $staffList as $key => $value ) {
  14020. if ($value ['username'] != 'admin') {
  14021. // 提交人
  14022. $receiptList = $receipt->find ( array (
  14023. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14024. 'asArray' => true
  14025. ) );
  14026. if (! empty ( $receiptList )) {
  14027. $html = '<br><div><style></style>
  14028. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14029. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14030. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14031. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14032. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14033. <tbody><tr>
  14034. <td style="padding: 0 40px;" align="left">
  14035. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14036. </td></tr><tr>
  14037. <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>
  14038. </tr>
  14039. </tbody> </table></td> </tr> <tr><td>
  14040. <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">
  14041. <tbody> <tr><td>
  14042. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14043. 以下报销单完成了审批,等着收款吧:</p>
  14044. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14045. foreach ( $receiptList as $k => $v ) {
  14046. $category = $Lcategory->getOne ( array (
  14047. 'where' => 'cid=' . $v ['cid'],
  14048. 'asArray' => true
  14049. ) );
  14050. $html .= '
  14051. <tr>
  14052. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14053. <td align="left">
  14054. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14055. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14056. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14057. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14058. </tr>';
  14059. }
  14060. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14061. <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>
  14062. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14063. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14064. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14065. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14066. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14067. $receipt = new receipt ();
  14068. $receipt->notice = 1;
  14069. $receipt->update ( array (
  14070. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14071. ) );
  14072. }
  14073. }
  14074. // 审批人
  14075. $verifyList = $verify->find ( array (
  14076. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14077. 'asArray' => true
  14078. ) );
  14079. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14080. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14081. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14082. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14083. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14084. <tbody><tr><td style="padding: 0 40px;" align="left">
  14085. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14086. </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>
  14087. </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">
  14088. <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>
  14089. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14090. foreach ( $verifyList as $k => $v ) {
  14091. $receiptList = $receipt->find ( array (
  14092. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14093. 'asArray' => true
  14094. ) );
  14095. foreach ( $receiptList as $r => $l ) {
  14096. $category = $Lcategory->getOne ( array (
  14097. 'where' => 'cid=' . $l ['cid'],
  14098. 'asArray' => true
  14099. ) );
  14100. $staffDetile = $staff->getOne ( array (
  14101. 'where' => 'sid=' . $l ['staff'],
  14102. 'asArray' => true
  14103. ) );
  14104. $html .= '
  14105. <tr>
  14106. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14107. <td align="left">
  14108. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14109. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14110. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14111. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14112. </tr>';
  14113. }
  14114. }
  14115. $html .= '
  14116. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14117. <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>
  14118. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14119. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14120. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14121. // $receipt=new receipt();
  14122. // $receipt->notice=1;
  14123. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14124. }
  14125. }
  14126. }
  14127. }
  14128. function setWXMsg($rid, $type) {
  14129. Doo::loadModel ( "receipt" );
  14130. $receipt = new receipt ();
  14131. $receiptDetail = $receipt->getOne ( array (
  14132. 'where' => 'rid=' . $rid,
  14133. 'asArray' => true
  14134. ) );
  14135. if (! empty ( $receiptDetail )) {
  14136. Doo::loadModel ( 'staff' );
  14137. $staff = new staff ();
  14138. $staffmsg = $staff->getOne ( array (
  14139. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14140. 'asArray' => TRUE
  14141. ) );
  14142. if (! empty ( $staffmsg ['wxid'] )) {
  14143. require_once (SITE_PATH . '/protected/class/client.php');
  14144. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14145. $user = $staffmsg ['wxid'];
  14146. $receiptName = '';
  14147. $msg = '';
  14148. switch ($receiptDetail ['Rtype']) {
  14149. case 0 :
  14150. $receiptName = '报销';
  14151. break;
  14152. case 1 :
  14153. $receiptName = '借款';
  14154. break;
  14155. case 2 :
  14156. $receiptName = '对公汇款';
  14157. break;
  14158. }
  14159. switch ($type) {
  14160. case 1 :
  14161. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14162. break;
  14163. case 2 :
  14164. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14165. break;
  14166. case 3 :
  14167. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14168. break;
  14169. }
  14170. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14171. }
  14172. }
  14173. }
  14174. // Email发送函数
  14175. function SMail($toemail, $subject, $contents) {
  14176. Doo::loadClass ( 'class.phpmailer' );
  14177. $mail = new PHPMailer ();
  14178. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14179. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14180. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14181. $mail->Password = "cDO1GjtY1seH"; // 密码
  14182. $mail->CharSet = "UTF8";
  14183. $mail->SMTPAuth = true;
  14184. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14185. $mail->Mailer = "smtp";
  14186. $mail->Port = 25;
  14187. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14188. $mail->MsgHTML ( $contents );
  14189. $mail->AddAddress ( $toemail );
  14190. $mail->CharSet = "UTF-8";
  14191. return $mail->Send ();
  14192. }
  14193. function h5Upload() {
  14194. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14195. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14196. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14197. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14198. header ( "HTTP/1.1 500 Internal Server Error" );
  14199. echo "POST exceeded maximum allowed size.";
  14200. exit ( 0 );
  14201. }
  14202. // Settings
  14203. $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)
  14204. $upload_name = "Filedata";
  14205. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14206. $extension_whitelist = array (
  14207. "doc",
  14208. "txt",
  14209. "jpg",
  14210. "gif",
  14211. "png"
  14212. ); // Allowed file extensions
  14213. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14214. // Other variables
  14215. $MAX_FILENAME_LENGTH = 260;
  14216. $file_name = "";
  14217. $file_extension = "";
  14218. $uploadErrors = array (
  14219. 0 => "文件上传成功",
  14220. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14221. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14222. 3 => "上传的文件仅为部分文件",
  14223. 4 => "没有文件上传",
  14224. 6 => "缺少临时文件夹"
  14225. );
  14226. $nk = time ();
  14227. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14228. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14229. echo "文件无法保存.";
  14230. exit ( 0 );
  14231. }
  14232. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14233. echo json_encode ( array (
  14234. 'filename' => $file_name,
  14235. 'id' => $nk
  14236. ) );
  14237. exit ( 0 );
  14238. }
  14239. function swfupload() {
  14240. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14241. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14242. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14243. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14244. header ( "HTTP/1.1 500 Internal Server Error" );
  14245. echo "POST exceeded maximum allowed size.";
  14246. exit ( 0 );
  14247. }
  14248. // Settings
  14249. $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)
  14250. $upload_name = "Filedata";
  14251. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14252. $extension_whitelist = array (
  14253. "doc",
  14254. "txt",
  14255. "jpg",
  14256. "gif",
  14257. "png"
  14258. ); // Allowed file extensions
  14259. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14260. // Other variables
  14261. $MAX_FILENAME_LENGTH = 260;
  14262. $file_name = "";
  14263. $file_extension = "";
  14264. $uploadErrors = array (
  14265. 0 => "文件上传成功",
  14266. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14267. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14268. 3 => "上传的文件仅为部分文件",
  14269. 4 => "没有文件上传",
  14270. 6 => "缺少临时文件夹"
  14271. );
  14272. $nk = time ();
  14273. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14274. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14275. echo "文件无法保存.";
  14276. exit ( 0 );
  14277. }
  14278. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14279. echo json_encode ( array (
  14280. 'filename' => $file_name,
  14281. 'id' => $nk
  14282. ) );
  14283. exit ( 0 );
  14284. }
  14285. function _GetFileEXT($filename) {
  14286. $pics = explode ( '.', $filename );
  14287. $num = count ( $pics );
  14288. return $pics [$num - 1];
  14289. }
  14290. /**
  14291. * 获取get或者POST值
  14292. * @param string $name 属性名称
  14293. * @return fixed 值
  14294. */
  14295. function get_args($name) {
  14296. if (isset ( $_GET [$name] )) {
  14297. if (is_array ( $_GET [$name] ))
  14298. return $_GET [$name];
  14299. else
  14300. return addslashes ( $_GET [$name] );
  14301. } elseif (isset ( $_POST [$name] )) {
  14302. if (is_array ( $_POST [$name] ))
  14303. return $_POST [$name];
  14304. else
  14305. return addslashes ( $_POST [$name] );
  14306. } else
  14307. return false;
  14308. }
  14309. function num_to_rmb($num) {
  14310. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14311. $c2 = "分角元拾佰仟万拾佰仟亿";
  14312. // 精确到分后面就不要了,所以只留两个小数位
  14313. $num = round ( $num, 2 );
  14314. // 将数字转化为整数
  14315. $num = $num * 100;
  14316. if (strlen ( $num ) > 10) {
  14317. return "金额太大,请检查";
  14318. }
  14319. $i = 0;
  14320. $c = "";
  14321. while ( 1 ) {
  14322. if ($i == 0) {
  14323. // 获取最后一位数字
  14324. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14325. } else {
  14326. $n = $num % 10;
  14327. }
  14328. // 每次将最后一位数字转化为中文
  14329. $p1 = substr ( $c1, 3 * $n, 3 );
  14330. $p2 = substr ( $c2, 3 * $i, 3 );
  14331. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14332. $c = $p1 . $p2 . $c;
  14333. } else {
  14334. $c = $p1 . $c;
  14335. }
  14336. $i = $i + 1;
  14337. // 去掉数字最后一位了
  14338. $num = $num / 10;
  14339. // echo $num.'</br>';
  14340. $num = ( int ) $num;
  14341. // $num =floor($num);
  14342. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14343. // echo $num.'</br>';
  14344. // 结束循环
  14345. if ($num == 0) {
  14346. break;
  14347. }
  14348. }
  14349. // echo $c.'</br>';
  14350. $j = 0;
  14351. $slen = strlen ( $c );
  14352. while ( $j < $slen ) {
  14353. // utf8一个汉字相当3个字符
  14354. $m = substr ( $c, $j, 6 );
  14355. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14356. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14357. $left = substr ( $c, 0, $j );
  14358. $right = substr ( $c, $j + 3 );
  14359. $c = $left . $right;
  14360. $j = $j - 3;
  14361. $slen = $slen - 3;
  14362. }
  14363. $j = $j + 3;
  14364. }
  14365. // 这个是为了去掉类似23.0中最后一个“零”字
  14366. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14367. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14368. }
  14369. // 将处理的汉字加上“整”
  14370. if (empty ( $c )) {
  14371. return "零元整";
  14372. } else {
  14373. return $c . "整";
  14374. }
  14375. }
  14376. /**
  14377. * 获得分页数据
  14378. * @param unknown_type $table
  14379. * @param unknown_type $condition
  14380. * @param unknown_type $on_page
  14381. * @param unknown_type $page_size
  14382. */
  14383. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14384. $page_c = "";
  14385. $page ['previous'] = $this->get_previous ( $on_page );
  14386. $page ['on_page'] = $on_page;
  14387. $total_count = $this->get_table_count ( $table, $condition );
  14388. $total = intval ( $total_count / $page_size );
  14389. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14390. $page ['total_data'] = $total_count;
  14391. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14392. $i = 1;
  14393. $page_max = 1;
  14394. $page_width = 3;
  14395. if ($on_page >= $page_width) {
  14396. $page_max = intval ( $on_page / $page_width ) + 1;
  14397. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14398. }
  14399. for(; $i <= $page ['total_page']; $i ++) {
  14400. if ($i == $on_page)
  14401. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14402. else
  14403. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14404. if ($i == ($page_width * $page_max))
  14405. break;
  14406. }
  14407. $page ['page'] = $page_c;
  14408. $page ['lower'] = (-- $on_page) * $page_size;
  14409. return $page;
  14410. }
  14411. /**
  14412. * 获取总页数
  14413. * @param unknown_type $table
  14414. * @param unknown_type $condition
  14415. */
  14416. public function get_table_count($table = "", $condition = "") {
  14417. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14418. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14419. // echo $sql;die;
  14420. $query = Doo::db ()->query ( $sql );
  14421. $result = $query->fetch ();
  14422. return $result ['count'];
  14423. }
  14424. /**
  14425. * 获取上一页
  14426. * @param unknown_type $on_page
  14427. */
  14428. function get_previous($on_page = 1) {
  14429. return $on_page != 0 ? $on_page - 1 : $on_page;
  14430. }
  14431. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14432. // 收入合计
  14433. Doo::loadModel ( 'invoiceTraining' );
  14434. $invoiceTraining = new invoiceTraining ();
  14435. Doo::loadModel ( 'receipt' );
  14436. $receipt = new receipt ();
  14437. $invoiceTrainingDetail = array (
  14438. 'invoiceArriveAmount' => '0.00',
  14439. 'RIAmount' => '0.00',
  14440. 'invoiceTotalAmount' => '0.00',
  14441. 'invoiceCompanyAmount' => '0.00',
  14442. 'invoiceArriveAmountM'=>'0.00',
  14443. 'invoiceCompanyAmountM'=>'0.00'
  14444. );
  14445. if ($invoiceTrainId != 0) {
  14446. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14447. }
  14448. $invoiceArriveAmount = $RIAmount = 0;
  14449. if (! empty ( $invoiceTrainingDetail )) {
  14450. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14451. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14452. }
  14453. // 备用金
  14454. $sum = 0;
  14455. if (! empty ( $trainLoanRid )) {
  14456. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14457. foreach ($receiptLoanList as $key=>$value){
  14458. $sum+=$value['sum'];
  14459. }
  14460. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14461. // $sum = $receiptLoanDetailBak ['sum'];
  14462. }
  14463. // 支出项金额详情
  14464. // 项目金额合计
  14465. Doo::loadModel ( 'RItem' );
  14466. $RItem = new RItem ();
  14467. Doo::loadModel ( 'accountItem' );
  14468. $accountItem = new accountItem ();
  14469. // 讲师获得
  14470. Doo::loadModel ( 'RILecturer' );
  14471. $RILecturer = new RILecturer ();
  14472. $RItemList = $RItem->getRItemByRid ($rid );
  14473. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14474. // 支出项金额详情
  14475. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14476. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14477. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14478. return $payment;
  14479. }
  14480. }
  14481. ?>