ReceiptController.php 540 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class ReceiptController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. // public static $NEW2 = 0;
  10. public $AGENCY = "日常相关费用";
  11. public $TRAVEL = "差旅相关费用";
  12. public $TRAIN = "培训班费用";
  13. public $OTHER = "其他";
  14. public $INTTRAIN='内部培训费用';
  15. private $MYREVEIPTCACHEPATH = "protected/cache/myReceipt/";
  16. private $PERSONALCOLLECTCACHEPATH = "protected/cache/personalCollect/";
  17. private $CATEGORYCOLLECTPATH = "protected/cache/categoryCollect/";
  18. private $STAFFCOLLECTPATH = "protected/cache/staffCollect/";
  19. private function showCache($path) {
  20. if (file_exists ( $path )) {
  21. echo "<!DOCTYPE html>";
  22. include $path;
  23. die ();
  24. }
  25. }
  26. private function cacheFile($path) {
  27. $content = ob_get_contents ();
  28. $fp = fopen ( $path, "w" );
  29. fwrite ( $fp, $content );
  30. fclose ( $fp );
  31. }
  32. private function collectHtml($receiptCollectList = array(), $itemCategory = "日常相关费用", $classType = "b") {
  33. $collectHtml = "";
  34. $sumPrice = 0.00;
  35. for($i = 1; $i <= 12; $i ++) {
  36. $falg = true;
  37. foreach ( $receiptCollectList as $key => $value ) {
  38. if ($value ['itemCategory'] == $itemCategory && $value ['month'] == $i) {
  39. $sumPrice += $value ['price'];
  40. if ($classType == "b") {
  41. $collectHtml .= '<td class="colGreen taR">¥' . $value ['price'] . '</td>';
  42. $falg = false;
  43. break;
  44. } else {
  45. $collectHtml .= '<td class="taR">¥' . $value ['price'] . '</td>';
  46. $falg = false;
  47. break;
  48. }
  49. }
  50. }
  51. if ($falg)
  52. $collectHtml .= '<td class="taR">-</td>';
  53. }
  54. $collectHtml .= '<td class="taR colGreen">¥' . $sumPrice . '</td>';
  55. return $collectHtml;
  56. }
  57. public function beforeRun($resource, $action) {
  58. Doo::loadClass ( 'XDeode' );
  59. $XDeode = new XDeode ( 5 );
  60. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  61. // 单独判断公司汇总的访问权限
  62. if ($action == 'companyCategoryCollect') {
  63. Doo::loadModel ( "receiptAuthorityManage" );
  64. $invoiceCompanyManage = new receiptAuthorityManage ();
  65. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  66. if (empty ( $icm ))
  67. die ( 'illegal request' );
  68. }
  69. Doo::loadModel ( 'staff' );
  70. $staff = new staff ();
  71. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  72. $accessModular = 'RECEIPTS';
  73. if (empty ( $detail ['cldAccessArray'] ))
  74. die ( 'illegal request' );
  75. else {
  76. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  77. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  78. $flag = true;
  79. } else {
  80. $flag = false;
  81. }
  82. } else {
  83. die ( 'illegal request' );
  84. }
  85. }
  86. if (! $flag)
  87. die ( 'illegal request' );
  88. }
  89. function __construct() {
  90. if (isset ( $_COOKIE ["staff"] )) {
  91. if (! empty ( $_COOKIE ["staff"] )) {
  92. Doo::loadModel ( 'staff' );
  93. Doo::loadModel ( 'verify' );
  94. $verify = new verify ();
  95. $staff = new staff ();
  96. Doo::loadModel ( "execute" );
  97. $execute = new execute ();
  98. $verifyList = $verify->find ( array (
  99. 'select' => 'staff',
  100. 'asArray' => true
  101. ) );
  102. $list = array ();
  103. // 判断角色的审批权限
  104. foreach ( $verifyList as $key => $value ) {
  105. $ver = json_decode ( $value ['staff'] );
  106. foreach ( $ver as $k => $v ) {
  107. if ($v [1] == 'ROLE') {
  108. $roleList = json_decode ( $v [3] );
  109. foreach ( $roleList as $t => $g ) {
  110. $gList = explode ( "_", $g );
  111. array_push ( $list, $gList [0] );
  112. // print_r($list);
  113. }
  114. } else
  115. array_push ( $list, $v [0] );
  116. }
  117. }
  118. // 判断执行人的审批权限
  119. $executeList = $execute->find ( array (
  120. 'where'=>'mold !="日常收支"',
  121. 'select' => 'staff',
  122. 'asArray' => true
  123. ) );
  124. $list2 = array ();
  125. foreach ( $executeList as $key => $value ) {
  126. $ver = json_decode ( $value ['staff'] );
  127. foreach ( $ver as $k => $v ) {
  128. array_push ( $list2, $v [0] );
  129. }
  130. }
  131. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  132. $eidList = array_filter ( explode ( ",", $eidList ) );
  133. $this->executeId = array_merge ( $list2, $eidList );
  134. $this->verifyId = $list;
  135. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  136. // 检测用户信息完成
  137. $this->data ['isStaffCompleteMsg'] = false;
  138. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  139. if (! empty ( $detail ))
  140. $this->data ['isStaffCompleteMsg'] = true;
  141. return "/";
  142. }
  143. }
  144. Doo::loadCore ( 'uri/DooUriRouter' );
  145. $router = new DooUriRouter ();
  146. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  147. if ($routeRs ['1'] != "login") {
  148. header ( 'Content-Type:text/html;charset=utf-8' );
  149. @header ( "Location: /login" );
  150. }
  151. }
  152. function saeaBorad() {
  153. Doo::loadModel ( 'receipt' );
  154. $receipt = new receipt ();
  155. Doo::loadModel ( 'verify' );
  156. $verify = new verify ();
  157. Doo::loadModel ( 'L_category' );
  158. $lCategory = new L_category ();
  159. Doo::loadModel ( "role" );
  160. $role = new role ();
  161. Doo::loadModel ( "receiptLog" );
  162. $receiptLog = new receiptLog ();
  163. Doo::loadClass ( 'XDeode' );
  164. $XDeode = new XDeode ( 7 );
  165. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  166. $receiptDetail = $receipt->find ( array (
  167. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  168. 'desc' => 'rid',
  169. 'asArray' => true
  170. ) );
  171. foreach ( $receiptDetail as $key => $value ) {
  172. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  173. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  174. $veList = $verify->getOne ( array (
  175. 'where' => 'vid=' . $value ['verify'],
  176. 'asArray' => true
  177. ) );
  178. $v = json_decode ( $veList ['staff'] );
  179. array_push ( $v [0], $veList ['description'] );
  180. foreach ( $v as $n => $m ) {
  181. if ($m ['1'] == 'ROLE') {
  182. $roleInfo = $role->getOne ( array (
  183. 'where' => 'rid=' . $m [0],
  184. 'asArray' => true
  185. ) );
  186. $v [$n] [1] = $roleInfo ['name'];
  187. }
  188. }
  189. $receiptDetail [$key] ['staff'] = $v;
  190. $category = $lCategory->getOne ( array (
  191. 'where' => 'cid=' . $value ['cid'],
  192. 'asArray' => true
  193. ) );
  194. $receiptDetail [$key] ['category'] = $category ['title'];
  195. }
  196. // print_r($receiptLogList);
  197. Doo::loadModel ( 'RAssist' );
  198. $RAssist = new RAssist ();
  199. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  200. $data ['receiptExtendList'] = $receiptExtendList;
  201. $data ['receiptLogList'] = $receiptLogList;
  202. $data ['receiptDetail'] = $receiptDetail;
  203. $data ['memu'] = "receipt";
  204. $data ['staff'] = $this->staff;
  205. $data ['receiptMemu'] = 'saeaBorad';
  206. $data ['verifyId'] = $this->verifyId;
  207. $data ['executeId'] = $this->executeId;
  208. $this->render ( "/admin/saeaBorad", $data );
  209. }
  210. function remitAdd() {
  211. Doo::loadModel ( 'accountItem' );
  212. Doo::loadModel ( 'verify' );
  213. Doo::loadModel ( 'receipt' );
  214. Doo::loadModel ( 'L_category' );
  215. $lCategory = new L_category ();
  216. $receipt = new receipt ();
  217. $verify = new verify ();
  218. $accountItem = new accountItem ();
  219. Doo::loadModel ( "role" );
  220. $role = new role ();
  221. $acItem = $accountItem->find ( array (
  222. 'asArray' => true
  223. ) );
  224. $veList = $verify->getVerifyBySubordinate('REMIT');
  225. $data ['category'] = $lCategory->find ( array (
  226. 'asArray' => true
  227. ) );
  228. $data ['veList'] = $veList;
  229. $data ['acItem'] = $acItem;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/admin/remitAdd", $data );
  236. }
  237. function remitAddDo() {
  238. $agency = $this->get_args ( 'agency' );
  239. $travel = $this->get_args ( 'travel' );
  240. $train = $this->get_args ( 'train' );
  241. $other = $this->get_args ( 'other' );
  242. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  243. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  244. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  245. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  246. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  247. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  248. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  249. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  250. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  251. // print_r($agency);die;
  252. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  253. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  254. header ( 'Content-Type:text/html;charset=utf-8' );
  255. die ( '请填写联行号' );
  256. }
  257. Doo::loadModel ( 'receipt' );
  258. Doo::loadModel ( 'receiptDetail' );
  259. Doo::loadModel ( 'accountItem' );
  260. $accountItem = new accountItem ();
  261. $receipt = new receipt ();
  262. Doo::loadModel ( 'enclosur' );
  263. Doo::loadModel ( 'execute' );
  264. $execute = new execute ();
  265. $executeDetail = $execute->getOne ( array (
  266. 'where' => 'mold="对公汇款执行人"',
  267. 'asArray' => true
  268. ) );
  269. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  270. $aItem = $accountItem->find ( array (
  271. 'where' => '(name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  272. 'asArray' => true
  273. ) );
  274. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  275. $ag = $tr = $ta = $ot = 0;
  276. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  277. print_r($aItem);
  278. foreach ( $aItem as $key => $value ) {
  279. if ($value ['category'] == $this->AGENCY) {
  280. if (isset ( $agency [$ag] )) {
  281. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  282. array_push ( $accountJson [$this->AGENCY], array (
  283. 'aid' => $value ['aid'],
  284. 'name' => $value ['name'],
  285. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  286. ) );
  287. $sum += $agency [$ag];
  288. $agencySum += $agency [$ag];
  289. }
  290. }
  291. $ag ++;
  292. }
  293. }
  294. $accountJson ['cSum'] = array (
  295. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  296. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  297. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  298. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  299. );
  300. //die;
  301. // 报销单
  302. $receipt->accountItem = json_encode ( $accountJson );
  303. $receipt->staff = $this->staff [0] ['sid'];
  304. $receipt->sum = number_format ( $sum, 2, '.', '' );
  305. $receipt->date = date ( "Y-m-d" );
  306. $receipt->cid = $cid;
  307. $receipt->status = 5;
  308. $receipt->Rtype = 2;
  309. // 修改审批流程加入角色
  310. $receipt->verify = $verify;
  311. $receipt->executeCopy = $executeDetail ['staff'];
  312. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  313. $order = array (
  314. "\r\n",
  315. "\n",
  316. "\r"
  317. );
  318. $replace = '<br/>';
  319. $explanation = str_replace ( $order, $replace, $explanation );
  320. $receipt->explanation = $explanation;
  321. $receipt->remittanceName = $remittanceName;
  322. $receipt->bankName = $bankName;
  323. $receipt->bankNumber = $bankNumber;
  324. $receipt->remittanceBankType = $remittanceBankType;
  325. if ($remittanceBankType == 1)
  326. $receipt->coupletNumber = $coupletNumber;
  327. $rid = $receipt->insert ();
  328. // 附件
  329. if (! empty ( $enclosurName )) {
  330. $enclosurArray = explode ( '-', $enclosurName );
  331. foreach ( $enclosurArray as $value ) {
  332. $enclosur = new enclosur ();
  333. $enclosur->name = $value;
  334. $enclosur->rid = $rid;
  335. $enclosur->insert ();
  336. }
  337. // print_r($enclosurArray);die;
  338. }
  339. // 报销详情
  340. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  341. $receiptDetail = new receiptDetail ();
  342. $receiptDetail->staff = $this->staff [0] ['sid'];
  343. $receiptDetail->item = $value ['name'];
  344. $receiptDetail->itemCategory = $this->AGENCY;
  345. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  346. $receiptDetail->date = date ( "Y-m-d" );
  347. $receiptDetail->cid = $cid;
  348. $receiptDetail->rid = $rid;
  349. $receiptDetail->status = 4;
  350. $receiptDetail->insert ();
  351. }
  352. return "/saeaBorad";
  353. } else
  354. die ( 'illegal request' );
  355. }
  356. function remitEdit() {
  357. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  358. Doo::loadClass ( 'XDeode' );
  359. $XDeode = new XDeode ( 7 );
  360. $rid = $XDeode->decode ( $ridKey );
  361. if (! is_numeric ( $rid ))
  362. die ( 'illegal request' );
  363. Doo::loadModel ( 'accountItem' );
  364. Doo::loadModel ( 'verify' );
  365. Doo::loadModel ( 'receipt' );
  366. $receipt = new receipt ();
  367. $verify = new verify ();
  368. $accountItem = new accountItem ();
  369. Doo::loadModel ( 'L_category' );
  370. $lCategory = new L_category ();
  371. Doo::loadModel ( "role" );
  372. $role = new role ();
  373. Doo::loadModel ( 'enclosur' );
  374. $enclosur = new enclosur ();
  375. $receiptDetail = $receipt->getOne ( array (
  376. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  377. 'asArray' => true
  378. ) );
  379. if (empty ( $receiptDetail ))
  380. return "/saeaCreate";
  381. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  382. $acItem = $accountItem->find ( array (
  383. 'asArray' => true
  384. ) );
  385. $veList = $verify->getVerifyBySubordinate('REMIT');
  386. // 配置编辑信息
  387. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  388. foreach ( $acItem as $key => $value ) {
  389. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  390. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  391. $acItem [$key] ['price'] = $v ['price'];
  392. }
  393. }
  394. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  395. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  396. $acItem [$key] ['price'] = $v ['price'];
  397. }
  398. }
  399. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  400. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  401. $acItem [$key] ['price'] = $v ['price'];
  402. }
  403. }
  404. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  405. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  406. $acItem [$key] ['price'] = $v ['price'];
  407. }
  408. }
  409. }
  410. $data ['category'] = $lCategory->find ( array (
  411. 'asArray' => true
  412. ) );
  413. $data ['enclosurList'] = $enclosurList;
  414. $data ['cSum'] = $accountItemList ['cSum'];
  415. $data ['sum'] = $receiptDetail ['sum'];
  416. $data ['receiptDetail'] = $receiptDetail;
  417. $data ['veList'] = $veList;
  418. $data ['acItem'] = $acItem;
  419. $data ['memu'] = "receipt";
  420. $data ['staff'] = $this->staff;
  421. $data ['receiptMemu'] = 'saeaBorad';
  422. $data ['verify'] = $receiptDetail ['verify'];
  423. $data ['verifyId'] = $this->verifyId;
  424. $data ['executeId'] = $this->executeId;
  425. $data ['rid'] = $rid;
  426. $data ['ridKey'] = $ridKey;
  427. $this->render ( "/admin/remitEdit", $data );
  428. }
  429. function remitEdiDo() {
  430. $agency = $this->get_args ( 'agency' );
  431. $travel = $this->get_args ( 'travel' );
  432. $train = $this->get_args ( 'train' );
  433. $other = $this->get_args ( 'other' );
  434. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  435. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  436. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  437. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  438. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  439. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  440. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  441. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  442. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  443. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  444. Doo::loadClass ( 'XDeode' );
  445. $XDeode = new XDeode ( 7 );
  446. $rid = $XDeode->decode ( $ridKey );
  447. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  448. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  449. header ( 'Content-Type:text/html;charset=utf-8' );
  450. die ( '请填写联行号' );
  451. }
  452. Doo::loadModel ( 'receipt' );
  453. Doo::loadModel ( 'receiptDetail' );
  454. Doo::loadModel ( 'accountItem' );
  455. $accountItem = new accountItem ();
  456. $receipt = new receipt ();
  457. Doo::loadModel ( 'enclosur' );
  458. $enclosur = new enclosur ();
  459. Doo::loadModel ( 'execute' );
  460. $execute = new execute ();
  461. $executeDetail = $execute->getOne ( array (
  462. 'where' => 'mold="对公汇款执行人"',
  463. 'asArray' => true
  464. ) );
  465. $receiptDetail = $receipt->getOne ( array (
  466. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  467. 'asArray' => true
  468. ) );
  469. if (empty ( $receiptDetail ))
  470. return "/saeaBorad";
  471. $aItem = $accountItem->find ( array (
  472. 'where' => '(name like "办公费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  473. 'asArray' => true
  474. ) );
  475. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  476. $ag = $tr = $ta = $ot = 0;
  477. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  478. foreach ( $aItem as $key => $value ) {
  479. if ($value ['category'] == $this->AGENCY) {
  480. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  481. array_push ( $accountJson [$this->AGENCY], array (
  482. 'aid' => $value ['aid'],
  483. 'name' => $value ['name'],
  484. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  485. ) );
  486. $sum += $agency [$ag];
  487. $agencySum += $agency [$ag];
  488. }
  489. $ag ++;
  490. }
  491. }
  492. $accountJson ['cSum'] = array (
  493. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  494. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  495. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  496. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  497. );
  498. // 报销单
  499. $rid = $receipt->rid = $receiptDetail ['rid'];
  500. $receipt->accountItem = json_encode ( $accountJson );
  501. $receipt->staff = $this->staff [0] ['sid'];
  502. $receipt->sum = number_format ( $sum, 2, '.', '' );
  503. $receipt->date = date ( "Y-m-d" );
  504. $receipt->cid = $cid;
  505. if ($receiptDetail ['Rtype'] == 1)
  506. $receipt->status = 7;
  507. else
  508. $receipt->status = 5;
  509. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  510. $receipt->verify = $verify;
  511. $receipt->executeCopy = $executeDetail ['staff'];
  512. $order = array (
  513. "\r\n",
  514. "\n",
  515. "\r"
  516. );
  517. $replace = '<br/>';
  518. $explanation = str_replace ( $order, $replace, $explanation );
  519. $receipt->explanation = $explanation;
  520. $receipt->remittanceName = $remittanceName;
  521. $receipt->bankName = $bankName;
  522. $receipt->bankNumber = $bankNumber;
  523. $receipt->remittanceBankType = $remittanceBankType;
  524. if ($remittanceBankType == 1)
  525. $receipt->coupletNumber = $coupletNumber;
  526. $receipt->update ();
  527. $receiptDetail = new receiptDetail ();
  528. $receiptDetail->delete ( array (
  529. 'where' => 'rid=' . $rid
  530. ) );
  531. // 报销详情
  532. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  533. $receiptDetail = new receiptDetail ();
  534. $receiptDetail->staff = $this->staff [0] ['sid'];
  535. $receiptDetail->item = $value ['name'];
  536. $receiptDetail->itemCategory = $this->AGENCY;
  537. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  538. $receiptDetail->date = date ( "Y-m-d" );
  539. $receiptDetail->cid = $cid;
  540. $receiptDetail->rid = $rid;
  541. $receiptDetail->status = 4;
  542. $receiptDetail->insert ();
  543. }
  544. // 附件
  545. if (! empty ( $enclosurName )) {
  546. $enclosurArray = explode ( '-', $enclosurName );
  547. foreach ( $enclosurArray as $value ) {
  548. $enclosur = new enclosur ();
  549. $enclosur->name = $value;
  550. $enclosur->rid = $rid;
  551. $enclosur->insert ();
  552. }
  553. }
  554. }
  555. return "/saeaBorad";
  556. }
  557. function remitApproval() {
  558. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  559. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  560. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  561. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  562. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  563. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  564. if (empty ( $status ))
  565. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  566. $vidList = array ();
  567. $button = 0;
  568. Doo::loadModel ( 'verify' );
  569. Doo::loadModel ( 'receipt' );
  570. Doo::loadModel ( 'staff' );
  571. $staff = new staff ();
  572. $receipt = new receipt ();
  573. $verify = new verify ();
  574. Doo::loadModel ( 'L_category' );
  575. $Lcategory = new L_category ();
  576. Doo::loadModel ( 'enclosur' );
  577. $enclosur = new enclosur ();
  578. // user verify ID
  579. $verifyDetail = $verify->find ( array (
  580. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  581. 'asArray' => true
  582. ) );
  583. foreach ( $verifyDetail as $key => $value ) {
  584. array_push ( $vidList, $value ['vid'] );
  585. }
  586. $vid = implode ( ",", $vidList );
  587. if (empty ( $verifyDetail ))
  588. $vid = 0;
  589. $categoryList = $Lcategory->find ( array (
  590. 'asArray' => true
  591. ) );
  592. $staffList = $staff->find ( array (
  593. 'where' => 'cid=' . $cid,
  594. 'asArray' => true
  595. ) );
  596. $ap = "";
  597. if ($status == 4) {
  598. $ap = 4;
  599. $status = 2;
  600. }
  601. // get Receipt By verifyID status 2
  602. $receiptList = $receipt->find ( array (
  603. 'where' => 'rid =' . $rid . ' and status=2',
  604. 'desc' => 'rid',
  605. 'asArray' => true
  606. ) );
  607. if (empty ( $receiptList )) {
  608. die ( 'illegal request' );
  609. }
  610. $Locate = 0;
  611. $roleId = 0;
  612. if ($ap == 4)
  613. $status = 4;
  614. foreach ( $receiptList as $key => $value ) {
  615. $receiptList [$key] ['Locate'] = $Locate;
  616. $Locate ++;
  617. $receiptList [$key] ['reviseDetail'] = array ();
  618. if (! empty ( $value ['reviseDetail'] ))
  619. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  620. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  621. $categoryDetil = $Lcategory->getOne ( array (
  622. 'where' => 'cid=' . $value ['cid'],
  623. 'asArray' => true
  624. ) );
  625. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  626. // 检测编辑状态
  627. $verifyList = $verify->getOne ( array (
  628. 'where' => 'vid=' . $value ['verify'],
  629. 'asArray' => true
  630. ) );
  631. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  632. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  633. Doo::loadModel ( 'role' );
  634. $role = new role ();
  635. // print_r($verifyList);
  636. $flag = true;
  637. $roleKey = 0;
  638. $endStaffArray = array ();
  639. $roleArrayCopy = array ();
  640. foreach ( $verifyList as $k => $v ) {
  641. // init verifyStaff
  642. if ($v [1] == 'ROLE') {
  643. if (! empty ( $verifyStaff )) {
  644. $endStaffArray = end ( $verifyStaff );
  645. if ($v [0] == $endStaffArray ['nextStaff']) {
  646. $roleId = $v [0];
  647. }
  648. }
  649. $roleVerify = json_decode ( $v [3], true );
  650. $roleKey = $k;
  651. $roleArray = array ();
  652. $rolename = $role->getOne ( array (
  653. 'where' => 'rid=' . $v [0],
  654. 'asArray' => true
  655. ) );
  656. foreach ( $roleVerify as $o => $p ) {
  657. $staffID = explode ( '_', $p );
  658. $staffInfo = $staff->getOne ( array (
  659. 'where' => 'sid=' . $staffID [0],
  660. 'asArray' => true
  661. ) );
  662. // print_r($staffID);
  663. $exp = array (
  664. 0 => $staffInfo ['sid'],
  665. 1 => $staffID [1],
  666. 2 => $staffInfo ['avatar'],
  667. 'date' => '',
  668. 'date' => '',
  669. 'opinion' => '',
  670. 'status' => '',
  671. 'rolename' => $rolename ['name']
  672. );
  673. array_push ( $roleArray, $exp );
  674. }
  675. $roleArrayCopy [$v [0]] = $roleArray;
  676. // $verifyList[$k]['roleArray']=$roleArray;
  677. }
  678. // print_r($roleArray);
  679. $verifyList [$k] ['date'] = "";
  680. $verifyList [$k] ['opinion'] = "";
  681. $verifyList [$k] ['status'] = "";
  682. if (empty ( $verifyStaff )) {
  683. $verifyList [$k] ['date'] = "";
  684. $verifyList [$k] ['opinion'] = "";
  685. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  686. $verifyList [$k] ['status'] = 4;
  687. $button = 4;
  688. $flag = false;
  689. }
  690. } else {
  691. foreach ( $verifyStaff as $m => $u ) {
  692. if ($v [0] == $m) {
  693. $verifyList [$k] ['date'] = $u ['date'];
  694. $verifyList [$k] ['opinion'] = $u ['opinion'];
  695. $verifyList [$k] ['status'] = $u ['status'];
  696. $flag = false;
  697. break;
  698. }
  699. }
  700. $endStaffArray = end ( $verifyStaff );
  701. if (isset ( $endStaffArray ['ROLE'] )) {
  702. } else {
  703. $endKey = key ( $verifyStaff );
  704. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  705. $button = 4;
  706. $verifyList [$k] ['status'] = 4;
  707. }
  708. }
  709. }
  710. }
  711. $rolename ['name'] = '';
  712. if (! empty ( $roleId )) {
  713. Doo::loadModel ( 'role' );
  714. $role = new role ();
  715. $rolename = $role->getOne ( array (
  716. 'where' => 'rid=' . $roleId,
  717. 'asArray' => true
  718. ) );
  719. }
  720. if (! empty ( $verifyStaff ))
  721. $endStaffArray = end ( $verifyStaff );
  722. $KOP = false;
  723. foreach ( $roleArrayCopy as $P => $A ) {
  724. foreach ( $A as $MKI => $AVL ) {
  725. if (! empty ( $verifyStaff )) {
  726. // &&$rolename['rid']==$endStaffArray['nextStaff']
  727. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  728. $button = 4;
  729. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  730. }
  731. foreach ( $verifyStaff as $m => $u ) {
  732. $AVLFK = $AVL [0] . '_R';
  733. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  734. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  735. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  736. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  737. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  738. break;
  739. }
  740. }
  741. } else {
  742. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  743. $button = 4;
  744. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  745. }
  746. }
  747. // $roleArray[$MKI]['rolename']=$rolename['name'];
  748. $KOP = true;
  749. }
  750. }
  751. foreach ( $roleArrayCopy as $k => $v ) {
  752. foreach ( $verifyList as $m => $n ) {
  753. if ($n [0] == $k) {
  754. array_splice ( $verifyList, $m, 1, $v );
  755. }
  756. }
  757. }
  758. $receiptList [$key] ['verifyList'] = $verifyList;
  759. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  760. 'where' => 'sid=' . $value ['staff'],
  761. 'asArray' => true
  762. ) );
  763. $receiptList [$key] ['button'] = $button;
  764. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  765. }
  766. $mothHtml = "";
  767. for($i = 1; $i <= 12; $i ++) {
  768. if ($month == $i)
  769. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  770. else
  771. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  772. }
  773. // 获取审批日志
  774. Doo::loadModel ( 'receiptLog' );
  775. $receiptLog = new receiptLog ();
  776. $rlList = array ();
  777. $rlInfo = $receiptLog->getOne ( array (
  778. 'where' => 'rid=' . $rid . ' and status=4',
  779. 'asArray' => true
  780. ) );
  781. $tijdate = $receiptLog->getOne ( array (
  782. 'where' => 'rid=' . $rid . ' and status=2',
  783. 'asc' => 'rlid',
  784. 'asArray' => true
  785. ) );
  786. if (! empty ( $rlInfo )) {
  787. $rlList = $receiptLog->find ( array (
  788. 'where' => 'rid=' . $rid,
  789. 'asc' => 'rlid',
  790. 'asArray' => true
  791. ) );
  792. }
  793. $receiptList [0] ['rlList'] = $rlList;
  794. $enclosurList = $enclosur->find ( array (
  795. 'where' => 'rid=' . $rid,
  796. 'asArray' => true
  797. ) );
  798. $enclosurHtml = '';
  799. foreach ( $enclosurList as $value ) {
  800. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  801. }
  802. // print_r($receiptList);
  803. $data ['enclosurHtml'] = $enclosurHtml;
  804. $data ['rolename'] = $rolename ['name'];
  805. $data ['datetij'] = $tijdate ['date'];
  806. $data ['mothHtml'] = $mothHtml;
  807. $data ['rid'] = $rid;
  808. $data ['receiptList'] = $receiptList;
  809. $data ['receiptApprovalCount'] = count ( $receiptList );
  810. $data ['status'] = $status;
  811. $data ['year'] = $year;
  812. $data ['categoryList'] = $categoryList;
  813. $data ['staffList'] = $staffList;
  814. $data ['cid'] = $cid;
  815. $data ['sid'] = $sid;
  816. $data ['ap'] = $ap;
  817. $data ['memu'] = "receipt";
  818. $data ['staff'] = $this->staff;
  819. $data ['receiptMemu'] = 'approvalExpenses';
  820. $data ['verifyId'] = $this->verifyId;
  821. $data ['executeId'] = $this->executeId;
  822. $this->render ( "/admin/remitApproval", $data );
  823. }
  824. function saeaLoanAdd() {
  825. Doo::loadModel ( 'verify' );
  826. $verify = new verify ();
  827. Doo::loadModel ( "role" );
  828. $role = new role ();
  829. Doo::loadModel ( 'L_category' );
  830. $lCategory = new L_category ();
  831. $veList = $verify->getVerifyBySubordinate('LOAN');
  832. $data ['category'] = $lCategory->find ( array (
  833. 'asArray' => true
  834. ) );
  835. $data ['veList'] = $veList;
  836. $data ['memu'] = "receipt";
  837. $data ['staff'] = $this->staff;
  838. $data ['receiptMemu'] = 'saeaBorad';
  839. $data ['verifyId'] = $this->verifyId;
  840. $data ['executeId'] = $this->executeId;
  841. $this->render ( "/admin/saeaLoanAdd", $data );
  842. }
  843. function saeaLoanAddDo() {
  844. $agency = $this->get_args ( 'agency' );
  845. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  846. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  847. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  848. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  849. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  850. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  851. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  852. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  853. // die;
  854. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  855. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  856. header ( 'Content-Type:text/html;charset=utf-8' );
  857. die ( '请填写联行号' );
  858. }
  859. Doo::loadModel ( 'receipt' );
  860. Doo::loadModel ( 'receiptDetail' );
  861. Doo::loadModel ( 'accountItem' );
  862. $accountItem = new accountItem ();
  863. $receipt = new receipt ();
  864. Doo::loadModel ( 'loanReceipt' );
  865. $loanReceipt = new loanReceipt ();
  866. Doo::loadModel ( 'execute' );
  867. $execute = new execute ();
  868. Doo::loadModel ( 'enclosur' );
  869. $executeDetail = $execute->getOne ( array (
  870. 'where' => 'mold="借款执行人"',
  871. 'asArray' => true
  872. ) );
  873. $aItem = $accountItem->find ( array (
  874. 'asArray' => true
  875. ) );
  876. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  877. $ag = $tr = $ta = $ot = 0;
  878. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  879. array_push ( $accountJson ['借款费用'], array (
  880. 'aid' => 0,
  881. 'name' => '申请金额',
  882. 'price' => number_format ( $agency, 2, '.', '' )
  883. ) );
  884. $sum += $agency;
  885. $agencySum += $agency;
  886. $accountJson ['cSum'] = array (
  887. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  888. 'agencySum' => number_format ( 0, 2, '.', '' ),
  889. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  890. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  891. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  892. );
  893. // 借款数据备份
  894. $loanReceipt->loanItem = json_encode ( $accountJson );
  895. $loanReceipt->staff = $this->staff [0] ['sid'];
  896. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  897. $loanReceipt->date = date ( "Y-m-d" );
  898. $loanReceipt->cid = $cid;
  899. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  900. $loanReceipt->status = 5;
  901. $loanReceipt->Rtype = 1;
  902. $loanReceipt->verify = $verify;
  903. $receipt->receiptOrder = $receipt->receiptOrder;
  904. // 添加HTML换行符
  905. // var_dump($explanation);
  906. $order = array (
  907. "\r\n",
  908. "\n",
  909. "\r"
  910. );
  911. $replace = '<br/>';
  912. $explanation = str_replace ( $order, $replace, $explanation );
  913. // $explanation=str_replace('\r',"<br/>",$explanation);
  914. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  915. $loanReceipt->explanation = $explanation;
  916. $loanRid = $loanReceipt->insert ();
  917. // 报销单
  918. $receipt->loanItem = json_encode ( $accountJson );
  919. $receipt->staff = $this->staff [0] ['sid'];
  920. $receipt->sum = number_format ( $sum, 2, '.', '' );
  921. $receipt->date = date ( "Y-m-d" );
  922. $receipt->cid = $cid;
  923. // 特殊状态
  924. $receipt->status = 5;
  925. $receipt->Rtype = 1;
  926. $receipt->loanRid = $loanRid;
  927. // 修改审批流程加入角色
  928. $receipt->verify = $verify;
  929. $receipt->executeCopy = $executeDetail ['staff'];
  930. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  931. $receipt->explanation = $explanation;
  932. $receipt->remittanceName = $remittanceName;
  933. $receipt->bankName = $bankName;
  934. $receipt->bankNumber = $bankNumber;
  935. $receipt->remittanceBankType = $remittanceBankType;
  936. if ($remittanceBankType == 1)
  937. $receipt->coupletNumber = $coupletNumber;
  938. $rid = $receipt->insert ();
  939. return "/saeaBorad";
  940. } else
  941. die ( 'illegal request' );
  942. }
  943. function saeaLoanEdi() {
  944. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  945. Doo::loadClass ( 'XDeode' );
  946. $XDeode = new XDeode ( 7 );
  947. $rid = $XDeode->decode ( $ridKey );
  948. if (! is_numeric ( $rid ))
  949. die ( 'illegal request' );
  950. Doo::loadModel ( 'verify' );
  951. $verify = new verify ();
  952. Doo::loadModel ( "role" );
  953. $role = new role ();
  954. Doo::loadModel ( 'L_category' );
  955. $lCategory = new L_category ();
  956. Doo::loadModel ( 'receipt' );
  957. $receipt = new receipt ();
  958. $receiptInfo = $receipt->getOne ( array (
  959. 'where' => 'rid=' . $rid,
  960. 'asArray' => true
  961. ) );
  962. $veList = $verify->find ( array (
  963. 'where'=>'subordinate like "%LOAN%"',
  964. 'asArray' => true
  965. ) );
  966. foreach ( $veList as $key => $value ) {
  967. $v = json_decode ( $value ['staff'] );
  968. $list = array ();
  969. foreach ( $v as $n => $m ) {
  970. if ($m ['1'] == 'ROLE') {
  971. $roleInfo = $role->getOne ( array (
  972. 'where' => 'rid=' . $m [0],
  973. 'asArray' => true
  974. ) );
  975. $v [$n] [1] = $roleInfo ['name'];
  976. array_push ( $list, $roleInfo ['name'] );
  977. } else {
  978. array_push ( $list, $v [$n] [1] );
  979. }
  980. }
  981. $veList [$key] ['staff'] = implode ( '>', $list );
  982. }
  983. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  984. // print_r($receiptInfo);
  985. $data ['receiptInfo'] = $receiptInfo;
  986. $data ['category'] = $lCategory->find ( array (
  987. 'asArray' => true
  988. ) );
  989. $data ['veList'] = $veList;
  990. $data ['ridKey'] = $ridKey;
  991. $data ['memu'] = "receipt";
  992. $data ['staff'] = $this->staff;
  993. $data ['receiptMemu'] = 'saeaBorad';
  994. $data ['verifyId'] = $this->verifyId;
  995. $data ['executeId'] = $this->executeId;
  996. $this->render ( "/admin/saeaLoanEdi", $data );
  997. }
  998. function saeaLoanEdiDo() {
  999. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1000. $agency = $this->get_args ( 'agency' );
  1001. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1002. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1003. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1004. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1005. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1006. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1007. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1008. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1009. // die;
  1010. Doo::loadClass ( 'XDeode' );
  1011. $XDeode = new XDeode ( 7 );
  1012. $rid = $XDeode->decode ( $ridKey );
  1013. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1014. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1015. header ( 'Content-Type:text/html;charset=utf-8' );
  1016. die ( '请填写联行号' );
  1017. }
  1018. Doo::loadModel ( 'receipt' );
  1019. Doo::loadModel ( 'receiptDetail' );
  1020. Doo::loadModel ( 'accountItem' );
  1021. $accountItem = new accountItem ();
  1022. $receipt = new receipt ();
  1023. Doo::loadModel ( 'loanReceipt' );
  1024. $loanReceipt = new loanReceipt ();
  1025. Doo::loadModel ( 'enclosur' );
  1026. Doo::loadModel ( 'execute' );
  1027. $execute = new execute ();
  1028. $executeDetail = $execute->getOne ( array (
  1029. 'where' => 'mold="借款执行人"',
  1030. 'asArray' => true
  1031. ) );
  1032. $receiptDetail = $receipt->getOne ( array (
  1033. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1034. 'asArray' => true
  1035. ) );
  1036. if (empty ( $receiptDetail ))
  1037. die ( '参数错误' );
  1038. $aItem = $accountItem->find ( array (
  1039. 'asArray' => true
  1040. ) );
  1041. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1042. $ag = $tr = $ta = $ot = 0;
  1043. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1044. array_push ( $accountJson ['借款费用'], array (
  1045. 'aid' => 0,
  1046. 'name' => '申请金额',
  1047. 'price' => number_format ( $agency, 2, '.', '' )
  1048. ) );
  1049. $sum += $agency;
  1050. $agencySum += $agency;
  1051. $accountJson ['cSum'] = array (
  1052. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1053. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1054. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1055. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1056. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1057. );
  1058. // 报销单
  1059. $receipt->loanItem = json_encode ( $accountJson );
  1060. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1061. $receipt->cid = $cid;
  1062. // 特殊状态
  1063. // 修改审批流程加入角色
  1064. if ($receiptDetail ['status'] != 4)
  1065. $receipt->verify = $verify;
  1066. $order = array (
  1067. "\r\n",
  1068. "\n",
  1069. "\r"
  1070. );
  1071. $replace = '<br/>';
  1072. $explanation = str_replace ( $order, $replace, $explanation );
  1073. $receipt->explanation = $explanation;
  1074. $receipt->remittanceName = $remittanceName;
  1075. $receipt->bankName = $bankName;
  1076. $receipt->bankNumber = $bankNumber;
  1077. $receipt->remittanceBankType = $remittanceBankType;
  1078. if ($remittanceBankType == 1)
  1079. $receipt->coupletNumber = $coupletNumber;
  1080. $receipt->update ( array (
  1081. 'where' => 'rid=' . $rid
  1082. ) );
  1083. // 借款数据更新
  1084. $loanReceipt->loanItem = json_encode ( $accountJson );
  1085. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1086. $loanReceipt->cid = $cid;
  1087. if ($receiptDetail ['status'] != 4)
  1088. $loanReceipt->verify = $verify;
  1089. $loanReceipt->explanation = $explanation;
  1090. $receipt->executeCopy = $executeDetail ['staff'];
  1091. $loanReceipt->update ( array (
  1092. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1093. ) );
  1094. }
  1095. return "/saeaBorad";
  1096. }
  1097. function saeaLoanReceiptAdd() {
  1098. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. Doo::loadModel ( 'loanReceipt' );
  1102. $loanReceipt = new loanReceipt ();
  1103. Doo::loadModel ( 'L_category' );
  1104. $Lcategory = new L_category ();
  1105. Doo::loadModel ( 'verify' );
  1106. Doo::loadModel ( 'statistics' );
  1107. $statistics = new statistics ();
  1108. $verify = new verify ();
  1109. Doo::loadModel ( 'staff' );
  1110. $staff = new staff ();
  1111. $receiptDetail = $receipt->getOne ( array (
  1112. 'where' => 'rid=' . $rid,
  1113. 'desc' => 'rid',
  1114. 'asArray' => true
  1115. ) );
  1116. $receiptList = $loanReceipt->find ( array (
  1117. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1118. 'desc' => 'rid',
  1119. 'asArray' => true
  1120. ) );
  1121. $Locate = 0;
  1122. $roleId = 0;
  1123. $button = 0;
  1124. foreach ( $receiptList as $key => $value ) {
  1125. $receiptList [$key] ['Locate'] = $Locate;
  1126. $Locate ++;
  1127. $receiptList [$key] ['reviseDetail'] = array ();
  1128. if (! empty ( $value ['reviseDetail'] ))
  1129. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1130. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1131. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1132. $categoryDetil = $Lcategory->getOne ( array (
  1133. 'where' => 'cid=' . $value ['cid'],
  1134. 'asArray' => true
  1135. ) );
  1136. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1137. // 检测编辑状态
  1138. $verifyList = $verify->getOne ( array (
  1139. 'where' => 'vid=' . $value ['verify'],
  1140. 'asArray' => true
  1141. ) );
  1142. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1143. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1144. Doo::loadModel ( 'role' );
  1145. $role = new role ();
  1146. $flag = true;
  1147. $roleKey = 0;
  1148. $endStaffArray = array ();
  1149. $roleArrayCopy = array ();
  1150. foreach ( $verifyList as $k => $v ) {
  1151. // init verifyStaff
  1152. if ($v [1] == 'ROLE') {
  1153. if (! empty ( $verifyStaff )) {
  1154. $endStaffArray = end ( $verifyStaff );
  1155. // if ($v[0]==$endStaffArray['nextStaff']){
  1156. // $roleId=$v[0];
  1157. // }
  1158. }
  1159. $roleVerify = json_decode ( $v [3], true );
  1160. $roleKey = $k;
  1161. $roleArray = array ();
  1162. $rolename = $role->getOne ( array (
  1163. 'where' => 'rid=' . $v [0],
  1164. 'asArray' => true
  1165. ) );
  1166. foreach ( $roleVerify as $o => $p ) {
  1167. $staffID = explode ( '_', $p );
  1168. $staffInfo = $staff->getOne ( array (
  1169. 'where' => 'sid=' . $staffID [0],
  1170. 'asArray' => true
  1171. ) );
  1172. // print_r($staffID);
  1173. $exp = array (
  1174. 0 => $staffInfo ['sid'],
  1175. 1 => $staffID [1],
  1176. 2 => $staffInfo ['avatar'],
  1177. 'date' => '',
  1178. 'date' => '',
  1179. 'opinion' => '',
  1180. 'status' => '',
  1181. 'rolename' => $rolename ['name']
  1182. );
  1183. array_push ( $roleArray, $exp );
  1184. }
  1185. $roleArrayCopy [$v [0]] = $roleArray;
  1186. // $verifyList[$k]['roleArray']=$roleArray;
  1187. }
  1188. $verifyList [$k] ['date'] = "";
  1189. $verifyList [$k] ['opinion'] = "";
  1190. $verifyList [$k] ['status'] = "";
  1191. if (empty ( $verifyStaff )) {
  1192. $verifyList [$k] ['date'] = "";
  1193. $verifyList [$k] ['opinion'] = "";
  1194. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1195. $verifyList [$k] ['status'] = 4;
  1196. $flag = false;
  1197. }
  1198. } else {
  1199. foreach ( $verifyStaff as $m => $u ) {
  1200. if ($v [0] == $m) {
  1201. $verifyList [$k] ['date'] = $u ['date'];
  1202. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1203. $verifyList [$k] ['status'] = $u ['status'];
  1204. $flag = false;
  1205. break;
  1206. }
  1207. }
  1208. $endStaffArray = end ( $verifyStaff );
  1209. if (isset ( $endStaffArray ['ROLE'] )) {
  1210. } else {
  1211. // $endKey=key($verifyStaff);
  1212. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1213. // $button=4;
  1214. // $verifyList[$k]['status']=4;
  1215. // }
  1216. }
  1217. }
  1218. }
  1219. $rolename ['name'] = '';
  1220. if (! empty ( $roleId )) {
  1221. Doo::loadModel ( 'role' );
  1222. $role = new role ();
  1223. $rolename = $role->getOne ( array (
  1224. 'where' => 'rid=' . $roleId,
  1225. 'asArray' => true
  1226. ) );
  1227. }
  1228. if (! empty ( $verifyStaff ))
  1229. $endStaffArray = end ( $verifyStaff );
  1230. $KOP = false;
  1231. foreach ( $roleArrayCopy as $P => $A ) {
  1232. foreach ( $A as $MKI => $AVL ) {
  1233. if (! empty ( $verifyStaff )) {
  1234. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1235. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1236. $button = 4;
  1237. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1238. }
  1239. foreach ( $verifyStaff as $m => $u ) {
  1240. $AVLFK = $AVL [0] . '_R';
  1241. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1242. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1243. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1244. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1245. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1246. break;
  1247. }
  1248. }
  1249. } else {
  1250. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1251. $button = 4;
  1252. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1253. }
  1254. }
  1255. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1256. $KOP = true;
  1257. }
  1258. }
  1259. foreach ( $roleArrayCopy as $k => $v ) {
  1260. foreach ( $verifyList as $m => $n ) {
  1261. if ($n [0] == $k) {
  1262. array_splice ( $verifyList, $m, 1, $v );
  1263. }
  1264. }
  1265. }
  1266. $receiptList [$key] ['verifyList'] = $verifyList;
  1267. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1268. 'where' => 'sid=' . $value ['staff'],
  1269. 'asArray' => true
  1270. ) );
  1271. $receiptList [$key] ['button'] = $button;
  1272. //
  1273. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1274. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1275. }
  1276. $data ['receiptList'] = $receiptList;
  1277. $data ['receiptDetail'] = $receiptDetail;
  1278. Doo::loadModel ( 'L_category' );
  1279. $lCategory = new L_category ();
  1280. Doo::loadModel ( 'accountItem' );
  1281. $accountItem = new accountItem ();
  1282. $acItem = $accountItem->find ( array (
  1283. 'asArray' => true
  1284. ) );
  1285. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  1286. $data ['rid'] = $rid;
  1287. $data ['category'] = $lCategory->find ( array (
  1288. 'asArray' => true
  1289. ) );
  1290. $data ['veList'] = $veList;
  1291. $data ['acItem'] = $acItem;
  1292. $data ['memu'] = "receipt";
  1293. $data ['staff'] = $this->staff;
  1294. $data ['receiptMemu'] = 'saeaBorad';
  1295. $data ['verifyId'] = $this->verifyId;
  1296. $data ['executeId'] = $this->executeId;
  1297. $this->render ( "/admin/saeaLoanAddReceipt", $data );
  1298. }
  1299. function saeaLoanReceiptAddDo() {
  1300. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  1301. $agency = $this->get_args ( 'agency' );
  1302. $travel = $this->get_args ( 'travel' );
  1303. $train = $this->get_args ( 'train' );
  1304. $other = $this->get_args ( 'other' );
  1305. $inttrain = $this->get_args ( 'inttrain' );
  1306. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1307. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1308. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1309. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1310. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1311. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1312. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1313. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1314. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1315. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1316. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1317. header ( 'Content-Type:text/html;charset=utf-8' );
  1318. die ( '请填写联行号' );
  1319. }
  1320. Doo::loadModel ( 'receipt' );
  1321. Doo::loadModel ( 'receiptDetail' );
  1322. Doo::loadModel ( 'accountItem' );
  1323. $accountItem = new accountItem ();
  1324. $receipt = new receipt ();
  1325. Doo::loadModel ( 'enclosur' );
  1326. Doo::loadModel ( 'execute' );
  1327. $execute = new execute ();
  1328. $executeDetail = $execute->getOne ( array (
  1329. 'where' => 'mold="借款费用执行人"',
  1330. 'asArray' => true
  1331. ) );
  1332. $receiptDet = $receipt->getOne ( array (
  1333. 'where' => 'rid=' . $rid,
  1334. 'asArray' => true
  1335. ) );
  1336. // if(!empty($receiptDetail))
  1337. // return "/referReceipt/".$receiptDetail['rid'];
  1338. $aItem = $accountItem->find ( array (
  1339. 'asArray' => true
  1340. ) );
  1341. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1342. $ag = $tr = $ta = $ot =$it = 0;
  1343. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  1344. foreach ( $aItem as $key => $value ) {
  1345. if ($value ['category'] == $this->AGENCY) {
  1346. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1347. array_push ( $accountJson [$this->AGENCY], array (
  1348. 'aid' => $value ['aid'],
  1349. 'name' => $value ['name'],
  1350. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1351. ) );
  1352. $sum += $agency [$ag];
  1353. $agencySum += $agency [$ag];
  1354. }
  1355. $ag ++;
  1356. }
  1357. if ($value ['category'] == $this->TRAVEL) {
  1358. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  1359. array_push ( $accountJson [$this->TRAVEL], array (
  1360. 'aid' => $value ['aid'],
  1361. 'name' => $value ['name'],
  1362. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  1363. ) );
  1364. $sum += $travel [$tr];
  1365. $travelSum += $travel [$tr];
  1366. }
  1367. $tr ++;
  1368. }
  1369. if ($value ['category'] == $this->INTTRAIN) {
  1370. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  1371. array_push ( $accountJson [$this->INTTRAIN], array (
  1372. 'aid' => $value ['aid'],
  1373. 'name' => $value ['name'],
  1374. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  1375. ) );
  1376. $sum += $inttrain [$it];
  1377. $inttrainSum += $inttrain [$it];
  1378. }
  1379. $it ++;
  1380. }
  1381. if ($value ['category'] == $this->TRAIN) {
  1382. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  1383. array_push ( $accountJson [$this->TRAIN], array (
  1384. 'aid' => $value ['aid'],
  1385. 'name' => $value ['name'],
  1386. 'price' => number_format ( $train [$ta], 2, '.', '' )
  1387. ) );
  1388. $sum += $train [$ta];
  1389. $trainSum += $train [$ta];
  1390. }
  1391. $ta ++;
  1392. }
  1393. if ($value ['category'] == $this->OTHER) {
  1394. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  1395. array_push ( $accountJson [$this->OTHER], array (
  1396. 'aid' => $value ['aid'],
  1397. 'name' => $value ['name'],
  1398. 'price' => number_format ( $other [$ot], 2, '.', '' )
  1399. ) );
  1400. $sum += $other [$ot];
  1401. $otherSum += $other [$ot];
  1402. }
  1403. $ot ++;
  1404. }
  1405. }
  1406. $accountJson ['cSum'] = array (
  1407. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1408. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1409. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1410. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  1411. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1412. );
  1413. // 报销单
  1414. $receipt->accountItem = json_encode ( $accountJson );
  1415. $receipt->staff = $this->staff [0] ['sid'];
  1416. $receipt->loanSum = $receiptDet ['sum'];
  1417. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1418. $receipt->date = date ( "Y-m-d" );
  1419. $receipt->pastDate = '';
  1420. $receipt->cid = $cid;
  1421. $receipt->status = 7;
  1422. // 修改审批流程加入角色
  1423. $receipt->verify = $verify;
  1424. $receipt->verifyStaff = '';
  1425. $receipt->executeStaff = '';
  1426. $receipt->executeCopy = $executeDetail ['staff'];
  1427. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  1428. $receipt->explanation = $explanation;
  1429. $receipt->remittanceName = $remittanceName;
  1430. $receipt->bankName = $bankName;
  1431. $receipt->bankNumber = $bankNumber;
  1432. $receipt->remittanceBankType = $remittanceBankType;
  1433. if ($remittanceBankType == 1)
  1434. $receipt->coupletNumber = $coupletNumber;
  1435. $receipt->update ( array (
  1436. 'where' => 'rid=' . $rid
  1437. ) );
  1438. // 附件
  1439. if (! empty ( $enclosurName )) {
  1440. $enclosurArray = explode ( '-', $enclosurName );
  1441. foreach ( $enclosurArray as $value ) {
  1442. $enclosur = new enclosur ();
  1443. $enclosur->name = $value;
  1444. $enclosur->rid = $rid;
  1445. $enclosur->insert ();
  1446. }
  1447. // print_r($enclosurArray);die;
  1448. }
  1449. // 报销详情
  1450. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1451. $receiptDetail = new receiptDetail ();
  1452. $receiptDetail->staff = $this->staff [0] ['sid'];
  1453. $receiptDetail->item = $value ['name'];
  1454. $receiptDetail->itemCategory = $this->AGENCY;
  1455. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1456. $receiptDetail->date = date ( "Y-m-d" );
  1457. $receiptDetail->cid = $cid;
  1458. $receiptDetail->rid = $rid;
  1459. $receiptDetail->status = 4;
  1460. $receiptDetail->insert ();
  1461. }
  1462. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1463. $receiptDetail = new receiptDetail ();
  1464. $receiptDetail->staff = $this->staff [0] ['sid'];
  1465. $receiptDetail->item = $value ['name'];
  1466. $receiptDetail->itemCategory = $this->TRAVEL;
  1467. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1468. $receiptDetail->date = date ( "Y-m-d" );
  1469. $receiptDetail->cid = $cid;
  1470. $receiptDetail->rid = $rid;
  1471. $receiptDetail->status = 4;
  1472. $receiptDetail->insert ();
  1473. }
  1474. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1475. $receiptDetail = new receiptDetail ();
  1476. $receiptDetail->staff = $this->staff [0] ['sid'];
  1477. $receiptDetail->item = $value ['name'];
  1478. $receiptDetail->itemCategory = $this->TRAIN;
  1479. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1480. $receiptDetail->date = date ( "Y-m-d" );
  1481. $receiptDetail->cid = $cid;
  1482. $receiptDetail->rid = $rid;
  1483. $receiptDetail->status = 4;
  1484. $receiptDetail->insert ();
  1485. }
  1486. //内训
  1487. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1488. $receiptDetail = new receiptDetail ();
  1489. $receiptDetail->staff = $this->staff [0] ['sid'];
  1490. $receiptDetail->item = $value ['name'];
  1491. $receiptDetail->itemCategory = $this->INTTRAIN;
  1492. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1493. $receiptDetail->date = date ( "Y-m-d" );
  1494. $receiptDetail->cid = $cid;
  1495. $receiptDetail->rid = $rid;
  1496. $receiptDetail->status = 4;
  1497. $receiptDetail->insert ();
  1498. }
  1499. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1500. $receiptDetail = new receiptDetail ();
  1501. $receiptDetail->staff = $this->staff [0] ['sid'];
  1502. $receiptDetail->item = $value ['name'];
  1503. $receiptDetail->itemCategory = $this->OTHER;
  1504. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1505. $receiptDetail->date = date ( "Y-m-d" );
  1506. $receiptDetail->cid = $cid;
  1507. $receiptDetail->rid = $rid;
  1508. $receiptDetail->status = 4;
  1509. $receiptDetail->insert ();
  1510. }
  1511. return "/saeaBorad";
  1512. }
  1513. return "/saeaLoanReceiptAdd/" . $rid;
  1514. }
  1515. function saeaLoanReceiptEdi() {
  1516. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1517. Doo::loadClass ( 'XDeode' );
  1518. $XDeode = new XDeode ( 7 );
  1519. $rid = $XDeode->decode ( $ridKey );
  1520. if (! is_numeric ( $rid ))
  1521. die ( 'illegal request' );
  1522. Doo::loadModel ( 'accountItem' );
  1523. Doo::loadModel ( 'verify' );
  1524. Doo::loadModel ( 'receipt' );
  1525. $receipt = new receipt ();
  1526. $verify = new verify ();
  1527. $accountItem = new accountItem ();
  1528. Doo::loadModel ( 'L_category' );
  1529. $Lcategory = new L_category ();
  1530. Doo::loadModel ( "role" );
  1531. $role = new role ();
  1532. Doo::loadModel ( 'loanReceipt' );
  1533. $loanReceipt = new loanReceipt ();
  1534. Doo::loadModel ( 'staff' );
  1535. $staff = new staff ();
  1536. $receiptDetail = $receipt->getOne ( array (
  1537. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  1538. 'asArray' => true
  1539. ) );
  1540. if (empty ( $receiptDetail ))
  1541. return "/saeaBorad";
  1542. $receiptList = $loanReceipt->find ( array (
  1543. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  1544. 'desc' => 'rid',
  1545. 'asArray' => true
  1546. ) );
  1547. $Locate = 0;
  1548. $roleId = 0;
  1549. $button = 0;
  1550. foreach ( $receiptList as $key => $value ) {
  1551. $receiptList [$key] ['Locate'] = $Locate;
  1552. $Locate ++;
  1553. $receiptList [$key] ['reviseDetail'] = array ();
  1554. if (! empty ( $value ['reviseDetail'] ))
  1555. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1556. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1557. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  1558. $categoryDetil = $Lcategory->getOne ( array (
  1559. 'where' => 'cid=' . $value ['cid'],
  1560. 'asArray' => true
  1561. ) );
  1562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1563. // 检测编辑状态
  1564. $verifyList = $verify->getOne ( array (
  1565. 'where' => 'vid=' . $value ['verify'],
  1566. 'asArray' => true
  1567. ) );
  1568. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1569. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1570. Doo::loadModel ( 'role' );
  1571. $role = new role ();
  1572. $flag = true;
  1573. $roleKey = 0;
  1574. $endStaffArray = array ();
  1575. $roleArrayCopy = array ();
  1576. foreach ( $verifyList as $k => $v ) {
  1577. // init verifyStaff
  1578. if ($v [1] == 'ROLE') {
  1579. if (! empty ( $verifyStaff )) {
  1580. $endStaffArray = end ( $verifyStaff );
  1581. // if ($v[0]==$endStaffArray['nextStaff']){
  1582. // $roleId=$v[0];
  1583. // }
  1584. }
  1585. $roleVerify = json_decode ( $v [3], true );
  1586. $roleKey = $k;
  1587. $roleArray = array ();
  1588. $rolename = $role->getOne ( array (
  1589. 'where' => 'rid=' . $v [0],
  1590. 'asArray' => true
  1591. ) );
  1592. foreach ( $roleVerify as $o => $p ) {
  1593. $staffID = explode ( '_', $p );
  1594. $staffInfo = $staff->getOne ( array (
  1595. 'where' => 'sid=' . $staffID [0],
  1596. 'asArray' => true
  1597. ) );
  1598. // print_r($staffID);
  1599. $exp = array (
  1600. 0 => $staffInfo ['sid'],
  1601. 1 => $staffID [1],
  1602. 2 => $staffInfo ['avatar'],
  1603. 'date' => '',
  1604. 'date' => '',
  1605. 'opinion' => '',
  1606. 'status' => '',
  1607. 'rolename' => $rolename ['name']
  1608. );
  1609. array_push ( $roleArray, $exp );
  1610. }
  1611. $roleArrayCopy [$v [0]] = $roleArray;
  1612. // $verifyList[$k]['roleArray']=$roleArray;
  1613. }
  1614. $verifyList [$k] ['date'] = "";
  1615. $verifyList [$k] ['opinion'] = "";
  1616. $verifyList [$k] ['status'] = "";
  1617. if (empty ( $verifyStaff )) {
  1618. $verifyList [$k] ['date'] = "";
  1619. $verifyList [$k] ['opinion'] = "";
  1620. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1621. $verifyList [$k] ['status'] = 4;
  1622. $flag = false;
  1623. }
  1624. } else {
  1625. foreach ( $verifyStaff as $m => $u ) {
  1626. if ($v [0] == $m) {
  1627. $verifyList [$k] ['date'] = $u ['date'];
  1628. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1629. $verifyList [$k] ['status'] = $u ['status'];
  1630. $flag = false;
  1631. break;
  1632. }
  1633. }
  1634. $endStaffArray = end ( $verifyStaff );
  1635. if (isset ( $endStaffArray ['ROLE'] )) {
  1636. } else {
  1637. // $endKey=key($verifyStaff);
  1638. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  1639. // $button=4;
  1640. // $verifyList[$k]['status']=4;
  1641. // }
  1642. }
  1643. }
  1644. }
  1645. $rolename ['name'] = '';
  1646. if (! empty ( $roleId )) {
  1647. Doo::loadModel ( 'role' );
  1648. $role = new role ();
  1649. $rolename = $role->getOne ( array (
  1650. 'where' => 'rid=' . $roleId,
  1651. 'asArray' => true
  1652. ) );
  1653. }
  1654. if (! empty ( $verifyStaff ))
  1655. $endStaffArray = end ( $verifyStaff );
  1656. $KOP = false;
  1657. foreach ( $roleArrayCopy as $P => $A ) {
  1658. foreach ( $A as $MKI => $AVL ) {
  1659. if (! empty ( $verifyStaff )) {
  1660. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. foreach ( $verifyStaff as $m => $u ) {
  1666. $AVLFK = $AVL [0] . '_R';
  1667. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1668. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1669. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1670. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1671. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1672. break;
  1673. }
  1674. }
  1675. } else {
  1676. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1677. $button = 4;
  1678. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1679. }
  1680. }
  1681. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1682. $KOP = true;
  1683. }
  1684. }
  1685. foreach ( $roleArrayCopy as $k => $v ) {
  1686. foreach ( $verifyList as $m => $n ) {
  1687. if ($n [0] == $k) {
  1688. array_splice ( $verifyList, $m, 1, $v );
  1689. }
  1690. }
  1691. }
  1692. $receiptList [$key] ['verifyList'] = $verifyList;
  1693. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1694. 'where' => 'sid=' . $value ['staff'],
  1695. 'asArray' => true
  1696. ) );
  1697. $receiptList [$key] ['button'] = $button;
  1698. //
  1699. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  1700. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1701. }
  1702. $data ['receiptList'] = $receiptList;
  1703. $acItem = $accountItem->find ( array (
  1704. 'asArray' => true
  1705. ) );
  1706. $veList = $verify->find ( array (
  1707. 'asArray' => true
  1708. ) );
  1709. foreach ( $veList as $key => $value ) {
  1710. $v = json_decode ( $value ['staff'] );
  1711. $list = array ();
  1712. foreach ( $v as $n => $m ) {
  1713. if ($m ['1'] == 'ROLE') {
  1714. $roleInfo = $role->getOne ( array (
  1715. 'where' => 'rid=' . $m [0],
  1716. 'asArray' => true
  1717. ) );
  1718. $v [$n] [1] = $roleInfo ['name'];
  1719. array_push ( $list, $roleInfo ['name'] );
  1720. } else {
  1721. array_push ( $list, $v [$n] [1] );
  1722. }
  1723. }
  1724. $veList [$key] ['staff'] = implode ( '>', $list );
  1725. }
  1726. // 配置编辑信息
  1727. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1728. foreach ( $acItem as $key => $value ) {
  1729. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1730. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1731. $acItem [$key] ['price'] = $v ['price'];
  1732. }
  1733. }
  1734. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1735. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1736. $acItem [$key] ['price'] = $v ['price'];
  1737. }
  1738. }
  1739. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1740. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1741. $acItem [$key] ['price'] = $v ['price'];
  1742. }
  1743. }
  1744. //内训
  1745. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  1746. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1747. $acItem [$key] ['price'] = $v ['price'];
  1748. }
  1749. }
  1750. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1751. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1752. $acItem [$key] ['price'] = $v ['price'];
  1753. }
  1754. }
  1755. }
  1756. $data ['category'] = $Lcategory->find ( array (
  1757. 'asArray' => true
  1758. ) );
  1759. $data ['ridKey'] = $ridKey;
  1760. $data ['cSum'] = $accountItemList ['cSum'];
  1761. $data ['sum'] = $receiptDetail ['sum'];
  1762. $data ['receiptDetail'] = $receiptDetail;
  1763. $data ['veList'] = $veList;
  1764. $data ['acItem'] = $acItem;
  1765. $data ['memu'] = "receipt";
  1766. $data ['staff'] = $this->staff;
  1767. $data ['receiptMemu'] = 'saeaBorad';
  1768. $data ['verify'] = $receiptDetail ['verify'];
  1769. $data ['verifyId'] = $this->verifyId;
  1770. $data ['executeId'] = $this->executeId;
  1771. $data ['rid'] = $rid;
  1772. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  1773. }
  1774. /**
  1775. * 培训班结算
  1776. */
  1777. function receiptTrainAdd() {
  1778. Doo::loadModel ( 'accountItem' );
  1779. $accountItem = new accountItem ();
  1780. $acItem = $accountItem->find ( array (
  1781. 'asArray' => true
  1782. ) );
  1783. // 审批组
  1784. Doo::loadModel ( 'verify' );
  1785. $verify = new verify ();
  1786. $veList = $verify->getVerifyBySubordinate('TRAIN');
  1787. // 办事处
  1788. Doo::loadModel ( 'L_category' );
  1789. $lCategory = new L_category ();
  1790. $data ['category'] = $lCategory->getCategory ();
  1791. $data ['veList'] = $veList;
  1792. $data ['memu'] = "receipt";
  1793. $data ['staff'] = $this->staff;
  1794. $data ['acItem'] = $acItem;
  1795. $data ['receiptMemu'] = 'saeaBorad';
  1796. $data ['verifyId'] = $this->verifyId;
  1797. $data ['executeId'] = $this->executeId;
  1798. $this->render ( "/receipt/receiptTrainAdd", $data );
  1799. }
  1800. /**
  1801. * 添加培训班结算
  1802. */
  1803. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1804. // 培训班信息
  1805. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1806. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  1807. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  1808. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  1809. $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. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1821. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1822. header ( 'Content-Type:text/html;charset=utf-8' );
  1823. die ( '请填写联行号' );
  1824. }
  1825. Doo::loadModel ( 'execute' );
  1826. $execute = new execute ();
  1827. $executeDetail = $execute->getOne ( array (
  1828. 'where' => 'mold="培训班结算"',
  1829. 'asArray' => true
  1830. ) );
  1831. if (empty ( $executeDetail )) {
  1832. header ( 'Content-Type:text/html;charset=utf-8' );
  1833. die ( '未设置执行人' );
  1834. }
  1835. Doo::loadClass ( 'XDeode' );
  1836. $XDeode = new XDeode ( 5 );
  1837. $cid = $XDeode->decode ( $cid );
  1838. Doo::loadModel ( 'receipt' );
  1839. $receipt = new receipt ();
  1840. Doo::loadModel ( 'receiptTraining' );
  1841. $receiptTraining = new receiptTraining ();
  1842. // 创建费用培训班
  1843. $item = array (
  1844. 'cid' => $this->staff [0] ['cid'],
  1845. 'categoryName' => $this->staff [0] ['category'],
  1846. 'trainName' => $trainName,
  1847. 'trainStartDate' => $trainStartDate,
  1848. 'trainEndDate' => $trainEndDate,
  1849. 'participants' => $participants,
  1850. 'freeParticipants'=>$freeParticipants,
  1851. 'trainAddress' => $trainAddress,
  1852. 'trainRemarks' => $trainRemarks,
  1853. 'creator' => $this->staff [0] ['sid'],
  1854. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1855. );
  1856. $irid = $receiptTraining->addReceiptTraining ( $item );
  1857. // 报销单
  1858. $receipt->status = 5;
  1859. $receipt->trainId = $irid;
  1860. $receipt->Rtype = 3;
  1861. $receipt->staff = $this->staff [0] ['sid'];
  1862. $receipt->cid = $cid;
  1863. $receipt->verify = $verify;
  1864. $receipt->date = date ( "Y-m-d" );
  1865. $receipt->executeCopy = $executeDetail ['staff'];
  1866. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1867. $receipt->remittanceName = $remittanceName;
  1868. $receipt->bankName = $bankName;
  1869. $receipt->bankNumber = $bankNumber;
  1870. $receipt->remittanceBankType = $remittanceBankType;
  1871. if ($remittanceBankType == 1)
  1872. $receipt->coupletNumber = $coupletNumber;
  1873. $rid = $receipt->insert ();
  1874. $XDeode = new XDeode ( 7 );
  1875. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1876. } else
  1877. die ( 'illegal request' );
  1878. }
  1879. /**
  1880. * 培训班编辑
  1881. */
  1882. function receiptTrainEdi() {
  1883. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1884. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1885. Doo::loadClass ( 'XDeode' );
  1886. $XDeode = new XDeode ( 7 );
  1887. $rid = $XDeode->decode ( $ridKey );
  1888. if (! is_numeric ( $rid ))
  1889. die ( 'illegal request' );
  1890. Doo::loadModel ( 'receipt' );
  1891. $receipt = new receipt ();
  1892. Doo::loadModel ( 'receiptTraining' );
  1893. $receiptTraining = new receiptTraining ();
  1894. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1895. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1896. die ('illegal request--status');
  1897. }
  1898. //如有已入账已收款的发票,自动取消办事处已收款
  1899. // Doo::loadModel ( 'RIExtend' );
  1900. // $RIExtend = new RIExtend ();
  1901. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1902. // if (!empty($RIExtendList)){
  1903. // foreach ($RIExtendList as $key=>$value){
  1904. // $RIExtend = new RIExtend ();
  1905. // $RIExtend->delete(array (
  1906. // 'where' => 'iid=' . $value['iid'],
  1907. // 'limit' => 1
  1908. // ));
  1909. // }
  1910. // }
  1911. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1912. // 汇总表合计
  1913. // 收入合计--加入开票合计
  1914. Doo::loadModel ( 'invoiceTraining' );
  1915. $invoiceTraining = new invoiceTraining ();
  1916. $invoiceTrainingDetail = array (
  1917. 'invoiceArriveAmount' => 0,
  1918. 'RIAmount' => 0,
  1919. 'invoiceTotalAmount' => 0,
  1920. 'invoiceCompanyAmount'=>0
  1921. );
  1922. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1923. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1924. }
  1925. // print_r($invoiceTrainingDetail);
  1926. $invoiceArriveAmount = $RIAmount = 0;
  1927. if (! empty ( $invoiceTrainingDetail )) {
  1928. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1929. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1930. }
  1931. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1932. //print_r($invoiceTrainingDetail);
  1933. // 支出项目
  1934. Doo::loadModel ( 'accountItem' );
  1935. $accountItem = new accountItem ();
  1936. // 项目金额合计
  1937. Doo::loadModel ( 'RItem' );
  1938. $RItem = new RItem ();
  1939. // 讲师获得
  1940. Doo::loadModel ( 'RILecturer' );
  1941. $RILecturer = new RILecturer ();
  1942. $RItemList = $RItem->getRItemByRid ( $rid );
  1943. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1944. // 支出项金额详情
  1945. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1946. // print_r($aiData);
  1947. // 利润
  1948. $profit=$invoiceArriveAmount - $aiData ['total'];
  1949. $companyProfit=$profit * 0.6;
  1950. $categoryProfit=$profit * 0.4;
  1951. $data ['profit'] = sprintf("%.2f",$profit);
  1952. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1953. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1954. //发票利润
  1955. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1956. //发票公司利润
  1957. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1958. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1959. //办事处利润
  1960. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1961. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1962. // print_r($aiData['dataList']);
  1963. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1964. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1965. // 备用金
  1966. $sum = 0;
  1967. $data ['receiptLoanDetail'] = array (
  1968. 'sum' => '0.00'
  1969. );
  1970. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1971. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1972. $sum = $data ['receiptLoanDetail'] ['sum'];
  1973. }
  1974. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1975. $data ['payment'] = sprintf("%.2f",$payment);
  1976. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1977. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1978. $data ['aiList'] = $aiData ['dataList'];
  1979. // 占比计算
  1980. if ($invoiceArriveAmount != 0) {
  1981. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1982. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1983. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1984. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1985. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1986. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1987. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1988. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1989. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1990. } else {
  1991. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1992. }
  1993. //发票金额占比计算
  1994. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1995. //支出
  1996. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //利润
  1998. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //公司利润
  2000. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //办事处利润
  2002. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //公司收款
  2004. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //备用金
  2006. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //办事处收款
  2008. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. //办事处实际支出
  2010. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2011. //付总部款
  2012. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2013. }else{
  2014. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2015. }
  2016. //讲师人数
  2017. Doo::loadModel ( 'RILecturer' );
  2018. $RILecturer = new RILecturer ();
  2019. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2020. $data['lectureCount']=count($RILecturerList);
  2021. // 审批组
  2022. Doo::loadModel ( 'verify' );
  2023. $verify = new verify ();
  2024. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2025. // 办事处
  2026. Doo::loadModel ( 'L_category' );
  2027. $lCategory = new L_category ();
  2028. $data ['category'] = $lCategory->getCategory ();
  2029. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2030. $data ['receiptDetail'] = $receiptDetail;
  2031. $data ['veList'] = $veList;
  2032. $data ['trainEdiType'] = $trainEdiType;
  2033. $data ['ridKey'] = $ridKey;
  2034. $data ['memu'] = "receipt";
  2035. $data ['staff'] = $this->staff;
  2036. $data ['receiptMemu'] = 'saeaBorad';
  2037. $data ['verifyId'] = $this->verifyId;
  2038. $data ['executeId'] = $this->executeId;
  2039. $this->render ( "/receipt/receiptTrainEdi", $data );
  2040. }
  2041. /**
  2042. * 培训班借款编辑
  2043. */
  2044. function receiptTrainLoanEdi() {
  2045. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2046. Doo::loadClass ( 'XDeode' );
  2047. $XDeode = new XDeode ( 7 );
  2048. $rid = $XDeode->decode ( $ridKey );
  2049. if (! is_numeric ( $rid ))
  2050. die ( 'illegal request' );
  2051. Doo::loadModel ( 'receipt' );
  2052. $receipt = new receipt ();
  2053. Doo::loadModel ( 'receiptTraining' );
  2054. $receiptTraining = new receiptTraining ();
  2055. Doo::loadModel ( 'verify' );
  2056. $verify = new verify ();
  2057. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2058. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2059. die ();
  2060. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2061. // 借款详情HTML
  2062. // 获得借款信息
  2063. $receiptLoanHtml = '';
  2064. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2065. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2066. // 获得某费用单审批信息
  2067. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2068. Doo::loadClass ( 'receipt.func' );
  2069. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2070. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2071. }
  2072. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2073. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2074. $data ['receiptDetail'] = $receiptDetail;
  2075. $data ['trainEdiType'] = "LOAN";
  2076. $data ['ridKey'] = $ridKey;
  2077. $data ['memu'] = "receipt";
  2078. $data ['staff'] = $this->staff;
  2079. $data ['receiptMemu'] = 'saeaBorad';
  2080. $data ['verifyId'] = $this->verifyId;
  2081. $data ['executeId'] = $this->executeId;
  2082. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2083. }
  2084. /**
  2085. * 更新培训班结算基本信息
  2086. */
  2087. function receiptTrainInfoEdiDo() {
  2088. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2089. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2090. // 培训班信息
  2091. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2092. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2093. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2094. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2095. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2096. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2097. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2098. // 发票信息
  2099. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2100. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2101. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2102. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2103. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2104. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2105. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2106. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2107. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2108. header ( 'Content-Type:text/html;charset=utf-8' );
  2109. die ( '请填写联行号' );
  2110. }
  2111. Doo::loadClass ( 'XDeode' );
  2112. $XDeode = new XDeode ( 5 );
  2113. $cid = $XDeode->decode ( $cid );
  2114. $rtid = $XDeode->decode ( $rtid );
  2115. $rid = $XDeode->decode ( $rid );
  2116. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2117. die ( 'illegal request-IdError' );
  2118. }
  2119. Doo::loadModel ( 'receipt' );
  2120. $receipt = new receipt ();
  2121. Doo::loadModel ( 'receiptTraining' );
  2122. $receiptTraining = new receiptTraining ();
  2123. // 更新费用培训班
  2124. $item = array (
  2125. 'rtid' => $rtid,
  2126. 'trainName' => $trainName,
  2127. 'trainStartDate' => $trainStartDate,
  2128. 'trainEndDate' => $trainEndDate,
  2129. 'participants' => $participants,
  2130. 'freeParticipants'=>$freeParticipants,
  2131. 'trainAddress' => $trainAddress,
  2132. 'trainRemarks' => $trainRemarks
  2133. );
  2134. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2135. // 报销单
  2136. $receipt->rid = $rid;
  2137. $receipt->cid = $cid;
  2138. $receipt->verify = $verify;
  2139. $receipt->remittanceName = $remittanceName;
  2140. $receipt->bankName = $bankName;
  2141. $receipt->bankNumber = $bankNumber;
  2142. $receipt->remittanceBankType = $remittanceBankType;
  2143. if ($remittanceBankType == 1)
  2144. $receipt->coupletNumber = $coupletNumber;
  2145. $receipt->update ();
  2146. $XDeode = new XDeode ( 7 );
  2147. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2148. } else
  2149. die ( 'illegal request' );
  2150. }
  2151. /**
  2152. * 编辑培训班结算---更新借款
  2153. */
  2154. function receiptTrainLoanEdiDo() {
  2155. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2156. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2157. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2158. Doo::loadModel ( 'receipt' );
  2159. $receipt = new receipt ();
  2160. Doo::loadClass ( 'XDeode' );
  2161. $XDeode = new XDeode ( 5 );
  2162. $rid = $XDeode->decode ( $ridKey );
  2163. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2164. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2165. die ( 'illegal request-ridError' );
  2166. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2167. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2168. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2169. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2170. die ( 'illegal request-receiptError' );
  2171. }
  2172. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2173. die ( 'illegal request-receipLoantError' );
  2174. }
  2175. // 培训班结算挂钩借款
  2176. $receipt = new receipt ();
  2177. $item = array (
  2178. 'rid' => $rid,
  2179. 'trainLoanRid' => $ridLoan
  2180. );
  2181. $receipt->setReceiptByCondition ( $item );
  2182. // 更新借款状态变成已挂钩
  2183. $receipt = new receipt ();
  2184. $item = array (
  2185. 'rid' => $ridLoan,
  2186. 'status' => 10,
  2187. 'statusTrain' => 1
  2188. );
  2189. $receipt->setReceiptByCondition ( $item );
  2190. $XDeode = new XDeode ( 7 );
  2191. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2192. } else
  2193. die ( 'illegal request' );
  2194. }
  2195. /**
  2196. * 编辑培训班结算--移除借款
  2197. */
  2198. function receiptTrainLoanRemoveDo() {
  2199. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2200. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2201. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2202. Doo::loadModel ( 'receipt' );
  2203. $receipt = new receipt ();
  2204. Doo::loadClass ( 'XDeode' );
  2205. $XDeode = new XDeode ( 5 );
  2206. $rid = $XDeode->decode ( $ridKey );
  2207. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2208. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2209. die ( 'illegal request-ridError' );
  2210. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2211. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2212. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2213. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2214. die ( 'illegal request-receiptError' );
  2215. }
  2216. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2217. die ( 'illegal request-receipLoantError' );
  2218. }
  2219. // 培训班结算挂钩借款
  2220. $receipt = new receipt ();
  2221. $item = array (
  2222. 'rid' => $rid,
  2223. 'trainLoanRid' => 0
  2224. );
  2225. $receipt->setReceiptByCondition ( $item );
  2226. // 更新借款状态变成已挂钩
  2227. $receipt = new receipt ();
  2228. $item = array (
  2229. 'rid' => $ridLoan,
  2230. 'status' => 8,
  2231. 'statusTrain' => 0
  2232. );
  2233. $receipt->setReceiptByCondition ( $item );
  2234. $XDeode = new XDeode ( 7 );
  2235. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2236. } else
  2237. die ( 'illegal request' );
  2238. }
  2239. /**
  2240. * 编辑培训班结算 ---开票
  2241. */
  2242. function receiptTrainInvoiceEdi() {
  2243. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2244. Doo::loadClass ( 'XDeode' );
  2245. $XDeode = new XDeode ( 7 );
  2246. $rid = $XDeode->decode ( $ridKey );
  2247. if (! is_numeric ( $rid ))
  2248. die ( 'illegal request' );
  2249. Doo::loadModel ( 'receipt' );
  2250. $receipt = new receipt ();
  2251. Doo::loadModel ( 'receiptTraining' );
  2252. $receiptTraining = new receiptTraining ();
  2253. Doo::loadModel ( 'invoice' );
  2254. $invoice = new invoice ();
  2255. Doo::loadModel ( 'invoiceTraining' );
  2256. $invoiceTraining = new invoiceTraining ();
  2257. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2258. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2259. die ();
  2260. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2261. $invoiceList = $invoiceTrainingDetail = array ();
  2262. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2263. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2264. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2265. }
  2266. //print_r($invoiceList);
  2267. $data ['invoiceList'] = $invoiceList;
  2268. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2269. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2270. $data ['receiptDetail'] = $receiptDetail;
  2271. $data ['trainEdiType'] = "INVOICE";
  2272. $data ['ridKey'] = $ridKey;
  2273. $data ['memu'] = "receipt";
  2274. $data ['staff'] = $this->staff;
  2275. $data ['receiptMemu'] = 'saeaBorad';
  2276. $data ['verifyId'] = $this->verifyId;
  2277. $data ['executeId'] = $this->executeId;
  2278. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2279. }
  2280. /**
  2281. * 编辑培训班结算---更新开票
  2282. */
  2283. function receiptTrainInvoiceEdiDo() {
  2284. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2285. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2286. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2287. Doo::loadModel ( 'receipt' );
  2288. $receipt = new receipt ();
  2289. Doo::loadModel ( 'invoiceTraining' );
  2290. $invoiceTraining = new invoiceTraining ();
  2291. Doo::loadClass ( 'XDeode' );
  2292. $XDeode = new XDeode ( 5 );
  2293. $rid = $XDeode->decode ( $ridKey );
  2294. $itid = $XDeode->decode ( $itidKey );
  2295. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2296. die ( 'illegal request-idError' );
  2297. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2298. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2299. // 不合法的数据
  2300. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2301. die ( 'illegal request-receiptError' );
  2302. }
  2303. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2304. die ( 'illegal request-receipLoantError' );
  2305. }
  2306. // 培训班结算挂钩借款
  2307. $receipt = new receipt ();
  2308. $item = array (
  2309. 'rid' => $rid,
  2310. 'invoiceTrainId' => $itid
  2311. );
  2312. $receipt->setReceiptByCondition ( $item );
  2313. $invoiceTraining = new invoiceTraining ();
  2314. $item = array (
  2315. 'bindReceipt' => 1,
  2316. 'itid' => $itid
  2317. );
  2318. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2319. $XDeode = new XDeode ( 7 );
  2320. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2321. } else
  2322. die ( 'illegal request' );
  2323. }
  2324. /**
  2325. * 更新培训班结算 收款和取消收款
  2326. */
  2327. function receiptTrainReceivables() {
  2328. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2329. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2330. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2331. Doo::loadClass ( 'XDeode' );
  2332. $XDeode = new XDeode ( 5 );
  2333. $rid = $XDeode->decode ( $ridKey );
  2334. $iid = $XDeode->decode ( $iidKey );
  2335. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2336. die ( 'illegal request-iid' );
  2337. Doo::loadModel ( 'RIExtend' );
  2338. $RIExtend = new RIExtend ();
  2339. if ($doType == 'CONFIRM') {
  2340. $RIExtend->rid = $rid;
  2341. $RIExtend->iid = $iid;
  2342. $RIExtend->RIstatus = 1;
  2343. $RIExtend->insert ();
  2344. echo json_encode ( array (
  2345. 'status' => 1,
  2346. ) );
  2347. die ( );
  2348. } elseif ($doType == 'CANCEL') {
  2349. $RIExtend->delete ( array (
  2350. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2351. 'limit' => 1
  2352. ) );
  2353. echo json_encode ( array (
  2354. 'status' => 1,
  2355. ) );
  2356. die ( );
  2357. } else {
  2358. echo json_encode ( array (
  2359. 'status' => 2,
  2360. ) );
  2361. die ( );
  2362. }
  2363. }
  2364. /**
  2365. * 移除挂钩的培训班发票
  2366. */
  2367. function receiptTrainReceivablesDelDo() {
  2368. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2369. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2370. Doo::loadModel ( 'receipt' );
  2371. $receipt = new receipt ();
  2372. Doo::loadModel ( 'RIExtend' );
  2373. $RIExtend = new RIExtend ();
  2374. Doo::loadClass ( 'XDeode' );
  2375. $XDeode = new XDeode ( 5 );
  2376. $rid = $XDeode->decode ( $ridKey );
  2377. $itid = $XDeode->decode ( $itidKey );
  2378. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2379. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2380. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2381. die ( 'illegal request-status' );
  2382. }
  2383. $receipt = new receipt ();
  2384. $receipt->rid = $rid;
  2385. $receipt->invoiceTrainId = 0;
  2386. $receipt->update ();
  2387. Doo::loadModel ( 'invoiceTraining' );
  2388. $invoiceTraining = new invoiceTraining ();
  2389. $item = array (
  2390. 'bindReceipt' => 0,
  2391. 'itid' => $itid
  2392. );
  2393. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2394. $RIExtend->delete ( array (
  2395. 'where' => 'rid=' . $rid
  2396. ) );
  2397. $XDeode = new XDeode ( 7 );
  2398. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2399. } else
  2400. die ( 'illegal request-iid' );
  2401. }
  2402. /**
  2403. * 编辑培训班结算
  2404. */
  2405. function receiptTrainItemEdi() {
  2406. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2407. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2408. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2409. Doo::loadClass ( 'XDeode' );
  2410. $XDeode = new XDeode ( 7 );
  2411. $rid = $XDeode->decode ( $ridKey );
  2412. if (! is_numeric ( $rid ))
  2413. die ( 'illegal request' );
  2414. Doo::loadModel ( 'receipt' );
  2415. $receipt = new receipt ();
  2416. Doo::loadModel ( 'receiptTraining' );
  2417. $receiptTraining = new receiptTraining ();
  2418. Doo::loadModel ( 'RItem' );
  2419. $RItem = new RItem ();
  2420. Doo::loadModel ( 'accountItem' );
  2421. $accountItem = new accountItem ();
  2422. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2423. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2424. die ();
  2425. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2426. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2427. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2428. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2429. // if($value['name']=='税款'){
  2430. // unset($aiList[$key]);break;
  2431. // }
  2432. // }
  2433. //print_r($RItemList);
  2434. $data ['name'] = $name;
  2435. $data ['RItemList'] = $RItemList;
  2436. $data ['aiList'] = $aiList;
  2437. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2438. $data ['receiptDetail'] = $receiptDetail;
  2439. $data ['trainEdiType'] = "ITEM";
  2440. $data ['ridKey'] = $ridKey;
  2441. $data ['memu'] = "receipt";
  2442. $data ['staff'] = $this->staff;
  2443. $data ['receiptMemu'] = 'saeaBorad';
  2444. $data ['verifyId'] = $this->verifyId;
  2445. $data ['executeId'] = $this->executeId;
  2446. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2447. }
  2448. /**
  2449. * 添加支出项 需要修改 费用金额合计
  2450. */
  2451. function receiptTrainItemAddDo() {
  2452. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2453. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2454. // 支出项信息
  2455. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2456. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2457. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2458. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2459. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2460. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2461. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2462. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2463. Doo::loadClass ( 'XDeode' );
  2464. $XDeode = new XDeode ( 5 );
  2465. Doo::loadModel ( 'RItem' );
  2466. $RItem = new RItem ();
  2467. $rid = $XDeode->decode ( $ridKey );
  2468. $rtid= $XDeode->decode ( $rtidKey );
  2469. if (! is_numeric ( $rid )){
  2470. die ( 'illegal request' );
  2471. }
  2472. Doo::loadModel ( 'receiptDetail' );
  2473. $receiptDetail = new receiptDetail ();
  2474. Doo::loadModel ( 'receipt' );
  2475. $receipt = new receipt ();
  2476. Doo::loadModel ( 'receiptTraining' );
  2477. $receiptTraining = new receiptTraining ();
  2478. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2479. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2480. $order = array (
  2481. "\r\n",
  2482. "\n",
  2483. "\r"
  2484. );
  2485. $replace = '<br/>';
  2486. $describe = str_replace ( $order, $replace, $describe );
  2487. $itemData = array (
  2488. 'rid' => $rid,
  2489. 'item' => $item,
  2490. 'price' => $price,
  2491. 'date' => $date,
  2492. 'inputer' => $inputer,
  2493. 'describe' => $describe,
  2494. 'creater' => $this->staff['0']['username'],
  2495. 'createrId' => $this->staff['0']['sid'],
  2496. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2497. 'identifying'=>$identifyingTotal
  2498. );
  2499. if($payType=='company'){
  2500. $itemData += array (
  2501. 'payType' => 1
  2502. );
  2503. }
  2504. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2505. //更新支出项标识总数
  2506. $itemData = array (
  2507. 'rtid'=>$rtid,
  2508. 'identifyingTotal'=>$identifyingTotal
  2509. );
  2510. $receiptTraining->setReceiptTrainByCondition($itemData);
  2511. $XDeode = new XDeode ( 7 );
  2512. if($payType=='company'){
  2513. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2514. }else{
  2515. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2516. }
  2517. } else
  2518. die ( 'illegal request-dataError' );
  2519. }
  2520. /**
  2521. * 培训班结算-讲师
  2522. */
  2523. function receiptTrainLecturerEdi() {
  2524. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2525. Doo::loadClass ( 'XDeode' );
  2526. $XDeode = new XDeode ( 7 );
  2527. $rid = $XDeode->decode ( $ridKey );
  2528. if (! is_numeric ( $rid ))
  2529. die ( 'illegal request' );
  2530. Doo::loadModel ( 'receipt' );
  2531. $receipt = new receipt ();
  2532. Doo::loadModel ( 'receiptTraining' );
  2533. $receiptTraining = new receiptTraining ();
  2534. Doo::loadModel ( 'RILecturer' );
  2535. $RILecturer = new RILecturer ();
  2536. Doo::loadModel ( 'lecturer' );
  2537. $lecturer = new lecturer ();
  2538. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2539. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2540. die ();
  2541. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2542. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2543. $lecturerList = $lecturer->getLecturerAll ();
  2544. $INSIDEhtml = $OUTSIDEhtml = '';
  2545. foreach ( $lecturerList as $key => $value ) {
  2546. if ($value ['ltype'] == 'INSIDE') {
  2547. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2548. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2549. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2550. }
  2551. }
  2552. $data ['INSIDEhtml'] = $INSIDEhtml;
  2553. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2554. // print_r($RItemList);
  2555. $data ['RILecturerList'] = $RILecturerList;
  2556. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2557. $data ['receiptDetail'] = $receiptDetail;
  2558. $data ['trainEdiType'] = "LECTURER";
  2559. $data ['ridKey'] = $ridKey;
  2560. $data ['memu'] = "receipt";
  2561. $data ['staff'] = $this->staff;
  2562. $data ['receiptMemu'] = 'saeaBorad';
  2563. $data ['verifyId'] = $this->verifyId;
  2564. $data ['executeId'] = $this->executeId;
  2565. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2566. }
  2567. /**
  2568. * 添加讲师
  2569. */
  2570. function receiptTrainLecturerAddDo() {
  2571. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2572. // 支出项信息
  2573. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2574. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2575. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2576. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2577. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2578. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2579. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2580. Doo::loadClass ( 'XDeode' );
  2581. $XDeode = new XDeode ( 5 );
  2582. Doo::loadModel ( 'RILecturer' );
  2583. $RILecturer = new RILecturer ();
  2584. $rid = $XDeode->decode ( $ridKey );
  2585. if (! is_numeric ( $rid ))
  2586. die ( 'illegal request' );
  2587. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2588. die ( 'illegal request-taxationError' );
  2589. $RILecturer->rid = $rid;
  2590. $RILecturer->ltype = $ltype;
  2591. if ($ltype == 'OUTSIDE') {
  2592. if ($taxation == 'TAXATION') {
  2593. $RILecturer->taxation = 1;
  2594. } elseif ($taxation == 'NOTAXATION') {
  2595. $RILecturer->taxation = 0;
  2596. }
  2597. }
  2598. $RILecturer->lecturerName = $lecturerName;
  2599. $RILecturer->schoolDay = $schoolDay;
  2600. $RILecturer->price = $price;
  2601. $RILecturer->fees=$fees;
  2602. $RILecturer->insert ();
  2603. // 添加公司汇总
  2604. // 报销详情
  2605. Doo::loadModel ( 'receiptDetail' );
  2606. $receiptDetail = new receiptDetail ();
  2607. Doo::loadModel ( 'receipt' );
  2608. $receipt = new receipt ();
  2609. // 金额总计
  2610. $price = $price * $schoolDay;
  2611. $rInfo = $receipt->getReceiptByRid ( $rid );
  2612. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2613. if (empty ( $rdInfo )) {
  2614. $receiptDetail = new receiptDetail ();
  2615. $receiptDetail->staff = $rInfo ['staff'];
  2616. $receiptDetail->item = '讲课费';
  2617. $receiptDetail->itemCategory = '培训班费用';
  2618. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2619. $receiptDetail->date = date ( "Y-m-d" );
  2620. $receiptDetail->cid = $rInfo ['cid'];
  2621. $receiptDetail->rid = $rid;
  2622. $receiptDetail->status = 4;
  2623. $receiptDetail->insert ();
  2624. } else {
  2625. $receiptDetail = new receiptDetail ();
  2626. $rdInfo ['price'] += $fees;
  2627. $receiptDetail->price = $rdInfo ['price'];
  2628. $receiptDetail->update ( array (
  2629. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2630. ) );
  2631. }
  2632. $receipt = new receipt ();
  2633. $receipt->sum=$rInfo['sum']+$fees;
  2634. $receipt->update ( array (
  2635. 'where' => 'rid=' . $rid
  2636. ) );
  2637. $XDeode = new XDeode ( 7 );
  2638. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2639. } else
  2640. die ( 'illegal request' );
  2641. }
  2642. /**
  2643. * 移除讲师
  2644. */
  2645. function receiptTrainLecturerDelDo() {
  2646. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2647. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2648. Doo::loadModel ( 'receipt' );
  2649. $receipt = new receipt ();
  2650. Doo::loadModel ( 'RILecturer' );
  2651. $RILecturer = new RILecturer ();
  2652. Doo::loadClass ( 'XDeode' );
  2653. $XDeode = new XDeode ( 5 );
  2654. $rid = $XDeode->decode ( $ridKey );
  2655. $rlid = $XDeode->decode ( $rlidKey );
  2656. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2657. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2658. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2659. die ( 'illegal request-status' );
  2660. }
  2661. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2662. if (empty($detail)){
  2663. die ( 'illegal request-data' );
  2664. }
  2665. $RILecturer->delete ( array (
  2666. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2667. ) );
  2668. //更新费用合计金额
  2669. $rInfo = $receipt->getReceiptByRid ( $rid );
  2670. $receipt = new receipt ();
  2671. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2672. $receipt->update ( array (
  2673. 'where' => 'rid=' . $rid
  2674. ) );
  2675. Doo::loadModel ( 'receiptDetail' );
  2676. $receiptDetail = new receiptDetail ();
  2677. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2678. $receiptDetail = new receiptDetail ();
  2679. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2680. $receiptDetail->price = $rdInfo ['price'];
  2681. $receiptDetail->update ( array (
  2682. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2683. ) );
  2684. $XDeode = new XDeode ( 7 );
  2685. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2686. } else
  2687. die ( 'illegal request-iid' );
  2688. }
  2689. /**
  2690. * 培训班提交审批
  2691. */
  2692. function receiptTrainDo() {
  2693. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2694. Doo::loadClass ( 'XDeode' );
  2695. $XDeode = new XDeode ( 7 );
  2696. $rid = $XDeode->decode ( $ridKey );
  2697. Doo::loadModel ( 'receipt' );
  2698. $receipt = new receipt ();
  2699. Doo::loadModel ( 'receiptDetail' );
  2700. $receiptDetail = new receiptDetail ();
  2701. Doo::loadModel ( 'statistics' );
  2702. $statistics = new statistics ();
  2703. Doo::loadModel ( "verify" );
  2704. $verify = new verify ();
  2705. // 审批状态的判定
  2706. $receiptDetailList = $receipt->getOne ( array (
  2707. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2708. 'asArray' => true
  2709. ) );
  2710. if (empty ( $receiptDetailList ))
  2711. return "/saeaBorad";
  2712. $verifyDetail = $verify->getOne ( array (
  2713. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2714. 'asArray' => true
  2715. ) );
  2716. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2717. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2718. $nowStaff = "";
  2719. $nowStaffList = array ();
  2720. if ($verifyDetail [0] [1] == 'ROLE') {
  2721. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2722. foreach ( $vStaffString as $key => $value ) {
  2723. $staffK = explode ( "_", $value );
  2724. array_push ( $nowStaffList, $staffK [0] );
  2725. }
  2726. $nowStaff = implode ( ',', $nowStaffList );
  2727. } else {
  2728. $nowStaff = $verifyDetail [0] [0];
  2729. }
  2730. $receipt->nowStaff = $nowStaff;
  2731. }
  2732. // echo $nowStaff;
  2733. // print_r($verifyDetail);die;
  2734. $receipt->rid = $receiptDetailList ['rid'];
  2735. $receipt->date = date ( "Y-m-d" );
  2736. $receipt->status = 2;
  2737. $receipt->update ();
  2738. $receiptDetail->status = 2;
  2739. $receiptDetail->update ( array (
  2740. 'where' => 'rid=' . $receiptDetailList ['rid']
  2741. ) );
  2742. Doo::loadModel ( "receiptLog" );
  2743. $receiptLog = new receiptLog ();
  2744. Doo::loadModel ( "verify" );
  2745. $verify = new verify ();
  2746. $vr = $verify->getOne ( array (
  2747. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2748. 'asArray' => true
  2749. ) );
  2750. $jd = json_decode ( $vr ['staff'] );
  2751. $roleId = 0;
  2752. foreach ( $jd as $key => $value ) {
  2753. if ($value [1] == 'ROLE') {
  2754. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2755. if ($pos !== false) {
  2756. $roleId = $value [0];
  2757. }
  2758. }
  2759. }
  2760. // 审批日志
  2761. // echo $roleId;die;
  2762. if (! empty ( $roleId )) {
  2763. Doo::loadModel ( "role" );
  2764. $role = new role ();
  2765. $roleInfo = $role->getOne ( array (
  2766. 'where' => 'rid=' . $roleId,
  2767. 'asArray' => true
  2768. ) );
  2769. // $receiptLog->rolename = $roleInfo ['name'];
  2770. }
  2771. $receiptLog->username = $this->staff [0] ['username'];
  2772. $receiptLog->uid = $this->staff [0] ['sid'];
  2773. $receiptLog->date = date ( "Y-m-d" );
  2774. $receiptLog->opinion = '提交审批';
  2775. $receiptLog->img = $this->staff [0] ['avatar'];
  2776. $receiptLog->status = 2;
  2777. $receiptLog->rid = $rid;
  2778. $receiptLog->insert ();
  2779. // 写入列表项
  2780. Doo::loadModel ( 'accountItem' );
  2781. $accountItem = new accountItem ();
  2782. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2783. // 项目金额合计
  2784. Doo::loadModel ( 'RItem' );
  2785. $RItem = new RItem ();
  2786. // 讲师获得
  2787. Doo::loadModel ( 'RILecturer' );
  2788. $RILecturer = new RILecturer ();
  2789. $RItemList = $RItem->getRItemByRid ( $rid );
  2790. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2791. // 支出项金额详情
  2792. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2793. // print_r($aItem);
  2794. // print_r($aiData);
  2795. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2796. $ag = $tr = $ta = $ot = 0;
  2797. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2798. foreach ( $aItem as $key => $value ) {
  2799. if ($value ['category'] == $this->TRAIN) {
  2800. foreach ( $aiData ['dataList'] as $k => $v ) {
  2801. if ($value ['name'] == $v ['name']) {
  2802. array_push ( $accountJson [$this->TRAIN], array (
  2803. 'aid' => $value ['aid'],
  2804. 'name' => $value ['name'],
  2805. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2806. ) );
  2807. $sum += $v ['price'];
  2808. $trainSum += $v ['price'];
  2809. unset ( $aiData ['dataList'] [$k] );
  2810. break;
  2811. }
  2812. }
  2813. }
  2814. }
  2815. $accountJson ['cSum'] = array (
  2816. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2817. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2818. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2819. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2820. );
  2821. // 报销单
  2822. $receipt = new receipt ();
  2823. $receipt->accountItem = json_encode ( $accountJson );
  2824. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2825. $receipt->update ( array (
  2826. 'where' => 'rid=' . $rid
  2827. ) );
  2828. // print_r($accountJson);
  2829. // statistics item 统计写入
  2830. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2831. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2832. $accountItem = $accountJson;
  2833. $stat = $statistics->getOne ( array (
  2834. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2835. 'asArray' => true
  2836. ) );
  2837. if (empty ( $stat )) {
  2838. $statistics->date = date ( "Y-m-d" );
  2839. $statistics->cid = $this->staff [0] ['cid'];
  2840. $statistics->staff = $this->staff [0] ['sid'];
  2841. $statistics->agPrice = 0;
  2842. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2843. $statistics->insert ();
  2844. } else {
  2845. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2846. $statistics->update ( array (
  2847. 'where' => 'sid=' . $stat ['sid']
  2848. ) );
  2849. }
  2850. return "/saeaBorad";
  2851. }
  2852. function confirmation() {
  2853. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2854. Doo::loadModel ( 'receipt' );
  2855. Doo::loadModel ( 'receiptDetail' );
  2856. $receipt = new receipt ();
  2857. $receiptDetail = new receiptDetail ();
  2858. Doo::loadModel ( 'statistics' );
  2859. Doo::loadModel ( 'itemStatistics' );
  2860. $statistics = new statistics ();
  2861. $itemStatistics = new itemStatistics ();
  2862. Doo::loadModel ( "verify" );
  2863. $verify = new verify ();
  2864. $receiptDetailList = $receipt->getOne ( array (
  2865. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2866. 'asArray' => true
  2867. ) );
  2868. if (empty ( $receiptDetailList ))
  2869. return "/saeaBorad";
  2870. $verifyDetail = $verify->getOne ( array (
  2871. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2872. 'asArray' => true
  2873. ) );
  2874. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2875. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2876. $nowStaff = "";
  2877. $nowStaffList = array ();
  2878. if ($verifyDetail [0] [1] == 'ROLE') {
  2879. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2880. foreach ( $vStaffString as $key => $value ) {
  2881. $staffK = explode ( "_", $value );
  2882. array_push ( $nowStaffList, $staffK [0] );
  2883. }
  2884. $nowStaff = implode ( ',', $nowStaffList );
  2885. } else {
  2886. $nowStaff = $verifyDetail [0] [0];
  2887. }
  2888. $receipt->nowStaff = $nowStaff;
  2889. }
  2890. // echo $nowStaff;
  2891. // print_r($verifyDetail);die;
  2892. $receipt->rid = $receiptDetailList ['rid'];
  2893. $receipt->status = 2;
  2894. $receipt->update ();
  2895. // 操作日志
  2896. Doo::loadModel ( "receiptLog" );
  2897. $receiptLog = new receiptLog ();
  2898. $verify = new verify ();
  2899. $receiptInfo = $receipt->getOne ( array (
  2900. 'where' => 'rid=' . $rid,
  2901. 'asArray' => true
  2902. ) );
  2903. $vr = $verify->getOne ( array (
  2904. 'where' => 'vid=' . $receiptInfo ['verify'],
  2905. 'asArray' => true
  2906. ) );
  2907. $jd = json_decode ( $vr ['staff'] );
  2908. $roleId = 0;
  2909. foreach ( $jd as $key => $value ) {
  2910. if ($value [1] == 'ROLE') {
  2911. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2912. if ($pos !== false) {
  2913. $roleId = $value [0];
  2914. }
  2915. }
  2916. }
  2917. // 审批日志
  2918. // echo $roleId;die;
  2919. if (! empty ( $roleId )) {
  2920. Doo::loadModel ( "role" );
  2921. $role = new role ();
  2922. $roleInfo = $role->getOne ( array (
  2923. 'where' => 'rid=' . $roleId,
  2924. 'asArray' => true
  2925. ) );
  2926. // $receiptLog->rolename = $roleInfo ['name'];
  2927. }
  2928. $receiptLog->username = $this->staff [0] ['username'];
  2929. $receiptLog->uid = $this->staff [0] ['sid'];
  2930. $receiptLog->date = date ( "Y-m-d" );
  2931. $receiptLog->opinion = '提交审批';
  2932. $receiptLog->img = $this->staff [0] ['avatar'];
  2933. $receiptLog->status = 2;
  2934. $receiptLog->rid = $rid;
  2935. $receiptLog->insert ();
  2936. return "/expenses";
  2937. }
  2938. function expenses() {
  2939. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2940. if (empty ( $item ))
  2941. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2942. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2943. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2944. Doo::loadClass ( 'XDeode' );
  2945. $XDeode = new XDeode ( 7 );
  2946. Doo::loadModel ( 'receipt' );
  2947. $receipt = new receipt ();
  2948. Doo::loadModel ( 'L_category' );
  2949. $Lcategory = new L_category ();
  2950. Doo::loadModel ( 'verify' );
  2951. Doo::loadModel ( 'statistics' );
  2952. $statistics = new statistics ();
  2953. $verify = new verify ();
  2954. Doo::loadModel ( 'staff' );
  2955. $staff = new staff ();
  2956. $condition = "";
  2957. if ($item == "expenses")
  2958. $condition = " and Rtype=1 ";
  2959. elseif ($item == "receipts")
  2960. $condition = " and Rtype=0 ";
  2961. elseif ($item == "remits")
  2962. $condition = " and Rtype=2 ";
  2963. elseif ($item == "train")
  2964. $condition = " and Rtype=3 ";
  2965. $dateCondition = " and Year(date) =" . $year;
  2966. if (! empty ( $moth )) {
  2967. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2968. $stList = $statistics->getOne ( array (
  2969. 'select' => 'rePrice ,agPrice',
  2970. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2971. 'asArray' => true
  2972. ) );
  2973. } else
  2974. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2975. if (empty ( $stList ))
  2976. $stList = array (
  2977. 'rePrice' => 0,
  2978. 'agPrice' => 0
  2979. );
  2980. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2981. if (! isset ( $noPassSum ['sum'] ))
  2982. $noPassSum ['sum'] = 0;
  2983. $data ['stList'] = array (
  2984. 'rePrice' => $stList ['rePrice'],
  2985. 'agPrice' => $stList ['agPrice'],
  2986. 'skPrice' => ($noPassSum ['sum'])
  2987. );
  2988. $receiptList = $receipt->find ( array (
  2989. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2990. 'desc' => 'rid',
  2991. 'asArray' => true
  2992. ) );
  2993. $Locate = 0;
  2994. $roleId = 0;
  2995. $button = 0;
  2996. foreach ( $receiptList as $key => $value ) {
  2997. $receiptList[$key]['balance']='';
  2998. if($value['Rtype']==1){
  2999. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3000. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3001. }elseif($value['Rtype']==3){
  3002. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3003. $receiptList[$key]['payment']=$payment;
  3004. $receiptList[$key]['paymentABS']=abs($payment);
  3005. }
  3006. $receiptList [$key] ['Locate'] = $Locate;
  3007. $Locate ++;
  3008. $receiptList [$key] ['reviseDetail'] = array ();
  3009. if (! empty ( $value ['reviseDetail'] ))
  3010. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3011. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3012. $categoryDetil = $Lcategory->getOne ( array (
  3013. 'where' => 'cid=' . $value ['cid'],
  3014. 'asArray' => true
  3015. ) );
  3016. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3017. // 检测编辑状态
  3018. $verifyList = $verify->getOne ( array (
  3019. 'where' => 'vid=' . $value ['verify'],
  3020. 'asArray' => true
  3021. ) );
  3022. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3023. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3024. Doo::loadModel ( 'role' );
  3025. $role = new role ();
  3026. $flag = true;
  3027. $roleKey = 0;
  3028. $endStaffArray = array ();
  3029. $roleArrayCopy = array ();
  3030. foreach ( $verifyList as $k => $v ) {
  3031. // init verifyStaff
  3032. if ($v [1] == 'ROLE') {
  3033. if (! empty ( $verifyStaff )) {
  3034. $endStaffArray = end ( $verifyStaff );
  3035. // if ($v[0]==$endStaffArray['nextStaff']){
  3036. // $roleId=$v[0];
  3037. // }
  3038. }
  3039. $roleVerify = json_decode ( $v [3], true );
  3040. $roleKey = $k;
  3041. $roleArray = array ();
  3042. $rolename = $role->getOne ( array (
  3043. 'where' => 'rid=' . $v [0],
  3044. 'asArray' => true
  3045. ) );
  3046. foreach ( $roleVerify as $o => $p ) {
  3047. $staffID = explode ( '_', $p );
  3048. $staffInfo = $staff->getOne ( array (
  3049. 'where' => 'sid=' . $staffID [0],
  3050. 'asArray' => true
  3051. ) );
  3052. // print_r($staffID);
  3053. $exp = array (
  3054. 0 => $staffInfo ['sid'],
  3055. 1 => $staffID [1],
  3056. 2 => $staffInfo ['avatar'],
  3057. 'date' => '',
  3058. 'date' => '',
  3059. 'opinion' => '',
  3060. 'status' => '',
  3061. 'rolename' => $rolename ['name']
  3062. );
  3063. array_push ( $roleArray, $exp );
  3064. }
  3065. $roleArrayCopy [$v [0]] = $roleArray;
  3066. // $verifyList[$k]['roleArray']=$roleArray;
  3067. }
  3068. $verifyList [$k] ['date'] = "";
  3069. $verifyList [$k] ['opinion'] = "";
  3070. $verifyList [$k] ['status'] = "";
  3071. if (empty ( $verifyStaff )) {
  3072. $verifyList [$k] ['date'] = "";
  3073. $verifyList [$k] ['opinion'] = "";
  3074. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3075. $verifyList [$k] ['status'] = 4;
  3076. $flag = false;
  3077. }
  3078. } else {
  3079. foreach ( $verifyStaff as $m => $u ) {
  3080. if ($v [0] == $m) {
  3081. $verifyList [$k] ['date'] = $u ['date'];
  3082. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3083. $verifyList [$k] ['status'] = $u ['status'];
  3084. $flag = false;
  3085. break;
  3086. }
  3087. }
  3088. $endStaffArray = end ( $verifyStaff );
  3089. if (isset ( $endStaffArray ['ROLE'] )) {
  3090. } else {
  3091. // $endKey=key($verifyStaff);
  3092. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3093. // $button=4;
  3094. // $verifyList[$k]['status']=4;
  3095. // }
  3096. }
  3097. }
  3098. }
  3099. $rolename ['name'] = '';
  3100. if (! empty ( $roleId )) {
  3101. Doo::loadModel ( 'role' );
  3102. $role = new role ();
  3103. $rolename = $role->getOne ( array (
  3104. 'where' => 'rid=' . $roleId,
  3105. 'asArray' => true
  3106. ) );
  3107. }
  3108. if (! empty ( $verifyStaff ))
  3109. $endStaffArray = end ( $verifyStaff );
  3110. $KOP = false;
  3111. foreach ( $roleArrayCopy as $P => $A ) {
  3112. foreach ( $A as $MKI => $AVL ) {
  3113. if (! empty ( $verifyStaff )) {
  3114. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3115. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3116. $button = 4;
  3117. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3118. }
  3119. foreach ( $verifyStaff as $m => $u ) {
  3120. $AVLFK = $AVL [0] . '_R';
  3121. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3122. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3123. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3124. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3125. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3126. break;
  3127. }
  3128. }
  3129. } else {
  3130. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3131. $button = 4;
  3132. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3133. }
  3134. }
  3135. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3136. $KOP = true;
  3137. }
  3138. }
  3139. foreach ( $roleArrayCopy as $k => $v ) {
  3140. foreach ( $verifyList as $m => $n ) {
  3141. if ($n [0] == $k) {
  3142. array_splice ( $verifyList, $m, 1, $v );
  3143. }
  3144. }
  3145. }
  3146. $receiptList [$key] ['verifyList'] = $verifyList;
  3147. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3148. 'where' => 'sid=' . $value ['staff'],
  3149. 'asArray' => true
  3150. ) );
  3151. $receiptList [$key] ['button'] = $button;
  3152. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3153. }
  3154. // print_r($receiptList);die;
  3155. $mothHtml = "";
  3156. for($i = 1; $i <= 12; $i ++) {
  3157. if ($moth == $i)
  3158. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3159. else
  3160. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3161. }
  3162. $dateHtml = "";
  3163. $now = date ( "Y" );
  3164. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3165. if ($YEARD <= $now) {
  3166. $dateHtml .= '<option ';
  3167. if ($year == $YEARD) {
  3168. $dateHtml .= 'selected ';
  3169. }
  3170. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3171. }
  3172. }
  3173. $data ['dateHtml'] = $dateHtml;
  3174. $data ['mothHtml'] = $mothHtml;
  3175. $data ['receiptList'] = $receiptList;
  3176. $data ['memu'] = "receipt";
  3177. $data ['staff'] = $this->staff;
  3178. $data ['receiptMemu'] = 'expenses';
  3179. $data ['verifyId'] = $this->verifyId;
  3180. $data ['executeId'] = $this->executeId;
  3181. $data ['item'] = $item;
  3182. $data ['year'] = $year;
  3183. $this->render ( "/admin/expenses", $data );
  3184. }
  3185. function expensesCollect() {
  3186. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3187. Doo::loadModel ( 'receipt' );
  3188. $receipt = new receipt ();
  3189. Doo::loadModel ( 'L_category' );
  3190. $Lcategory = new L_category ();
  3191. Doo::loadModel ( 'verify' );
  3192. Doo::loadModel ( 'statistics' );
  3193. $statistics = new statistics ();
  3194. $verify = new verify ();
  3195. Doo::loadModel ( 'staff' );
  3196. $staff = new staff ();
  3197. Doo::loadModel ( 'loanReceipt' );
  3198. $loanReceipt = new loanReceipt ();
  3199. $receiptList = $receipt->find ( array (//去掉
  3200. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3201. 'desc' => 'rid',
  3202. 'asArray' => true
  3203. ) );
  3204. $loanList = $loanReceipt->find ( array (
  3205. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3206. 'desc' => 'rid',
  3207. 'asArray' => true
  3208. ) );
  3209. /*
  3210. * $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;
  3211. */
  3212. $data ['explanation'] = '';
  3213. if (! empty ( $loanList ))
  3214. $data ['explanation'] = $loanList [0] ['explanation'];
  3215. $Locate = 0;
  3216. $roleId = 0;
  3217. $button = 0;
  3218. foreach ( $receiptList as $key => $value ) {
  3219. $receiptList [$key] ['Locate'] = $Locate;
  3220. $Locate ++;
  3221. $receiptList [$key] ['reviseDetail'] = array ();
  3222. if (! empty ( $value ['reviseDetail'] ))
  3223. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3224. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3225. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3226. $categoryDetil = $Lcategory->getOne ( array (
  3227. 'where' => 'cid=' . $value ['cid'],
  3228. 'asArray' => true
  3229. ) );
  3230. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3231. // 检测编辑状态
  3232. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3233. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3234. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3235. else
  3236. $verifyList ['staff'] = $value ['verifyBreakup'];
  3237. } else
  3238. $verifyList = $verify->getOne ( array (
  3239. 'where' => 'vid=' . $value ['verify'],
  3240. 'asArray' => true
  3241. ) );
  3242. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3243. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3244. Doo::loadModel ( 'role' );
  3245. $role = new role ();
  3246. $flag = true;
  3247. $roleKey = 0;
  3248. $endStaffArray = array ();
  3249. $roleArrayCopy = array ();
  3250. foreach ( $verifyList as $k => $v ) {
  3251. // init verifyStaff
  3252. if ($v [1] == 'ROLE') {
  3253. if (! empty ( $verifyStaff )) {
  3254. $endStaffArray = end ( $verifyStaff );
  3255. // if ($v[0]==$endStaffArray['nextStaff']){
  3256. // $roleId=$v[0];
  3257. // }
  3258. }
  3259. $roleVerify = json_decode ( $v [3], true );
  3260. $roleKey = $k;
  3261. $roleArray = array ();
  3262. $rolename = $role->getOne ( array (
  3263. 'where' => 'rid=' . $v [0],
  3264. 'asArray' => true
  3265. ) );
  3266. foreach ( $roleVerify as $o => $p ) {
  3267. $staffID = explode ( '_', $p );
  3268. $staffInfo = $staff->getOne ( array (
  3269. 'where' => 'sid=' . $staffID [0],
  3270. 'asArray' => true
  3271. ) );
  3272. // print_r($staffID);
  3273. $exp = array (
  3274. 0 => $staffInfo ['sid'],
  3275. 1 => $staffID [1],
  3276. 2 => $staffInfo ['avatar'],
  3277. 'date' => '',
  3278. 'date' => '',
  3279. 'opinion' => '',
  3280. 'status' => '',
  3281. 'rolename' => $rolename ['name']
  3282. );
  3283. array_push ( $roleArray, $exp );
  3284. }
  3285. $roleArrayCopy [$v [0]] = $roleArray;
  3286. // $verifyList[$k]['roleArray']=$roleArray;
  3287. }
  3288. $verifyList [$k] ['date'] = "";
  3289. $verifyList [$k] ['opinion'] = "";
  3290. $verifyList [$k] ['status'] = "";
  3291. if (empty ( $verifyStaff )) {
  3292. $verifyList [$k] ['date'] = "";
  3293. $verifyList [$k] ['opinion'] = "";
  3294. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3295. $verifyList [$k] ['status'] = 4;
  3296. $flag = false;
  3297. }
  3298. } else {
  3299. foreach ( $verifyStaff as $m => $u ) {
  3300. if ($v [0] == $m) {
  3301. $verifyList [$k] ['date'] = $u ['date'];
  3302. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3303. $verifyList [$k] ['status'] = $u ['status'];
  3304. $flag = false;
  3305. break;
  3306. }
  3307. }
  3308. $endStaffArray = end ( $verifyStaff );
  3309. if (isset ( $endStaffArray ['ROLE'] )) {
  3310. } else {
  3311. // $endKey=key($verifyStaff);
  3312. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3313. // $button=4;
  3314. // $verifyList[$k]['status']=4;
  3315. // }
  3316. }
  3317. }
  3318. }
  3319. $rolename ['name'] = '';
  3320. if (! empty ( $roleId )) {
  3321. Doo::loadModel ( 'role' );
  3322. $role = new role ();
  3323. $rolename = $role->getOne ( array (
  3324. 'where' => 'rid=' . $roleId,
  3325. 'asArray' => true
  3326. ) );
  3327. }
  3328. if (! empty ( $verifyStaff ))
  3329. $endStaffArray = end ( $verifyStaff );
  3330. $KOP = false;
  3331. foreach ( $roleArrayCopy as $P => $A ) {
  3332. foreach ( $A as $MKI => $AVL ) {
  3333. if (! empty ( $verifyStaff )) {
  3334. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3335. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3336. $button = 4;
  3337. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3338. }
  3339. foreach ( $verifyStaff as $m => $u ) {
  3340. $AVLFK = $AVL [0] . '_R';
  3341. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3342. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3343. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3344. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3345. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3346. break;
  3347. }
  3348. }
  3349. } else {
  3350. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3351. $button = 4;
  3352. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3353. }
  3354. }
  3355. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3356. $KOP = true;
  3357. }
  3358. }
  3359. foreach ( $roleArrayCopy as $k => $v ) {
  3360. foreach ( $verifyList as $m => $n ) {
  3361. if ($n [0] == $k) {
  3362. array_splice ( $verifyList, $m, 1, $v );
  3363. }
  3364. }
  3365. }
  3366. // 费用执行人相关数据
  3367. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3368. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3369. foreach ( $executeCopy as $k => $v ) {
  3370. $executeCopy [$k] ['date'] = '';
  3371. $executeCopy [$k] ['opinion'] = '';
  3372. $executeCopy [$k] ['status'] = '';
  3373. if (! empty ( $executeStaff ))
  3374. foreach ( $executeStaff as $m => $u ) {
  3375. if ($v [0] == $m) {
  3376. $executeCopy [$k] ['date'] = $u ['date'];
  3377. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3378. $executeCopy [$k] ['status'] = $u ['status'];
  3379. break;
  3380. }
  3381. }
  3382. }
  3383. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3384. $receiptList [$key] ['verifyList'] = $verifyList;
  3385. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3386. 'where' => 'sid=' . $value ['staff'],
  3387. 'asArray' => true
  3388. ) );
  3389. $receiptList [$key] ['button'] = $button;
  3390. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3391. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3392. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3393. $receiptList [$key] ['relust'] = $relust;
  3394. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3395. }
  3396. Doo::loadModel ( 'enclosur' );
  3397. $enclosur = new enclosur ();
  3398. $enclosurList = $enclosur->find ( array (
  3399. 'where' => 'rid=' . $rid,
  3400. 'asArray' => true
  3401. ) );
  3402. $enclosurHtml = '';
  3403. foreach ( $enclosurList as $value ) {
  3404. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3405. }
  3406. $data ['enclosurHtml'] = $enclosurHtml;
  3407. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3408. $data ['receiptList'] = $receiptList;
  3409. $data ['memu'] = "receipt";
  3410. $data ['staff'] = $this->staff;
  3411. $data ['receiptMemu'] = 'expenses';
  3412. $data ['verifyId'] = $this->verifyId;
  3413. $data ['executeId'] = $this->executeId;
  3414. $this->render ( "/admin/expensesCollect", $data );
  3415. }
  3416. function approvalExpenses() {
  3417. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3418. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3419. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3420. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3421. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3422. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3423. // echo $rdate;
  3424. if (empty ( $status ))
  3425. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3426. $page_size = 8;
  3427. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3428. $vidList = array ();
  3429. $button = 0;
  3430. Doo::loadModel ( 'verify' );
  3431. $verify = new verify ();
  3432. Doo::loadModel ( 'receipt' );
  3433. $receipt = new receipt ();
  3434. Doo::loadModel ( 'staff' );
  3435. $staff = new staff ();
  3436. Doo::loadModel ( 'L_category' );
  3437. $Lcategory = new L_category ();
  3438. // user verify ID
  3439. $verifyDetail = $verify->find ( array (
  3440. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3441. 'asArray' => true
  3442. ) );
  3443. foreach ( $verifyDetail as $key => $value ) {
  3444. array_push ( $vidList, $value ['vid'] );
  3445. }
  3446. $vid = implode ( ",", $vidList );
  3447. if (empty ( $verifyDetail ))
  3448. $vid = 0;
  3449. // if ($status==0)
  3450. // $dateCondition="";
  3451. // else
  3452. $dateCondition = " ";
  3453. // if (! empty ( $month ))
  3454. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3455. if ($status == 'done' || $status == 'termination') {
  3456. if (! empty ( $year )) {
  3457. $dateCondition = " and Year(pastDate) =" . $year;
  3458. if (! empty ( $month ))
  3459. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3460. }
  3461. } elseif ($status == 'finish') {
  3462. if (! empty ( $year )) {
  3463. $dateCondition = " and Year(pastDate) =" . $year;
  3464. if (! empty ( $month ))
  3465. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3466. }
  3467. }
  3468. // date ( 'Y-m' )
  3469. // if (! empty ( $rdate ) && $status == 'done')
  3470. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3471. // elseif (! empty ( $rdate ))
  3472. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3473. $categoryList = $Lcategory->find ( array (
  3474. 'asArray' => true
  3475. ) );
  3476. $staffList = $staff->find ( array (
  3477. 'where' => 'cid=' . $cid,
  3478. 'asArray' => true
  3479. ) );
  3480. $cateCondition = "";
  3481. $staffCondition = "";
  3482. $approvalCondition = "";
  3483. if (! empty ( $cid )) {
  3484. $cateCondition = ' and cid=' . $cid;
  3485. }
  3486. if (! empty ( $sid )) {
  3487. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3488. $cateCondition = "";
  3489. }
  3490. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3491. if ($status == 'pendApproval') {
  3492. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3493. }
  3494. if ($status == 'ongoing') {
  3495. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3496. }
  3497. if ($status == 'done') {
  3498. $approvalCondition = ' and (status=8 or status=9 ) ';
  3499. }
  3500. if ($status == 'termination') {
  3501. $approvalCondition = " and status=3";
  3502. }
  3503. if ($status == 'finish') {
  3504. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3505. }
  3506. $pageinfo ['page'] = array (
  3507. 'previous' => ''
  3508. );
  3509. if(!empty($receiptOrder)){
  3510. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3511. $receiptList = $receipt->find ( array ( // $dateCondition
  3512. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3513. 'desc' => 'rid',
  3514. 'asArray' => true
  3515. ) );
  3516. }else{
  3517. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3518. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3519. $receiptList = $receipt->find ( array ( // $dateCondition.
  3520. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3521. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3522. 'desc' => 'rid',
  3523. 'asArray' => true
  3524. ) );
  3525. } else {
  3526. $receiptList = $receipt->find ( array ( // $dateCondition
  3527. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3528. 'desc' => 'rid',
  3529. 'asArray' => true
  3530. ) );
  3531. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3532. }
  3533. }
  3534. $rLRes = $receipt->find ( array (
  3535. '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 . ')',
  3536. 'desc' => 'rid',
  3537. 'asArray' => true
  3538. ) );
  3539. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3540. // print_r($receiptList);
  3541. Doo::loadClass ( 'XDeode' );
  3542. $XDeode = new XDeode ( 7 );
  3543. $Locate = 0;
  3544. $reportList = $reportCateList = array ();
  3545. foreach ( $receiptList as $key => $value ) {
  3546. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3547. $receiptList [$key] ['Locate'] = $Locate;
  3548. $Locate ++;
  3549. $receiptList [$key] ['reviseDetail'] = array ();
  3550. if (! empty ( $value ['reviseDetail'] ))
  3551. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3552. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3553. $categoryDetil = $Lcategory->getOne ( array (
  3554. 'where' => 'cid=' . $value ['cid'],
  3555. 'asArray' => true
  3556. ) );
  3557. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3558. $verifyList = $verify->getOne ( array (
  3559. 'where' => 'vid=' . $value ['verify'],
  3560. 'asArray' => true
  3561. ) );
  3562. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3563. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3564. foreach ( $verifyList as $k => $v ) {
  3565. // init verifyStaff
  3566. $verifyList [$k] ['date'] = "";
  3567. $verifyList [$k] ['opinion'] = "";
  3568. $verifyList [$k] ['status'] = "";
  3569. if (empty ( $verifyStaff )) {
  3570. $verifyList [$k] ['date'] = "";
  3571. $verifyList [$k] ['opinion'] = "";
  3572. if ($v [0] == $this->staff [0] ['sid']) {
  3573. $verifyList [$k] ['status'] = 4;
  3574. $button = 4;
  3575. }
  3576. } else {
  3577. $flag = true;
  3578. foreach ( $verifyStaff as $m => $u ) {
  3579. if ($v [0] == $m) {
  3580. $verifyList [$k] ['date'] = $u ['date'];
  3581. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3582. $verifyList [$k] ['status'] = $u ['status'];
  3583. $flag = false;
  3584. break;
  3585. }
  3586. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3587. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3588. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3589. }
  3590. if ($flag) { // 检测可编辑
  3591. if ($v [0] == $this->staff [0] ['sid']) {
  3592. $verifyList [$k] ['status'] = 4;
  3593. $button = 4;
  3594. }
  3595. }
  3596. }
  3597. }
  3598. $receiptList [$key] ['verifyList'] = $verifyList;
  3599. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3600. 'where' => 'sid=' . $value ['staff'],
  3601. 'asArray' => true
  3602. ) );
  3603. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3604. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3605. $receiptList [$key] ['button'] = $button;
  3606. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3607. //获得培训班结算RID 借款费用--已经锁定
  3608. if($value['status']==10){
  3609. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  3610. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  3611. }
  3612. }
  3613. $reportList = array_unique ( $reportList );
  3614. $reportHtml = '';
  3615. foreach ( $reportList as $key => $value ) {
  3616. $v = explode ( "-", $value );
  3617. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3618. }
  3619. // print_r($reportList)
  3620. $data ['reportHtml'] = $reportHtml;
  3621. $reportCateList = array_unique ( $reportCateList );
  3622. $reportCateHtml = '';
  3623. foreach ( $reportCateList as $key => $value ) {
  3624. $v = explode ( "-", $value );
  3625. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3626. }
  3627. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3628. $data ['reportCateHtml'] = $reportCateHtml;
  3629. // print_r($receiptList);die;
  3630. // $data['verifyDetail']=$verifyDetail;
  3631. $mothHtml = "";
  3632. for($i = 1; $i <= 12; $i ++) {
  3633. if ($month == $i)
  3634. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3635. else
  3636. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3637. }
  3638. $data ['mothHtml'] = $mothHtml;
  3639. $dateHtml = "";
  3640. $now = date ( "Y" );
  3641. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3642. if ($YEARD <= $now) {
  3643. $dateHtml .= '<option ';
  3644. if ($year == $YEARD) {
  3645. $dateHtml .= 'selected ';
  3646. }
  3647. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3648. }
  3649. }
  3650. $data ['dateHtml'] = $dateHtml;
  3651. $data ['page'] = $pageinfo;
  3652. $data ['receiptList'] = $receiptList;
  3653. $data ['receiptApprovalCount'] = count ( $rLRes );
  3654. $data ['status'] = $status;
  3655. $data ['year'] = $year;
  3656. $data ['month'] = $month;
  3657. $data ['categoryList'] = $categoryList;
  3658. $data ['staffList'] = $staffList;
  3659. $data ['cid'] = $cid;
  3660. $data ['sid'] = $sid;
  3661. // print_r($receiptList);
  3662. $data['receiptOrder']=$receiptOrder;
  3663. $data ['memu'] = "receipt";
  3664. $data ['staff'] = $this->staff;
  3665. $data ['receiptMemu'] = 'approvalExpenses';
  3666. $data ['verifyId'] = $this->verifyId;
  3667. $data ['executeId'] = $this->executeId;
  3668. $this->render ( "/admin/approvalExpenses", $data );
  3669. }
  3670. function expensesDoc() {
  3671. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3672. Doo::loadClass ( 'XDeode' );
  3673. $XDeode = new XDeode ( 5 );
  3674. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3675. $rid = $XDeode->decode ( $rid );
  3676. if (! is_numeric ( $rid ))
  3677. die ( 'illegal request' );
  3678. Doo::loadModel ( 'receipt' );
  3679. $receipt = new receipt ();
  3680. Doo::loadModel ( 'L_category' );
  3681. $Lcategory = new L_category ();
  3682. Doo::loadModel ( 'verify' );
  3683. Doo::loadModel ( 'statistics' );
  3684. $statistics = new statistics ();
  3685. $verify = new verify ();
  3686. Doo::loadModel ( 'staff' );
  3687. $staff = new staff ();
  3688. Doo::loadModel ( 'loanReceipt' );
  3689. $loanReceipt = new loanReceipt ();
  3690. $receiptList = $receipt->find ( array (
  3691. 'where' => ' rid=' . $rid,
  3692. 'desc' => 'rid',
  3693. 'asArray' => true
  3694. ) );
  3695. $loanList = array ();
  3696. if (! empty ( $receiptList ))
  3697. $loanList = $loanReceipt->find ( array (
  3698. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3699. 'desc' => 'rid',
  3700. 'asArray' => true
  3701. ) );
  3702. $Locate = 0;
  3703. $roleId = 0;
  3704. $button = 0;
  3705. foreach ( $loanList as $key => $value ) {
  3706. $loanList [$key] ['Locate'] = $Locate;
  3707. $Locate ++;
  3708. $loanList [$key] ['reviseDetail'] = array ();
  3709. if (! empty ( $value ['reviseDetail'] ))
  3710. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3711. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3712. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3713. $categoryDetil = $Lcategory->getOne ( array (
  3714. 'where' => 'cid=' . $value ['cid'],
  3715. 'asArray' => true
  3716. ) );
  3717. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3718. // 检测编辑状态
  3719. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3720. $verifyList ['staff'] = $value ['verifyBreakup'];
  3721. else
  3722. $verifyList = $verify->getOne ( array (
  3723. 'where' => 'vid=' . $value ['verify'],
  3724. 'asArray' => true
  3725. ) );
  3726. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3727. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3728. Doo::loadModel ( 'role' );
  3729. $role = new role ();
  3730. $flag = true;
  3731. $roleKey = 0;
  3732. $endStaffArray = array ();
  3733. $roleArrayCopy = array ();
  3734. foreach ( $verifyList as $k => $v ) {
  3735. // init verifyStaff
  3736. if ($v [1] == 'ROLE') {
  3737. if (! empty ( $verifyStaff )) {
  3738. $endStaffArray = end ( $verifyStaff );
  3739. // if ($v[0]==$endStaffArray['nextStaff']){
  3740. // $roleId=$v[0];
  3741. // }
  3742. }
  3743. $roleVerify = json_decode ( $v [3], true );
  3744. $roleKey = $k;
  3745. $roleArray = array ();
  3746. $rolename = $role->getOne ( array (
  3747. 'where' => 'rid=' . $v [0],
  3748. 'asArray' => true
  3749. ) );
  3750. foreach ( $roleVerify as $o => $p ) {
  3751. $staffID = explode ( '_', $p );
  3752. $staffInfo = $staff->getOne ( array (
  3753. 'where' => 'sid=' . $staffID [0],
  3754. 'asArray' => true
  3755. ) );
  3756. // print_r($staffID);
  3757. $exp = array (
  3758. 0 => $staffInfo ['sid'],
  3759. 1 => $staffID [1],
  3760. 2 => $staffInfo ['avatar'],
  3761. 'date' => '',
  3762. 'date' => '',
  3763. 'opinion' => '',
  3764. 'status' => '',
  3765. 'rolename' => $rolename ['name']
  3766. );
  3767. array_push ( $roleArray, $exp );
  3768. }
  3769. $roleArrayCopy [$v [0]] = $roleArray;
  3770. // $verifyList[$k]['roleArray']=$roleArray;
  3771. }
  3772. $verifyList [$k] ['date'] = "";
  3773. $verifyList [$k] ['opinion'] = "";
  3774. $verifyList [$k] ['status'] = "";
  3775. if (empty ( $verifyStaff )) {
  3776. $verifyList [$k] ['date'] = "";
  3777. $verifyList [$k] ['opinion'] = "";
  3778. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3779. $verifyList [$k] ['status'] = 4;
  3780. $flag = false;
  3781. }
  3782. } else {
  3783. foreach ( $verifyStaff as $m => $u ) {
  3784. if ($v [0] == $m) {
  3785. $verifyList [$k] ['date'] = $u ['date'];
  3786. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3787. $verifyList [$k] ['status'] = $u ['status'];
  3788. $flag = false;
  3789. break;
  3790. }
  3791. }
  3792. $endStaffArray = end ( $verifyStaff );
  3793. if (isset ( $endStaffArray ['ROLE'] )) {
  3794. } else {
  3795. // $endKey=key($verifyStaff);
  3796. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3797. // $button=4;
  3798. // $verifyList[$k]['status']=4;
  3799. // }
  3800. }
  3801. }
  3802. }
  3803. $rolename ['name'] = '';
  3804. if (! empty ( $roleId )) {
  3805. Doo::loadModel ( 'role' );
  3806. $role = new role ();
  3807. $rolename = $role->getOne ( array (
  3808. 'where' => 'rid=' . $roleId,
  3809. 'asArray' => true
  3810. ) );
  3811. }
  3812. if (! empty ( $verifyStaff ))
  3813. $endStaffArray = end ( $verifyStaff );
  3814. $KOP = false;
  3815. foreach ( $roleArrayCopy as $P => $A ) {
  3816. foreach ( $A as $MKI => $AVL ) {
  3817. if (! empty ( $verifyStaff )) {
  3818. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3819. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3820. $button = 4;
  3821. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3822. }
  3823. foreach ( $verifyStaff as $m => $u ) {
  3824. $AVLFK = $AVL [0] . '_R';
  3825. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3826. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3827. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3828. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3829. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3830. break;
  3831. }
  3832. }
  3833. } else {
  3834. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3835. $button = 4;
  3836. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3837. }
  3838. }
  3839. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3840. $KOP = true;
  3841. }
  3842. }
  3843. foreach ( $roleArrayCopy as $k => $v ) {
  3844. foreach ( $verifyList as $m => $n ) {
  3845. if ($n [0] == $k) {
  3846. array_splice ( $verifyList, $m, 1, $v );
  3847. }
  3848. }
  3849. }
  3850. $loanList [$key] ['verifyList'] = $verifyList;
  3851. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3852. 'where' => 'sid=' . $value ['staff'],
  3853. 'asArray' => true
  3854. ) );
  3855. $loanList [$key] ['button'] = $button;
  3856. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3857. }
  3858. $data ['loanList'] = $loanList;
  3859. //print_r($loanList);
  3860. $Locate = 0;
  3861. $roleId = 0;
  3862. $button = 0;
  3863. foreach ( $receiptList as $key => $value ) {
  3864. $receiptList [$key] ['Locate'] = $Locate;
  3865. $Locate ++;
  3866. $receiptList [$key] ['reviseDetail'] = array ();
  3867. if (! empty ( $value ['reviseDetail'] ))
  3868. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3869. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3870. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3871. $categoryDetil = $Lcategory->getOne ( array (
  3872. 'where' => 'cid=' . $value ['cid'],
  3873. 'asArray' => true
  3874. ) );
  3875. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3876. // 检测编辑状态
  3877. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3878. $verifyList ['staff'] = $value ['verifyBreakup'];
  3879. } else
  3880. $verifyList = $verify->getOne ( array (
  3881. 'where' => 'vid=' . $value ['verify'],
  3882. 'asArray' => true
  3883. ) );
  3884. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3885. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3886. Doo::loadModel ( 'role' );
  3887. $role = new role ();
  3888. if ($verifyList == NULL)
  3889. $verifyList = array ();
  3890. $flag = true;
  3891. $roleKey = 0;
  3892. $endStaffArray = array ();
  3893. $roleArrayCopy = array ();
  3894. foreach ( $verifyList as $k => $v ) {
  3895. // init verifyStaff
  3896. if ($v [1] == 'ROLE') {
  3897. if (! empty ( $verifyStaff )) {
  3898. $endStaffArray = end ( $verifyStaff );
  3899. // if ($v[0]==$endStaffArray['nextStaff']){
  3900. // $roleId=$v[0];
  3901. // }
  3902. }
  3903. $roleVerify = json_decode ( $v [3], true );
  3904. $roleKey = $k;
  3905. $roleArray = array ();
  3906. $rolename = $role->getOne ( array (
  3907. 'where' => 'rid=' . $v [0],
  3908. 'asArray' => true
  3909. ) );
  3910. foreach ( $roleVerify as $o => $p ) {
  3911. $staffID = explode ( '_', $p );
  3912. $staffInfo = $staff->getOne ( array (
  3913. 'where' => 'sid=' . $staffID [0],
  3914. 'asArray' => true
  3915. ) );
  3916. // print_r($staffID);
  3917. $exp = array (
  3918. 0 => $staffInfo ['sid'],
  3919. 1 => $staffID [1],
  3920. 2 => $staffInfo ['avatar'],
  3921. 'date' => '',
  3922. 'date' => '',
  3923. 'opinion' => '',
  3924. 'status' => '',
  3925. 'rolename' => $rolename ['name']
  3926. );
  3927. array_push ( $roleArray, $exp );
  3928. }
  3929. $roleArrayCopy [$v [0]] = $roleArray;
  3930. // $verifyList[$k]['roleArray']=$roleArray;
  3931. }
  3932. $verifyList [$k] ['date'] = "";
  3933. $verifyList [$k] ['opinion'] = "";
  3934. $verifyList [$k] ['status'] = "";
  3935. if (empty ( $verifyStaff )) {
  3936. $verifyList [$k] ['date'] = "";
  3937. $verifyList [$k] ['opinion'] = "";
  3938. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3939. $verifyList [$k] ['status'] = 4;
  3940. $flag = false;
  3941. }
  3942. } else {
  3943. foreach ( $verifyStaff as $m => $u ) {
  3944. if ($v [0] == $m) {
  3945. $verifyList [$k] ['date'] = $u ['date'];
  3946. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3947. $verifyList [$k] ['status'] = $u ['status'];
  3948. $flag = false;
  3949. break;
  3950. }
  3951. }
  3952. $endStaffArray = end ( $verifyStaff );
  3953. if (isset ( $endStaffArray ['ROLE'] )) {
  3954. } else {
  3955. // $endKey=key($verifyStaff);
  3956. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3957. // $button=4;
  3958. // $verifyList[$k]['status']=4;
  3959. // }
  3960. }
  3961. }
  3962. }
  3963. $FC = @$rolename ['name'];
  3964. $rolename ['name'] = '';
  3965. if (! empty ( $roleId )) {
  3966. Doo::loadModel ( 'role' );
  3967. $role = new role ();
  3968. $rolename = $role->getOne ( array (
  3969. 'where' => 'rid=' . $roleId,
  3970. 'asArray' => true
  3971. ) );
  3972. }
  3973. if (! empty ( $verifyStaff ))
  3974. $endStaffArray = end ( $verifyStaff );
  3975. $KOP = false;
  3976. foreach ( $roleArrayCopy as $P => $A ) {
  3977. foreach ( $A as $MKI => $AVL ) {
  3978. if (! empty ( $verifyStaff )) {
  3979. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3980. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3981. $button = 4;
  3982. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3983. }
  3984. foreach ( $verifyStaff as $m => $u ) {
  3985. $AVLFK = $AVL [0] . '_R';
  3986. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3987. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3988. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3989. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3990. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3991. break;
  3992. }
  3993. }
  3994. } else {
  3995. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3996. $button = 4;
  3997. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3998. }
  3999. }
  4000. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4001. $KOP = true;
  4002. }
  4003. }
  4004. foreach ( $roleArrayCopy as $k => $v ) {
  4005. foreach ( $verifyList as $m => $n ) {
  4006. if ($n [0] == $k) {
  4007. array_splice ( $verifyList, $m, 1, $v );
  4008. }
  4009. }
  4010. }
  4011. // 费用执行人相关数据
  4012. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4013. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4014. foreach ( $executeCopy as $k => $v ) {
  4015. $executeCopy [$k] ['date'] = '';
  4016. $executeCopy [$k] ['opinion'] = '';
  4017. $executeCopy [$k] ['status'] = '';
  4018. if (! empty ( $executeStaff ))
  4019. foreach ( $executeStaff as $m => $u ) {
  4020. if ($v [0] == $m) {
  4021. $executeCopy [$k] ['date'] = $u ['date'];
  4022. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4023. $executeCopy [$k] ['status'] = $u ['status'];
  4024. break;
  4025. }
  4026. }
  4027. }
  4028. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4029. // print_r($verifyList);
  4030. $receiptList [$key] ['verifyList'] = $verifyList;
  4031. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4032. 'where' => 'sid=' . $value ['staff'],
  4033. 'asArray' => true
  4034. ) );
  4035. $receiptList [$key] ['button'] = $button;
  4036. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4037. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4038. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4039. $receiptList [$key] ['relust'] = $relust;
  4040. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4041. }
  4042. // print_r($receiptList);
  4043. // 获取审批日志
  4044. Doo::loadModel ( 'receiptLog' );
  4045. $receiptLog = new receiptLog ();
  4046. $rlList = array ();
  4047. $rlInfo = $receiptLog->getOne ( array (
  4048. 'where' => 'rid=' . $rid . ' and status=4',
  4049. 'asArray' => true
  4050. ) );
  4051. // $tijdate = $receiptLog->getOne ( array (
  4052. // 'where' => 'rid=' . $rid . ' and status=2',
  4053. // 'asc' => 'rlid',
  4054. // 'asArray' => true
  4055. // ) );
  4056. if (! empty ( $rlInfo )) {
  4057. $rlList = $receiptLog->find ( array (
  4058. 'where' => 'rid=' . $rid,
  4059. 'asc' => 'rlid',
  4060. 'asArray' => true
  4061. ) );
  4062. }
  4063. $RN=array();
  4064. if (!empty( $rolename ['staff'])){
  4065. $RN = @json_decode ( $rolename ['staff'] );
  4066. }
  4067. //
  4068. foreach ( $rlList as $key => $value ) {
  4069. $rlList [$key] ['rolename'] = '';
  4070. foreach ( $RN as $k => $v ) {
  4071. $id = explode ( "_", $v );
  4072. if ($id [0] == $value ['uid']) {
  4073. $rlList [$key] ['rolename'] = $FC;
  4074. break;
  4075. }
  4076. }
  4077. }
  4078. Doo::loadModel ( 'enclosur' );
  4079. $enclosur = new enclosur ();
  4080. $enclosurList = $enclosur->find ( array (
  4081. 'where' => 'rid=' . $rid,
  4082. 'asArray' => true
  4083. ) );
  4084. $enclosurHtml = '';
  4085. foreach ( $enclosurList as $value ) {
  4086. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4087. }
  4088. $data ['enclosurHtml'] = $enclosurHtml;
  4089. $receiptList [0] ['rlList'] = $rlList;
  4090. $data ['receiptList'] = $receiptList;
  4091. // print_r($receiptList);
  4092. $data ['memu'] = "receipt";
  4093. $data ['staff'] = $this->staff;
  4094. $data ['receiptMemu'] = 'approvalExpenses';
  4095. $data ['verifyId'] = $this->verifyId;
  4096. $data ['executeId'] = $this->executeId;
  4097. $this->render ( "/admin/expensesDoc", $data );
  4098. }
  4099. function expensesEdi() {
  4100. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4101. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4102. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4103. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4104. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4105. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4106. if (empty ( $status ))
  4107. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4108. $vidList = array ();
  4109. $button = 0;
  4110. Doo::loadModel ( 'verify' );
  4111. Doo::loadModel ( 'receipt' );
  4112. Doo::loadModel ( 'staff' );
  4113. $staff = new staff ();
  4114. $receipt = new receipt ();
  4115. $verify = new verify ();
  4116. Doo::loadModel ( 'L_category' );
  4117. $Lcategory = new L_category ();
  4118. Doo::loadModel ( 'enclosur' );
  4119. $enclosur = new enclosur ();
  4120. // user verify ID
  4121. $verifyDetail = $verify->find ( array (
  4122. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4123. 'asArray' => true
  4124. ) );
  4125. foreach ( $verifyDetail as $key => $value ) {
  4126. array_push ( $vidList, $value ['vid'] );
  4127. }
  4128. $vid = implode ( ",", $vidList );
  4129. if (empty ( $verifyDetail ))
  4130. $vid = 0;
  4131. $categoryList = $Lcategory->find ( array (
  4132. 'asArray' => true
  4133. ) );
  4134. $staffList = $staff->find ( array (
  4135. 'where' => 'cid=' . $cid,
  4136. 'asArray' => true
  4137. ) );
  4138. $ap = "";
  4139. if ($status == 4) {
  4140. $ap = 4;
  4141. $status = 2;
  4142. }
  4143. // get Receipt By verifyID status 2
  4144. $receiptList = $receipt->find ( array (
  4145. 'where' => 'rid =' . $rid . ' and status=2',
  4146. 'desc' => 'rid',
  4147. 'asArray' => true
  4148. ) );
  4149. if (empty ( $receiptList )) {
  4150. die ( 'illegal request' );
  4151. }
  4152. $Locate = 0;
  4153. $roleId = 0;
  4154. if ($ap == 4)
  4155. $status = 4;
  4156. foreach ( $receiptList as $key => $value ) {
  4157. $receiptList [$key] ['Locate'] = $Locate;
  4158. $Locate ++;
  4159. $receiptList [$key] ['reviseDetail'] = array ();
  4160. if (! empty ( $value ['reviseDetail'] ))
  4161. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4162. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4163. $categoryDetil = $Lcategory->getOne ( array (
  4164. 'where' => 'cid=' . $value ['cid'],
  4165. 'asArray' => true
  4166. ) );
  4167. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4168. // 检测编辑状态
  4169. $verifyList = $verify->getOne ( array (
  4170. 'where' => 'vid=' . $value ['verify'],
  4171. 'asArray' => true
  4172. ) );
  4173. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4174. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4175. Doo::loadModel ( 'role' );
  4176. $role = new role ();
  4177. // print_r($verifyList);
  4178. $flag = true;
  4179. $roleKey = 0;
  4180. $endStaffArray = array ();
  4181. $roleArrayCopy = array ();
  4182. foreach ( $verifyList as $k => $v ) {
  4183. // init verifyStaff
  4184. if ($v [1] == 'ROLE') {
  4185. if (! empty ( $verifyStaff )) {
  4186. $endStaffArray = end ( $verifyStaff );
  4187. if ($v [0] == $endStaffArray ['nextStaff']) {
  4188. $roleId = $v [0];
  4189. }
  4190. }
  4191. $roleVerify = json_decode ( $v [3], true );
  4192. $roleKey = $k;
  4193. $roleArray = array ();
  4194. $rolename = $role->getOne ( array (
  4195. 'where' => 'rid=' . $v [0],
  4196. 'asArray' => true
  4197. ) );
  4198. foreach ( $roleVerify as $o => $p ) {
  4199. $staffID = explode ( '_', $p );
  4200. $staffInfo = $staff->getOne ( array (
  4201. 'where' => 'sid=' . $staffID [0],
  4202. 'asArray' => true
  4203. ) );
  4204. // print_r($staffID);
  4205. $exp = array (
  4206. 0 => $staffInfo ['sid'],
  4207. 1 => $staffID [1],
  4208. 2 => $staffInfo ['avatar'],
  4209. 'date' => '',
  4210. 'date' => '',
  4211. 'opinion' => '',
  4212. 'status' => '',
  4213. 'rolename' => $rolename ['name']
  4214. );
  4215. array_push ( $roleArray, $exp );
  4216. }
  4217. $roleArrayCopy [$v [0]] = $roleArray;
  4218. // $verifyList[$k]['roleArray']=$roleArray;
  4219. }
  4220. // print_r($roleArray);
  4221. $verifyList [$k] ['date'] = "";
  4222. $verifyList [$k] ['opinion'] = "";
  4223. $verifyList [$k] ['status'] = "";
  4224. if (empty ( $verifyStaff )) {
  4225. $verifyList [$k] ['date'] = "";
  4226. $verifyList [$k] ['opinion'] = "";
  4227. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4228. $verifyList [$k] ['status'] = 4;
  4229. $button = 4;
  4230. $flag = false;
  4231. }
  4232. } else {
  4233. foreach ( $verifyStaff as $m => $u ) {
  4234. if ($v [0] == $m) {
  4235. $verifyList [$k] ['date'] = $u ['date'];
  4236. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4237. $verifyList [$k] ['status'] = $u ['status'];
  4238. $flag = false;
  4239. break;
  4240. }
  4241. }
  4242. $endStaffArray = end ( $verifyStaff );
  4243. if (isset ( $endStaffArray ['ROLE'] )) {
  4244. } else {
  4245. $endKey = key ( $verifyStaff );
  4246. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4247. $button = 4;
  4248. $verifyList [$k] ['status'] = 4;
  4249. }
  4250. }
  4251. }
  4252. }
  4253. $rolename ['name'] = '';
  4254. if (! empty ( $roleId )) {
  4255. Doo::loadModel ( 'role' );
  4256. $role = new role ();
  4257. $rolename = $role->getOne ( array (
  4258. 'where' => 'rid=' . $roleId,
  4259. 'asArray' => true
  4260. ) );
  4261. }
  4262. if (! empty ( $verifyStaff ))
  4263. $endStaffArray = end ( $verifyStaff );
  4264. $KOP = false;
  4265. foreach ( $roleArrayCopy as $P => $A ) {
  4266. foreach ( $A as $MKI => $AVL ) {
  4267. if (! empty ( $verifyStaff )) {
  4268. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4269. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4270. $button = 4;
  4271. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4272. }
  4273. foreach ( $verifyStaff as $m => $u ) {
  4274. $AVLFK = $AVL [0] . '_R';
  4275. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4276. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4277. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4278. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4279. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4280. break;
  4281. }
  4282. }
  4283. } else {
  4284. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4285. $button = 4;
  4286. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4287. }
  4288. }
  4289. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4290. $KOP = true;
  4291. }
  4292. }
  4293. // print_r($roleArrayCopy);
  4294. // echo $roleKey;
  4295. foreach ( $roleArrayCopy as $k => $v ) {
  4296. foreach ( $verifyList as $m => $n ) {
  4297. if ($n [0] == $k) {
  4298. array_splice ( $verifyList, $m, 1, $v );
  4299. }
  4300. }
  4301. }
  4302. $receiptList [$key] ['verifyList'] = $verifyList;
  4303. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4304. 'where' => 'sid=' . $value ['staff'],
  4305. 'asArray' => true
  4306. ) );
  4307. $receiptList [$key] ['button'] = $button;
  4308. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4309. }
  4310. // $data['verifyDetail']=$verifyDetail;
  4311. $mothHtml = "";
  4312. for($i = 1; $i <= 12; $i ++) {
  4313. if ($month == $i)
  4314. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4315. else
  4316. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4317. }
  4318. // 获取审批日志
  4319. Doo::loadModel ( 'receiptLog' );
  4320. $receiptLog = new receiptLog ();
  4321. $rlList = array ();
  4322. $rlInfo = $receiptLog->getOne ( array (
  4323. 'where' => 'rid=' . $rid . ' and status=4',
  4324. 'asArray' => true
  4325. ) );
  4326. $tijdate = $receiptLog->getOne ( array (
  4327. 'where' => 'rid=' . $rid . ' and status=2',
  4328. 'asc' => 'rlid',
  4329. 'asArray' => true
  4330. ) );
  4331. if (! empty ( $rlInfo )) {
  4332. $rlList = $receiptLog->find ( array (
  4333. 'where' => 'rid=' . $rid,
  4334. 'asc' => 'rlid',
  4335. 'asArray' => true
  4336. ) );
  4337. }
  4338. $receiptList [0] ['rlList'] = $rlList;
  4339. $enclosurList = $enclosur->find ( array (
  4340. 'where' => 'rid=' . $rid,
  4341. 'asArray' => true
  4342. ) );
  4343. $enclosurHtml = '';
  4344. foreach ( $enclosurList as $value ) {
  4345. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4346. }
  4347. // print_r($receiptList);
  4348. $data ['rid'] = $rid;
  4349. $data ['enclosurHtml'] = $enclosurHtml;
  4350. $data ['rolename'] = $rolename ['name'];
  4351. $data ['datetij'] = $tijdate ['date'];
  4352. $data ['mothHtml'] = $mothHtml;
  4353. $data ['receiptList'] = $receiptList;
  4354. $data ['receiptApprovalCount'] = count ( $receiptList );
  4355. $data ['status'] = $status;
  4356. $data ['year'] = $year;
  4357. $data ['categoryList'] = $categoryList;
  4358. $data ['staffList'] = $staffList;
  4359. $data ['cid'] = $cid;
  4360. $data ['sid'] = $sid;
  4361. $data ['ap'] = $ap;
  4362. $data ['memu'] = "receipt";
  4363. $data ['staff'] = $this->staff;
  4364. $data ['receiptMemu'] = 'approvalExpenses';
  4365. $data ['verifyId'] = $this->verifyId;
  4366. $data ['executeId'] = $this->executeId;
  4367. $this->render ( "/admin/expensesEdi", $data );
  4368. }
  4369. function expensesDefray() {
  4370. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4371. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4372. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4373. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4374. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4375. if (! empty ( $rid )) {
  4376. Doo::loadModel ( "verify" );
  4377. $verify = new verify ();
  4378. Doo::loadModel ( "receiptDetail" );
  4379. $receiptDetailObj = new receiptDetail ();
  4380. Doo::loadModel ( "itemStatistics" );
  4381. Doo::loadModel ( "statistics" );
  4382. $statistics = new statistics ();
  4383. $itemStatistics = new itemStatistics ();
  4384. Doo::loadModel ( "receipt" );
  4385. $receipt = new receipt ();
  4386. Doo::loadModel ( "loanReceipt" );
  4387. $loanReceipt = new loanReceipt ();
  4388. $receiptDetail = $receipt->getOne ( array (
  4389. 'where' => 'rid=' . $rid . ' and status=2 ',
  4390. 'asArray' => true
  4391. ) );
  4392. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4393. $nsflag = true;
  4394. foreach ( $nslist as $value ) {
  4395. if ($value == $this->staff ['0'] ['sid']) {
  4396. $nsflag = false;
  4397. break;
  4398. }
  4399. }
  4400. // print_r($nslist);die;
  4401. if (empty ( $receiptDetail ) || $nsflag)
  4402. return "/approvalExpenses/pendApproval";
  4403. $verifyDetail = $verify->getOne ( array (
  4404. 'where' => ' vid =' . $receiptDetail ['verify'],
  4405. 'asArray' => true
  4406. ) );
  4407. $verifyString = $verifyDetail ['staff'];
  4408. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4409. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4410. if (empty ( $opinion )) {
  4411. if ($status == 3)
  4412. $opinion = "终止";
  4413. else
  4414. $opinion = "同意支付";
  4415. }
  4416. $nowStaff = 0;
  4417. $nowStaffList = array ();
  4418. if (empty ( $verifyStaff )) {
  4419. // 还需加入是否已经进入角色审批
  4420. if ($verifyDetail [0] [1] == 'ROLE') {
  4421. // print_r($verifyDetail);echo "ddd";
  4422. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4423. foreach ( $vStaffString as $key => $value ) {
  4424. $staffK = explode ( "_", $value );
  4425. if ($staffK [0] != $this->staff [0] ['sid'])
  4426. array_push ( $nowStaffList, $staffK [0] );
  4427. }
  4428. // print_r($verifyDetail);
  4429. // die;
  4430. if (! empty ( $nowStaffList )) {
  4431. $nowStaff = implode ( ',', $nowStaffList );
  4432. $verifyStaff = array (
  4433. $this->staff [0] ['sid'] . "_R" => array (
  4434. 'date' => date ( 'Y-m-d' ),
  4435. 'opinion' => $opinion,
  4436. 'status' => $status,
  4437. 'nextStaff' => $verifyDetail [0] [0],
  4438. 'ROLE' => 1
  4439. )
  4440. );
  4441. } else {
  4442. $nowStaff = $verifyDetail [1] [0];
  4443. $verifyStaff = array (
  4444. $this->staff [0] ['sid'] . "_R" => array (
  4445. 'date' => date ( 'Y-m-d' ),
  4446. 'opinion' => $opinion,
  4447. 'status' => $status,
  4448. 'nextStaff' => $verifyDetail [1] [0]
  4449. )
  4450. );
  4451. }
  4452. } else {
  4453. if ($verifyDetail [1] [1] == 'ROLE') {
  4454. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4455. // echo "dd";
  4456. foreach ( $vStaffString as $key => $value ) {
  4457. $staffK = explode ( "_", $value );
  4458. array_push ( $nowStaffList, $staffK [0] );
  4459. }
  4460. $nowStaff = implode ( ',', $nowStaffList );
  4461. $verifyStaff = array (
  4462. $this->staff [0] ['sid'] => array (
  4463. 'date' => date ( 'Y-m-d' ),
  4464. 'opinion' => $opinion,
  4465. 'status' => $status,
  4466. 'nextStaff' => $verifyDetail [1] [0],
  4467. 'ROLE' => 1
  4468. )
  4469. );
  4470. } else {
  4471. $nowStaff = $verifyDetail [1] [0];
  4472. $verifyStaff = array (
  4473. $this->staff [0] ['sid'] => array (
  4474. 'date' => date ( 'Y-m-d' ),
  4475. 'opinion' => $opinion,
  4476. 'status' => $status,
  4477. 'nextStaff' => $verifyDetail [1] [0]
  4478. )
  4479. );
  4480. }
  4481. }
  4482. if ($status == 3)
  4483. $verifyStaff = array (
  4484. 'final' => $status,
  4485. $this->staff [0] ['sid'] => array (
  4486. 'date' => date ( 'Y-m-d' ),
  4487. 'opinion' => $opinion,
  4488. 'status' => $status
  4489. )
  4490. );
  4491. $vStaffString = json_encode ( $verifyStaff );
  4492. $receipt->nowStaff = $nowStaff;
  4493. $receipt->verifyStaff = $vStaffString;
  4494. $loanReceipt->nowStaff = $nowStaff;
  4495. $loanReceipt->verifyStaff = $vStaffString;
  4496. } else {
  4497. $VS = end ( $verifyStaff );
  4498. // 非角色审批
  4499. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4500. $nextStaff = 0;
  4501. $roleSTF = false;
  4502. foreach ( $verifyDetail as $key => $value ) {
  4503. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4504. if (isset ( $verifyDetail [$key + 1] )) {
  4505. $nextStaff = $verifyDetail [$key + 1] [0];
  4506. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4507. $roleSTF = true;
  4508. }
  4509. break;
  4510. }
  4511. }
  4512. if (! $roleSTF) {
  4513. $nowStaff = $nextStaff;
  4514. $verifyStaff [$this->staff [0] ['sid']] = array (
  4515. 'date' => date ( 'Y-m-d' ),
  4516. 'opinion' => $opinion,
  4517. 'status' => $status,
  4518. 'nextStaff' => $nextStaff
  4519. );
  4520. } else {
  4521. // 获取角色下的所有用户ID
  4522. $nowStaffList = array ();
  4523. foreach ( $verifyDetail as $vfk ) {
  4524. if ($vfk [1] == 'ROLE') {
  4525. $vStaffString = json_decode ( $vfk [3] );
  4526. foreach ( $vStaffString as $key => $value ) {
  4527. $staffK = explode ( "_", $value );
  4528. array_push ( $nowStaffList, $staffK [0] );
  4529. }
  4530. }
  4531. }
  4532. $nowStaff = implode ( ',', $nowStaffList );
  4533. $verifyStaff [$this->staff [0] ['sid']] = array (
  4534. 'date' => date ( 'Y-m-d' ),
  4535. 'opinion' => $opinion,
  4536. 'status' => $status,
  4537. 'nextStaff' => $nextStaff,
  4538. 'ROLE' => 0
  4539. );
  4540. }
  4541. if ($status == 3) {
  4542. $verifyStaff ['final'] = $status;
  4543. $verifyStaff [$this->staff [0] ['sid']] = array (
  4544. 'date' => date ( 'Y-m-d' ),
  4545. 'opinion' => $opinion,
  4546. 'status' => $status
  4547. );
  4548. }
  4549. $vStaffString = json_encode ( $verifyStaff );
  4550. $receipt->nowStaff = $nowStaff;
  4551. $receipt->verifyStaff = $vStaffString;
  4552. $loanReceipt->nowStaff = $nowStaff;
  4553. $loanReceipt->verifyStaff = $vStaffString;
  4554. }
  4555. // 角色审批
  4556. if (isset ( $VS ['ROLE'] )) {
  4557. // 找出角色人 当前审批角色组
  4558. $verifyJSStaff = array ();
  4559. $nowStaffList2 = array ();
  4560. foreach ( $verifyDetail as $key => $value ) {
  4561. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4562. $verifyJSStaff = json_decode ( $value [3] );
  4563. foreach ( $verifyJSStaff as $m ) {
  4564. $staffK = explode ( "_", $m );
  4565. array_push ( $nowStaffList2, $staffK [0] );
  4566. }
  4567. // print_r($nowStaffList2);
  4568. }
  4569. }
  4570. $RoleVerifyStaff = array ();
  4571. foreach ( $verifyStaff as $key => $value ) {
  4572. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4573. foreach ( $nowStaffList2 as $m ) {
  4574. if ($key == $m . "_R")
  4575. $RoleVerifyStaff [$key] = $value;
  4576. }
  4577. }
  4578. }
  4579. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4580. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4581. // 下一个审批人ID
  4582. $nextStaff = 0;
  4583. $falg = false;
  4584. foreach ( $verifyDetail as $key => $value ) {
  4585. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4586. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4587. $falg = true;
  4588. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4589. $nowStaffList = array ();
  4590. foreach ( $vStaffString as $v ) {
  4591. $staffK = explode ( "_", $v );
  4592. array_push ( $nowStaffList, $staffK [0] );
  4593. }
  4594. $nowStaff = implode ( ',', $nowStaffList );
  4595. $nextStaff = $verifyDetail [$key + 1] [0];
  4596. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4597. $nextStaff = $verifyDetail [$key + 1] [0];
  4598. $nowStaff = $nextStaff;
  4599. } else
  4600. $nowStaff = '';
  4601. break;
  4602. }
  4603. }
  4604. if ($falg)
  4605. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4606. 'date' => date ( 'Y-m-d' ),
  4607. 'opinion' => $opinion,
  4608. 'status' => $status,
  4609. 'nextStaff' => $nextStaff,
  4610. 'ROLE' => 1
  4611. );
  4612. else
  4613. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4614. 'date' => date ( 'Y-m-d' ),
  4615. 'opinion' => $opinion,
  4616. 'status' => $status,
  4617. 'nextStaff' => $nextStaff
  4618. );
  4619. // print_r($verifyStaff);
  4620. // echo $nowStaff;die;
  4621. } else { // 进入下一个角色或者审批人
  4622. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4623. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4624. 'date' => date ( 'Y-m-d' ),
  4625. 'opinion' => $opinion,
  4626. 'status' => $status,
  4627. 'nextStaff' => $VS ['nextStaff'],
  4628. 'ROLE' => 1
  4629. );
  4630. }
  4631. if ($status == 3) {
  4632. $verifyStaff ['final'] = $status;
  4633. $verifyStaff [$this->staff [0] ['sid']] = array (
  4634. 'date' => date ( 'Y-m-d' ),
  4635. 'opinion' => $opinion,
  4636. 'status' => $status
  4637. );
  4638. }
  4639. $vStaffString = json_encode ( $verifyStaff );
  4640. $receipt->verifyStaff = $vStaffString;
  4641. $receipt->nowStaff = $nowStaff;
  4642. $loanReceipt->nowStaff = $nowStaff;
  4643. $loanReceipt->verifyStaff = $vStaffString;
  4644. }
  4645. // print_r($verifyStaff);die;
  4646. }
  4647. $roleKey = 0;
  4648. $roleId = 0;
  4649. $verifyDetailCopy = array ();
  4650. foreach ( $verifyDetail as $k => $v ) {
  4651. if ($v [1] == 'ROLE') {
  4652. $roleId = $v [0];
  4653. $roleVerify = json_decode ( $v [3], true );
  4654. $roleKey = $k;
  4655. $roleArray = array ();
  4656. foreach ( $roleVerify as $o => $p ) {
  4657. $staffID = explode ( '_', $p );
  4658. $exp = array (
  4659. 0 => $staffID [0],
  4660. 1 => $staffID [1]
  4661. );
  4662. array_push ( $roleArray, $exp );
  4663. }
  4664. $verifyDetailCopy [$v [0]] = $roleArray;
  4665. }
  4666. }
  4667. // print_r($verifyDetail);
  4668. foreach ( $verifyDetailCopy as $k => $v ) {
  4669. foreach ( $verifyDetail as $m => $n ) {
  4670. if ($n [0] == $k) {
  4671. array_splice ( $verifyDetail, $m, 1, $v );
  4672. }
  4673. }
  4674. }
  4675. // 审批日志
  4676. if (! isset ( $verifyStaff ['final'] )) {
  4677. Doo::loadModel ( "receiptLog" );
  4678. $receiptLog = new receiptLog ();
  4679. if (! empty ( $roleId )) {
  4680. Doo::loadModel ( "role" );
  4681. $role = new role ();
  4682. $roleInfo = $role->getOne ( array (
  4683. 'where' => 'rid=' . $roleId,
  4684. 'asArray' => true
  4685. ) );
  4686. $receiptLog->rolename = $roleInfo ['name'];
  4687. }
  4688. $receiptLog->username = $this->staff [0] ['username'];
  4689. $receiptLog->uid = $this->staff [0] ['sid'];
  4690. $receiptLog->date = date ( "Y-m-d" );
  4691. $receiptLog->opinion = $opinion;
  4692. $receiptLog->img = $this->staff [0] ['avatar'];
  4693. $receiptLog->status = 1;
  4694. $receiptLog->rid = $rid;
  4695. $receiptLog->insert ();
  4696. }
  4697. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4698. $receipt->status = 3;
  4699. $receipt->verifyBreakup = $verifyString;
  4700. $receiptDetailObj->status = 3;
  4701. $receiptDetailObj->update ( array (
  4702. 'where' => 'rid=' . $rid
  4703. ) );
  4704. // 微信企业号通知
  4705. $this->setWXMsg ( $rid, 3 );
  4706. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4707. $receipt->status = 6;
  4708. $receipt->pastDate = date ( "Y-m-d" );
  4709. $receipt->isBK = 1;
  4710. $loanReceipt->verifyBreakup = $verifyString;
  4711. $loanReceipt->status = 1;
  4712. $loanReceipt->pastDate = date ( "Y-m-d" );
  4713. //生成流水后 不更新汇款金额
  4714. Doo::loadModel ( 'wasteBook' );
  4715. $wasteBook = new wasteBook ();
  4716. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4717. if (empty($wbDetail)){
  4718. $loanReceipt->amount = $receiptDetail ['amount'];
  4719. }
  4720. $loanReceipt->update ( array (
  4721. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4722. ) );
  4723. // 微信企业号通知
  4724. $this->setWXMsg ( $rid, 1 );
  4725. }
  4726. $receipt->amount = $receiptDetail['sum'];
  4727. $receipt->update ( array (
  4728. 'where' => ' rid = ' . $rid
  4729. ) );
  4730. // 进入下一条审批费用新加需求
  4731. $vidList = array ();
  4732. $verifyDetail = $verify->find ( array (
  4733. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4734. 'asArray' => true
  4735. ) );
  4736. foreach ( $verifyDetail as $key => $value ) {
  4737. array_push ( $vidList, $value ['vid'] );
  4738. }
  4739. $vid = implode ( ",", $vidList );
  4740. if (empty ( $verifyDetail ))
  4741. $vid = 0;
  4742. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4743. $receipt = new receipt ();
  4744. $rd = $receipt->getOne ( array (
  4745. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4746. 'asc' => 'rid',
  4747. 'asArray' => true
  4748. ) );
  4749. if (empty ( $rd )) {
  4750. return '/approvalExpenses/pendApproval';
  4751. }
  4752. if ($rd ['Rtype'] == 1) {
  4753. if ($rd ['isBK'] == 1) {
  4754. return '/receiptburEdi/' . $rd ['rid'];
  4755. } else {
  4756. return '/expensesEdi/' . $rd ['rid'];
  4757. }
  4758. } elseif ($rd ['Rtype'] == 2) {
  4759. return '/remitApproval/' . $rd ['rid'];
  4760. } else {
  4761. return '/receiptburEdi/' . $rd ['rid'];
  4762. }
  4763. // return "/approvalExpenses/pendApproval";
  4764. }
  4765. }
  4766. function ajaxExamineExe() {
  4767. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4768. Doo::loadModel ( 'receipt' );
  4769. $receipt = new receipt ();
  4770. Doo::loadClass ( 'XDeode' );
  4771. $XDeode = new XDeode ( 5 );
  4772. if (! empty ( $rid )) {
  4773. $rLRes = $receipt->find ( array (
  4774. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4775. 'asArray' => true
  4776. ) );
  4777. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4778. echo json_encode ( array (
  4779. 'status' => 1,
  4780. 'receipt' => $rLRes [0]
  4781. ) );
  4782. die ();
  4783. }
  4784. echo json_encode ( array (
  4785. 'status' => 0,
  4786. 'receipt' => array ()
  4787. ) );
  4788. die ();
  4789. }
  4790. function implement() {
  4791. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4792. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  4793. Doo::loadClass ( 'XDeode' );
  4794. $XDeode = new XDeode ( 5 );
  4795. Doo::loadModel ( 'receipt' );
  4796. $receipt = new receipt ();
  4797. Doo::loadModel ( 'L_category' );
  4798. $Lcategory = new L_category ();
  4799. Doo::loadModel ( 'verify' );
  4800. $verify = new verify ();
  4801. Doo::loadModel ( 'staff' );
  4802. $staff = new staff ();
  4803. Doo::loadModel ( "execute" );
  4804. $execute = new execute ();
  4805. $rid = $XDeode->decode ( $rid );
  4806. $receiptList = $receipt->find ( array (
  4807. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4808. 'desc' => 'rid',
  4809. 'asArray' => true
  4810. ) );
  4811. Doo::loadModel ( 'loanReceipt' );
  4812. $loanReceipt = new loanReceipt ();
  4813. // print_r($receiptList);
  4814. $loanList = array ();
  4815. if (! isset ( $receiptList ))
  4816. $loanList = $loanReceipt->find ( array (
  4817. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4818. 'desc' => 'rid',
  4819. 'asArray' => true
  4820. ) );
  4821. $Locate = 0;
  4822. $roleId = 0;
  4823. $button = 0;
  4824. foreach ( $loanList as $key => $value ) {
  4825. $loanList [$key] ['Locate'] = $Locate;
  4826. $Locate ++;
  4827. $loanList [$key] ['reviseDetail'] = array ();
  4828. if (! empty ( $value ['reviseDetail'] ))
  4829. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4830. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4831. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4832. $categoryDetil = $Lcategory->getOne ( array (
  4833. 'where' => 'cid=' . $value ['cid'],
  4834. 'asArray' => true
  4835. ) );
  4836. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4837. // 检测编辑状态
  4838. $verifyList = $verify->getOne ( array (
  4839. 'where' => 'vid=' . $value ['verify'],
  4840. 'asArray' => true
  4841. ) );
  4842. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4843. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4844. Doo::loadModel ( 'role' );
  4845. $role = new role ();
  4846. $flag = true;
  4847. $roleKey = 0;
  4848. $endStaffArray = array ();
  4849. $roleArrayCopy = array ();
  4850. foreach ( $verifyList as $k => $v ) {
  4851. // init verifyStaff
  4852. if ($v [1] == 'ROLE') {
  4853. if (! empty ( $verifyStaff )) {
  4854. $endStaffArray = end ( $verifyStaff );
  4855. // if ($v[0]==$endStaffArray['nextStaff']){
  4856. // $roleId=$v[0];
  4857. // }
  4858. }
  4859. $roleVerify = json_decode ( $v [3], true );
  4860. $roleKey = $k;
  4861. $roleArray = array ();
  4862. $rolename = $role->getOne ( array (
  4863. 'where' => 'rid=' . $v [0],
  4864. 'asArray' => true
  4865. ) );
  4866. foreach ( $roleVerify as $o => $p ) {
  4867. $staffID = explode ( '_', $p );
  4868. $staffInfo = $staff->getOne ( array (
  4869. 'where' => 'sid=' . $staffID [0],
  4870. 'asArray' => true
  4871. ) );
  4872. // print_r($staffID);
  4873. $exp = array (
  4874. 0 => $staffInfo ['sid'],
  4875. 1 => $staffID [1],
  4876. 2 => $staffInfo ['avatar'],
  4877. 'date' => '',
  4878. 'date' => '',
  4879. 'opinion' => '',
  4880. 'status' => '',
  4881. 'rolename' => $rolename ['name']
  4882. );
  4883. array_push ( $roleArray, $exp );
  4884. }
  4885. $roleArrayCopy [$v [0]] = $roleArray;
  4886. // $verifyList[$k]['roleArray']=$roleArray;
  4887. }
  4888. $verifyList [$k] ['date'] = "";
  4889. $verifyList [$k] ['opinion'] = "";
  4890. $verifyList [$k] ['status'] = "";
  4891. if (empty ( $verifyStaff )) {
  4892. $verifyList [$k] ['date'] = "";
  4893. $verifyList [$k] ['opinion'] = "";
  4894. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4895. $verifyList [$k] ['status'] = 4;
  4896. $flag = false;
  4897. }
  4898. } else {
  4899. foreach ( $verifyStaff as $m => $u ) {
  4900. if ($v [0] == $m) {
  4901. $verifyList [$k] ['date'] = $u ['date'];
  4902. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4903. $verifyList [$k] ['status'] = $u ['status'];
  4904. $flag = false;
  4905. break;
  4906. }
  4907. }
  4908. $endStaffArray = end ( $verifyStaff );
  4909. if (isset ( $endStaffArray ['ROLE'] )) {
  4910. } else {
  4911. // $endKey=key($verifyStaff);
  4912. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4913. // $button=4;
  4914. // $verifyList[$k]['status']=4;
  4915. // }
  4916. }
  4917. }
  4918. }
  4919. $rolename ['name'] = '';
  4920. if (! empty ( $roleId )) {
  4921. Doo::loadModel ( 'role' );
  4922. $role = new role ();
  4923. $rolename = $role->getOne ( array (
  4924. 'where' => 'rid=' . $roleId,
  4925. 'asArray' => true
  4926. ) );
  4927. }
  4928. if (! empty ( $verifyStaff ))
  4929. $endStaffArray = end ( $verifyStaff );
  4930. $KOP = false;
  4931. foreach ( $roleArrayCopy as $P => $A ) {
  4932. foreach ( $A as $MKI => $AVL ) {
  4933. if (! empty ( $verifyStaff )) {
  4934. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4935. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4936. $button = 4;
  4937. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4938. }
  4939. foreach ( $verifyStaff as $m => $u ) {
  4940. $AVLFK = $AVL [0] . '_R';
  4941. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4942. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4943. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4944. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4945. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4946. break;
  4947. }
  4948. }
  4949. } else {
  4950. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4951. $button = 4;
  4952. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4953. }
  4954. }
  4955. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4956. $KOP = true;
  4957. }
  4958. }
  4959. foreach ( $roleArrayCopy as $k => $v ) {
  4960. foreach ( $verifyList as $m => $n ) {
  4961. if ($n [0] == $k) {
  4962. array_splice ( $verifyList, $m, 1, $v );
  4963. }
  4964. }
  4965. }
  4966. $loanList [$key] ['verifyList'] = $verifyList;
  4967. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4968. 'where' => 'sid=' . $value ['staff'],
  4969. 'asArray' => true
  4970. ) );
  4971. }
  4972. $data ['loanList'] = $loanList;
  4973. $Locate = 0;
  4974. $roleId = 0;
  4975. $button = 0;
  4976. Doo::loadClass ( 'XDeode' );
  4977. $XDeode = new XDeode ( 5 );
  4978. foreach ( $receiptList as $key => $value ) {
  4979. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4980. $button2 = 0;
  4981. $receiptList [$key] ['Locate'] = $Locate;
  4982. $Locate ++;
  4983. $receiptList [$key] ['reviseDetail'] = array ();
  4984. if (! empty ( $value ['reviseDetail'] ))
  4985. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4986. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4987. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4988. $categoryDetil = $Lcategory->getOne ( array (
  4989. 'where' => 'cid=' . $value ['cid'],
  4990. 'asArray' => true
  4991. ) );
  4992. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4993. $executeList = json_decode ( $value ['executeCopy'], true );
  4994. $executeStaff = array ();
  4995. if (! empty ( $value ['executeStaff'] ))
  4996. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4997. if (isset ( $executeList )) {
  4998. foreach ( $executeList as $op => $lo ) {
  4999. $executeList [$op] ['date'] = "";
  5000. $executeList [$op] ['opinion'] = "";
  5001. $executeList [$op] ['status'] = "";
  5002. foreach ( $executeStaff as $m => $u ) {
  5003. if ($lo [0] == $m) {
  5004. $executeList [$op] ['date'] = $u ['date'];
  5005. $executeList [$op] ['opinion'] = $u ['opinion'];
  5006. $executeList [$op] ['status'] = $u ['status'];
  5007. break;
  5008. }
  5009. }
  5010. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5011. $button2 = 1;
  5012. $executeList [$op] ['status'] = 4;
  5013. }
  5014. }
  5015. }
  5016. // 检测编辑状态
  5017. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5018. $verifyList ['staff'] = $value ['verifyBreakup'];
  5019. } else
  5020. $verifyList = $verify->getOne ( array (
  5021. 'where' => 'vid=' . $value ['verify'],
  5022. 'asArray' => true
  5023. ) );
  5024. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5025. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5026. Doo::loadModel ( 'role' );
  5027. $role = new role ();
  5028. if ($verifyList == NULL)
  5029. $verifyList = array ();
  5030. $flag = true;
  5031. $roleKey = 0;
  5032. $endStaffArray = array ();
  5033. $roleArrayCopy = array ();
  5034. foreach ( $verifyList as $k => $v ) {
  5035. // init verifyStaff
  5036. if ($v [1] == 'ROLE') {
  5037. if (! empty ( $verifyStaff )) {
  5038. $endStaffArray = end ( $verifyStaff );
  5039. // if ($v[0]==$endStaffArray['nextStaff']){
  5040. // $roleId=$v[0];
  5041. // }
  5042. }
  5043. $roleVerify = json_decode ( $v [3], true );
  5044. $roleKey = $k;
  5045. $roleArray = array ();
  5046. $rolename = $role->getOne ( array (
  5047. 'where' => 'rid=' . $v [0],
  5048. 'asArray' => true
  5049. ) );
  5050. foreach ( $roleVerify as $o => $p ) {
  5051. $staffID = explode ( '_', $p );
  5052. $staffInfo = $staff->getOne ( array (
  5053. 'where' => 'sid=' . $staffID [0],
  5054. 'asArray' => true
  5055. ) );
  5056. // print_r($staffID);
  5057. $exp = array (
  5058. 0 => $staffInfo ['sid'],
  5059. 1 => $staffID [1],
  5060. 2 => $staffInfo ['avatar'],
  5061. 'date' => '',
  5062. 'date' => '',
  5063. 'opinion' => '',
  5064. 'status' => '',
  5065. 'rolename' => $rolename ['name']
  5066. );
  5067. array_push ( $roleArray, $exp );
  5068. }
  5069. $roleArrayCopy [$v [0]] = $roleArray;
  5070. // $verifyList[$k]['roleArray']=$roleArray;
  5071. }
  5072. $verifyList [$k] ['date'] = "";
  5073. $verifyList [$k] ['opinion'] = "";
  5074. $verifyList [$k] ['status'] = "";
  5075. if (empty ( $verifyStaff )) {
  5076. $verifyList [$k] ['date'] = "";
  5077. $verifyList [$k] ['opinion'] = "";
  5078. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5079. $verifyList [$k] ['status'] = 4;
  5080. $flag = false;
  5081. }
  5082. } else {
  5083. foreach ( $verifyStaff as $m => $u ) {
  5084. if ($v [0] == $m) {
  5085. $verifyList [$k] ['date'] = $u ['date'];
  5086. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5087. $verifyList [$k] ['status'] = $u ['status'];
  5088. $flag = false;
  5089. break;
  5090. }
  5091. }
  5092. $endStaffArray = end ( $verifyStaff );
  5093. if (isset ( $endStaffArray ['ROLE'] )) {
  5094. } else {
  5095. // $endKey=key($verifyStaff);
  5096. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5097. // $button=4;
  5098. // $verifyList[$k]['status']=4;
  5099. // }
  5100. }
  5101. }
  5102. }
  5103. $rolename ['name'] = '';
  5104. if (! empty ( $roleId )) {
  5105. Doo::loadModel ( 'role' );
  5106. $role = new role ();
  5107. $rolename = $role->getOne ( array (
  5108. 'where' => 'rid=' . $roleId,
  5109. 'asArray' => true
  5110. ) );
  5111. }
  5112. if (! empty ( $verifyStaff ))
  5113. $endStaffArray = end ( $verifyStaff );
  5114. $KOP = false;
  5115. foreach ( $roleArrayCopy as $P => $A ) {
  5116. foreach ( $A as $MKI => $AVL ) {
  5117. if (! empty ( $verifyStaff )) {
  5118. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5119. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5120. $button = 4;
  5121. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5122. }
  5123. foreach ( $verifyStaff as $m => $u ) {
  5124. $AVLFK = $AVL [0] . '_R';
  5125. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5126. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5127. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5128. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5129. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5130. break;
  5131. }
  5132. }
  5133. } else {
  5134. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5135. $button = 4;
  5136. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5137. }
  5138. }
  5139. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5140. $KOP = true;
  5141. }
  5142. }
  5143. foreach ( $roleArrayCopy as $k => $v ) {
  5144. foreach ( $verifyList as $m => $n ) {
  5145. if ($n [0] == $k) {
  5146. array_splice ( $verifyList, $m, 1, $v );
  5147. }
  5148. }
  5149. }
  5150. $receiptList [$key] ['verifyList'] = $verifyList;
  5151. $receiptList [$key] ['executeList'] = $executeList;
  5152. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5153. 'where' => 'sid=' . $value ['staff'],
  5154. 'asArray' => true
  5155. ) );
  5156. $receiptList [$key] ['button2'] = $button2;
  5157. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5158. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5159. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5160. $receiptList [$key] ['relust'] = $relust;
  5161. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5162. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  5163. }
  5164. //执行人是否是最后一位
  5165. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  5166. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  5167. $executePrimary=count($executeCopy)-1;
  5168. $lastOne=true;
  5169. if($executePrimary!=count($executeStaff)){
  5170. $lastOne=false;
  5171. }
  5172. $data['lastOne']=$lastOne;
  5173. // 是否写入过流水
  5174. $accountType = 0;
  5175. if ($receiptList [0] ['Rtype'] == 0) {
  5176. $accountType = 3;
  5177. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5178. if (!empty($receiptList [0]['accountItem']) )
  5179. $accountType = 2;
  5180. else
  5181. $accountType = 1;
  5182. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5183. $accountType = 4;
  5184. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5185. $accountType = 12;
  5186. }
  5187. Doo::loadModel ( 'wasteBook' );
  5188. $wasteBook = new wasteBook ();
  5189. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5190. $data ['wbDetail'] = $wbDetail;
  5191. $wbDetailLoan=array();
  5192. if ($accountType==2){
  5193. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5194. }
  5195. $data ['wbDetailLoan'] = $wbDetailLoan;
  5196. $data['inputDate']=date ( "Y-m-d H:i:s" );
  5197. //print_r($wbDetail);
  5198. $data ['receiptList'] = $receiptList;
  5199. $data ['memu'] = "receipt";
  5200. $data ['staff'] = $this->staff;
  5201. $data ['receiptMemu'] = 'implement';
  5202. $data ['verifyId'] = $this->verifyId;
  5203. $data ['executeId'] = $this->executeId;
  5204. if ($Rtype=="loan"){
  5205. $this->render ( "/receipt/receiptImplementLoan", $data );
  5206. }elseif($Rtype=="receipt"){
  5207. $this->render ( "/receipt/receiptImplement", $data );
  5208. }elseif($Rtype=="public"){
  5209. $this->render ( "/receipt/receiptImplementPublic", $data );
  5210. }else{
  5211. //$this->render ( "/admin/implement", $data );
  5212. }
  5213. }
  5214. function implementDo() {
  5215. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  5216. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5217. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5218. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5219. // $ab = '';
  5220. // if ($accountBank == 'CGBDeposit')
  5221. // $ab = '纵横广发';
  5222. // elseif ($accountBank == 'ICBCDeposit')
  5223. // $ab = '纵横工行';
  5224. // elseif ($accountBank == 'HUADeposit')
  5225. // $ab = '华润银行';
  5226. // elseif ($accountBank == 'PersonalDeposit')
  5227. // $ab = '个人广发';
  5228. // if (empty ( $ab ))
  5229. // die ( 'illegal request--22' );
  5230. if (! empty ( $rid )) {
  5231. Doo::loadModel ( 'receipt' );
  5232. $receipt = new receipt ();
  5233. Doo::loadClass ( 'XDeode' );
  5234. $XDeode = new XDeode ( 5 );
  5235. $rid=$XDeode->decode($rid);
  5236. if (!is_numeric($rid)){
  5237. die;
  5238. }
  5239. // $rinfo = $receipt->getOne ( array (
  5240. // 'where' => 'rid=' . $rid,
  5241. // 'asArray' => true
  5242. // ) );
  5243. $rinfo = $receipt->getReceiptByRid ( $rid );
  5244. // $accountType = '';
  5245. // if ($rinfo ['Rtype'] == 1) {
  5246. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5247. // $accountType = 2;
  5248. // else
  5249. // $accountType = 1;
  5250. // } elseif ($rinfo ['Rtype'] == 2) {
  5251. // $accountType = 4;
  5252. // } elseif ($rinfo ['Rtype'] == 0)
  5253. // $accountType = 3;
  5254. // if (empty ( $accountType ))
  5255. // die ( 'illegal request' );
  5256. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5257. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5258. if (empty ( $executeStaff )) {
  5259. $executeStaff = array (
  5260. $this->staff [0] ['sid'] => array (
  5261. 'date' => date ( 'Y-m-d' ),
  5262. 'opinion' => $implementOpinions,
  5263. 'status' => 1
  5264. )
  5265. );
  5266. } else {
  5267. $executeStaff [$this->staff [0] ['sid']] = array (
  5268. 'date' => date ( 'Y-m-d' ),
  5269. 'opinion' => $implementOpinions,
  5270. 'status' => 1
  5271. );
  5272. }
  5273. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5274. $receipt->executeStaff = json_encode ( $executeStaff );
  5275. $receipt->status = 8;
  5276. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5277. $receipt->status = 9;
  5278. if ($rinfo ['status'] == 6) {
  5279. $receipt->loanDate = date ( "Y-m-d" );
  5280. }
  5281. $receipt->executeDate = date ( "Y-m-d" );
  5282. } else {
  5283. $receipt->executeStaff = json_encode ( $executeStaff );
  5284. }
  5285. //$receipt->amount = $amount;
  5286. $receipt->update ( array (
  5287. 'where' => 'rid=' . $rid
  5288. ) );
  5289. // 公司流水记录
  5290. // Doo::loadModel ( 'wasteBook' );
  5291. // $wasteBook = new wasteBook ();
  5292. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5293. // // 银行
  5294. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5295. // $item = array (
  5296. // 'dataID' => $rid,
  5297. // 'expensesType' => 2,
  5298. // 'accountType' => $accountType,
  5299. // 'accountPriceShow' => $amount,
  5300. // 'accountPrice' => - $amount,
  5301. // 'accountBank' => $accountBank,
  5302. // 'category' => $rinfo ['category'] [0] ['title'],
  5303. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5304. // 'name' => $rinfo ['staffDetail'] ['username'],
  5305. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5306. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5307. // );
  5308. // $wasteBook->setAccountBookStatistics ( $item );
  5309. // }
  5310. }
  5311. //$ridKey = $XDeode->encode ( $rid );
  5312. return "/hisImplement";
  5313. // return "/implement/" . $ridKey . ".html";
  5314. }
  5315. function receiptburEdi() {
  5316. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5317. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5318. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5319. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5320. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5321. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5322. if (empty ( $status ))
  5323. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5324. $vidList = array ();
  5325. $button = 0;
  5326. Doo::loadModel ( 'verify' );
  5327. Doo::loadModel ( 'receipt' );
  5328. Doo::loadModel ( 'staff' );
  5329. $staff = new staff ();
  5330. $receipt = new receipt ();
  5331. $verify = new verify ();
  5332. Doo::loadModel ( 'L_category' );
  5333. $Lcategory = new L_category ();
  5334. Doo::loadModel ( 'enclosur' );
  5335. $enclosur = new enclosur ();
  5336. Doo::loadModel ( 'loanReceipt' );
  5337. $loanReceipt = new loanReceipt ();
  5338. // user verify ID
  5339. $verifyDetail = $verify->find ( array (
  5340. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5341. 'asArray' => true
  5342. ) );
  5343. foreach ( $verifyDetail as $key => $value ) {
  5344. array_push ( $vidList, $value ['vid'] );
  5345. }
  5346. $vid = implode ( ",", $vidList );
  5347. if (empty ( $verifyDetail ))
  5348. $vid = 0;
  5349. $categoryList = $Lcategory->find ( array (
  5350. 'asArray' => true
  5351. ) );
  5352. $staffList = $staff->find ( array (
  5353. 'where' => 'cid=' . $cid,
  5354. 'asArray' => true
  5355. ) );
  5356. $ap = "";
  5357. if ($status == 4) {
  5358. $ap = 4;
  5359. $status = 2;
  5360. }
  5361. // get Receipt By verifyID status 2
  5362. $receiptList = $receipt->find ( array (
  5363. 'where' => 'rid =' . $rid . ' and status=2',
  5364. 'desc' => 'rid',
  5365. 'asArray' => true
  5366. ) );
  5367. if (empty ( $receiptList )) {
  5368. die ( 'illegal request' );
  5369. }
  5370. $loanList = $loanReceipt->find ( array (
  5371. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5372. 'desc' => 'rid',
  5373. 'asArray' => true
  5374. ) );
  5375. $data ['explanation'] = '';
  5376. if (! empty ( $loanList ))
  5377. $data ['explanation'] = $loanList [0] ['explanation'];
  5378. $Locate = 0;
  5379. $roleId = 0;
  5380. $button = 0;
  5381. foreach ( $loanList as $key => $value ) {
  5382. $loanList [$key] ['Locate'] = $Locate;
  5383. $Locate ++;
  5384. $loanList [$key] ['reviseDetail'] = array ();
  5385. if (! empty ( $value ['reviseDetail'] ))
  5386. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5387. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5388. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5389. $categoryDetil = $Lcategory->getOne ( array (
  5390. 'where' => 'cid=' . $value ['cid'],
  5391. 'asArray' => true
  5392. ) );
  5393. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5394. // 检测编辑状态
  5395. $verifyList = $verify->getOne ( array (
  5396. 'where' => 'vid=' . $value ['verify'],
  5397. 'asArray' => true
  5398. ) );
  5399. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5400. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5401. Doo::loadModel ( 'role' );
  5402. $role = new role ();
  5403. $flag = true;
  5404. $roleKey = 0;
  5405. $endStaffArray = array ();
  5406. $roleArrayCopy = array ();
  5407. foreach ( $verifyList as $k => $v ) {
  5408. // init verifyStaff
  5409. if ($v [1] == 'ROLE') {
  5410. if (! empty ( $verifyStaff )) {
  5411. $endStaffArray = end ( $verifyStaff );
  5412. }
  5413. $roleVerify = json_decode ( $v [3], true );
  5414. $roleKey = $k;
  5415. $roleArray = array ();
  5416. $rolename = $role->getOne ( array (
  5417. 'where' => 'rid=' . $v [0],
  5418. 'asArray' => true
  5419. ) );
  5420. foreach ( $roleVerify as $o => $p ) {
  5421. $staffID = explode ( '_', $p );
  5422. $staffInfo = $staff->getOne ( array (
  5423. 'where' => 'sid=' . $staffID [0],
  5424. 'asArray' => true
  5425. ) );
  5426. // print_r($staffID);
  5427. $exp = array (
  5428. 0 => $staffInfo ['sid'],
  5429. 1 => $staffID [1],
  5430. 2 => $staffInfo ['avatar'],
  5431. 'date' => '',
  5432. 'date' => '',
  5433. 'opinion' => '',
  5434. 'status' => '',
  5435. 'rolename' => $rolename ['name']
  5436. );
  5437. array_push ( $roleArray, $exp );
  5438. }
  5439. $roleArrayCopy [$v [0]] = $roleArray;
  5440. // $verifyList[$k]['roleArray']=$roleArray;
  5441. }
  5442. $verifyList [$k] ['date'] = "";
  5443. $verifyList [$k] ['opinion'] = "";
  5444. $verifyList [$k] ['status'] = "";
  5445. if (empty ( $verifyStaff )) {
  5446. $verifyList [$k] ['date'] = "";
  5447. $verifyList [$k] ['opinion'] = "";
  5448. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5449. $verifyList [$k] ['status'] = 4;
  5450. $flag = false;
  5451. }
  5452. } else {
  5453. foreach ( $verifyStaff as $m => $u ) {
  5454. if ($v [0] == $m) {
  5455. $verifyList [$k] ['date'] = $u ['date'];
  5456. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5457. $verifyList [$k] ['status'] = $u ['status'];
  5458. $flag = false;
  5459. break;
  5460. }
  5461. }
  5462. $endStaffArray = end ( $verifyStaff );
  5463. if (isset ( $endStaffArray ['ROLE'] )) {
  5464. } else {
  5465. }
  5466. }
  5467. }
  5468. $rolename ['name'] = '';
  5469. if (! empty ( $roleId )) {
  5470. Doo::loadModel ( 'role' );
  5471. $role = new role ();
  5472. $rolename = $role->getOne ( array (
  5473. 'where' => 'rid=' . $roleId,
  5474. 'asArray' => true
  5475. ) );
  5476. }
  5477. if (! empty ( $verifyStaff ))
  5478. $endStaffArray = end ( $verifyStaff );
  5479. $KOP = false;
  5480. foreach ( $roleArrayCopy as $P => $A ) {
  5481. foreach ( $A as $MKI => $AVL ) {
  5482. if (! empty ( $verifyStaff )) {
  5483. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5484. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5485. $button = 4;
  5486. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5487. }
  5488. foreach ( $verifyStaff as $m => $u ) {
  5489. $AVLFK = $AVL [0] . '_R';
  5490. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5491. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5492. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5493. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5494. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5495. break;
  5496. }
  5497. }
  5498. } else {
  5499. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5500. $button = 4;
  5501. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5502. }
  5503. }
  5504. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5505. $KOP = true;
  5506. }
  5507. }
  5508. foreach ( $roleArrayCopy as $k => $v ) {
  5509. foreach ( $verifyList as $m => $n ) {
  5510. if ($n [0] == $k) {
  5511. array_splice ( $verifyList, $m, 1, $v );
  5512. }
  5513. }
  5514. }
  5515. $loanList [$key] ['verifyList'] = $verifyList;
  5516. }
  5517. $htmlLoan = '';
  5518. $data ['loanReceiptDate'] = '';
  5519. if (isset ( $loanList [0] )) {
  5520. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5521. if ($value ['status'] == 1)
  5522. $htmlLoan .= '<li class="done" >';
  5523. elseif ($value ['status'] == 3)
  5524. $htmlLoan .= '<li class="undone" >';
  5525. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5526. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5527. if (isset ( $value ['rolename'] ))
  5528. $htmlLoan .= $value ['rolename'];
  5529. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5530. }
  5531. $data ['loanDate'] = $loanList [0] ['date'];
  5532. } else {
  5533. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5534. }
  5535. $data ['htmlLoan'] = $htmlLoan;
  5536. // $data ['LoanReceipt']=$loanList[0];
  5537. // print_r($loanList);
  5538. $Locate = 0;
  5539. $roleId = 0;
  5540. $button = 0;
  5541. if ($ap == 4)
  5542. $status = 4;
  5543. Doo::loadClass ( 'XDeode' );
  5544. $XDeode = new XDeode ( 5 );
  5545. foreach ( $receiptList as $key => $value ) {
  5546. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5547. $receiptList [$key] ['Locate'] = $Locate;
  5548. $Locate ++;
  5549. $receiptList [$key] ['reviseDetail'] = array ();
  5550. // 调整金额 代码调整
  5551. if (! empty ( $value ['reviseDetail'] )) {
  5552. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5553. foreach ( $reviseDetail as $ry => $re ) {
  5554. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5555. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5556. }
  5557. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5558. // print_r($reviseDetail);
  5559. }
  5560. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5561. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5562. $categoryDetil = $Lcategory->getOne ( array (
  5563. 'where' => 'cid=' . $value ['cid'],
  5564. 'asArray' => true
  5565. ) );
  5566. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5567. // 检测编辑状态
  5568. $verifyList = $verify->getOne ( array (
  5569. 'where' => 'vid=' . $value ['verify'],
  5570. 'asArray' => true
  5571. ) );
  5572. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5573. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5574. Doo::loadModel ( 'role' );
  5575. $role = new role ();
  5576. // print_r($verifyList);
  5577. $flag = true;
  5578. $roleKey = 0;
  5579. $endStaffArray = array ();
  5580. $roleArrayCopy = array ();
  5581. foreach ( $verifyList as $k => $v ) {
  5582. // init verifyStaff
  5583. if ($v [1] == 'ROLE') {
  5584. if (! empty ( $verifyStaff )) {
  5585. $endStaffArray = end ( $verifyStaff );
  5586. if ($v [0] == $endStaffArray ['nextStaff']) {
  5587. $roleId = $v [0];
  5588. }
  5589. }
  5590. $roleVerify = json_decode ( $v [3], true );
  5591. $roleKey = $k;
  5592. $roleArray = array ();
  5593. $rolename = $role->getOne ( array (
  5594. 'where' => 'rid=' . $v [0],
  5595. 'asArray' => true
  5596. ) );
  5597. foreach ( $roleVerify as $o => $p ) {
  5598. $staffID = explode ( '_', $p );
  5599. $staffInfo = $staff->getOne ( array (
  5600. 'where' => 'sid=' . $staffID [0],
  5601. 'asArray' => true
  5602. ) );
  5603. // print_r($staffID);
  5604. $exp = array (
  5605. 0 => $staffInfo ['sid'],
  5606. 1 => $staffID [1],
  5607. 2 => $staffInfo ['avatar'],
  5608. 'date' => '',
  5609. 'date' => '',
  5610. 'opinion' => '',
  5611. 'status' => '',
  5612. 'rolename' => $rolename ['name']
  5613. );
  5614. array_push ( $roleArray, $exp );
  5615. }
  5616. $roleArrayCopy [$v [0]] = $roleArray;
  5617. // $verifyList[$k]['roleArray']=$roleArray;
  5618. }
  5619. // print_r($roleArray);
  5620. $verifyList [$k] ['date'] = "";
  5621. $verifyList [$k] ['opinion'] = "";
  5622. $verifyList [$k] ['status'] = "";
  5623. if (empty ( $verifyStaff )) {
  5624. $verifyList [$k] ['date'] = "";
  5625. $verifyList [$k] ['opinion'] = "";
  5626. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5627. $verifyList [$k] ['status'] = 4;
  5628. $button = 4;
  5629. $flag = false;
  5630. }
  5631. } else {
  5632. foreach ( $verifyStaff as $m => $u ) {
  5633. if ($v [0] == $m) {
  5634. $verifyList [$k] ['date'] = $u ['date'];
  5635. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5636. $verifyList [$k] ['status'] = $u ['status'];
  5637. $flag = false;
  5638. break;
  5639. }
  5640. }
  5641. $endStaffArray = end ( $verifyStaff );
  5642. if (isset ( $endStaffArray ['ROLE'] )) {
  5643. } else {
  5644. $endKey = key ( $verifyStaff );
  5645. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5646. $button = 4;
  5647. $verifyList [$k] ['status'] = 4;
  5648. }
  5649. }
  5650. }
  5651. }
  5652. $rolename ['name'] = '';
  5653. if (! empty ( $roleId )) {
  5654. Doo::loadModel ( 'role' );
  5655. $role = new role ();
  5656. $rolename = $role->getOne ( array (
  5657. 'where' => 'rid=' . $roleId,
  5658. 'asArray' => true
  5659. ) );
  5660. }
  5661. if (! empty ( $verifyStaff ))
  5662. $endStaffArray = end ( $verifyStaff );
  5663. $KOP = false;
  5664. foreach ( $roleArrayCopy as $P => $A ) {
  5665. foreach ( $A as $MKI => $AVL ) {
  5666. if (! empty ( $verifyStaff )) {
  5667. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5668. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5669. $button = 4;
  5670. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5671. }
  5672. foreach ( $verifyStaff as $m => $u ) {
  5673. $AVLFK = $AVL [0] . '_R';
  5674. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5675. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5676. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5677. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5678. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5679. break;
  5680. }
  5681. }
  5682. } else {
  5683. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5684. $button = 4;
  5685. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5686. }
  5687. }
  5688. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5689. $KOP = true;
  5690. }
  5691. }
  5692. foreach ( $roleArrayCopy as $k => $v ) {
  5693. foreach ( $verifyList as $m => $n ) {
  5694. if ($n [0] == $k) {
  5695. array_splice ( $verifyList, $m, 1, $v );
  5696. }
  5697. }
  5698. }
  5699. // print_r($verifyList);
  5700. $receiptList [$key] ['verifyList'] = $verifyList;
  5701. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5702. 'where' => 'sid=' . $value ['staff'],
  5703. 'asArray' => true
  5704. ) );
  5705. $receiptList [$key] ['button'] = $button;
  5706. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5707. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5708. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5709. $receiptList [$key] ['relust'] = $relust;
  5710. $receiptList [$key] ['relustABS'] = abs ( $relust );
  5711. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5712. }
  5713. //print_r($receiptList);die;
  5714. // $data['verifyDetail']=$verifyDetail;
  5715. $mothHtml = "";
  5716. for($i = 1; $i <= 12; $i ++) {
  5717. if ($month == $i)
  5718. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5719. else
  5720. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5721. }
  5722. // 获取审批日志
  5723. Doo::loadModel ( 'receiptLog' );
  5724. $receiptLog = new receiptLog ();
  5725. $rlList = array ();
  5726. $rlInfo = $receiptLog->getOne ( array (
  5727. 'where' => 'rid=' . $rid . ' and status=4',
  5728. 'asArray' => true
  5729. ) );
  5730. $tijdate = $receiptLog->getOne ( array (
  5731. 'where' => 'rid=' . $rid . ' and status=2',
  5732. 'asc' => 'rlid',
  5733. 'asArray' => true
  5734. ) );
  5735. if (! empty ( $rlInfo )) {
  5736. $rlList = $receiptLog->find ( array (
  5737. 'where' => 'rid=' . $rid,
  5738. 'asc' => 'rlid',
  5739. 'asArray' => true
  5740. ) );
  5741. }
  5742. // echo $rid;
  5743. // print_r($receiptList);
  5744. $receiptList [0] ['rlList'] = $rlList;
  5745. // print_r($receiptList);
  5746. $enclosurList = $enclosur->find ( array (
  5747. 'where' => 'rid=' . $rid,
  5748. 'asArray' => true
  5749. ) );
  5750. $enclosurHtml = '';
  5751. foreach ( $enclosurList as $value ) {
  5752. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5753. }
  5754. $data ['enclosurHtml'] = $enclosurHtml;
  5755. $data ['rolename'] = $rolename ['name'];
  5756. $data ['mothHtml'] = $mothHtml;
  5757. // print_r($receiptList);
  5758. $data ['rid'] = $rid;
  5759. $data ['tijdate'] = $tijdate ['date'];
  5760. $data ['receiptList'] = $receiptList;
  5761. $data ['receiptApprovalCount'] = count ( $receiptList );
  5762. $data ['status'] = $status;
  5763. $data ['year'] = $year;
  5764. $data ['categoryList'] = $categoryList;
  5765. $data ['staffList'] = $staffList;
  5766. $data ['cid'] = $cid;
  5767. $data ['sid'] = $sid;
  5768. $data ['ap'] = $ap;
  5769. $data ['memu'] = "receipt";
  5770. $data ['staff'] = $this->staff;
  5771. $data ['receiptMemu'] = 'approvalExpenses';
  5772. $data ['verifyId'] = $this->verifyId;
  5773. $data ['executeId'] = $this->executeId;
  5774. $this->render ( "/admin/receiptburEdi", $data );
  5775. }
  5776. function hisImplement() {
  5777. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5778. if (empty ( $item ))
  5779. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5780. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5781. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5782. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5783. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5784. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5785. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5786. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5787. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5788. Doo::loadClass ( 'XDeode' );
  5789. $XDeode = new XDeode ( 5 );
  5790. Doo::loadModel ( 'receipt' );
  5791. $receipt = new receipt ();
  5792. Doo::loadModel ( 'L_category' );
  5793. $Lcategory = new L_category ();
  5794. Doo::loadModel ( 'verify' );
  5795. Doo::loadModel ( 'statistics' );
  5796. $statistics = new statistics ();
  5797. $verify = new verify ();
  5798. Doo::loadModel ( 'staff' );
  5799. $staff = new staff ();
  5800. Doo::loadClass ( 'XDeode' );
  5801. $XDeode = new XDeode ( 5 );
  5802. $XDeode7 = new XDeode ( 7 );
  5803. $cid = $XDeode->decode ( $cidKey );
  5804. $condition = "";
  5805. if ($item == "expenses")
  5806. $condition = " and Rtype=1 ";
  5807. elseif ($item == "receipts")
  5808. $condition = " and Rtype=0 ";
  5809. elseif ($item == "remits")
  5810. $condition = " and Rtype=2 ";
  5811. elseif($item == "train")
  5812. $condition = " and Rtype=3 ";
  5813. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5814. $sopString = $cidString = "";
  5815. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5816. if (empty ( $rdate ))
  5817. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5818. else
  5819. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5820. if ($status == 'pendImplement') {
  5821. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5822. } elseif ($status == 'alerpts') {
  5823. $statusCon = '(status=8 or status=9 )';
  5824. if (empty ( $rdate ))
  5825. $dateCondition .= " and Year(date) =" . $year;
  5826. else
  5827. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5828. }
  5829. if ($sop != 'SOP')
  5830. $sopString = " and staff=" . $sop;
  5831. if ($cidKey != 'ALL')
  5832. $cidString = " and cid=" . $cid;
  5833. //汇款信息需要提取出来
  5834. if(!empty($receiptOrder)){
  5835. $receiptList = $receipt->find ( array (
  5836. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5837. 'desc' => 'rid',
  5838. 'asArray' => true
  5839. ) );
  5840. // 员工筛选
  5841. $receiptList2 = $receipt->find ( array (
  5842. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5843. 'desc' => 'rid',
  5844. 'asArray' => true
  5845. ) );
  5846. }else{
  5847. $receiptList = $receipt->find ( array (
  5848. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5849. 'desc' => 'rid',
  5850. 'asArray' => true
  5851. ) );
  5852. // 员工筛选
  5853. $receiptList2 = $receipt->find ( array (
  5854. 'where' => $statusCon . $condition . $dateCondition,
  5855. 'desc' => 'rid',
  5856. 'asArray' => true
  5857. ) );
  5858. }
  5859. $sopStaff = array ();
  5860. foreach ( $receiptList2 as $key => $value ) {
  5861. $staffDetail = $staff->getOne ( array (
  5862. 'select' => 'username',
  5863. 'where' => 'sid=' . $value ['staff'],
  5864. 'asArray' => true
  5865. ) );
  5866. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5867. }
  5868. // 办事处筛选
  5869. $categoryScreen = array ();
  5870. $categorList = $Lcategory->getCategory ();
  5871. foreach ( $receiptList2 as $key => $value ) {
  5872. foreach ( $categorList as $k => $v ) {
  5873. if ($value ['cid'] == $v ['cid']) {
  5874. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5875. break;
  5876. }
  5877. }
  5878. }
  5879. $categoryScreenHtml = "";
  5880. foreach ( $categoryScreen as $key => $value ) {
  5881. if ($cidKey == $key)
  5882. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5883. else
  5884. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5885. }
  5886. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5887. $data ['cidKey'] = $cidKey;
  5888. $Locate = 0;
  5889. $roleId = 0;
  5890. $button = 0;
  5891. $staffBatchNumber = 100001;
  5892. $remittanceList = array ();
  5893. foreach ( $receiptList as $key => $value ) {
  5894. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5895. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5896. $receiptList [$key] ['Texe'] = 'false';
  5897. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5898. $receiptList [$key] ['Texe'] = 'true';
  5899. }
  5900. $receiptList [$key] ['TRexe'] = 'true';
  5901. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5902. $receiptList [$key] ['TRexe'] = 'false';
  5903. }
  5904. $receiptList [$key] ['Locate'] = $Locate;
  5905. $Locate ++;
  5906. $receiptList [$key] ['reviseDetail'] = array ();
  5907. if (! empty ( $value ['reviseDetail'] ))
  5908. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5909. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5910. $categoryDetil = $Lcategory->getOne ( array (
  5911. 'where' => 'cid=' . $value ['cid'],
  5912. 'asArray' => true
  5913. ) );
  5914. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5915. // 检测编辑状态
  5916. $verifyList = $verify->getOne ( array (
  5917. 'where' => 'vid=' . $value ['verify'],
  5918. 'asArray' => true
  5919. ) );
  5920. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5921. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5922. Doo::loadModel ( 'role' );
  5923. $role = new role ();
  5924. $flag = true;
  5925. $roleKey = 0;
  5926. $endStaffArray = array ();
  5927. $roleArrayCopy = array ();
  5928. foreach ( $verifyList as $k => $v ) {
  5929. // init verifyStaff
  5930. if ($v [1] == 'ROLE') {
  5931. if (! empty ( $verifyStaff )) {
  5932. $endStaffArray = end ( $verifyStaff );
  5933. }
  5934. $roleVerify = json_decode ( $v [3], true );
  5935. $roleKey = $k;
  5936. $roleArray = array ();
  5937. $rolename = $role->getOne ( array (
  5938. 'where' => 'rid=' . $v [0],
  5939. 'asArray' => true
  5940. ) );
  5941. foreach ( $roleVerify as $o => $p ) {
  5942. $staffID = explode ( '_', $p );
  5943. $staffInfo = $staff->getOne ( array (
  5944. 'where' => 'sid=' . $staffID [0],
  5945. 'asArray' => true
  5946. ) );
  5947. $exp = array (
  5948. 0 => $staffInfo ['sid'],
  5949. 1 => $staffID [1],
  5950. 2 => $staffInfo ['avatar'],
  5951. 'date' => '',
  5952. 'date' => '',
  5953. 'opinion' => '',
  5954. 'status' => '',
  5955. 'rolename' => $rolename ['name']
  5956. );
  5957. array_push ( $roleArray, $exp );
  5958. }
  5959. $roleArrayCopy [$v [0]] = $roleArray;
  5960. }
  5961. $verifyList [$k] ['date'] = "";
  5962. $verifyList [$k] ['opinion'] = "";
  5963. $verifyList [$k] ['status'] = "";
  5964. if (empty ( $verifyStaff )) {
  5965. $verifyList [$k] ['date'] = "";
  5966. $verifyList [$k] ['opinion'] = "";
  5967. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5968. $verifyList [$k] ['status'] = 4;
  5969. $flag = false;
  5970. }
  5971. } else {
  5972. foreach ( $verifyStaff as $m => $u ) {
  5973. if ($v [0] == $m) {
  5974. $verifyList [$k] ['date'] = $u ['date'];
  5975. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5976. $verifyList [$k] ['status'] = $u ['status'];
  5977. $flag = false;
  5978. break;
  5979. }
  5980. }
  5981. $endStaffArray = end ( $verifyStaff );
  5982. }
  5983. }
  5984. $rolename ['name'] = '';
  5985. if (! empty ( $roleId )) {
  5986. Doo::loadModel ( 'role' );
  5987. $role = new role ();
  5988. $rolename = $role->getOne ( array (
  5989. 'where' => 'rid=' . $roleId,
  5990. 'asArray' => true
  5991. ) );
  5992. }
  5993. if (! empty ( $verifyStaff ))
  5994. $endStaffArray = end ( $verifyStaff );
  5995. $KOP = false;
  5996. foreach ( $roleArrayCopy as $P => $A ) {
  5997. foreach ( $A as $MKI => $AVL ) {
  5998. if (! empty ( $verifyStaff )) {
  5999. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6000. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6001. $button = 4;
  6002. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6003. }
  6004. foreach ( $verifyStaff as $m => $u ) {
  6005. $AVLFK = $AVL [0] . '_R';
  6006. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6007. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6008. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6009. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6010. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6011. break;
  6012. }
  6013. }
  6014. } else {
  6015. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6016. $button = 4;
  6017. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6018. }
  6019. }
  6020. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6021. $KOP = true;
  6022. }
  6023. }
  6024. foreach ( $roleArrayCopy as $k => $v ) {
  6025. foreach ( $verifyList as $m => $n ) {
  6026. if ($n [0] == $k) {
  6027. array_splice ( $verifyList, $m, 1, $v );
  6028. }
  6029. }
  6030. }
  6031. $receiptList [$key] ['verifyList'] = $verifyList;
  6032. $staffDetail = $staff->getOne ( array (
  6033. 'where' => 'sid=' . $value ['staff'],
  6034. 'asArray' => true
  6035. ) );
  6036. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6037. $receiptList [$key] ['button'] = $button;
  6038. if ($value['Rtype']==1){
  6039. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  6040. $receiptList [$key] ['relustABS'] = abs($receiptList [$key] ['relust']);
  6041. }elseif($value['Rtype']==3){
  6042. // 收入合计
  6043. Doo::loadModel ( 'invoiceTraining' );
  6044. $invoiceTraining = new invoiceTraining ();
  6045. $invoiceTrainingDetail = array (
  6046. 'invoiceArriveAmount' => '0.00',
  6047. 'RIAmount' => '0.00',
  6048. 'invoiceTotalAmount' => '0.00',
  6049. 'invoiceCompanyAmount' => '0.00',
  6050. 'invoiceArriveAmountM'=>'0.00',
  6051. 'invoiceCompanyAmountM'=>'0.00'
  6052. );
  6053. if ($value ['invoiceTrainId'] != 0) {
  6054. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  6055. }
  6056. $invoiceArriveAmount = $RIAmount = 0;
  6057. if (! empty ( $invoiceTrainingDetail )) {
  6058. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  6059. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  6060. }
  6061. // 备用金
  6062. $sum = 0;
  6063. if (! empty ( $value ['trainLoanRid'] )) {
  6064. $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  6065. $sum = $receiptLoanDetailBak ['sum'];
  6066. }
  6067. // 支出项金额详情
  6068. // 项目金额合计
  6069. Doo::loadModel ( 'RItem' );
  6070. $RItem = new RItem ();
  6071. Doo::loadModel ( 'accountItem' );
  6072. $accountItem = new accountItem ();
  6073. // 讲师获得
  6074. Doo::loadModel ( 'RILecturer' );
  6075. $RILecturer = new RILecturer ();
  6076. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  6077. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  6078. // 支出项金额详情
  6079. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  6080. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  6081. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  6082. $receiptList [$key] ['payment'] =$payment;
  6083. $receiptList [$key] ['paymentABS'] =abs($payment);
  6084. }
  6085. // 设置导出汇款execl
  6086. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6087. $remittanceDetail = array (
  6088. $staffBatchNumber,
  6089. $value ['remittanceName'],
  6090. $value ['bankNumber'],
  6091. $value ['bankName'],
  6092. $value ['remittanceBankType'],
  6093. $value ['coupletNumber'],
  6094. $value ['sum']
  6095. );
  6096. array_push ( $remittanceList, $remittanceDetail );
  6097. $staffBatchNumber ++;
  6098. }
  6099. }
  6100. $data ['remittanceList'] = json_encode ( $remittanceList );
  6101. // print_r($receiptList);
  6102. $mothHtml = "";
  6103. for($i = 1; $i <= 12; $i ++) {
  6104. if ($moth == $i)
  6105. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6106. else
  6107. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6108. }
  6109. $dayHtml = "";
  6110. if ($day != "DAY" || $moth != "MONTH") {
  6111. for($i = 1; $i <= 31; $i ++) {
  6112. if ($day == $i)
  6113. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6114. else
  6115. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6116. }
  6117. }
  6118. $sopHtml = "";
  6119. foreach ( $sopStaff as $key => $value ) {
  6120. if ($sop == $key)
  6121. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6122. else
  6123. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6124. }
  6125. $data ['status'] = $status;
  6126. $data ['rdate'] = $rdate;
  6127. $data ['sopHtml'] = $sopHtml;
  6128. $data ['dayHtml'] = $dayHtml;
  6129. $data ['mothHtml'] = $mothHtml;
  6130. $data ['receiptList'] = $receiptList;
  6131. $data ['memu'] = "receipt";
  6132. $data ['staff'] = $this->staff;
  6133. $data ['receiptMemu'] = 'implement';
  6134. $data ['verifyId'] = $this->verifyId;
  6135. $data ['executeId'] = $this->executeId;
  6136. $data ['item'] = $item;
  6137. $data ['year'] = $year;
  6138. $data ['moth'] = $moth;
  6139. $data['receiptOrder']=$receiptOrder;
  6140. $data ['day'] = $day;
  6141. $data ['sop'] = $sop;
  6142. $this->render ( "/admin/hisImplement", $data );
  6143. }
  6144. /**
  6145. * 导出汇款信息的exelc
  6146. */
  6147. function exportRemittance() {
  6148. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6149. if (empty ( $remittanceInfo ))
  6150. die ( 'illegal request' );
  6151. $title = array (
  6152. '员工编号',
  6153. '姓名',
  6154. '员工账号',
  6155. '员工账户开户行',
  6156. '转账类型',
  6157. '联行号',
  6158. '金额'
  6159. );
  6160. $data = json_decode ( $remittanceInfo, true );
  6161. if (empty ( $data ))
  6162. die ( 'illegal request' );
  6163. Doo::loadClass ( 'receipt.func' );
  6164. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6165. header ( 'Content-Type:text/html;charset=utf-8' );
  6166. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6167. }
  6168. function ajaxExamine() {
  6169. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6170. Doo::loadModel ( 'receipt' );
  6171. $receipt = new receipt ();
  6172. if (! empty ( $rid )) {
  6173. $rLRes = $receipt->find ( array (
  6174. '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,
  6175. 'asArray' => true
  6176. ) );
  6177. echo json_encode ( array (
  6178. 'status' => 1,
  6179. 'receipt' => $rLRes [0]
  6180. ) );
  6181. die ();
  6182. }
  6183. echo json_encode ( array (
  6184. 'status' => 0,
  6185. 'receipt' => array ()
  6186. ) );
  6187. die ();
  6188. }
  6189. /*
  6190. * 废弃
  6191. */
  6192. function myReceipt() {
  6193. // all approval past withdraw
  6194. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6195. if (empty ( $item ))
  6196. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6197. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6198. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6199. Doo::loadModel ( 'receipt' );
  6200. $receipt = new receipt ();
  6201. // pre-loaded
  6202. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6203. // have cache
  6204. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6205. if (! empty ( $moth )) // yearPage
  6206. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6207. $this->showCache ( $path );
  6208. }
  6209. Doo::loadModel ( 'L_category' );
  6210. $Lcategory = new L_category ();
  6211. Doo::loadModel ( 'verify' );
  6212. Doo::loadModel ( 'statistics' );
  6213. $statistics = new statistics ();
  6214. $verify = new verify ();
  6215. Doo::loadModel ( 'staff' );
  6216. $staff = new staff ();
  6217. $condition = " and status!=0 ";
  6218. if ($item == "approval")
  6219. $condition = " and status=2 ";
  6220. elseif ($item == "withdraw")
  6221. $condition = " and status=3 ";
  6222. elseif ($item == "past")
  6223. $condition = " and status=1 ";
  6224. elseif ($item == "whdw")
  6225. $condition = " and status=4 ";
  6226. $dateCondition = " and Year(date) =" . $year;
  6227. if (! empty ( $moth )) {
  6228. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6229. $stList = $statistics->getOne ( array (
  6230. 'select' => 'rePrice ,agPrice',
  6231. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6232. 'asArray' => true
  6233. ) );
  6234. } else
  6235. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6236. if (empty ( $stList ))
  6237. $stList = array (
  6238. 'rePrice' => 0,
  6239. 'agPrice' => 0
  6240. );
  6241. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6242. $data ['stList'] = array (
  6243. 'rePrice' => $stList ['rePrice'],
  6244. 'agPrice' => $stList ['agPrice'],
  6245. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6246. );
  6247. $receiptList = $receipt->find ( array (
  6248. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6249. 'desc' => 'rid',
  6250. 'asArray' => true
  6251. ) );
  6252. $Locate = 0;
  6253. $roleId = 0;
  6254. $button = 0;
  6255. foreach ( $receiptList as $key => $value ) {
  6256. $receiptList [$key] ['Locate'] = $Locate;
  6257. $Locate ++;
  6258. $receiptList [$key] ['reviseDetail'] = array ();
  6259. if (! empty ( $value ['reviseDetail'] ))
  6260. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6261. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6262. $categoryDetil = $Lcategory->getOne ( array (
  6263. 'where' => 'cid=' . $value ['cid'],
  6264. 'asArray' => true
  6265. ) );
  6266. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6267. // 检测编辑状态
  6268. $verifyList = $verify->getOne ( array (
  6269. 'where' => 'vid=' . $value ['verify'],
  6270. 'asArray' => true
  6271. ) );
  6272. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6273. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6274. Doo::loadModel ( 'role' );
  6275. $role = new role ();
  6276. $flag = true;
  6277. $roleKey = 0;
  6278. $endStaffArray = array ();
  6279. $roleArrayCopy = array ();
  6280. foreach ( $verifyList as $k => $v ) {
  6281. // init verifyStaff
  6282. if ($v [1] == 'ROLE') {
  6283. if (! empty ( $verifyStaff )) {
  6284. $endStaffArray = end ( $verifyStaff );
  6285. // if ($v[0]==$endStaffArray['nextStaff']){
  6286. // $roleId=$v[0];
  6287. // }
  6288. }
  6289. $roleVerify = json_decode ( $v [3], true );
  6290. $roleKey = $k;
  6291. $roleArray = array ();
  6292. $rolename = $role->getOne ( array (
  6293. 'where' => 'rid=' . $v [0],
  6294. 'asArray' => true
  6295. ) );
  6296. foreach ( $roleVerify as $o => $p ) {
  6297. $staffID = explode ( '_', $p );
  6298. $staffInfo = $staff->getOne ( array (
  6299. 'where' => 'sid=' . $staffID [0],
  6300. 'asArray' => true
  6301. ) );
  6302. // print_r($staffID);
  6303. $exp = array (
  6304. 0 => $staffInfo ['sid'],
  6305. 1 => $staffID [1],
  6306. 2 => $staffInfo ['avatar'],
  6307. 'date' => '',
  6308. 'date' => '',
  6309. 'opinion' => '',
  6310. 'status' => '',
  6311. 'rolename' => $rolename ['name']
  6312. );
  6313. array_push ( $roleArray, $exp );
  6314. }
  6315. $roleArrayCopy [$v [0]] = $roleArray;
  6316. // $verifyList[$k]['roleArray']=$roleArray;
  6317. }
  6318. $verifyList [$k] ['date'] = "";
  6319. $verifyList [$k] ['opinion'] = "";
  6320. $verifyList [$k] ['status'] = "";
  6321. if (empty ( $verifyStaff )) {
  6322. $verifyList [$k] ['date'] = "";
  6323. $verifyList [$k] ['opinion'] = "";
  6324. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6325. $verifyList [$k] ['status'] = 4;
  6326. $flag = false;
  6327. }
  6328. } else {
  6329. foreach ( $verifyStaff as $m => $u ) {
  6330. if ($v [0] == $m) {
  6331. $verifyList [$k] ['date'] = $u ['date'];
  6332. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6333. $verifyList [$k] ['status'] = $u ['status'];
  6334. $flag = false;
  6335. break;
  6336. }
  6337. }
  6338. $endStaffArray = end ( $verifyStaff );
  6339. if (isset ( $endStaffArray ['ROLE'] )) {
  6340. } else {
  6341. // $endKey=key($verifyStaff);
  6342. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6343. // $button=4;
  6344. // $verifyList[$k]['status']=4;
  6345. // }
  6346. }
  6347. }
  6348. }
  6349. $rolename ['name'] = '';
  6350. if (! empty ( $roleId )) {
  6351. Doo::loadModel ( 'role' );
  6352. $role = new role ();
  6353. $rolename = $role->getOne ( array (
  6354. 'where' => 'rid=' . $roleId,
  6355. 'asArray' => true
  6356. ) );
  6357. }
  6358. if (! empty ( $verifyStaff ))
  6359. $endStaffArray = end ( $verifyStaff );
  6360. $KOP = false;
  6361. foreach ( $roleArrayCopy as $P => $A ) {
  6362. foreach ( $A as $MKI => $AVL ) {
  6363. if (! empty ( $verifyStaff )) {
  6364. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6365. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6366. $button = 4;
  6367. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6368. }
  6369. foreach ( $verifyStaff as $m => $u ) {
  6370. $AVLFK = $AVL [0] . '_R';
  6371. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6372. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6373. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6374. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6375. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6376. break;
  6377. }
  6378. }
  6379. } else {
  6380. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6381. $button = 4;
  6382. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6383. }
  6384. }
  6385. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6386. $KOP = true;
  6387. }
  6388. }
  6389. foreach ( $roleArrayCopy as $k => $v ) {
  6390. foreach ( $verifyList as $m => $n ) {
  6391. if ($n [0] == $k) {
  6392. array_splice ( $verifyList, $m, 1, $v );
  6393. }
  6394. }
  6395. }
  6396. $receiptList [$key] ['verifyList'] = $verifyList;
  6397. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6398. 'where' => 'sid=' . $value ['staff'],
  6399. 'asArray' => true
  6400. ) );
  6401. $receiptList [$key] ['button'] = $button;
  6402. }
  6403. // print_r($receiptList);die;
  6404. $mothHtml = "";
  6405. for($i = 1; $i <= 12; $i ++) {
  6406. if ($moth == $i)
  6407. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6408. else
  6409. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6410. }
  6411. $data ['mothHtml'] = $mothHtml;
  6412. $data ['receiptList'] = $receiptList;
  6413. $data ['memu'] = "receipt";
  6414. $data ['staff'] = $this->staff;
  6415. $data ['receiptMemu'] = 'receipt';
  6416. $data ['verifyId'] = $this->verifyId;
  6417. $data ['executeId'] = $this->executeId;
  6418. $data ['item'] = $item;
  6419. $data ['year'] = $year;
  6420. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6421. // sufficient condition to generate cache
  6422. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6423. $receiptList = $receipt->find ( array (
  6424. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6425. 'asArray' => true
  6426. ) );
  6427. if (empty ( $receiptList )) { // generated files
  6428. ob_start ();
  6429. $this->render ( "/admin/saea_myList", $data );
  6430. $this->cacheFile ( $path );
  6431. die ();
  6432. // $content = ob_get_contents();
  6433. // $fp = fopen($path, "w");
  6434. // fwrite($fp, $content);
  6435. // fclose($fp);
  6436. }
  6437. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6438. $receiptList = $receipt->find ( array (
  6439. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6440. 'asArray' => true
  6441. ) );
  6442. if (empty ( $receiptList )) { // generated files
  6443. ob_start ();
  6444. $this->render ( "/admin/saea_myList", $data );
  6445. $this->cacheFile ( $path );
  6446. die ();
  6447. }
  6448. }
  6449. }
  6450. $this->render ( "/admin/saea_myList", $data );
  6451. }
  6452. function saeaCreate() {
  6453. Doo::loadModel ( 'accountItem' );
  6454. Doo::loadModel ( 'verify' );
  6455. Doo::loadModel ( 'receipt' );
  6456. Doo::loadModel ( 'L_category' );
  6457. $lCategory = new L_category ();
  6458. $receipt = new receipt ();
  6459. $verify = new verify ();
  6460. $accountItem = new accountItem ();
  6461. Doo::loadModel ( "role" );
  6462. $role = new role ();
  6463. $acItem = $accountItem->find ( array (
  6464. 'asArray' => true
  6465. ) );
  6466. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6467. $data ['category'] = $lCategory->find ( array (
  6468. 'asArray' => true
  6469. ) );
  6470. $data ['veList'] = $veList;
  6471. $data ['acItem'] = $acItem;
  6472. $data ['memu'] = "receipt";
  6473. $data ['staff'] = $this->staff;
  6474. $data ['receiptMemu'] = 'saeaBorad';
  6475. $data ['verifyId'] = $this->verifyId;
  6476. $data ['executeId'] = $this->executeId;
  6477. $this->render ( "/admin/saea_create", $data );
  6478. }
  6479. function addReceipt() {
  6480. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6481. $agency = $this->get_args ( 'agency' );
  6482. $travel = $this->get_args ( 'travel' );
  6483. $train = $this->get_args ( 'train' );
  6484. $other = $this->get_args ( 'other' );
  6485. $inttrain = $this->get_args ( 'inttrain' );
  6486. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6487. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6488. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6489. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6490. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6491. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6492. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6493. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6494. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6495. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6496. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6497. header ( 'Content-Type:text/html;charset=utf-8' );
  6498. die ( '请填写联行号' );
  6499. }
  6500. Doo::loadModel ( 'receipt' );
  6501. Doo::loadModel ( 'receiptDetail' );
  6502. Doo::loadModel ( 'accountItem' );
  6503. $accountItem = new accountItem ();
  6504. $receipt = new receipt ();
  6505. Doo::loadModel ( 'enclosur' );
  6506. Doo::loadModel ( 'execute' );
  6507. $execute = new execute ();
  6508. $executeDetail = $execute->getOne ( array (
  6509. 'where' => 'mold="报销单执行人"',
  6510. 'asArray' => true
  6511. ) );
  6512. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6513. // if(!empty($receiptDetail))
  6514. // return "/referReceipt/".$receiptDetail['rid'];
  6515. $aItem = $accountItem->find ( array (
  6516. 'asArray' => true
  6517. ) );
  6518. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6519. $ag = $tr = $ta = $ot= $it = 0;
  6520. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6521. foreach ( $aItem as $key => $value ) {
  6522. if ($value ['category'] == $this->AGENCY) {
  6523. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6524. array_push ( $accountJson [$this->AGENCY], array (
  6525. 'aid' => $value ['aid'],
  6526. 'name' => $value ['name'],
  6527. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6528. ) );
  6529. $sum += $agency [$ag];
  6530. $agencySum += $agency [$ag];
  6531. }
  6532. $ag ++;
  6533. }
  6534. if ($value ['category'] == $this->TRAVEL) {
  6535. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6536. array_push ( $accountJson [$this->TRAVEL], array (
  6537. 'aid' => $value ['aid'],
  6538. 'name' => $value ['name'],
  6539. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6540. ) );
  6541. $sum += $travel [$tr];
  6542. $travelSum += $travel [$tr];
  6543. }
  6544. $tr ++;
  6545. }
  6546. if ($value ['category'] == $this->TRAIN) {
  6547. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6548. array_push ( $accountJson [$this->TRAIN], array (
  6549. 'aid' => $value ['aid'],
  6550. 'name' => $value ['name'],
  6551. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6552. ) );
  6553. $sum += $train [$ta];
  6554. $trainSum += $train [$ta];
  6555. }
  6556. $ta ++;
  6557. }
  6558. if ($value ['category'] == $this->INTTRAIN) {
  6559. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6560. array_push ( $accountJson [$this->INTTRAIN], array (
  6561. 'aid' => $value ['aid'],
  6562. 'name' => $value ['name'],
  6563. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6564. ) );
  6565. $sum += $inttrain [$it];
  6566. $inttrainSum += $inttrain [$it];
  6567. }
  6568. $it ++;
  6569. }
  6570. if ($value ['category'] == $this->OTHER) {
  6571. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6572. array_push ( $accountJson [$this->OTHER], array (
  6573. 'aid' => $value ['aid'],
  6574. 'name' => $value ['name'],
  6575. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6576. ) );
  6577. $sum += $other [$ot];
  6578. $otherSum += $other [$ot];
  6579. }
  6580. $ot ++;
  6581. }
  6582. }
  6583. $accountJson ['cSum'] = array (
  6584. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6585. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6586. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6587. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6588. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6589. );
  6590. // 报销单
  6591. $receipt->accountItem = json_encode ( $accountJson );
  6592. $receipt->staff = $this->staff [0] ['sid'];
  6593. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6594. $receipt->date = date ( "Y-m-d" );
  6595. $receipt->cid = $cid;
  6596. $receipt->status = 5;
  6597. // 修改审批流程加入角色
  6598. $receipt->verify = $verify;
  6599. $receipt->executeCopy = $executeDetail ['staff'];
  6600. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6601. $order = array (
  6602. "\r\n",
  6603. "\n",
  6604. "\r"
  6605. );
  6606. $replace = '<br/>';
  6607. $explanation = str_replace ( $order, $replace, $explanation );
  6608. $receipt->explanation = $explanation;
  6609. $receipt->remittanceName = $remittanceName;
  6610. $receipt->bankName = $bankName;
  6611. $receipt->bankNumber = $bankNumber;
  6612. $receipt->remittanceBankType = $remittanceBankType;
  6613. if ($remittanceBankType == 1)
  6614. $receipt->coupletNumber = $coupletNumber;
  6615. $rid = $receipt->insert ();
  6616. // 附件
  6617. if (! empty ( $enclosurName )) {
  6618. $enclosurArray = explode ( '-', $enclosurName );
  6619. foreach ( $enclosurArray as $value ) {
  6620. $enclosur = new enclosur ();
  6621. $enclosur->name = $value;
  6622. $enclosur->rid = $rid;
  6623. $enclosur->insert ();
  6624. }
  6625. // print_r($enclosurArray);die;
  6626. }
  6627. // 报销详情
  6628. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6629. $receiptDetail = new receiptDetail ();
  6630. $receiptDetail->staff = $this->staff [0] ['sid'];
  6631. $receiptDetail->item = $value ['name'];
  6632. $receiptDetail->itemCategory = $this->AGENCY;
  6633. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6634. $receiptDetail->date = date ( "Y-m-d" );
  6635. $receiptDetail->cid = $cid;
  6636. $receiptDetail->rid = $rid;
  6637. $receiptDetail->status = 4;
  6638. $receiptDetail->insert ();
  6639. }
  6640. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6641. $receiptDetail = new receiptDetail ();
  6642. $receiptDetail->staff = $this->staff [0] ['sid'];
  6643. $receiptDetail->item = $value ['name'];
  6644. $receiptDetail->itemCategory = $this->TRAVEL;
  6645. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6646. $receiptDetail->date = date ( "Y-m-d" );
  6647. $receiptDetail->cid = $cid;
  6648. $receiptDetail->rid = $rid;
  6649. $receiptDetail->status = 4;
  6650. $receiptDetail->insert ();
  6651. }
  6652. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6653. $receiptDetail = new receiptDetail ();
  6654. $receiptDetail->staff = $this->staff [0] ['sid'];
  6655. $receiptDetail->item = $value ['name'];
  6656. $receiptDetail->itemCategory = $this->TRAIN;
  6657. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6658. $receiptDetail->date = date ( "Y-m-d" );
  6659. $receiptDetail->cid = $cid;
  6660. $receiptDetail->rid = $rid;
  6661. $receiptDetail->status = 4;
  6662. $receiptDetail->insert ();
  6663. }
  6664. //内训
  6665. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6666. $receiptDetail = new receiptDetail ();
  6667. $receiptDetail->staff = $this->staff [0] ['sid'];
  6668. $receiptDetail->item = $value ['name'];
  6669. $receiptDetail->itemCategory = $this->INTTRAIN;
  6670. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6671. $receiptDetail->date = date ( "Y-m-d" );
  6672. $receiptDetail->cid = $cid;
  6673. $receiptDetail->rid = $rid;
  6674. $receiptDetail->status = 4;
  6675. $receiptDetail->insert ();
  6676. }
  6677. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6678. $receiptDetail = new receiptDetail ();
  6679. $receiptDetail->staff = $this->staff [0] ['sid'];
  6680. $receiptDetail->item = $value ['name'];
  6681. $receiptDetail->itemCategory = $this->OTHER;
  6682. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6683. $receiptDetail->date = date ( "Y-m-d" );
  6684. $receiptDetail->cid = $cid;
  6685. $receiptDetail->rid = $rid;
  6686. $receiptDetail->status = 4;
  6687. $receiptDetail->insert ();
  6688. }
  6689. return "/saeaBorad";
  6690. } else
  6691. die ( 'illegal request' );
  6692. }
  6693. function referReceipt() {
  6694. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6695. Doo::loadModel ( 'receipt' );
  6696. Doo::loadModel ( 'verify' );
  6697. $verify = new verify ();
  6698. $receipt = new receipt ();
  6699. Doo::loadModel ( 'L_category' );
  6700. $lCategory = new L_category ();
  6701. Doo::loadModel ( "role" );
  6702. $role = new role ();
  6703. $receiptDetail = $receipt->find ( array (
  6704. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6705. 'asArray' => true
  6706. ) );
  6707. if (empty ( $receiptDetail ))
  6708. return "/addReceipt";
  6709. foreach ( $receiptDetail as $key => $value ) {
  6710. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6711. $veList = $verify->getOne ( array (
  6712. 'where' => 'vid=' . $value ['verify'],
  6713. 'asArray' => true
  6714. ) );
  6715. $v = json_decode ( $veList ['staff'] );
  6716. array_push ( $v [0], $veList ['description'] );
  6717. foreach ( $v as $n => $m ) {
  6718. if ($m ['1'] == 'ROLE') {
  6719. $roleInfo = $role->getOne ( array (
  6720. 'where' => 'rid=' . $m [0],
  6721. 'asArray' => true
  6722. ) );
  6723. $v [$n] [1] = $roleInfo ['name'];
  6724. }
  6725. }
  6726. $receiptDetail [$key] ['staff'] = $v;
  6727. $category = $lCategory->getOne ( array (
  6728. 'where' => 'cid=' . $value ['cid'],
  6729. 'asArray' => true
  6730. ) );
  6731. $receiptDetail [$key] ['category'] = $category ['title'];
  6732. }
  6733. // print_r($receiptDetail);
  6734. $data ['receiptDetail'] = $receiptDetail;
  6735. $data ['memu'] = "receipt";
  6736. $data ['staff'] = $this->staff;
  6737. $data ['receiptMemu'] = 'saeaCreate';
  6738. $data ['verifyId'] = $this->verifyId;
  6739. $data ['executeId'] = $this->executeId;
  6740. $this->render ( "/admin/saea_confirm", $data );
  6741. }
  6742. function editReceipt() {
  6743. // edit status 4
  6744. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6745. Doo::loadClass ( 'XDeode' );
  6746. $XDeode = new XDeode ( 7 );
  6747. $rid = $XDeode->decode ( $ridKey );
  6748. if (empty ( $rid ))
  6749. die ( 'illegal request' );
  6750. // echo $rid.'sd';
  6751. Doo::loadModel ( 'accountItem' );
  6752. Doo::loadModel ( 'verify' );
  6753. Doo::loadModel ( 'receipt' );
  6754. $receipt = new receipt ();
  6755. $verify = new verify ();
  6756. $accountItem = new accountItem ();
  6757. Doo::loadModel ( 'L_category' );
  6758. $lCategory = new L_category ();
  6759. Doo::loadModel ( "role" );
  6760. $role = new role ();
  6761. Doo::loadModel ( 'enclosur' );
  6762. $enclosur = new enclosur ();
  6763. $receiptDetail = $receipt->getOne ( array (
  6764. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6765. 'asArray' => true
  6766. ) );
  6767. if (empty ( $receiptDetail ))
  6768. die ( 'illegal request' );
  6769. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6770. $acItem = $accountItem->find ( array (
  6771. 'asArray' => true
  6772. ) );
  6773. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6774. // 配置编辑信息
  6775. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6776. foreach ( $acItem as $key => $value ) {
  6777. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6778. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6779. $acItem [$key] ['price'] = $v ['price'];
  6780. }
  6781. }
  6782. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6783. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6784. $acItem [$key] ['price'] = $v ['price'];
  6785. }
  6786. }
  6787. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6788. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6789. $acItem [$key] ['price'] = $v ['price'];
  6790. }
  6791. }
  6792. //内训
  6793. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6794. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6795. $acItem [$key] ['price'] = $v ['price'];
  6796. }
  6797. }
  6798. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6799. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6800. $acItem [$key] ['price'] = $v ['price'];
  6801. }
  6802. }
  6803. }
  6804. $data ['category'] = $lCategory->find ( array (
  6805. 'asArray' => true
  6806. ) );
  6807. $data ['cSum'] = $accountItemList ['cSum'];
  6808. $data ['sum'] = $receiptDetail ['sum'];
  6809. $data ['enclosurList'] = $enclosurList;
  6810. $data ['receiptDetail'] = $receiptDetail;
  6811. $data ['veList'] = $veList;
  6812. $data ['acItem'] = $acItem;
  6813. $data ['memu'] = "receipt";
  6814. $data ['staff'] = $this->staff;
  6815. $data ['receiptMemu'] = 'saeaBorad';
  6816. $data ['verify'] = $receiptDetail ['verify'];
  6817. $data ['verifyId'] = $this->verifyId;
  6818. $data ['executeId'] = $this->executeId;
  6819. $data ['rid'] = $ridKey;
  6820. $this->render ( "/admin/saea_edit", $data );
  6821. }
  6822. function updateReceipt() {
  6823. $agency = $this->get_args ( 'agency' );
  6824. $travel = $this->get_args ( 'travel' );
  6825. $train = $this->get_args ( 'train' );
  6826. $other = $this->get_args ( 'other' );
  6827. $inttrain = $this->get_args ( 'inttrain' );
  6828. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6829. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6830. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6831. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6832. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6833. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6834. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6835. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6836. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6837. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6838. Doo::loadClass ( 'XDeode' );
  6839. $XDeode = new XDeode ( 7 );
  6840. $rid = $XDeode->decode ( $ridKey );
  6841. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6842. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6843. header ( 'Content-Type:text/html;charset=utf-8' );
  6844. die ( '请填写联行号' );
  6845. }
  6846. Doo::loadModel ( 'receipt' );
  6847. Doo::loadModel ( 'receiptDetail' );
  6848. Doo::loadModel ( 'accountItem' );
  6849. $accountItem = new accountItem ();
  6850. $receipt = new receipt ();
  6851. Doo::loadModel ( 'enclosur' );
  6852. Doo::loadModel ( 'execute' );
  6853. $execute = new execute ();
  6854. $receiptDetail = $receipt->getOne ( array (
  6855. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6856. 'asArray' => true
  6857. ) );
  6858. if (empty ( $receiptDetail ))
  6859. return "/saeaBorad";
  6860. if ($receiptDetail ['Rtype'] == 1)
  6861. $executeDetail = $execute->getOne ( array (
  6862. 'where' => 'mold="借款费用执行人"',
  6863. 'asArray' => true
  6864. ) );
  6865. else
  6866. $executeDetail = $execute->getOne ( array (
  6867. 'where' => 'mold="报销单执行人"',
  6868. 'asArray' => true
  6869. ) );
  6870. $aItem = $accountItem->find ( array (
  6871. 'asArray' => true
  6872. ) );
  6873. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6874. $ag = $tr = $ta = $ot = $it = 0 ;
  6875. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6876. foreach ( $aItem as $key => $value ) {
  6877. if ($value ['category'] == $this->AGENCY) {
  6878. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6879. array_push ( $accountJson [$this->AGENCY], array (
  6880. 'aid' => $value ['aid'],
  6881. 'name' => $value ['name'],
  6882. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6883. ) );
  6884. $sum += $agency [$ag];
  6885. $agencySum += $agency [$ag];
  6886. }
  6887. $ag ++;
  6888. }
  6889. if ($value ['category'] == $this->TRAVEL) {
  6890. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6891. array_push ( $accountJson [$this->TRAVEL], array (
  6892. 'aid' => $value ['aid'],
  6893. 'name' => $value ['name'],
  6894. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6895. ) );
  6896. $sum += $travel [$tr];
  6897. $travelSum += $travel [$tr];
  6898. }
  6899. $tr ++;
  6900. }
  6901. if ($value ['category'] == $this->TRAIN) {
  6902. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6903. array_push ( $accountJson [$this->TRAIN], array (
  6904. 'aid' => $value ['aid'],
  6905. 'name' => $value ['name'],
  6906. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6907. ) );
  6908. $sum += $train [$ta];
  6909. $trainSum += $train [$ta];
  6910. }
  6911. $ta ++;
  6912. }
  6913. if ($value ['category'] == $this->INTTRAIN) {
  6914. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6915. array_push ( $accountJson [$this->INTTRAIN], array (
  6916. 'aid' => $value ['aid'],
  6917. 'name' => $value ['name'],
  6918. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6919. ) );
  6920. $sum += $inttrain [$it];
  6921. $inttrainSum += $inttrain [$it];
  6922. }
  6923. $it ++;
  6924. }
  6925. if ($value ['category'] == $this->OTHER) {
  6926. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6927. array_push ( $accountJson [$this->OTHER], array (
  6928. 'aid' => $value ['aid'],
  6929. 'name' => $value ['name'],
  6930. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6931. ) );
  6932. $sum += $other [$ot];
  6933. $otherSum += $other [$ot];
  6934. }
  6935. $ot ++;
  6936. }
  6937. }
  6938. $accountJson ['cSum'] = array (
  6939. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6940. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6941. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6942. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6943. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6944. );
  6945. // 报销单
  6946. $rid = $receipt->rid = $receiptDetail ['rid'];
  6947. $receipt->accountItem = json_encode ( $accountJson );
  6948. $receipt->staff = $this->staff [0] ['sid'];
  6949. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6950. $receipt->date = date ( "Y-m-d" );
  6951. $receipt->cid = $cid;
  6952. if (($receiptDetail ['status'] != 4)) {
  6953. if ($receiptDetail ['Rtype'] == 1)
  6954. $receipt->status = 7;
  6955. else
  6956. $receipt->status = 5;
  6957. }
  6958. if ($receiptDetail != 4 && ! empty ( $verify ))
  6959. $receipt->verify = $verify;
  6960. $receipt->executeCopy = $executeDetail ['staff'];
  6961. $order = array (
  6962. "\r\n",
  6963. "\n",
  6964. "\r"
  6965. );
  6966. $replace = '<br/>';
  6967. $explanation = str_replace ( $order, $replace, $explanation );
  6968. $receipt->explanation = $explanation;
  6969. $receipt->remittanceName = $remittanceName;
  6970. $receipt->bankName = $bankName;
  6971. $receipt->bankNumber = $bankNumber;
  6972. $receipt->remittanceBankType = $remittanceBankType;
  6973. if ($remittanceBankType == 1)
  6974. $receipt->coupletNumber = $coupletNumber;
  6975. $receipt->update ();
  6976. $receiptDetail = new receiptDetail ();
  6977. $receiptDetail->delete ( array (
  6978. 'where' => 'rid=' . $rid
  6979. ) );
  6980. // 报销详情
  6981. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6982. $receiptDetail = new receiptDetail ();
  6983. $receiptDetail->staff = $this->staff [0] ['sid'];
  6984. $receiptDetail->item = $value ['name'];
  6985. $receiptDetail->itemCategory = $this->AGENCY;
  6986. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6987. $receiptDetail->date = date ( "Y-m-d" );
  6988. $receiptDetail->cid = $cid;
  6989. $receiptDetail->rid = $rid;
  6990. $receiptDetail->status = 4;
  6991. $receiptDetail->insert ();
  6992. }
  6993. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6994. $receiptDetail = new receiptDetail ();
  6995. $receiptDetail->staff = $this->staff [0] ['sid'];
  6996. $receiptDetail->item = $value ['name'];
  6997. $receiptDetail->itemCategory = $this->TRAVEL;
  6998. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6999. $receiptDetail->date = date ( "Y-m-d" );
  7000. $receiptDetail->cid = $cid;
  7001. $receiptDetail->rid = $rid;
  7002. $receiptDetail->status = 4;
  7003. $receiptDetail->insert ();
  7004. }
  7005. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  7006. $receiptDetail = new receiptDetail ();
  7007. $receiptDetail->staff = $this->staff [0] ['sid'];
  7008. $receiptDetail->item = $value ['name'];
  7009. $receiptDetail->itemCategory = $this->TRAIN;
  7010. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7011. $receiptDetail->date = date ( "Y-m-d" );
  7012. $receiptDetail->cid = $cid;
  7013. $receiptDetail->rid = $rid;
  7014. $receiptDetail->status = 4;
  7015. $receiptDetail->insert ();
  7016. }
  7017. //内训
  7018. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  7019. $receiptDetail = new receiptDetail ();
  7020. $receiptDetail->staff = $this->staff [0] ['sid'];
  7021. $receiptDetail->item = $value ['name'];
  7022. $receiptDetail->itemCategory = $this->INTTRAIN;
  7023. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7024. $receiptDetail->date = date ( "Y-m-d" );
  7025. $receiptDetail->cid = $cid;
  7026. $receiptDetail->rid = $rid;
  7027. $receiptDetail->status = 4;
  7028. $receiptDetail->insert ();
  7029. }
  7030. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  7031. $receiptDetail = new receiptDetail ();
  7032. $receiptDetail->staff = $this->staff [0] ['sid'];
  7033. $receiptDetail->item = $value ['name'];
  7034. $receiptDetail->itemCategory = $this->OTHER;
  7035. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7036. $receiptDetail->date = date ( "Y-m-d" );
  7037. $receiptDetail->cid = $cid;
  7038. $receiptDetail->rid = $rid;
  7039. $receiptDetail->status = 4;
  7040. $receiptDetail->insert ();
  7041. }
  7042. // 附件
  7043. if (! empty ( $enclosurName )) {
  7044. $enclosurArray = explode ( '-', $enclosurName );
  7045. foreach ( $enclosurArray as $value ) {
  7046. $enclosur = new enclosur ();
  7047. $enclosur->name = $value;
  7048. $enclosur->rid = $rid;
  7049. $enclosur->insert ();
  7050. }
  7051. }
  7052. // return "/referReceipt/".$rid;
  7053. }
  7054. return "/saeaBorad";
  7055. }
  7056. function approvedReceipt() {
  7057. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7058. Doo::loadModel ( 'receipt' );
  7059. Doo::loadModel ( 'receiptDetail' );
  7060. $receipt = new receipt ();
  7061. $receiptDetail = new receiptDetail ();
  7062. Doo::loadModel ( 'statistics' );
  7063. Doo::loadModel ( 'itemStatistics' );
  7064. $statistics = new statistics ();
  7065. $itemStatistics = new itemStatistics ();
  7066. Doo::loadModel ( "verify" );
  7067. $verify = new verify ();
  7068. // 审批状态的判定
  7069. $receiptDetailList = $receipt->getOne ( array (
  7070. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7071. 'asArray' => true
  7072. ) );
  7073. if (empty ( $receiptDetailList ))
  7074. return "/saeaBorad";
  7075. $verifyDetail = $verify->getOne ( array (
  7076. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7077. 'asArray' => true
  7078. ) );
  7079. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7080. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7081. $nowStaff = "";
  7082. $nowStaffList = array ();
  7083. if ($verifyDetail [0] [1] == 'ROLE') {
  7084. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7085. foreach ( $vStaffString as $key => $value ) {
  7086. $staffK = explode ( "_", $value );
  7087. array_push ( $nowStaffList, $staffK [0] );
  7088. }
  7089. $nowStaff = implode ( ',', $nowStaffList );
  7090. } else {
  7091. $nowStaff = $verifyDetail [0] [0];
  7092. }
  7093. $receipt->nowStaff = $nowStaff;
  7094. }
  7095. // echo $nowStaff;
  7096. // print_r($verifyDetail);die;
  7097. $receipt->rid = $receiptDetailList ['rid'];
  7098. $receipt->date = date ( "Y-m-d" );
  7099. $receipt->status = 2;
  7100. $receipt->update ();
  7101. $receiptDetail->status = 2;
  7102. $receiptDetail->update ( array (
  7103. 'where' => 'rid=' . $receiptDetailList ['rid']
  7104. ) );
  7105. Doo::loadModel ( "receiptLog" );
  7106. $receiptLog = new receiptLog ();
  7107. Doo::loadModel ( "verify" );
  7108. $verify = new verify ();
  7109. $receiptInfo = $receipt->getOne ( array (
  7110. 'where' => 'rid=' . $rid,
  7111. 'asArray' => true
  7112. ) );
  7113. $vr = $verify->getOne ( array (
  7114. 'where' => 'vid=' . $receiptInfo ['verify'],
  7115. 'asArray' => true
  7116. ) );
  7117. $jd = json_decode ( $vr ['staff'] );
  7118. $roleId = 0;
  7119. foreach ( $jd as $key => $value ) {
  7120. if ($value [1] == 'ROLE') {
  7121. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7122. if ($pos !== false) {
  7123. $roleId = $value [0];
  7124. }
  7125. }
  7126. }
  7127. // 审批日志
  7128. // echo $roleId;die;
  7129. if (! empty ( $roleId )) {
  7130. Doo::loadModel ( "role" );
  7131. $role = new role ();
  7132. $roleInfo = $role->getOne ( array (
  7133. 'where' => 'rid=' . $roleId,
  7134. 'asArray' => true
  7135. ) );
  7136. // $receiptLog->rolename = $roleInfo ['name'];
  7137. }
  7138. $receiptLog->username = $this->staff [0] ['username'];
  7139. $receiptLog->uid = $this->staff [0] ['sid'];
  7140. $receiptLog->date = date ( "Y-m-d" );
  7141. $receiptLog->opinion = '提交审批';
  7142. $receiptLog->img = $this->staff [0] ['avatar'];
  7143. $receiptLog->status = 2;
  7144. $receiptLog->rid = $rid;
  7145. $receiptLog->insert ();
  7146. // statistics item
  7147. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7148. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7149. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7150. $stat = $statistics->getOne ( array (
  7151. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7152. 'asArray' => true
  7153. ) );
  7154. if (empty ( $stat )) {
  7155. $statistics->date = date ( "Y-m-d" );
  7156. $statistics->cid = $this->staff [0] ['cid'];
  7157. $statistics->staff = $this->staff [0] ['sid'];
  7158. $statistics->agPrice = 0;
  7159. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7160. $statistics->insert ();
  7161. } else {
  7162. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7163. $statistics->update ( array (
  7164. 'where' => 'sid=' . $stat ['sid']
  7165. ) );
  7166. }
  7167. return "/expenses";
  7168. }
  7169. function approval() {
  7170. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7171. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7172. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7173. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7174. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7175. if (empty ( $status ))
  7176. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7177. $vidList = array ();
  7178. $button = 0;
  7179. Doo::loadModel ( 'verify' );
  7180. $verify = new verify ();
  7181. Doo::loadModel ( 'receipt' );
  7182. $receipt = new receipt ();
  7183. Doo::loadModel ( 'staff' );
  7184. $staff = new staff ();
  7185. Doo::loadModel ( 'L_category' );
  7186. $Lcategory = new L_category ();
  7187. // user verify ID
  7188. $verifyDetail = $verify->find ( array (
  7189. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7190. 'asArray' => true
  7191. ) );
  7192. foreach ( $verifyDetail as $key => $value ) {
  7193. array_push ( $vidList, $value ['vid'] );
  7194. }
  7195. $vid = implode ( ",", $vidList );
  7196. if (empty ( $verifyDetail ))
  7197. $vid = 0;
  7198. /*
  7199. */
  7200. $dateCondition = " and Year(date) =" . $year;
  7201. if (! empty ( $month ))
  7202. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7203. $categoryList = $Lcategory->find ( array (
  7204. 'asArray' => true
  7205. ) );
  7206. $staffList = $staff->find ( array (
  7207. 'where' => 'cid=' . $cid,
  7208. 'asArray' => true
  7209. ) );
  7210. $cateCondition = "";
  7211. $staffCondition = "";
  7212. $approvalCondition = "";
  7213. if (! empty ( $cid ))
  7214. $cateCondition = ' and cid=' . $cid;
  7215. if (! empty ( $sid )) {
  7216. $staffCondition = ' and staff=' . $sid;
  7217. $cateCondition = "";
  7218. }
  7219. // elseif($status==1){
  7220. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7221. // }
  7222. if ($status == 2) {
  7223. // 查找角色审批人
  7224. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7225. }
  7226. $ap = "";
  7227. if ($status == 4) {
  7228. $ap = 4;
  7229. $status = 2;
  7230. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7231. }
  7232. if ($status == 5) {
  7233. $status = 4;
  7234. $ap = 5;
  7235. }
  7236. // echo $vid;
  7237. // get Receipt By verifyID status 2 .$approvalCondition
  7238. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7239. $receiptList = $receipt->find ( array (
  7240. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7241. 'desc' => 'rid',
  7242. 'asArray' => true
  7243. ) );
  7244. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7245. $Locate = 0;
  7246. if ($ap == 4)
  7247. $status = 4;
  7248. elseif ($ap == 5)
  7249. $status = 5;
  7250. foreach ( $receiptList as $key => $value ) {
  7251. $receiptList [$key] ['Locate'] = $Locate;
  7252. $Locate ++;
  7253. $receiptList [$key] ['reviseDetail'] = array ();
  7254. if (! empty ( $value ['reviseDetail'] ))
  7255. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7256. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7257. $categoryDetil = $Lcategory->getOne ( array (
  7258. 'where' => 'cid=' . $value ['cid'],
  7259. 'asArray' => true
  7260. ) );
  7261. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7262. $verifyList = $verify->getOne ( array (
  7263. 'where' => 'vid=' . $value ['verify'],
  7264. 'asArray' => true
  7265. ) );
  7266. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7267. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7268. foreach ( $verifyList as $k => $v ) {
  7269. // init verifyStaff
  7270. $verifyList [$k] ['date'] = "";
  7271. $verifyList [$k] ['opinion'] = "";
  7272. $verifyList [$k] ['status'] = "";
  7273. if (empty ( $verifyStaff )) {
  7274. $verifyList [$k] ['date'] = "";
  7275. $verifyList [$k] ['opinion'] = "";
  7276. if ($v [0] == $this->staff [0] ['sid']) {
  7277. $verifyList [$k] ['status'] = 4;
  7278. $button = 4;
  7279. }
  7280. } else {
  7281. $flag = true;
  7282. foreach ( $verifyStaff as $m => $u ) {
  7283. if ($v [0] == $m) {
  7284. $verifyList [$k] ['date'] = $u ['date'];
  7285. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7286. $verifyList [$k] ['status'] = $u ['status'];
  7287. $flag = false;
  7288. break;
  7289. }
  7290. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7291. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7292. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7293. }
  7294. if ($flag) { // 检测可编辑
  7295. if ($v [0] == $this->staff [0] ['sid']) {
  7296. $verifyList [$k] ['status'] = 4;
  7297. $button = 4;
  7298. }
  7299. }
  7300. }
  7301. }
  7302. $receiptList [$key] ['verifyList'] = $verifyList;
  7303. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7304. 'where' => 'sid=' . $value ['staff'],
  7305. 'asArray' => true
  7306. ) );
  7307. $receiptList [$key] ['button'] = $button;
  7308. }
  7309. // print_r($receiptList);die;
  7310. // $data['verifyDetail']=$verifyDetail;
  7311. $mothHtml = "";
  7312. for($i = 1; $i <= 12; $i ++) {
  7313. if ($month == $i)
  7314. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7315. else
  7316. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7317. }
  7318. $data ['mothHtml'] = $mothHtml;
  7319. $data ['receiptList'] = $receiptList;
  7320. $data ['receiptApprovalCount'] = count ( $receiptList );
  7321. $data ['status'] = $status;
  7322. $data ['year'] = $year;
  7323. $data ['categoryList'] = $categoryList;
  7324. $data ['staffList'] = $staffList;
  7325. $data ['cid'] = $cid;
  7326. $data ['sid'] = $sid;
  7327. $data ['ap'] = $ap;
  7328. $data ['memu'] = "receipt";
  7329. $data ['staff'] = $this->staff;
  7330. $data ['receiptMemu'] = 'approval';
  7331. $data ['verifyId'] = $this->verifyId;
  7332. $data ['executeId'] = $this->executeId;
  7333. $this->render ( "/admin/saea_reportList", $data );
  7334. }
  7335. function approvalDetails() {
  7336. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7337. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7338. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7339. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7340. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7341. Doo::loadModel ( 'verify' );
  7342. $verify = new verify ();
  7343. Doo::loadModel ( 'receipt' );
  7344. $receipt = new receipt ();
  7345. Doo::loadModel ( 'staff' );
  7346. $staff = new staff ();
  7347. Doo::loadModel ( 'L_category' );
  7348. $Lcategory = new L_category ();
  7349. Doo::loadModel ( 'enclosur' );
  7350. $enclosur = new enclosur ();
  7351. $vidList = array ();
  7352. $verifyDetail = $verify->find ( array (
  7353. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7354. 'asArray' => true
  7355. ) );
  7356. foreach ( $verifyDetail as $key => $value ) {
  7357. array_push ( $vidList, $value ['vid'] );
  7358. }
  7359. $vid = implode ( ",", $vidList );
  7360. if (empty ( $verifyDetail ))
  7361. $vid = 0;
  7362. $categoryList = $Lcategory->find ( array (
  7363. 'asArray' => true
  7364. ) );
  7365. $staffList = $staff->find ( array (
  7366. 'where' => 'cid=' . $cid,
  7367. 'asArray' => true
  7368. ) );
  7369. $ap = 0;
  7370. $receiptList = $receipt->find ( array (
  7371. 'where' => 'rid =' . $rid,
  7372. 'desc' => 'rid',
  7373. 'asArray' => true
  7374. ) );
  7375. $Locate = 0;
  7376. $roleId = 0;
  7377. $button = 0;
  7378. foreach ( $receiptList as $key => $value ) {
  7379. $receiptList [$key] ['Locate'] = $Locate;
  7380. $Locate ++;
  7381. $receiptList [$key] ['reviseDetail'] = array ();
  7382. if (! empty ( $value ['reviseDetail'] ))
  7383. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7384. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7385. $categoryDetil = $Lcategory->getOne ( array (
  7386. 'where' => 'cid=' . $value ['cid'],
  7387. 'asArray' => true
  7388. ) );
  7389. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7390. // 检测编辑状态
  7391. $verifyList = $verify->getOne ( array (
  7392. 'where' => 'vid=' . $value ['verify'],
  7393. 'asArray' => true
  7394. ) );
  7395. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7396. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7397. Doo::loadModel ( 'role' );
  7398. $role = new role ();
  7399. // print_r($verifyList);
  7400. $flag = true;
  7401. $roleKey = 0;
  7402. $endStaffArray = array ();
  7403. $roleArrayCopy = array ();
  7404. foreach ( $verifyList as $k => $v ) {
  7405. // init verifyStaff
  7406. if ($v [1] == 'ROLE') {
  7407. if (! empty ( $verifyStaff )) {
  7408. $endStaffArray = end ( $verifyStaff );
  7409. if ($v [0] == $endStaffArray ['nextStaff']) {
  7410. $roleId = $v [0];
  7411. }
  7412. }
  7413. $roleVerify = json_decode ( $v [3], true );
  7414. $roleKey = $k;
  7415. $roleArray = array ();
  7416. $rolename = $role->getOne ( array (
  7417. 'where' => 'rid=' . $v [0],
  7418. 'asArray' => true
  7419. ) );
  7420. foreach ( $roleVerify as $o => $p ) {
  7421. $staffID = explode ( '_', $p );
  7422. $staffInfo = $staff->getOne ( array (
  7423. 'where' => 'sid=' . $staffID [0],
  7424. 'asArray' => true
  7425. ) );
  7426. // print_r($staffID);
  7427. $exp = array (
  7428. 0 => $staffInfo ['sid'],
  7429. 1 => $staffID [1],
  7430. 2 => $staffInfo ['avatar'],
  7431. 'date' => '',
  7432. 'date' => '',
  7433. 'opinion' => '',
  7434. 'status' => '',
  7435. 'rolename' => $rolename ['name']
  7436. );
  7437. array_push ( $roleArray, $exp );
  7438. }
  7439. $roleArrayCopy [$v [0]] = $roleArray;
  7440. // $verifyList[$k]['roleArray']=$roleArray;
  7441. }
  7442. // print_r($roleArray);
  7443. $verifyList [$k] ['date'] = "";
  7444. $verifyList [$k] ['opinion'] = "";
  7445. $verifyList [$k] ['status'] = "";
  7446. if (empty ( $verifyStaff )) {
  7447. $verifyList [$k] ['date'] = "";
  7448. $verifyList [$k] ['opinion'] = "";
  7449. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7450. $verifyList [$k] ['status'] = 4;
  7451. $button = 4;
  7452. $flag = false;
  7453. }
  7454. } else {
  7455. foreach ( $verifyStaff as $m => $u ) {
  7456. if ($v [0] == $m) {
  7457. $verifyList [$k] ['date'] = $u ['date'];
  7458. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7459. $verifyList [$k] ['status'] = $u ['status'];
  7460. $flag = false;
  7461. break;
  7462. }
  7463. }
  7464. $endStaffArray = end ( $verifyStaff );
  7465. if (isset ( $endStaffArray ['ROLE'] )) {
  7466. } else {
  7467. $endKey = key ( $verifyStaff );
  7468. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7469. $button = 4;
  7470. $verifyList [$k] ['status'] = 4;
  7471. }
  7472. }
  7473. }
  7474. }
  7475. $rolename ['name'] = '';
  7476. if (! empty ( $roleId )) {
  7477. Doo::loadModel ( 'role' );
  7478. $role = new role ();
  7479. $rolename = $role->getOne ( array (
  7480. 'where' => 'rid=' . $roleId,
  7481. 'asArray' => true
  7482. ) );
  7483. }
  7484. if (! empty ( $verifyStaff ))
  7485. $endStaffArray = end ( $verifyStaff );
  7486. $KOP = false;
  7487. foreach ( $roleArrayCopy as $P => $A ) {
  7488. foreach ( $A as $MKI => $AVL ) {
  7489. if (! empty ( $verifyStaff )) {
  7490. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7491. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7492. $button = 4;
  7493. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7494. }
  7495. foreach ( $verifyStaff as $m => $u ) {
  7496. $AVLFK = $AVL [0] . '_R';
  7497. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7498. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7499. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7500. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7501. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7502. break;
  7503. }
  7504. }
  7505. } else {
  7506. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7507. $button = 4;
  7508. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7509. }
  7510. }
  7511. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7512. $KOP = true;
  7513. }
  7514. }
  7515. foreach ( $roleArrayCopy as $k => $v ) {
  7516. foreach ( $verifyList as $m => $n ) {
  7517. if ($n [0] == $k) {
  7518. array_splice ( $verifyList, $m, 1, $v );
  7519. }
  7520. }
  7521. }
  7522. $receiptList [$key] ['verifyList'] = $verifyList;
  7523. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7524. 'where' => 'sid=' . $value ['staff'],
  7525. 'asArray' => true
  7526. ) );
  7527. $receiptList [$key] ['button'] = $button;
  7528. }
  7529. $mothHtml = "";
  7530. for($i = 1; $i <= 12; $i ++) {
  7531. if ($month == $i)
  7532. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7533. else
  7534. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7535. }
  7536. // 获取审批日志
  7537. Doo::loadModel ( 'receiptLog' );
  7538. $receiptLog = new receiptLog ();
  7539. $rlList = array ();
  7540. $rlInfo = $receiptLog->getOne ( array (
  7541. 'where' => 'rid=' . $rid . ' and status=4',
  7542. 'asArray' => true
  7543. ) );
  7544. $tijdate = $receiptLog->getOne ( array (
  7545. 'where' => 'rid=' . $rid . ' and status=2',
  7546. 'asc' => 'rlid',
  7547. 'asArray' => true
  7548. ) );
  7549. if (! empty ( $rlInfo )) {
  7550. $rlList = $receiptLog->find ( array (
  7551. 'where' => 'rid=' . $rid,
  7552. 'asc' => 'rlid',
  7553. 'asArray' => true
  7554. ) );
  7555. }
  7556. $receiptList [0] ['rlList'] = $rlList;
  7557. $enclosurList = $enclosur->find ( array (
  7558. 'where' => 'rid=' . $rid,
  7559. 'asArray' => true
  7560. ) );
  7561. $enclosurHtml = '';
  7562. foreach ( $enclosurList as $value ) {
  7563. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7564. }
  7565. $data ['enclosurHtml'] = $enclosurHtml;
  7566. $data ['rolename'] = $rolename ['name'];
  7567. $data ['datetij'] = $tijdate ['date'];
  7568. $data ['mothHtml'] = $mothHtml;
  7569. $data ['receiptList'] = $receiptList;
  7570. $data ['receiptApprovalCount'] = count ( $receiptList );
  7571. $data ['year'] = $year;
  7572. $data ['categoryList'] = $categoryList;
  7573. $data ['staffList'] = $staffList;
  7574. $data ['cid'] = $cid;
  7575. $data ['sid'] = $sid;
  7576. $data ['status'] = 0;
  7577. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7578. $ap = 4;
  7579. } else
  7580. $data ['status'] = $receiptList [0] ['status'];
  7581. if ($receiptList [0] ['status'] == 4) {
  7582. $data ['status'] = 5;
  7583. $ap = 0;
  7584. }
  7585. $data ['ap'] = $ap;
  7586. $data ['memu'] = "receipt";
  7587. $data ['staff'] = $this->staff;
  7588. $data ['receiptMemu'] = 'approval';
  7589. $data ['verifyId'] = $this->verifyId;
  7590. $data ['executeId'] = $this->executeId;
  7591. $this->render ( "/admin/saeaReportListReport", $data );
  7592. }
  7593. function approvalEdi() {
  7594. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7595. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7596. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7597. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7598. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7599. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7600. if (empty ( $status ))
  7601. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7602. $vidList = array ();
  7603. $button = 0;
  7604. Doo::loadModel ( 'verify' );
  7605. Doo::loadModel ( 'receipt' );
  7606. Doo::loadModel ( 'staff' );
  7607. $staff = new staff ();
  7608. $receipt = new receipt ();
  7609. $verify = new verify ();
  7610. Doo::loadModel ( 'L_category' );
  7611. $Lcategory = new L_category ();
  7612. Doo::loadModel ( 'enclosur' );
  7613. $enclosur = new enclosur ();
  7614. // user verify ID
  7615. $verifyDetail = $verify->find ( array (
  7616. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7617. 'asArray' => true
  7618. ) );
  7619. foreach ( $verifyDetail as $key => $value ) {
  7620. array_push ( $vidList, $value ['vid'] );
  7621. }
  7622. $vid = implode ( ",", $vidList );
  7623. if (empty ( $verifyDetail ))
  7624. $vid = 0;
  7625. $categoryList = $Lcategory->find ( array (
  7626. 'asArray' => true
  7627. ) );
  7628. $staffList = $staff->find ( array (
  7629. 'where' => 'cid=' . $cid,
  7630. 'asArray' => true
  7631. ) );
  7632. $ap = "";
  7633. if ($status == 4) {
  7634. $ap = 4;
  7635. $status = 2;
  7636. }
  7637. // get Receipt By verifyID status 2
  7638. $receiptList = $receipt->find ( array (
  7639. 'where' => 'rid =' . $rid,
  7640. 'desc' => 'rid',
  7641. 'asArray' => true
  7642. ) );
  7643. $Locate = 0;
  7644. $roleId = 0;
  7645. if ($ap == 4)
  7646. $status = 4;
  7647. foreach ( $receiptList as $key => $value ) {
  7648. $receiptList [$key] ['Locate'] = $Locate;
  7649. $Locate ++;
  7650. $receiptList [$key] ['reviseDetail'] = array ();
  7651. if (! empty ( $value ['reviseDetail'] ))
  7652. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7653. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7654. $categoryDetil = $Lcategory->getOne ( array (
  7655. 'where' => 'cid=' . $value ['cid'],
  7656. 'asArray' => true
  7657. ) );
  7658. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7659. // 检测编辑状态
  7660. $verifyList = $verify->getOne ( array (
  7661. 'where' => 'vid=' . $value ['verify'],
  7662. 'asArray' => true
  7663. ) );
  7664. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7665. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7666. // print_r($verifyList);
  7667. //
  7668. // if (empty($verifyStaff)){
  7669. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7670. // $verifyList[0]['status']=4;$button=4;
  7671. // }
  7672. //
  7673. // }else{
  7674. //
  7675. // }
  7676. // die;
  7677. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7678. // echo array_search("green",$a);
  7679. //
  7680. Doo::loadModel ( 'role' );
  7681. $role = new role ();
  7682. // print_r($verifyList);
  7683. $flag = true;
  7684. $roleKey = 0;
  7685. $endStaffArray = array ();
  7686. $roleArrayCopy = array ();
  7687. foreach ( $verifyList as $k => $v ) {
  7688. // init verifyStaff
  7689. if ($v [1] == 'ROLE') {
  7690. if (! empty ( $verifyStaff )) {
  7691. $endStaffArray = end ( $verifyStaff );
  7692. if ($v [0] == $endStaffArray ['nextStaff']) {
  7693. $roleId = $v [0];
  7694. }
  7695. }
  7696. $roleVerify = json_decode ( $v [3], true );
  7697. $roleKey = $k;
  7698. $roleArray = array ();
  7699. $rolename = $role->getOne ( array (
  7700. 'where' => 'rid=' . $v [0],
  7701. 'asArray' => true
  7702. ) );
  7703. foreach ( $roleVerify as $o => $p ) {
  7704. $staffID = explode ( '_', $p );
  7705. $staffInfo = $staff->getOne ( array (
  7706. 'where' => 'sid=' . $staffID [0],
  7707. 'asArray' => true
  7708. ) );
  7709. // print_r($staffID);
  7710. $exp = array (
  7711. 0 => $staffInfo ['sid'],
  7712. 1 => $staffID [1],
  7713. 2 => $staffInfo ['avatar'],
  7714. 'date' => '',
  7715. 'date' => '',
  7716. 'opinion' => '',
  7717. 'status' => '',
  7718. 'rolename' => $rolename ['name']
  7719. );
  7720. array_push ( $roleArray, $exp );
  7721. }
  7722. $roleArrayCopy [$v [0]] = $roleArray;
  7723. // $verifyList[$k]['roleArray']=$roleArray;
  7724. }
  7725. // print_r($roleArray);
  7726. $verifyList [$k] ['date'] = "";
  7727. $verifyList [$k] ['opinion'] = "";
  7728. $verifyList [$k] ['status'] = "";
  7729. if (empty ( $verifyStaff )) {
  7730. $verifyList [$k] ['date'] = "";
  7731. $verifyList [$k] ['opinion'] = "";
  7732. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7733. $verifyList [$k] ['status'] = 4;
  7734. $button = 4;
  7735. $flag = false;
  7736. }
  7737. } else {
  7738. foreach ( $verifyStaff as $m => $u ) {
  7739. if ($v [0] == $m) {
  7740. $verifyList [$k] ['date'] = $u ['date'];
  7741. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7742. $verifyList [$k] ['status'] = $u ['status'];
  7743. $flag = false;
  7744. break;
  7745. }
  7746. }
  7747. $endStaffArray = end ( $verifyStaff );
  7748. if (isset ( $endStaffArray ['ROLE'] )) {
  7749. } else {
  7750. $endKey = key ( $verifyStaff );
  7751. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7752. $button = 4;
  7753. $verifyList [$k] ['status'] = 4;
  7754. }
  7755. }
  7756. // print_r($endStaffArray);die;
  7757. // if (empty($verifyStaff)){
  7758. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7759. // $verifyList[$k]['status']=4;$button=4;
  7760. // }
  7761. //
  7762. // }else{
  7763. //
  7764. // }
  7765. // if($flag){//检测可编辑
  7766. // if($v[0]==$this->staff[0]['sid']){
  7767. // $verifyList[$k]['status']=4;$button=4;
  7768. // }
  7769. // }
  7770. }
  7771. }
  7772. $rolename ['name'] = '';
  7773. if (! empty ( $roleId )) {
  7774. Doo::loadModel ( 'role' );
  7775. $role = new role ();
  7776. $rolename = $role->getOne ( array (
  7777. 'where' => 'rid=' . $roleId,
  7778. 'asArray' => true
  7779. ) );
  7780. }
  7781. if (! empty ( $verifyStaff ))
  7782. $endStaffArray = end ( $verifyStaff );
  7783. $KOP = false;
  7784. foreach ( $roleArrayCopy as $P => $A ) {
  7785. foreach ( $A as $MKI => $AVL ) {
  7786. if (! empty ( $verifyStaff )) {
  7787. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7788. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7789. $button = 4;
  7790. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7791. }
  7792. foreach ( $verifyStaff as $m => $u ) {
  7793. $AVLFK = $AVL [0] . '_R';
  7794. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7795. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7796. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7797. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7798. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7799. break;
  7800. }
  7801. }
  7802. } else {
  7803. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7804. $button = 4;
  7805. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7806. }
  7807. }
  7808. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7809. $KOP = true;
  7810. }
  7811. }
  7812. // print_r($roleArrayCopy);
  7813. // echo $roleKey;
  7814. foreach ( $roleArrayCopy as $k => $v ) {
  7815. foreach ( $verifyList as $m => $n ) {
  7816. if ($n [0] == $k) {
  7817. array_splice ( $verifyList, $m, 1, $v );
  7818. }
  7819. }
  7820. }
  7821. // if ($KOP)
  7822. // array_splice($verifyList,$roleKey,1,$roleArray);
  7823. // print_r($verifyList);
  7824. $receiptList [$key] ['verifyList'] = $verifyList;
  7825. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7826. 'where' => 'sid=' . $value ['staff'],
  7827. 'asArray' => true
  7828. ) );
  7829. $receiptList [$key] ['button'] = $button;
  7830. }
  7831. // $data['verifyDetail']=$verifyDetail;
  7832. $mothHtml = "";
  7833. for($i = 1; $i <= 12; $i ++) {
  7834. if ($month == $i)
  7835. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7836. else
  7837. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7838. }
  7839. // 获取审批日志
  7840. Doo::loadModel ( 'receiptLog' );
  7841. $receiptLog = new receiptLog ();
  7842. $rlList = array ();
  7843. $rlInfo = $receiptLog->getOne ( array (
  7844. 'where' => 'rid=' . $rid . ' and status=4',
  7845. 'asArray' => true
  7846. ) );
  7847. $tijdate = $receiptLog->getOne ( array (
  7848. 'where' => 'rid=' . $rid . ' and status=2',
  7849. 'asc' => 'rlid',
  7850. 'asArray' => true
  7851. ) );
  7852. if (! empty ( $rlInfo )) {
  7853. $rlList = $receiptLog->find ( array (
  7854. 'where' => 'rid=' . $rid,
  7855. 'asc' => 'rlid',
  7856. 'asArray' => true
  7857. ) );
  7858. }
  7859. $receiptList [0] ['rlList'] = $rlList;
  7860. $enclosurList = $enclosur->find ( array (
  7861. 'where' => 'rid=' . $rid,
  7862. 'asArray' => true
  7863. ) );
  7864. $enclosurHtml = '';
  7865. foreach ( $enclosurList as $value ) {
  7866. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7867. }
  7868. $data ['enclosurHtml'] = $enclosurHtml;
  7869. $data ['rolename'] = $rolename ['name'];
  7870. $data ['datetij'] = $tijdate ['date'];
  7871. $data ['mothHtml'] = $mothHtml;
  7872. $data ['receiptList'] = $receiptList;
  7873. $data ['receiptApprovalCount'] = count ( $receiptList );
  7874. $data ['status'] = $status;
  7875. $data ['year'] = $year;
  7876. $data ['categoryList'] = $categoryList;
  7877. $data ['staffList'] = $staffList;
  7878. $data ['cid'] = $cid;
  7879. $data ['sid'] = $sid;
  7880. $data ['ap'] = $ap;
  7881. $data ['memu'] = "receipt";
  7882. $data ['staff'] = $this->staff;
  7883. $data ['receiptMemu'] = 'approval';
  7884. $data ['verifyId'] = $this->verifyId;
  7885. $data ['executeId'] = $this->executeId;
  7886. $this->render ( "/admin/saeaReportListReport", $data );
  7887. }
  7888. function remittanceHky() {
  7889. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7890. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7891. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7892. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7893. $page_size = 15;
  7894. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7895. Doo::loadModel ( 'receipt' );
  7896. $receipt = new receipt ();
  7897. Doo::loadModel ( 'staff' );
  7898. $staff = new staff ();
  7899. $dateCondition = " and Year(executeDate) =" . $year;
  7900. if ($moth != 'MONTH')
  7901. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7902. if ($day != 'DAY' && $moth != 'MONTH')
  7903. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7904. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  7905. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7906. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7907. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7908. $dayList = $receipt->find ( array (
  7909. 'select' => 'executeDate,sum(amount) as amount',
  7910. 'where' => $sql,
  7911. 'desc' => 'executeDate',
  7912. 'groupby' => 'executeDate',
  7913. 'limit' => $limit,
  7914. 'asArray' => true
  7915. ) );
  7916. // print_r($dayList);
  7917. foreach ( $dayList as $key => $value ) {
  7918. $remitString = "";
  7919. $receiptList = $receipt->find ( array (
  7920. 'select' => 'rid,executeDate,amount,staff,cid',
  7921. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7922. 'desc' => 'executeDate',
  7923. 'asArray' => true
  7924. ) );
  7925. foreach ( $receiptList as $k => $v ) {
  7926. $sinfo = $staff->getOne ( array (
  7927. 'select' => 'username,category',
  7928. 'where' => ' sid=' . $v ['staff'],
  7929. 'asArray' => true
  7930. ) );
  7931. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7932. }
  7933. $dayList [$key] ['staff'] = $remitString;
  7934. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7935. }
  7936. // print_r($dayList);
  7937. $mothHtml = "";
  7938. for($i = 1; $i <= 12; $i ++) {
  7939. if ($moth == $i)
  7940. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7941. else
  7942. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7943. }
  7944. $dayHtml = "";
  7945. if ($day != "DAY" || $moth != "MONTH") {
  7946. for($i = 1; $i <= 31; $i ++) {
  7947. if ($day == $i)
  7948. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7949. else
  7950. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7951. }
  7952. }
  7953. $dateHtml = "";
  7954. $now = date ( "Y" );
  7955. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7956. if ($YEARD <= $now) {
  7957. $dateHtml .= '<option ';
  7958. if ($year == $YEARD) {
  7959. $dateHtml .= 'selected ';
  7960. }
  7961. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7962. }
  7963. }
  7964. $data ['dateHtml'] = $dateHtml;
  7965. $data ['page'] = $pageinfo;
  7966. $data ['year'] = $year;
  7967. $data ['moth'] = $moth;
  7968. $data ['day'] = $day;
  7969. $data ['get'] = $get;
  7970. $data ['dayHtml'] = $dayHtml;
  7971. $data ['mothHtml'] = $mothHtml;
  7972. $data ['receiptList'] = $dayList;
  7973. $data ['memu'] = "receipt";
  7974. $data ['staff'] = $this->staff;
  7975. $data ['receiptMemu'] = 'remittanceHky';
  7976. $data ['verifyId'] = $this->verifyId;
  7977. $data ['executeId'] = $this->executeId;
  7978. $this->render ( "/admin/remittanceHky", $data );
  7979. }
  7980. function remittancep() {
  7981. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7982. Doo::loadModel ( 'receipt' );
  7983. $receipt = new receipt ();
  7984. Doo::loadModel ( 'staff' );
  7985. $staff = new staff ();
  7986. Doo::loadClass ( 'XDeode' );
  7987. $XDeode = new XDeode ( 5 );
  7988. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7989. $rplist = $receipt->find ( array (
  7990. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7991. 'asArray' => true
  7992. ) );
  7993. $dayList = $receipt->find ( array (
  7994. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7995. 'desc' => 'executeDate',
  7996. 'groupby' => 'staff',
  7997. 'asArray' => true
  7998. ) );
  7999. $html = '';
  8000. foreach ( $dayList as $key => $value ) {
  8001. $sinfo = $staff->getOne ( array (
  8002. 'select' => 'username,category',
  8003. 'where' => ' sid=' . $value ['staff'],
  8004. 'asArray' => true
  8005. ) );
  8006. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8007. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8008. $au = 0;
  8009. foreach ( $rplist as $k => $v ) {
  8010. if ($value ['staff'] == $v ['staff']) {
  8011. $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>';
  8012. $au += $v ['amount'];
  8013. }
  8014. }
  8015. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8016. }
  8017. $data ['html'] = $html;
  8018. $data ['memu'] = "receipt";
  8019. $data ['staff'] = $this->staff;
  8020. $data ['receiptMemu'] = 'remittanceHky';
  8021. $data ['verifyId'] = $this->verifyId;
  8022. $data ['executeId'] = $this->executeId;
  8023. $this->render ( "/admin/remittancep", $data );
  8024. }
  8025. function ajaxGetReceiptDetails() {
  8026. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8027. Doo::loadClass ( 'XDeode' );
  8028. $XDeode = new XDeode ( 5 );
  8029. $rid = $XDeode->decode ( $rid );
  8030. if (empty ( $rid )) {
  8031. echo json_encode ( array (
  8032. 'status' => 2,
  8033. 'msg' => 'illegal request'
  8034. ) );
  8035. die ();
  8036. }
  8037. Doo::loadModel ( 'receipt' );
  8038. $receipt = new receipt ();
  8039. Doo::loadModel ( 'staff' );
  8040. $staff = new staff ();
  8041. $rinfo = $receipt->getOne ( array (
  8042. 'where' => 'rid= ' . $rid,
  8043. 'asArray' => true
  8044. ) );
  8045. $sinfo = $staff->getOne ( array (
  8046. 'select' => 'username,category',
  8047. 'where' => ' sid=' . $rinfo ['staff'],
  8048. 'asArray' => true
  8049. ) );
  8050. $rinfo ['reviseDetail'] = array ();
  8051. if (! empty ( $rinfo ['reviseDetail'] ))
  8052. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8053. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8054. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8055. $rinfo ['category'] = $sinfo ['category'];
  8056. $verifyStaff = array ();
  8057. if (! empty ( $rinfo ['verifyStaff'] ))
  8058. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8059. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8060. $rinfo ['relust'] = $relust;
  8061. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8062. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8063. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8064. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8065. // 费用执行人相关数据
  8066. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8067. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8068. foreach ( $executeCopy as $k => $v ) {
  8069. $executeCopy [$k] ['date'] = '';
  8070. $executeCopy [$k] ['opinion'] = '';
  8071. $executeCopy [$k] ['status'] = '';
  8072. if (! empty ( $executeStaff ))
  8073. foreach ( $executeStaff as $m => $u ) {
  8074. if ($v [0] == $m) {
  8075. $executeCopy [$k] ['date'] = $u ['date'];
  8076. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8077. $executeCopy [$k] ['status'] = $u ['status'];
  8078. break;
  8079. }
  8080. }
  8081. }
  8082. $rinfo ['executeCopy'] = $executeCopy;
  8083. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8084. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8085. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8086. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8087. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8088. $html .= '<tr><th>' . $value ['name'] . '</th>
  8089. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8090. }
  8091. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8092. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8093. <tr><th class="taC" colspan="2">费用说明</th>
  8094. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8095. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8096. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8097. </tbody></table>';
  8098. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8099. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8100. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8101. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8102. $html .= '<tr><th>' . $value ['name'] . '</th>
  8103. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8104. }
  8105. $html .= '<tr><th class="taR">合计</th>
  8106. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8107. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8108. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8109. $html .= '<tr><th>' . $value ['name'] . '</th>
  8110. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8111. }
  8112. $html .= '<tr><th class="taR">合计</th>
  8113. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8114. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8115. foreach ( $rinfo ['accountItem'] ['培训班费用'] 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="taR">合计</th>
  8120. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8121. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8122. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8123. $html .= '<tr><th>' . $value ['name'] . '</th>
  8124. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8125. }
  8126. $html .= '<tr><th class="taR">合计</th>
  8127. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8128. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8129. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8130. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8131. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8132. }
  8133. $html .= '<tr><th class="taR">合计</th>
  8134. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8135. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8136. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8137. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8138. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8139. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8140. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8141. <tr';
  8142. if ($rinfo ['relust'] >= 0) {
  8143. $html .= 'class="success"';
  8144. } else {
  8145. $html .= 'class="error"';
  8146. }
  8147. $html .= '><td class="taR"><b>借款结余</b></td>
  8148. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8149. </tbody></table>
  8150. ';
  8151. }
  8152. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8153. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8154. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8155. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8156. $html .= '<tr><th>' . $value ['name'] . '</th>
  8157. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8158. }
  8159. $html .= '<tr><th class="taR">合计</th>
  8160. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8161. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8162. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8163. <tr><th class="taC" colspan="2">费用说明</th>
  8164. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8165. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8166. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8167. </tbody></table>';
  8168. } else {
  8169. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8170. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8171. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8172. $html .= '<tr><th>' . $value ['name'] . '</th>
  8173. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8174. }
  8175. $html .= '<tr><th class="taR">合计</th>
  8176. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8177. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8178. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8179. $html .= '<tr><th>' . $value ['name'] . '</th>
  8180. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8181. }
  8182. $html .= '<tr><th class="taR">合计</th>
  8183. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8184. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8185. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8186. $html .= '<tr><th>' . $value ['name'] . '</th>
  8187. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8188. }
  8189. $html .= '<tr><th class="taR">合计</th>
  8190. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8191. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8192. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8193. $html .= '<tr><th>' . $value ['name'] . '</th>
  8194. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8195. }
  8196. $html .= '<tr><th class="taR">合计</th>
  8197. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8198. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8199. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8200. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8201. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8202. }
  8203. $html .= '<tr><th class="taR">合计</th>
  8204. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8205. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8206. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8207. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8208. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8209. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8210. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8211. $html .= '</tbody></table>';
  8212. /*
  8213. * <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>
  8214. */
  8215. }
  8216. // print_r($verifyStaff);die;
  8217. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8218. foreach ( $verifyStaff as $key => $value ) {
  8219. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8220. $sinfo = $staff->getOne ( array (
  8221. 'select' => 'username',
  8222. 'where' => ' sid=' . $key,
  8223. 'asArray' => true
  8224. ) );
  8225. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8226. }
  8227. $html .= '</tbody></table>';
  8228. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8229. foreach ( $rinfo ['executeCopy'] as $value ) {
  8230. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8231. }
  8232. $html .= '</tbody></table>';
  8233. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8234. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8235. </tr></table>';
  8236. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8237. echo json_encode ( array (
  8238. 'status' => 1,
  8239. 'html' => $html
  8240. ) );
  8241. die ();
  8242. }
  8243. /**
  8244. * 删除附件
  8245. */
  8246. function ajaxRemEnclousur() {
  8247. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8248. if (empty ( $key ))
  8249. echo json_encode ( array (
  8250. 'status' => 2
  8251. ) );
  8252. Doo::loadModel ( 'enclosur' );
  8253. $enclosur = new enclosur ();
  8254. $enclosur->delEnclosurByEid ( $key );
  8255. echo json_encode ( array (
  8256. 'status' => 1
  8257. ) );
  8258. }
  8259. function remittance() {
  8260. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8261. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8262. Doo::loadModel ( 'receipt' );
  8263. $receipt = new receipt ();
  8264. Doo::loadModel ( 'staff' );
  8265. $staff = new staff ();
  8266. $dateCondition = " and Year(pastDate) =" . $year;
  8267. if (! empty ( $month ))
  8268. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8269. // get Receipt By verifyID status 1
  8270. $receiptList = $receipt->find ( array (
  8271. 'select' => 'sum(sum) as sum,staff,pastDate',
  8272. 'where' => ' status=1' . $dateCondition,
  8273. 'desc' => 'pastDate',
  8274. 'groupby' => 'staff,pastDate',
  8275. 'asArray' => true
  8276. ) );
  8277. $dateList = $receipt->find ( array (
  8278. 'select' => 'pastDate,verifyStaff',
  8279. 'where' => ' status=1' . $dateCondition,
  8280. 'desc' => 'pastDate',
  8281. 'groupby' => 'pastDate',
  8282. 'asArray' => true
  8283. ) );
  8284. $dataList = array ();
  8285. foreach ( $dateList as $d => $a ) {
  8286. $dataList [$a ['pastDate']] = array ();
  8287. $daySum = 0;
  8288. foreach ( $receiptList as $key => $value ) {
  8289. if ($a ['pastDate'] == $value ['pastDate']) {
  8290. $oderList = $receipt->find ( array (
  8291. 'select' => 'receiptOrder',
  8292. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8293. 'asArray' => true
  8294. ) );
  8295. $list = array ();
  8296. $html = "";
  8297. foreach ( $oderList as $v ) {
  8298. array_push ( $list, $v ['receiptOrder'] );
  8299. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8300. }
  8301. $receiptList [$key] ['receiptOrder'] = $html;
  8302. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8303. $sinfo = $staff->getOne ( array (
  8304. 'select' => 'username ',
  8305. 'where' => ' sid=' . $value ['staff'],
  8306. 'asArray' => true
  8307. ) );
  8308. $receiptList [$key] ['username'] = $sinfo ['username'];
  8309. $daySum += $value ['sum'];
  8310. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8311. }
  8312. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8313. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8314. }
  8315. }
  8316. // print_r($dataList);
  8317. $data ['dataList'] = $dataList;
  8318. $mothHtml = "";
  8319. for($i = 1; $i <= 12; $i ++) {
  8320. if ($month == $i)
  8321. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8322. else
  8323. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8324. }
  8325. $data ['year'] = $year;
  8326. $data ['mothHtml'] = $mothHtml;
  8327. $data ['memu'] = "receipt";
  8328. $data ['staff'] = $this->staff;
  8329. $data ['receiptMemu'] = 'approval';
  8330. $data ['verifyId'] = $this->verifyId;
  8331. $data ['executeId'] = $this->executeId;
  8332. $this->render ( "/admin/saeaReportListPay", $data );
  8333. }
  8334. /**
  8335. * 金额调整,提高稳定性
  8336. * @return string
  8337. */
  8338. function revocationAdjustment() {
  8339. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8340. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8341. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8342. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8343. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8344. Doo::loadClass ( 'XDeode' );
  8345. $XDeode = new XDeode ( 5 );
  8346. Doo::loadModel ( 'receipt' );
  8347. $receipt = new receipt ();
  8348. $sid = $XDeode->decode ( $sidKey );
  8349. $rid = $XDeode->decode ( $ridKey );
  8350. $reviseKey = $XDeode->decode ( $reviseKey );
  8351. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8352. die ( 'illegal request' );
  8353. $receiptDetail = $receipt->getOne ( array (
  8354. 'where' => 'rid=' . $rid,
  8355. 'asArray' => true
  8356. ) );
  8357. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8358. die ( 'illegal request' );
  8359. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8360. if (! isset ( $reviseDetail [$reviseKey] ))
  8361. die ( 'illegal request' );
  8362. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8363. unset ( $reviseDetail [$reviseKey] );
  8364. $revisePrice = 0;
  8365. foreach ( $reviseDetail as $key => $value ) {
  8366. $revisePrice += $value ['price'];
  8367. }
  8368. $reviseDetailString = json_encode ( $reviseDetail );
  8369. $receipt->reviseDetail = $reviseDetailString;
  8370. $receipt->sum = $receiptDetail ['sum'] - $price;
  8371. $receipt->revisePrice = $revisePrice;
  8372. $receipt->update ( array (
  8373. 'where' => 'rid=' . $rid
  8374. ) );
  8375. return '/receiptburEdi/' . $rid;
  8376. } else
  8377. die ( 'illegal request2' );
  8378. }
  8379. function updateApprovalReceipt() {
  8380. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8381. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8382. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8383. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8384. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8385. if (! empty ( $rid )) {
  8386. Doo::loadModel ( "verify" );
  8387. $verify = new verify ();
  8388. Doo::loadModel ( "receiptDetail" );
  8389. $receiptDetailObj = new receiptDetail ();
  8390. Doo::loadModel ( "itemStatistics" );
  8391. Doo::loadModel ( "statistics" );
  8392. $statistics = new statistics ();
  8393. $itemStatistics = new itemStatistics ();
  8394. Doo::loadModel ( "receipt" );
  8395. $receipt = new receipt ();
  8396. $receiptDetail = $receipt->getOne ( array (
  8397. 'where' => 'rid=' . $rid . ' and status=2 ',
  8398. 'asArray' => true
  8399. ) );
  8400. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8401. $nsflag = true;
  8402. foreach ( $nslist as $value ) {
  8403. if ($value == $this->staff ['0'] ['sid']) {
  8404. $nsflag = false;
  8405. break;
  8406. }
  8407. }
  8408. if (empty ( $receiptDetail ) || $nsflag)
  8409. return "/approvalExpenses/pendApproval";
  8410. $verifyDetail = $verify->getOne ( array (
  8411. 'where' => ' vid =' . $receiptDetail ['verify'],
  8412. 'asArray' => true
  8413. ) );
  8414. $verifyString = $verifyDetail ['staff'];
  8415. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8416. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8417. if (empty ( $opinion )) {
  8418. if ($status == 3)
  8419. $opinion = "终止";
  8420. else
  8421. $opinion = "同意支付";
  8422. }
  8423. $nowStaff = 0;
  8424. $nowStaffList = array ();
  8425. if (empty ( $verifyStaff )) {
  8426. // 还需加入是否已经进入角色审批
  8427. if ($verifyDetail [0] [1] == 'ROLE') {
  8428. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8429. foreach ( $vStaffString as $key => $value ) {
  8430. $staffK = explode ( "_", $value );
  8431. if ($staffK [0] != $this->staff [0] ['sid'])
  8432. array_push ( $nowStaffList, $staffK [0] );
  8433. }
  8434. // print_r($verifyDetail);
  8435. // die;
  8436. if (! empty ( $nowStaffList )) {
  8437. $nowStaff = implode ( ',', $nowStaffList );
  8438. $verifyStaff = array (
  8439. $this->staff [0] ['sid'] . "_R" => array (
  8440. 'date' => date ( 'Y-m-d' ),
  8441. 'opinion' => $opinion,
  8442. 'status' => $status,
  8443. 'nextStaff' => $verifyDetail [0] [0],
  8444. 'ROLE' => 1
  8445. )
  8446. );
  8447. } else {
  8448. $nowStaff = $verifyDetail [1] [0];
  8449. $verifyStaff = array (
  8450. $this->staff [0] ['sid'] . "_R" => array (
  8451. 'date' => date ( 'Y-m-d' ),
  8452. 'opinion' => $opinion,
  8453. 'status' => $status,
  8454. 'nextStaff' => $verifyDetail [1] [0]
  8455. )
  8456. );
  8457. }
  8458. } else {
  8459. if ($verifyDetail [1] [1] == 'ROLE') {
  8460. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8461. // echo "dd";
  8462. foreach ( $vStaffString as $key => $value ) {
  8463. $staffK = explode ( "_", $value );
  8464. array_push ( $nowStaffList, $staffK [0] );
  8465. }
  8466. $nowStaff = implode ( ',', $nowStaffList );
  8467. $verifyStaff = array (
  8468. $this->staff [0] ['sid'] => array (
  8469. 'date' => date ( 'Y-m-d' ),
  8470. 'opinion' => $opinion,
  8471. 'status' => $status,
  8472. 'nextStaff' => $verifyDetail [1] [0],
  8473. 'ROLE' => 1
  8474. )
  8475. );
  8476. } else {
  8477. $nowStaff = $verifyDetail [1] [0];
  8478. $verifyStaff = array (
  8479. $this->staff [0] ['sid'] => array (
  8480. 'date' => date ( 'Y-m-d' ),
  8481. 'opinion' => $opinion,
  8482. 'status' => $status,
  8483. 'nextStaff' => $verifyDetail [1] [0]
  8484. )
  8485. );
  8486. }
  8487. }
  8488. if ($status == 3)
  8489. $verifyStaff = array (
  8490. 'final' => $status,
  8491. $this->staff [0] ['sid'] => array (
  8492. 'date' => date ( 'Y-m-d' ),
  8493. 'opinion' => $opinion,
  8494. 'status' => $status
  8495. )
  8496. );
  8497. $vStaffString = json_encode ( $verifyStaff );
  8498. $receipt->nowStaff = $nowStaff;
  8499. $receipt->verifyStaff = $vStaffString;
  8500. } else {
  8501. $VS = end ( $verifyStaff );
  8502. // 非角色审批
  8503. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8504. $nextStaff = 0;
  8505. $roleSTF = false;
  8506. foreach ( $verifyDetail as $key => $value ) {
  8507. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8508. if (isset ( $verifyDetail [$key + 1] )) {
  8509. $nextStaff = $verifyDetail [$key + 1] [0];
  8510. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8511. $roleSTF = true;
  8512. }
  8513. break;
  8514. }
  8515. }
  8516. if (! $roleSTF) {
  8517. $nowStaff = $nextStaff;
  8518. $verifyStaff [$this->staff [0] ['sid']] = array (
  8519. 'date' => date ( 'Y-m-d' ),
  8520. 'opinion' => $opinion,
  8521. 'status' => $status,
  8522. 'nextStaff' => $nextStaff
  8523. );
  8524. } else {
  8525. // 获取角色下的所有用户ID
  8526. $nowStaffList = array ();
  8527. foreach ( $verifyDetail as $vfk ) {
  8528. if ($vfk [1] == 'ROLE') {
  8529. $vStaffString = json_decode ( $vfk [3] );
  8530. foreach ( $vStaffString as $key => $value ) {
  8531. $staffK = explode ( "_", $value );
  8532. array_push ( $nowStaffList, $staffK [0] );
  8533. }
  8534. }
  8535. }
  8536. $nowStaff = implode ( ',', $nowStaffList );
  8537. $verifyStaff [$this->staff [0] ['sid']] = array (
  8538. 'date' => date ( 'Y-m-d' ),
  8539. 'opinion' => $opinion,
  8540. 'status' => $status,
  8541. 'nextStaff' => $nextStaff,
  8542. 'ROLE' => 0
  8543. );
  8544. }
  8545. if ($status == 3) {
  8546. $verifyStaff ['final'] = $status;
  8547. $verifyStaff [$this->staff [0] ['sid']] = array (
  8548. 'date' => date ( 'Y-m-d' ),
  8549. 'opinion' => $opinion,
  8550. 'status' => $status
  8551. );
  8552. }
  8553. $vStaffString = json_encode ( $verifyStaff );
  8554. $receipt->nowStaff = $nowStaff;
  8555. $receipt->verifyStaff = $vStaffString;
  8556. }
  8557. // 角色审批
  8558. if (isset ( $VS ['ROLE'] )) {
  8559. // 找出角色人 当前审批角色组
  8560. $verifyJSStaff = array ();
  8561. $nowStaffList2 = array ();
  8562. foreach ( $verifyDetail as $key => $value ) {
  8563. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8564. $verifyJSStaff = json_decode ( $value [3] );
  8565. foreach ( $verifyJSStaff as $m ) {
  8566. $staffK = explode ( "_", $m );
  8567. array_push ( $nowStaffList2, $staffK [0] );
  8568. }
  8569. // print_r($nowStaffList2);
  8570. }
  8571. }
  8572. $RoleVerifyStaff = array ();
  8573. foreach ( $verifyStaff as $key => $value ) {
  8574. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8575. foreach ( $nowStaffList2 as $m ) {
  8576. if ($key == $m . "_R")
  8577. $RoleVerifyStaff [$key] = $value;
  8578. }
  8579. }
  8580. }
  8581. // print_r($verifyStaff);
  8582. // print_r($nowStaffList2);
  8583. // print_r($RoleVerifyStaff);
  8584. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8585. // print_r($verifyJSStaff);
  8586. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8587. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8588. // 下一个审批人ID
  8589. $nextStaff = 0;
  8590. $falg = false;
  8591. foreach ( $verifyDetail as $key => $value ) {
  8592. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8593. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8594. $falg = true;
  8595. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8596. $nowStaffList = array ();
  8597. foreach ( $vStaffString as $v ) {
  8598. $staffK = explode ( "_", $v );
  8599. array_push ( $nowStaffList, $staffK [0] );
  8600. }
  8601. $nowStaff = implode ( ',', $nowStaffList );
  8602. $nextStaff = $verifyDetail [$key + 1] [0];
  8603. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8604. $nextStaff = $verifyDetail [$key + 1] [0];
  8605. $nowStaff = $nextStaff;
  8606. } else
  8607. $nowStaff = '';
  8608. break;
  8609. }
  8610. }
  8611. if ($falg)
  8612. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8613. 'date' => date ( 'Y-m-d' ),
  8614. 'opinion' => $opinion,
  8615. 'status' => $status,
  8616. 'nextStaff' => $nextStaff,
  8617. 'ROLE' => 1
  8618. );
  8619. else
  8620. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8621. 'date' => date ( 'Y-m-d' ),
  8622. 'opinion' => $opinion,
  8623. 'status' => $status,
  8624. 'nextStaff' => $nextStaff
  8625. );
  8626. // print_r($verifyStaff);
  8627. // echo $nowStaff;die;
  8628. } else { // 进入下一个角色或者审批人
  8629. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8630. //
  8631. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8632. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8633. 'date' => date ( 'Y-m-d' ),
  8634. 'opinion' => $opinion,
  8635. 'status' => $status,
  8636. 'nextStaff' => $VS ['nextStaff'],
  8637. 'ROLE' => 1
  8638. );
  8639. // print_r($verifyStaff);
  8640. // die;
  8641. }
  8642. if ($status == 3) {
  8643. $verifyStaff ['final'] = $status;
  8644. $verifyStaff [$this->staff [0] ['sid']] = array (
  8645. 'date' => date ( 'Y-m-d' ),
  8646. 'opinion' => $opinion,
  8647. 'status' => $status
  8648. );
  8649. }
  8650. $vStaffString = json_encode ( $verifyStaff );
  8651. $receipt->verifyStaff = $vStaffString;
  8652. $receipt->nowStaff = $nowStaff;
  8653. // die;
  8654. // }
  8655. // print_r($verifyStaff);
  8656. // die;
  8657. }
  8658. // print_r($verifyStaff);die;
  8659. }
  8660. // print_r($verifyDetail);
  8661. $roleKey = 0;
  8662. $roleId = 0;
  8663. $verifyDetailCopy = array ();
  8664. foreach ( $verifyDetail as $k => $v ) {
  8665. if ($v [1] == 'ROLE') {
  8666. $roleId = $v [0];
  8667. $roleVerify = json_decode ( $v [3], true );
  8668. $roleKey = $k;
  8669. $roleArray = array ();
  8670. foreach ( $roleVerify as $o => $p ) {
  8671. $staffID = explode ( '_', $p );
  8672. $exp = array (
  8673. 0 => $staffID [0],
  8674. 1 => $staffID [1]
  8675. );
  8676. array_push ( $roleArray, $exp );
  8677. }
  8678. $verifyDetailCopy [$v [0]] = $roleArray;
  8679. }
  8680. }
  8681. // print_r($verifyDetail);
  8682. foreach ( $verifyDetailCopy as $k => $v ) {
  8683. foreach ( $verifyDetail as $m => $n ) {
  8684. if ($n [0] == $k) {
  8685. array_splice ( $verifyDetail, $m, 1, $v );
  8686. }
  8687. }
  8688. }
  8689. // die;
  8690. // if (!empty($roleArray))
  8691. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8692. // echo $roleId;
  8693. // print_r($verifyStaff);
  8694. // print_r($verifyDetail);
  8695. // die;
  8696. Doo::loadModel ( "receiptLog" );
  8697. $receiptLog = new receiptLog ();
  8698. // 审批日志
  8699. if (! isset ( $verifyStaff ['final'] )) {
  8700. if (! empty ( $roleId )) {
  8701. Doo::loadModel ( "role" );
  8702. $role = new role ();
  8703. $roleInfo = $role->getOne ( array (
  8704. 'where' => 'rid=' . $roleId,
  8705. 'asArray' => true
  8706. ) );
  8707. $receiptLog->rolename = $roleInfo ['name'];
  8708. }
  8709. $receiptLog->username = $this->staff [0] ['username'];
  8710. $receiptLog->uid = $this->staff [0] ['sid'];
  8711. $receiptLog->date = date ( "Y-m-d" );
  8712. $receiptLog->opinion = $opinion;
  8713. $receiptLog->img = $this->staff [0] ['avatar'];
  8714. $receiptLog->status = 1;
  8715. $receiptLog->rid = $rid;
  8716. $receiptLog->insert ();
  8717. }
  8718. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8719. $receipt->verifyBreakup = $verifyString;
  8720. $receipt->status = 3;
  8721. $receiptDetailObj->status = 3;
  8722. $receiptDetailObj->update ( array (
  8723. 'where' => 'rid=' . $rid
  8724. ) );
  8725. if (! empty ( $roleId )) {
  8726. Doo::loadModel ( "role" );
  8727. $role = new role ();
  8728. $roleInfo = $role->getOne ( array (
  8729. 'where' => 'rid=' . $roleId,
  8730. 'asArray' => true
  8731. ) );
  8732. $receiptLog->rolename = $roleInfo ['name'];
  8733. }
  8734. $receiptLog->username = $this->staff [0] ['username'];
  8735. $receiptLog->uid = $this->staff [0] ['sid'];
  8736. $receiptLog->date = date ( "Y-m-d" );
  8737. $receiptLog->opinion = $opinion;
  8738. $receiptLog->img = $this->staff [0] ['avatar'];
  8739. $receiptLog->status = 3;
  8740. $receiptLog->rid = $rid;
  8741. $receiptLog->insert ();
  8742. // 微信企业号通知
  8743. $this->setWXMsg ( $rid, 3 );
  8744. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8745. $receipt->status = 1;
  8746. $reviseSum = 0;
  8747. $receipt->verifyBreakup = $verifyString;
  8748. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8749. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8750. foreach ( $reviseDetail as $key => $value ) {
  8751. $receiptDetailObj = new receiptDetail ();
  8752. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8753. $receiptDetailObj->item = $value ['description'];
  8754. $receiptDetailObj->itemCategory = "报销金额调整";
  8755. $receiptDetailObj->price = $value ['price'];
  8756. $receiptDetailObj->date = $receiptDetail ['date'];
  8757. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8758. $receiptDetailObj->rid = $rid;
  8759. $receiptDetailObj->status = 1;
  8760. $receiptDetailObj->insert ();
  8761. $reviseSum += $value ['price'];
  8762. }
  8763. $itemStatistics = new itemStatistics ();
  8764. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8765. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8766. $itemStatistics->price = $reviseSum;
  8767. $itemStatistics->itemCategory = "报销金额调整";
  8768. $itemStatistics->date = $receiptDetail ['date'];
  8769. $itemStatistics->insert ();
  8770. }
  8771. $receiptDetailObj = new receiptDetail ();
  8772. $receiptDetailObj->status = 1;
  8773. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8774. $receiptDetailObj->update ( array (
  8775. 'where' => 'rid=' . $rid
  8776. ) );
  8777. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8778. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8779. $stat = $statistics->getOne ( array (
  8780. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8781. 'asArray' => true
  8782. ) );
  8783. if (empty ( $stat )) {
  8784. $statistics->date = $receiptDetail ['date'];
  8785. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8786. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8787. $statistics->agPrice = $receiptDetail ['sum'];
  8788. $statistics->rePrice = $reviseSum;
  8789. $statistics->insert ();
  8790. } else {
  8791. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8792. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8793. $statistics->update ( array (
  8794. 'where' => 'sid=' . $stat ['sid']
  8795. ) );
  8796. }
  8797. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8798. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8799. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8800. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8801. if ($key == "agencySum") {
  8802. $iStatistics = $itemStatistics->getOne ( array (
  8803. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8804. 'asArray' => true
  8805. ) );
  8806. if (empty ( $iStatistics )) {
  8807. $itemStatistics->cid = $receiptDetail ['cid'];
  8808. ;
  8809. $itemStatistics->staff = $receiptDetail ['staff'];
  8810. $itemStatistics->price = $value;
  8811. $itemStatistics->itemCategory = $this->AGENCY;
  8812. $itemStatistics->date = $receiptDetail ['date'];
  8813. $itemStatistics->insert ();
  8814. } else {
  8815. if (! empty ( $value )) {
  8816. $itemStatistics->price = $value + $iStatistics ['price'];
  8817. $itemStatistics->update ( array (
  8818. 'where' => 'sid=' . $iStatistics ['sid']
  8819. ) );
  8820. }
  8821. }
  8822. } elseif ($key == "travelSum") {
  8823. $iStatistics = $itemStatistics->getOne ( array (
  8824. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8825. 'asArray' => true
  8826. ) );
  8827. if (empty ( $iStatistics )) {
  8828. $itemStatistics->cid = $receiptDetail ['cid'];
  8829. $itemStatistics->staff = $receiptDetail ['staff'];
  8830. $itemStatistics->price = $value;
  8831. $itemStatistics->itemCategory = $this->TRAVEL;
  8832. $itemStatistics->date = $receiptDetail ['date'];
  8833. $itemStatistics->insert ();
  8834. } else {
  8835. if (! empty ( $value )) {
  8836. $itemStatistics->price = $value + $iStatistics ['price'];
  8837. $itemStatistics->update ( array (
  8838. 'where' => 'sid=' . $iStatistics ['sid']
  8839. ) );
  8840. }
  8841. }
  8842. } elseif ($key == "trainSum") {
  8843. $iStatistics = $itemStatistics->getOne ( array (
  8844. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8845. 'asArray' => true
  8846. ) );
  8847. if (empty ( $iStatistics )) {
  8848. $itemStatistics->cid = $receiptDetail ['cid'];
  8849. $itemStatistics->staff = $receiptDetail ['staff'];
  8850. $itemStatistics->price = $value;
  8851. $itemStatistics->itemCategory = $this->TRAIN;
  8852. $itemStatistics->date = $receiptDetail ['date'];
  8853. $itemStatistics->insert ();
  8854. } else {
  8855. if (! empty ( $value )) {
  8856. $itemStatistics->price = $value + $iStatistics ['price'];
  8857. $itemStatistics->update ( array (
  8858. 'where' => 'sid=' . $iStatistics ['sid']
  8859. ) );
  8860. }
  8861. }
  8862. } elseif ($key == "otherSum") {
  8863. $iStatistics = $itemStatistics->getOne ( array (
  8864. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8865. 'asArray' => true
  8866. ) );
  8867. if (empty ( $iStatistics )) {
  8868. $itemStatistics->cid = $receiptDetail ['cid'];
  8869. $itemStatistics->staff = $receiptDetail ['staff'];
  8870. $itemStatistics->price = $value;
  8871. $itemStatistics->itemCategory = $this->OTHER;
  8872. $itemStatistics->date = $receiptDetail ['date'];
  8873. $itemStatistics->insert ();
  8874. } else {
  8875. if (! empty ( $value )) {
  8876. $itemStatistics->price = $value + $iStatistics ['price'];
  8877. $itemStatistics->update ( array (
  8878. 'where' => 'sid=' . $iStatistics ['sid']
  8879. ) );
  8880. }
  8881. }
  8882. }
  8883. }
  8884. $receipt->pastDate = date ( "Y-m-d" );
  8885. // 微信企业号通知
  8886. $this->setWXMsg ( $rid, 1 );
  8887. }
  8888. //是否有流水
  8889. Doo::loadModel ( 'wasteBook' );
  8890. $wasteBook = new wasteBook ();
  8891. $accountType=3;
  8892. if ($receiptDetail['Rtype']==1){
  8893. $accountType=2;
  8894. }elseif($receiptDetail['Rtype']==2){
  8895. $accountType=4;
  8896. }
  8897. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8898. if (empty($wbDetail)){
  8899. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  8900. $receipt->amount = $rsum;//$amount;
  8901. }
  8902. $receipt->update ( array (
  8903. 'where' => ' rid = ' . $rid
  8904. ) );
  8905. // 进入下一条审批费用新加需求
  8906. $vidList = array ();
  8907. $verifyDetail = $verify->find ( array (
  8908. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8909. 'asArray' => true
  8910. ) );
  8911. foreach ( $verifyDetail as $key => $value ) {
  8912. array_push ( $vidList, $value ['vid'] );
  8913. }
  8914. $vid = implode ( ",", $vidList );
  8915. if (empty ( $verifyDetail ))
  8916. $vid = 0;
  8917. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8918. $receipt = new receipt ();
  8919. $rd = $receipt->getOne ( array (
  8920. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8921. 'asc' => 'rid',
  8922. 'asArray' => true
  8923. ) );
  8924. if (empty ( $rd )) {
  8925. return '/approvalExpenses/pendApproval';
  8926. }
  8927. if ($rd ['Rtype'] == 1) {
  8928. if ($rd ['isBK'] == 1) {
  8929. return '/receiptburEdi/' . $rd ['rid'];
  8930. } else {
  8931. return '/expensesEdi/' . $rd ['rid'];
  8932. }
  8933. } elseif ($rd ['Rtype'] == 2) {
  8934. return '/remitApproval/' . $rd ['rid'];
  8935. } else {
  8936. return '/receiptburEdi/' . $rd ['rid'];
  8937. }
  8938. // return "/approvalExpenses/pendApproval";
  8939. }
  8940. }
  8941. function expensesRetreats() {
  8942. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8943. if (! empty ( $rid )) {
  8944. // 操作记录
  8945. Doo::loadModel ( "receipt" );
  8946. $receipt = new receipt ();
  8947. Doo::loadModel ( "receiptLog" );
  8948. $receiptLog = new receiptLog ();
  8949. Doo::loadModel ( "verify" );
  8950. $verify = new verify ();
  8951. $receiptInfo = $receipt->getOne ( array (
  8952. 'where' => 'rid=' . $rid,
  8953. 'asArray' => true
  8954. ) );
  8955. $vr = $verify->getOne ( array (
  8956. 'where' => 'vid=' . $receiptInfo ['verify'],
  8957. 'asArray' => true
  8958. ) );
  8959. $jd = json_decode ( $vr ['staff'] );
  8960. $roleId = 0;
  8961. foreach ( $jd as $key => $value ) {
  8962. if ($value [1] == 'ROLE') {
  8963. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8964. if ($pos !== false) {
  8965. $roleId = $value [0];
  8966. }
  8967. }
  8968. }
  8969. // 审批日志
  8970. // echo $roleId;die;
  8971. if (! empty ( $roleId )) {
  8972. Doo::loadModel ( "role" );
  8973. $role = new role ();
  8974. $roleInfo = $role->getOne ( array (
  8975. 'where' => 'rid=' . $roleId,
  8976. 'asArray' => true
  8977. ) );
  8978. $receiptLog->rolename = $roleInfo ['name'];
  8979. }
  8980. $receiptLog->username = $this->staff [0] ['username'];
  8981. $receiptLog->uid = $this->staff [0] ['sid'];
  8982. $receiptLog->date = date ( "Y-m-d" );
  8983. $receiptLog->opinion = '撤回';
  8984. $receiptLog->img = $this->staff [0] ['avatar'];
  8985. $receiptLog->status = 4;
  8986. $receiptLog->rid = $rid;
  8987. $receiptLog->insert ();
  8988. $receipt->status = 4;
  8989. $receipt->update ( array (
  8990. 'where' => 'rid=' . $rid
  8991. ) );
  8992. // 微信企业号通知
  8993. $this->setWXMsg ( $rid, 2 );
  8994. }
  8995. // echo "ddd";
  8996. return '/approvalExpenses/pendApproval';
  8997. }
  8998. function updateCheReceipt() {
  8999. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9000. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9001. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9002. if (! empty ( $rid )) {
  9003. // 操作记录
  9004. Doo::loadModel ( "receipt" );
  9005. $receipt = new receipt ();
  9006. Doo::loadModel ( "receiptLog" );
  9007. $receiptLog = new receiptLog ();
  9008. Doo::loadModel ( "verify" );
  9009. $verify = new verify ();
  9010. $receiptInfo = $receipt->getOne ( array (
  9011. 'where' => 'rid=' . $rid . ' and status=2',
  9012. 'asArray' => true
  9013. ) );
  9014. if (empty ( $receiptInfo )) {
  9015. echo json_encode ( array (
  9016. 'status' => 2
  9017. ) );
  9018. die ();
  9019. }
  9020. $vr = $verify->getOne ( array (
  9021. 'where' => 'vid=' . $receiptInfo ['verify'],
  9022. 'asArray' => true
  9023. ) );
  9024. $jd = json_decode ( $vr ['staff'] );
  9025. $roleId = 0;
  9026. foreach ( $jd as $key => $value ) {
  9027. if ($value [1] == 'ROLE') {
  9028. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9029. if ($pos !== false) {
  9030. $roleId = $value [0];
  9031. }
  9032. }
  9033. }
  9034. // 审批日志
  9035. // echo $roleId;die;
  9036. if (! empty ( $roleId )) {
  9037. Doo::loadModel ( "role" );
  9038. $role = new role ();
  9039. $roleInfo = $role->getOne ( array (
  9040. 'where' => 'rid=' . $roleId,
  9041. 'asArray' => true
  9042. ) );
  9043. $receiptLog->rolename = $roleInfo ['name'];
  9044. }
  9045. $receiptLog->username = $this->staff [0] ['username'];
  9046. $receiptLog->uid = $this->staff [0] ['sid'];
  9047. $receiptLog->date = date ( "Y-m-d" );
  9048. $receiptLog->opinion = $opinion;
  9049. $receiptLog->img = $this->staff [0] ['avatar'];
  9050. $receiptLog->status = 4;
  9051. $receiptLog->rid = $rid;
  9052. $receiptLog->insert ();
  9053. $receipt->status = 4;
  9054. $receipt->update ( array (
  9055. 'where' => 'rid=' . $rid
  9056. ) );
  9057. // 微信企业号通知
  9058. $this->setWXMsg ( $rid, 2 );
  9059. echo json_encode ( array (
  9060. 'status' => 1
  9061. ) );
  9062. // Header("HTTP/1.1 303 See Other");
  9063. // Header("Location: /approvalExpenses/pendApproval");
  9064. die ();
  9065. }
  9066. echo json_encode ( array (
  9067. 'status' => 2
  9068. ) );
  9069. die ();
  9070. // echo "ddd";
  9071. // return '/saeaBorad';
  9072. }
  9073. function revisePrice() {
  9074. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9075. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9076. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9077. // echo $price;die;
  9078. if (! empty ( $rid )) {
  9079. Doo::loadModel ( "receipt" );
  9080. $receipt = new receipt ();
  9081. $receiptDetail = $receipt->getOne ( array (
  9082. 'where' => 'rid=' . $rid . ' and status=2 ',
  9083. 'asArray' => true
  9084. ) );
  9085. if (empty ( $receiptDetail ))
  9086. die ( 'illegal request' );
  9087. $reviseDetail = array ();
  9088. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9089. array_push ( $reviseDetail, array (
  9090. 'sid' => $this->staff [0] ['sid'],
  9091. 'name' => $this->staff [0] ['username'],
  9092. 'description' => $description,
  9093. 'price' => $price
  9094. ) );
  9095. $reviseDetailString = json_encode ( $reviseDetail );
  9096. $receipt->reviseDetail = $reviseDetailString;
  9097. $receipt->revisePrice = $price;
  9098. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9099. } else {
  9100. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9101. array_push ( $reviseDetail, array (
  9102. 'sid' => $this->staff [0] ['sid'],
  9103. 'name' => $this->staff [0] ['username'],
  9104. 'description' => $description,
  9105. 'price' => $price
  9106. ) );
  9107. $reviseDetailString = json_encode ( $reviseDetail );
  9108. $receipt->reviseDetail = $reviseDetailString;
  9109. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9110. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9111. }
  9112. $receipt->update ( array (
  9113. 'where' => 'rid=' . $rid
  9114. ) );
  9115. if ($receiptDetail ['Rtype'] == 1) {
  9116. if ($receiptDetail ['isBK'] == 1) {
  9117. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9118. }
  9119. } elseif ($receiptDetail ['Rtype'] == 2) {
  9120. } else {
  9121. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9122. }
  9123. }
  9124. die ( 'illegal request' );
  9125. }
  9126. function personalCollect() {
  9127. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9128. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9129. $this->showCache ( $path );
  9130. Doo::loadModel ( "receiptDetail" );
  9131. Doo::loadModel ( "itemStatistics" );
  9132. Doo::loadModel ( 'statistics' );
  9133. $statistics = new statistics ();
  9134. $itemStatistics = new itemStatistics ();
  9135. $receiptDetail = new receiptDetail ();
  9136. $receiptCollectList = $receiptDetail->find ( array (
  9137. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9138. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9139. 'groupby' => 'itemCategory,Month(date)',
  9140. 'asArray' => true
  9141. ) );
  9142. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9143. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9144. 'asArray' => true
  9145. ) );
  9146. // create collect html
  9147. $collectArray = array (
  9148. '日常相关费用' => array (),
  9149. '差旅相关费用' => array (),
  9150. '培训班费用' => array (),
  9151. '其他' => array ()
  9152. );
  9153. $adjustment = array ();
  9154. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9155. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9156. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9157. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9158. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9159. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9160. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9161. array_push ( $collectArray ['其他'], $collectHtml );
  9162. $data ['collectArray'] = $collectArray;
  9163. // statistics html
  9164. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9165. if (empty ( $stList ))
  9166. $stList = array (
  9167. 'rePrice' => 0,
  9168. 'agPrice' => 0
  9169. );
  9170. $data ['stList'] = array (
  9171. 'rePrice' => $stList ['rePrice'],
  9172. 'agPrice' => $stList ['agPrice'],
  9173. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9174. );
  9175. // Adjustment price html
  9176. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9177. array_push ( $adjustment, $collectHtml );
  9178. $data ['adjustment'] = $adjustment;
  9179. // total price html
  9180. $collectHtml = "";
  9181. $total = 0;
  9182. for($i = 1; $i <= 12; $i ++) {
  9183. $sumPrice = 0;
  9184. foreach ( $receiptCollectList as $key => $value ) {
  9185. if ($value ['month'] == $i) {
  9186. $sumPrice += $value ['price'];
  9187. }
  9188. }
  9189. if ($sumPrice == 0)
  9190. $collectHtml .= '<td class="taR">-</td>';
  9191. else
  9192. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9193. $total += $sumPrice;
  9194. }
  9195. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9196. $data ['totalPrice'] = $collectHtml;
  9197. $dateHtml = "";
  9198. $now = date ( "Y" );
  9199. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9200. if ($YEARD <= $now) {
  9201. $dateHtml .= '<option ';
  9202. if ($year == $YEARD) {
  9203. $dateHtml .= 'selected ';
  9204. }
  9205. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9206. }
  9207. }
  9208. $data ['dateHtml'] = $dateHtml;
  9209. $data ['year'] = $year;
  9210. $data ['totalYear'] = $total;
  9211. $data ['memu'] = "receipt";
  9212. $data ['staff'] = $this->staff;
  9213. $data ['receiptMemu'] = 'personalCollect';
  9214. $data ['verifyId'] = $this->verifyId;
  9215. $data ['executeId'] = $this->executeId;
  9216. // year staff status 2,4
  9217. if ($year < date ( "Y" )) {
  9218. Doo::loadModel ( 'receipt' );
  9219. $receipt = new receipt ();
  9220. $receiptList = $receipt->find ( array (
  9221. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9222. 'asArray' => true
  9223. ) );
  9224. if (empty ( $receiptList )) {
  9225. ob_start ();
  9226. $this->render ( "/admin/saea_slist_collect", $data );
  9227. $this->cacheFile ( $path );
  9228. die ();
  9229. }
  9230. }
  9231. $this->render ( "/admin/saea_slist_collect", $data );
  9232. }
  9233. function personalCollectDetail() {
  9234. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9235. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9236. $this->showCache ( $path );
  9237. Doo::loadModel ( "receiptDetail" );
  9238. Doo::loadModel ( "itemStatistics" );
  9239. Doo::loadModel ( 'statistics' );
  9240. Doo::loadModel ( 'accountItem' );
  9241. $accountItem = new accountItem ();
  9242. $statistics = new statistics ();
  9243. $itemStatistics = new itemStatistics ();
  9244. $receiptDetail = new receiptDetail ();
  9245. $receiptCollectList = $receiptDetail->find ( array (
  9246. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9247. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9248. 'groupby' => 'item,Month(date)',
  9249. 'asArray' => true
  9250. ) );
  9251. $accountList = $accountItem->find ( array (
  9252. 'asArray' => true
  9253. ) );
  9254. // create CollectDetail HTML
  9255. $collectHtml = array ();
  9256. foreach ( $accountList as $key => $value ) {
  9257. $html = "";
  9258. $asum = 0;
  9259. for($i = 1; $i <= 12; $i ++) {
  9260. $falg = true;
  9261. foreach ( $receiptCollectList as $v ) {
  9262. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9263. $asum += $v ['price'];
  9264. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9265. $falg = false;
  9266. break;
  9267. }
  9268. }
  9269. if ($falg)
  9270. $html .= '<td class="taR">-</td>';
  9271. }
  9272. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9273. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9274. }
  9275. $data ['collectHtml'] = $collectHtml;
  9276. // create Adjustment price html
  9277. $receiptCollectList = $receiptDetail->find ( array (
  9278. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9279. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9280. 'groupby' => 'itemCategory,Month(date)',
  9281. 'asArray' => true
  9282. ) );
  9283. $adjustment = array ();
  9284. $collectArray = array (
  9285. '日常相关费用' => array (),
  9286. '差旅相关费用' => array (),
  9287. '培训班费用' => array (),
  9288. '其他' => array ()
  9289. );
  9290. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9291. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9292. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9293. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9294. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9295. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9296. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9297. array_push ( $collectArray ['其他'], $collectHtml );
  9298. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9299. array_push ( $adjustment, $collectHtml );
  9300. // total price html
  9301. $collectHtml = "";
  9302. $total = 0;
  9303. for($i = 1; $i <= 12; $i ++) {
  9304. $sumPrice = 0;
  9305. foreach ( $receiptCollectList as $key => $value ) {
  9306. if ($value ['month'] == $i) {
  9307. $sumPrice += $value ['price'];
  9308. }
  9309. }
  9310. if ($sumPrice == 0)
  9311. $collectHtml .= '<td class="taR">-</td>';
  9312. else
  9313. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9314. $total += $sumPrice;
  9315. }
  9316. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9317. // statistics html
  9318. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9319. if (empty ( $stList ))
  9320. $stList = array (
  9321. 'rePrice' => 0,
  9322. 'agPrice' => 0
  9323. );
  9324. $data ['stList'] = array (
  9325. 'rePrice' => $stList ['rePrice'],
  9326. 'agPrice' => $stList ['agPrice'],
  9327. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9328. );
  9329. $data ['collectArray'] = $collectArray;
  9330. $data ['adjustment'] = $adjustment;
  9331. $data ['totalPrice'] = $collectHtml;
  9332. $data ['totalYear'] = $total;
  9333. $data ['year'] = $year;
  9334. $dateHtml = "";
  9335. $now = date ( "Y" );
  9336. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9337. if ($YEARD <= $now) {
  9338. $dateHtml .= '<option ';
  9339. if ($year == $YEARD) {
  9340. $dateHtml .= 'selected ';
  9341. }
  9342. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9343. }
  9344. }
  9345. $data ['dateHtml'] = $dateHtml;
  9346. $data ['memu'] = "receipt";
  9347. $data ['staff'] = $this->staff;
  9348. $data ['receiptMemu'] = 'personalCollect';
  9349. $data ['verifyId'] = $this->verifyId;
  9350. $data ['executeId'] = $this->executeId;
  9351. // year staff status 2,4
  9352. if ($year < date ( "Y" )) {
  9353. Doo::loadModel ( 'receipt' );
  9354. $receipt = new receipt ();
  9355. $receiptList = $receipt->find ( array (
  9356. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9357. 'asArray' => true
  9358. ) );
  9359. if (empty ( $receiptList )) {
  9360. ob_start ();
  9361. $this->render ( "/admin/saeaCollectArticles", $data );
  9362. $this->cacheFile ( $path );
  9363. die ();
  9364. }
  9365. }
  9366. $this->render ( "/admin/saeaCollectArticles", $data );
  9367. }
  9368. function companyCategoryCollect() {
  9369. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9370. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9371. $this->showCache ( $path );
  9372. Doo::loadModel ( 'L_category' );
  9373. Doo::loadModel ( 'itemStatistics' );
  9374. Doo::loadModel ( 'statistics' );
  9375. $statistics = new statistics ();
  9376. $Lcategory = new L_category ();
  9377. $itemStatistics = new itemStatistics ();
  9378. Doo::loadModel ( "receiptAuthorityManage" );
  9379. $receiptAuthorityManage = new receiptAuthorityManage ();
  9380. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9381. $cidList = array ();
  9382. foreach ( $imcStaff as $key => $value ) {
  9383. array_push ( $cidList, $value ['cid'] );
  9384. }
  9385. $cidString = implode ( ',', $cidList );
  9386. $LcategoryList = $Lcategory->find ( array (
  9387. 'where' => ' cid in (' . $cidString . ')',
  9388. 'asArray' => true
  9389. ) ); // 'staff='.$this->staff[0]['sid']." and
  9390. $itemStatisticsList = $itemStatistics->find ( array (
  9391. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9392. 'where' => " Year(date)=" . $year,
  9393. 'groupby' => 'cid,Month(date)',
  9394. 'asArray' => true
  9395. ) );
  9396. // ceatre companyCollectHtml
  9397. foreach ( $LcategoryList as $value ) {
  9398. $html = "";
  9399. $asum = 0;
  9400. for($i = 1; $i <= 12; $i ++) {
  9401. $falg = true;
  9402. foreach ( $itemStatisticsList as $v ) {
  9403. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9404. $asum += $v ['price'];
  9405. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9406. $falg = false;
  9407. break;
  9408. }
  9409. }
  9410. if ($falg)
  9411. $html .= '<td class="taR">-</td>';
  9412. }
  9413. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9414. $collectHtml [$value ['title']] = array (
  9415. 'html' => $html,
  9416. 'cid' => $value ['cid']
  9417. );
  9418. }
  9419. $data ['companyHtml'] = $collectHtml;
  9420. // total price html
  9421. $collectHtml = "";
  9422. $total = 0;
  9423. for($i = 1; $i <= 12; $i ++) {
  9424. $sumPrice = 0;
  9425. foreach ( $itemStatisticsList as $key => $value ) {
  9426. if ($value ['month'] == $i) {
  9427. $sumPrice += $value ['price'];
  9428. }
  9429. }
  9430. if ($sumPrice == 0)
  9431. $collectHtml .= '<td class="taR">-</td>';
  9432. else
  9433. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9434. $total += $sumPrice;
  9435. }
  9436. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9437. $data ['companyTotalHtml'] = $collectHtml;
  9438. $data ['total'] = $total;
  9439. // statistics html
  9440. // echo $cidString;
  9441. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9442. if (empty ( $stList ))
  9443. $stList = array (
  9444. 'rePrice' => 0,
  9445. 'agPrice' => 0
  9446. );
  9447. $data ['stList'] = array (
  9448. 'rePrice' => $stList ['rePrice'],
  9449. 'agPrice' => $stList ['agPrice'],
  9450. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9451. );
  9452. $data ['year'] = $year;
  9453. $data ['memu'] = "receipt";
  9454. $data ['staff'] = $this->staff;
  9455. $data ['receiptMemu'] = 'companyCategoryCollect';
  9456. $data ['verifyId'] = $this->verifyId;
  9457. $data ['executeId'] = $this->executeId;
  9458. $dateHtml = "";
  9459. $now = date ( "Y" );
  9460. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9461. if ($YEARD <= $now) {
  9462. $dateHtml .= '<option ';
  9463. if ($year == $YEARD) {
  9464. $dateHtml .= 'selected ';
  9465. }
  9466. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9467. }
  9468. }
  9469. $data ['dateHtml'] = $dateHtml;
  9470. // year staff status 2,4
  9471. if ($year < date ( "Y" )) {
  9472. Doo::loadModel ( 'receipt' );
  9473. $receipt = new receipt ();
  9474. $receiptList = $receipt->find ( array (
  9475. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9476. 'asArray' => true
  9477. ) );
  9478. if (empty ( $receiptList )) {
  9479. ob_start ();
  9480. $this->render ( "/admin/saeaCompanyCollect", $data );
  9481. $this->cacheFile ( $path );
  9482. die ();
  9483. }
  9484. }
  9485. $this->render ( "/admin/saeaCompanyCollect", $data );
  9486. }
  9487. function categoryCollectDetail() {
  9488. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9489. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9490. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9491. $this->showCache ( $path );
  9492. Doo::loadModel ( 'statistics' );
  9493. $statistics = new statistics ();
  9494. Doo::loadModel ( "receiptDetail" );
  9495. $receiptDetail = new receiptDetail ();
  9496. Doo::loadModel ( 'L_category' );
  9497. $Lcategory = new L_category ();
  9498. Doo::loadModel ( 'accountItem' );
  9499. $accountItem = new accountItem ();
  9500. Doo::loadModel ( "receiptAuthorityManage" );
  9501. $receiptAuthorityManage = new receiptAuthorityManage ();
  9502. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9503. $cidList = array ();
  9504. foreach ( $imcStaff as $key => $value ) {
  9505. array_push ( $cidList, $value ['cid'] );
  9506. }
  9507. $cidString = implode ( ',', $cidList );
  9508. $LcategoryList = $Lcategory->find ( array (
  9509. 'where' => 'cid in (' . $cidString . ')',
  9510. 'asArray' => true
  9511. ) );
  9512. if ($cid == 0) {
  9513. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9514. if ($cid == 0)
  9515. $cid = $LcategoryList [0] ['cid'];
  9516. }
  9517. $data ['LcategoryList'] = $LcategoryList;
  9518. $receiptCollectList = $receiptDetail->find ( array (
  9519. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9520. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9521. 'groupby' => 'item,Month(pastDate)',
  9522. 'asArray' => true
  9523. ) );
  9524. $accountList = $accountItem->find ( array (
  9525. 'asArray' => true
  9526. ) );
  9527. // create CollectDetail HTML
  9528. $collectHtml = array ();
  9529. foreach ( $accountList as $key => $value ) {
  9530. $html = "";
  9531. $asum = 0;
  9532. for($i = 1; $i <= 12; $i ++) {
  9533. $falg = true;
  9534. foreach ( $receiptCollectList as $v ) {
  9535. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9536. $asum += $v ['price'];
  9537. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9538. $falg = false;
  9539. break;
  9540. }
  9541. }
  9542. if ($falg)
  9543. $html .= '<td class="taR">-</td>';
  9544. }
  9545. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9546. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9547. }
  9548. $data ['collectHtml'] = $collectHtml;
  9549. // create Adjustment price html
  9550. $receiptCollectList = $receiptDetail->find ( array (
  9551. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9552. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9553. 'groupby' => 'itemCategory,Month(pastDate)',
  9554. 'asArray' => true
  9555. ) );
  9556. $adjustment = array ();
  9557. $collectArray = array (
  9558. '日常相关费用' => array (),
  9559. '差旅相关费用' => array (),
  9560. '培训班费用' => array (),
  9561. '内部培训费用'=>array(),
  9562. '其他' => array ()
  9563. );
  9564. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9565. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9566. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9567. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9568. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9569. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9570. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9571. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9572. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9573. array_push ( $collectArray ['其他'], $collectHtml );
  9574. $data ['collectArray'] = $collectArray;
  9575. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9576. array_push ( $adjustment, $collectHtml );
  9577. $data ['adjustment'] = $adjustment;
  9578. // total price html
  9579. $collectHtml = "";
  9580. $total = 0;
  9581. for($i = 1; $i <= 12; $i ++) {
  9582. $sumPrice = 0;
  9583. foreach ( $receiptCollectList as $key => $value ) {
  9584. if ($value ['month'] == $i) {
  9585. $sumPrice += $value ['price'];
  9586. }
  9587. }
  9588. if ($sumPrice == 0)
  9589. $collectHtml .= '<td class="taR">-</td>';
  9590. else
  9591. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9592. $total += $sumPrice;
  9593. }
  9594. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9595. // statistics html
  9596. $stList = $statistics->statisticsByCid ( $year, $cid );
  9597. if (empty ( $stList ))
  9598. $stList = array (
  9599. 'rePrice' => 0,
  9600. 'agPrice' => 0
  9601. );
  9602. $data ['stList'] = array (
  9603. 'rePrice' => $stList ['rePrice'],
  9604. 'agPrice' => $stList ['agPrice'],
  9605. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9606. );
  9607. $data ['totalYear'] = $total;
  9608. $data ['year'] = $year;
  9609. $data ['cid'] = $cid;
  9610. $data ['memu'] = "receipt";
  9611. $data ['staff'] = $this->staff;
  9612. $data ['receiptMemu'] = 'companyCategoryCollect';
  9613. $data ['verifyId'] = $this->verifyId;
  9614. $data ['executeId'] = $this->executeId;
  9615. // year staff status 2,4
  9616. if ($year < date ( "Y" )) {
  9617. Doo::loadModel ( 'receipt' );
  9618. $receipt = new receipt ();
  9619. $receiptList = $receipt->find ( array (
  9620. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9621. 'asArray' => true
  9622. ) );
  9623. if (empty ( $receiptList )) {
  9624. ob_start ();
  9625. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9626. $this->cacheFile ( $path );
  9627. die ();
  9628. }
  9629. }
  9630. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9631. }
  9632. function staffCollect() {
  9633. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9634. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9635. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9636. // $this->showCache($path);
  9637. Doo::loadModel ( 'statistics' );
  9638. $statistics = new statistics ();
  9639. Doo::loadModel ( "receiptDetail" );
  9640. $receiptDetail = new receiptDetail ();
  9641. Doo::loadModel ( 'L_category' );
  9642. $Lcategory = new L_category ();
  9643. Doo::loadModel ( 'accountItem' );
  9644. $accountItem = new accountItem ();
  9645. Doo::loadModel ( 'staff' );
  9646. $staff = new staff ();
  9647. Doo::loadModel ( 'itemStatistics' );
  9648. $itemStatistics = new itemStatistics ();
  9649. Doo::loadModel ( "receiptAuthorityManage" );
  9650. $receiptAuthorityManage = new receiptAuthorityManage ();
  9651. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9652. $cidList = array ();
  9653. foreach ( $imcStaff as $key => $value ) {
  9654. array_push ( $cidList, $value ['cid'] );
  9655. }
  9656. $cidString = implode ( ',', $cidList );
  9657. $naturecon='';
  9658. if ($nature=='ONJOB'){
  9659. $naturecon=' and (nature!=4 )';
  9660. }elseif($nature=='LEAVEJOB'){
  9661. $naturecon=' and (nature=4 )';
  9662. }else{
  9663. die ( 'illegal request--nature' );
  9664. }
  9665. // statistics html
  9666. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9667. if (empty ( $stList ))
  9668. $stList = array (
  9669. 'rePrice' => 0,
  9670. 'agPrice' => 0
  9671. );
  9672. $data ['stList'] = array (
  9673. 'rePrice' => $stList ['rePrice'],
  9674. 'agPrice' => $stList ['agPrice'],
  9675. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9676. );
  9677. // ---
  9678. $staffList = $staff->find ( array (
  9679. 'where' => 'username !="admin" '.$naturecon,
  9680. 'asArray' => true
  9681. ) );
  9682. $LcategoryList = $Lcategory->find ( array (
  9683. 'asArray' => true
  9684. ) ); // 'staff='.$this->staff[0]['sid']." and
  9685. $itemStatisticsList = $itemStatistics->find ( array (
  9686. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9687. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9688. 'groupby' => 'staff,Month(date)',
  9689. 'asArray' => true
  9690. ) );
  9691. $categoryList = $staff->find ( array (
  9692. 'select' => 'COUNT(*) as count,cid,category',
  9693. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9694. 'groupby' => 'cid',
  9695. 'asArray' => true
  9696. ) );
  9697. // print_r($itemStatisticsList);die;
  9698. // ceatre companyCollectHtml
  9699. foreach ( $categoryList as $vlu ) {
  9700. $count = $vlu ['count'] + 1;
  9701. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9702. $m1 = 0;
  9703. $m2 = 0;
  9704. $m3 = 0;
  9705. $m4 = 0;
  9706. $m5 = 0;
  9707. $m6 = 0;
  9708. $m7 = 0;
  9709. $m8 = 0;
  9710. $m9 = 0;
  9711. $m10 = 0;
  9712. $m11 = 0;
  9713. $m12 = 0;
  9714. $m13 = 0;
  9715. foreach ( $staffList as $value ) {
  9716. if ($vlu ['cid'] == $value ['cid']) {
  9717. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9718. $asum = 0;
  9719. for($i = 1; $i <= 12; $i ++) {
  9720. $falg = true;
  9721. foreach ( $itemStatisticsList as $v ) {
  9722. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9723. if ($v ['month'] == 1)
  9724. $m1 += $v ['price'];
  9725. if ($v ['month'] == 2)
  9726. $m2 += $v ['price'];
  9727. if ($v ['month'] == 3)
  9728. $m3 += $v ['price'];
  9729. if ($v ['month'] == 4)
  9730. $m4 += $v ['price'];
  9731. if ($v ['month'] == 5)
  9732. $m5 += $v ['price'];
  9733. if ($v ['month'] == 6)
  9734. $m6 += $v ['price'];
  9735. if ($v ['month'] == 7)
  9736. $m7 += $v ['price'];
  9737. if ($v ['month'] == 8)
  9738. $m8 += $v ['price'];
  9739. if ($v ['month'] == 9)
  9740. $m9 += $v ['price'];
  9741. if ($v ['month'] == 10)
  9742. $m10 += $v ['price'];
  9743. if ($v ['month'] == 11)
  9744. $m11 += $v ['price'];
  9745. if ($v ['month'] == 12)
  9746. $m12 += $v ['price'];
  9747. $asum += $v ['price'];
  9748. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9749. $falg = false;
  9750. break;
  9751. }
  9752. }
  9753. if ($falg)
  9754. $html .= '<td class="taR">-</td>';
  9755. }
  9756. $m13 += $asum;
  9757. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9758. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9759. 'html' => $html,
  9760. 'sid' => $value ['sid']
  9761. );
  9762. $html = "";
  9763. }
  9764. }
  9765. $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>
  9766. <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>
  9767. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9768. $collectHtml [$vlu ['cid']] = array (
  9769. 'html' => $hl,
  9770. 'sid' => ''
  9771. );
  9772. }
  9773. $data ['companyHtml'] = $collectHtml;
  9774. // total price html
  9775. $collectHtml = "";
  9776. $total = 0;
  9777. for($i = 1; $i <= 12; $i ++) {
  9778. $sumPrice = 0;
  9779. foreach ( $itemStatisticsList as $key => $value ) {
  9780. if ($value ['month'] == $i) {
  9781. $sumPrice += $value ['price'];
  9782. }
  9783. }
  9784. if ($sumPrice == 0)
  9785. $collectHtml .= '<td class="taR">-</td>';
  9786. else
  9787. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9788. $total += $sumPrice;
  9789. }
  9790. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9791. $data ['companyTotalHtml'] = $collectHtml;
  9792. $data ['total'] = $total;
  9793. $data ['nature'] =$nature;
  9794. $data ['year'] = $year;
  9795. $data ['memu'] = "receipt";
  9796. $data ['staff'] = $this->staff;
  9797. $data ['receiptMemu'] = 'companyCategoryCollect';
  9798. $data ['verifyId'] = $this->verifyId;
  9799. $data ['executeId'] = $this->executeId;
  9800. if ($year <= date ( "Y" )) {
  9801. Doo::loadModel ( 'receipt' );
  9802. $receipt = new receipt ();
  9803. $receiptList = $receipt->find ( array (
  9804. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9805. 'asArray' => true
  9806. ) );
  9807. if (empty ( $receiptList )) { // generated files
  9808. ob_start ();
  9809. $this->render ( "/admin/saeaStaffCollectB", $data );
  9810. $this->cacheFile ( $path );
  9811. die ();
  9812. }
  9813. }
  9814. $this->render ( "/admin/saeaStaffCollectB", $data );
  9815. }
  9816. function staffCollectBak() {
  9817. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9818. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9819. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9820. $this->showCache ( $path );
  9821. Doo::loadModel ( 'statistics' );
  9822. $statistics = new statistics ();
  9823. Doo::loadModel ( "receiptDetail" );
  9824. $receiptDetail = new receiptDetail ();
  9825. Doo::loadModel ( 'L_category' );
  9826. $Lcategory = new L_category ();
  9827. Doo::loadModel ( 'accountItem' );
  9828. $accountItem = new accountItem ();
  9829. Doo::loadModel ( 'staff' );
  9830. $staff = new staff ();
  9831. Doo::loadModel ( 'itemStatistics' );
  9832. $itemStatistics = new itemStatistics ();
  9833. $itemStatisticsList = $itemStatistics->find ( array (
  9834. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9835. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9836. 'groupby' => 'staff,itemCategory,Month(date)',
  9837. 'asArray' => true
  9838. ) );
  9839. $itemCategoryList = $itemStatistics->find ( array (
  9840. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9841. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9842. 'groupby' => 'cid,itemCategory,Month(date)',
  9843. 'asArray' => true
  9844. ) );
  9845. $LcategoryList = $Lcategory->find ( array (
  9846. 'asArray' => true
  9847. ) );
  9848. $staffList = $staff->find ( array (
  9849. 'asArray' => true
  9850. ) );
  9851. $htmlArray = array ();
  9852. foreach ( $LcategoryList as $value ) {
  9853. $htmlArray [$value ['title']] = array ();
  9854. foreach ( $staffList as $v ) {
  9855. if ($value ['cid'] == $v ['cid']) {
  9856. $html = "";
  9857. $falg = true;
  9858. $staffSumPrice = 0;
  9859. foreach ( $itemStatisticsList as $a ) {
  9860. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9861. if (empty ( $a ['price'] )) {
  9862. $html .= '<td class="taR">-</td>';
  9863. $falg = false;
  9864. break;
  9865. } else {
  9866. $staffSumPrice += $a ['price'];
  9867. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9868. $falg = false;
  9869. break;
  9870. }
  9871. }
  9872. }
  9873. if ($falg) {
  9874. $html .= '<td class="taR">-</td>';
  9875. $falg = true;
  9876. }
  9877. $falg = true;
  9878. foreach ( $itemStatisticsList as $a ) {
  9879. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9880. if (empty ( $a ['price'] )) {
  9881. $html .= '<td class="taR">-</td>';
  9882. $falg = false;
  9883. break;
  9884. } else {
  9885. $staffSumPrice += $a ['price'];
  9886. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9887. $falg = false;
  9888. break;
  9889. }
  9890. }
  9891. }
  9892. if ($falg) {
  9893. $html .= '<td class="taR">-</td>';
  9894. $falg = true;
  9895. }
  9896. $falg = true;
  9897. foreach ( $itemStatisticsList as $a ) {
  9898. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9899. if (empty ( $a ['price'] )) {
  9900. $html .= '<td class="taR">-</td>';
  9901. $falg = false;
  9902. break;
  9903. } else {
  9904. $staffSumPrice += $a ['price'];
  9905. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9906. $falg = false;
  9907. break;
  9908. }
  9909. }
  9910. }
  9911. if ($falg) {
  9912. $html .= '<td class="taR">-</td>';
  9913. $falg = true;
  9914. }
  9915. $falg = true;
  9916. foreach ( $itemStatisticsList as $a ) {
  9917. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9918. if (! empty ( $a ['price'] )) {
  9919. $staffSumPrice += $a ['price'];
  9920. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9921. $falg = false;
  9922. break;
  9923. } else {
  9924. $html .= '<td class="taR">-</td>';
  9925. $falg = false;
  9926. break;
  9927. }
  9928. }
  9929. }
  9930. if ($falg) {
  9931. $html .= '<td class="taR">-</td>';
  9932. $falg = true;
  9933. }
  9934. $falg = true;
  9935. foreach ( $itemStatisticsList as $a ) {
  9936. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9937. if (! empty ( $a ['price'] )) {
  9938. $staffSumPrice += $a ['price'];
  9939. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9940. $falg = false;
  9941. break;
  9942. } else {
  9943. $html .= '<td class="taR">-</td>';
  9944. $falg = false;
  9945. break;
  9946. }
  9947. }
  9948. }
  9949. if ($falg) {
  9950. $html .= '<td class="taR">-</td>';
  9951. $falg = true;
  9952. }
  9953. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9954. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9955. }
  9956. }
  9957. /* -- --- */
  9958. // 合计费用
  9959. $cateHtml = "";
  9960. $catePrice = 0;
  9961. $cateFalg = true;
  9962. foreach ( $itemCategoryList as $l ) {
  9963. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9964. if (empty ( $l ['price'] )) {
  9965. $cateHtml .= '<td class="colGreen taR">-</td>';
  9966. $cateFalg = false;
  9967. break;
  9968. } else {
  9969. $catePrice += $l ['price'];
  9970. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9971. $cateFalg = false;
  9972. break;
  9973. }
  9974. }
  9975. }
  9976. if ($cateFalg) {
  9977. $cateHtml .= '<td class="colGreen taR">-</td>';
  9978. $cateFalg = true;
  9979. }
  9980. $cateFalg = true;
  9981. foreach ( $itemCategoryList as $l ) {
  9982. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9983. if (empty ( $l ['price'] )) {
  9984. $cateHtml .= '<td class="colGreen taR">-</td>';
  9985. $cateFalg = false;
  9986. break;
  9987. } else {
  9988. $catePrice += $l ['price'];
  9989. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9990. $cateFalg = false;
  9991. break;
  9992. }
  9993. }
  9994. }
  9995. if ($cateFalg) {
  9996. $cateHtml .= '<td class="colGreen taR">-</td>';
  9997. $cateFalg = true;
  9998. }
  9999. $cateFalg = true;
  10000. foreach ( $itemCategoryList as $l ) {
  10001. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10002. if (empty ( $l ['price'] )) {
  10003. $cateHtml .= '<td class="colGreen taR">-</td>';
  10004. $cateFalg = false;
  10005. break;
  10006. } else {
  10007. $catePrice += $l ['price'];
  10008. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10009. $cateFalg = false;
  10010. break;
  10011. }
  10012. }
  10013. }
  10014. if ($cateFalg) {
  10015. $cateHtml .= '<td class="colGreen taR">-</td>';
  10016. $cateFalg = true;
  10017. }
  10018. $cateFalg = true;
  10019. foreach ( $itemCategoryList as $l ) {
  10020. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10021. if (empty ( $l ['price'] )) {
  10022. $cateHtml .= '<td class="colGreen taR">-</td>';
  10023. $cateFalg = false;
  10024. break;
  10025. } else {
  10026. $catePrice += $l ['price'];
  10027. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10028. $cateFalg = false;
  10029. break;
  10030. }
  10031. }
  10032. }
  10033. if ($cateFalg) {
  10034. $cateHtml .= '<td class="colGreen taR">-</td>';
  10035. $cateFalg = true;
  10036. }
  10037. $cateFalg = true;
  10038. foreach ( $itemCategoryList as $l ) {
  10039. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10040. if (empty ( $l ['price'] )) {
  10041. $cateHtml .= '<td class="colGreen taR">-</td>';
  10042. $cateFalg = false;
  10043. break;
  10044. } else {
  10045. $catePrice += $l ['price'];
  10046. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10047. $cateFalg = false;
  10048. break;
  10049. }
  10050. }
  10051. }
  10052. if ($cateFalg) {
  10053. $cateHtml .= '<td class="colGreen taR">-</td>';
  10054. $cateFalg = true;
  10055. }
  10056. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10057. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10058. /* -- --- */
  10059. }
  10060. // print_r($htmlArray);die;
  10061. $data ['htmlArray'] = $htmlArray;
  10062. // statistics html
  10063. $stList = $statistics->getOne ( array (
  10064. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10065. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10066. 'groupby' => 'Month(date)',
  10067. 'asArray' => true
  10068. ) );
  10069. if (empty ( $stList ))
  10070. $stList = array (
  10071. 'rePrice' => 0,
  10072. 'agPrice' => 0
  10073. );
  10074. $data ['stList'] = array (
  10075. 'rePrice' => $stList ['rePrice'],
  10076. 'agPrice' => $stList ['agPrice'],
  10077. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10078. );
  10079. $monthHtml = "";
  10080. for($i = 1; $i <= 12; $i ++) {
  10081. if ($i == $month)
  10082. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10083. else
  10084. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10085. }
  10086. $data ['monthHtml'] = $monthHtml;
  10087. $data ['year'] = $year;
  10088. $data ['month'] = $month;
  10089. $data ['memu'] = "receipt";
  10090. $data ['staff'] = $this->staff;
  10091. $data ['receiptMemu'] = 'companyCategoryCollect';
  10092. $data ['verifyId'] = $this->verifyId;
  10093. $data ['executeId'] = $this->executeId;
  10094. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10095. Doo::loadModel ( 'receipt' );
  10096. $receipt = new receipt ();
  10097. $receiptList = $receipt->find ( array (
  10098. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10099. 'asArray' => true
  10100. ) );
  10101. if (empty ( $receiptList )) { // generated files
  10102. ob_start ();
  10103. $this->render ( "/admin/saeaStaffCollect", $data );
  10104. $this->cacheFile ( $path );
  10105. die ();
  10106. }
  10107. }
  10108. $this->render ( "/admin/saeaStaffCollect", $data );
  10109. }
  10110. /**
  10111. * 日常收支
  10112. */
  10113. function payments() {
  10114. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10115. Doo::loadModel ( "execute" );
  10116. $execute = new execute ();
  10117. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10118. die ( 'illegal request' );
  10119. }
  10120. Doo::loadModel ( "accountBook" );
  10121. $accountBook = new accountBook ();
  10122. Doo::loadModel ( "accountBookStatistics" );
  10123. $accountBookStatistics = new accountBookStatistics ();
  10124. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10125. $list = $accountBook->getAccountBookByLimit ( 10 );
  10126. $data ['date'] = date ( "Y-m-d" );
  10127. $data ['statisticsList'] = $statisticsList;
  10128. $data ['list'] = $list;
  10129. $data ['memu'] = "receipt";
  10130. $data ['staff'] = $this->staff;
  10131. $data ['receiptMemu'] = 'payments';
  10132. $data ['verifyId'] = $this->verifyId;
  10133. $data ['executeId'] = $this->executeId;
  10134. $this->render ( "/expenses/payments", $data );
  10135. }
  10136. function paymentsIncomeDo() {
  10137. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10138. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10139. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10140. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10141. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10142. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10143. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10144. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10145. Doo::loadClass ( 'XDeode' );
  10146. $XDeode = new XDeode ( 5 );
  10147. Doo::loadModel ( "accountBook" );
  10148. Doo::loadModel ( "accountBookStatistics" );
  10149. Doo::loadModel ( 'wasteBook' );
  10150. // 记录流水时银行的转换
  10151. $accountBank = '';
  10152. if ($receivedBank == '纵横广发') {
  10153. $accountBank = 'CGBDeposit';
  10154. } elseif ($receivedBank == '纵横工行') {
  10155. $accountBank = 'ICBCDeposit';
  10156. } elseif ($receivedBank == '华润银行') {
  10157. $accountBank = 'HUADeposit';
  10158. } elseif ($receivedBank == '个人广发') {
  10159. $accountBank = 'PersonalDeposit';
  10160. }
  10161. if (empty ( $accountBank ))
  10162. die ( 'illegal request' );
  10163. // 收入为理财时特殊处理
  10164. if ($accountType == 7 || $accountType == 9) {
  10165. if ($receivedBank == '个人广发') {
  10166. die ( '个人广发 illegal request' );
  10167. }
  10168. // 添加一条收入
  10169. $accountBook = new accountBook ();
  10170. $accountBook->accountType = 10;
  10171. $accountBook->accountMsg = $accountMsg;
  10172. $accountBook->receivedPrice = $receivedPrice;
  10173. $accountBook->receivedMsg = $receivedMsg;
  10174. $accountBook->receivedBank = $receivedBank;
  10175. $accountBook->receivedDate = $receivedDate;
  10176. $accountBook->remarks = $remarks;
  10177. $accountBook->expensesType = 1;
  10178. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10179. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10180. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10181. $inComeId = $accountBook->insert ();
  10182. // 收支汇总-添加一条收入日常汇总
  10183. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10184. $accountBookStatistics = new accountBookStatistics ();
  10185. $item = array (
  10186. 'date' => date ( "Y-m-d" ),
  10187. 'accountType' => $abDetail ['accountType'],
  10188. 'accountMsg' => $abDetail ['accountMsg'],
  10189. 'aid' => $abDetail ['aid'],
  10190. 'inComePrice' => $abDetail ['receivedPrice'],
  10191. 'expensesType' => $abDetail ['expensesType']
  10192. );
  10193. $accountBookStatistics->setAccountBookStatistics ( $item );
  10194. // 添加收入流水
  10195. $wasteBook = new wasteBook ();
  10196. $itemWaste = array (
  10197. 'accountPriceShow' => $receivedPrice,
  10198. 'accountPrice' => $receivedPrice,
  10199. 'expensesType' => 1,
  10200. 'accountType' => 6, // 流水类型
  10201. 'dataID' => $inComeId,
  10202. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10203. 'accountBank' => $accountBank,
  10204. 'category' => $this->staff [0] ['category'],
  10205. 'cid' => $this->staff [0] ['cid'],
  10206. 'name' => $this->staff [0] ['username'],
  10207. 'sid' => $this->staff [0] ['sid'],
  10208. 'inputDate' => date ( "Y-m-d H:i:s" )
  10209. );
  10210. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10211. // 添加一条理财支出
  10212. $accountBank = 'CGBDeposit';
  10213. $expenditureBank = '纵横广发';
  10214. $dailyExpenditureType = 4;
  10215. if ($accountType == 9) {
  10216. $accountBank = 'ICBCDeposit';
  10217. $expenditureBank = '纵横工行';
  10218. $dailyExpenditureType = 6;
  10219. }
  10220. $accountBook = new accountBook ();
  10221. $accountBook->expensesType = 2;
  10222. $accountBook->expenditureType = $dailyExpenditureType;
  10223. $accountBook->expenditureMsg = $accountMsg;
  10224. $accountBook->expenditurePrice = $receivedPrice;
  10225. $accountBook->expenditureBank = $expenditureBank;
  10226. $accountBook->expenditureDate = $receivedDate;
  10227. $accountBook->remarks = $remarks;
  10228. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10229. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10230. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10231. $id = $accountBook->insert ();
  10232. // 收支汇总-添加一条理财支出汇总
  10233. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10234. $accountBookStatistics = new accountBookStatistics ();
  10235. $item = array (
  10236. 'date' => date ( "Y-m-d" ),
  10237. 'accountType' => $abDetail ['accountType'],
  10238. 'accountMsg' => $abDetail ['accountMsg'],
  10239. 'aid' => $abDetail ['aid'],
  10240. 'financingPrice' => - $receivedPrice,
  10241. 'expensesType' => 3
  10242. );
  10243. $accountBookStatistics->setAccountBookStatistics ( $item );
  10244. // 添加一条支出理财流水
  10245. $accountTypeWaste = 5;
  10246. if ($accountMsg == '公司固定') {
  10247. $accountTypeWaste = 9;
  10248. } elseif ($accountMsg == '公司活期') {
  10249. $accountTypeWaste = 10;
  10250. } elseif ($accountMsg == '个人(GR)') {
  10251. $accountBank = 'PersonalDeposit';
  10252. }
  10253. $itemWaste = array (
  10254. 'expensesType' => 2,
  10255. 'accountType' => $accountTypeWaste,
  10256. 'accountPriceShow' => $receivedPrice,
  10257. 'accountPrice' => - $receivedPrice,
  10258. 'dataID' => $id,
  10259. 'dailyExpenditureType' => $dailyExpenditureType,
  10260. 'accountBank' => $accountBank,
  10261. 'category' => $this->staff [0] ['category'],
  10262. 'cid' => $this->staff [0] ['cid'],
  10263. 'name' => $this->staff [0] ['username'],
  10264. 'sid' => $this->staff [0] ['sid'],
  10265. 'inputDate' => date ( "Y-m-d H:i:s" )
  10266. );
  10267. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10268. } elseif ($accountType == 1) {
  10269. if ($receivedBank == '个人广发')
  10270. die ( 'illegal request' );
  10271. // 添加一条收入
  10272. $accountBook = new accountBook ();
  10273. $accountBook->accountType = $accountType;
  10274. $accountBook->accountMsg = $accountMsg;
  10275. $accountBook->receivedPrice = $receivedPrice;
  10276. $accountBook->receivedMsg = $receivedMsg;
  10277. $accountBook->receivedBank = $receivedBank;
  10278. $accountBook->receivedDate = $receivedDate;
  10279. $accountBook->remarks = $remarks;
  10280. $accountBook->expensesType = 1;
  10281. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10282. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10283. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10284. $id = $accountBook->insert ();
  10285. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10286. // 收支汇总-添加一条收入日常汇总
  10287. $accountBookStatistics = new accountBookStatistics ();
  10288. $item = array (
  10289. 'date' => date ( "Y-m-d" ),
  10290. 'accountType' => $abDetail ['accountType'],
  10291. 'accountMsg' => $abDetail ['accountMsg'],
  10292. 'aid' => $abDetail ['aid'],
  10293. 'expensesType' => $abDetail ['expensesType']
  10294. );
  10295. if ($abDetail ['accountType'] == 8) {
  10296. $item += array (
  10297. 'inComePrice' => $abDetail ['receivedPrice']
  10298. );
  10299. } else {
  10300. $item += array (
  10301. 'inComePrice' => $abDetail ['receivedPrice']
  10302. );
  10303. }
  10304. $accountBookStatistics->setAccountBookStatistics ( $item );
  10305. // 流水存储方向
  10306. $itemWaste = array (
  10307. 'accountType' => 6
  10308. ); // 流水类型
  10309. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10310. // }else
  10311. if ($accountMsg == '活期理财收益') {
  10312. $itemWaste = array (
  10313. 'accountType' => 10
  10314. ); // 流水类型
  10315. }
  10316. // 添加收入流水
  10317. $wasteBook = new wasteBook ();
  10318. $itemWaste += array (
  10319. 'accountPrice' => $receivedPrice,
  10320. 'accountPriceShow' => $receivedPrice,
  10321. 'expensesType' => 1,
  10322. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10323. 'dataID' => $id,
  10324. 'accountBank' => $accountBank,
  10325. 'category' => $this->staff [0] ['category'],
  10326. 'cid' => $this->staff [0] ['cid'],
  10327. 'name' => $this->staff [0] ['username'],
  10328. 'sid' => $this->staff [0] ['sid'],
  10329. 'inputDate' => date ( "Y-m-d H:i:s" )
  10330. );
  10331. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10332. } else { // 普通日常收入处理
  10333. // 添加一条收入
  10334. $accountBook = new accountBook ();
  10335. $accountBook->accountType = $accountType;
  10336. $accountBook->accountMsg = $accountMsg;
  10337. $accountBook->receivedPrice = $receivedPrice;
  10338. $accountBook->receivedMsg = $receivedMsg;
  10339. $accountBook->receivedBank = $receivedBank;
  10340. $accountBook->receivedDate = $receivedDate;
  10341. $accountBook->remarks = $remarks;
  10342. $accountBook->expensesType = 1;
  10343. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10344. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10345. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10346. $id = $accountBook->insert ();
  10347. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10348. // 收支汇总-添加一条收入日常汇总
  10349. $accountBookStatistics = new accountBookStatistics ();
  10350. $item = array (
  10351. 'date' => date ( "Y-m-d" ),
  10352. 'accountType' => $abDetail ['accountType'],
  10353. 'accountMsg' => $abDetail ['accountMsg'],
  10354. 'aid' => $abDetail ['aid'],
  10355. 'expensesType' => $abDetail ['expensesType']
  10356. );
  10357. if ($abDetail ['accountType'] == 8) {
  10358. $item += array (
  10359. 'inComePrice' => $abDetail ['receivedPrice']
  10360. );
  10361. } else {
  10362. $item += array (
  10363. 'inComePrice' => $abDetail ['receivedPrice']
  10364. );
  10365. }
  10366. $accountBookStatistics->setAccountBookStatistics ( $item );
  10367. // 添加收入流水
  10368. $itemWaste = array (
  10369. 'accountPrice' => $receivedPrice
  10370. );
  10371. if ($receivedBank == '个人广发') {
  10372. $itemWaste = array (
  10373. 'accountPrice' => - $receivedPrice
  10374. );
  10375. }
  10376. $wasteBook = new wasteBook ();
  10377. $itemWaste += array (
  10378. 'accountPriceShow' => $receivedPrice,
  10379. 'expensesType' => 1,
  10380. 'accountType' => 6, // 流水类型
  10381. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10382. 'dataID' => $id,
  10383. 'accountBank' => $accountBank,
  10384. 'category' => $this->staff [0] ['category'],
  10385. 'cid' => $this->staff [0] ['cid'],
  10386. 'name' => $this->staff [0] ['username'],
  10387. 'sid' => $this->staff [0] ['sid'],
  10388. 'inputDate' => date ( "Y-m-d H:i:s" )
  10389. );
  10390. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10391. }
  10392. }
  10393. return '/payments';
  10394. }
  10395. /**
  10396. * 添加收入
  10397. * @return string
  10398. */
  10399. function paymentsIncomeDo_() {
  10400. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10401. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10402. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10403. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10404. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10405. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10406. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10407. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10408. Doo::loadClass ( 'XDeode' );
  10409. $XDeode = new XDeode ( 5 );
  10410. Doo::loadModel ( "accountBook" );
  10411. $accountBook = new accountBook ();
  10412. $accountBank = '';
  10413. $accountTypeWaste = 6;
  10414. if ($receivedBank == '纵横广发') {
  10415. $accountBank = 'CGBDeposit';
  10416. } elseif ($receivedBank == '纵横工行') {
  10417. $accountBank = 'ICBCDeposit';
  10418. } elseif ($receivedBank == '华润银行') {
  10419. $accountBank = 'HUADeposit';
  10420. } elseif ($receivedBank == '个人广发') {
  10421. $accountBank = 'PersonalDeposit';
  10422. }
  10423. if (empty ( $accountBank ))
  10424. die ( 'illegal request' );
  10425. $dailyIncomeType = '';
  10426. $itemWaste = array (
  10427. 'accountPrice' => $receivedPrice,
  10428. 'expensesType' => 1
  10429. );
  10430. if ($receivedBank == '个人广发') {
  10431. $itemWaste = array (
  10432. 'accountPrice' => - $receivedPrice,
  10433. 'expensesType' => 1
  10434. );
  10435. }
  10436. if ($accountType == 4) {
  10437. $dailyIncomeType = 4;
  10438. } elseif ($accountType == 1) {
  10439. $dailyIncomeType = 1;
  10440. } elseif ($accountType == 2) {
  10441. $dailyIncomeType = 2;
  10442. } elseif ($accountType == 3) {
  10443. $dailyIncomeType = 3;
  10444. } elseif ($accountType == 5) {
  10445. $dailyIncomeType = 5;
  10446. } elseif ($accountType == 6) {
  10447. $dailyIncomeType = 6;
  10448. } elseif ($accountType == 7 || $accountType == 9) {
  10449. $dailyIncomeType = 7;
  10450. if ($accountMsg == '公司固定') {
  10451. $accountTypeWaste = 9;
  10452. } elseif ($accountMsg == '公司活期') {
  10453. $accountTypeWaste = 10;
  10454. } elseif ($accountMsg == '个人(GR)') {
  10455. $accountBank = 'PersonalDeposit';
  10456. }
  10457. $itemWaste = array (
  10458. 'accountPrice' => - $receivedPrice,
  10459. 'expensesType' => 2
  10460. );
  10461. } elseif ($accountType == 8) {
  10462. $dailyIncomeType = 8;
  10463. }
  10464. if (empty ( $dailyIncomeType ))
  10465. die ( 'illegal request' );
  10466. $accountBook->accountType = $accountType;
  10467. $accountBook->accountMsg = $accountMsg;
  10468. $accountBook->receivedPrice = $receivedPrice;
  10469. $accountBook->receivedMsg = $receivedMsg;
  10470. $accountBook->receivedBank = $receivedBank;
  10471. $accountBook->receivedDate = $receivedDate;
  10472. $accountBook->remarks = $remarks;
  10473. $accountBook->expensesType = 1;
  10474. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10475. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10476. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10477. $id = $accountBook->insert ();
  10478. //
  10479. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10480. // 收支汇总
  10481. Doo::loadModel ( "accountBookStatistics" );
  10482. $accountBookStatistics = new accountBookStatistics ();
  10483. $item = array (
  10484. 'date' => date ( "Y-m-d" ),
  10485. 'accountType' => $abDetail ['accountType'],
  10486. 'accountMsg' => $abDetail ['accountMsg'],
  10487. 'aid' => $abDetail ['aid']
  10488. );
  10489. if ($abDetail ['expensesType'] == 1) {
  10490. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10491. $item += array (
  10492. 'financingPrice' => - $receivedPrice,
  10493. 'expensesType' => 3
  10494. );
  10495. } else if ($abDetail ['accountType'] == 8) {
  10496. $item += array (
  10497. 'inComePrice' => - $abDetail ['receivedPrice'],
  10498. 'expensesType' => $abDetail ['expensesType']
  10499. );
  10500. } else {
  10501. $item += array (
  10502. 'inComePrice' => $abDetail ['receivedPrice'],
  10503. 'expensesType' => $abDetail ['expensesType']
  10504. );
  10505. }
  10506. }
  10507. $accountBookStatistics->setAccountBookStatistics ( $item );
  10508. // 为理财时需添加一条日常支出
  10509. if ($accountType == 7 || $accountType == 9) {
  10510. }
  10511. // 公司流水记录
  10512. Doo::loadModel ( 'wasteBook' );
  10513. $wasteBook = new wasteBook ();
  10514. // 银行
  10515. // if (empty($abDetail)){
  10516. $itemWaste += array (
  10517. 'accountPriceShow' => $receivedPrice,
  10518. 'dataID' => $id,
  10519. 'accountType' => $accountTypeWaste,
  10520. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10521. 'accountBank' => $accountBank,
  10522. 'category' => $this->staff [0] ['category'],
  10523. 'cid' => $this->staff [0] ['cid'],
  10524. 'name' => $this->staff [0] ['username'],
  10525. 'sid' => $this->staff [0] ['sid'],
  10526. 'inputDate' => date ( "Y-m-d H:i:s" )
  10527. );
  10528. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10529. // }
  10530. // 类型为理财7或者9 要添加一笔理财支出
  10531. if ($accountType == 7 || $accountType == 9) {
  10532. $accountBank = 'CGBDeposit';
  10533. $expenditureBank = '纵横广发';
  10534. $dailyExpenditureType = 4;
  10535. if ($accountType == 9) {
  10536. $accountBank = 'ICBCDeposit';
  10537. $expenditureBank = '纵横工行';
  10538. $dailyExpenditureType = 6;
  10539. }
  10540. // 添加一条支出
  10541. $accountBook = new accountBook ();
  10542. $accountBook->expenditureType = $dailyExpenditureType;
  10543. $accountBook->expenditureMsg = $accountMsg;
  10544. $accountBook->expenditurePrice = $receivedPrice;
  10545. $accountBook->expenditureBank = $expenditureBank;
  10546. $accountBook->expenditureDate = $receivedDate;
  10547. $accountBook->remarks = $remarks;
  10548. $accountBook->expensesType = 2;
  10549. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10550. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10551. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10552. $id = $accountBook->insert ();
  10553. // 添加一条收入流水
  10554. $itemWaste = array (
  10555. 'accountPriceShow' => $receivedPrice,
  10556. 'accountPrice' => $receivedPrice,
  10557. 'dataID' => $id,
  10558. 'expensesType' => 2,
  10559. 'accountType' => $accountTypeWaste,
  10560. 'dailyExpenditureType' => $dailyExpenditureType,
  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. }
  10571. return '/payments';
  10572. }
  10573. function paymentsExpenditureDo() {
  10574. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10575. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10576. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10577. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10578. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10579. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10580. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10581. // 理财支出特殊处理
  10582. Doo::loadModel ( "accountBook" );
  10583. Doo::loadModel ( "accountBookStatistics" );
  10584. Doo::loadModel ( 'wasteBook' );
  10585. $accountBank = '';
  10586. if ($expenditureBank == '纵横广发') {
  10587. $accountBank = 'CGBDeposit';
  10588. } elseif ($expenditureBank == '纵横工行') {
  10589. $accountBank = 'ICBCDeposit';
  10590. } elseif ($expenditureBank == '华润银行') {
  10591. $accountBank = 'HUADeposit';
  10592. } elseif ($expenditureBank == '个人广发') {
  10593. $accountBank = 'PersonalDeposit';
  10594. }
  10595. if (empty ( $accountBank ))
  10596. die ( 'illegal request' );
  10597. if ($expenditureType == 4 || $expenditureType == 6) {
  10598. if ($expenditureBank == '个人广发') {
  10599. die ( '个人广发 illegal request' );
  10600. }
  10601. // 添加一笔日常支出
  10602. $accountBook = new accountBook ();
  10603. $accountBook->expensesType = 2;
  10604. $accountBook->expenditureType = 7;
  10605. $accountBook->expenditureMsg = $expenditureMsg;
  10606. $accountBook->expenditurePrice = $expenditurePrice;
  10607. $accountBook->expenditureBank = $expenditureBank;
  10608. $accountBook->expenditureDate = $expenditureDate;
  10609. $accountBook->remarks = $remarks;
  10610. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10611. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10612. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10613. $expenditureId = $accountBook->insert ();
  10614. // 添加日常支出汇总
  10615. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10616. $accountBookStatistics = new accountBookStatistics ();
  10617. $item = array (
  10618. 'date' => date ( "Y-m-d" ),
  10619. 'expenditureType' => $abDetail ['expenditureType'],
  10620. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10621. 'aid' => $abDetail ['aid'],
  10622. 'payPrice' => $abDetail ['expenditurePrice'],
  10623. 'expensesType' => $abDetail ['expensesType']
  10624. );
  10625. $accountBookStatistics->setAccountBookStatistics ( $item );
  10626. // 公司日常支出流水
  10627. $wasteBook = new wasteBook ();
  10628. $itemWaste = array (
  10629. 'accountPrice' => - $expenditurePrice
  10630. );
  10631. if ($expenditureBank == '个人广发') {
  10632. $itemWaste = array (
  10633. 'accountPrice' => $expenditurePrice
  10634. );
  10635. }
  10636. $itemWaste += array (
  10637. 'expensesType' => 2,
  10638. 'accountType' => 5,
  10639. 'dailyExpenditureType' => $expenditureType,
  10640. 'accountPriceShow' => $expenditurePrice,
  10641. 'accountPrice' => - $expenditurePrice,
  10642. 'dataID' => $expenditureId,
  10643. 'accountBank' => $accountBank,
  10644. 'category' => $this->staff [0] ['category'],
  10645. 'cid' => $this->staff [0] ['cid'],
  10646. 'name' => $this->staff [0] ['username'],
  10647. 'sid' => $this->staff [0] ['sid'],
  10648. 'inputDate' => date ( "Y-m-d H:i:s" )
  10649. );
  10650. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10651. // 添加一笔理财收入
  10652. $accountBank = 'CGBDeposit';
  10653. $dailyIncomeType = 7;
  10654. $receivedBank = '纵横广发';
  10655. if ($expenditureType == 6) {
  10656. $accountBank = 'ICBCDeposit';
  10657. $receivedBank = '纵横工行';
  10658. $dailyIncomeType = 9;
  10659. }
  10660. $accountBook = new accountBook ();
  10661. $accountBook->expensesType = 1;
  10662. $accountBook->accountType = $dailyIncomeType;
  10663. $accountBook->accountMsg = $expenditureMsg;
  10664. $accountBook->receivedPrice = $expenditurePrice;
  10665. $accountBook->receivedBank = $receivedBank;
  10666. $accountBook->receivedDate = $expenditureDate;
  10667. $accountBook->remarks = $remarks;
  10668. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10669. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10670. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10671. $id = $accountBook->insert ();
  10672. // 添加日常理财收入汇总
  10673. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10674. $accountBookStatistics = new accountBookStatistics ();
  10675. $item = array (
  10676. 'date' => date ( "Y-m-d" ),
  10677. 'expenditureType' => $abDetail ['expenditureType'],
  10678. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10679. 'aid' => $abDetail ['aid'],
  10680. 'financingPrice' => $expenditurePrice,
  10681. 'expensesType' => 3
  10682. );
  10683. $accountBookStatistics->setAccountBookStatistics ( $item );
  10684. // 添加一笔收入流水
  10685. if ($expenditureMsg == '公司固定') {
  10686. $accountTypeWaste = 9;
  10687. } elseif ($expenditureMsg == '公司活期') {
  10688. $accountTypeWaste = 10;
  10689. } elseif ($expenditureMsg == '个人(GR)') {
  10690. $accountBank = 'PersonalDeposit';
  10691. }
  10692. $itemWaste = array (
  10693. 'expensesType' => 1,
  10694. 'accountType' => $accountTypeWaste,
  10695. 'accountPriceShow' => $expenditurePrice,
  10696. 'accountPrice' => $expenditurePrice,
  10697. 'dataID' => $id,
  10698. 'dailyIncomeType' => $dailyIncomeType,
  10699. 'accountBank' => $accountBank,
  10700. 'category' => $this->staff [0] ['category'],
  10701. 'cid' => $this->staff [0] ['cid'],
  10702. 'name' => $this->staff [0] ['username'],
  10703. 'sid' => $this->staff [0] ['sid'],
  10704. 'inputDate' => date ( "Y-m-d H:i:s" )
  10705. );
  10706. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10707. } else {
  10708. // 添加一笔日常支出
  10709. $accountBook = new accountBook ();
  10710. $accountBook->expensesType = 2;
  10711. $accountBook->expenditureType = $expenditureType;
  10712. $accountBook->expenditureMsg = $expenditureMsg;
  10713. $accountBook->expenditurePrice = $expenditurePrice;
  10714. $accountBook->expenditureBank = $expenditureBank;
  10715. $accountBook->expenditureDate = $expenditureDate;
  10716. $accountBook->remarks = $remarks;
  10717. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10718. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10719. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10720. $id = $accountBook->insert ();
  10721. // 添加日常支出汇总
  10722. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10723. $accountBookStatistics = new accountBookStatistics ();
  10724. $item = array (
  10725. 'date' => date ( "Y-m-d" ),
  10726. 'expenditureType' => $abDetail ['expenditureType'],
  10727. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10728. 'aid' => $abDetail ['aid'],
  10729. 'expensesType' => $abDetail ['expensesType']
  10730. );
  10731. if ($expenditureType == 5) {
  10732. $item += array (
  10733. 'payPrice' => - $abDetail ['expenditurePrice']
  10734. );
  10735. } else {
  10736. $item += array (
  10737. 'payPrice' => $abDetail ['expenditurePrice']
  10738. );
  10739. }
  10740. $accountBookStatistics->setAccountBookStatistics ( $item );
  10741. // 公司日常支出流水
  10742. $wasteBook = new wasteBook ();
  10743. $itemWaste = array (
  10744. 'accountPrice' => - $expenditurePrice
  10745. );
  10746. if ($expenditureBank == '个人广发') {
  10747. $itemWaste = array (
  10748. 'accountPrice' => $expenditurePrice
  10749. );
  10750. }
  10751. $itemWaste += array (
  10752. 'expensesType' => 2,
  10753. 'accountType' => 5,
  10754. 'accountPriceShow' => $expenditurePrice,
  10755. 'dataID' => $id,
  10756. 'dailyExpenditureType' => $expenditureType,
  10757. 'accountBank' => $accountBank,
  10758. 'category' => $this->staff [0] ['category'],
  10759. 'cid' => $this->staff [0] ['cid'],
  10760. 'name' => $this->staff [0] ['username'],
  10761. 'sid' => $this->staff [0] ['sid'],
  10762. 'inputDate' => date ( "Y-m-d H:i:s" )
  10763. );
  10764. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10765. }
  10766. }
  10767. return '/payments';
  10768. }
  10769. /**
  10770. * 添加支出
  10771. */
  10772. function paymentsExpenditureDo_() {
  10773. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10774. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10775. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10776. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10777. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10778. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10779. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10780. $dailyExpenditureType = '';
  10781. $accountTypeWaste = 5;
  10782. $accountBank = '';
  10783. if ($expenditureBank == '纵横广发') {
  10784. $accountBank = 'CGBDeposit';
  10785. } elseif ($expenditureBank == '纵横工行') {
  10786. $accountBank = 'ICBCDeposit';
  10787. } elseif ($expenditureBank == '华润银行') {
  10788. $accountBank = 'HUADeposit';
  10789. } elseif ($expenditureBank == '个人广发') {
  10790. $accountBank = 'PersonalDeposit';
  10791. }
  10792. if (empty ( $accountBank ))
  10793. die ( 'illegal request' );
  10794. $itemWaste = array (
  10795. 'accountPrice' => - $expenditurePrice
  10796. );
  10797. if ($expenditureBank == '个人广发') {
  10798. $itemWaste = array (
  10799. 'accountPrice' => $expenditurePrice
  10800. );
  10801. }
  10802. if ($expenditureType == 4 || $expenditureType == 6) {
  10803. $dailyExpenditureType = 4;
  10804. if ($expenditureMsg == '公司固定') {
  10805. $accountTypeWaste = 9;
  10806. } elseif ($expenditureMsg == '公司活期') {
  10807. $accountTypeWaste = 10;
  10808. } elseif ($expenditureMsg == '个人(GR)') {
  10809. $accountBank = 'PersonalDeposit';
  10810. }
  10811. $itemWaste = array (
  10812. 'accountPrice' => $expenditurePrice
  10813. );
  10814. } elseif ($expenditureType == 1) {
  10815. $dailyExpenditureType = 1;
  10816. } elseif ($expenditureType == 2) {
  10817. $dailyExpenditureType = 2;
  10818. } elseif ($expenditureType == 3) {
  10819. $dailyExpenditureType = 3;
  10820. } elseif ($expenditureType == 5) {
  10821. $dailyExpenditureType = 5;
  10822. }
  10823. if (empty ( $dailyExpenditureType ))
  10824. die ( 'illegal request' );
  10825. Doo::loadModel ( "accountBook" );
  10826. $accountBook = new accountBook ();
  10827. $accountBook->expenditureType = $expenditureType;
  10828. $accountBook->expenditureMsg = $expenditureMsg;
  10829. $accountBook->expenditurePrice = $expenditurePrice;
  10830. $accountBook->expenditureBank = $expenditureBank;
  10831. $accountBook->expenditureDate = $expenditureDate;
  10832. $accountBook->remarks = $remarks;
  10833. $accountBook->expensesType = 2;
  10834. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10835. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10836. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10837. $id = $accountBook->insert ();
  10838. //
  10839. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10840. Doo::loadModel ( "accountBookStatistics" );
  10841. $accountBookStatistics = new accountBookStatistics ();
  10842. $item = array (
  10843. 'date' => date ( "Y-m-d" ),
  10844. 'expenditureType' => $abDetail ['expenditureType'],
  10845. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10846. 'aid' => $abDetail ['aid']
  10847. );
  10848. if ($abDetail ['expensesType'] == 2) {
  10849. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10850. $item += array (
  10851. 'financingPrice' => $expenditurePrice,
  10852. 'expensesType' => 3
  10853. );
  10854. } elseif ($abDetail ['expenditureType'] == 5) {
  10855. $item += array (
  10856. 'payPrice' => $abDetail ['expenditurePrice'],
  10857. 'expensesType' => $abDetail ['expensesType']
  10858. );
  10859. } else {
  10860. $item += array (
  10861. 'payPrice' => $abDetail ['expenditurePrice'],
  10862. 'expensesType' => $abDetail ['expensesType']
  10863. );
  10864. }
  10865. }
  10866. $accountBookStatistics->setAccountBookStatistics ( $item );
  10867. // 公司流水记录
  10868. Doo::loadModel ( 'wasteBook' );
  10869. $wasteBook = new wasteBook ();
  10870. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10871. // 银行
  10872. if (empty ( $abDetail )) {
  10873. $itemWaste += array (
  10874. 'accountPriceShow' => $expenditurePrice,
  10875. 'dataID' => $id,
  10876. 'expensesType' => 2,
  10877. 'accountType' => $accountTypeWaste,
  10878. 'dailyExpenditureType' => $expenditureType,
  10879. 'accountBank' => $accountBank,
  10880. 'category' => $this->staff [0] ['category'],
  10881. 'cid' => $this->staff [0] ['cid'],
  10882. 'name' => $this->staff [0] ['username'],
  10883. 'sid' => $this->staff [0] ['sid'],
  10884. 'inputDate' => date ( "Y-m-d H:i:s" )
  10885. );
  10886. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10887. }
  10888. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10889. if ($expenditureType == 4 || $expenditureType == 6) {
  10890. $accountBank = 'CGBDeposit';
  10891. $dailyIncomeType = 7;
  10892. $receivedBank = '纵横广发';
  10893. if ($expenditureType == 6) {
  10894. $accountBank = 'ICBCDeposit';
  10895. $receivedBank = '纵横工行';
  10896. $dailyIncomeType = 9;
  10897. }
  10898. // 添加一笔收入
  10899. $accountBook = new accountBook ();
  10900. $accountBook->accountType = $dailyIncomeType;
  10901. $accountBook->accountMsg = $expenditureMsg;
  10902. $accountBook->receivedPrice = $expenditurePrice;
  10903. $accountBook->receivedBank = $receivedBank;
  10904. $accountBook->receivedDate = $expenditureDate;
  10905. $accountBook->remarks = $remarks;
  10906. $accountBook->expensesType = 1;
  10907. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10908. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10909. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10910. $id = $accountBook->insert ();
  10911. // 添加一笔收入流水
  10912. $itemWaste = array (
  10913. 'accountPriceShow' => $expenditurePrice,
  10914. 'accountPrice' => - $expenditurePrice,
  10915. 'dataID' => $id,
  10916. 'expensesType' => 1,
  10917. 'accountType' => $accountTypeWaste,
  10918. 'dailyIncomeType' => $dailyIncomeType,
  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. }
  10929. return '/payments';
  10930. }
  10931. /**
  10932. * 所有收支
  10933. */
  10934. function paymentsAchieve() {
  10935. $page_size = 12;
  10936. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10937. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10938. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10939. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10940. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10941. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10942. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10943. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10944. Doo::loadModel ( "accountBookStatistics" );
  10945. $accountBookStatistics = new accountBookStatistics ();
  10946. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10947. $data ['statisticsList'] = $statisticsList;
  10948. Doo::loadModel ( "accountBook" );
  10949. $accountBook = new accountBook ();
  10950. $con = '';
  10951. if ($expensesType == 'INCOME')
  10952. $con = ' and expensesType=1 ';
  10953. elseif ($expensesType == 'PAY')
  10954. $con = ' and expensesType=2 ';
  10955. $dateArr = explode ( ':', $date );
  10956. $D1 = $dateString = '';
  10957. $D2 = '';
  10958. if (! empty ( $date )) {
  10959. $D1 = $dateArr [0];
  10960. if (isset ( $dateArr [1] ))
  10961. $D2 = $dateArr [1];
  10962. else
  10963. $D2 = '';
  10964. $dateString = $D1 . " : " . $D2;
  10965. }
  10966. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10967. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10968. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10969. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10970. if (! empty ( $price ))
  10971. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10972. if ($submitType == 1) {
  10973. if ($accountType != '') {
  10974. $expenditureType = '';
  10975. $con .= ' and accountType=' . $accountType;
  10976. if (! empty ( $accountMsg ))
  10977. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10978. }
  10979. } elseif ($submitType == 2) {
  10980. if ($expenditureType != '') {
  10981. $accountType = $accountMsg = '';
  10982. $con .= ' and expenditureType=' . $expenditureType;
  10983. }
  10984. } else {
  10985. $accountType = $accountMsg = $expenditureType = '';
  10986. }
  10987. $sql = "" . $con;
  10988. $action = "paymentsAchieve";
  10989. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10990. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10991. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10992. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10993. $data ['expenditureType'] = $expenditureType;
  10994. $data ['accountMsg'] = $accountMsg;
  10995. $data ['accountType'] = $accountType;
  10996. $data ['inputDate'] = $date;
  10997. $data ['price'] = $price;
  10998. $data ['expensesType'] = $expensesType;
  10999. $data ['page'] = $pageinfo;
  11000. $data ['list'] = $list;
  11001. $data ['memu'] = "receipt";
  11002. $data ['staff'] = $this->staff;
  11003. $data ['receiptMemu'] = 'payments';
  11004. $data ['verifyId'] = $this->verifyId;
  11005. $data ['executeId'] = $this->executeId;
  11006. $this->render ( "/expenses/paymentsAchieve", $data );
  11007. }
  11008. function paymentsIncomeUpdateDo() {
  11009. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11010. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11011. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11012. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11013. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11014. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11015. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11016. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11017. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11018. Doo::loadClass ( 'XDeode' );
  11019. $XDeode = new XDeode ( 5 );
  11020. $aid = $XDeode->decode ( $aidKey );
  11021. Doo::loadModel ( "accountBook" );
  11022. $accountBook = new accountBook ();
  11023. //
  11024. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11025. $price = $receivedPrice - $abDetail [inComePrice];
  11026. Doo::loadModel ( "accountBookStatistics" );
  11027. $accountBookStatistics = new accountBookStatistics ();
  11028. if ($abDetail ['accountType'] == 7) {
  11029. $item += array (
  11030. 'date' => date ( "Y-m-d" ),
  11031. 'financingPrice' => - $price,
  11032. 'expensesType' => 3,
  11033. 'aid' => $abDetail ['aid']
  11034. );
  11035. } elseif ($abDetail ['accountType'] == 8) {
  11036. $item += array (
  11037. 'date' => date ( "Y-m-d" ),
  11038. 'expensesType' => $abDetail ['expensesType'],
  11039. 'inComePrice' => - $price,
  11040. 'aid' => $abDetail ['aid']
  11041. );
  11042. } else {
  11043. $item = array (
  11044. 'date' => date ( "Y-m-d" ),
  11045. 'expensesType' => $abDetail ['expensesType'],
  11046. 'inComePrice' => $price,
  11047. 'aid' => $abDetail ['aid']
  11048. );
  11049. }
  11050. $accountBookStatistics->setAccountBookStatistics ( $item );
  11051. $accountBook->accountType = $accountType;
  11052. $accountBook->accountMsg = $accountMsg;
  11053. $accountBook->receivedPrice = $receivedPrice;
  11054. $accountBook->receivedMsg = $receivedMsg;
  11055. $accountBook->receivedBank = $receivedBank;
  11056. $accountBook->receivedDate = $receivedDate;
  11057. $accountBook->remarks = $remarks;
  11058. $accountBook->aid = $aid;
  11059. $accountBook->update ();
  11060. }
  11061. return '/paymentsAchieve';
  11062. }
  11063. function paymentsExpenditureEdiDo() {
  11064. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11065. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11066. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11067. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11068. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11069. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11070. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11071. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11072. Doo::loadClass ( 'XDeode' );
  11073. $XDeode = new XDeode ( 5 );
  11074. $aid = $XDeode->decode ( $aidKey );
  11075. Doo::loadModel ( "accountBook" );
  11076. $accountBook = new accountBook ();
  11077. // 汇总信息
  11078. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11079. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11080. Doo::loadModel ( "accountBookStatistics" );
  11081. $accountBookStatistics = new accountBookStatistics ();
  11082. if ($abDetail ['expenditureType'] == 4) {
  11083. $item += array (
  11084. 'date' => date ( "Y-m-d" ),
  11085. 'financingPrice' => $price,
  11086. 'expensesType' => 3,
  11087. 'aid' => $abDetail ['aid']
  11088. );
  11089. } elseif ($abDetail ['expenditureType'] == 5) {
  11090. $item += array (
  11091. 'date' => date ( "Y-m-d" ),
  11092. 'expensesType' => $abDetail ['expensesType'],
  11093. 'payPrice' => $price,
  11094. 'aid' => $abDetail ['aid']
  11095. );
  11096. } else {
  11097. $item = array (
  11098. 'date' => date ( "Y-m-d" ),
  11099. 'expensesType' => $abDetail ['expensesType'],
  11100. 'payPrice' => $price,
  11101. 'aid' => $abDetail ['aid']
  11102. );
  11103. }
  11104. $accountBookStatistics->setAccountBookStatistics ( $item );
  11105. //
  11106. $accountBook->expenditureType = $expenditureType;
  11107. $accountBook->expenditureMsg = $expenditureMsg;
  11108. $accountBook->expenditurePrice = $expenditurePrice;
  11109. $accountBook->expenditureBank = $expenditureBank;
  11110. $accountBook->remarks = $remarks;
  11111. $accountBook->expenditureDate = $expenditureDate;
  11112. $accountBook->aid = $aid;
  11113. $id = $accountBook->update ();
  11114. }
  11115. return '/paymentsAchieve';
  11116. }
  11117. function paymentsDelDo() {
  11118. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11119. if (! empty ( $aidKey )) {
  11120. Doo::loadClass ( 'XDeode' );
  11121. $XDeode = new XDeode ( 5 );
  11122. $aid = $XDeode->decode ( $aidKey );
  11123. Doo::loadModel ( "accountBook" );
  11124. $accountBook = new accountBook ();
  11125. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11126. if (empty ( $abDetail ))
  11127. die ( 'illegal request' );
  11128. // 删除收支
  11129. Doo::loadModel ( "accountBookStatistics" );
  11130. $accountBookStatistics = new accountBookStatistics ();
  11131. $item = array (
  11132. 'date' => date ( "Y-m-d" ),
  11133. 'aid' => $abDetail ['aid']
  11134. );
  11135. $accountType = '';
  11136. if ($abDetail ['expensesType'] == 1) {
  11137. $accountType = 6;
  11138. if ($abDetail ['accountType'] != 7) {
  11139. $item += array (
  11140. 'expensesType' => $abDetail ['expensesType'],
  11141. 'inComePrice' => - $abDetail ['receivedPrice']
  11142. );
  11143. } else {
  11144. $item += array (
  11145. 'financingPrice' => $abDetail ['receivedPrice'],
  11146. 'expensesType' => 3
  11147. );
  11148. }
  11149. } elseif ($abDetail ['expensesType'] == 2) {
  11150. $accountType = 5;
  11151. if ($abDetail ['accountType'] != 7) {
  11152. $item += array (
  11153. 'expensesType' => $abDetail ['expensesType'],
  11154. 'payPrice' => - $abDetail ['expenditurePrice']
  11155. );
  11156. } else {
  11157. $item += array (
  11158. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11159. 'expensesType' => 3
  11160. );
  11161. }
  11162. }
  11163. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11164. if ($abDetail ['expenditureMsg'] == '公司固定')
  11165. $accountType = 9;
  11166. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11167. $accountType = 10;
  11168. }
  11169. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11170. if ($abDetail ['accountMsg'] == '公司固定')
  11171. $accountType = 9;
  11172. elseif ($abDetail ['accountMsg'] == '公司活期')
  11173. $accountType = 10;
  11174. }
  11175. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11176. $accountType = 10;
  11177. }
  11178. $accountBookStatistics->setAccountBookStatistics ( $item );
  11179. $accountBook->delete ( array (
  11180. 'where' => 'aid=' . $aid,
  11181. 'limit' => 1
  11182. ) );
  11183. // 删除收入流水
  11184. if (! empty ( $accountType )) {
  11185. Doo::loadModel ( 'wasteBook' );
  11186. $wasteBook = new wasteBook ();
  11187. $wasteBook->delete ( array (
  11188. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11189. 'limit' => 1
  11190. ) );
  11191. }
  11192. }
  11193. return '/paymentsAchieve';
  11194. }
  11195. function paymentsCollect() {
  11196. Doo::loadModel ( "execute" );
  11197. $execute = new execute ();
  11198. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11199. die ( 'illegal request' );
  11200. }
  11201. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11202. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11203. Doo::loadModel ( "accountBookStatistics" );
  11204. $accountBookStatistics = new accountBookStatistics ();
  11205. Doo::loadClass ( 'receipt.func' );
  11206. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11207. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11208. $data ['html'] = $html ['html'];
  11209. $data ['inSum'] = $html ['sum'];
  11210. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11211. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11212. $data ['payHtml'] = $html ['html'];
  11213. $data ['paySum'] = $html ['sum'];
  11214. // 余额统计
  11215. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11216. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11217. include './protected/config/wasteBook.conf.php';
  11218. Doo::loadModel ( 'wasteBook' );
  11219. $wasteBook = new wasteBook ();
  11220. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11221. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11222. // 获得年份之前所有金额
  11223. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11224. // print_r($detail);
  11225. // $waste['total'];
  11226. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11227. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11228. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11229. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11230. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11231. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11232. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11233. if (date ( 'Y' ) > $year) {
  11234. $limitMonth = 12;
  11235. }
  11236. for($i = 1; $i <= 12; $i ++) {
  11237. $inComeA = $payB = 0;
  11238. $falg = true;
  11239. foreach ( $inComePay as $key => $value ) {
  11240. if ($value ['month'] == $i) {
  11241. $falg = false;
  11242. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11243. $inSum += $value ['accountPrice'];
  11244. $showInSum += $value ['accountPriceShow'];
  11245. $inComeA = $value ['accountPrice'];
  11246. break;
  11247. }
  11248. }
  11249. if ($falg)
  11250. $inComeHtml .= '<td class="taR">-</td>';
  11251. $payFalg = true;
  11252. foreach ( $pay as $key => $value ) {
  11253. if ($value ['month'] == $i) {
  11254. $payFalg = false;
  11255. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11256. $paySum += $value ['accountPrice'];
  11257. $showPaySum += $value ['accountPriceShow'];
  11258. $payB = $value ['accountPrice'];
  11259. break;
  11260. }
  11261. }
  11262. if ($payFalg)
  11263. $payHtml .= '<td class="taR">-</td>';
  11264. if (empty ( $balanceC ) || $limitMonth < $i)
  11265. $lastBalanceHtml .= '<td class="taR">-</td>';
  11266. else
  11267. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11268. $balanceC = $balanceC + $inComeA + $payB;
  11269. $balanceSum += $balanceC;
  11270. if (empty ( $balanceC ) || $limitMonth < $i)
  11271. $BalanceHtml .= '<td class="taR">-</td>';
  11272. else
  11273. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11274. // 余额统计
  11275. }
  11276. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11277. $data ['inComeHtml'] = $inComeHtml;
  11278. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11279. $data ['payBalanceHtml'] = $payHtml;
  11280. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11281. $data ['BalanceHtml'] = $BalanceHtml;
  11282. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11283. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11284. $mothHtml = "";
  11285. for($i = 1; $i <= 12; $i ++) {
  11286. if ($moth == $i)
  11287. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11288. else
  11289. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11290. }
  11291. $data ['mothHtml'] = $mothHtml;
  11292. $dateHtml = "";
  11293. $now = date ( "Y" );
  11294. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11295. if ($YEARD <= $now) {
  11296. $dateHtml .= '<option ';
  11297. if ($year == $YEARD) {
  11298. $dateHtml .= 'selected ';
  11299. }
  11300. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11301. }
  11302. }
  11303. $data ['dateHtml'] = $dateHtml;
  11304. $data ['year'] = $year;
  11305. $data ['memu'] = "receipt";
  11306. $data ['staff'] = $this->staff;
  11307. $data ['receiptMemu'] = 'paymentsCollect';
  11308. $data ['verifyId'] = $this->verifyId;
  11309. $data ['executeId'] = $this->executeId;
  11310. $this->render ( "/expenses/paymentsCollect", $data );
  11311. }
  11312. function paymentsCollectDay() {
  11313. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11314. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11315. if (empty ( $moth ))
  11316. return 'paymentsCollect';
  11317. Doo::loadModel ( "accountBookStatistics" );
  11318. $accountBookStatistics = new accountBookStatistics ();
  11319. $i = 2;
  11320. $y = 2013;
  11321. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11322. Doo::loadClass ( 'receipt.func' );
  11323. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11324. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11325. $data ['html'] = $html ['html'];
  11326. $data ['inSum'] = $html ['sum'];
  11327. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11328. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11329. $data ['payHtml'] = $html ['html'];
  11330. $data ['paySum'] = $html ['sum'];
  11331. $mothHtml = "";
  11332. for($i = 1; $i <= 12; $i ++) {
  11333. if ($moth == $i)
  11334. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11335. else
  11336. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11337. }
  11338. $data ['mothHtml'] = $mothHtml;
  11339. $data ['year'] = $year;
  11340. // 余额
  11341. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11342. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11343. include './protected/config/wasteBook.conf.php';
  11344. Doo::loadModel ( 'wasteBook' );
  11345. $wasteBook = new wasteBook ();
  11346. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11347. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11348. // 获得年份之前所有金额
  11349. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11350. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11351. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11352. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11353. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11354. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11355. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11356. // $balanceC = 0;
  11357. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11358. $limitDay = date ( 'd' );
  11359. $monthLK = ( int ) date ( 'm' );
  11360. if (date ( 'Y' ) > $year) {
  11361. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11362. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11363. $limitDay = 0;
  11364. }
  11365. for($i = 1; $i <= $day; $i ++) {
  11366. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11367. $inComeA = $payB = 0;
  11368. $falg = true;
  11369. foreach ( $inComePay as $key => $value ) {
  11370. if ($value ['day'] == $i) {
  11371. $falg = false;
  11372. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11373. $inSum += $value ['accountPrice'];
  11374. $showInSum += $value ['accountPriceShow'];
  11375. $inComeA = $value ['accountPrice'];
  11376. break;
  11377. }
  11378. }
  11379. if ($falg)
  11380. $inComeHtml .= '<td class="taR">-</td>';
  11381. $payFalg = true;
  11382. foreach ( $pay as $key => $value ) {
  11383. if ($value ['day'] == $i) {
  11384. $payFalg = false;
  11385. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11386. $paySum += $value ['accountPrice'];
  11387. $showPaySum += $value ['accountPriceShow'];
  11388. $payB = $value ['accountPrice'];
  11389. break;
  11390. }
  11391. }
  11392. if ($payFalg)
  11393. $payHtml .= '<td class="taR">-</td>';
  11394. if (empty ( $balanceC ) || $limitDay < $i)
  11395. $lastBalanceHtml .= '<td class="taR">-</td>';
  11396. else
  11397. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11398. $balanceC = $balanceC + $inComeA + $payB;
  11399. $balanceSum += $balanceC;
  11400. if (empty ( $balanceC ) || $limitDay < $i)
  11401. $BalanceHtml .= '<td class="taR">-</td>';
  11402. else
  11403. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11404. }
  11405. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11406. $data ['inComeHtml'] = $inComeHtml;
  11407. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11408. $data ['payBalanceHtml'] = $payHtml;
  11409. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11410. $data ['BalanceHtml'] = $BalanceHtml;
  11411. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11412. $data ['dayHtml'] = $dayHtml;
  11413. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11414. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11415. $dateHtml = "";
  11416. $now = date ( "Y" );
  11417. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11418. if ($YEARD <= $now) {
  11419. $dateHtml .= '<option ';
  11420. if ($year == $YEARD) {
  11421. $dateHtml .= 'selected ';
  11422. }
  11423. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11424. }
  11425. }
  11426. $data ['dateHtml'] = $dateHtml;
  11427. $data ['memu'] = "receipt";
  11428. $data ['staff'] = $this->staff;
  11429. $data ['receiptMemu'] = 'paymentsCollect';
  11430. $data ['verifyId'] = $this->verifyId;
  11431. $data ['executeId'] = $this->executeId;
  11432. $this->render ( "/expenses/paymentsCollectDay", $data );
  11433. }
  11434. // 公司流水
  11435. function wasteBook() {
  11436. Doo::loadModel ( "execute" );
  11437. $execute = new execute ();
  11438. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11439. die ( 'illegal request' );
  11440. }
  11441. include './protected/config/wasteBook.conf.php';
  11442. Doo::loadModel ( 'wasteBook' );
  11443. $wasteBook = new wasteBook ();
  11444. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11445. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11446. $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'];
  11447. // print_r($waste);
  11448. $data ['waste'] = $waste;
  11449. $data ['total'] = $total;
  11450. // 月流水数据结构
  11451. $monthStatistics = array ();
  11452. $incomeMothStatistics = array ();
  11453. $expenditureMothStatistics = array ();
  11454. for($i = 1; $i <= 12; $i ++) {
  11455. $month = date ( 'Y' ) . '-' . $i;
  11456. if ($i < 10)
  11457. $month = date ( 'Y' ) . '-0' . $i;
  11458. array_push ( $monthStatistics, $month );
  11459. }
  11460. foreach ( $monthStatistics as $value ) {
  11461. $falg = true;
  11462. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11463. if ($value == $v ['inputDate']) {
  11464. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11465. $falg = false;
  11466. }
  11467. }
  11468. if ($falg) {
  11469. array_push ( $incomeMothStatistics, '' );
  11470. }
  11471. $falgEx = true;
  11472. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11473. if ($value == $v ['inputDate']) {
  11474. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11475. $falg = false;
  11476. }
  11477. }
  11478. if ($falgEx) {
  11479. array_push ( $expenditureMothStatistics, '' );
  11480. }
  11481. }
  11482. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11483. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11484. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11485. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11486. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11487. // print_r($incomeList);
  11488. $data ['expenditureList'] = $expenditureList;
  11489. $data ['incomeList'] = $incomeList;
  11490. $data ['memu'] = "receipt";
  11491. $data ['staff'] = $this->staff;
  11492. $data ['receiptMemu'] = 'wasteBook';
  11493. $data ['verifyId'] = $this->verifyId;
  11494. $data ['executeId'] = $this->executeId;
  11495. $this->render ( "/expenses/wasteBook", $data );
  11496. }
  11497. function wasteBookIncome() {
  11498. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11499. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11500. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11501. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11502. $data ['dailyIncomeType'] = $dailyIncomeType;
  11503. Doo::loadModel ( 'wasteBook' );
  11504. $wasteBook = new wasteBook ();
  11505. Doo::loadModel ( 'L_category' );
  11506. $L_category = new L_category ();
  11507. Doo::loadClass ( 'XDeode' );
  11508. $XDeode = new XDeode ( 5 );
  11509. // echo $XDeode->encode(1).'<br>';
  11510. // echo $XDeode->encode(2).'<br>';
  11511. // echo $XDeode->encode(3).'<br>';
  11512. // echo $XDeode->encode(4).'<br>';
  11513. // echo $XDeode->encode(5).'<br>';
  11514. // echo $XDeode->encode(6).'<br>';
  11515. // echo $XDeode->encode(7).'<br>';
  11516. // echo $XDeode->encode(8).'<br>';
  11517. // echo $XDeode->encode(9).'<br>';
  11518. // echo $XDeode->encode(10).'<br>';
  11519. $dateArr = explode ( ':', $date );
  11520. $D1 = '';
  11521. $D2 = '';
  11522. $con = '';
  11523. if (! empty ( $date )) {
  11524. $D1 = $dateArr [0];
  11525. $D2 = $dateArr [1];
  11526. }
  11527. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11528. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11529. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11530. $con = ' and inputDate = "' . $D1 . '"';
  11531. if ($cid != 'ALL') {
  11532. $cid = $XDeode->decode ( $cid );
  11533. $con .= ' and cid = "' . $cid . '"';
  11534. }
  11535. if ($accountType != 'ALL') {
  11536. if ($accountType == 'INVOICE') {
  11537. $con .= ' and (accountType = 7 or accountType = 8)';
  11538. } elseif ($accountType == 'PAYMENTS') {
  11539. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11540. if ($dailyIncomeType != 'ALL') {
  11541. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11542. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11543. }
  11544. }
  11545. }
  11546. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11547. $sum = 0;
  11548. foreach ( $incomeList as $key => $value ) {
  11549. $sum += $value ['accountPrice'];
  11550. }
  11551. // print_r($incomeList);
  11552. // 获得办事和部门
  11553. $categoryList = $L_category->getCategory ();
  11554. $data ['accountType'] = $accountType;
  11555. $data ['cid'] = $cid;
  11556. $data ['categoryList'] = $categoryList;
  11557. $data ['sum'] = $sum;
  11558. $data ['incomeList'] = $incomeList;
  11559. $data ['inputDate'] = $date;
  11560. $data ['memu'] = "receipt";
  11561. $data ['staff'] = $this->staff;
  11562. $data ['receiptMemu'] = 'wasteBook';
  11563. $data ['verifyId'] = $this->verifyId;
  11564. $data ['executeId'] = $this->executeId;
  11565. $this->render ( "/expenses/wasteBookIncome", $data );
  11566. }
  11567. /**
  11568. * 所有支出
  11569. */
  11570. function wasteBookExpenditure() {
  11571. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11572. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11573. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11574. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11575. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11576. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11577. $data ['receiptType'] = $receiptType;
  11578. Doo::loadModel ( 'wasteBook' );
  11579. $wasteBook = new wasteBook ();
  11580. Doo::loadModel ( 'L_category' );
  11581. $L_category = new L_category ();
  11582. Doo::loadClass ( 'XDeode' );
  11583. $XDeode = new XDeode ( 5 );
  11584. $dateArr = explode ( ':', $date );
  11585. $D1 = '';
  11586. $D2 = '';
  11587. $con = '';
  11588. if (! empty ( $date )) {
  11589. $D1 = $dateArr [0];
  11590. $D2 = $dateArr [1];
  11591. }
  11592. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11593. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11594. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11595. $con = ' and inputDate = "' . $D1 . '"';
  11596. if ($cid != 'ALL') {
  11597. $cid = $XDeode->decode ( $cid );
  11598. $con .= ' and cid = "' . $cid . '"';
  11599. }
  11600. if ($accountType != 'ALL') {
  11601. if ($accountType == 'INVOICE') {
  11602. $con .= ' and accountType = 11';
  11603. } elseif ($accountType == 'PAYMENTS') {
  11604. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11605. if ($dailyExpenditureType != 'ALL') {
  11606. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11607. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11608. }
  11609. } elseif ($accountType == 'RECEIPT') {
  11610. if ($receiptType == 'ALL') {
  11611. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11612. } else {
  11613. $receiptType = $XDeode->decode ( $receiptType );
  11614. echo $receiptType;
  11615. if ($receiptType == 1) {
  11616. $con .= ' and (accountType = 1 or accountType=2)';
  11617. } else {
  11618. $con .= ' and accountType = ' . $receiptType;
  11619. }
  11620. }
  11621. }
  11622. }
  11623. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11624. $sum = 0;
  11625. foreach ( $incomeList as $key => $value ) {
  11626. $sum += $value ['accountPriceShow'];
  11627. }
  11628. // print_r($incomeList);
  11629. // 获得办事和部门
  11630. $categoryList = $L_category->getCategory ();
  11631. $data ['accountType'] = $accountType;
  11632. $data ['cid'] = $cid;
  11633. $data ['categoryList'] = $categoryList;
  11634. $data ['sum'] = $sum;
  11635. $data ['incomeList'] = $incomeList;
  11636. $data ['inputDate'] = $date;
  11637. $data ['memu'] = "receipt";
  11638. $data ['staff'] = $this->staff;
  11639. $data ['receiptMemu'] = 'wasteBook';
  11640. $data ['verifyId'] = $this->verifyId;
  11641. $data ['executeId'] = $this->executeId;
  11642. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11643. }
  11644. function ajaxGetWasteinvoiceReceivables() {
  11645. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11646. Doo::loadClass ( 'XDeode' );
  11647. $XDeode = new XDeode ( 5 );
  11648. $irid = $XDeode->decode ( $serial );
  11649. Doo::loadModel ( 'invoiceReceivables' );
  11650. $invoiceReceivables = new invoiceReceivables ();
  11651. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11652. echo json_encode ( array (
  11653. 'status' => 1,
  11654. 'detail' => $detail
  11655. ) );
  11656. }
  11657. function ajaxGetPaymentsByAid() {
  11658. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11659. Doo::loadModel ( "accountBook" );
  11660. $accountBook = new accountBook ();
  11661. $detail = $accountBook->getAccountBookByAid ( $serial );
  11662. echo json_encode ( array (
  11663. 'status' => 1,
  11664. 'detail' => $detail
  11665. ) );
  11666. }
  11667. function ajaxGetWasteInvoice() {
  11668. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11669. Doo::loadModel ( 'invoice' );
  11670. $invoice = new invoice ();
  11671. Doo::loadModel ( 'invoiceReceivables' );
  11672. $invoiceReceivables = new invoiceReceivables ();
  11673. $detail = $invoice->getInvoiceByIid ( $serial );
  11674. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11675. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11676. echo json_encode ( array (
  11677. 'status' => 1,
  11678. 'detail' => $detail
  11679. ) );
  11680. }
  11681. /**
  11682. */
  11683. function ajaxGetWasteReceipt() {
  11684. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11685. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11686. Doo::loadModel ( 'receipt' );
  11687. $receipt = new receipt ();
  11688. Doo::loadClass ( 'XDeode' );
  11689. $XDeode = new XDeode ( 5 );
  11690. $rid = $XDeode->decode ( $serial );
  11691. $accountType= $XDeode->decode ( $accountTypeKey );
  11692. // 获得个数据
  11693. $detail = $receipt->getReceiptByRid ( $rid );
  11694. // 初始化
  11695. $detail ['reviseDetail'] = array ();
  11696. if (! empty ( $value ['reviseDetail'] ))
  11697. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11698. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11699. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11700. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11701. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11702. // 获得费用html
  11703. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11704. // 获得费用审批人数据
  11705. $detail = $this->getReceiptApproverHtml ( $detail );
  11706. // 审批执行
  11707. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11708. <th class="taC" width="90">审批人</th>
  11709. <th class="taC">审批意见</th></tr>';
  11710. foreach ( $detail ['verifyList'] as $key => $value ) {
  11711. $html .= '<tr>
  11712. <td>' . $value [1] . '</td>
  11713. <td>' . $value ['opinion'] . '</td>
  11714. </tr>
  11715. ';
  11716. }
  11717. $html .= ' </tbody></table>';
  11718. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11719. <th class="taC" width="90">执行人</th>
  11720. <th class="taC">执行意见</th></tr>';
  11721. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11722. $html .= '<tr>
  11723. <td>' . $value [1] . '</td>
  11724. <td>' . $value ['opinion'] . '</td>
  11725. </tr>
  11726. ';
  11727. }
  11728. $html .= ' </tbody></table>';
  11729. if($accountType==1){
  11730. Doo::loadModel ( 'loanReceipt' );
  11731. $loanReceipt = new loanReceipt ();
  11732. $loanList = $loanReceipt->getOne ( array (
  11733. 'where' => 'rid=' . $detail ['loanRid'],
  11734. 'desc' => 'rid',
  11735. 'asArray' => true
  11736. ) );
  11737. $html .= '<table class="table table-bordered table-condensed">
  11738. <tr class="warning">
  11739. <td class="taR"><b>汇款金额</b></td>
  11740. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11741. </tr>
  11742. </table>';
  11743. }else{
  11744. $html .= '<table class="table table-bordered table-condensed">
  11745. <tr class="warning">
  11746. <td class="taR"><b>汇款金额</b></td>
  11747. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11748. </tr>
  11749. </table>';
  11750. }
  11751. // print_r($detail['verifyList']);
  11752. // header ( 'Content-Type:text/html;charset=utf-8' );
  11753. // echo $html;
  11754. echo json_encode ( array (
  11755. 'status' => 1,
  11756. 'html' => $html,
  11757. 'detail' => $detail
  11758. ) );
  11759. }
  11760. function getReceiptApproverHtml($detail = array()) {
  11761. Doo::loadModel ( 'loanReceipt' );
  11762. $loanReceipt = new loanReceipt ();
  11763. Doo::loadModel ( 'verify' );
  11764. $verify = new verify ();
  11765. Doo::loadModel ( 'staff' );
  11766. $staff = new staff ();
  11767. if (empty ( $detail ))
  11768. return array ();
  11769. $loanList = $loanReceipt->getOne ( array (
  11770. 'where' => 'rid=' . $detail ['loanRid'],
  11771. 'desc' => 'rid',
  11772. 'asArray' => true
  11773. ) );
  11774. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11775. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11776. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11777. else
  11778. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11779. } else
  11780. $verifyList = $verify->getOne ( array (
  11781. 'where' => 'vid=' . $detail ['verify'],
  11782. 'asArray' => true
  11783. ) );
  11784. $verifyList = json_decode ( $verifyList ['staff'], true );
  11785. Doo::loadModel ( 'role' );
  11786. $role = new role ();
  11787. $roleId = 0;
  11788. $flag = true;
  11789. $roleKey = 0;
  11790. $endStaffArray = array ();
  11791. $roleArrayCopy = array ();
  11792. foreach ( $verifyList as $k => $v ) {
  11793. // init verifyStaff
  11794. if ($v [1] == 'ROLE') {
  11795. if (! empty ( $verifyStaff )) {
  11796. $endStaffArray = end ( $verifyStaff );
  11797. }
  11798. $roleVerify = json_decode ( $v [3], true );
  11799. $roleKey = $k;
  11800. $roleArray = array ();
  11801. $rolename = $role->getOne ( array (
  11802. 'where' => 'rid=' . $v [0],
  11803. 'asArray' => true
  11804. ) );
  11805. foreach ( $roleVerify as $o => $p ) {
  11806. $staffID = explode ( '_', $p );
  11807. $staffInfo = $staff->getOne ( array (
  11808. 'where' => 'sid=' . $staffID [0],
  11809. 'asArray' => true
  11810. ) );
  11811. // print_r($staffID);
  11812. $exp = array (
  11813. 0 => $staffInfo ['sid'],
  11814. 1 => $staffID [1],
  11815. 2 => $staffInfo ['avatar'],
  11816. 'date' => '',
  11817. 'date' => '',
  11818. 'opinion' => '',
  11819. 'status' => '',
  11820. 'rolename' => $rolename ['name']
  11821. );
  11822. array_push ( $roleArray, $exp );
  11823. }
  11824. $roleArrayCopy [$v [0]] = $roleArray;
  11825. // $verifyList[$k]['roleArray']=$roleArray;
  11826. }
  11827. $verifyList [$k] ['date'] = "";
  11828. $verifyList [$k] ['opinion'] = "";
  11829. $verifyList [$k] ['status'] = "";
  11830. if (empty ( $verifyStaff )) {
  11831. $verifyList [$k] ['date'] = "";
  11832. $verifyList [$k] ['opinion'] = "";
  11833. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11834. $verifyList [$k] ['status'] = 4;
  11835. $flag = false;
  11836. }
  11837. } else {
  11838. foreach ( $verifyStaff as $m => $u ) {
  11839. if ($v [0] == $m) {
  11840. $verifyList [$k] ['date'] = $u ['date'];
  11841. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11842. $verifyList [$k] ['status'] = $u ['status'];
  11843. $flag = false;
  11844. break;
  11845. }
  11846. }
  11847. $endStaffArray = end ( $verifyStaff );
  11848. }
  11849. }
  11850. $rolename ['name'] = '';
  11851. if (! empty ( $roleId )) {
  11852. Doo::loadModel ( 'role' );
  11853. $role = new role ();
  11854. $rolename = $role->getOne ( array (
  11855. 'where' => 'rid=' . $roleId,
  11856. 'asArray' => true
  11857. ) );
  11858. }
  11859. if (! empty ( $verifyStaff ))
  11860. $endStaffArray = end ( $verifyStaff );
  11861. $KOP = false;
  11862. foreach ( $roleArrayCopy as $P => $A ) {
  11863. foreach ( $A as $MKI => $AVL ) {
  11864. if (! empty ( $verifyStaff )) {
  11865. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11866. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11867. $button = 4;
  11868. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11869. }
  11870. foreach ( $verifyStaff as $m => $u ) {
  11871. $AVLFK = $AVL [0] . '_R';
  11872. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11873. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11874. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11875. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11876. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11877. break;
  11878. }
  11879. }
  11880. } else {
  11881. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11882. $button = 4;
  11883. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11884. }
  11885. }
  11886. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11887. $KOP = true;
  11888. }
  11889. }
  11890. foreach ( $roleArrayCopy as $k => $v ) {
  11891. foreach ( $verifyList as $m => $n ) {
  11892. if ($n [0] == $k) {
  11893. array_splice ( $verifyList, $m, 1, $v );
  11894. }
  11895. }
  11896. }
  11897. // 费用执行人相关数据
  11898. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11899. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11900. foreach ( $executeCopy as $k => $v ) {
  11901. $executeCopy [$k] ['date'] = '';
  11902. $executeCopy [$k] ['opinion'] = '';
  11903. $executeCopy [$k] ['status'] = '';
  11904. if (! empty ( $executeStaff ))
  11905. foreach ( $executeStaff as $m => $u ) {
  11906. if ($v [0] == $m) {
  11907. $executeCopy [$k] ['date'] = $u ['date'];
  11908. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11909. $executeCopy [$k] ['status'] = $u ['status'];
  11910. break;
  11911. }
  11912. }
  11913. }
  11914. $detail ['executeCopy'] = $executeCopy;
  11915. $detail ['verifyList'] = $verifyList;
  11916. return $detail;
  11917. }
  11918. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11919. if (empty ( $detail ))
  11920. return '';
  11921. $html = '';
  11922. if ($detail ['Rtype'] == 0) { // 报销单
  11923. $html .= '<table class="table table-bordered table-condensed">
  11924. <tbody>
  11925. <tr>
  11926. <th colspan="2" class="taC">日常相关费用</th>
  11927. </tr>';
  11928. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11929. $html .= '
  11930. <tr>
  11931. <th>' . $value ['name'] . '</th>
  11932. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11933. </tr>';
  11934. }
  11935. $html .= '
  11936. <tr>
  11937. <th class="taR">合计</th>
  11938. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11939. </tr>';
  11940. $html .= '<tr>
  11941. <th colspan="2" class="taC">差旅相关费用</th>
  11942. </tr>';
  11943. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11944. $html .= '
  11945. <tr>
  11946. <th>' . $value ['name'] . '</th>
  11947. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11948. </tr>';
  11949. }
  11950. $html .= '
  11951. <tr>
  11952. <th class="taR">合计</th>
  11953. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11954. </tr>';
  11955. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11956. $html .= '<tr>
  11957. <th colspan="2" class="taC">内部培训费用</th>
  11958. </tr>';
  11959. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11960. $html .= '
  11961. <tr>
  11962. <th>' . $value ['name'] . '</th>
  11963. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11964. </tr>';
  11965. }
  11966. $html .= '
  11967. <tr>
  11968. <th class="taR">合计</th>
  11969. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11970. </tr>';
  11971. }
  11972. $html .= '<tr>
  11973. <th colspan="2" class="taC">其他</th>
  11974. </tr>';
  11975. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11976. $html .= '
  11977. <tr>
  11978. <th>' . $value ['name'] . '</th>
  11979. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11980. </tr>';
  11981. }
  11982. $html .= '
  11983. <tr>
  11984. <th class="taR">合计</th>
  11985. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11986. </tr>';
  11987. $html .= '<tr>
  11988. <th colspan="2" class="taC">报销金额调整</th>
  11989. </tr>';
  11990. foreach ( $detail ['reviseDetail'] 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 ['revisePrice'] . '</td>
  12001. </tr>';
  12002. $html .= '
  12003. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12004. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12005. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12006. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12007. <tr class="warning">
  12008. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12009. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12010. </tr>
  12011. </tbody>
  12012. </table>';
  12013. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12014. $html .= '
  12015. <table class="table table-bordered table-condensed">
  12016. <tbody>
  12017. <tr>
  12018. <th colspan="2" class="taC">办事处相关费用</th>
  12019. </tr>';
  12020. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12021. $html .= '
  12022. <tr>
  12023. <th>' . $value ['name'] . '</th>
  12024. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12025. </tr>';
  12026. }
  12027. $html .= '
  12028. <tr>
  12029. <th class="taR">合计</th>
  12030. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12031. </tr>';
  12032. $html .= '
  12033. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12034. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12035. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12036. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12037. <tr class="warning">
  12038. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12039. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12040. </tr>
  12041. </tbody>
  12042. </table>';
  12043. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12044. Doo::loadModel ( 'loanReceipt' );
  12045. $loanReceipt = new loanReceipt ();
  12046. $loanList = $loanReceipt->getOne ( array (
  12047. 'where' => 'rid=' . $detail ['loanRid'],
  12048. 'desc' => 'rid',
  12049. 'asArray' => true
  12050. ) );
  12051. // print_r($loanList);
  12052. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12053. $html .= '<table class="table table-bordered table-condensed">
  12054. <tbody>
  12055. <tr>
  12056. <th colspan="2" class="taC">借款费用</th>
  12057. </tr>';
  12058. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12059. $html .= '<tr>
  12060. <th>' . $value ['name'] . '</th>
  12061. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12062. </tr>';
  12063. }
  12064. $html .= '<tr>
  12065. <th class="taC" colspan="2">产生费用所在办事处</th>
  12066. </tr>
  12067. <tr>
  12068. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12069. </tr>
  12070. <tr>
  12071. <th class="taC" colspan="2">费用说明</th>
  12072. </tr>
  12073. <tr>
  12074. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12075. </tr>
  12076. <tr class="warning">
  12077. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12078. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12079. </tr>
  12080. </tbody>
  12081. </table>
  12082. ';
  12083. if ( $accountType==2) {
  12084. $balance=$detail ['sum']-$loanList ['sum'];
  12085. $balanceCN=$this->num_to_rmb($balance);
  12086. $html .= '<table class="table table-bordered table-condensed">
  12087. <tbody>
  12088. <tr>
  12089. <th colspan="2" class="taC">日常相关费用</th>
  12090. </tr>';
  12091. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12092. $html .= '
  12093. <tr>
  12094. <th>' . $value ['name'] . '</th>
  12095. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12096. </tr>';
  12097. }
  12098. $html .= '
  12099. <tr>
  12100. <th class="taR">合计</th>
  12101. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12102. </tr>';
  12103. $html .= '<tr>
  12104. <th colspan="2" class="taC">差旅相关费用</th>
  12105. </tr>';
  12106. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12107. $html .= '
  12108. <tr>
  12109. <th>' . $value ['name'] . '</th>
  12110. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12111. </tr>';
  12112. }
  12113. $html .= '
  12114. <tr>
  12115. <th class="taR">合计</th>
  12116. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12117. </tr>';
  12118. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12119. $html .= '<tr>
  12120. <th colspan="2" class="taC">内部培训费用</th>
  12121. </tr>';
  12122. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12123. $html .= '
  12124. <tr>
  12125. <th>' . $value ['name'] . '</th>
  12126. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12127. </tr>';
  12128. }
  12129. $html .= '
  12130. <tr>
  12131. <th class="taR">合计</th>
  12132. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12133. </tr>';
  12134. }
  12135. $html .= '<tr>
  12136. <th colspan="2" class="taC">其他</th>
  12137. </tr>';
  12138. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12139. $html .= '
  12140. <tr>
  12141. <th>' . $value ['name'] . '</th>
  12142. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12143. </tr>';
  12144. }
  12145. $html .= '
  12146. <tr>
  12147. <th class="taR">合计</th>
  12148. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12149. </tr>';
  12150. $html .= '<tr>
  12151. <th colspan="2" class="taC">报销金额调整</th>
  12152. </tr>';
  12153. foreach ( $detail ['reviseDetail'] 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 ['revisePrice'] . '</td>
  12164. </tr>';
  12165. $html .= '
  12166. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12167. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12168. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12169. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12170. <tr class="warning">
  12171. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12172. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12173. </tr>
  12174. <tr class="success">
  12175. <td class="taR"><b>借款结余</b></td>
  12176. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12177. </tr>
  12178. </tbody>
  12179. </table>';
  12180. }
  12181. }
  12182. return $html;
  12183. }
  12184. /**
  12185. * 计算流水
  12186. */
  12187. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12188. $bakWaste ['bank'] = array (
  12189. 'CGBDeposit' => 0,
  12190. 'ICBCDeposit' => 0,
  12191. 'HUADeposit' => 0,
  12192. 'PersonalDeposit' => 0
  12193. );
  12194. $bakWaste ['financial'] = array (
  12195. 'current' => array (
  12196. 'CGBDeposit' => 0,
  12197. 'ICBCDeposit' => 0
  12198. ),
  12199. 'fixed' => array (
  12200. 'CGBDeposit' => 0,
  12201. 'ICBCDeposit' => 0
  12202. )
  12203. );
  12204. // 存款
  12205. foreach ( $waste ['bank'] as $key => $value ) {
  12206. // 收入
  12207. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12208. // 广发
  12209. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12210. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12211. }
  12212. // 工商
  12213. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12214. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12215. }
  12216. // 华润
  12217. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12218. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12219. }
  12220. // 个人
  12221. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12222. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12223. }
  12224. }
  12225. }
  12226. foreach ( $waste ['bank'] as $key => $value ) {
  12227. // 支出
  12228. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12229. // 广发
  12230. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12231. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12232. }
  12233. // 工商
  12234. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12235. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12236. }
  12237. // 华润
  12238. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12239. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12240. }
  12241. // 个人
  12242. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12243. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12244. }
  12245. }
  12246. }
  12247. // 活期
  12248. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12249. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12250. // 广发
  12251. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12252. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12253. }
  12254. // 工商
  12255. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12256. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12257. }
  12258. // 个人
  12259. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12260. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12261. }
  12262. }
  12263. }
  12264. // print_r($inComeStatistics ['fixedStatistics']);
  12265. // 固期
  12266. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12267. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12268. // 广发
  12269. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12270. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12271. }
  12272. // 工商
  12273. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12274. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12275. }
  12276. // 个人
  12277. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12278. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12279. }
  12280. }
  12281. }
  12282. return $waste;
  12283. }
  12284. function lyt() {
  12285. Doo::loadModel ( "receiptDetail" );
  12286. $receiptDetail = new receiptDetail ();
  12287. $receiptCollectList = $receiptDetail->find ( array (
  12288. 'where' => 'status=1 ',
  12289. 'asArray' => true
  12290. ) );
  12291. foreach ( $receiptCollectList as $key => $value ) {
  12292. $receiptDetail = new receiptDetail ();
  12293. $receiptDetail->pastDate = $value ['date'];
  12294. $receiptDetail->update ( array (
  12295. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12296. ) );
  12297. }
  12298. }
  12299. function staffCollectMonthDetail() {
  12300. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12301. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12302. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12303. if (! $year)
  12304. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12305. if (! $month)
  12306. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12307. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12308. if (! $nature){
  12309. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12310. }
  12311. Doo::loadModel ( 'staff' );
  12312. $staff = new staff ();
  12313. Doo::loadModel ( "receiptDetail" );
  12314. $receiptDetail = new receiptDetail ();
  12315. Doo::loadModel ( 'accountItem' );
  12316. $accountItem = new accountItem ();
  12317. Doo::loadModel ( 'statistics' );
  12318. $statistics = new statistics ();
  12319. Doo::loadModel ( "receiptAuthorityManage" );
  12320. $receiptAuthorityManage = new receiptAuthorityManage ();
  12321. $aiList=$accountItem->getAccountItem();
  12322. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12323. $cidList = array ();
  12324. foreach ( $imcStaff as $key => $value ) {
  12325. array_push ( $cidList, $value ['cid'] );
  12326. }
  12327. $cidString = implode ( ',', $cidList );
  12328. $naturecon='';
  12329. if ($nature=='ONJOB'){
  12330. $naturecon=' and (nature!=4 )';
  12331. }elseif($nature=='LEAVEJOB'){
  12332. $naturecon=' and (nature=4 )';
  12333. }else{
  12334. die ( 'illegal request--nature' );
  12335. }
  12336. $staffList = $staff->find ( array (
  12337. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12338. 'asArray' => true
  12339. ) );
  12340. $categoryList = $staff->find ( array (
  12341. 'select' => 'COUNT(*) as count,cid,category',
  12342. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12343. 'groupby' => 'cid',
  12344. 'asArray' => true
  12345. ) );
  12346. $list = array ();
  12347. foreach($aiList as $key=>$value){
  12348. foreach ($value as $v){
  12349. $subtotal[$key][$v['name']]=0;
  12350. }
  12351. }
  12352. foreach ( $categoryList as $vlu ) {
  12353. $s1 = 0;
  12354. $m1 = 0;
  12355. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12356. foreach ( $staffList as $value ) {
  12357. if ($vlu ['cid'] == $value ['cid']) {
  12358. // pastDate
  12359. $receiptCollectList = $receiptDetail->find ( array (
  12360. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12361. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12362. 'groupby' => 'item,Month(pastDate),itemCategory',
  12363. 'asArray' => true
  12364. ) );
  12365. if (! empty ( $receiptCollectList )) {
  12366. $receiptL = array (
  12367. '日常相关费用' => array (),
  12368. '差旅相关费用' => array (),
  12369. '内部培训费用' => array (),
  12370. '培训班费用' => array (),
  12371. '其他' => array ()
  12372. );
  12373. $html = "";
  12374. $psum = 0;
  12375. foreach ( $aiList[$this->AGENCY] as $va ) {
  12376. $falg = true;
  12377. foreach ( $receiptCollectList as $v ) {
  12378. if ($v ['itemCategory'] == '日常相关费用') {
  12379. if ($v ['item'] == $va['name']) {
  12380. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12381. $psum += $v ['price'];
  12382. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12383. $falg = false;
  12384. break;
  12385. }
  12386. }
  12387. }
  12388. if ($falg)
  12389. $html .= '<td class="taR">-</td>';
  12390. }
  12391. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12392. if (! empty ( $psum ))
  12393. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12394. else
  12395. $psum = '<td class="colGreen taR">-</td>';
  12396. $receiptL ['日常相关费用'] = $psum . $html;
  12397. /* ----------------------------------- */
  12398. $html = "";
  12399. $psum = 0;
  12400. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12401. $falg = true;
  12402. foreach ( $receiptCollectList as $v ) {
  12403. if ($v ['itemCategory'] == '差旅相关费用') {
  12404. if ($v ['item'] == $va['name']) {
  12405. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12406. $psum += $v ['price'];
  12407. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12408. $falg = false;
  12409. break;
  12410. }
  12411. }
  12412. }
  12413. if ($falg)
  12414. $html .= '<td class="taR">-</td>';
  12415. }
  12416. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12417. if (! empty ( $psum ))
  12418. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12419. else
  12420. $psum = '<td class="colGreen taR">-</td>';
  12421. $receiptL ['差旅相关费用'] = $psum . $html;
  12422. /* ------------------------------------- */
  12423. $html = "";
  12424. $psum = 0;
  12425. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12426. $falg = true;
  12427. foreach ( $receiptCollectList as $v ) {
  12428. if ($v ['itemCategory'] == '内部培训费用') {
  12429. if ($v ['item'] == $va['name']) {
  12430. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12431. $psum += $v ['price'];
  12432. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12433. $falg = false;
  12434. break;
  12435. }
  12436. }
  12437. }
  12438. if ($falg)
  12439. $html .= '<td class="taR">-</td>';
  12440. }
  12441. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12442. if (! empty ( $psum ))
  12443. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12444. else
  12445. $psum = '<td class="colGreen taR">-</td>';
  12446. $receiptL ['内部培训费用'] = $psum . $html;
  12447. /* ----------------------------------- */
  12448. $html = "";
  12449. $psum = 0;
  12450. foreach ( $aiList[$this->TRAIN] as $va ) {
  12451. $falg = true;
  12452. foreach ( $receiptCollectList as $v ) {
  12453. if ($v ['itemCategory'] == '培训班费用') {
  12454. if ($v ['item'] == $va['name']) {
  12455. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12456. $psum += $v ['price'];
  12457. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12458. $falg = false;
  12459. break;
  12460. }
  12461. }
  12462. }
  12463. if ($falg)
  12464. $html .= '<td class="taR">-</td>';
  12465. }
  12466. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12467. if (! empty ( $psum ))
  12468. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12469. else
  12470. $psum = '<td class="colGreen taR">-</td>';
  12471. $receiptL ['培训班费用'] = $psum . $html;
  12472. /* ------------------------------------- */
  12473. $html = "";
  12474. $psum = 0;
  12475. foreach ( $aiList[$this->OTHER] as $va ) {
  12476. $falg = true;
  12477. foreach ( $receiptCollectList as $v ) {
  12478. if ($v ['itemCategory'] == '其他') {
  12479. if (trim ( $v ['item'] ) == $va['name']) {
  12480. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12481. $psum += $v ['price'];
  12482. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12483. $falg = false;
  12484. break;
  12485. }
  12486. }
  12487. }
  12488. if ($falg)
  12489. $html .= '<td class="taR">-</td>';
  12490. }
  12491. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12492. if (! empty ( $psum ))
  12493. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12494. else
  12495. $psum = '<td class="colGreen taR">-</td>';
  12496. $receiptL ['其他'] = $psum . $html;
  12497. /* ------------------------------------- */
  12498. $html = "";
  12499. $psum = 0;
  12500. foreach ( $receiptCollectList as $v ) {
  12501. if ($v ['itemCategory'] == '报销金额调整') {
  12502. if (! empty ( $v ['price'] )) {
  12503. $psum += $v ['price'];
  12504. }
  12505. }
  12506. }
  12507. $s1 += $psum;
  12508. if (! empty ( $psum ))
  12509. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12510. else
  12511. $psum = '<td class="taR colOrange">-</td>';
  12512. $receiptL ['报销金额调整'] = $psum . $html;
  12513. } else {
  12514. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12515. foreach ( $aiList[$this->AGENCY] as $va ) {
  12516. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12517. }
  12518. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12519. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12520. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12521. }
  12522. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12523. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12524. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12525. }
  12526. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12527. foreach ( $aiList[$this->TRAIN] as $va ) {
  12528. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12529. }
  12530. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12531. foreach ( $aiList[$this->OTHER] as $va ) {
  12532. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12533. }
  12534. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12535. }
  12536. $monthStaffPrice = $receiptDetail->find ( array (
  12537. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12538. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12539. 'groupby' => 'Month(pastDate)',
  12540. 'asArray' => true
  12541. ) );
  12542. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12543. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12544. $m1 += $monthStaffPrice [0] ['price'];
  12545. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12546. } else
  12547. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12548. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12549. $list [$value ['username']] = $receiptL;
  12550. }
  12551. }
  12552. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12553. foreach ( $aiList[$this->AGENCY] as $va ) {
  12554. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12555. $subtotal[$this->AGENCY][$va['name']]=0;
  12556. }
  12557. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12558. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12559. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12560. $subtotal[$this->TRAVEL][$va['name']]=0;
  12561. }
  12562. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12563. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12564. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12565. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12566. }
  12567. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12568. foreach ( $aiList[$this->TRAIN] as $va ) {
  12569. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12570. $subtotal[$this->TRAIN][$va['name']]=0;
  12571. }
  12572. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12573. foreach ( $aiList[$this->OTHER] as $va ) {
  12574. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12575. $subtotal[$this->OTHER][$va['name']]=0;
  12576. }
  12577. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12578. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12579. $receiptL ['usernameEn'] =false;
  12580. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12581. }
  12582. $data ['list'] = $list;
  12583. // print_r($list);
  12584. $receiptCollectList = $receiptDetail->find ( array (
  12585. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12586. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12587. 'groupby' => 'item,Month(pastDate),itemCategory',
  12588. 'asArray' => true
  12589. ) );
  12590. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12591. // statistics html
  12592. $stList = $statistics->getOne ( array (
  12593. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12594. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12595. 'groupby' => 'Month(date)',
  12596. 'asArray' => true
  12597. ) );
  12598. if (empty ( $stList ))
  12599. $stList = array (
  12600. 'rePrice' => 0,
  12601. 'agPrice' => 0
  12602. );
  12603. $data ['stList'] = array (
  12604. 'rePrice' => $stList ['rePrice'],
  12605. 'agPrice' => $stList ['agPrice'],
  12606. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12607. );
  12608. $monthHtml = "";
  12609. for($i = 1; $i <= 12; $i ++) {
  12610. if ($i == $month)
  12611. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12612. else
  12613. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12614. }
  12615. $data ['monthHtml'] = $monthHtml;
  12616. $data ['year'] = $year;
  12617. $data ['month'] = $month;
  12618. $data ['nature'] = $nature;
  12619. $data ['aiList'] = $aiList;
  12620. $data ['memu'] = "receipt";
  12621. $data ['staff'] = $this->staff;
  12622. $data ['receiptMemu'] = 'companyCategoryCollect';
  12623. $data ['verifyId'] = $this->verifyId;
  12624. $data ['executeId'] = $this->executeId;
  12625. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12626. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12627. }
  12628. function staffCollectMonthDetail2() {
  12629. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12630. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12631. if (! $year)
  12632. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12633. if (! $month)
  12634. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12635. Doo::loadModel ( 'staff' );
  12636. $staff = new staff ();
  12637. Doo::loadModel ( "receiptDetail" );
  12638. $receiptDetail = new receiptDetail ();
  12639. Doo::loadModel ( 'accountItem' );
  12640. $accountItem = new accountItem ();
  12641. Doo::loadModel ( 'statistics' );
  12642. $statistics = new statistics ();
  12643. Doo::loadModel ( 'L_category' );
  12644. $lCategory = new L_category ();
  12645. $staffList = $staff->find ( array (
  12646. 'where' => 'username!="admin"',
  12647. 'asArray' => true
  12648. ) );
  12649. $categoryList = $staff->find ( array (
  12650. 'select' => 'COUNT(*) as count,cid,category',
  12651. 'where' => 'username !="admin"',
  12652. 'groupby' => 'cid',
  12653. 'asArray' => true
  12654. ) );
  12655. $list = array ();
  12656. foreach ( $categoryList as $vlu ) {
  12657. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12658. $r1 = 0;
  12659. $r2 = 0;
  12660. $r3 = 0;
  12661. $r4 = 0;
  12662. $r5 = 0;
  12663. $r6 = 0;
  12664. $r7 = 0;
  12665. $r8 = 0;
  12666. $r9 = 0;
  12667. $r10 = 0;
  12668. $r11 = 0;
  12669. $r12 = 0;
  12670. $r13 = 0;
  12671. $r14 = 0;
  12672. $r15 = 0;
  12673. $c1 = 0;
  12674. $c2 = 0;
  12675. $c3 = 0;
  12676. $c4 = 0;
  12677. $c5 = 0;
  12678. $c6 = 0;
  12679. $p1 = 0;
  12680. $p2 = 0;
  12681. $p3 = 0;
  12682. $p4 = 0;
  12683. $p5 = 0;
  12684. $p6 = 0;
  12685. $p7 = 0;
  12686. $p8 = 0;
  12687. $p9 = 0;
  12688. $t1 = 0;
  12689. $t2 = 0;
  12690. $t3 = 0;
  12691. $t4 = 0;
  12692. $t5 = 0;
  12693. $s1 = 0;
  12694. $m1 = 0;
  12695. foreach ( $staffList as $value ) {
  12696. if ($vlu ['cid'] == $value ['cid']) {
  12697. $receiptCollectList = $receiptDetail->find ( array (
  12698. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12699. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12700. 'groupby' => 'item,Month(date),itemCategory',
  12701. 'asArray' => true
  12702. ) );
  12703. if (! empty ( $receiptCollectList )) {
  12704. $receiptL = array (
  12705. '日常相关费用' => array (),
  12706. '差旅相关费用' => array (),
  12707. '培训班费用' => array (),
  12708. '其他' => array ()
  12709. );
  12710. $html = "";
  12711. $psum = 0;
  12712. $item = array (
  12713. '市内交通费',
  12714. '市内出租费',
  12715. '办事处房租',
  12716. '电话费',
  12717. '水费',
  12718. '电费',
  12719. '办公费用',
  12720. '邮寄费',
  12721. '其他费用',
  12722. '车辆费用',
  12723. '广告费',
  12724. '团队建设费',
  12725. '物业管理费',
  12726. '宽带费'
  12727. );
  12728. foreach ( $item as $va ) {
  12729. $falg = true;
  12730. foreach ( $receiptCollectList as $v ) {
  12731. if ($v ['itemCategory'] == '日常相关费用') {
  12732. if ($v ['item'] == $va) {
  12733. if ($va == '市内交通费')
  12734. $r1 += $v ['price'];
  12735. if ($va == '市内出租费')
  12736. $r2 += $v ['price'];
  12737. if ($va == '办事处房租')
  12738. $r3 += $v ['price'];
  12739. if ($va == '电话费')
  12740. $r4 += $v ['price'];
  12741. if ($va == '水费')
  12742. $r5 += $v ['price'];
  12743. if ($va == '电费')
  12744. $r6 += $v ['price'];
  12745. if ($va == '办公费用')
  12746. $r7 += $v ['price'];
  12747. if ($va == '邮寄费')
  12748. $r8 += $v ['price'];
  12749. if ($va == '其他费用')
  12750. $r9 += $v ['price'];
  12751. if ($va == '车辆费用')
  12752. $r10 += $v ['price'];
  12753. if ($va == '广告费')
  12754. $r11 += $v ['price'];
  12755. if ($va == '团队建设费')
  12756. $r13 += $v ['price'];
  12757. if ($va == '物业管理费')
  12758. $r14 += $v ['price'];
  12759. if ($va == '宽带费')
  12760. $r15 += $v ['price'];
  12761. $psum += $v ['price'];
  12762. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12763. $falg = false;
  12764. break;
  12765. }
  12766. }
  12767. }
  12768. if ($falg)
  12769. $html .= '<td class="taR">-</td>';
  12770. }
  12771. $r12 += $psum;
  12772. if (! empty ( $psum ))
  12773. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12774. else
  12775. $psum = '<td class="colGreen taR">-</td>';
  12776. $receiptL ['日常相关费用'] = $psum . $html;
  12777. /* ----------------------------------- */
  12778. $html = "";
  12779. $psum = 0;
  12780. $item = array (
  12781. '往来交通费',
  12782. '市内交通费',
  12783. '出差住宿费',
  12784. '出差补助',
  12785. '其他费用'
  12786. );
  12787. foreach ( $item as $va ) {
  12788. $falg = true;
  12789. foreach ( $receiptCollectList as $v ) {
  12790. if ($v ['itemCategory'] == '差旅相关费用') {
  12791. if ($v ['item'] == $va) {
  12792. if ($va == '往来交通费')
  12793. $c1 += $v ['price'];
  12794. if ($va == '市内交通费')
  12795. $c2 += $v ['price'];
  12796. if ($va == '出差住宿费')
  12797. $c3 += $v ['price'];
  12798. if ($va == '出差补助')
  12799. $c4 += $v ['price'];
  12800. if ($va == '其他费用')
  12801. $c5 += $v ['price'];
  12802. $psum += $v ['price'];
  12803. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12804. $falg = false;
  12805. break;
  12806. }
  12807. }
  12808. }
  12809. if ($falg)
  12810. $html .= '<td class="taR">-</td>';
  12811. }
  12812. $c6 += $psum;
  12813. if (! empty ( $psum ))
  12814. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12815. else
  12816. $psum = '<td class="colGreen taR">-</td>';
  12817. $receiptL ['差旅相关费用'] = $psum . $html;
  12818. /* ------------------------------------- */
  12819. $html = "";
  12820. $psum = 0;
  12821. $item = array (
  12822. '场租费',
  12823. '薪酬',
  12824. '住宿费',
  12825. '交通费',
  12826. '餐饮费',
  12827. '办公费',
  12828. '公关费',
  12829. '其他'
  12830. );
  12831. foreach ( $item as $va ) {
  12832. $falg = true;
  12833. foreach ( $receiptCollectList as $v ) {
  12834. if ($v ['itemCategory'] == '培训班费用') {
  12835. if ($v ['item'] == $va) {
  12836. if ($va == '场租费')
  12837. $p1 += $v ['price'];
  12838. if ($va == '薪酬')
  12839. $p2 += $v ['price'];
  12840. if ($va == '住宿费')
  12841. $p3 += $v ['price'];
  12842. if ($va == '交通费')
  12843. $p4 += $v ['price'];
  12844. if ($va == '餐饮费')
  12845. $p5 += $v ['price'];
  12846. if ($va == '办公费')
  12847. $p6 += $v ['price'];
  12848. if ($va == '公关费')
  12849. $p7 += $v ['price'];
  12850. if ($va == '其他')
  12851. $p8 += $v ['price'];
  12852. $psum += $v ['price'];
  12853. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12854. $falg = false;
  12855. break;
  12856. }
  12857. }
  12858. }
  12859. if ($falg)
  12860. $html .= '<td class="taR">-</td>';
  12861. }
  12862. $p9 += $psum;
  12863. if (! empty ( $psum ))
  12864. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12865. else
  12866. $psum = '<td class="colGreen taR">-</td>';
  12867. $receiptL ['培训班费用'] = $psum . $html;
  12868. /* ------------------------------------- */
  12869. $html = "";
  12870. $psum = 0;
  12871. $item = array (
  12872. '公关费',
  12873. '广告费',
  12874. '借款',
  12875. '可自加费用'
  12876. );
  12877. foreach ( $item as $va ) {
  12878. $falg = true;
  12879. foreach ( $receiptCollectList as $v ) {
  12880. if ($v ['itemCategory'] == '其他') {
  12881. if ($v ['item'] == $va) {
  12882. if ($va == '公关费')
  12883. $t1 += $v ['price'];
  12884. if ($va == '广告费')
  12885. $t2 += $v ['price'];
  12886. if ($va == '借款')
  12887. $t3 += $v ['price'];
  12888. if ($va == '可自加费用')
  12889. $t4 += $v ['price'];
  12890. $psum += $v ['price'];
  12891. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12892. $falg = false;
  12893. break;
  12894. }
  12895. }
  12896. }
  12897. if ($falg)
  12898. $html .= '<td class="taR">-</td>';
  12899. }
  12900. $t5 += $psum;
  12901. if (! empty ( $psum ))
  12902. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12903. else
  12904. $psum = '<td class="colGreen taR">-</td>';
  12905. $receiptL ['其他'] = $psum . $html;
  12906. /* ------------------------------------- */
  12907. $html = "";
  12908. $psum = 0;
  12909. foreach ( $receiptCollectList as $v ) {
  12910. if ($v ['itemCategory'] == '报销金额调整') {
  12911. if (! empty ( $v ['price'] )) {
  12912. $psum += $v ['price'];
  12913. }
  12914. }
  12915. }
  12916. $s1 += $psum;
  12917. if (! empty ( $psum ))
  12918. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12919. else
  12920. $psum = '<td class="taR colOrange">-</td>';
  12921. $receiptL ['报销金额调整'] = $psum . $html;
  12922. } else {
  12923. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12924. <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>';
  12925. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12926. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12927. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12928. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12929. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12930. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12931. }
  12932. $monthStaffPrice = $receiptDetail->find ( array (
  12933. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12934. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12935. 'asArray' => true
  12936. ) );
  12937. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12938. $m1 += $monthStaffPrice [0] ['price'];
  12939. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12940. } else
  12941. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12942. $list [$value ['username']] = $receiptL;
  12943. }
  12944. }
  12945. $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>
  12946. <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>
  12947. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12948. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12949. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12950. $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>
  12951. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12952. $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>';
  12953. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12954. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12955. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12956. }
  12957. $data ['list'] = $list;
  12958. $receiptCollectList = $receiptDetail->find ( array (
  12959. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12960. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12961. 'groupby' => 'item,Month(date),itemCategory',
  12962. 'asArray' => true
  12963. ) );
  12964. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12965. // statistics html
  12966. $stList = $statistics->getOne ( array (
  12967. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12968. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12969. 'groupby' => 'Month(date)',
  12970. 'asArray' => true
  12971. ) );
  12972. if (empty ( $stList ))
  12973. $stList = array (
  12974. 'rePrice' => 0,
  12975. 'agPrice' => 0
  12976. );
  12977. $data ['stList'] = array (
  12978. 'rePrice' => $stList ['rePrice'],
  12979. 'agPrice' => $stList ['agPrice'],
  12980. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12981. );
  12982. $monthHtml = "";
  12983. for($i = 1; $i <= 12; $i ++) {
  12984. if ($i == $month)
  12985. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12986. else
  12987. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12988. }
  12989. $data ['monthHtml'] = $monthHtml;
  12990. $data ['year'] = $year;
  12991. $data ['month'] = $month;
  12992. $data ['memu'] = "receipt";
  12993. $data ['staff'] = $this->staff;
  12994. $data ['receiptMemu'] = 'companyCategoryCollect';
  12995. $data ['verifyId'] = $this->verifyId;
  12996. $data ['executeId'] = $this->executeId;
  12997. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12998. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12999. }
  13000. /**
  13001. * 用户报销单列表
  13002. */
  13003. function receiptStatisticsStaffDetail() {
  13004. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13005. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13006. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13007. Doo::loadModel ( "receipt" );
  13008. $receipt = new receipt ();
  13009. Doo::loadModel ( "receiptDetail" );
  13010. $receiptDetail = new receiptDetail ();
  13011. Doo::loadModel ( 'staff' );
  13012. $staff = new staff ();
  13013. Doo::loadModel ( 'accountItem' );
  13014. $accountItem = new accountItem ();
  13015. Doo::loadModel ( 'statistics' );
  13016. $statistics = new statistics ();
  13017. if (! empty ( $username )) {
  13018. $username = addslashes ( urldecode ( $username ) );
  13019. $staffDetail = $staff->getStaffByName ( $username );
  13020. if (empty ( $staffDetail ))
  13021. die ( 'illegal request' );
  13022. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13023. $itemList = $accountItem->getAccountItem ();
  13024. $itemHtml = '';
  13025. $categoryHtml = '';
  13026. $itemKeyList = array_keys ( $itemList );
  13027. $revisePrice = 0;
  13028. // 报销单内容详情
  13029. foreach ( $list as $key => $value ) {
  13030. $accountItemList = json_decode ( $value ['accountItem'], true );
  13031. $list [$key] ['accountItemList'] = $accountItemList;
  13032. $receiptItemHtml = '';
  13033. foreach ( $itemKeyList as $v ) {
  13034. if ($v == '日常相关费用')
  13035. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13036. elseif ($v == '差旅相关费用')
  13037. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13038. elseif ($v == '培训班费用')
  13039. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13040. elseif ($v == '内部培训费用'){
  13041. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13042. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13043. }else{
  13044. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13045. }
  13046. }elseif ($v == '其他')
  13047. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13048. foreach ( $itemList [$v] as $ke => $va ) {
  13049. $falg = true;
  13050. if (! empty ( $accountItemList [$v] )) {
  13051. foreach ( $accountItemList [$v] as $ve ) {
  13052. if ($va ['name'] == $ve ['name']) {
  13053. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13054. $falg = false;
  13055. break;
  13056. }
  13057. }
  13058. }
  13059. if ($falg)
  13060. $receiptItemHtml .= '<td class="taR"></td>';
  13061. }
  13062. }
  13063. // 金额调整和费用查看
  13064. $revisePrice += $value ['revisePrice'];
  13065. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13066. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13067. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13068. }
  13069. // 报销单合计
  13070. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13071. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13072. $receiptTotalHtml = '';
  13073. // 报销单项目抬头
  13074. foreach ( $itemKeyList as $value ) {
  13075. $count = count ( $itemList [$value] ) + 1;
  13076. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13077. $categoryHtml .= '<th class="taC">合计</th>';
  13078. $sumfalg=true;
  13079. foreach ( $rtl as $rtlValue ) {
  13080. if ($rtlValue ['itemCategory'] == $value) {
  13081. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13082. $sumfalg=false;
  13083. break;
  13084. }
  13085. }
  13086. if ($sumfalg)
  13087. $receiptTotalHtml .= '<th></th>';
  13088. foreach ( $itemList [$value] as $k => $v ) {
  13089. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13090. // 合计
  13091. $falg = true;
  13092. foreach ( $receiptTotalList as $ve ) {
  13093. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13094. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13095. $falg = false;
  13096. break;
  13097. }
  13098. }
  13099. if ($falg)
  13100. $receiptTotalHtml .= '<th></th>';
  13101. }
  13102. }
  13103. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13104. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13105. if (empty ( $stList ))
  13106. $stList = array (
  13107. 'rePrice' => 0,
  13108. 'agPrice' => 0
  13109. );
  13110. $data ['stList'] = array (
  13111. 'rePrice' => $stList ['rePrice'],
  13112. 'agPrice' => $stList ['agPrice'],
  13113. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13114. );
  13115. $monthHtml = "";
  13116. for($i = 1; $i <= 12; $i ++) {
  13117. if ($i == $month)
  13118. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13119. else
  13120. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13121. }
  13122. $data ['username'] = urlencode ( $username );
  13123. $data ['usernameEN'] = $username;
  13124. $data ['monthHtml'] = $monthHtml;
  13125. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13126. $data ['list'] = $list;
  13127. $data ['categoryHtml'] = $categoryHtml;
  13128. $data ['itemHtml'] = $itemHtml;
  13129. $data ['itemList'] = $itemList;
  13130. $data ['year'] = $year;
  13131. $data ['month'] = $month;
  13132. $data ['memu'] = "receipt";
  13133. $data ['staff'] = $this->staff;
  13134. $data ['receiptMemu'] = 'companyCategoryCollect';
  13135. $data ['verifyId'] = $this->verifyId;
  13136. $data ['executeId'] = $this->executeId;
  13137. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13138. }
  13139. die ( 'illegal request' );
  13140. }
  13141. function companyMonthCollectDetail() {
  13142. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13143. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13144. if (! $year)
  13145. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13146. if (! $month)
  13147. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13148. Doo::loadModel ( 'staff' );
  13149. $staff = new staff ();
  13150. Doo::loadModel ( "receiptDetail" );
  13151. $receiptDetail = new receiptDetail ();
  13152. Doo::loadModel ( 'accountItem' );
  13153. $accountItem = new accountItem ();
  13154. Doo::loadModel ( 'statistics' );
  13155. $statistics = new statistics ();
  13156. Doo::loadModel ( 'L_category' );
  13157. $lCategory = new L_category ();
  13158. $staffList = $staff->find ( array (
  13159. 'where' => 'username!="admin"',
  13160. 'asArray' => true
  13161. ) );
  13162. $categoryList = $lCategory->find ( array (
  13163. 'asArray' => true
  13164. ) );
  13165. $aiList=$accountItem->getAccountItem();
  13166. $list = array ();
  13167. foreach ( $categoryList as $value ) {
  13168. $receiptCollectList = $receiptDetail->find ( array (
  13169. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13170. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13171. 'groupby' => 'item,Month(pastDate),itemCategory',
  13172. 'asArray' => true
  13173. ) );
  13174. if (! empty ( $receiptCollectList )) {
  13175. $receiptL = array (
  13176. '日常相关费用' => array (),
  13177. '差旅相关费用' => array (),
  13178. '内部培训费用' => array (),
  13179. '培训班费用' => array (),
  13180. '其他' => array ()
  13181. );
  13182. $html = "";
  13183. $psum = 0;
  13184. foreach ( $aiList[$this->AGENCY] as $va ) {
  13185. $falg = true;
  13186. foreach ( $receiptCollectList as $v ) {
  13187. if ($v ['itemCategory'] == $this->AGENCY) {
  13188. if ($v ['item'] == $va['name']) {
  13189. $psum += $v ['price'];
  13190. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13191. $falg = false;
  13192. break;
  13193. }
  13194. }
  13195. }
  13196. if ($falg)
  13197. $html .= '<td class="taR">-</td>';
  13198. }
  13199. if (! empty ( $psum ))
  13200. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13201. else
  13202. $psum = '<td class="colGreen taR">-</td>';
  13203. $receiptL [$this->AGENCY] = $psum . $html;
  13204. /* ----------------------------------- */
  13205. $html = "";
  13206. $psum = 0;
  13207. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13208. $falg = true;
  13209. foreach ( $receiptCollectList as $v ) {
  13210. if ($v ['itemCategory'] == $this->TRAVEL) {
  13211. if ($v ['item'] == $va['name']) {
  13212. $psum += $v ['price'];
  13213. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13214. $falg = false;
  13215. break;
  13216. }
  13217. }
  13218. }
  13219. if ($falg)
  13220. $html .= '<td class="taR">-</td>';
  13221. }
  13222. if (! empty ( $psum ))
  13223. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13224. else
  13225. $psum = '<td class="colGreen taR">-</td>';
  13226. $receiptL [$this->TRAVEL] = $psum . $html;
  13227. /* ------------------------------------- */
  13228. $html = "";
  13229. $psum = 0;
  13230. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13231. $falg = true;
  13232. foreach ( $receiptCollectList as $v ) {
  13233. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13234. if ($v ['item'] == $va['name']) {
  13235. $psum += $v ['price'];
  13236. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13237. $falg = false;
  13238. break;
  13239. }
  13240. }
  13241. }
  13242. if ($falg)
  13243. $html .= '<td class="taR">-</td>';
  13244. }
  13245. if (! empty ( $psum ))
  13246. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13247. else
  13248. $psum = '<td class="colGreen taR">-</td>';
  13249. $receiptL [$this->INTTRAIN] = $psum . $html;
  13250. /* ------------------------------------- */
  13251. $html = "";
  13252. $psum = 0;
  13253. foreach ( $aiList[$this->TRAIN] as $va ) {
  13254. $falg = true;
  13255. foreach ( $receiptCollectList as $v ) {
  13256. if ($v ['itemCategory'] == $this->TRAIN) {
  13257. if ($v ['item'] == $va['name']) {
  13258. $psum += $v ['price'];
  13259. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13260. $falg = false;
  13261. break;
  13262. }
  13263. }
  13264. }
  13265. if ($falg)
  13266. $html .= '<td class="taR">-</td>';
  13267. }
  13268. if (! empty ( $psum ))
  13269. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13270. else
  13271. $psum = '<td class="colGreen taR">-</td>';
  13272. $receiptL [$this->TRAIN] = $psum . $html;
  13273. /* ------------------------------------- */
  13274. $html = "";
  13275. $psum = 0;
  13276. foreach ( $aiList[$this->OTHER] as $va ) {
  13277. $falg = true;
  13278. foreach ( $receiptCollectList as $v ) {
  13279. if ($v ['itemCategory'] == $this->OTHER) {
  13280. if ($v ['item'] == $va['name']) {
  13281. $psum += $v ['price'];
  13282. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13283. $falg = false;
  13284. break;
  13285. }
  13286. }
  13287. }
  13288. if ($falg)
  13289. $html .= '<td class="taR">-</td>';
  13290. }
  13291. if (! empty ( $psum ))
  13292. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13293. else
  13294. $psum = '<td class="colGreen taR">-</td>';
  13295. $receiptL [$this->OTHER] = $psum . $html;
  13296. /* ------------------------------------- */
  13297. $html = "";
  13298. $psum = 0;
  13299. foreach ( $receiptCollectList as $v ) {
  13300. if ($v ['itemCategory'] == '报销金额调整') {
  13301. if (! empty ( $v ['price'] ))
  13302. $psum += $v ['price'];
  13303. }
  13304. }
  13305. if (! empty ( $psum ))
  13306. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13307. else
  13308. $psum = '<td class="taR colOrange">-</td>';
  13309. $receiptL ['报销金额调整'] = $psum . $html;
  13310. } else {
  13311. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13312. foreach ( $aiList[$this->AGENCY] as $va ) {
  13313. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13314. }
  13315. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13316. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13317. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13318. }
  13319. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13320. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13321. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13322. }
  13323. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13324. foreach ( $aiList[$this->TRAIN] as $va ) {
  13325. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13326. }
  13327. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13328. foreach ( $aiList[$this->OTHER] as $va ) {
  13329. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13330. }
  13331. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13332. }
  13333. $monthStaffPrice = $receiptDetail->find ( array (
  13334. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13335. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13336. 'asArray' => true
  13337. ) );
  13338. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13339. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13340. else
  13341. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13342. $list [$value ['title']] = $receiptL;
  13343. }
  13344. $data ['list'] = $list;
  13345. $receiptCollectList = $receiptDetail->find ( array (
  13346. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13347. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13348. 'groupby' => 'item,Month(pastDate),itemCategory',
  13349. 'asArray' => true
  13350. ) );
  13351. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13352. //print_r($data['monthPriceHtml']);
  13353. // foreach ($data['monthPriceHtml'] as $value){
  13354. // echo $value;
  13355. // }
  13356. // die;
  13357. // statistics html
  13358. $stList = $statistics->getOne ( array (
  13359. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13360. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13361. 'groupby' => 'Month(date)',
  13362. 'asArray' => true
  13363. ) );
  13364. if (empty ( $stList ))
  13365. $stList = array (
  13366. 'rePrice' => 0,
  13367. 'agPrice' => 0
  13368. );
  13369. $data ['stList'] = array (
  13370. 'rePrice' => $stList ['rePrice'],
  13371. 'agPrice' => $stList ['agPrice'],
  13372. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13373. );
  13374. $monthHtml = "";
  13375. for($i = 1; $i <= 12; $i ++) {
  13376. if ($i == $month)
  13377. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13378. else
  13379. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13380. }
  13381. $data ['aiList'] = $aiList;
  13382. $data ['monthHtml'] = $monthHtml;
  13383. $data ['year'] = $year;
  13384. $data ['month'] = $month;
  13385. $data ['memu'] = "receipt";
  13386. $data ['staff'] = $this->staff;
  13387. $data ['receiptMemu'] = 'companyCategoryCollect';
  13388. $data ['verifyId'] = $this->verifyId;
  13389. $data ['executeId'] = $this->executeId;
  13390. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13391. }
  13392. function staffCollectDetail() {
  13393. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13394. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13395. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13396. if (! $staffname) {
  13397. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13398. $staffname = urldecode ( $staffname );
  13399. }
  13400. Doo::loadModel ( 'staff' );
  13401. $staff = new staff ();
  13402. Doo::loadModel ( "receiptDetail" );
  13403. $receiptDetail = new receiptDetail ();
  13404. Doo::loadModel ( 'accountItem' );
  13405. $accountItem = new accountItem ();
  13406. Doo::loadModel ( 'statistics' );
  13407. $statistics = new statistics ();
  13408. Doo::loadModel ( 'L_category' );
  13409. $lCategory = new L_category ();
  13410. Doo::loadModel ( "receiptAuthorityManage" );
  13411. $receiptAuthorityManage = new receiptAuthorityManage ();
  13412. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13413. $cidList = array ();
  13414. foreach ( $imcStaff as $key => $value ) {
  13415. array_push ( $cidList, $value ['cid'] );
  13416. }
  13417. $cidString = implode ( ',', $cidList );
  13418. $staffList = $staff->find ( array (
  13419. 'where' => ' cid in (' . $cidString . ')',
  13420. 'asArray' => true
  13421. ) );
  13422. $stHtml = '';
  13423. $stTitle = "";
  13424. $staffId = 0;
  13425. $cid = 0;
  13426. $ocid = 0;
  13427. foreach ( $staffList as $value ) {
  13428. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13429. $stTitle = $value ['category'] . '-' . $value ['username'];
  13430. $staffId = $value ['sid'];
  13431. $cid = $value ['cid'];
  13432. $ocid = $value ['cid'];
  13433. if (! empty ( $value ['othercid'] ))
  13434. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13435. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13436. } elseif ($value ['username'] != 'admin')
  13437. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13438. }
  13439. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13440. 'where' => 'cid in(' . $cid . ')',
  13441. 'asArray' => true
  13442. ) );
  13443. if (empty ( $pcid ))
  13444. $pcid = $ocid;
  13445. $data ['ocid'] = $pcid;
  13446. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13447. $this->showCache ( $path );
  13448. //
  13449. $receiptCollectList = $receiptDetail->find ( array (
  13450. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13451. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13452. 'groupby' => 'item,Month(pastDate),itemCategory',
  13453. 'asArray' => true
  13454. ) );
  13455. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13456. // print_r($receiptCollectList);
  13457. $accountList = $accountItem->find ( array (
  13458. 'asArray' => true
  13459. ) );
  13460. // create CollectDetail HTML
  13461. $collectHtml = array ();
  13462. foreach ( $accountList as $key => $value ) {
  13463. $html = "";
  13464. $asum = 0;
  13465. for($i = 1; $i <= 12; $i ++) {
  13466. $falg = true;
  13467. foreach ( $receiptCollectList as $v ) {
  13468. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13469. if ($v ['item'] == '可自加费用') {
  13470. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13471. }
  13472. $asum += $v ['price'];
  13473. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13474. $falg = false;
  13475. break;
  13476. }
  13477. }
  13478. if ($falg)
  13479. $html .= '<td class="taR">-</td>';
  13480. }
  13481. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13482. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13483. }
  13484. $data ['collectHtml'] = $collectHtml;
  13485. // print_r($collectHtml);
  13486. // create Adjustment price html
  13487. $receiptCollectList = $receiptDetail->find ( array (
  13488. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13489. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13490. 'groupby' => 'itemCategory,Month(pastDate)',
  13491. 'asArray' => true
  13492. ) );
  13493. $adjustment = array ();
  13494. $collectArray = array (
  13495. '日常相关费用' => array (),
  13496. '差旅相关费用' => array (),
  13497. '培训班费用' => array (),
  13498. '内部培训费用'=>array(),
  13499. '其他' => array ()
  13500. );
  13501. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13502. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13503. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13504. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13505. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13506. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13507. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13508. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13509. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13510. array_push ( $collectArray ['其他'], $collectHtml );
  13511. $data ['collectArray'] = $collectArray;
  13512. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13513. array_push ( $adjustment, $collectHtml );
  13514. $data ['adjustment'] = $adjustment;
  13515. // total price html
  13516. $collectHtml = "";
  13517. $total = 0;
  13518. for($i = 1; $i <= 12; $i ++) {
  13519. $sumPrice = 0;
  13520. foreach ( $receiptCollectList as $key => $value ) {
  13521. if ($value ['month'] == $i) {
  13522. $sumPrice += $value ['price'];
  13523. }
  13524. }
  13525. if ($sumPrice == 0)
  13526. $collectHtml .= '<td class="taR">-</td>';
  13527. else
  13528. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13529. $total += $sumPrice;
  13530. }
  13531. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13532. // statistics html
  13533. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13534. if (empty ( $stList ))
  13535. $stList = array (
  13536. 'rePrice' => 0,
  13537. 'agPrice' => 0
  13538. );
  13539. $data ['stList'] = array (
  13540. 'rePrice' => $stList ['rePrice'],
  13541. 'agPrice' => $stList ['agPrice'],
  13542. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13543. );
  13544. $data ['totalPrice'] = $collectHtml;
  13545. $data ['totalYear'] = $total;
  13546. $data ['stHtml'] = $stHtml;
  13547. $data ['year'] = $year;
  13548. $data ['stTitle'] = $stTitle;
  13549. $data ['staffname'] = urlencode ( $staffname );
  13550. $data ['memu'] = "receipt";
  13551. $data ['staff'] = $this->staff;
  13552. $data ['receiptMemu'] = 'companyCategoryCollect';
  13553. $data ['verifyId'] = $this->verifyId;
  13554. $data ['executeId'] = $this->executeId;
  13555. if ($year < date ( "Y" )) {
  13556. Doo::loadModel ( 'receipt' );
  13557. $receipt = new receipt ();
  13558. $receiptList = $receipt->find ( array (
  13559. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13560. 'asArray' => true
  13561. ) );
  13562. if (empty ( $receiptList )) { // generated files
  13563. ob_start ();
  13564. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13565. $this->cacheFile ( $path );
  13566. die ();
  13567. }
  13568. }
  13569. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13570. }
  13571. function BUGFLAG() {
  13572. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13573. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13574. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13575. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13576. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13577. if (empty ( $status ))
  13578. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13579. $page_size = 12;
  13580. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13581. $vidList = array ();
  13582. $button = 0;
  13583. Doo::loadModel ( 'verify' );
  13584. $verify = new verify ();
  13585. Doo::loadModel ( 'receipt' );
  13586. $receipt = new receipt ();
  13587. Doo::loadModel ( 'staff' );
  13588. $staff = new staff ();
  13589. Doo::loadModel ( 'L_category' );
  13590. $Lcategory = new L_category ();
  13591. $dateCondition = " and Year(date) =" . $year;
  13592. if (! empty ( $month ))
  13593. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13594. $categoryList = $Lcategory->find ( array (
  13595. 'asArray' => true
  13596. ) );
  13597. $staffList = $staff->find ( array (
  13598. 'where' => 'cid=' . $cid,
  13599. 'asArray' => true
  13600. ) );
  13601. $cateCondition = "";
  13602. $staffCondition = "";
  13603. $approvalCondition = "";
  13604. if (! empty ( $cid ))
  13605. $cateCondition = ' and cid=' . $cid;
  13606. if (! empty ( $sid )) {
  13607. $staffCondition = ' and staff=' . $sid;
  13608. $cateCondition = "";
  13609. }
  13610. $approvalCondition = " and status=" . $status;
  13611. if ($status == 2) {
  13612. // 查找角色审批人
  13613. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13614. }
  13615. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13616. $approvalCondition = ' and status=2 ';
  13617. }
  13618. if ($status == 1) {
  13619. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13620. }
  13621. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13622. $pageinfo ['page'] = array (
  13623. 'previous' => ''
  13624. );
  13625. if ($status == 0) {
  13626. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13627. $receiptList = $receipt->find ( array (
  13628. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13629. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13630. 'desc' => 'rid',
  13631. 'asArray' => true
  13632. ) );
  13633. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13634. } else
  13635. $receiptList = $receipt->find ( array (
  13636. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13637. 'desc' => 'rid',
  13638. 'asArray' => true
  13639. ) );
  13640. $rLRes = $receipt->find ( array (
  13641. '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,
  13642. 'desc' => 'rid',
  13643. 'asArray' => true
  13644. ) );
  13645. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13646. // print_r($pageinfo);
  13647. $Locate = 0;
  13648. foreach ( $receiptList as $key => $value ) {
  13649. $receiptList [$key] ['Locate'] = $Locate;
  13650. $Locate ++;
  13651. $receiptList [$key] ['reviseDetail'] = array ();
  13652. if (! empty ( $value ['reviseDetail'] ))
  13653. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13654. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13655. $categoryDetil = $Lcategory->getOne ( array (
  13656. 'where' => 'cid=' . $value ['cid'],
  13657. 'asArray' => true
  13658. ) );
  13659. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13660. $verifyList = $verify->getOne ( array (
  13661. 'where' => 'vid=' . $value ['verify'],
  13662. 'asArray' => true
  13663. ) );
  13664. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13665. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13666. foreach ( $verifyList as $k => $v ) {
  13667. // init verifyStaff
  13668. $verifyList [$k] ['date'] = "";
  13669. $verifyList [$k] ['opinion'] = "";
  13670. $verifyList [$k] ['status'] = "";
  13671. if (empty ( $verifyStaff )) {
  13672. $verifyList [$k] ['date'] = "";
  13673. $verifyList [$k] ['opinion'] = "";
  13674. if ($v [0] == $this->staff [0] ['sid']) {
  13675. $verifyList [$k] ['status'] = 4;
  13676. $button = 4;
  13677. }
  13678. } else {
  13679. $flag = true;
  13680. foreach ( $verifyStaff as $m => $u ) {
  13681. if ($v [0] == $m) {
  13682. $verifyList [$k] ['date'] = $u ['date'];
  13683. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13684. $verifyList [$k] ['status'] = $u ['status'];
  13685. $flag = false;
  13686. break;
  13687. }
  13688. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13689. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13690. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13691. }
  13692. if ($flag) { // 检测可编辑
  13693. if ($v [0] == $this->staff [0] ['sid']) {
  13694. $verifyList [$k] ['status'] = 4;
  13695. $button = 4;
  13696. }
  13697. }
  13698. }
  13699. }
  13700. $receiptList [$key] ['verifyList'] = $verifyList;
  13701. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13702. 'where' => 'sid=' . $value ['staff'],
  13703. 'asArray' => true
  13704. ) );
  13705. $receiptList [$key] ['button'] = $button;
  13706. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13707. }
  13708. // print_r($receiptList);die;
  13709. // $data['verifyDetail']=$verifyDetail;
  13710. $mothHtml = "";
  13711. for($i = 1; $i <= 12; $i ++) {
  13712. if ($month == $i)
  13713. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13714. else
  13715. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13716. }
  13717. $data ['mothHtml'] = $mothHtml;
  13718. $data ['page'] = $pageinfo;
  13719. $data ['receiptList'] = $receiptList;
  13720. $data ['receiptApprovalCount'] = count ( $rLRes );
  13721. $data ['status'] = $status;
  13722. $data ['year'] = $year;
  13723. $data ['categoryList'] = $categoryList;
  13724. $data ['staffList'] = $staffList;
  13725. $data ['cid'] = $cid;
  13726. $data ['sid'] = $sid;
  13727. // print_r($receiptList);
  13728. $data ['memu'] = "receipt";
  13729. $data ['staff'] = $this->staff;
  13730. $data ['receiptMemu'] = 'approvalExpenses';
  13731. $data ['verifyId'] = $this->verifyId;
  13732. $data ['executeId'] = $this->executeId;
  13733. $this->render ( "/admin/FALG", $data );
  13734. }
  13735. function ajaxGetReceiptOrder() {
  13736. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13737. if (! empty ( $receiptOrder )) {
  13738. Doo::loadModel ( 'receipt' );
  13739. $receipt = new receipt ();
  13740. Doo::loadModel ( 'staff' );
  13741. $staff = new staff ();
  13742. $receiptInfo = $receipt->getOne ( array (
  13743. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13744. 'asArray' => true
  13745. ) );
  13746. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13747. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13748. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13749. </tbody></table><table class="table table table-bordered"><tbody>';
  13750. foreach ( $verifyStaff as $key => $value ) {
  13751. $staffInfo = $staff->getOne ( array (
  13752. 'select' => 'username',
  13753. 'where' => ' sid="' . $key . '"',
  13754. 'asArray' => true
  13755. ) );
  13756. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13757. }
  13758. $html .= '</tbody></table></div></div>';
  13759. echo json_encode ( array (
  13760. 'status' => 1,
  13761. 'receiptHtml' => $html
  13762. ) );
  13763. die ();
  13764. }
  13765. echo json_encode ( array (
  13766. 'status' => 2,
  13767. 'receiptHtml' => ''
  13768. ) );
  13769. die ();
  13770. }
  13771. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13772. if (! empty ( $receiptCollectList )) {
  13773. $receiptL = array (
  13774. '日常相关费用' => array (),
  13775. '差旅相关费用' => array (),
  13776. '内部培训费用'=>array(),
  13777. '培训班费用' => array (),
  13778. '其他' => array ()
  13779. );
  13780. $html = "";
  13781. $psum = 0;
  13782. foreach ( $aiList[$this->AGENCY] as $value ) {
  13783. $falg = true;
  13784. foreach ( $receiptCollectList as $v ) {
  13785. if ($v ['itemCategory'] == '日常相关费用') {
  13786. if ($v ['item'] == $value['name']) {
  13787. $psum += $v ['price'];
  13788. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13789. $falg = false;
  13790. break;
  13791. }
  13792. }
  13793. }
  13794. if ($falg)
  13795. $html .= '<td class="taR">-</td>';
  13796. }
  13797. if (! empty ( $psum ))
  13798. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13799. else
  13800. $psum = '<td class="colGreen taR">-</td>';
  13801. $receiptL ['日常相关费用'] = $psum . $html;
  13802. /* ----------------------------------- */
  13803. $html = "";
  13804. $psum = 0;
  13805. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13806. $falg = true;
  13807. foreach ( $receiptCollectList as $v ) {
  13808. if ($v ['itemCategory'] == '差旅相关费用') {
  13809. if ($v ['item'] == $value['name']) {
  13810. $psum += $v ['price'];
  13811. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13812. $falg = false;
  13813. break;
  13814. }
  13815. }
  13816. }
  13817. if ($falg)
  13818. $html .= '<td class="taR">-</td>';
  13819. }
  13820. if (! empty ( $psum ))
  13821. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13822. else
  13823. $psum = '<td class="colGreen taR">-</td>';
  13824. $receiptL ['差旅相关费用'] = $psum . $html;
  13825. /* ----------------------------------- */
  13826. $html = "";
  13827. $psum = 0;
  13828. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13829. $falg = true;
  13830. foreach ( $receiptCollectList as $v ) {
  13831. if ($v ['itemCategory'] == '内部培训费用') {
  13832. if ($v ['item'] == $value['name']) {
  13833. $psum += $v ['price'];
  13834. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13835. $falg = false;
  13836. break;
  13837. }
  13838. }
  13839. }
  13840. if ($falg)
  13841. $html .= '<td class="taR">-</td>';
  13842. }
  13843. if (! empty ( $psum ))
  13844. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13845. else
  13846. $psum = '<td class="colGreen taR">-</td>';
  13847. $receiptL ['内部培训费用'] = $psum . $html;
  13848. /* ------------------------------------- */
  13849. $html = "";
  13850. $psum = 0;
  13851. foreach ( $aiList[$this->TRAIN] as $value ) {
  13852. $falg = true;
  13853. foreach ( $receiptCollectList as $v ) {
  13854. if ($v ['itemCategory'] == '培训班费用') {
  13855. if ($v ['item'] == $value['name']) {
  13856. $psum += $v ['price'];
  13857. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13858. $falg = false;
  13859. break;
  13860. }
  13861. }
  13862. }
  13863. if ($falg)
  13864. $html .= '<td class="taR">-</td>';
  13865. }
  13866. if (! empty ( $psum ))
  13867. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13868. else
  13869. $psum = '<td class="colGreen taR">-</td>';
  13870. $receiptL ['培训班费用'] = $psum . $html;
  13871. /* ------------------------------------- */
  13872. $html = "";
  13873. $psum = 0;
  13874. foreach ( $aiList[$this->OTHER] as $value ) {
  13875. $falg = true;
  13876. foreach ( $receiptCollectList as $v ) {
  13877. if ($v ['itemCategory'] == '其他') {
  13878. if ($v ['item'] == $value['name']) {
  13879. $psum += $v ['price'];
  13880. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13881. $falg = false;
  13882. break;
  13883. }
  13884. }
  13885. }
  13886. if ($falg)
  13887. $html .= '<td class="taR">-</td>';
  13888. }
  13889. if (! empty ( $psum ))
  13890. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13891. else
  13892. $psum = '<td class="colGreen taR">-</td>';
  13893. $receiptL ['其他'] = $psum . $html;
  13894. /* ------------------------------------- */
  13895. $html = "";
  13896. $psum = 0;
  13897. foreach ( $receiptCollectList as $v ) {
  13898. if ($v ['itemCategory'] == '报销金额调整') {
  13899. if (! empty ( $v ['price'] ))
  13900. $psum += $v ['price'];
  13901. }
  13902. }
  13903. if (! empty ( $psum ))
  13904. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13905. else
  13906. $psum = '<td class="taR colOrange">-</td>';
  13907. $receiptL ['报销金额调整'] = $psum . $html;
  13908. } else {
  13909. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13910. foreach ( $aiList[$this->AGENCY] as $va ) {
  13911. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13912. }
  13913. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13914. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13915. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13916. }
  13917. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13918. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13919. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13920. }
  13921. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13922. foreach ( $aiList[$this->TRAIN] as $va ) {
  13923. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13924. }
  13925. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13926. foreach ( $aiList[$this->OTHER] as $va ) {
  13927. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13928. }
  13929. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13930. }
  13931. return $receiptL;
  13932. }
  13933. function eMail() {
  13934. Doo::loadModel ( 'staff' );
  13935. $staff = new staff ();
  13936. Doo::loadModel ( 'receipt' );
  13937. $receipt = new receipt ();
  13938. Doo::loadModel ( 'L_category' );
  13939. $Lcategory = new L_category ();
  13940. Doo::loadModel ( "verify" );
  13941. $verify = new verify ();
  13942. $staffList = $staff->find ( array (
  13943. 'asArray' => true
  13944. ) );
  13945. foreach ( $staffList as $key => $value ) {
  13946. if ($value ['username'] != 'admin') {
  13947. // 提交人
  13948. $receiptList = $receipt->find ( array (
  13949. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13950. 'asArray' => true
  13951. ) );
  13952. if (! empty ( $receiptList )) {
  13953. $html = '<br><div><style></style>
  13954. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13955. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13956. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13957. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13958. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13959. <tbody><tr>
  13960. <td style="padding: 0 40px;" align="left">
  13961. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13962. </td></tr><tr>
  13963. <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>
  13964. </tr>
  13965. </tbody> </table></td> </tr> <tr><td>
  13966. <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">
  13967. <tbody> <tr><td>
  13968. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13969. 以下报销单完成了审批,等着收款吧:</p>
  13970. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13971. foreach ( $receiptList as $k => $v ) {
  13972. $category = $Lcategory->getOne ( array (
  13973. 'where' => 'cid=' . $v ['cid'],
  13974. 'asArray' => true
  13975. ) );
  13976. $html .= '
  13977. <tr>
  13978. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13979. <td align="left">
  13980. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13981. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13982. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13983. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13984. </tr>';
  13985. }
  13986. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13987. <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>
  13988. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13989. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13990. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13991. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13992. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13993. $receipt = new receipt ();
  13994. $receipt->notice = 1;
  13995. $receipt->update ( array (
  13996. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13997. ) );
  13998. }
  13999. }
  14000. // 审批人
  14001. $verifyList = $verify->find ( array (
  14002. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14003. 'asArray' => true
  14004. ) );
  14005. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14006. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14007. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14008. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14009. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14010. <tbody><tr><td style="padding: 0 40px;" align="left">
  14011. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14012. </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>
  14013. </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">
  14014. <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>
  14015. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14016. foreach ( $verifyList as $k => $v ) {
  14017. $receiptList = $receipt->find ( array (
  14018. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14019. 'asArray' => true
  14020. ) );
  14021. foreach ( $receiptList as $r => $l ) {
  14022. $category = $Lcategory->getOne ( array (
  14023. 'where' => 'cid=' . $l ['cid'],
  14024. 'asArray' => true
  14025. ) );
  14026. $staffDetile = $staff->getOne ( array (
  14027. 'where' => 'sid=' . $l ['staff'],
  14028. 'asArray' => true
  14029. ) );
  14030. $html .= '
  14031. <tr>
  14032. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14033. <td align="left">
  14034. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14035. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14036. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14037. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14038. </tr>';
  14039. }
  14040. }
  14041. $html .= '
  14042. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14043. <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>
  14044. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14045. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14046. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14047. // $receipt=new receipt();
  14048. // $receipt->notice=1;
  14049. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14050. }
  14051. }
  14052. }
  14053. }
  14054. function setWXMsg($rid, $type) {
  14055. Doo::loadModel ( "receipt" );
  14056. $receipt = new receipt ();
  14057. $receiptDetail = $receipt->getOne ( array (
  14058. 'where' => 'rid=' . $rid,
  14059. 'asArray' => true
  14060. ) );
  14061. if (! empty ( $receiptDetail )) {
  14062. Doo::loadModel ( 'staff' );
  14063. $staff = new staff ();
  14064. $staffmsg = $staff->getOne ( array (
  14065. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14066. 'asArray' => TRUE
  14067. ) );
  14068. if (! empty ( $staffmsg ['wxid'] )) {
  14069. require_once (SITE_PATH . '/protected/class/client.php');
  14070. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14071. $user = $staffmsg ['wxid'];
  14072. $receiptName = '';
  14073. $msg = '';
  14074. switch ($receiptDetail ['Rtype']) {
  14075. case 0 :
  14076. $receiptName = '报销';
  14077. break;
  14078. case 1 :
  14079. $receiptName = '借款';
  14080. break;
  14081. case 2 :
  14082. $receiptName = '对公汇款';
  14083. break;
  14084. }
  14085. switch ($type) {
  14086. case 1 :
  14087. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14088. break;
  14089. case 2 :
  14090. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14091. break;
  14092. case 3 :
  14093. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14094. break;
  14095. }
  14096. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14097. }
  14098. }
  14099. }
  14100. // Email发送函数
  14101. function SMail($toemail, $subject, $contents) {
  14102. Doo::loadClass ( 'class.phpmailer' );
  14103. $mail = new PHPMailer ();
  14104. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14105. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14106. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14107. $mail->Password = "cDO1GjtY1seH"; // 密码
  14108. $mail->CharSet = "UTF8";
  14109. $mail->SMTPAuth = true;
  14110. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14111. $mail->Mailer = "smtp";
  14112. $mail->Port = 25;
  14113. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14114. $mail->MsgHTML ( $contents );
  14115. $mail->AddAddress ( $toemail );
  14116. $mail->CharSet = "UTF-8";
  14117. return $mail->Send ();
  14118. }
  14119. function h5Upload() {
  14120. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14121. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14122. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14123. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14124. header ( "HTTP/1.1 500 Internal Server Error" );
  14125. echo "POST exceeded maximum allowed size.";
  14126. exit ( 0 );
  14127. }
  14128. // Settings
  14129. $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)
  14130. $upload_name = "Filedata";
  14131. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14132. $extension_whitelist = array (
  14133. "doc",
  14134. "txt",
  14135. "jpg",
  14136. "gif",
  14137. "png"
  14138. ); // Allowed file extensions
  14139. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14140. // Other variables
  14141. $MAX_FILENAME_LENGTH = 260;
  14142. $file_name = "";
  14143. $file_extension = "";
  14144. $uploadErrors = array (
  14145. 0 => "文件上传成功",
  14146. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14147. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14148. 3 => "上传的文件仅为部分文件",
  14149. 4 => "没有文件上传",
  14150. 6 => "缺少临时文件夹"
  14151. );
  14152. $nk = time ();
  14153. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14154. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14155. echo "文件无法保存.";
  14156. exit ( 0 );
  14157. }
  14158. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14159. echo json_encode ( array (
  14160. 'filename' => $file_name,
  14161. 'id' => $nk
  14162. ) );
  14163. exit ( 0 );
  14164. }
  14165. function swfupload() {
  14166. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14167. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14168. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14169. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14170. header ( "HTTP/1.1 500 Internal Server Error" );
  14171. echo "POST exceeded maximum allowed size.";
  14172. exit ( 0 );
  14173. }
  14174. // Settings
  14175. $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)
  14176. $upload_name = "Filedata";
  14177. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14178. $extension_whitelist = array (
  14179. "doc",
  14180. "txt",
  14181. "jpg",
  14182. "gif",
  14183. "png"
  14184. ); // Allowed file extensions
  14185. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14186. // Other variables
  14187. $MAX_FILENAME_LENGTH = 260;
  14188. $file_name = "";
  14189. $file_extension = "";
  14190. $uploadErrors = array (
  14191. 0 => "文件上传成功",
  14192. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14193. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14194. 3 => "上传的文件仅为部分文件",
  14195. 4 => "没有文件上传",
  14196. 6 => "缺少临时文件夹"
  14197. );
  14198. $nk = time ();
  14199. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14200. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14201. echo "文件无法保存.";
  14202. exit ( 0 );
  14203. }
  14204. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14205. echo json_encode ( array (
  14206. 'filename' => $file_name,
  14207. 'id' => $nk
  14208. ) );
  14209. exit ( 0 );
  14210. }
  14211. function _GetFileEXT($filename) {
  14212. $pics = explode ( '.', $filename );
  14213. $num = count ( $pics );
  14214. return $pics [$num - 1];
  14215. }
  14216. /**
  14217. * 获取get或者POST值
  14218. * @param string $name 属性名称
  14219. * @return fixed 值
  14220. */
  14221. function get_args($name) {
  14222. if (isset ( $_GET [$name] )) {
  14223. if (is_array ( $_GET [$name] ))
  14224. return $_GET [$name];
  14225. else
  14226. return addslashes ( $_GET [$name] );
  14227. } elseif (isset ( $_POST [$name] )) {
  14228. if (is_array ( $_POST [$name] ))
  14229. return $_POST [$name];
  14230. else
  14231. return addslashes ( $_POST [$name] );
  14232. } else
  14233. return false;
  14234. }
  14235. function num_to_rmb($num) {
  14236. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14237. $c2 = "分角元拾佰仟万拾佰仟亿";
  14238. // 精确到分后面就不要了,所以只留两个小数位
  14239. $num = round ( $num, 2 );
  14240. // 将数字转化为整数
  14241. $num = $num * 100;
  14242. if (strlen ( $num ) > 10) {
  14243. return "金额太大,请检查";
  14244. }
  14245. $i = 0;
  14246. $c = "";
  14247. while ( 1 ) {
  14248. if ($i == 0) {
  14249. // 获取最后一位数字
  14250. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14251. } else {
  14252. $n = $num % 10;
  14253. }
  14254. // 每次将最后一位数字转化为中文
  14255. $p1 = substr ( $c1, 3 * $n, 3 );
  14256. $p2 = substr ( $c2, 3 * $i, 3 );
  14257. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14258. $c = $p1 . $p2 . $c;
  14259. } else {
  14260. $c = $p1 . $c;
  14261. }
  14262. $i = $i + 1;
  14263. // 去掉数字最后一位了
  14264. $num = $num / 10;
  14265. // echo $num.'</br>';
  14266. $num = ( int ) $num;
  14267. // $num =floor($num);
  14268. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14269. // echo $num.'</br>';
  14270. // 结束循环
  14271. if ($num == 0) {
  14272. break;
  14273. }
  14274. }
  14275. // echo $c.'</br>';
  14276. $j = 0;
  14277. $slen = strlen ( $c );
  14278. while ( $j < $slen ) {
  14279. // utf8一个汉字相当3个字符
  14280. $m = substr ( $c, $j, 6 );
  14281. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14282. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14283. $left = substr ( $c, 0, $j );
  14284. $right = substr ( $c, $j + 3 );
  14285. $c = $left . $right;
  14286. $j = $j - 3;
  14287. $slen = $slen - 3;
  14288. }
  14289. $j = $j + 3;
  14290. }
  14291. // 这个是为了去掉类似23.0中最后一个“零”字
  14292. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14293. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14294. }
  14295. // 将处理的汉字加上“整”
  14296. if (empty ( $c )) {
  14297. return "零元整";
  14298. } else {
  14299. return $c . "整";
  14300. }
  14301. }
  14302. /**
  14303. * 获得分页数据
  14304. * @param unknown_type $table
  14305. * @param unknown_type $condition
  14306. * @param unknown_type $on_page
  14307. * @param unknown_type $page_size
  14308. */
  14309. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14310. $page_c = "";
  14311. $page ['previous'] = $this->get_previous ( $on_page );
  14312. $page ['on_page'] = $on_page;
  14313. $total_count = $this->get_table_count ( $table, $condition );
  14314. $total = intval ( $total_count / $page_size );
  14315. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14316. $page ['total_data'] = $total_count;
  14317. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14318. $i = 1;
  14319. $page_max = 1;
  14320. $page_width = 3;
  14321. if ($on_page >= $page_width) {
  14322. $page_max = intval ( $on_page / $page_width ) + 1;
  14323. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14324. }
  14325. for(; $i <= $page ['total_page']; $i ++) {
  14326. if ($i == $on_page)
  14327. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14328. else
  14329. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14330. if ($i == ($page_width * $page_max))
  14331. break;
  14332. }
  14333. $page ['page'] = $page_c;
  14334. $page ['lower'] = (-- $on_page) * $page_size;
  14335. return $page;
  14336. }
  14337. /**
  14338. * 获取总页数
  14339. * @param unknown_type $table
  14340. * @param unknown_type $condition
  14341. */
  14342. public function get_table_count($table = "", $condition = "") {
  14343. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14344. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14345. // echo $sql;die;
  14346. $query = Doo::db ()->query ( $sql );
  14347. $result = $query->fetch ();
  14348. return $result ['count'];
  14349. }
  14350. /**
  14351. * 获取上一页
  14352. * @param unknown_type $on_page
  14353. */
  14354. function get_previous($on_page = 1) {
  14355. return $on_page != 0 ? $on_page - 1 : $on_page;
  14356. }
  14357. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14358. // 收入合计
  14359. Doo::loadModel ( 'invoiceTraining' );
  14360. $invoiceTraining = new invoiceTraining ();
  14361. Doo::loadModel ( 'receipt' );
  14362. $receipt = new receipt ();
  14363. $invoiceTrainingDetail = array (
  14364. 'invoiceArriveAmount' => '0.00',
  14365. 'RIAmount' => '0.00',
  14366. 'invoiceTotalAmount' => '0.00',
  14367. 'invoiceCompanyAmount' => '0.00',
  14368. 'invoiceArriveAmountM'=>'0.00',
  14369. 'invoiceCompanyAmountM'=>'0.00'
  14370. );
  14371. if ($invoiceTrainId != 0) {
  14372. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14373. }
  14374. $invoiceArriveAmount = $RIAmount = 0;
  14375. if (! empty ( $invoiceTrainingDetail )) {
  14376. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14377. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14378. }
  14379. // 备用金
  14380. $sum = 0;
  14381. if (! empty ( $trainLoanRid )) {
  14382. $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14383. $sum = $receiptLoanDetailBak ['sum'];
  14384. }
  14385. // 支出项金额详情
  14386. // 项目金额合计
  14387. Doo::loadModel ( 'RItem' );
  14388. $RItem = new RItem ();
  14389. Doo::loadModel ( 'accountItem' );
  14390. $accountItem = new accountItem ();
  14391. // 讲师获得
  14392. Doo::loadModel ( 'RILecturer' );
  14393. $RILecturer = new RILecturer ();
  14394. $RItemList = $RItem->getRItemByRid ($rid );
  14395. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14396. // 支出项金额详情
  14397. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14398. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14399. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14400. return $payment;
  14401. }
  14402. }
  14403. ?>