ReceiptController.php 540 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447
  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. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  1810. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  1811. // 发票信息
  1812. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1813. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1814. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1815. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1816. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1817. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1818. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1819. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  1820. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1821. header ( 'Content-Type:text/html;charset=utf-8' );
  1822. die ( '请填写联行号' );
  1823. }
  1824. Doo::loadModel ( 'execute' );
  1825. $execute = new execute ();
  1826. $executeDetail = $execute->getOne ( array (
  1827. 'where' => 'mold="培训班结算"',
  1828. 'asArray' => true
  1829. ) );
  1830. if (empty ( $executeDetail )) {
  1831. header ( 'Content-Type:text/html;charset=utf-8' );
  1832. die ( '未设置执行人' );
  1833. }
  1834. Doo::loadClass ( 'XDeode' );
  1835. $XDeode = new XDeode ( 5 );
  1836. $cid = $XDeode->decode ( $cid );
  1837. Doo::loadModel ( 'receipt' );
  1838. $receipt = new receipt ();
  1839. Doo::loadModel ( 'receiptTraining' );
  1840. $receiptTraining = new receiptTraining ();
  1841. // 创建费用培训班
  1842. $item = array (
  1843. 'cid' => $this->staff [0] ['cid'],
  1844. 'categoryName' => $this->staff [0] ['category'],
  1845. 'trainName' => $trainName,
  1846. 'trainStartDate' => $trainStartDate,
  1847. 'trainEndDate' => $trainEndDate,
  1848. 'participants' => $participants,
  1849. 'trainAddress' => $trainAddress,
  1850. 'trainRemarks' => $trainRemarks,
  1851. 'creator' => $this->staff [0] ['sid'],
  1852. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1853. );
  1854. $irid = $receiptTraining->addReceiptTraining ( $item );
  1855. // 报销单
  1856. $receipt->status = 5;
  1857. $receipt->trainId = $irid;
  1858. $receipt->Rtype = 3;
  1859. $receipt->staff = $this->staff [0] ['sid'];
  1860. $receipt->cid = $cid;
  1861. $receipt->verify = $verify;
  1862. $receipt->date = date ( "Y-m-d" );
  1863. $receipt->executeCopy = $executeDetail ['staff'];
  1864. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1865. $receipt->remittanceName = $remittanceName;
  1866. $receipt->bankName = $bankName;
  1867. $receipt->bankNumber = $bankNumber;
  1868. $receipt->remittanceBankType = $remittanceBankType;
  1869. if ($remittanceBankType == 1)
  1870. $receipt->coupletNumber = $coupletNumber;
  1871. $rid = $receipt->insert ();
  1872. $XDeode = new XDeode ( 7 );
  1873. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  1874. } else
  1875. die ( 'illegal request' );
  1876. }
  1877. /**
  1878. * 培训班编辑
  1879. */
  1880. function receiptTrainEdi() {
  1881. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1882. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  1883. Doo::loadClass ( 'XDeode' );
  1884. $XDeode = new XDeode ( 7 );
  1885. $rid = $XDeode->decode ( $ridKey );
  1886. if (! is_numeric ( $rid ))
  1887. die ( 'illegal request' );
  1888. Doo::loadModel ( 'receipt' );
  1889. $receipt = new receipt ();
  1890. Doo::loadModel ( 'receiptTraining' );
  1891. $receiptTraining = new receiptTraining ();
  1892. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  1893. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  1894. die ('illegal request--status');
  1895. }
  1896. //如有已入账已收款的发票,自动取消办事处已收款
  1897. // Doo::loadModel ( 'RIExtend' );
  1898. // $RIExtend = new RIExtend ();
  1899. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  1900. // if (!empty($RIExtendList)){
  1901. // foreach ($RIExtendList as $key=>$value){
  1902. // $RIExtend = new RIExtend ();
  1903. // $RIExtend->delete(array (
  1904. // 'where' => 'iid=' . $value['iid'],
  1905. // 'limit' => 1
  1906. // ));
  1907. // }
  1908. // }
  1909. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  1910. // 汇总表合计
  1911. // 收入合计--加入开票合计
  1912. Doo::loadModel ( 'invoiceTraining' );
  1913. $invoiceTraining = new invoiceTraining ();
  1914. $invoiceTrainingDetail = array (
  1915. 'invoiceArriveAmount' => 0,
  1916. 'RIAmount' => 0,
  1917. 'invoiceTotalAmount' => 0,
  1918. 'invoiceCompanyAmount'=>0
  1919. );
  1920. if ($receiptDetail ['invoiceTrainId'] != 0) {
  1921. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  1922. }
  1923. // print_r($invoiceTrainingDetail);
  1924. $invoiceArriveAmount = $RIAmount = 0;
  1925. if (! empty ( $invoiceTrainingDetail )) {
  1926. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  1927. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  1928. }
  1929. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  1930. //print_r($invoiceTrainingDetail);
  1931. // 支出项目
  1932. Doo::loadModel ( 'accountItem' );
  1933. $accountItem = new accountItem ();
  1934. // 项目金额合计
  1935. Doo::loadModel ( 'RItem' );
  1936. $RItem = new RItem ();
  1937. // 讲师获得
  1938. Doo::loadModel ( 'RILecturer' );
  1939. $RILecturer = new RILecturer ();
  1940. $RItemList = $RItem->getRItemByRid ( $rid );
  1941. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  1942. // 支出项金额详情
  1943. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  1944. // print_r($aiData);
  1945. // 利润
  1946. $profit=$invoiceArriveAmount - $aiData ['total'];
  1947. $companyProfit=$profit * 0.6;
  1948. $categoryProfit=$profit * 0.4;
  1949. $data ['profit'] = sprintf("%.2f",$profit);
  1950. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  1951. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  1952. //发票利润
  1953. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  1954. //发票公司利润
  1955. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  1956. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  1957. //办事处利润
  1958. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  1959. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  1960. // print_r($aiData['dataList']);
  1961. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  1962. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  1963. // 备用金
  1964. $sum = 0;
  1965. $data ['receiptLoanDetail'] = array (
  1966. 'sum' => '0.00'
  1967. );
  1968. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  1969. $data ['receiptLoanDetail'] = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  1970. $sum = $data ['receiptLoanDetail'] ['sum'];
  1971. }
  1972. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  1973. $data ['payment'] = sprintf("%.2f",$payment);
  1974. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  1975. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  1976. $data ['aiList'] = $aiData ['dataList'];
  1977. // 占比计算
  1978. if ($invoiceArriveAmount != 0) {
  1979. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  1980. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1981. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  1982. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  1983. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  1984. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  1985. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  1986. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  1987. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  1988. } else {
  1989. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  1990. }
  1991. //发票金额占比计算
  1992. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  1993. //支出
  1994. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1995. //利润
  1996. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1997. //公司利润
  1998. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  1999. //办事处利润
  2000. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2001. //公司收款
  2002. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2003. //备用金
  2004. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2005. //办事处收款
  2006. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2007. //办事处实际支出
  2008. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2009. //付总部款
  2010. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2011. }else{
  2012. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2013. }
  2014. //讲师人数
  2015. Doo::loadModel ( 'RILecturer' );
  2016. $RILecturer = new RILecturer ();
  2017. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2018. $data['lectureCount']=count($RILecturerList);
  2019. // 审批组
  2020. Doo::loadModel ( 'verify' );
  2021. $verify = new verify ();
  2022. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2023. // 办事处
  2024. Doo::loadModel ( 'L_category' );
  2025. $lCategory = new L_category ();
  2026. $data ['category'] = $lCategory->getCategory ();
  2027. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2028. $data ['receiptDetail'] = $receiptDetail;
  2029. $data ['veList'] = $veList;
  2030. $data ['trainEdiType'] = $trainEdiType;
  2031. $data ['ridKey'] = $ridKey;
  2032. $data ['memu'] = "receipt";
  2033. $data ['staff'] = $this->staff;
  2034. $data ['receiptMemu'] = 'saeaBorad';
  2035. $data ['verifyId'] = $this->verifyId;
  2036. $data ['executeId'] = $this->executeId;
  2037. $this->render ( "/receipt/receiptTrainEdi", $data );
  2038. }
  2039. /**
  2040. * 培训班借款编辑
  2041. */
  2042. function receiptTrainLoanEdi() {
  2043. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2044. Doo::loadClass ( 'XDeode' );
  2045. $XDeode = new XDeode ( 7 );
  2046. $rid = $XDeode->decode ( $ridKey );
  2047. if (! is_numeric ( $rid ))
  2048. die ( 'illegal request' );
  2049. Doo::loadModel ( 'receipt' );
  2050. $receipt = new receipt ();
  2051. Doo::loadModel ( 'receiptTraining' );
  2052. $receiptTraining = new receiptTraining ();
  2053. Doo::loadModel ( 'verify' );
  2054. $verify = new verify ();
  2055. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2056. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2057. die ();
  2058. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2059. // 借款详情HTML
  2060. // 获得借款信息
  2061. $receiptLoanHtml = '';
  2062. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2063. $receiptLoanDetail = $receipt->getReceiptByRid ( $receiptDetail ['trainLoanRid'] );
  2064. // 获得某费用单审批信息
  2065. $verifylist = $verify->getVerifyByRid ( $receiptDetail ['trainLoanRid'] );
  2066. Doo::loadClass ( 'receipt.func' );
  2067. $extendHtml = '<p><a class="button" href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $receiptDetail ['trainLoanRidKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  2068. $receiptLoanHtml = _getReceiptLoanHtml ( $receiptLoanDetail, $verifylist, $extendHtml );
  2069. }
  2070. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  2071. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2072. $data ['receiptDetail'] = $receiptDetail;
  2073. $data ['trainEdiType'] = "LOAN";
  2074. $data ['ridKey'] = $ridKey;
  2075. $data ['memu'] = "receipt";
  2076. $data ['staff'] = $this->staff;
  2077. $data ['receiptMemu'] = 'saeaBorad';
  2078. $data ['verifyId'] = $this->verifyId;
  2079. $data ['executeId'] = $this->executeId;
  2080. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  2081. }
  2082. /**
  2083. * 更新培训班结算基本信息
  2084. */
  2085. function receiptTrainInfoEdiDo() {
  2086. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  2087. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  2088. // 培训班信息
  2089. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2090. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2091. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2092. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2093. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2094. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2095. // 发票信息
  2096. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2097. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2098. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2099. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2100. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2101. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2102. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2103. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $participants ) && ! empty ( $trainAddress )) {
  2104. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2105. header ( 'Content-Type:text/html;charset=utf-8' );
  2106. die ( '请填写联行号' );
  2107. }
  2108. Doo::loadClass ( 'XDeode' );
  2109. $XDeode = new XDeode ( 5 );
  2110. $cid = $XDeode->decode ( $cid );
  2111. $rtid = $XDeode->decode ( $rtid );
  2112. $rid = $XDeode->decode ( $rid );
  2113. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  2114. die ( 'illegal request-IdError' );
  2115. }
  2116. Doo::loadModel ( 'receipt' );
  2117. $receipt = new receipt ();
  2118. Doo::loadModel ( 'receiptTraining' );
  2119. $receiptTraining = new receiptTraining ();
  2120. // 更新费用培训班
  2121. $item = array (
  2122. 'rtid' => $rtid,
  2123. 'trainName' => $trainName,
  2124. 'trainStartDate' => $trainStartDate,
  2125. 'trainEndDate' => $trainEndDate,
  2126. 'participants' => $participants,
  2127. 'trainAddress' => $trainAddress,
  2128. 'trainRemarks' => $trainRemarks
  2129. );
  2130. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  2131. // 报销单
  2132. $receipt->rid = $rid;
  2133. $receipt->cid = $cid;
  2134. $receipt->verify = $verify;
  2135. $receipt->remittanceName = $remittanceName;
  2136. $receipt->bankName = $bankName;
  2137. $receipt->bankNumber = $bankNumber;
  2138. $receipt->remittanceBankType = $remittanceBankType;
  2139. if ($remittanceBankType == 1)
  2140. $receipt->coupletNumber = $coupletNumber;
  2141. $receipt->update ();
  2142. $XDeode = new XDeode ( 7 );
  2143. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  2144. } else
  2145. die ( 'illegal request' );
  2146. }
  2147. /**
  2148. * 编辑培训班结算---更新借款
  2149. */
  2150. function receiptTrainLoanEdiDo() {
  2151. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2152. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  2153. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  2154. Doo::loadModel ( 'receipt' );
  2155. $receipt = new receipt ();
  2156. Doo::loadClass ( 'XDeode' );
  2157. $XDeode = new XDeode ( 5 );
  2158. $rid = $XDeode->decode ( $ridKey );
  2159. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2160. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2161. die ( 'illegal request-ridError' );
  2162. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2163. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2164. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2165. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2166. die ( 'illegal request-receiptError' );
  2167. }
  2168. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  2169. die ( 'illegal request-receipLoantError' );
  2170. }
  2171. // 培训班结算挂钩借款
  2172. $receipt = new receipt ();
  2173. $item = array (
  2174. 'rid' => $rid,
  2175. 'trainLoanRid' => $ridLoan
  2176. );
  2177. $receipt->setReceiptByCondition ( $item );
  2178. // 更新借款状态变成已挂钩
  2179. $receipt = new receipt ();
  2180. $item = array (
  2181. 'rid' => $ridLoan,
  2182. 'status' => 10,
  2183. 'statusTrain' => 1
  2184. );
  2185. $receipt->setReceiptByCondition ( $item );
  2186. $XDeode = new XDeode ( 7 );
  2187. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2188. } else
  2189. die ( 'illegal request' );
  2190. }
  2191. /**
  2192. * 编辑培训班结算--移除借款
  2193. */
  2194. function receiptTrainLoanRemoveDo() {
  2195. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  2196. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  2197. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  2198. Doo::loadModel ( 'receipt' );
  2199. $receipt = new receipt ();
  2200. Doo::loadClass ( 'XDeode' );
  2201. $XDeode = new XDeode ( 5 );
  2202. $rid = $XDeode->decode ( $ridKey );
  2203. $ridLoan = $XDeode->decode ( $ridLoanKey );
  2204. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  2205. die ( 'illegal request-ridError' );
  2206. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2207. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  2208. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  2209. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2210. die ( 'illegal request-receiptError' );
  2211. }
  2212. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  2213. die ( 'illegal request-receipLoantError' );
  2214. }
  2215. // 培训班结算挂钩借款
  2216. $receipt = new receipt ();
  2217. $item = array (
  2218. 'rid' => $rid,
  2219. 'trainLoanRid' => 0
  2220. );
  2221. $receipt->setReceiptByCondition ( $item );
  2222. // 更新借款状态变成已挂钩
  2223. $receipt = new receipt ();
  2224. $item = array (
  2225. 'rid' => $ridLoan,
  2226. 'status' => 8,
  2227. 'statusTrain' => 0
  2228. );
  2229. $receipt->setReceiptByCondition ( $item );
  2230. $XDeode = new XDeode ( 7 );
  2231. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  2232. } else
  2233. die ( 'illegal request' );
  2234. }
  2235. /**
  2236. * 编辑培训班结算 ---开票
  2237. */
  2238. function receiptTrainInvoiceEdi() {
  2239. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2240. Doo::loadClass ( 'XDeode' );
  2241. $XDeode = new XDeode ( 7 );
  2242. $rid = $XDeode->decode ( $ridKey );
  2243. if (! is_numeric ( $rid ))
  2244. die ( 'illegal request' );
  2245. Doo::loadModel ( 'receipt' );
  2246. $receipt = new receipt ();
  2247. Doo::loadModel ( 'receiptTraining' );
  2248. $receiptTraining = new receiptTraining ();
  2249. Doo::loadModel ( 'invoice' );
  2250. $invoice = new invoice ();
  2251. Doo::loadModel ( 'invoiceTraining' );
  2252. $invoiceTraining = new invoiceTraining ();
  2253. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2254. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2255. die ();
  2256. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2257. $invoiceList = $invoiceTrainingDetail = array ();
  2258. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2259. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  2260. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2261. }
  2262. //print_r($invoiceList);
  2263. $data ['invoiceList'] = $invoiceList;
  2264. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2265. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2266. $data ['receiptDetail'] = $receiptDetail;
  2267. $data ['trainEdiType'] = "INVOICE";
  2268. $data ['ridKey'] = $ridKey;
  2269. $data ['memu'] = "receipt";
  2270. $data ['staff'] = $this->staff;
  2271. $data ['receiptMemu'] = 'saeaBorad';
  2272. $data ['verifyId'] = $this->verifyId;
  2273. $data ['executeId'] = $this->executeId;
  2274. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  2275. }
  2276. /**
  2277. * 编辑培训班结算---更新开票
  2278. */
  2279. function receiptTrainInvoiceEdiDo() {
  2280. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2281. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  2282. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  2283. Doo::loadModel ( 'receipt' );
  2284. $receipt = new receipt ();
  2285. Doo::loadModel ( 'invoiceTraining' );
  2286. $invoiceTraining = new invoiceTraining ();
  2287. Doo::loadClass ( 'XDeode' );
  2288. $XDeode = new XDeode ( 5 );
  2289. $rid = $XDeode->decode ( $ridKey );
  2290. $itid = $XDeode->decode ( $itidKey );
  2291. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  2292. die ( 'illegal request-idError' );
  2293. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2294. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  2295. // 不合法的数据
  2296. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  2297. die ( 'illegal request-receiptError' );
  2298. }
  2299. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  2300. die ( 'illegal request-receipLoantError' );
  2301. }
  2302. // 培训班结算挂钩借款
  2303. $receipt = new receipt ();
  2304. $item = array (
  2305. 'rid' => $rid,
  2306. 'invoiceTrainId' => $itid
  2307. );
  2308. $receipt->setReceiptByCondition ( $item );
  2309. $invoiceTraining = new invoiceTraining ();
  2310. $item = array (
  2311. 'bindReceipt' => 1,
  2312. 'itid' => $itid
  2313. );
  2314. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2315. $XDeode = new XDeode ( 7 );
  2316. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  2317. } else
  2318. die ( 'illegal request' );
  2319. }
  2320. /**
  2321. * 更新培训班结算 收款和取消收款
  2322. */
  2323. function receiptTrainReceivables() {
  2324. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  2325. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2326. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2327. Doo::loadClass ( 'XDeode' );
  2328. $XDeode = new XDeode ( 5 );
  2329. $rid = $XDeode->decode ( $ridKey );
  2330. $iid = $XDeode->decode ( $iidKey );
  2331. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  2332. die ( 'illegal request-iid' );
  2333. Doo::loadModel ( 'RIExtend' );
  2334. $RIExtend = new RIExtend ();
  2335. if ($doType == 'CONFIRM') {
  2336. $RIExtend->rid = $rid;
  2337. $RIExtend->iid = $iid;
  2338. $RIExtend->RIstatus = 1;
  2339. $RIExtend->insert ();
  2340. echo json_encode ( array (
  2341. 'status' => 1,
  2342. ) );
  2343. die ( );
  2344. } elseif ($doType == 'CANCEL') {
  2345. $RIExtend->delete ( array (
  2346. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  2347. 'limit' => 1
  2348. ) );
  2349. echo json_encode ( array (
  2350. 'status' => 1,
  2351. ) );
  2352. die ( );
  2353. } else {
  2354. echo json_encode ( array (
  2355. 'status' => 2,
  2356. ) );
  2357. die ( );
  2358. }
  2359. }
  2360. /**
  2361. * 移除挂钩的培训班发票
  2362. */
  2363. function receiptTrainReceivablesDelDo() {
  2364. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2365. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  2366. Doo::loadModel ( 'receipt' );
  2367. $receipt = new receipt ();
  2368. Doo::loadModel ( 'RIExtend' );
  2369. $RIExtend = new RIExtend ();
  2370. Doo::loadClass ( 'XDeode' );
  2371. $XDeode = new XDeode ( 5 );
  2372. $rid = $XDeode->decode ( $ridKey );
  2373. $itid = $XDeode->decode ( $itidKey );
  2374. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  2375. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2376. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2377. die ( 'illegal request-status' );
  2378. }
  2379. $receipt = new receipt ();
  2380. $receipt->rid = $rid;
  2381. $receipt->invoiceTrainId = 0;
  2382. $receipt->update ();
  2383. Doo::loadModel ( 'invoiceTraining' );
  2384. $invoiceTraining = new invoiceTraining ();
  2385. $item = array (
  2386. 'bindReceipt' => 0,
  2387. 'itid' => $itid
  2388. );
  2389. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  2390. $RIExtend->delete ( array (
  2391. 'where' => 'rid=' . $rid
  2392. ) );
  2393. $XDeode = new XDeode ( 7 );
  2394. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  2395. } else
  2396. die ( 'illegal request-iid' );
  2397. }
  2398. /**
  2399. * 编辑培训班结算
  2400. */
  2401. function receiptTrainItemEdi() {
  2402. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  2403. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2404. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  2405. Doo::loadClass ( 'XDeode' );
  2406. $XDeode = new XDeode ( 7 );
  2407. $rid = $XDeode->decode ( $ridKey );
  2408. if (! is_numeric ( $rid ))
  2409. die ( 'illegal request' );
  2410. Doo::loadModel ( 'receipt' );
  2411. $receipt = new receipt ();
  2412. Doo::loadModel ( 'receiptTraining' );
  2413. $receiptTraining = new receiptTraining ();
  2414. Doo::loadModel ( 'RItem' );
  2415. $RItem = new RItem ();
  2416. Doo::loadModel ( 'accountItem' );
  2417. $accountItem = new accountItem ();
  2418. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2419. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2420. die ();
  2421. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2422. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  2423. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  2424. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  2425. // if($value['name']=='税款'){
  2426. // unset($aiList[$key]);break;
  2427. // }
  2428. // }
  2429. //print_r($RItemList);
  2430. $data ['name'] = $name;
  2431. $data ['RItemList'] = $RItemList;
  2432. $data ['aiList'] = $aiList;
  2433. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2434. $data ['receiptDetail'] = $receiptDetail;
  2435. $data ['trainEdiType'] = "ITEM";
  2436. $data ['ridKey'] = $ridKey;
  2437. $data ['memu'] = "receipt";
  2438. $data ['staff'] = $this->staff;
  2439. $data ['receiptMemu'] = 'saeaBorad';
  2440. $data ['verifyId'] = $this->verifyId;
  2441. $data ['executeId'] = $this->executeId;
  2442. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  2443. }
  2444. /**
  2445. * 添加支出项 需要修改 费用金额合计
  2446. */
  2447. function receiptTrainItemAddDo() {
  2448. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2449. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  2450. // 支出项信息
  2451. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2452. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  2453. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2454. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  2455. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  2456. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  2457. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  2458. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  2459. Doo::loadClass ( 'XDeode' );
  2460. $XDeode = new XDeode ( 5 );
  2461. Doo::loadModel ( 'RItem' );
  2462. $RItem = new RItem ();
  2463. $rid = $XDeode->decode ( $ridKey );
  2464. $rtid= $XDeode->decode ( $rtidKey );
  2465. if (! is_numeric ( $rid )){
  2466. die ( 'illegal request' );
  2467. }
  2468. Doo::loadModel ( 'receiptDetail' );
  2469. $receiptDetail = new receiptDetail ();
  2470. Doo::loadModel ( 'receipt' );
  2471. $receipt = new receipt ();
  2472. Doo::loadModel ( 'receiptTraining' );
  2473. $receiptTraining = new receiptTraining ();
  2474. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  2475. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  2476. $order = array (
  2477. "\r\n",
  2478. "\n",
  2479. "\r"
  2480. );
  2481. $replace = '<br/>';
  2482. $describe = str_replace ( $order, $replace, $describe );
  2483. $itemData = array (
  2484. 'rid' => $rid,
  2485. 'item' => $item,
  2486. 'price' => $price,
  2487. 'date' => $date,
  2488. 'inputer' => $inputer,
  2489. 'describe' => $describe,
  2490. 'creater' => $this->staff['0']['username'],
  2491. 'createrId' => $this->staff['0']['sid'],
  2492. 'creatDate' => date ( "Y-m-d H:i:s" ),
  2493. 'identifying'=>$identifyingTotal
  2494. );
  2495. if($payType=='company'){
  2496. $itemData += array (
  2497. 'payType' => 1
  2498. );
  2499. }
  2500. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  2501. //更新支出项标识总数
  2502. $itemData = array (
  2503. 'rtid'=>$rtid,
  2504. 'identifyingTotal'=>$identifyingTotal
  2505. );
  2506. $receiptTraining->setReceiptTrainByCondition($itemData);
  2507. $XDeode = new XDeode ( 7 );
  2508. if($payType=='company'){
  2509. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  2510. }else{
  2511. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  2512. }
  2513. } else
  2514. die ( 'illegal request-dataError' );
  2515. }
  2516. /**
  2517. * 培训班结算-讲师
  2518. */
  2519. function receiptTrainLecturerEdi() {
  2520. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2521. Doo::loadClass ( 'XDeode' );
  2522. $XDeode = new XDeode ( 7 );
  2523. $rid = $XDeode->decode ( $ridKey );
  2524. if (! is_numeric ( $rid ))
  2525. die ( 'illegal request' );
  2526. Doo::loadModel ( 'receipt' );
  2527. $receipt = new receipt ();
  2528. Doo::loadModel ( 'receiptTraining' );
  2529. $receiptTraining = new receiptTraining ();
  2530. Doo::loadModel ( 'RILecturer' );
  2531. $RILecturer = new RILecturer ();
  2532. Doo::loadModel ( 'lecturer' );
  2533. $lecturer = new lecturer ();
  2534. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2535. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  2536. die ();
  2537. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2538. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2539. $lecturerList = $lecturer->getLecturerAll ();
  2540. $INSIDEhtml = $OUTSIDEhtml = '';
  2541. foreach ( $lecturerList as $key => $value ) {
  2542. if ($value ['ltype'] == 'INSIDE') {
  2543. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  2544. } elseif ($value ['ltype'] == 'OUTSIDE') {
  2545. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  2546. }
  2547. }
  2548. $data ['INSIDEhtml'] = $INSIDEhtml;
  2549. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  2550. // print_r($RItemList);
  2551. $data ['RILecturerList'] = $RILecturerList;
  2552. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2553. $data ['receiptDetail'] = $receiptDetail;
  2554. $data ['trainEdiType'] = "LECTURER";
  2555. $data ['ridKey'] = $ridKey;
  2556. $data ['memu'] = "receipt";
  2557. $data ['staff'] = $this->staff;
  2558. $data ['receiptMemu'] = 'saeaBorad';
  2559. $data ['verifyId'] = $this->verifyId;
  2560. $data ['executeId'] = $this->executeId;
  2561. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  2562. }
  2563. /**
  2564. * 添加讲师
  2565. */
  2566. function receiptTrainLecturerAddDo() {
  2567. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2568. // 支出项信息
  2569. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  2570. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  2571. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  2572. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  2573. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  2574. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  2575. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  2576. Doo::loadClass ( 'XDeode' );
  2577. $XDeode = new XDeode ( 5 );
  2578. Doo::loadModel ( 'RILecturer' );
  2579. $RILecturer = new RILecturer ();
  2580. $rid = $XDeode->decode ( $ridKey );
  2581. if (! is_numeric ( $rid ))
  2582. die ( 'illegal request' );
  2583. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  2584. die ( 'illegal request-taxationError' );
  2585. $RILecturer->rid = $rid;
  2586. $RILecturer->ltype = $ltype;
  2587. if ($ltype == 'OUTSIDE') {
  2588. if ($taxation == 'TAXATION') {
  2589. $RILecturer->taxation = 1;
  2590. } elseif ($taxation == 'NOTAXATION') {
  2591. $RILecturer->taxation = 0;
  2592. }
  2593. }
  2594. $RILecturer->lecturerName = $lecturerName;
  2595. $RILecturer->schoolDay = $schoolDay;
  2596. $RILecturer->price = $price;
  2597. $RILecturer->fees=$fees;
  2598. $RILecturer->insert ();
  2599. // 添加公司汇总
  2600. // 报销详情
  2601. Doo::loadModel ( 'receiptDetail' );
  2602. $receiptDetail = new receiptDetail ();
  2603. Doo::loadModel ( 'receipt' );
  2604. $receipt = new receipt ();
  2605. // 金额总计
  2606. $price = $price * $schoolDay;
  2607. $rInfo = $receipt->getReceiptByRid ( $rid );
  2608. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2609. if (empty ( $rdInfo )) {
  2610. $receiptDetail = new receiptDetail ();
  2611. $receiptDetail->staff = $rInfo ['staff'];
  2612. $receiptDetail->item = '讲课费';
  2613. $receiptDetail->itemCategory = '培训班费用';
  2614. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  2615. $receiptDetail->date = date ( "Y-m-d" );
  2616. $receiptDetail->cid = $rInfo ['cid'];
  2617. $receiptDetail->rid = $rid;
  2618. $receiptDetail->status = 4;
  2619. $receiptDetail->insert ();
  2620. } else {
  2621. $receiptDetail = new receiptDetail ();
  2622. $rdInfo ['price'] += $fees;
  2623. $receiptDetail->price = $rdInfo ['price'];
  2624. $receiptDetail->update ( array (
  2625. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2626. ) );
  2627. }
  2628. $receipt = new receipt ();
  2629. $receipt->sum=$rInfo['sum']+$fees;
  2630. $receipt->update ( array (
  2631. 'where' => 'rid=' . $rid
  2632. ) );
  2633. $XDeode = new XDeode ( 7 );
  2634. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2635. } else
  2636. die ( 'illegal request' );
  2637. }
  2638. /**
  2639. * 移除讲师
  2640. */
  2641. function receiptTrainLecturerDelDo() {
  2642. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  2643. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  2644. Doo::loadModel ( 'receipt' );
  2645. $receipt = new receipt ();
  2646. Doo::loadModel ( 'RILecturer' );
  2647. $RILecturer = new RILecturer ();
  2648. Doo::loadClass ( 'XDeode' );
  2649. $XDeode = new XDeode ( 5 );
  2650. $rid = $XDeode->decode ( $ridKey );
  2651. $rlid = $XDeode->decode ( $rlidKey );
  2652. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  2653. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2654. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  2655. die ( 'illegal request-status' );
  2656. }
  2657. $detail=$RILecturer->getRILecturerByRlid($rlid);
  2658. if (empty($detail)){
  2659. die ( 'illegal request-data' );
  2660. }
  2661. $RILecturer->delete ( array (
  2662. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  2663. ) );
  2664. //更新费用合计金额
  2665. $rInfo = $receipt->getReceiptByRid ( $rid );
  2666. $receipt = new receipt ();
  2667. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  2668. $receipt->update ( array (
  2669. 'where' => 'rid=' . $rid
  2670. ) );
  2671. Doo::loadModel ( 'receiptDetail' );
  2672. $receiptDetail = new receiptDetail ();
  2673. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  2674. $receiptDetail = new receiptDetail ();
  2675. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  2676. $receiptDetail->price = $rdInfo ['price'];
  2677. $receiptDetail->update ( array (
  2678. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  2679. ) );
  2680. $XDeode = new XDeode ( 7 );
  2681. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  2682. } else
  2683. die ( 'illegal request-iid' );
  2684. }
  2685. /**
  2686. * 培训班提交审批
  2687. */
  2688. function receiptTrainDo() {
  2689. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  2690. Doo::loadClass ( 'XDeode' );
  2691. $XDeode = new XDeode ( 7 );
  2692. $rid = $XDeode->decode ( $ridKey );
  2693. Doo::loadModel ( 'receipt' );
  2694. $receipt = new receipt ();
  2695. Doo::loadModel ( 'receiptDetail' );
  2696. $receiptDetail = new receiptDetail ();
  2697. Doo::loadModel ( 'statistics' );
  2698. $statistics = new statistics ();
  2699. Doo::loadModel ( "verify" );
  2700. $verify = new verify ();
  2701. // 审批状态的判定
  2702. $receiptDetailList = $receipt->getOne ( array (
  2703. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  2704. 'asArray' => true
  2705. ) );
  2706. if (empty ( $receiptDetailList ))
  2707. return "/saeaBorad";
  2708. $verifyDetail = $verify->getOne ( array (
  2709. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2710. 'asArray' => true
  2711. ) );
  2712. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2713. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2714. $nowStaff = "";
  2715. $nowStaffList = array ();
  2716. if ($verifyDetail [0] [1] == 'ROLE') {
  2717. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2718. foreach ( $vStaffString as $key => $value ) {
  2719. $staffK = explode ( "_", $value );
  2720. array_push ( $nowStaffList, $staffK [0] );
  2721. }
  2722. $nowStaff = implode ( ',', $nowStaffList );
  2723. } else {
  2724. $nowStaff = $verifyDetail [0] [0];
  2725. }
  2726. $receipt->nowStaff = $nowStaff;
  2727. }
  2728. // echo $nowStaff;
  2729. // print_r($verifyDetail);die;
  2730. $receipt->rid = $receiptDetailList ['rid'];
  2731. $receipt->date = date ( "Y-m-d" );
  2732. $receipt->status = 2;
  2733. $receipt->update ();
  2734. $receiptDetail->status = 2;
  2735. $receiptDetail->update ( array (
  2736. 'where' => 'rid=' . $receiptDetailList ['rid']
  2737. ) );
  2738. Doo::loadModel ( "receiptLog" );
  2739. $receiptLog = new receiptLog ();
  2740. Doo::loadModel ( "verify" );
  2741. $verify = new verify ();
  2742. $vr = $verify->getOne ( array (
  2743. 'where' => 'vid=' . $receiptDetailList ['verify'],
  2744. 'asArray' => true
  2745. ) );
  2746. $jd = json_decode ( $vr ['staff'] );
  2747. $roleId = 0;
  2748. foreach ( $jd as $key => $value ) {
  2749. if ($value [1] == 'ROLE') {
  2750. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2751. if ($pos !== false) {
  2752. $roleId = $value [0];
  2753. }
  2754. }
  2755. }
  2756. // 审批日志
  2757. // echo $roleId;die;
  2758. if (! empty ( $roleId )) {
  2759. Doo::loadModel ( "role" );
  2760. $role = new role ();
  2761. $roleInfo = $role->getOne ( array (
  2762. 'where' => 'rid=' . $roleId,
  2763. 'asArray' => true
  2764. ) );
  2765. // $receiptLog->rolename = $roleInfo ['name'];
  2766. }
  2767. $receiptLog->username = $this->staff [0] ['username'];
  2768. $receiptLog->uid = $this->staff [0] ['sid'];
  2769. $receiptLog->date = date ( "Y-m-d" );
  2770. $receiptLog->opinion = '提交审批';
  2771. $receiptLog->img = $this->staff [0] ['avatar'];
  2772. $receiptLog->status = 2;
  2773. $receiptLog->rid = $rid;
  2774. $receiptLog->insert ();
  2775. // 写入列表项
  2776. Doo::loadModel ( 'accountItem' );
  2777. $accountItem = new accountItem ();
  2778. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  2779. // 项目金额合计
  2780. Doo::loadModel ( 'RItem' );
  2781. $RItem = new RItem ();
  2782. // 讲师获得
  2783. Doo::loadModel ( 'RILecturer' );
  2784. $RILecturer = new RILecturer ();
  2785. $RItemList = $RItem->getRItemByRid ( $rid );
  2786. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2787. // 支出项金额详情
  2788. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  2789. // print_r($aItem);
  2790. // print_r($aiData);
  2791. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2792. $ag = $tr = $ta = $ot = 0;
  2793. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  2794. foreach ( $aItem as $key => $value ) {
  2795. if ($value ['category'] == $this->TRAIN) {
  2796. foreach ( $aiData ['dataList'] as $k => $v ) {
  2797. if ($value ['name'] == $v ['name']) {
  2798. array_push ( $accountJson [$this->TRAIN], array (
  2799. 'aid' => $value ['aid'],
  2800. 'name' => $value ['name'],
  2801. 'price' => number_format ( $v ['price'], 2, '.', '' )
  2802. ) );
  2803. $sum += $v ['price'];
  2804. $trainSum += $v ['price'];
  2805. unset ( $aiData ['dataList'] [$k] );
  2806. break;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. $accountJson ['cSum'] = array (
  2812. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2813. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2814. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2815. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2816. );
  2817. // 报销单
  2818. $receipt = new receipt ();
  2819. $receipt->accountItem = json_encode ( $accountJson );
  2820. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2821. $receipt->update ( array (
  2822. 'where' => 'rid=' . $rid
  2823. ) );
  2824. // print_r($accountJson);
  2825. // statistics item 统计写入
  2826. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  2827. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  2828. $accountItem = $accountJson;
  2829. $stat = $statistics->getOne ( array (
  2830. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2831. 'asArray' => true
  2832. ) );
  2833. if (empty ( $stat )) {
  2834. $statistics->date = date ( "Y-m-d" );
  2835. $statistics->cid = $this->staff [0] ['cid'];
  2836. $statistics->staff = $this->staff [0] ['sid'];
  2837. $statistics->agPrice = 0;
  2838. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2839. $statistics->insert ();
  2840. } else {
  2841. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  2842. $statistics->update ( array (
  2843. 'where' => 'sid=' . $stat ['sid']
  2844. ) );
  2845. }
  2846. return "/saeaBorad";
  2847. }
  2848. function confirmation() {
  2849. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2850. Doo::loadModel ( 'receipt' );
  2851. Doo::loadModel ( 'receiptDetail' );
  2852. $receipt = new receipt ();
  2853. $receiptDetail = new receiptDetail ();
  2854. Doo::loadModel ( 'statistics' );
  2855. Doo::loadModel ( 'itemStatistics' );
  2856. $statistics = new statistics ();
  2857. $itemStatistics = new itemStatistics ();
  2858. Doo::loadModel ( "verify" );
  2859. $verify = new verify ();
  2860. $receiptDetailList = $receipt->getOne ( array (
  2861. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  2862. 'asArray' => true
  2863. ) );
  2864. if (empty ( $receiptDetailList ))
  2865. return "/saeaBorad";
  2866. $verifyDetail = $verify->getOne ( array (
  2867. 'where' => ' vid =' . $receiptDetailList ['verify'],
  2868. 'asArray' => true
  2869. ) );
  2870. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  2871. if (empty ( $receiptDetailList ['nowStaff'] )) {
  2872. $nowStaff = "";
  2873. $nowStaffList = array ();
  2874. if ($verifyDetail [0] [1] == 'ROLE') {
  2875. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  2876. foreach ( $vStaffString as $key => $value ) {
  2877. $staffK = explode ( "_", $value );
  2878. array_push ( $nowStaffList, $staffK [0] );
  2879. }
  2880. $nowStaff = implode ( ',', $nowStaffList );
  2881. } else {
  2882. $nowStaff = $verifyDetail [0] [0];
  2883. }
  2884. $receipt->nowStaff = $nowStaff;
  2885. }
  2886. // echo $nowStaff;
  2887. // print_r($verifyDetail);die;
  2888. $receipt->rid = $receiptDetailList ['rid'];
  2889. $receipt->status = 2;
  2890. $receipt->update ();
  2891. // 操作日志
  2892. Doo::loadModel ( "receiptLog" );
  2893. $receiptLog = new receiptLog ();
  2894. $verify = new verify ();
  2895. $receiptInfo = $receipt->getOne ( array (
  2896. 'where' => 'rid=' . $rid,
  2897. 'asArray' => true
  2898. ) );
  2899. $vr = $verify->getOne ( array (
  2900. 'where' => 'vid=' . $receiptInfo ['verify'],
  2901. 'asArray' => true
  2902. ) );
  2903. $jd = json_decode ( $vr ['staff'] );
  2904. $roleId = 0;
  2905. foreach ( $jd as $key => $value ) {
  2906. if ($value [1] == 'ROLE') {
  2907. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  2908. if ($pos !== false) {
  2909. $roleId = $value [0];
  2910. }
  2911. }
  2912. }
  2913. // 审批日志
  2914. // echo $roleId;die;
  2915. if (! empty ( $roleId )) {
  2916. Doo::loadModel ( "role" );
  2917. $role = new role ();
  2918. $roleInfo = $role->getOne ( array (
  2919. 'where' => 'rid=' . $roleId,
  2920. 'asArray' => true
  2921. ) );
  2922. // $receiptLog->rolename = $roleInfo ['name'];
  2923. }
  2924. $receiptLog->username = $this->staff [0] ['username'];
  2925. $receiptLog->uid = $this->staff [0] ['sid'];
  2926. $receiptLog->date = date ( "Y-m-d" );
  2927. $receiptLog->opinion = '提交审批';
  2928. $receiptLog->img = $this->staff [0] ['avatar'];
  2929. $receiptLog->status = 2;
  2930. $receiptLog->rid = $rid;
  2931. $receiptLog->insert ();
  2932. return "/expenses";
  2933. }
  2934. function expenses() {
  2935. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  2936. if (empty ( $item ))
  2937. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  2938. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2939. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  2940. Doo::loadClass ( 'XDeode' );
  2941. $XDeode = new XDeode ( 7 );
  2942. Doo::loadModel ( 'receipt' );
  2943. $receipt = new receipt ();
  2944. Doo::loadModel ( 'L_category' );
  2945. $Lcategory = new L_category ();
  2946. Doo::loadModel ( 'verify' );
  2947. Doo::loadModel ( 'statistics' );
  2948. $statistics = new statistics ();
  2949. $verify = new verify ();
  2950. Doo::loadModel ( 'staff' );
  2951. $staff = new staff ();
  2952. $condition = "";
  2953. if ($item == "expenses")
  2954. $condition = " and Rtype=1 ";
  2955. elseif ($item == "receipts")
  2956. $condition = " and Rtype=0 ";
  2957. elseif ($item == "remits")
  2958. $condition = " and Rtype=2 ";
  2959. elseif ($item == "train")
  2960. $condition = " and Rtype=3 ";
  2961. $dateCondition = " and Year(date) =" . $year;
  2962. if (! empty ( $moth )) {
  2963. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  2964. $stList = $statistics->getOne ( array (
  2965. 'select' => 'rePrice ,agPrice',
  2966. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  2967. 'asArray' => true
  2968. ) );
  2969. } else
  2970. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  2971. if (empty ( $stList ))
  2972. $stList = array (
  2973. 'rePrice' => 0,
  2974. 'agPrice' => 0
  2975. );
  2976. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  2977. if (! isset ( $noPassSum ['sum'] ))
  2978. $noPassSum ['sum'] = 0;
  2979. $data ['stList'] = array (
  2980. 'rePrice' => $stList ['rePrice'],
  2981. 'agPrice' => $stList ['agPrice'],
  2982. 'skPrice' => ($noPassSum ['sum'])
  2983. );
  2984. $receiptList = $receipt->find ( array (
  2985. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  2986. 'desc' => 'rid',
  2987. 'asArray' => true
  2988. ) );
  2989. $Locate = 0;
  2990. $roleId = 0;
  2991. $button = 0;
  2992. foreach ( $receiptList as $key => $value ) {
  2993. $receiptList[$key]['balance']='';
  2994. if($value['Rtype']==1){
  2995. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  2996. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  2997. }elseif($value['Rtype']==3){
  2998. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  2999. $receiptList[$key]['payment']=$payment;
  3000. $receiptList[$key]['paymentABS']=abs($payment);
  3001. }
  3002. $receiptList [$key] ['Locate'] = $Locate;
  3003. $Locate ++;
  3004. $receiptList [$key] ['reviseDetail'] = array ();
  3005. if (! empty ( $value ['reviseDetail'] ))
  3006. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3007. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3008. $categoryDetil = $Lcategory->getOne ( array (
  3009. 'where' => 'cid=' . $value ['cid'],
  3010. 'asArray' => true
  3011. ) );
  3012. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3013. // 检测编辑状态
  3014. $verifyList = $verify->getOne ( array (
  3015. 'where' => 'vid=' . $value ['verify'],
  3016. 'asArray' => true
  3017. ) );
  3018. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3019. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3020. Doo::loadModel ( 'role' );
  3021. $role = new role ();
  3022. $flag = true;
  3023. $roleKey = 0;
  3024. $endStaffArray = array ();
  3025. $roleArrayCopy = array ();
  3026. foreach ( $verifyList as $k => $v ) {
  3027. // init verifyStaff
  3028. if ($v [1] == 'ROLE') {
  3029. if (! empty ( $verifyStaff )) {
  3030. $endStaffArray = end ( $verifyStaff );
  3031. // if ($v[0]==$endStaffArray['nextStaff']){
  3032. // $roleId=$v[0];
  3033. // }
  3034. }
  3035. $roleVerify = json_decode ( $v [3], true );
  3036. $roleKey = $k;
  3037. $roleArray = array ();
  3038. $rolename = $role->getOne ( array (
  3039. 'where' => 'rid=' . $v [0],
  3040. 'asArray' => true
  3041. ) );
  3042. foreach ( $roleVerify as $o => $p ) {
  3043. $staffID = explode ( '_', $p );
  3044. $staffInfo = $staff->getOne ( array (
  3045. 'where' => 'sid=' . $staffID [0],
  3046. 'asArray' => true
  3047. ) );
  3048. // print_r($staffID);
  3049. $exp = array (
  3050. 0 => $staffInfo ['sid'],
  3051. 1 => $staffID [1],
  3052. 2 => $staffInfo ['avatar'],
  3053. 'date' => '',
  3054. 'date' => '',
  3055. 'opinion' => '',
  3056. 'status' => '',
  3057. 'rolename' => $rolename ['name']
  3058. );
  3059. array_push ( $roleArray, $exp );
  3060. }
  3061. $roleArrayCopy [$v [0]] = $roleArray;
  3062. // $verifyList[$k]['roleArray']=$roleArray;
  3063. }
  3064. $verifyList [$k] ['date'] = "";
  3065. $verifyList [$k] ['opinion'] = "";
  3066. $verifyList [$k] ['status'] = "";
  3067. if (empty ( $verifyStaff )) {
  3068. $verifyList [$k] ['date'] = "";
  3069. $verifyList [$k] ['opinion'] = "";
  3070. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3071. $verifyList [$k] ['status'] = 4;
  3072. $flag = false;
  3073. }
  3074. } else {
  3075. foreach ( $verifyStaff as $m => $u ) {
  3076. if ($v [0] == $m) {
  3077. $verifyList [$k] ['date'] = $u ['date'];
  3078. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3079. $verifyList [$k] ['status'] = $u ['status'];
  3080. $flag = false;
  3081. break;
  3082. }
  3083. }
  3084. $endStaffArray = end ( $verifyStaff );
  3085. if (isset ( $endStaffArray ['ROLE'] )) {
  3086. } else {
  3087. // $endKey=key($verifyStaff);
  3088. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3089. // $button=4;
  3090. // $verifyList[$k]['status']=4;
  3091. // }
  3092. }
  3093. }
  3094. }
  3095. $rolename ['name'] = '';
  3096. if (! empty ( $roleId )) {
  3097. Doo::loadModel ( 'role' );
  3098. $role = new role ();
  3099. $rolename = $role->getOne ( array (
  3100. 'where' => 'rid=' . $roleId,
  3101. 'asArray' => true
  3102. ) );
  3103. }
  3104. if (! empty ( $verifyStaff ))
  3105. $endStaffArray = end ( $verifyStaff );
  3106. $KOP = false;
  3107. foreach ( $roleArrayCopy as $P => $A ) {
  3108. foreach ( $A as $MKI => $AVL ) {
  3109. if (! empty ( $verifyStaff )) {
  3110. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3111. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3112. $button = 4;
  3113. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3114. }
  3115. foreach ( $verifyStaff as $m => $u ) {
  3116. $AVLFK = $AVL [0] . '_R';
  3117. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3118. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3119. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3120. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3121. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3122. break;
  3123. }
  3124. }
  3125. } else {
  3126. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3127. $button = 4;
  3128. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3129. }
  3130. }
  3131. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3132. $KOP = true;
  3133. }
  3134. }
  3135. foreach ( $roleArrayCopy as $k => $v ) {
  3136. foreach ( $verifyList as $m => $n ) {
  3137. if ($n [0] == $k) {
  3138. array_splice ( $verifyList, $m, 1, $v );
  3139. }
  3140. }
  3141. }
  3142. $receiptList [$key] ['verifyList'] = $verifyList;
  3143. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3144. 'where' => 'sid=' . $value ['staff'],
  3145. 'asArray' => true
  3146. ) );
  3147. $receiptList [$key] ['button'] = $button;
  3148. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  3149. }
  3150. // print_r($receiptList);die;
  3151. $mothHtml = "";
  3152. for($i = 1; $i <= 12; $i ++) {
  3153. if ($moth == $i)
  3154. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  3155. else
  3156. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  3157. }
  3158. $dateHtml = "";
  3159. $now = date ( "Y" );
  3160. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3161. if ($YEARD <= $now) {
  3162. $dateHtml .= '<option ';
  3163. if ($year == $YEARD) {
  3164. $dateHtml .= 'selected ';
  3165. }
  3166. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3167. }
  3168. }
  3169. $data ['dateHtml'] = $dateHtml;
  3170. $data ['mothHtml'] = $mothHtml;
  3171. $data ['receiptList'] = $receiptList;
  3172. $data ['memu'] = "receipt";
  3173. $data ['staff'] = $this->staff;
  3174. $data ['receiptMemu'] = 'expenses';
  3175. $data ['verifyId'] = $this->verifyId;
  3176. $data ['executeId'] = $this->executeId;
  3177. $data ['item'] = $item;
  3178. $data ['year'] = $year;
  3179. $this->render ( "/admin/expenses", $data );
  3180. }
  3181. function expensesCollect() {
  3182. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3183. Doo::loadModel ( 'receipt' );
  3184. $receipt = new receipt ();
  3185. Doo::loadModel ( 'L_category' );
  3186. $Lcategory = new L_category ();
  3187. Doo::loadModel ( 'verify' );
  3188. Doo::loadModel ( 'statistics' );
  3189. $statistics = new statistics ();
  3190. $verify = new verify ();
  3191. Doo::loadModel ( 'staff' );
  3192. $staff = new staff ();
  3193. Doo::loadModel ( 'loanReceipt' );
  3194. $loanReceipt = new loanReceipt ();
  3195. $receiptList = $receipt->find ( array (//去掉
  3196. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  3197. 'desc' => 'rid',
  3198. 'asArray' => true
  3199. ) );
  3200. $loanList = $loanReceipt->find ( array (
  3201. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3202. 'desc' => 'rid',
  3203. 'asArray' => true
  3204. ) );
  3205. /*
  3206. * $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;
  3207. */
  3208. $data ['explanation'] = '';
  3209. if (! empty ( $loanList ))
  3210. $data ['explanation'] = $loanList [0] ['explanation'];
  3211. $Locate = 0;
  3212. $roleId = 0;
  3213. $button = 0;
  3214. foreach ( $receiptList as $key => $value ) {
  3215. $receiptList [$key] ['Locate'] = $Locate;
  3216. $Locate ++;
  3217. $receiptList [$key] ['reviseDetail'] = array ();
  3218. if (! empty ( $value ['reviseDetail'] ))
  3219. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3220. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3221. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3222. $categoryDetil = $Lcategory->getOne ( array (
  3223. 'where' => 'cid=' . $value ['cid'],
  3224. 'asArray' => true
  3225. ) );
  3226. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3227. // 检测编辑状态
  3228. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  3229. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  3230. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  3231. else
  3232. $verifyList ['staff'] = $value ['verifyBreakup'];
  3233. } else
  3234. $verifyList = $verify->getOne ( array (
  3235. 'where' => 'vid=' . $value ['verify'],
  3236. 'asArray' => true
  3237. ) );
  3238. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3239. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3240. Doo::loadModel ( 'role' );
  3241. $role = new role ();
  3242. $flag = true;
  3243. $roleKey = 0;
  3244. $endStaffArray = array ();
  3245. $roleArrayCopy = array ();
  3246. foreach ( $verifyList as $k => $v ) {
  3247. // init verifyStaff
  3248. if ($v [1] == 'ROLE') {
  3249. if (! empty ( $verifyStaff )) {
  3250. $endStaffArray = end ( $verifyStaff );
  3251. // if ($v[0]==$endStaffArray['nextStaff']){
  3252. // $roleId=$v[0];
  3253. // }
  3254. }
  3255. $roleVerify = json_decode ( $v [3], true );
  3256. $roleKey = $k;
  3257. $roleArray = array ();
  3258. $rolename = $role->getOne ( array (
  3259. 'where' => 'rid=' . $v [0],
  3260. 'asArray' => true
  3261. ) );
  3262. foreach ( $roleVerify as $o => $p ) {
  3263. $staffID = explode ( '_', $p );
  3264. $staffInfo = $staff->getOne ( array (
  3265. 'where' => 'sid=' . $staffID [0],
  3266. 'asArray' => true
  3267. ) );
  3268. // print_r($staffID);
  3269. $exp = array (
  3270. 0 => $staffInfo ['sid'],
  3271. 1 => $staffID [1],
  3272. 2 => $staffInfo ['avatar'],
  3273. 'date' => '',
  3274. 'date' => '',
  3275. 'opinion' => '',
  3276. 'status' => '',
  3277. 'rolename' => $rolename ['name']
  3278. );
  3279. array_push ( $roleArray, $exp );
  3280. }
  3281. $roleArrayCopy [$v [0]] = $roleArray;
  3282. // $verifyList[$k]['roleArray']=$roleArray;
  3283. }
  3284. $verifyList [$k] ['date'] = "";
  3285. $verifyList [$k] ['opinion'] = "";
  3286. $verifyList [$k] ['status'] = "";
  3287. if (empty ( $verifyStaff )) {
  3288. $verifyList [$k] ['date'] = "";
  3289. $verifyList [$k] ['opinion'] = "";
  3290. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3291. $verifyList [$k] ['status'] = 4;
  3292. $flag = false;
  3293. }
  3294. } else {
  3295. foreach ( $verifyStaff as $m => $u ) {
  3296. if ($v [0] == $m) {
  3297. $verifyList [$k] ['date'] = $u ['date'];
  3298. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3299. $verifyList [$k] ['status'] = $u ['status'];
  3300. $flag = false;
  3301. break;
  3302. }
  3303. }
  3304. $endStaffArray = end ( $verifyStaff );
  3305. if (isset ( $endStaffArray ['ROLE'] )) {
  3306. } else {
  3307. // $endKey=key($verifyStaff);
  3308. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3309. // $button=4;
  3310. // $verifyList[$k]['status']=4;
  3311. // }
  3312. }
  3313. }
  3314. }
  3315. $rolename ['name'] = '';
  3316. if (! empty ( $roleId )) {
  3317. Doo::loadModel ( 'role' );
  3318. $role = new role ();
  3319. $rolename = $role->getOne ( array (
  3320. 'where' => 'rid=' . $roleId,
  3321. 'asArray' => true
  3322. ) );
  3323. }
  3324. if (! empty ( $verifyStaff ))
  3325. $endStaffArray = end ( $verifyStaff );
  3326. $KOP = false;
  3327. foreach ( $roleArrayCopy as $P => $A ) {
  3328. foreach ( $A as $MKI => $AVL ) {
  3329. if (! empty ( $verifyStaff )) {
  3330. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3331. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3332. $button = 4;
  3333. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3334. }
  3335. foreach ( $verifyStaff as $m => $u ) {
  3336. $AVLFK = $AVL [0] . '_R';
  3337. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3338. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3339. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3340. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3341. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3342. break;
  3343. }
  3344. }
  3345. } else {
  3346. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3347. $button = 4;
  3348. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3349. }
  3350. }
  3351. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3352. $KOP = true;
  3353. }
  3354. }
  3355. foreach ( $roleArrayCopy as $k => $v ) {
  3356. foreach ( $verifyList as $m => $n ) {
  3357. if ($n [0] == $k) {
  3358. array_splice ( $verifyList, $m, 1, $v );
  3359. }
  3360. }
  3361. }
  3362. // 费用执行人相关数据
  3363. $executeCopy = json_decode ( $value ['executeCopy'], true );
  3364. $executeStaff = json_decode ( $value ['executeStaff'], true );
  3365. foreach ( $executeCopy as $k => $v ) {
  3366. $executeCopy [$k] ['date'] = '';
  3367. $executeCopy [$k] ['opinion'] = '';
  3368. $executeCopy [$k] ['status'] = '';
  3369. if (! empty ( $executeStaff ))
  3370. foreach ( $executeStaff as $m => $u ) {
  3371. if ($v [0] == $m) {
  3372. $executeCopy [$k] ['date'] = $u ['date'];
  3373. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  3374. $executeCopy [$k] ['status'] = $u ['status'];
  3375. break;
  3376. }
  3377. }
  3378. }
  3379. $receiptList [$key] ['executeCopy'] = $executeCopy;
  3380. $receiptList [$key] ['verifyList'] = $verifyList;
  3381. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3382. 'where' => 'sid=' . $value ['staff'],
  3383. 'asArray' => true
  3384. ) );
  3385. $receiptList [$key] ['button'] = $button;
  3386. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  3387. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  3388. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  3389. $receiptList [$key] ['relust'] = $relust;
  3390. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  3391. }
  3392. Doo::loadModel ( 'enclosur' );
  3393. $enclosur = new enclosur ();
  3394. $enclosurList = $enclosur->find ( array (
  3395. 'where' => 'rid=' . $rid,
  3396. 'asArray' => true
  3397. ) );
  3398. $enclosurHtml = '';
  3399. foreach ( $enclosurList as $value ) {
  3400. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  3401. }
  3402. $data ['enclosurHtml'] = $enclosurHtml;
  3403. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  3404. $data ['receiptList'] = $receiptList;
  3405. $data ['memu'] = "receipt";
  3406. $data ['staff'] = $this->staff;
  3407. $data ['receiptMemu'] = 'expenses';
  3408. $data ['verifyId'] = $this->verifyId;
  3409. $data ['executeId'] = $this->executeId;
  3410. $this->render ( "/admin/expensesCollect", $data );
  3411. }
  3412. function approvalExpenses() {
  3413. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  3414. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  3415. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  3416. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3417. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  3418. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  3419. // echo $rdate;
  3420. if (empty ( $status ))
  3421. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  3422. $page_size = 8;
  3423. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3424. $vidList = array ();
  3425. $button = 0;
  3426. Doo::loadModel ( 'verify' );
  3427. $verify = new verify ();
  3428. Doo::loadModel ( 'receipt' );
  3429. $receipt = new receipt ();
  3430. Doo::loadModel ( 'staff' );
  3431. $staff = new staff ();
  3432. Doo::loadModel ( 'L_category' );
  3433. $Lcategory = new L_category ();
  3434. // user verify ID
  3435. $verifyDetail = $verify->find ( array (
  3436. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  3437. 'asArray' => true
  3438. ) );
  3439. foreach ( $verifyDetail as $key => $value ) {
  3440. array_push ( $vidList, $value ['vid'] );
  3441. }
  3442. $vid = implode ( ",", $vidList );
  3443. if (empty ( $verifyDetail ))
  3444. $vid = 0;
  3445. // if ($status==0)
  3446. // $dateCondition="";
  3447. // else
  3448. $dateCondition = " ";
  3449. // if (! empty ( $month ))
  3450. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  3451. if ($status == 'done' || $status == 'termination') {
  3452. if (! empty ( $year )) {
  3453. $dateCondition = " and Year(pastDate) =" . $year;
  3454. if (! empty ( $month ))
  3455. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3456. }
  3457. } elseif ($status == 'finish') {
  3458. if (! empty ( $year )) {
  3459. $dateCondition = " and Year(pastDate) =" . $year;
  3460. if (! empty ( $month ))
  3461. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  3462. }
  3463. }
  3464. // date ( 'Y-m' )
  3465. // if (! empty ( $rdate ) && $status == 'done')
  3466. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  3467. // elseif (! empty ( $rdate ))
  3468. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  3469. $categoryList = $Lcategory->find ( array (
  3470. 'asArray' => true
  3471. ) );
  3472. $staffList = $staff->find ( array (
  3473. 'where' => 'cid=' . $cid,
  3474. 'asArray' => true
  3475. ) );
  3476. $cateCondition = "";
  3477. $staffCondition = "";
  3478. $approvalCondition = "";
  3479. if (! empty ( $cid )) {
  3480. $cateCondition = ' and cid=' . $cid;
  3481. }
  3482. if (! empty ( $sid )) {
  3483. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  3484. $cateCondition = "";
  3485. }
  3486. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  3487. if ($status == 'pendApproval') {
  3488. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  3489. }
  3490. if ($status == 'ongoing') {
  3491. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  3492. }
  3493. if ($status == 'done') {
  3494. $approvalCondition = ' and (status=8 or status=9 ) ';
  3495. }
  3496. if ($status == 'termination') {
  3497. $approvalCondition = " and status=3";
  3498. }
  3499. if ($status == 'finish') {
  3500. $approvalCondition = " and (status=1 or status=8 or status=9)";
  3501. }
  3502. $pageinfo ['page'] = array (
  3503. 'previous' => ''
  3504. );
  3505. if(!empty($receiptOrder)){
  3506. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3507. $receiptList = $receipt->find ( array ( // $dateCondition
  3508. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  3509. 'desc' => 'rid',
  3510. 'asArray' => true
  3511. ) );
  3512. }else{
  3513. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  3514. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  3515. $receiptList = $receipt->find ( array ( // $dateCondition.
  3516. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3517. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  3518. 'desc' => 'rid',
  3519. 'asArray' => true
  3520. ) );
  3521. } else {
  3522. $receiptList = $receipt->find ( array ( // $dateCondition
  3523. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  3524. 'desc' => 'rid',
  3525. 'asArray' => true
  3526. ) );
  3527. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3528. }
  3529. }
  3530. $rLRes = $receipt->find ( array (
  3531. '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 . ')',
  3532. 'desc' => 'rid',
  3533. 'asArray' => true
  3534. ) );
  3535. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  3536. // print_r($receiptList);
  3537. Doo::loadClass ( 'XDeode' );
  3538. $XDeode = new XDeode ( 7 );
  3539. $Locate = 0;
  3540. $reportList = $reportCateList = array ();
  3541. foreach ( $receiptList as $key => $value ) {
  3542. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  3543. $receiptList [$key] ['Locate'] = $Locate;
  3544. $Locate ++;
  3545. $receiptList [$key] ['reviseDetail'] = array ();
  3546. if (! empty ( $value ['reviseDetail'] ))
  3547. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3548. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3549. $categoryDetil = $Lcategory->getOne ( array (
  3550. 'where' => 'cid=' . $value ['cid'],
  3551. 'asArray' => true
  3552. ) );
  3553. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3554. $verifyList = $verify->getOne ( array (
  3555. 'where' => 'vid=' . $value ['verify'],
  3556. 'asArray' => true
  3557. ) );
  3558. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3559. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3560. foreach ( $verifyList as $k => $v ) {
  3561. // init verifyStaff
  3562. $verifyList [$k] ['date'] = "";
  3563. $verifyList [$k] ['opinion'] = "";
  3564. $verifyList [$k] ['status'] = "";
  3565. if (empty ( $verifyStaff )) {
  3566. $verifyList [$k] ['date'] = "";
  3567. $verifyList [$k] ['opinion'] = "";
  3568. if ($v [0] == $this->staff [0] ['sid']) {
  3569. $verifyList [$k] ['status'] = 4;
  3570. $button = 4;
  3571. }
  3572. } else {
  3573. $flag = true;
  3574. foreach ( $verifyStaff as $m => $u ) {
  3575. if ($v [0] == $m) {
  3576. $verifyList [$k] ['date'] = $u ['date'];
  3577. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3578. $verifyList [$k] ['status'] = $u ['status'];
  3579. $flag = false;
  3580. break;
  3581. }
  3582. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  3583. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  3584. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  3585. }
  3586. if ($flag) { // 检测可编辑
  3587. if ($v [0] == $this->staff [0] ['sid']) {
  3588. $verifyList [$k] ['status'] = 4;
  3589. $button = 4;
  3590. }
  3591. }
  3592. }
  3593. }
  3594. $receiptList [$key] ['verifyList'] = $verifyList;
  3595. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  3596. 'where' => 'sid=' . $value ['staff'],
  3597. 'asArray' => true
  3598. ) );
  3599. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3600. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  3601. $receiptList [$key] ['button'] = $button;
  3602. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  3603. //获得培训班结算RID 借款费用--已经锁定
  3604. if($value['status']==10){
  3605. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  3606. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  3607. }
  3608. }
  3609. $reportList = array_unique ( $reportList );
  3610. $reportHtml = '';
  3611. foreach ( $reportList as $key => $value ) {
  3612. $v = explode ( "-", $value );
  3613. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  3614. }
  3615. // print_r($reportList)
  3616. $data ['reportHtml'] = $reportHtml;
  3617. $reportCateList = array_unique ( $reportCateList );
  3618. $reportCateHtml = '';
  3619. foreach ( $reportCateList as $key => $value ) {
  3620. $v = explode ( "-", $value );
  3621. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  3622. }
  3623. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  3624. $data ['reportCateHtml'] = $reportCateHtml;
  3625. // print_r($receiptList);die;
  3626. // $data['verifyDetail']=$verifyDetail;
  3627. $mothHtml = "";
  3628. for($i = 1; $i <= 12; $i ++) {
  3629. if ($month == $i)
  3630. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  3631. else
  3632. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  3633. }
  3634. $data ['mothHtml'] = $mothHtml;
  3635. $dateHtml = "";
  3636. $now = date ( "Y" );
  3637. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  3638. if ($YEARD <= $now) {
  3639. $dateHtml .= '<option ';
  3640. if ($year == $YEARD) {
  3641. $dateHtml .= 'selected ';
  3642. }
  3643. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  3644. }
  3645. }
  3646. $data ['dateHtml'] = $dateHtml;
  3647. $data ['page'] = $pageinfo;
  3648. $data ['receiptList'] = $receiptList;
  3649. $data ['receiptApprovalCount'] = count ( $rLRes );
  3650. $data ['status'] = $status;
  3651. $data ['year'] = $year;
  3652. $data ['month'] = $month;
  3653. $data ['categoryList'] = $categoryList;
  3654. $data ['staffList'] = $staffList;
  3655. $data ['cid'] = $cid;
  3656. $data ['sid'] = $sid;
  3657. // print_r($receiptList);
  3658. $data['receiptOrder']=$receiptOrder;
  3659. $data ['memu'] = "receipt";
  3660. $data ['staff'] = $this->staff;
  3661. $data ['receiptMemu'] = 'approvalExpenses';
  3662. $data ['verifyId'] = $this->verifyId;
  3663. $data ['executeId'] = $this->executeId;
  3664. $this->render ( "/admin/approvalExpenses", $data );
  3665. }
  3666. function expensesDoc() {
  3667. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3668. Doo::loadClass ( 'XDeode' );
  3669. $XDeode = new XDeode ( 5 );
  3670. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  3671. $rid = $XDeode->decode ( $rid );
  3672. if (! is_numeric ( $rid ))
  3673. die ( 'illegal request' );
  3674. Doo::loadModel ( 'receipt' );
  3675. $receipt = new receipt ();
  3676. Doo::loadModel ( 'L_category' );
  3677. $Lcategory = new L_category ();
  3678. Doo::loadModel ( 'verify' );
  3679. Doo::loadModel ( 'statistics' );
  3680. $statistics = new statistics ();
  3681. $verify = new verify ();
  3682. Doo::loadModel ( 'staff' );
  3683. $staff = new staff ();
  3684. Doo::loadModel ( 'loanReceipt' );
  3685. $loanReceipt = new loanReceipt ();
  3686. $receiptList = $receipt->find ( array (
  3687. 'where' => ' rid=' . $rid,
  3688. 'desc' => 'rid',
  3689. 'asArray' => true
  3690. ) );
  3691. $loanList = array ();
  3692. if (! empty ( $receiptList ))
  3693. $loanList = $loanReceipt->find ( array (
  3694. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  3695. 'desc' => 'rid',
  3696. 'asArray' => true
  3697. ) );
  3698. $Locate = 0;
  3699. $roleId = 0;
  3700. $button = 0;
  3701. foreach ( $loanList as $key => $value ) {
  3702. $loanList [$key] ['Locate'] = $Locate;
  3703. $Locate ++;
  3704. $loanList [$key] ['reviseDetail'] = array ();
  3705. if (! empty ( $value ['reviseDetail'] ))
  3706. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3707. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3708. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3709. $categoryDetil = $Lcategory->getOne ( array (
  3710. 'where' => 'cid=' . $value ['cid'],
  3711. 'asArray' => true
  3712. ) );
  3713. $loanList [$key] ['category'] = $categoryDetil ['title'];
  3714. // 检测编辑状态
  3715. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  3716. $verifyList ['staff'] = $value ['verifyBreakup'];
  3717. else
  3718. $verifyList = $verify->getOne ( array (
  3719. 'where' => 'vid=' . $value ['verify'],
  3720. 'asArray' => true
  3721. ) );
  3722. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3723. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3724. Doo::loadModel ( 'role' );
  3725. $role = new role ();
  3726. $flag = true;
  3727. $roleKey = 0;
  3728. $endStaffArray = array ();
  3729. $roleArrayCopy = array ();
  3730. foreach ( $verifyList as $k => $v ) {
  3731. // init verifyStaff
  3732. if ($v [1] == 'ROLE') {
  3733. if (! empty ( $verifyStaff )) {
  3734. $endStaffArray = end ( $verifyStaff );
  3735. // if ($v[0]==$endStaffArray['nextStaff']){
  3736. // $roleId=$v[0];
  3737. // }
  3738. }
  3739. $roleVerify = json_decode ( $v [3], true );
  3740. $roleKey = $k;
  3741. $roleArray = array ();
  3742. $rolename = $role->getOne ( array (
  3743. 'where' => 'rid=' . $v [0],
  3744. 'asArray' => true
  3745. ) );
  3746. foreach ( $roleVerify as $o => $p ) {
  3747. $staffID = explode ( '_', $p );
  3748. $staffInfo = $staff->getOne ( array (
  3749. 'where' => 'sid=' . $staffID [0],
  3750. 'asArray' => true
  3751. ) );
  3752. // print_r($staffID);
  3753. $exp = array (
  3754. 0 => $staffInfo ['sid'],
  3755. 1 => $staffID [1],
  3756. 2 => $staffInfo ['avatar'],
  3757. 'date' => '',
  3758. 'date' => '',
  3759. 'opinion' => '',
  3760. 'status' => '',
  3761. 'rolename' => $rolename ['name']
  3762. );
  3763. array_push ( $roleArray, $exp );
  3764. }
  3765. $roleArrayCopy [$v [0]] = $roleArray;
  3766. // $verifyList[$k]['roleArray']=$roleArray;
  3767. }
  3768. $verifyList [$k] ['date'] = "";
  3769. $verifyList [$k] ['opinion'] = "";
  3770. $verifyList [$k] ['status'] = "";
  3771. if (empty ( $verifyStaff )) {
  3772. $verifyList [$k] ['date'] = "";
  3773. $verifyList [$k] ['opinion'] = "";
  3774. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3775. $verifyList [$k] ['status'] = 4;
  3776. $flag = false;
  3777. }
  3778. } else {
  3779. foreach ( $verifyStaff as $m => $u ) {
  3780. if ($v [0] == $m) {
  3781. $verifyList [$k] ['date'] = $u ['date'];
  3782. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3783. $verifyList [$k] ['status'] = $u ['status'];
  3784. $flag = false;
  3785. break;
  3786. }
  3787. }
  3788. $endStaffArray = end ( $verifyStaff );
  3789. if (isset ( $endStaffArray ['ROLE'] )) {
  3790. } else {
  3791. // $endKey=key($verifyStaff);
  3792. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3793. // $button=4;
  3794. // $verifyList[$k]['status']=4;
  3795. // }
  3796. }
  3797. }
  3798. }
  3799. $rolename ['name'] = '';
  3800. if (! empty ( $roleId )) {
  3801. Doo::loadModel ( 'role' );
  3802. $role = new role ();
  3803. $rolename = $role->getOne ( array (
  3804. 'where' => 'rid=' . $roleId,
  3805. 'asArray' => true
  3806. ) );
  3807. }
  3808. if (! empty ( $verifyStaff ))
  3809. $endStaffArray = end ( $verifyStaff );
  3810. $KOP = false;
  3811. foreach ( $roleArrayCopy as $P => $A ) {
  3812. foreach ( $A as $MKI => $AVL ) {
  3813. if (! empty ( $verifyStaff )) {
  3814. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3815. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3816. $button = 4;
  3817. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3818. }
  3819. foreach ( $verifyStaff as $m => $u ) {
  3820. $AVLFK = $AVL [0] . '_R';
  3821. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3822. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3823. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3824. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3825. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3826. break;
  3827. }
  3828. }
  3829. } else {
  3830. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3831. $button = 4;
  3832. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3833. }
  3834. }
  3835. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3836. $KOP = true;
  3837. }
  3838. }
  3839. foreach ( $roleArrayCopy as $k => $v ) {
  3840. foreach ( $verifyList as $m => $n ) {
  3841. if ($n [0] == $k) {
  3842. array_splice ( $verifyList, $m, 1, $v );
  3843. }
  3844. }
  3845. }
  3846. $loanList [$key] ['verifyList'] = $verifyList;
  3847. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  3848. 'where' => 'sid=' . $value ['staff'],
  3849. 'asArray' => true
  3850. ) );
  3851. $loanList [$key] ['button'] = $button;
  3852. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  3853. }
  3854. $data ['loanList'] = $loanList;
  3855. //print_r($loanList);
  3856. $Locate = 0;
  3857. $roleId = 0;
  3858. $button = 0;
  3859. foreach ( $receiptList as $key => $value ) {
  3860. $receiptList [$key] ['Locate'] = $Locate;
  3861. $Locate ++;
  3862. $receiptList [$key] ['reviseDetail'] = array ();
  3863. if (! empty ( $value ['reviseDetail'] ))
  3864. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3865. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3866. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  3867. $categoryDetil = $Lcategory->getOne ( array (
  3868. 'where' => 'cid=' . $value ['cid'],
  3869. 'asArray' => true
  3870. ) );
  3871. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3872. // 检测编辑状态
  3873. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  3874. $verifyList ['staff'] = $value ['verifyBreakup'];
  3875. } else
  3876. $verifyList = $verify->getOne ( array (
  3877. 'where' => 'vid=' . $value ['verify'],
  3878. 'asArray' => true
  3879. ) );
  3880. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3881. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3882. Doo::loadModel ( 'role' );
  3883. $role = new role ();
  3884. if ($verifyList == NULL)
  3885. $verifyList = array ();
  3886. $flag = true;
  3887. $roleKey = 0;
  3888. $endStaffArray = array ();
  3889. $roleArrayCopy = array ();
  3890. foreach ( $verifyList as $k => $v ) {
  3891. // init verifyStaff
  3892. if ($v [1] == 'ROLE') {
  3893. if (! empty ( $verifyStaff )) {
  3894. $endStaffArray = end ( $verifyStaff );
  3895. // if ($v[0]==$endStaffArray['nextStaff']){
  3896. // $roleId=$v[0];
  3897. // }
  3898. }
  3899. $roleVerify = json_decode ( $v [3], true );
  3900. $roleKey = $k;
  3901. $roleArray = array ();
  3902. $rolename = $role->getOne ( array (
  3903. 'where' => 'rid=' . $v [0],
  3904. 'asArray' => true
  3905. ) );
  3906. foreach ( $roleVerify as $o => $p ) {
  3907. $staffID = explode ( '_', $p );
  3908. $staffInfo = $staff->getOne ( array (
  3909. 'where' => 'sid=' . $staffID [0],
  3910. 'asArray' => true
  3911. ) );
  3912. // print_r($staffID);
  3913. $exp = array (
  3914. 0 => $staffInfo ['sid'],
  3915. 1 => $staffID [1],
  3916. 2 => $staffInfo ['avatar'],
  3917. 'date' => '',
  3918. 'date' => '',
  3919. 'opinion' => '',
  3920. 'status' => '',
  3921. 'rolename' => $rolename ['name']
  3922. );
  3923. array_push ( $roleArray, $exp );
  3924. }
  3925. $roleArrayCopy [$v [0]] = $roleArray;
  3926. // $verifyList[$k]['roleArray']=$roleArray;
  3927. }
  3928. $verifyList [$k] ['date'] = "";
  3929. $verifyList [$k] ['opinion'] = "";
  3930. $verifyList [$k] ['status'] = "";
  3931. if (empty ( $verifyStaff )) {
  3932. $verifyList [$k] ['date'] = "";
  3933. $verifyList [$k] ['opinion'] = "";
  3934. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  3935. $verifyList [$k] ['status'] = 4;
  3936. $flag = false;
  3937. }
  3938. } else {
  3939. foreach ( $verifyStaff as $m => $u ) {
  3940. if ($v [0] == $m) {
  3941. $verifyList [$k] ['date'] = $u ['date'];
  3942. $verifyList [$k] ['opinion'] = $u ['opinion'];
  3943. $verifyList [$k] ['status'] = $u ['status'];
  3944. $flag = false;
  3945. break;
  3946. }
  3947. }
  3948. $endStaffArray = end ( $verifyStaff );
  3949. if (isset ( $endStaffArray ['ROLE'] )) {
  3950. } else {
  3951. // $endKey=key($verifyStaff);
  3952. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  3953. // $button=4;
  3954. // $verifyList[$k]['status']=4;
  3955. // }
  3956. }
  3957. }
  3958. }
  3959. $FC = @$rolename ['name'];
  3960. $rolename ['name'] = '';
  3961. if (! empty ( $roleId )) {
  3962. Doo::loadModel ( 'role' );
  3963. $role = new role ();
  3964. $rolename = $role->getOne ( array (
  3965. 'where' => 'rid=' . $roleId,
  3966. 'asArray' => true
  3967. ) );
  3968. }
  3969. if (! empty ( $verifyStaff ))
  3970. $endStaffArray = end ( $verifyStaff );
  3971. $KOP = false;
  3972. foreach ( $roleArrayCopy as $P => $A ) {
  3973. foreach ( $A as $MKI => $AVL ) {
  3974. if (! empty ( $verifyStaff )) {
  3975. // &&$rolename['rid']==$endStaffArray['nextStaff']
  3976. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  3977. $button = 4;
  3978. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3979. }
  3980. foreach ( $verifyStaff as $m => $u ) {
  3981. $AVLFK = $AVL [0] . '_R';
  3982. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  3983. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  3984. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  3985. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  3986. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  3987. break;
  3988. }
  3989. }
  3990. } else {
  3991. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  3992. $button = 4;
  3993. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  3994. }
  3995. }
  3996. // $roleArray[$MKI]['rolename']=$rolename['name'];
  3997. $KOP = true;
  3998. }
  3999. }
  4000. foreach ( $roleArrayCopy as $k => $v ) {
  4001. foreach ( $verifyList as $m => $n ) {
  4002. if ($n [0] == $k) {
  4003. array_splice ( $verifyList, $m, 1, $v );
  4004. }
  4005. }
  4006. }
  4007. // 费用执行人相关数据
  4008. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4009. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4010. foreach ( $executeCopy as $k => $v ) {
  4011. $executeCopy [$k] ['date'] = '';
  4012. $executeCopy [$k] ['opinion'] = '';
  4013. $executeCopy [$k] ['status'] = '';
  4014. if (! empty ( $executeStaff ))
  4015. foreach ( $executeStaff as $m => $u ) {
  4016. if ($v [0] == $m) {
  4017. $executeCopy [$k] ['date'] = $u ['date'];
  4018. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4019. $executeCopy [$k] ['status'] = $u ['status'];
  4020. break;
  4021. }
  4022. }
  4023. }
  4024. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4025. // print_r($verifyList);
  4026. $receiptList [$key] ['verifyList'] = $verifyList;
  4027. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4028. 'where' => 'sid=' . $value ['staff'],
  4029. 'asArray' => true
  4030. ) );
  4031. $receiptList [$key] ['button'] = $button;
  4032. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4033. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4034. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4035. $receiptList [$key] ['relust'] = $relust;
  4036. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4037. }
  4038. // print_r($receiptList);
  4039. // 获取审批日志
  4040. Doo::loadModel ( 'receiptLog' );
  4041. $receiptLog = new receiptLog ();
  4042. $rlList = array ();
  4043. $rlInfo = $receiptLog->getOne ( array (
  4044. 'where' => 'rid=' . $rid . ' and status=4',
  4045. 'asArray' => true
  4046. ) );
  4047. // $tijdate = $receiptLog->getOne ( array (
  4048. // 'where' => 'rid=' . $rid . ' and status=2',
  4049. // 'asc' => 'rlid',
  4050. // 'asArray' => true
  4051. // ) );
  4052. if (! empty ( $rlInfo )) {
  4053. $rlList = $receiptLog->find ( array (
  4054. 'where' => 'rid=' . $rid,
  4055. 'asc' => 'rlid',
  4056. 'asArray' => true
  4057. ) );
  4058. }
  4059. $RN=array();
  4060. if (!empty( $rolename ['staff'])){
  4061. $RN = @json_decode ( $rolename ['staff'] );
  4062. }
  4063. //
  4064. foreach ( $rlList as $key => $value ) {
  4065. $rlList [$key] ['rolename'] = '';
  4066. foreach ( $RN as $k => $v ) {
  4067. $id = explode ( "_", $v );
  4068. if ($id [0] == $value ['uid']) {
  4069. $rlList [$key] ['rolename'] = $FC;
  4070. break;
  4071. }
  4072. }
  4073. }
  4074. Doo::loadModel ( 'enclosur' );
  4075. $enclosur = new enclosur ();
  4076. $enclosurList = $enclosur->find ( array (
  4077. 'where' => 'rid=' . $rid,
  4078. 'asArray' => true
  4079. ) );
  4080. $enclosurHtml = '';
  4081. foreach ( $enclosurList as $value ) {
  4082. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4083. }
  4084. $data ['enclosurHtml'] = $enclosurHtml;
  4085. $receiptList [0] ['rlList'] = $rlList;
  4086. $data ['receiptList'] = $receiptList;
  4087. // print_r($receiptList);
  4088. $data ['memu'] = "receipt";
  4089. $data ['staff'] = $this->staff;
  4090. $data ['receiptMemu'] = 'approvalExpenses';
  4091. $data ['verifyId'] = $this->verifyId;
  4092. $data ['executeId'] = $this->executeId;
  4093. $this->render ( "/admin/expensesDoc", $data );
  4094. }
  4095. function expensesEdi() {
  4096. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4097. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  4098. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4099. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4100. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4101. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4102. if (empty ( $status ))
  4103. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  4104. $vidList = array ();
  4105. $button = 0;
  4106. Doo::loadModel ( 'verify' );
  4107. Doo::loadModel ( 'receipt' );
  4108. Doo::loadModel ( 'staff' );
  4109. $staff = new staff ();
  4110. $receipt = new receipt ();
  4111. $verify = new verify ();
  4112. Doo::loadModel ( 'L_category' );
  4113. $Lcategory = new L_category ();
  4114. Doo::loadModel ( 'enclosur' );
  4115. $enclosur = new enclosur ();
  4116. // user verify ID
  4117. $verifyDetail = $verify->find ( array (
  4118. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  4119. 'asArray' => true
  4120. ) );
  4121. foreach ( $verifyDetail as $key => $value ) {
  4122. array_push ( $vidList, $value ['vid'] );
  4123. }
  4124. $vid = implode ( ",", $vidList );
  4125. if (empty ( $verifyDetail ))
  4126. $vid = 0;
  4127. $categoryList = $Lcategory->find ( array (
  4128. 'asArray' => true
  4129. ) );
  4130. $staffList = $staff->find ( array (
  4131. 'where' => 'cid=' . $cid,
  4132. 'asArray' => true
  4133. ) );
  4134. $ap = "";
  4135. if ($status == 4) {
  4136. $ap = 4;
  4137. $status = 2;
  4138. }
  4139. // get Receipt By verifyID status 2
  4140. $receiptList = $receipt->find ( array (
  4141. 'where' => 'rid =' . $rid . ' and status=2',
  4142. 'desc' => 'rid',
  4143. 'asArray' => true
  4144. ) );
  4145. if (empty ( $receiptList )) {
  4146. die ( 'illegal request' );
  4147. }
  4148. $Locate = 0;
  4149. $roleId = 0;
  4150. if ($ap == 4)
  4151. $status = 4;
  4152. foreach ( $receiptList as $key => $value ) {
  4153. $receiptList [$key] ['Locate'] = $Locate;
  4154. $Locate ++;
  4155. $receiptList [$key] ['reviseDetail'] = array ();
  4156. if (! empty ( $value ['reviseDetail'] ))
  4157. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4158. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4159. $categoryDetil = $Lcategory->getOne ( array (
  4160. 'where' => 'cid=' . $value ['cid'],
  4161. 'asArray' => true
  4162. ) );
  4163. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4164. // 检测编辑状态
  4165. $verifyList = $verify->getOne ( array (
  4166. 'where' => 'vid=' . $value ['verify'],
  4167. 'asArray' => true
  4168. ) );
  4169. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4170. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4171. Doo::loadModel ( 'role' );
  4172. $role = new role ();
  4173. // print_r($verifyList);
  4174. $flag = true;
  4175. $roleKey = 0;
  4176. $endStaffArray = array ();
  4177. $roleArrayCopy = array ();
  4178. foreach ( $verifyList as $k => $v ) {
  4179. // init verifyStaff
  4180. if ($v [1] == 'ROLE') {
  4181. if (! empty ( $verifyStaff )) {
  4182. $endStaffArray = end ( $verifyStaff );
  4183. if ($v [0] == $endStaffArray ['nextStaff']) {
  4184. $roleId = $v [0];
  4185. }
  4186. }
  4187. $roleVerify = json_decode ( $v [3], true );
  4188. $roleKey = $k;
  4189. $roleArray = array ();
  4190. $rolename = $role->getOne ( array (
  4191. 'where' => 'rid=' . $v [0],
  4192. 'asArray' => true
  4193. ) );
  4194. foreach ( $roleVerify as $o => $p ) {
  4195. $staffID = explode ( '_', $p );
  4196. $staffInfo = $staff->getOne ( array (
  4197. 'where' => 'sid=' . $staffID [0],
  4198. 'asArray' => true
  4199. ) );
  4200. // print_r($staffID);
  4201. $exp = array (
  4202. 0 => $staffInfo ['sid'],
  4203. 1 => $staffID [1],
  4204. 2 => $staffInfo ['avatar'],
  4205. 'date' => '',
  4206. 'date' => '',
  4207. 'opinion' => '',
  4208. 'status' => '',
  4209. 'rolename' => $rolename ['name']
  4210. );
  4211. array_push ( $roleArray, $exp );
  4212. }
  4213. $roleArrayCopy [$v [0]] = $roleArray;
  4214. // $verifyList[$k]['roleArray']=$roleArray;
  4215. }
  4216. // print_r($roleArray);
  4217. $verifyList [$k] ['date'] = "";
  4218. $verifyList [$k] ['opinion'] = "";
  4219. $verifyList [$k] ['status'] = "";
  4220. if (empty ( $verifyStaff )) {
  4221. $verifyList [$k] ['date'] = "";
  4222. $verifyList [$k] ['opinion'] = "";
  4223. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4224. $verifyList [$k] ['status'] = 4;
  4225. $button = 4;
  4226. $flag = false;
  4227. }
  4228. } else {
  4229. foreach ( $verifyStaff as $m => $u ) {
  4230. if ($v [0] == $m) {
  4231. $verifyList [$k] ['date'] = $u ['date'];
  4232. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4233. $verifyList [$k] ['status'] = $u ['status'];
  4234. $flag = false;
  4235. break;
  4236. }
  4237. }
  4238. $endStaffArray = end ( $verifyStaff );
  4239. if (isset ( $endStaffArray ['ROLE'] )) {
  4240. } else {
  4241. $endKey = key ( $verifyStaff );
  4242. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  4243. $button = 4;
  4244. $verifyList [$k] ['status'] = 4;
  4245. }
  4246. }
  4247. }
  4248. }
  4249. $rolename ['name'] = '';
  4250. if (! empty ( $roleId )) {
  4251. Doo::loadModel ( 'role' );
  4252. $role = new role ();
  4253. $rolename = $role->getOne ( array (
  4254. 'where' => 'rid=' . $roleId,
  4255. 'asArray' => true
  4256. ) );
  4257. }
  4258. if (! empty ( $verifyStaff ))
  4259. $endStaffArray = end ( $verifyStaff );
  4260. $KOP = false;
  4261. foreach ( $roleArrayCopy as $P => $A ) {
  4262. foreach ( $A as $MKI => $AVL ) {
  4263. if (! empty ( $verifyStaff )) {
  4264. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4265. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4266. $button = 4;
  4267. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4268. }
  4269. foreach ( $verifyStaff as $m => $u ) {
  4270. $AVLFK = $AVL [0] . '_R';
  4271. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4272. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4273. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4274. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4275. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4276. break;
  4277. }
  4278. }
  4279. } else {
  4280. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4281. $button = 4;
  4282. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4283. }
  4284. }
  4285. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4286. $KOP = true;
  4287. }
  4288. }
  4289. // print_r($roleArrayCopy);
  4290. // echo $roleKey;
  4291. foreach ( $roleArrayCopy as $k => $v ) {
  4292. foreach ( $verifyList as $m => $n ) {
  4293. if ($n [0] == $k) {
  4294. array_splice ( $verifyList, $m, 1, $v );
  4295. }
  4296. }
  4297. }
  4298. $receiptList [$key] ['verifyList'] = $verifyList;
  4299. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4300. 'where' => 'sid=' . $value ['staff'],
  4301. 'asArray' => true
  4302. ) );
  4303. $receiptList [$key] ['button'] = $button;
  4304. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  4305. }
  4306. // $data['verifyDetail']=$verifyDetail;
  4307. $mothHtml = "";
  4308. for($i = 1; $i <= 12; $i ++) {
  4309. if ($month == $i)
  4310. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4311. else
  4312. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4313. }
  4314. // 获取审批日志
  4315. Doo::loadModel ( 'receiptLog' );
  4316. $receiptLog = new receiptLog ();
  4317. $rlList = array ();
  4318. $rlInfo = $receiptLog->getOne ( array (
  4319. 'where' => 'rid=' . $rid . ' and status=4',
  4320. 'asArray' => true
  4321. ) );
  4322. $tijdate = $receiptLog->getOne ( array (
  4323. 'where' => 'rid=' . $rid . ' and status=2',
  4324. 'asc' => 'rlid',
  4325. 'asArray' => true
  4326. ) );
  4327. if (! empty ( $rlInfo )) {
  4328. $rlList = $receiptLog->find ( array (
  4329. 'where' => 'rid=' . $rid,
  4330. 'asc' => 'rlid',
  4331. 'asArray' => true
  4332. ) );
  4333. }
  4334. $receiptList [0] ['rlList'] = $rlList;
  4335. $enclosurList = $enclosur->find ( array (
  4336. 'where' => 'rid=' . $rid,
  4337. 'asArray' => true
  4338. ) );
  4339. $enclosurHtml = '';
  4340. foreach ( $enclosurList as $value ) {
  4341. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4342. }
  4343. // print_r($receiptList);
  4344. $data ['rid'] = $rid;
  4345. $data ['enclosurHtml'] = $enclosurHtml;
  4346. $data ['rolename'] = $rolename ['name'];
  4347. $data ['datetij'] = $tijdate ['date'];
  4348. $data ['mothHtml'] = $mothHtml;
  4349. $data ['receiptList'] = $receiptList;
  4350. $data ['receiptApprovalCount'] = count ( $receiptList );
  4351. $data ['status'] = $status;
  4352. $data ['year'] = $year;
  4353. $data ['categoryList'] = $categoryList;
  4354. $data ['staffList'] = $staffList;
  4355. $data ['cid'] = $cid;
  4356. $data ['sid'] = $sid;
  4357. $data ['ap'] = $ap;
  4358. $data ['memu'] = "receipt";
  4359. $data ['staff'] = $this->staff;
  4360. $data ['receiptMemu'] = 'approvalExpenses';
  4361. $data ['verifyId'] = $this->verifyId;
  4362. $data ['executeId'] = $this->executeId;
  4363. $this->render ( "/admin/expensesEdi", $data );
  4364. }
  4365. function expensesDefray() {
  4366. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  4367. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4368. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4369. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  4370. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  4371. if (! empty ( $rid )) {
  4372. Doo::loadModel ( "verify" );
  4373. $verify = new verify ();
  4374. Doo::loadModel ( "receiptDetail" );
  4375. $receiptDetailObj = new receiptDetail ();
  4376. Doo::loadModel ( "itemStatistics" );
  4377. Doo::loadModel ( "statistics" );
  4378. $statistics = new statistics ();
  4379. $itemStatistics = new itemStatistics ();
  4380. Doo::loadModel ( "receipt" );
  4381. $receipt = new receipt ();
  4382. Doo::loadModel ( "loanReceipt" );
  4383. $loanReceipt = new loanReceipt ();
  4384. $receiptDetail = $receipt->getOne ( array (
  4385. 'where' => 'rid=' . $rid . ' and status=2 ',
  4386. 'asArray' => true
  4387. ) );
  4388. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  4389. $nsflag = true;
  4390. foreach ( $nslist as $value ) {
  4391. if ($value == $this->staff ['0'] ['sid']) {
  4392. $nsflag = false;
  4393. break;
  4394. }
  4395. }
  4396. // print_r($nslist);die;
  4397. if (empty ( $receiptDetail ) || $nsflag)
  4398. return "/approvalExpenses/pendApproval";
  4399. $verifyDetail = $verify->getOne ( array (
  4400. 'where' => ' vid =' . $receiptDetail ['verify'],
  4401. 'asArray' => true
  4402. ) );
  4403. $verifyString = $verifyDetail ['staff'];
  4404. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  4405. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  4406. if (empty ( $opinion )) {
  4407. if ($status == 3)
  4408. $opinion = "终止";
  4409. else
  4410. $opinion = "同意支付";
  4411. }
  4412. $nowStaff = 0;
  4413. $nowStaffList = array ();
  4414. if (empty ( $verifyStaff )) {
  4415. // 还需加入是否已经进入角色审批
  4416. if ($verifyDetail [0] [1] == 'ROLE') {
  4417. // print_r($verifyDetail);echo "ddd";
  4418. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  4419. foreach ( $vStaffString as $key => $value ) {
  4420. $staffK = explode ( "_", $value );
  4421. if ($staffK [0] != $this->staff [0] ['sid'])
  4422. array_push ( $nowStaffList, $staffK [0] );
  4423. }
  4424. // print_r($verifyDetail);
  4425. // die;
  4426. if (! empty ( $nowStaffList )) {
  4427. $nowStaff = implode ( ',', $nowStaffList );
  4428. $verifyStaff = array (
  4429. $this->staff [0] ['sid'] . "_R" => array (
  4430. 'date' => date ( 'Y-m-d' ),
  4431. 'opinion' => $opinion,
  4432. 'status' => $status,
  4433. 'nextStaff' => $verifyDetail [0] [0],
  4434. 'ROLE' => 1
  4435. )
  4436. );
  4437. } else {
  4438. $nowStaff = $verifyDetail [1] [0];
  4439. $verifyStaff = array (
  4440. $this->staff [0] ['sid'] . "_R" => array (
  4441. 'date' => date ( 'Y-m-d' ),
  4442. 'opinion' => $opinion,
  4443. 'status' => $status,
  4444. 'nextStaff' => $verifyDetail [1] [0]
  4445. )
  4446. );
  4447. }
  4448. } else {
  4449. if ($verifyDetail [1] [1] == 'ROLE') {
  4450. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  4451. // echo "dd";
  4452. foreach ( $vStaffString as $key => $value ) {
  4453. $staffK = explode ( "_", $value );
  4454. array_push ( $nowStaffList, $staffK [0] );
  4455. }
  4456. $nowStaff = implode ( ',', $nowStaffList );
  4457. $verifyStaff = array (
  4458. $this->staff [0] ['sid'] => array (
  4459. 'date' => date ( 'Y-m-d' ),
  4460. 'opinion' => $opinion,
  4461. 'status' => $status,
  4462. 'nextStaff' => $verifyDetail [1] [0],
  4463. 'ROLE' => 1
  4464. )
  4465. );
  4466. } else {
  4467. $nowStaff = $verifyDetail [1] [0];
  4468. $verifyStaff = array (
  4469. $this->staff [0] ['sid'] => array (
  4470. 'date' => date ( 'Y-m-d' ),
  4471. 'opinion' => $opinion,
  4472. 'status' => $status,
  4473. 'nextStaff' => $verifyDetail [1] [0]
  4474. )
  4475. );
  4476. }
  4477. }
  4478. if ($status == 3)
  4479. $verifyStaff = array (
  4480. 'final' => $status,
  4481. $this->staff [0] ['sid'] => array (
  4482. 'date' => date ( 'Y-m-d' ),
  4483. 'opinion' => $opinion,
  4484. 'status' => $status
  4485. )
  4486. );
  4487. $vStaffString = json_encode ( $verifyStaff );
  4488. $receipt->nowStaff = $nowStaff;
  4489. $receipt->verifyStaff = $vStaffString;
  4490. $loanReceipt->nowStaff = $nowStaff;
  4491. $loanReceipt->verifyStaff = $vStaffString;
  4492. } else {
  4493. $VS = end ( $verifyStaff );
  4494. // 非角色审批
  4495. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  4496. $nextStaff = 0;
  4497. $roleSTF = false;
  4498. foreach ( $verifyDetail as $key => $value ) {
  4499. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  4500. if (isset ( $verifyDetail [$key + 1] )) {
  4501. $nextStaff = $verifyDetail [$key + 1] [0];
  4502. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  4503. $roleSTF = true;
  4504. }
  4505. break;
  4506. }
  4507. }
  4508. if (! $roleSTF) {
  4509. $nowStaff = $nextStaff;
  4510. $verifyStaff [$this->staff [0] ['sid']] = array (
  4511. 'date' => date ( 'Y-m-d' ),
  4512. 'opinion' => $opinion,
  4513. 'status' => $status,
  4514. 'nextStaff' => $nextStaff
  4515. );
  4516. } else {
  4517. // 获取角色下的所有用户ID
  4518. $nowStaffList = array ();
  4519. foreach ( $verifyDetail as $vfk ) {
  4520. if ($vfk [1] == 'ROLE') {
  4521. $vStaffString = json_decode ( $vfk [3] );
  4522. foreach ( $vStaffString as $key => $value ) {
  4523. $staffK = explode ( "_", $value );
  4524. array_push ( $nowStaffList, $staffK [0] );
  4525. }
  4526. }
  4527. }
  4528. $nowStaff = implode ( ',', $nowStaffList );
  4529. $verifyStaff [$this->staff [0] ['sid']] = array (
  4530. 'date' => date ( 'Y-m-d' ),
  4531. 'opinion' => $opinion,
  4532. 'status' => $status,
  4533. 'nextStaff' => $nextStaff,
  4534. 'ROLE' => 0
  4535. );
  4536. }
  4537. if ($status == 3) {
  4538. $verifyStaff ['final'] = $status;
  4539. $verifyStaff [$this->staff [0] ['sid']] = array (
  4540. 'date' => date ( 'Y-m-d' ),
  4541. 'opinion' => $opinion,
  4542. 'status' => $status
  4543. );
  4544. }
  4545. $vStaffString = json_encode ( $verifyStaff );
  4546. $receipt->nowStaff = $nowStaff;
  4547. $receipt->verifyStaff = $vStaffString;
  4548. $loanReceipt->nowStaff = $nowStaff;
  4549. $loanReceipt->verifyStaff = $vStaffString;
  4550. }
  4551. // 角色审批
  4552. if (isset ( $VS ['ROLE'] )) {
  4553. // 找出角色人 当前审批角色组
  4554. $verifyJSStaff = array ();
  4555. $nowStaffList2 = array ();
  4556. foreach ( $verifyDetail as $key => $value ) {
  4557. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  4558. $verifyJSStaff = json_decode ( $value [3] );
  4559. foreach ( $verifyJSStaff as $m ) {
  4560. $staffK = explode ( "_", $m );
  4561. array_push ( $nowStaffList2, $staffK [0] );
  4562. }
  4563. // print_r($nowStaffList2);
  4564. }
  4565. }
  4566. $RoleVerifyStaff = array ();
  4567. foreach ( $verifyStaff as $key => $value ) {
  4568. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  4569. foreach ( $nowStaffList2 as $m ) {
  4570. if ($key == $m . "_R")
  4571. $RoleVerifyStaff [$key] = $value;
  4572. }
  4573. }
  4574. }
  4575. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  4576. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  4577. // 下一个审批人ID
  4578. $nextStaff = 0;
  4579. $falg = false;
  4580. foreach ( $verifyDetail as $key => $value ) {
  4581. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  4582. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  4583. $falg = true;
  4584. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  4585. $nowStaffList = array ();
  4586. foreach ( $vStaffString as $v ) {
  4587. $staffK = explode ( "_", $v );
  4588. array_push ( $nowStaffList, $staffK [0] );
  4589. }
  4590. $nowStaff = implode ( ',', $nowStaffList );
  4591. $nextStaff = $verifyDetail [$key + 1] [0];
  4592. } elseif (isset ( $verifyDetail [$key + 1] )) {
  4593. $nextStaff = $verifyDetail [$key + 1] [0];
  4594. $nowStaff = $nextStaff;
  4595. } else
  4596. $nowStaff = '';
  4597. break;
  4598. }
  4599. }
  4600. if ($falg)
  4601. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4602. 'date' => date ( 'Y-m-d' ),
  4603. 'opinion' => $opinion,
  4604. 'status' => $status,
  4605. 'nextStaff' => $nextStaff,
  4606. 'ROLE' => 1
  4607. );
  4608. else
  4609. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4610. 'date' => date ( 'Y-m-d' ),
  4611. 'opinion' => $opinion,
  4612. 'status' => $status,
  4613. 'nextStaff' => $nextStaff
  4614. );
  4615. // print_r($verifyStaff);
  4616. // echo $nowStaff;die;
  4617. } else { // 进入下一个角色或者审批人
  4618. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  4619. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  4620. 'date' => date ( 'Y-m-d' ),
  4621. 'opinion' => $opinion,
  4622. 'status' => $status,
  4623. 'nextStaff' => $VS ['nextStaff'],
  4624. 'ROLE' => 1
  4625. );
  4626. }
  4627. if ($status == 3) {
  4628. $verifyStaff ['final'] = $status;
  4629. $verifyStaff [$this->staff [0] ['sid']] = array (
  4630. 'date' => date ( 'Y-m-d' ),
  4631. 'opinion' => $opinion,
  4632. 'status' => $status
  4633. );
  4634. }
  4635. $vStaffString = json_encode ( $verifyStaff );
  4636. $receipt->verifyStaff = $vStaffString;
  4637. $receipt->nowStaff = $nowStaff;
  4638. $loanReceipt->nowStaff = $nowStaff;
  4639. $loanReceipt->verifyStaff = $vStaffString;
  4640. }
  4641. // print_r($verifyStaff);die;
  4642. }
  4643. $roleKey = 0;
  4644. $roleId = 0;
  4645. $verifyDetailCopy = array ();
  4646. foreach ( $verifyDetail as $k => $v ) {
  4647. if ($v [1] == 'ROLE') {
  4648. $roleId = $v [0];
  4649. $roleVerify = json_decode ( $v [3], true );
  4650. $roleKey = $k;
  4651. $roleArray = array ();
  4652. foreach ( $roleVerify as $o => $p ) {
  4653. $staffID = explode ( '_', $p );
  4654. $exp = array (
  4655. 0 => $staffID [0],
  4656. 1 => $staffID [1]
  4657. );
  4658. array_push ( $roleArray, $exp );
  4659. }
  4660. $verifyDetailCopy [$v [0]] = $roleArray;
  4661. }
  4662. }
  4663. // print_r($verifyDetail);
  4664. foreach ( $verifyDetailCopy as $k => $v ) {
  4665. foreach ( $verifyDetail as $m => $n ) {
  4666. if ($n [0] == $k) {
  4667. array_splice ( $verifyDetail, $m, 1, $v );
  4668. }
  4669. }
  4670. }
  4671. // 审批日志
  4672. if (! isset ( $verifyStaff ['final'] )) {
  4673. Doo::loadModel ( "receiptLog" );
  4674. $receiptLog = new receiptLog ();
  4675. if (! empty ( $roleId )) {
  4676. Doo::loadModel ( "role" );
  4677. $role = new role ();
  4678. $roleInfo = $role->getOne ( array (
  4679. 'where' => 'rid=' . $roleId,
  4680. 'asArray' => true
  4681. ) );
  4682. $receiptLog->rolename = $roleInfo ['name'];
  4683. }
  4684. $receiptLog->username = $this->staff [0] ['username'];
  4685. $receiptLog->uid = $this->staff [0] ['sid'];
  4686. $receiptLog->date = date ( "Y-m-d" );
  4687. $receiptLog->opinion = $opinion;
  4688. $receiptLog->img = $this->staff [0] ['avatar'];
  4689. $receiptLog->status = 1;
  4690. $receiptLog->rid = $rid;
  4691. $receiptLog->insert ();
  4692. }
  4693. if (isset ( $verifyStaff ['final'] )) { // rDetail
  4694. $receipt->status = 3;
  4695. $receipt->verifyBreakup = $verifyString;
  4696. $receiptDetailObj->status = 3;
  4697. $receiptDetailObj->update ( array (
  4698. 'where' => 'rid=' . $rid
  4699. ) );
  4700. // 微信企业号通知
  4701. $this->setWXMsg ( $rid, 3 );
  4702. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  4703. $receipt->status = 6;
  4704. $receipt->pastDate = date ( "Y-m-d" );
  4705. $receipt->isBK = 1;
  4706. $loanReceipt->verifyBreakup = $verifyString;
  4707. $loanReceipt->status = 1;
  4708. $loanReceipt->pastDate = date ( "Y-m-d" );
  4709. //生成流水后 不更新汇款金额
  4710. Doo::loadModel ( 'wasteBook' );
  4711. $wasteBook = new wasteBook ();
  4712. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  4713. if (empty($wbDetail)){
  4714. $loanReceipt->amount = $receiptDetail ['amount'];
  4715. }
  4716. $loanReceipt->update ( array (
  4717. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  4718. ) );
  4719. // 微信企业号通知
  4720. $this->setWXMsg ( $rid, 1 );
  4721. }
  4722. $receipt->amount = $receiptDetail['sum'];
  4723. $receipt->update ( array (
  4724. 'where' => ' rid = ' . $rid
  4725. ) );
  4726. // 进入下一条审批费用新加需求
  4727. $vidList = array ();
  4728. $verifyDetail = $verify->find ( array (
  4729. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4730. 'asArray' => true
  4731. ) );
  4732. foreach ( $verifyDetail as $key => $value ) {
  4733. array_push ( $vidList, $value ['vid'] );
  4734. }
  4735. $vid = implode ( ",", $vidList );
  4736. if (empty ( $verifyDetail ))
  4737. $vid = 0;
  4738. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4739. $receipt = new receipt ();
  4740. $rd = $receipt->getOne ( array (
  4741. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  4742. 'asc' => 'rid',
  4743. 'asArray' => true
  4744. ) );
  4745. if (empty ( $rd )) {
  4746. return '/approvalExpenses/pendApproval';
  4747. }
  4748. if ($rd ['Rtype'] == 1) {
  4749. if ($rd ['isBK'] == 1) {
  4750. return '/receiptburEdi/' . $rd ['rid'];
  4751. } else {
  4752. return '/expensesEdi/' . $rd ['rid'];
  4753. }
  4754. } elseif ($rd ['Rtype'] == 2) {
  4755. return '/remitApproval/' . $rd ['rid'];
  4756. } else {
  4757. return '/receiptburEdi/' . $rd ['rid'];
  4758. }
  4759. // return "/approvalExpenses/pendApproval";
  4760. }
  4761. }
  4762. function ajaxExamineExe() {
  4763. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  4764. Doo::loadModel ( 'receipt' );
  4765. $receipt = new receipt ();
  4766. Doo::loadClass ( 'XDeode' );
  4767. $XDeode = new XDeode ( 5 );
  4768. if (! empty ( $rid )) {
  4769. $rLRes = $receipt->find ( array (
  4770. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  4771. 'asArray' => true
  4772. ) );
  4773. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  4774. echo json_encode ( array (
  4775. 'status' => 1,
  4776. 'receipt' => $rLRes [0]
  4777. ) );
  4778. die ();
  4779. }
  4780. echo json_encode ( array (
  4781. 'status' => 0,
  4782. 'receipt' => array ()
  4783. ) );
  4784. die ();
  4785. }
  4786. function implement() {
  4787. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4788. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  4789. Doo::loadClass ( 'XDeode' );
  4790. $XDeode = new XDeode ( 5 );
  4791. Doo::loadModel ( 'receipt' );
  4792. $receipt = new receipt ();
  4793. Doo::loadModel ( 'L_category' );
  4794. $Lcategory = new L_category ();
  4795. Doo::loadModel ( 'verify' );
  4796. $verify = new verify ();
  4797. Doo::loadModel ( 'staff' );
  4798. $staff = new staff ();
  4799. Doo::loadModel ( "execute" );
  4800. $execute = new execute ();
  4801. $rid = $XDeode->decode ( $rid );
  4802. $receiptList = $receipt->find ( array (
  4803. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  4804. 'desc' => 'rid',
  4805. 'asArray' => true
  4806. ) );
  4807. Doo::loadModel ( 'loanReceipt' );
  4808. $loanReceipt = new loanReceipt ();
  4809. // print_r($receiptList);
  4810. $loanList = array ();
  4811. if (! isset ( $receiptList ))
  4812. $loanList = $loanReceipt->find ( array (
  4813. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4814. 'desc' => 'rid',
  4815. 'asArray' => true
  4816. ) );
  4817. $Locate = 0;
  4818. $roleId = 0;
  4819. $button = 0;
  4820. foreach ( $loanList as $key => $value ) {
  4821. $loanList [$key] ['Locate'] = $Locate;
  4822. $Locate ++;
  4823. $loanList [$key] ['reviseDetail'] = array ();
  4824. if (! empty ( $value ['reviseDetail'] ))
  4825. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4826. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4827. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4828. $categoryDetil = $Lcategory->getOne ( array (
  4829. 'where' => 'cid=' . $value ['cid'],
  4830. 'asArray' => true
  4831. ) );
  4832. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4833. // 检测编辑状态
  4834. $verifyList = $verify->getOne ( array (
  4835. 'where' => 'vid=' . $value ['verify'],
  4836. 'asArray' => true
  4837. ) );
  4838. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4839. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4840. Doo::loadModel ( 'role' );
  4841. $role = new role ();
  4842. $flag = true;
  4843. $roleKey = 0;
  4844. $endStaffArray = array ();
  4845. $roleArrayCopy = array ();
  4846. foreach ( $verifyList as $k => $v ) {
  4847. // init verifyStaff
  4848. if ($v [1] == 'ROLE') {
  4849. if (! empty ( $verifyStaff )) {
  4850. $endStaffArray = end ( $verifyStaff );
  4851. // if ($v[0]==$endStaffArray['nextStaff']){
  4852. // $roleId=$v[0];
  4853. // }
  4854. }
  4855. $roleVerify = json_decode ( $v [3], true );
  4856. $roleKey = $k;
  4857. $roleArray = array ();
  4858. $rolename = $role->getOne ( array (
  4859. 'where' => 'rid=' . $v [0],
  4860. 'asArray' => true
  4861. ) );
  4862. foreach ( $roleVerify as $o => $p ) {
  4863. $staffID = explode ( '_', $p );
  4864. $staffInfo = $staff->getOne ( array (
  4865. 'where' => 'sid=' . $staffID [0],
  4866. 'asArray' => true
  4867. ) );
  4868. // print_r($staffID);
  4869. $exp = array (
  4870. 0 => $staffInfo ['sid'],
  4871. 1 => $staffID [1],
  4872. 2 => $staffInfo ['avatar'],
  4873. 'date' => '',
  4874. 'date' => '',
  4875. 'opinion' => '',
  4876. 'status' => '',
  4877. 'rolename' => $rolename ['name']
  4878. );
  4879. array_push ( $roleArray, $exp );
  4880. }
  4881. $roleArrayCopy [$v [0]] = $roleArray;
  4882. // $verifyList[$k]['roleArray']=$roleArray;
  4883. }
  4884. $verifyList [$k] ['date'] = "";
  4885. $verifyList [$k] ['opinion'] = "";
  4886. $verifyList [$k] ['status'] = "";
  4887. if (empty ( $verifyStaff )) {
  4888. $verifyList [$k] ['date'] = "";
  4889. $verifyList [$k] ['opinion'] = "";
  4890. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4891. $verifyList [$k] ['status'] = 4;
  4892. $flag = false;
  4893. }
  4894. } else {
  4895. foreach ( $verifyStaff as $m => $u ) {
  4896. if ($v [0] == $m) {
  4897. $verifyList [$k] ['date'] = $u ['date'];
  4898. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4899. $verifyList [$k] ['status'] = $u ['status'];
  4900. $flag = false;
  4901. break;
  4902. }
  4903. }
  4904. $endStaffArray = end ( $verifyStaff );
  4905. if (isset ( $endStaffArray ['ROLE'] )) {
  4906. } else {
  4907. // $endKey=key($verifyStaff);
  4908. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4909. // $button=4;
  4910. // $verifyList[$k]['status']=4;
  4911. // }
  4912. }
  4913. }
  4914. }
  4915. $rolename ['name'] = '';
  4916. if (! empty ( $roleId )) {
  4917. Doo::loadModel ( 'role' );
  4918. $role = new role ();
  4919. $rolename = $role->getOne ( array (
  4920. 'where' => 'rid=' . $roleId,
  4921. 'asArray' => true
  4922. ) );
  4923. }
  4924. if (! empty ( $verifyStaff ))
  4925. $endStaffArray = end ( $verifyStaff );
  4926. $KOP = false;
  4927. foreach ( $roleArrayCopy as $P => $A ) {
  4928. foreach ( $A as $MKI => $AVL ) {
  4929. if (! empty ( $verifyStaff )) {
  4930. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4931. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4932. $button = 4;
  4933. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4934. }
  4935. foreach ( $verifyStaff as $m => $u ) {
  4936. $AVLFK = $AVL [0] . '_R';
  4937. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4938. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4939. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4940. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4941. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4942. break;
  4943. }
  4944. }
  4945. } else {
  4946. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4947. $button = 4;
  4948. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4949. }
  4950. }
  4951. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4952. $KOP = true;
  4953. }
  4954. }
  4955. foreach ( $roleArrayCopy as $k => $v ) {
  4956. foreach ( $verifyList as $m => $n ) {
  4957. if ($n [0] == $k) {
  4958. array_splice ( $verifyList, $m, 1, $v );
  4959. }
  4960. }
  4961. }
  4962. $loanList [$key] ['verifyList'] = $verifyList;
  4963. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4964. 'where' => 'sid=' . $value ['staff'],
  4965. 'asArray' => true
  4966. ) );
  4967. }
  4968. $data ['loanList'] = $loanList;
  4969. $Locate = 0;
  4970. $roleId = 0;
  4971. $button = 0;
  4972. Doo::loadClass ( 'XDeode' );
  4973. $XDeode = new XDeode ( 5 );
  4974. foreach ( $receiptList as $key => $value ) {
  4975. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  4976. $button2 = 0;
  4977. $receiptList [$key] ['Locate'] = $Locate;
  4978. $Locate ++;
  4979. $receiptList [$key] ['reviseDetail'] = array ();
  4980. if (! empty ( $value ['reviseDetail'] ))
  4981. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4982. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4983. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4984. $categoryDetil = $Lcategory->getOne ( array (
  4985. 'where' => 'cid=' . $value ['cid'],
  4986. 'asArray' => true
  4987. ) );
  4988. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4989. $executeList = json_decode ( $value ['executeCopy'], true );
  4990. $executeStaff = array ();
  4991. if (! empty ( $value ['executeStaff'] ))
  4992. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4993. if (isset ( $executeList )) {
  4994. foreach ( $executeList as $op => $lo ) {
  4995. $executeList [$op] ['date'] = "";
  4996. $executeList [$op] ['opinion'] = "";
  4997. $executeList [$op] ['status'] = "";
  4998. foreach ( $executeStaff as $m => $u ) {
  4999. if ($lo [0] == $m) {
  5000. $executeList [$op] ['date'] = $u ['date'];
  5001. $executeList [$op] ['opinion'] = $u ['opinion'];
  5002. $executeList [$op] ['status'] = $u ['status'];
  5003. break;
  5004. }
  5005. }
  5006. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5007. $button2 = 1;
  5008. $executeList [$op] ['status'] = 4;
  5009. }
  5010. }
  5011. }
  5012. // 检测编辑状态
  5013. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5014. $verifyList ['staff'] = $value ['verifyBreakup'];
  5015. } else
  5016. $verifyList = $verify->getOne ( array (
  5017. 'where' => 'vid=' . $value ['verify'],
  5018. 'asArray' => true
  5019. ) );
  5020. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5021. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5022. Doo::loadModel ( 'role' );
  5023. $role = new role ();
  5024. if ($verifyList == NULL)
  5025. $verifyList = array ();
  5026. $flag = true;
  5027. $roleKey = 0;
  5028. $endStaffArray = array ();
  5029. $roleArrayCopy = array ();
  5030. foreach ( $verifyList as $k => $v ) {
  5031. // init verifyStaff
  5032. if ($v [1] == 'ROLE') {
  5033. if (! empty ( $verifyStaff )) {
  5034. $endStaffArray = end ( $verifyStaff );
  5035. // if ($v[0]==$endStaffArray['nextStaff']){
  5036. // $roleId=$v[0];
  5037. // }
  5038. }
  5039. $roleVerify = json_decode ( $v [3], true );
  5040. $roleKey = $k;
  5041. $roleArray = array ();
  5042. $rolename = $role->getOne ( array (
  5043. 'where' => 'rid=' . $v [0],
  5044. 'asArray' => true
  5045. ) );
  5046. foreach ( $roleVerify as $o => $p ) {
  5047. $staffID = explode ( '_', $p );
  5048. $staffInfo = $staff->getOne ( array (
  5049. 'where' => 'sid=' . $staffID [0],
  5050. 'asArray' => true
  5051. ) );
  5052. // print_r($staffID);
  5053. $exp = array (
  5054. 0 => $staffInfo ['sid'],
  5055. 1 => $staffID [1],
  5056. 2 => $staffInfo ['avatar'],
  5057. 'date' => '',
  5058. 'date' => '',
  5059. 'opinion' => '',
  5060. 'status' => '',
  5061. 'rolename' => $rolename ['name']
  5062. );
  5063. array_push ( $roleArray, $exp );
  5064. }
  5065. $roleArrayCopy [$v [0]] = $roleArray;
  5066. // $verifyList[$k]['roleArray']=$roleArray;
  5067. }
  5068. $verifyList [$k] ['date'] = "";
  5069. $verifyList [$k] ['opinion'] = "";
  5070. $verifyList [$k] ['status'] = "";
  5071. if (empty ( $verifyStaff )) {
  5072. $verifyList [$k] ['date'] = "";
  5073. $verifyList [$k] ['opinion'] = "";
  5074. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5075. $verifyList [$k] ['status'] = 4;
  5076. $flag = false;
  5077. }
  5078. } else {
  5079. foreach ( $verifyStaff as $m => $u ) {
  5080. if ($v [0] == $m) {
  5081. $verifyList [$k] ['date'] = $u ['date'];
  5082. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5083. $verifyList [$k] ['status'] = $u ['status'];
  5084. $flag = false;
  5085. break;
  5086. }
  5087. }
  5088. $endStaffArray = end ( $verifyStaff );
  5089. if (isset ( $endStaffArray ['ROLE'] )) {
  5090. } else {
  5091. // $endKey=key($verifyStaff);
  5092. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5093. // $button=4;
  5094. // $verifyList[$k]['status']=4;
  5095. // }
  5096. }
  5097. }
  5098. }
  5099. $rolename ['name'] = '';
  5100. if (! empty ( $roleId )) {
  5101. Doo::loadModel ( 'role' );
  5102. $role = new role ();
  5103. $rolename = $role->getOne ( array (
  5104. 'where' => 'rid=' . $roleId,
  5105. 'asArray' => true
  5106. ) );
  5107. }
  5108. if (! empty ( $verifyStaff ))
  5109. $endStaffArray = end ( $verifyStaff );
  5110. $KOP = false;
  5111. foreach ( $roleArrayCopy as $P => $A ) {
  5112. foreach ( $A as $MKI => $AVL ) {
  5113. if (! empty ( $verifyStaff )) {
  5114. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5115. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5116. $button = 4;
  5117. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5118. }
  5119. foreach ( $verifyStaff as $m => $u ) {
  5120. $AVLFK = $AVL [0] . '_R';
  5121. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5122. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5123. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5124. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5125. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5126. break;
  5127. }
  5128. }
  5129. } else {
  5130. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5131. $button = 4;
  5132. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5133. }
  5134. }
  5135. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5136. $KOP = true;
  5137. }
  5138. }
  5139. foreach ( $roleArrayCopy as $k => $v ) {
  5140. foreach ( $verifyList as $m => $n ) {
  5141. if ($n [0] == $k) {
  5142. array_splice ( $verifyList, $m, 1, $v );
  5143. }
  5144. }
  5145. }
  5146. $receiptList [$key] ['verifyList'] = $verifyList;
  5147. $receiptList [$key] ['executeList'] = $executeList;
  5148. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5149. 'where' => 'sid=' . $value ['staff'],
  5150. 'asArray' => true
  5151. ) );
  5152. $receiptList [$key] ['button2'] = $button2;
  5153. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5154. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5155. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5156. $receiptList [$key] ['relust'] = $relust;
  5157. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  5158. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  5159. }
  5160. //执行人是否是最后一位
  5161. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  5162. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  5163. $executePrimary=count($executeCopy)-1;
  5164. $lastOne=true;
  5165. if($executePrimary!=count($executeStaff)){
  5166. $lastOne=false;
  5167. }
  5168. $data['lastOne']=$lastOne;
  5169. // 是否写入过流水
  5170. $accountType = 0;
  5171. if ($receiptList [0] ['Rtype'] == 0) {
  5172. $accountType = 3;
  5173. } elseif ($receiptList [0] ['Rtype'] == 1) {
  5174. if (!empty($receiptList [0]['accountItem']) )
  5175. $accountType = 2;
  5176. else
  5177. $accountType = 1;
  5178. } elseif ($receiptList [0] ['Rtype'] == 2) {
  5179. $accountType = 4;
  5180. } elseif ($receiptList [0] ['Rtype'] == 3) {
  5181. $accountType = 12;
  5182. }
  5183. Doo::loadModel ( 'wasteBook' );
  5184. $wasteBook = new wasteBook ();
  5185. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  5186. $data ['wbDetail'] = $wbDetail;
  5187. $wbDetailLoan=array();
  5188. if ($accountType==2){
  5189. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  5190. }
  5191. $data ['wbDetailLoan'] = $wbDetailLoan;
  5192. $data['inputDate']=date ( "Y-m-d H:i:s" );
  5193. //print_r($wbDetail);
  5194. $data ['receiptList'] = $receiptList;
  5195. $data ['memu'] = "receipt";
  5196. $data ['staff'] = $this->staff;
  5197. $data ['receiptMemu'] = 'implement';
  5198. $data ['verifyId'] = $this->verifyId;
  5199. $data ['executeId'] = $this->executeId;
  5200. if ($Rtype=="loan"){
  5201. $this->render ( "/receipt/receiptImplementLoan", $data );
  5202. }elseif($Rtype=="receipt"){
  5203. $this->render ( "/receipt/receiptImplement", $data );
  5204. }elseif($Rtype=="public"){
  5205. $this->render ( "/receipt/receiptImplementPublic", $data );
  5206. }else{
  5207. //$this->render ( "/admin/implement", $data );
  5208. }
  5209. }
  5210. function implementDo() {
  5211. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  5212. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5213. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  5214. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  5215. // $ab = '';
  5216. // if ($accountBank == 'CGBDeposit')
  5217. // $ab = '纵横广发';
  5218. // elseif ($accountBank == 'ICBCDeposit')
  5219. // $ab = '纵横工行';
  5220. // elseif ($accountBank == 'HUADeposit')
  5221. // $ab = '华润银行';
  5222. // elseif ($accountBank == 'PersonalDeposit')
  5223. // $ab = '个人广发';
  5224. // if (empty ( $ab ))
  5225. // die ( 'illegal request--22' );
  5226. if (! empty ( $rid )) {
  5227. Doo::loadModel ( 'receipt' );
  5228. $receipt = new receipt ();
  5229. Doo::loadClass ( 'XDeode' );
  5230. $XDeode = new XDeode ( 5 );
  5231. $rid=$XDeode->decode($rid);
  5232. if (!is_numeric($rid)){
  5233. die;
  5234. }
  5235. // $rinfo = $receipt->getOne ( array (
  5236. // 'where' => 'rid=' . $rid,
  5237. // 'asArray' => true
  5238. // ) );
  5239. $rinfo = $receipt->getReceiptByRid ( $rid );
  5240. // $accountType = '';
  5241. // if ($rinfo ['Rtype'] == 1) {
  5242. // if ($rinfo ['loanRid'] != 0)//判断有问题
  5243. // $accountType = 2;
  5244. // else
  5245. // $accountType = 1;
  5246. // } elseif ($rinfo ['Rtype'] == 2) {
  5247. // $accountType = 4;
  5248. // } elseif ($rinfo ['Rtype'] == 0)
  5249. // $accountType = 3;
  5250. // if (empty ( $accountType ))
  5251. // die ( 'illegal request' );
  5252. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  5253. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  5254. if (empty ( $executeStaff )) {
  5255. $executeStaff = array (
  5256. $this->staff [0] ['sid'] => array (
  5257. 'date' => date ( 'Y-m-d' ),
  5258. 'opinion' => $implementOpinions,
  5259. 'status' => 1
  5260. )
  5261. );
  5262. } else {
  5263. $executeStaff [$this->staff [0] ['sid']] = array (
  5264. 'date' => date ( 'Y-m-d' ),
  5265. 'opinion' => $implementOpinions,
  5266. 'status' => 1
  5267. );
  5268. }
  5269. if (count ( $executeStaff ) == count ( $executeCopy )) {
  5270. $receipt->executeStaff = json_encode ( $executeStaff );
  5271. $receipt->status = 8;
  5272. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  5273. $receipt->status = 9;
  5274. if ($rinfo ['status'] == 6) {
  5275. $receipt->loanDate = date ( "Y-m-d" );
  5276. }
  5277. $receipt->executeDate = date ( "Y-m-d" );
  5278. } else {
  5279. $receipt->executeStaff = json_encode ( $executeStaff );
  5280. }
  5281. //$receipt->amount = $amount;
  5282. $receipt->update ( array (
  5283. 'where' => 'rid=' . $rid
  5284. ) );
  5285. // 公司流水记录
  5286. // Doo::loadModel ( 'wasteBook' );
  5287. // $wasteBook = new wasteBook ();
  5288. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  5289. // // 银行
  5290. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  5291. // $item = array (
  5292. // 'dataID' => $rid,
  5293. // 'expensesType' => 2,
  5294. // 'accountType' => $accountType,
  5295. // 'accountPriceShow' => $amount,
  5296. // 'accountPrice' => - $amount,
  5297. // 'accountBank' => $accountBank,
  5298. // 'category' => $rinfo ['category'] [0] ['title'],
  5299. // 'cid' => $rinfo ['category'] [0] ['cid'],
  5300. // 'name' => $rinfo ['staffDetail'] ['username'],
  5301. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  5302. // 'inputDate' => date ( "Y-m-d H:i:s" )
  5303. // );
  5304. // $wasteBook->setAccountBookStatistics ( $item );
  5305. // }
  5306. }
  5307. //$ridKey = $XDeode->encode ( $rid );
  5308. return "/hisImplement";
  5309. // return "/implement/" . $ridKey . ".html";
  5310. }
  5311. function receiptburEdi() {
  5312. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5313. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5314. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5315. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5316. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5317. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5318. if (empty ( $status ))
  5319. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5320. $vidList = array ();
  5321. $button = 0;
  5322. Doo::loadModel ( 'verify' );
  5323. Doo::loadModel ( 'receipt' );
  5324. Doo::loadModel ( 'staff' );
  5325. $staff = new staff ();
  5326. $receipt = new receipt ();
  5327. $verify = new verify ();
  5328. Doo::loadModel ( 'L_category' );
  5329. $Lcategory = new L_category ();
  5330. Doo::loadModel ( 'enclosur' );
  5331. $enclosur = new enclosur ();
  5332. Doo::loadModel ( 'loanReceipt' );
  5333. $loanReceipt = new loanReceipt ();
  5334. // user verify ID
  5335. $verifyDetail = $verify->find ( array (
  5336. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5337. 'asArray' => true
  5338. ) );
  5339. foreach ( $verifyDetail as $key => $value ) {
  5340. array_push ( $vidList, $value ['vid'] );
  5341. }
  5342. $vid = implode ( ",", $vidList );
  5343. if (empty ( $verifyDetail ))
  5344. $vid = 0;
  5345. $categoryList = $Lcategory->find ( array (
  5346. 'asArray' => true
  5347. ) );
  5348. $staffList = $staff->find ( array (
  5349. 'where' => 'cid=' . $cid,
  5350. 'asArray' => true
  5351. ) );
  5352. $ap = "";
  5353. if ($status == 4) {
  5354. $ap = 4;
  5355. $status = 2;
  5356. }
  5357. // get Receipt By verifyID status 2
  5358. $receiptList = $receipt->find ( array (
  5359. 'where' => 'rid =' . $rid . ' and status=2',
  5360. 'desc' => 'rid',
  5361. 'asArray' => true
  5362. ) );
  5363. if (empty ( $receiptList )) {
  5364. die ( 'illegal request' );
  5365. }
  5366. $loanList = $loanReceipt->find ( array (
  5367. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5368. 'desc' => 'rid',
  5369. 'asArray' => true
  5370. ) );
  5371. $data ['explanation'] = '';
  5372. if (! empty ( $loanList ))
  5373. $data ['explanation'] = $loanList [0] ['explanation'];
  5374. $Locate = 0;
  5375. $roleId = 0;
  5376. $button = 0;
  5377. foreach ( $loanList as $key => $value ) {
  5378. $loanList [$key] ['Locate'] = $Locate;
  5379. $Locate ++;
  5380. $loanList [$key] ['reviseDetail'] = array ();
  5381. if (! empty ( $value ['reviseDetail'] ))
  5382. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5383. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5384. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5385. $categoryDetil = $Lcategory->getOne ( array (
  5386. 'where' => 'cid=' . $value ['cid'],
  5387. 'asArray' => true
  5388. ) );
  5389. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5390. // 检测编辑状态
  5391. $verifyList = $verify->getOne ( array (
  5392. 'where' => 'vid=' . $value ['verify'],
  5393. 'asArray' => true
  5394. ) );
  5395. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5396. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5397. Doo::loadModel ( 'role' );
  5398. $role = new role ();
  5399. $flag = true;
  5400. $roleKey = 0;
  5401. $endStaffArray = array ();
  5402. $roleArrayCopy = array ();
  5403. foreach ( $verifyList as $k => $v ) {
  5404. // init verifyStaff
  5405. if ($v [1] == 'ROLE') {
  5406. if (! empty ( $verifyStaff )) {
  5407. $endStaffArray = end ( $verifyStaff );
  5408. }
  5409. $roleVerify = json_decode ( $v [3], true );
  5410. $roleKey = $k;
  5411. $roleArray = array ();
  5412. $rolename = $role->getOne ( array (
  5413. 'where' => 'rid=' . $v [0],
  5414. 'asArray' => true
  5415. ) );
  5416. foreach ( $roleVerify as $o => $p ) {
  5417. $staffID = explode ( '_', $p );
  5418. $staffInfo = $staff->getOne ( array (
  5419. 'where' => 'sid=' . $staffID [0],
  5420. 'asArray' => true
  5421. ) );
  5422. // print_r($staffID);
  5423. $exp = array (
  5424. 0 => $staffInfo ['sid'],
  5425. 1 => $staffID [1],
  5426. 2 => $staffInfo ['avatar'],
  5427. 'date' => '',
  5428. 'date' => '',
  5429. 'opinion' => '',
  5430. 'status' => '',
  5431. 'rolename' => $rolename ['name']
  5432. );
  5433. array_push ( $roleArray, $exp );
  5434. }
  5435. $roleArrayCopy [$v [0]] = $roleArray;
  5436. // $verifyList[$k]['roleArray']=$roleArray;
  5437. }
  5438. $verifyList [$k] ['date'] = "";
  5439. $verifyList [$k] ['opinion'] = "";
  5440. $verifyList [$k] ['status'] = "";
  5441. if (empty ( $verifyStaff )) {
  5442. $verifyList [$k] ['date'] = "";
  5443. $verifyList [$k] ['opinion'] = "";
  5444. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5445. $verifyList [$k] ['status'] = 4;
  5446. $flag = false;
  5447. }
  5448. } else {
  5449. foreach ( $verifyStaff as $m => $u ) {
  5450. if ($v [0] == $m) {
  5451. $verifyList [$k] ['date'] = $u ['date'];
  5452. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5453. $verifyList [$k] ['status'] = $u ['status'];
  5454. $flag = false;
  5455. break;
  5456. }
  5457. }
  5458. $endStaffArray = end ( $verifyStaff );
  5459. if (isset ( $endStaffArray ['ROLE'] )) {
  5460. } else {
  5461. }
  5462. }
  5463. }
  5464. $rolename ['name'] = '';
  5465. if (! empty ( $roleId )) {
  5466. Doo::loadModel ( 'role' );
  5467. $role = new role ();
  5468. $rolename = $role->getOne ( array (
  5469. 'where' => 'rid=' . $roleId,
  5470. 'asArray' => true
  5471. ) );
  5472. }
  5473. if (! empty ( $verifyStaff ))
  5474. $endStaffArray = end ( $verifyStaff );
  5475. $KOP = false;
  5476. foreach ( $roleArrayCopy as $P => $A ) {
  5477. foreach ( $A as $MKI => $AVL ) {
  5478. if (! empty ( $verifyStaff )) {
  5479. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5480. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5481. $button = 4;
  5482. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5483. }
  5484. foreach ( $verifyStaff as $m => $u ) {
  5485. $AVLFK = $AVL [0] . '_R';
  5486. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5487. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5488. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5489. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5490. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5491. break;
  5492. }
  5493. }
  5494. } else {
  5495. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5496. $button = 4;
  5497. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5498. }
  5499. }
  5500. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5501. $KOP = true;
  5502. }
  5503. }
  5504. foreach ( $roleArrayCopy as $k => $v ) {
  5505. foreach ( $verifyList as $m => $n ) {
  5506. if ($n [0] == $k) {
  5507. array_splice ( $verifyList, $m, 1, $v );
  5508. }
  5509. }
  5510. }
  5511. $loanList [$key] ['verifyList'] = $verifyList;
  5512. }
  5513. $htmlLoan = '';
  5514. $data ['loanReceiptDate'] = '';
  5515. if (isset ( $loanList [0] )) {
  5516. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  5517. if ($value ['status'] == 1)
  5518. $htmlLoan .= '<li class="done" >';
  5519. elseif ($value ['status'] == 3)
  5520. $htmlLoan .= '<li class="undone" >';
  5521. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  5522. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  5523. if (isset ( $value ['rolename'] ))
  5524. $htmlLoan .= $value ['rolename'];
  5525. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  5526. }
  5527. $data ['loanDate'] = $loanList [0] ['date'];
  5528. } else {
  5529. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  5530. }
  5531. $data ['htmlLoan'] = $htmlLoan;
  5532. // $data ['LoanReceipt']=$loanList[0];
  5533. // print_r($loanList);
  5534. $Locate = 0;
  5535. $roleId = 0;
  5536. $button = 0;
  5537. if ($ap == 4)
  5538. $status = 4;
  5539. Doo::loadClass ( 'XDeode' );
  5540. $XDeode = new XDeode ( 5 );
  5541. foreach ( $receiptList as $key => $value ) {
  5542. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5543. $receiptList [$key] ['Locate'] = $Locate;
  5544. $Locate ++;
  5545. $receiptList [$key] ['reviseDetail'] = array ();
  5546. // 调整金额 代码调整
  5547. if (! empty ( $value ['reviseDetail'] )) {
  5548. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  5549. foreach ( $reviseDetail as $ry => $re ) {
  5550. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  5551. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  5552. }
  5553. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  5554. // print_r($reviseDetail);
  5555. }
  5556. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5557. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5558. $categoryDetil = $Lcategory->getOne ( array (
  5559. 'where' => 'cid=' . $value ['cid'],
  5560. 'asArray' => true
  5561. ) );
  5562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5563. // 检测编辑状态
  5564. $verifyList = $verify->getOne ( array (
  5565. 'where' => 'vid=' . $value ['verify'],
  5566. 'asArray' => true
  5567. ) );
  5568. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5569. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5570. Doo::loadModel ( 'role' );
  5571. $role = new role ();
  5572. // print_r($verifyList);
  5573. $flag = true;
  5574. $roleKey = 0;
  5575. $endStaffArray = array ();
  5576. $roleArrayCopy = array ();
  5577. foreach ( $verifyList as $k => $v ) {
  5578. // init verifyStaff
  5579. if ($v [1] == 'ROLE') {
  5580. if (! empty ( $verifyStaff )) {
  5581. $endStaffArray = end ( $verifyStaff );
  5582. if ($v [0] == $endStaffArray ['nextStaff']) {
  5583. $roleId = $v [0];
  5584. }
  5585. }
  5586. $roleVerify = json_decode ( $v [3], true );
  5587. $roleKey = $k;
  5588. $roleArray = array ();
  5589. $rolename = $role->getOne ( array (
  5590. 'where' => 'rid=' . $v [0],
  5591. 'asArray' => true
  5592. ) );
  5593. foreach ( $roleVerify as $o => $p ) {
  5594. $staffID = explode ( '_', $p );
  5595. $staffInfo = $staff->getOne ( array (
  5596. 'where' => 'sid=' . $staffID [0],
  5597. 'asArray' => true
  5598. ) );
  5599. // print_r($staffID);
  5600. $exp = array (
  5601. 0 => $staffInfo ['sid'],
  5602. 1 => $staffID [1],
  5603. 2 => $staffInfo ['avatar'],
  5604. 'date' => '',
  5605. 'date' => '',
  5606. 'opinion' => '',
  5607. 'status' => '',
  5608. 'rolename' => $rolename ['name']
  5609. );
  5610. array_push ( $roleArray, $exp );
  5611. }
  5612. $roleArrayCopy [$v [0]] = $roleArray;
  5613. // $verifyList[$k]['roleArray']=$roleArray;
  5614. }
  5615. // print_r($roleArray);
  5616. $verifyList [$k] ['date'] = "";
  5617. $verifyList [$k] ['opinion'] = "";
  5618. $verifyList [$k] ['status'] = "";
  5619. if (empty ( $verifyStaff )) {
  5620. $verifyList [$k] ['date'] = "";
  5621. $verifyList [$k] ['opinion'] = "";
  5622. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5623. $verifyList [$k] ['status'] = 4;
  5624. $button = 4;
  5625. $flag = false;
  5626. }
  5627. } else {
  5628. foreach ( $verifyStaff as $m => $u ) {
  5629. if ($v [0] == $m) {
  5630. $verifyList [$k] ['date'] = $u ['date'];
  5631. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5632. $verifyList [$k] ['status'] = $u ['status'];
  5633. $flag = false;
  5634. break;
  5635. }
  5636. }
  5637. $endStaffArray = end ( $verifyStaff );
  5638. if (isset ( $endStaffArray ['ROLE'] )) {
  5639. } else {
  5640. $endKey = key ( $verifyStaff );
  5641. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5642. $button = 4;
  5643. $verifyList [$k] ['status'] = 4;
  5644. }
  5645. }
  5646. }
  5647. }
  5648. $rolename ['name'] = '';
  5649. if (! empty ( $roleId )) {
  5650. Doo::loadModel ( 'role' );
  5651. $role = new role ();
  5652. $rolename = $role->getOne ( array (
  5653. 'where' => 'rid=' . $roleId,
  5654. 'asArray' => true
  5655. ) );
  5656. }
  5657. if (! empty ( $verifyStaff ))
  5658. $endStaffArray = end ( $verifyStaff );
  5659. $KOP = false;
  5660. foreach ( $roleArrayCopy as $P => $A ) {
  5661. foreach ( $A as $MKI => $AVL ) {
  5662. if (! empty ( $verifyStaff )) {
  5663. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5664. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5665. $button = 4;
  5666. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5667. }
  5668. foreach ( $verifyStaff as $m => $u ) {
  5669. $AVLFK = $AVL [0] . '_R';
  5670. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5671. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5672. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5673. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5674. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5675. break;
  5676. }
  5677. }
  5678. } else {
  5679. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5680. $button = 4;
  5681. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5682. }
  5683. }
  5684. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5685. $KOP = true;
  5686. }
  5687. }
  5688. foreach ( $roleArrayCopy as $k => $v ) {
  5689. foreach ( $verifyList as $m => $n ) {
  5690. if ($n [0] == $k) {
  5691. array_splice ( $verifyList, $m, 1, $v );
  5692. }
  5693. }
  5694. }
  5695. // print_r($verifyList);
  5696. $receiptList [$key] ['verifyList'] = $verifyList;
  5697. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5698. 'where' => 'sid=' . $value ['staff'],
  5699. 'asArray' => true
  5700. ) );
  5701. $receiptList [$key] ['button'] = $button;
  5702. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5703. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5704. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5705. $receiptList [$key] ['relust'] = $relust;
  5706. $receiptList [$key] ['relustABS'] = abs ( $relust );
  5707. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5708. }
  5709. //print_r($receiptList);die;
  5710. // $data['verifyDetail']=$verifyDetail;
  5711. $mothHtml = "";
  5712. for($i = 1; $i <= 12; $i ++) {
  5713. if ($month == $i)
  5714. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5715. else
  5716. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5717. }
  5718. // 获取审批日志
  5719. Doo::loadModel ( 'receiptLog' );
  5720. $receiptLog = new receiptLog ();
  5721. $rlList = array ();
  5722. $rlInfo = $receiptLog->getOne ( array (
  5723. 'where' => 'rid=' . $rid . ' and status=4',
  5724. 'asArray' => true
  5725. ) );
  5726. $tijdate = $receiptLog->getOne ( array (
  5727. 'where' => 'rid=' . $rid . ' and status=2',
  5728. 'asc' => 'rlid',
  5729. 'asArray' => true
  5730. ) );
  5731. if (! empty ( $rlInfo )) {
  5732. $rlList = $receiptLog->find ( array (
  5733. 'where' => 'rid=' . $rid,
  5734. 'asc' => 'rlid',
  5735. 'asArray' => true
  5736. ) );
  5737. }
  5738. // echo $rid;
  5739. // print_r($receiptList);
  5740. $receiptList [0] ['rlList'] = $rlList;
  5741. // print_r($receiptList);
  5742. $enclosurList = $enclosur->find ( array (
  5743. 'where' => 'rid=' . $rid,
  5744. 'asArray' => true
  5745. ) );
  5746. $enclosurHtml = '';
  5747. foreach ( $enclosurList as $value ) {
  5748. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5749. }
  5750. $data ['enclosurHtml'] = $enclosurHtml;
  5751. $data ['rolename'] = $rolename ['name'];
  5752. $data ['mothHtml'] = $mothHtml;
  5753. // print_r($receiptList);
  5754. $data ['rid'] = $rid;
  5755. $data ['tijdate'] = $tijdate ['date'];
  5756. $data ['receiptList'] = $receiptList;
  5757. $data ['receiptApprovalCount'] = count ( $receiptList );
  5758. $data ['status'] = $status;
  5759. $data ['year'] = $year;
  5760. $data ['categoryList'] = $categoryList;
  5761. $data ['staffList'] = $staffList;
  5762. $data ['cid'] = $cid;
  5763. $data ['sid'] = $sid;
  5764. $data ['ap'] = $ap;
  5765. $data ['memu'] = "receipt";
  5766. $data ['staff'] = $this->staff;
  5767. $data ['receiptMemu'] = 'approvalExpenses';
  5768. $data ['verifyId'] = $this->verifyId;
  5769. $data ['executeId'] = $this->executeId;
  5770. $this->render ( "/admin/receiptburEdi", $data );
  5771. }
  5772. function hisImplement() {
  5773. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  5774. if (empty ( $item ))
  5775. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  5776. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5777. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  5778. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  5779. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  5780. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  5781. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  5782. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  5783. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  5784. Doo::loadClass ( 'XDeode' );
  5785. $XDeode = new XDeode ( 5 );
  5786. Doo::loadModel ( 'receipt' );
  5787. $receipt = new receipt ();
  5788. Doo::loadModel ( 'L_category' );
  5789. $Lcategory = new L_category ();
  5790. Doo::loadModel ( 'verify' );
  5791. Doo::loadModel ( 'statistics' );
  5792. $statistics = new statistics ();
  5793. $verify = new verify ();
  5794. Doo::loadModel ( 'staff' );
  5795. $staff = new staff ();
  5796. Doo::loadClass ( 'XDeode' );
  5797. $XDeode = new XDeode ( 5 );
  5798. $XDeode7 = new XDeode ( 7 );
  5799. $cid = $XDeode->decode ( $cidKey );
  5800. $condition = "";
  5801. if ($item == "expenses")
  5802. $condition = " and Rtype=1 ";
  5803. elseif ($item == "receipts")
  5804. $condition = " and Rtype=0 ";
  5805. elseif ($item == "remits")
  5806. $condition = " and Rtype=2 ";
  5807. elseif($item == "train")
  5808. $condition = " and Rtype=3 ";
  5809. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  5810. $sopString = $cidString = "";
  5811. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  5812. if (empty ( $rdate ))
  5813. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  5814. else
  5815. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  5816. if ($status == 'pendImplement') {
  5817. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" ) ';
  5818. } elseif ($status == 'alerpts') {
  5819. $statusCon = '(status=8 or status=9 )';
  5820. if (empty ( $rdate ))
  5821. $dateCondition .= " and Year(date) =" . $year;
  5822. else
  5823. $dateCondition .= " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  5824. }
  5825. if ($sop != 'SOP')
  5826. $sopString = " and staff=" . $sop;
  5827. if ($cidKey != 'ALL')
  5828. $cidString = " and cid=" . $cid;
  5829. if(!empty($receiptOrder)){
  5830. $receiptList = $receipt->find ( array (
  5831. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5832. 'desc' => 'rid',
  5833. 'asArray' => true
  5834. ) );
  5835. // 员工筛选
  5836. $receiptList2 = $receipt->find ( array (
  5837. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  5838. 'desc' => 'rid',
  5839. 'asArray' => true
  5840. ) );
  5841. }else{
  5842. $receiptList = $receipt->find ( array (
  5843. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  5844. 'desc' => 'rid',
  5845. 'asArray' => true
  5846. ) );
  5847. // 员工筛选
  5848. $receiptList2 = $receipt->find ( array (
  5849. 'where' => $statusCon . $condition . $dateCondition,
  5850. 'desc' => 'rid',
  5851. 'asArray' => true
  5852. ) );
  5853. }
  5854. $sopStaff = array ();
  5855. foreach ( $receiptList2 as $key => $value ) {
  5856. $staffDetail = $staff->getOne ( array (
  5857. 'select' => 'username',
  5858. 'where' => 'sid=' . $value ['staff'],
  5859. 'asArray' => true
  5860. ) );
  5861. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  5862. }
  5863. // 办事处筛选
  5864. $categoryScreen = array ();
  5865. $categorList = $Lcategory->getCategory ();
  5866. foreach ( $receiptList2 as $key => $value ) {
  5867. foreach ( $categorList as $k => $v ) {
  5868. if ($value ['cid'] == $v ['cid']) {
  5869. $categoryScreen [$v ['cidKey']] = $v ['title'];
  5870. break;
  5871. }
  5872. }
  5873. }
  5874. $categoryScreenHtml = "";
  5875. foreach ( $categoryScreen as $key => $value ) {
  5876. if ($cidKey == $key)
  5877. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  5878. else
  5879. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  5880. }
  5881. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  5882. $data ['cidKey'] = $cidKey;
  5883. $Locate = 0;
  5884. $roleId = 0;
  5885. $button = 0;
  5886. $staffBatchNumber = 100001;
  5887. $remittanceList = array ();
  5888. foreach ( $receiptList as $key => $value ) {
  5889. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  5890. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  5891. $receiptList [$key] ['Texe'] = 'false';
  5892. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  5893. $receiptList [$key] ['Texe'] = 'true';
  5894. }
  5895. $receiptList [$key] ['TRexe'] = 'true';
  5896. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  5897. $receiptList [$key] ['TRexe'] = 'false';
  5898. }
  5899. $receiptList [$key] ['Locate'] = $Locate;
  5900. $Locate ++;
  5901. $receiptList [$key] ['reviseDetail'] = array ();
  5902. if (! empty ( $value ['reviseDetail'] ))
  5903. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5904. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5905. $categoryDetil = $Lcategory->getOne ( array (
  5906. 'where' => 'cid=' . $value ['cid'],
  5907. 'asArray' => true
  5908. ) );
  5909. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5910. // 检测编辑状态
  5911. $verifyList = $verify->getOne ( array (
  5912. 'where' => 'vid=' . $value ['verify'],
  5913. 'asArray' => true
  5914. ) );
  5915. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5916. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5917. Doo::loadModel ( 'role' );
  5918. $role = new role ();
  5919. $flag = true;
  5920. $roleKey = 0;
  5921. $endStaffArray = array ();
  5922. $roleArrayCopy = array ();
  5923. foreach ( $verifyList as $k => $v ) {
  5924. // init verifyStaff
  5925. if ($v [1] == 'ROLE') {
  5926. if (! empty ( $verifyStaff )) {
  5927. $endStaffArray = end ( $verifyStaff );
  5928. }
  5929. $roleVerify = json_decode ( $v [3], true );
  5930. $roleKey = $k;
  5931. $roleArray = array ();
  5932. $rolename = $role->getOne ( array (
  5933. 'where' => 'rid=' . $v [0],
  5934. 'asArray' => true
  5935. ) );
  5936. foreach ( $roleVerify as $o => $p ) {
  5937. $staffID = explode ( '_', $p );
  5938. $staffInfo = $staff->getOne ( array (
  5939. 'where' => 'sid=' . $staffID [0],
  5940. 'asArray' => true
  5941. ) );
  5942. $exp = array (
  5943. 0 => $staffInfo ['sid'],
  5944. 1 => $staffID [1],
  5945. 2 => $staffInfo ['avatar'],
  5946. 'date' => '',
  5947. 'date' => '',
  5948. 'opinion' => '',
  5949. 'status' => '',
  5950. 'rolename' => $rolename ['name']
  5951. );
  5952. array_push ( $roleArray, $exp );
  5953. }
  5954. $roleArrayCopy [$v [0]] = $roleArray;
  5955. }
  5956. $verifyList [$k] ['date'] = "";
  5957. $verifyList [$k] ['opinion'] = "";
  5958. $verifyList [$k] ['status'] = "";
  5959. if (empty ( $verifyStaff )) {
  5960. $verifyList [$k] ['date'] = "";
  5961. $verifyList [$k] ['opinion'] = "";
  5962. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5963. $verifyList [$k] ['status'] = 4;
  5964. $flag = false;
  5965. }
  5966. } else {
  5967. foreach ( $verifyStaff as $m => $u ) {
  5968. if ($v [0] == $m) {
  5969. $verifyList [$k] ['date'] = $u ['date'];
  5970. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5971. $verifyList [$k] ['status'] = $u ['status'];
  5972. $flag = false;
  5973. break;
  5974. }
  5975. }
  5976. $endStaffArray = end ( $verifyStaff );
  5977. }
  5978. }
  5979. $rolename ['name'] = '';
  5980. if (! empty ( $roleId )) {
  5981. Doo::loadModel ( 'role' );
  5982. $role = new role ();
  5983. $rolename = $role->getOne ( array (
  5984. 'where' => 'rid=' . $roleId,
  5985. 'asArray' => true
  5986. ) );
  5987. }
  5988. if (! empty ( $verifyStaff ))
  5989. $endStaffArray = end ( $verifyStaff );
  5990. $KOP = false;
  5991. foreach ( $roleArrayCopy as $P => $A ) {
  5992. foreach ( $A as $MKI => $AVL ) {
  5993. if (! empty ( $verifyStaff )) {
  5994. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5995. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5996. $button = 4;
  5997. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5998. }
  5999. foreach ( $verifyStaff as $m => $u ) {
  6000. $AVLFK = $AVL [0] . '_R';
  6001. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6002. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6003. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6004. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6005. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6006. break;
  6007. }
  6008. }
  6009. } else {
  6010. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6011. $button = 4;
  6012. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6013. }
  6014. }
  6015. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6016. $KOP = true;
  6017. }
  6018. }
  6019. foreach ( $roleArrayCopy as $k => $v ) {
  6020. foreach ( $verifyList as $m => $n ) {
  6021. if ($n [0] == $k) {
  6022. array_splice ( $verifyList, $m, 1, $v );
  6023. }
  6024. }
  6025. }
  6026. $receiptList [$key] ['verifyList'] = $verifyList;
  6027. $staffDetail = $staff->getOne ( array (
  6028. 'where' => 'sid=' . $value ['staff'],
  6029. 'asArray' => true
  6030. ) );
  6031. $receiptList [$key] ['staffDetail'] = $staffDetail;
  6032. $receiptList [$key] ['button'] = $button;
  6033. if ($value['Rtype']==1){
  6034. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  6035. $receiptList [$key] ['relustABS'] = abs($receiptList [$key] ['relust']);
  6036. }elseif($value['Rtype']==3){
  6037. // 收入合计
  6038. Doo::loadModel ( 'invoiceTraining' );
  6039. $invoiceTraining = new invoiceTraining ();
  6040. $invoiceTrainingDetail = array (
  6041. 'invoiceArriveAmount' => '0.00',
  6042. 'RIAmount' => '0.00',
  6043. 'invoiceTotalAmount' => '0.00',
  6044. 'invoiceCompanyAmount' => '0.00',
  6045. 'invoiceArriveAmountM'=>'0.00',
  6046. 'invoiceCompanyAmountM'=>'0.00'
  6047. );
  6048. if ($value ['invoiceTrainId'] != 0) {
  6049. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  6050. }
  6051. $invoiceArriveAmount = $RIAmount = 0;
  6052. if (! empty ( $invoiceTrainingDetail )) {
  6053. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  6054. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  6055. }
  6056. // 备用金
  6057. $sum = 0;
  6058. if (! empty ( $value ['trainLoanRid'] )) {
  6059. $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  6060. $sum = $receiptLoanDetailBak ['sum'];
  6061. }
  6062. // 支出项金额详情
  6063. // 项目金额合计
  6064. Doo::loadModel ( 'RItem' );
  6065. $RItem = new RItem ();
  6066. Doo::loadModel ( 'accountItem' );
  6067. $accountItem = new accountItem ();
  6068. // 讲师获得
  6069. Doo::loadModel ( 'RILecturer' );
  6070. $RILecturer = new RILecturer ();
  6071. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  6072. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  6073. // 支出项金额详情
  6074. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  6075. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  6076. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  6077. $receiptList [$key] ['payment'] =$payment;
  6078. $receiptList [$key] ['paymentABS'] =abs($payment);
  6079. }
  6080. // 设置导出汇款execl
  6081. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  6082. $remittanceDetail = array (
  6083. $staffBatchNumber,
  6084. $value ['remittanceName'],
  6085. $value ['bankNumber'],
  6086. $value ['bankName'],
  6087. $value ['remittanceBankType'],
  6088. $value ['coupletNumber'],
  6089. $value ['sum']
  6090. );
  6091. array_push ( $remittanceList, $remittanceDetail );
  6092. $staffBatchNumber ++;
  6093. }
  6094. }
  6095. $data ['remittanceList'] = json_encode ( $remittanceList );
  6096. // print_r($receiptList);
  6097. $mothHtml = "";
  6098. for($i = 1; $i <= 12; $i ++) {
  6099. if ($moth == $i)
  6100. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6101. else
  6102. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6103. }
  6104. $dayHtml = "";
  6105. if ($day != "DAY" || $moth != "MONTH") {
  6106. for($i = 1; $i <= 31; $i ++) {
  6107. if ($day == $i)
  6108. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  6109. else
  6110. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  6111. }
  6112. }
  6113. $sopHtml = "";
  6114. foreach ( $sopStaff as $key => $value ) {
  6115. if ($sop == $key)
  6116. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6117. else
  6118. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6119. }
  6120. $data ['status'] = $status;
  6121. $data ['rdate'] = $rdate;
  6122. $data ['sopHtml'] = $sopHtml;
  6123. $data ['dayHtml'] = $dayHtml;
  6124. $data ['mothHtml'] = $mothHtml;
  6125. $data ['receiptList'] = $receiptList;
  6126. $data ['memu'] = "receipt";
  6127. $data ['staff'] = $this->staff;
  6128. $data ['receiptMemu'] = 'implement';
  6129. $data ['verifyId'] = $this->verifyId;
  6130. $data ['executeId'] = $this->executeId;
  6131. $data ['item'] = $item;
  6132. $data ['year'] = $year;
  6133. $data ['moth'] = $moth;
  6134. $data['receiptOrder']=$receiptOrder;
  6135. $data ['day'] = $day;
  6136. $data ['sop'] = $sop;
  6137. $this->render ( "/admin/hisImplement", $data );
  6138. }
  6139. /**
  6140. * 导出汇款信息的exelc
  6141. */
  6142. function exportRemittance() {
  6143. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  6144. if (empty ( $remittanceInfo ))
  6145. die ( 'illegal request' );
  6146. $title = array (
  6147. '员工编号',
  6148. '姓名',
  6149. '员工账号',
  6150. '员工账户开户行',
  6151. '转账类型',
  6152. '联行号',
  6153. '金额'
  6154. );
  6155. $data = json_decode ( $remittanceInfo, true );
  6156. if (empty ( $data ))
  6157. die ( 'illegal request' );
  6158. Doo::loadClass ( 'receipt.func' );
  6159. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  6160. header ( 'Content-Type:text/html;charset=utf-8' );
  6161. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  6162. }
  6163. function ajaxExamine() {
  6164. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  6165. Doo::loadModel ( 'receipt' );
  6166. $receipt = new receipt ();
  6167. if (! empty ( $rid )) {
  6168. $rLRes = $receipt->find ( array (
  6169. '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,
  6170. 'asArray' => true
  6171. ) );
  6172. echo json_encode ( array (
  6173. 'status' => 1,
  6174. 'receipt' => $rLRes [0]
  6175. ) );
  6176. die ();
  6177. }
  6178. echo json_encode ( array (
  6179. 'status' => 0,
  6180. 'receipt' => array ()
  6181. ) );
  6182. die ();
  6183. }
  6184. /*
  6185. * 废弃
  6186. */
  6187. function myReceipt() {
  6188. // all approval past withdraw
  6189. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6190. if (empty ( $item ))
  6191. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  6192. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6193. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  6194. Doo::loadModel ( 'receipt' );
  6195. $receipt = new receipt ();
  6196. // pre-loaded
  6197. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6198. // have cache
  6199. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  6200. if (! empty ( $moth )) // yearPage
  6201. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  6202. $this->showCache ( $path );
  6203. }
  6204. Doo::loadModel ( 'L_category' );
  6205. $Lcategory = new L_category ();
  6206. Doo::loadModel ( 'verify' );
  6207. Doo::loadModel ( 'statistics' );
  6208. $statistics = new statistics ();
  6209. $verify = new verify ();
  6210. Doo::loadModel ( 'staff' );
  6211. $staff = new staff ();
  6212. $condition = " and status!=0 ";
  6213. if ($item == "approval")
  6214. $condition = " and status=2 ";
  6215. elseif ($item == "withdraw")
  6216. $condition = " and status=3 ";
  6217. elseif ($item == "past")
  6218. $condition = " and status=1 ";
  6219. elseif ($item == "whdw")
  6220. $condition = " and status=4 ";
  6221. $dateCondition = " and Year(date) =" . $year;
  6222. if (! empty ( $moth )) {
  6223. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  6224. $stList = $statistics->getOne ( array (
  6225. 'select' => 'rePrice ,agPrice',
  6226. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  6227. 'asArray' => true
  6228. ) );
  6229. } else
  6230. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  6231. if (empty ( $stList ))
  6232. $stList = array (
  6233. 'rePrice' => 0,
  6234. 'agPrice' => 0
  6235. );
  6236. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  6237. $data ['stList'] = array (
  6238. 'rePrice' => $stList ['rePrice'],
  6239. 'agPrice' => $stList ['agPrice'],
  6240. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  6241. );
  6242. $receiptList = $receipt->find ( array (
  6243. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  6244. 'desc' => 'rid',
  6245. 'asArray' => true
  6246. ) );
  6247. $Locate = 0;
  6248. $roleId = 0;
  6249. $button = 0;
  6250. foreach ( $receiptList as $key => $value ) {
  6251. $receiptList [$key] ['Locate'] = $Locate;
  6252. $Locate ++;
  6253. $receiptList [$key] ['reviseDetail'] = array ();
  6254. if (! empty ( $value ['reviseDetail'] ))
  6255. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6256. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6257. $categoryDetil = $Lcategory->getOne ( array (
  6258. 'where' => 'cid=' . $value ['cid'],
  6259. 'asArray' => true
  6260. ) );
  6261. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6262. // 检测编辑状态
  6263. $verifyList = $verify->getOne ( array (
  6264. 'where' => 'vid=' . $value ['verify'],
  6265. 'asArray' => true
  6266. ) );
  6267. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6268. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6269. Doo::loadModel ( 'role' );
  6270. $role = new role ();
  6271. $flag = true;
  6272. $roleKey = 0;
  6273. $endStaffArray = array ();
  6274. $roleArrayCopy = array ();
  6275. foreach ( $verifyList as $k => $v ) {
  6276. // init verifyStaff
  6277. if ($v [1] == 'ROLE') {
  6278. if (! empty ( $verifyStaff )) {
  6279. $endStaffArray = end ( $verifyStaff );
  6280. // if ($v[0]==$endStaffArray['nextStaff']){
  6281. // $roleId=$v[0];
  6282. // }
  6283. }
  6284. $roleVerify = json_decode ( $v [3], true );
  6285. $roleKey = $k;
  6286. $roleArray = array ();
  6287. $rolename = $role->getOne ( array (
  6288. 'where' => 'rid=' . $v [0],
  6289. 'asArray' => true
  6290. ) );
  6291. foreach ( $roleVerify as $o => $p ) {
  6292. $staffID = explode ( '_', $p );
  6293. $staffInfo = $staff->getOne ( array (
  6294. 'where' => 'sid=' . $staffID [0],
  6295. 'asArray' => true
  6296. ) );
  6297. // print_r($staffID);
  6298. $exp = array (
  6299. 0 => $staffInfo ['sid'],
  6300. 1 => $staffID [1],
  6301. 2 => $staffInfo ['avatar'],
  6302. 'date' => '',
  6303. 'date' => '',
  6304. 'opinion' => '',
  6305. 'status' => '',
  6306. 'rolename' => $rolename ['name']
  6307. );
  6308. array_push ( $roleArray, $exp );
  6309. }
  6310. $roleArrayCopy [$v [0]] = $roleArray;
  6311. // $verifyList[$k]['roleArray']=$roleArray;
  6312. }
  6313. $verifyList [$k] ['date'] = "";
  6314. $verifyList [$k] ['opinion'] = "";
  6315. $verifyList [$k] ['status'] = "";
  6316. if (empty ( $verifyStaff )) {
  6317. $verifyList [$k] ['date'] = "";
  6318. $verifyList [$k] ['opinion'] = "";
  6319. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6320. $verifyList [$k] ['status'] = 4;
  6321. $flag = false;
  6322. }
  6323. } else {
  6324. foreach ( $verifyStaff as $m => $u ) {
  6325. if ($v [0] == $m) {
  6326. $verifyList [$k] ['date'] = $u ['date'];
  6327. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6328. $verifyList [$k] ['status'] = $u ['status'];
  6329. $flag = false;
  6330. break;
  6331. }
  6332. }
  6333. $endStaffArray = end ( $verifyStaff );
  6334. if (isset ( $endStaffArray ['ROLE'] )) {
  6335. } else {
  6336. // $endKey=key($verifyStaff);
  6337. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6338. // $button=4;
  6339. // $verifyList[$k]['status']=4;
  6340. // }
  6341. }
  6342. }
  6343. }
  6344. $rolename ['name'] = '';
  6345. if (! empty ( $roleId )) {
  6346. Doo::loadModel ( 'role' );
  6347. $role = new role ();
  6348. $rolename = $role->getOne ( array (
  6349. 'where' => 'rid=' . $roleId,
  6350. 'asArray' => true
  6351. ) );
  6352. }
  6353. if (! empty ( $verifyStaff ))
  6354. $endStaffArray = end ( $verifyStaff );
  6355. $KOP = false;
  6356. foreach ( $roleArrayCopy as $P => $A ) {
  6357. foreach ( $A as $MKI => $AVL ) {
  6358. if (! empty ( $verifyStaff )) {
  6359. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6360. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6361. $button = 4;
  6362. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6363. }
  6364. foreach ( $verifyStaff as $m => $u ) {
  6365. $AVLFK = $AVL [0] . '_R';
  6366. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6367. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6368. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6369. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6370. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6371. break;
  6372. }
  6373. }
  6374. } else {
  6375. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6376. $button = 4;
  6377. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6378. }
  6379. }
  6380. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6381. $KOP = true;
  6382. }
  6383. }
  6384. foreach ( $roleArrayCopy as $k => $v ) {
  6385. foreach ( $verifyList as $m => $n ) {
  6386. if ($n [0] == $k) {
  6387. array_splice ( $verifyList, $m, 1, $v );
  6388. }
  6389. }
  6390. }
  6391. $receiptList [$key] ['verifyList'] = $verifyList;
  6392. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6393. 'where' => 'sid=' . $value ['staff'],
  6394. 'asArray' => true
  6395. ) );
  6396. $receiptList [$key] ['button'] = $button;
  6397. }
  6398. // print_r($receiptList);die;
  6399. $mothHtml = "";
  6400. for($i = 1; $i <= 12; $i ++) {
  6401. if ($moth == $i)
  6402. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6403. else
  6404. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6405. }
  6406. $data ['mothHtml'] = $mothHtml;
  6407. $data ['receiptList'] = $receiptList;
  6408. $data ['memu'] = "receipt";
  6409. $data ['staff'] = $this->staff;
  6410. $data ['receiptMemu'] = 'receipt';
  6411. $data ['verifyId'] = $this->verifyId;
  6412. $data ['executeId'] = $this->executeId;
  6413. $data ['item'] = $item;
  6414. $data ['year'] = $year;
  6415. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  6416. // sufficient condition to generate cache
  6417. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  6418. $receiptList = $receipt->find ( array (
  6419. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  6420. 'asArray' => true
  6421. ) );
  6422. if (empty ( $receiptList )) { // generated files
  6423. ob_start ();
  6424. $this->render ( "/admin/saea_myList", $data );
  6425. $this->cacheFile ( $path );
  6426. die ();
  6427. // $content = ob_get_contents();
  6428. // $fp = fopen($path, "w");
  6429. // fwrite($fp, $content);
  6430. // fclose($fp);
  6431. }
  6432. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  6433. $receiptList = $receipt->find ( array (
  6434. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  6435. 'asArray' => true
  6436. ) );
  6437. if (empty ( $receiptList )) { // generated files
  6438. ob_start ();
  6439. $this->render ( "/admin/saea_myList", $data );
  6440. $this->cacheFile ( $path );
  6441. die ();
  6442. }
  6443. }
  6444. }
  6445. $this->render ( "/admin/saea_myList", $data );
  6446. }
  6447. function saeaCreate() {
  6448. Doo::loadModel ( 'accountItem' );
  6449. Doo::loadModel ( 'verify' );
  6450. Doo::loadModel ( 'receipt' );
  6451. Doo::loadModel ( 'L_category' );
  6452. $lCategory = new L_category ();
  6453. $receipt = new receipt ();
  6454. $verify = new verify ();
  6455. $accountItem = new accountItem ();
  6456. Doo::loadModel ( "role" );
  6457. $role = new role ();
  6458. $acItem = $accountItem->find ( array (
  6459. 'asArray' => true
  6460. ) );
  6461. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6462. $data ['category'] = $lCategory->find ( array (
  6463. 'asArray' => true
  6464. ) );
  6465. $data ['veList'] = $veList;
  6466. $data ['acItem'] = $acItem;
  6467. $data ['memu'] = "receipt";
  6468. $data ['staff'] = $this->staff;
  6469. $data ['receiptMemu'] = 'saeaBorad';
  6470. $data ['verifyId'] = $this->verifyId;
  6471. $data ['executeId'] = $this->executeId;
  6472. $this->render ( "/admin/saea_create", $data );
  6473. }
  6474. function addReceipt() {
  6475. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6476. $agency = $this->get_args ( 'agency' );
  6477. $travel = $this->get_args ( 'travel' );
  6478. $train = $this->get_args ( 'train' );
  6479. $other = $this->get_args ( 'other' );
  6480. $inttrain = $this->get_args ( 'inttrain' );
  6481. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6482. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6483. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6484. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6485. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6486. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6487. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6488. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6489. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6490. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6491. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6492. header ( 'Content-Type:text/html;charset=utf-8' );
  6493. die ( '请填写联行号' );
  6494. }
  6495. Doo::loadModel ( 'receipt' );
  6496. Doo::loadModel ( 'receiptDetail' );
  6497. Doo::loadModel ( 'accountItem' );
  6498. $accountItem = new accountItem ();
  6499. $receipt = new receipt ();
  6500. Doo::loadModel ( 'enclosur' );
  6501. Doo::loadModel ( 'execute' );
  6502. $execute = new execute ();
  6503. $executeDetail = $execute->getOne ( array (
  6504. 'where' => 'mold="报销单执行人"',
  6505. 'asArray' => true
  6506. ) );
  6507. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  6508. // if(!empty($receiptDetail))
  6509. // return "/referReceipt/".$receiptDetail['rid'];
  6510. $aItem = $accountItem->find ( array (
  6511. 'asArray' => true
  6512. ) );
  6513. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6514. $ag = $tr = $ta = $ot= $it = 0;
  6515. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  6516. foreach ( $aItem as $key => $value ) {
  6517. if ($value ['category'] == $this->AGENCY) {
  6518. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6519. array_push ( $accountJson [$this->AGENCY], array (
  6520. 'aid' => $value ['aid'],
  6521. 'name' => $value ['name'],
  6522. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6523. ) );
  6524. $sum += $agency [$ag];
  6525. $agencySum += $agency [$ag];
  6526. }
  6527. $ag ++;
  6528. }
  6529. if ($value ['category'] == $this->TRAVEL) {
  6530. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6531. array_push ( $accountJson [$this->TRAVEL], array (
  6532. 'aid' => $value ['aid'],
  6533. 'name' => $value ['name'],
  6534. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6535. ) );
  6536. $sum += $travel [$tr];
  6537. $travelSum += $travel [$tr];
  6538. }
  6539. $tr ++;
  6540. }
  6541. if ($value ['category'] == $this->TRAIN) {
  6542. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6543. array_push ( $accountJson [$this->TRAIN], array (
  6544. 'aid' => $value ['aid'],
  6545. 'name' => $value ['name'],
  6546. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6547. ) );
  6548. $sum += $train [$ta];
  6549. $trainSum += $train [$ta];
  6550. }
  6551. $ta ++;
  6552. }
  6553. if ($value ['category'] == $this->INTTRAIN) {
  6554. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6555. array_push ( $accountJson [$this->INTTRAIN], array (
  6556. 'aid' => $value ['aid'],
  6557. 'name' => $value ['name'],
  6558. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6559. ) );
  6560. $sum += $inttrain [$it];
  6561. $inttrainSum += $inttrain [$it];
  6562. }
  6563. $it ++;
  6564. }
  6565. if ($value ['category'] == $this->OTHER) {
  6566. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6567. array_push ( $accountJson [$this->OTHER], array (
  6568. 'aid' => $value ['aid'],
  6569. 'name' => $value ['name'],
  6570. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6571. ) );
  6572. $sum += $other [$ot];
  6573. $otherSum += $other [$ot];
  6574. }
  6575. $ot ++;
  6576. }
  6577. }
  6578. $accountJson ['cSum'] = array (
  6579. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6580. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6581. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6582. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6583. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6584. );
  6585. // 报销单
  6586. $receipt->accountItem = json_encode ( $accountJson );
  6587. $receipt->staff = $this->staff [0] ['sid'];
  6588. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6589. $receipt->date = date ( "Y-m-d" );
  6590. $receipt->cid = $cid;
  6591. $receipt->status = 5;
  6592. // 修改审批流程加入角色
  6593. $receipt->verify = $verify;
  6594. $receipt->executeCopy = $executeDetail ['staff'];
  6595. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6596. $order = array (
  6597. "\r\n",
  6598. "\n",
  6599. "\r"
  6600. );
  6601. $replace = '<br/>';
  6602. $explanation = str_replace ( $order, $replace, $explanation );
  6603. $receipt->explanation = $explanation;
  6604. $receipt->remittanceName = $remittanceName;
  6605. $receipt->bankName = $bankName;
  6606. $receipt->bankNumber = $bankNumber;
  6607. $receipt->remittanceBankType = $remittanceBankType;
  6608. if ($remittanceBankType == 1)
  6609. $receipt->coupletNumber = $coupletNumber;
  6610. $rid = $receipt->insert ();
  6611. // 附件
  6612. if (! empty ( $enclosurName )) {
  6613. $enclosurArray = explode ( '-', $enclosurName );
  6614. foreach ( $enclosurArray as $value ) {
  6615. $enclosur = new enclosur ();
  6616. $enclosur->name = $value;
  6617. $enclosur->rid = $rid;
  6618. $enclosur->insert ();
  6619. }
  6620. // print_r($enclosurArray);die;
  6621. }
  6622. // 报销详情
  6623. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6624. $receiptDetail = new receiptDetail ();
  6625. $receiptDetail->staff = $this->staff [0] ['sid'];
  6626. $receiptDetail->item = $value ['name'];
  6627. $receiptDetail->itemCategory = $this->AGENCY;
  6628. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6629. $receiptDetail->date = date ( "Y-m-d" );
  6630. $receiptDetail->cid = $cid;
  6631. $receiptDetail->rid = $rid;
  6632. $receiptDetail->status = 4;
  6633. $receiptDetail->insert ();
  6634. }
  6635. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6636. $receiptDetail = new receiptDetail ();
  6637. $receiptDetail->staff = $this->staff [0] ['sid'];
  6638. $receiptDetail->item = $value ['name'];
  6639. $receiptDetail->itemCategory = $this->TRAVEL;
  6640. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6641. $receiptDetail->date = date ( "Y-m-d" );
  6642. $receiptDetail->cid = $cid;
  6643. $receiptDetail->rid = $rid;
  6644. $receiptDetail->status = 4;
  6645. $receiptDetail->insert ();
  6646. }
  6647. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  6648. $receiptDetail = new receiptDetail ();
  6649. $receiptDetail->staff = $this->staff [0] ['sid'];
  6650. $receiptDetail->item = $value ['name'];
  6651. $receiptDetail->itemCategory = $this->TRAIN;
  6652. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6653. $receiptDetail->date = date ( "Y-m-d" );
  6654. $receiptDetail->cid = $cid;
  6655. $receiptDetail->rid = $rid;
  6656. $receiptDetail->status = 4;
  6657. $receiptDetail->insert ();
  6658. }
  6659. //内训
  6660. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  6661. $receiptDetail = new receiptDetail ();
  6662. $receiptDetail->staff = $this->staff [0] ['sid'];
  6663. $receiptDetail->item = $value ['name'];
  6664. $receiptDetail->itemCategory = $this->INTTRAIN;
  6665. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6666. $receiptDetail->date = date ( "Y-m-d" );
  6667. $receiptDetail->cid = $cid;
  6668. $receiptDetail->rid = $rid;
  6669. $receiptDetail->status = 4;
  6670. $receiptDetail->insert ();
  6671. }
  6672. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  6673. $receiptDetail = new receiptDetail ();
  6674. $receiptDetail->staff = $this->staff [0] ['sid'];
  6675. $receiptDetail->item = $value ['name'];
  6676. $receiptDetail->itemCategory = $this->OTHER;
  6677. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6678. $receiptDetail->date = date ( "Y-m-d" );
  6679. $receiptDetail->cid = $cid;
  6680. $receiptDetail->rid = $rid;
  6681. $receiptDetail->status = 4;
  6682. $receiptDetail->insert ();
  6683. }
  6684. return "/saeaBorad";
  6685. } else
  6686. die ( 'illegal request' );
  6687. }
  6688. function referReceipt() {
  6689. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  6690. Doo::loadModel ( 'receipt' );
  6691. Doo::loadModel ( 'verify' );
  6692. $verify = new verify ();
  6693. $receipt = new receipt ();
  6694. Doo::loadModel ( 'L_category' );
  6695. $lCategory = new L_category ();
  6696. Doo::loadModel ( "role" );
  6697. $role = new role ();
  6698. $receiptDetail = $receipt->find ( array (
  6699. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  6700. 'asArray' => true
  6701. ) );
  6702. if (empty ( $receiptDetail ))
  6703. return "/addReceipt";
  6704. foreach ( $receiptDetail as $key => $value ) {
  6705. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6706. $veList = $verify->getOne ( array (
  6707. 'where' => 'vid=' . $value ['verify'],
  6708. 'asArray' => true
  6709. ) );
  6710. $v = json_decode ( $veList ['staff'] );
  6711. array_push ( $v [0], $veList ['description'] );
  6712. foreach ( $v as $n => $m ) {
  6713. if ($m ['1'] == 'ROLE') {
  6714. $roleInfo = $role->getOne ( array (
  6715. 'where' => 'rid=' . $m [0],
  6716. 'asArray' => true
  6717. ) );
  6718. $v [$n] [1] = $roleInfo ['name'];
  6719. }
  6720. }
  6721. $receiptDetail [$key] ['staff'] = $v;
  6722. $category = $lCategory->getOne ( array (
  6723. 'where' => 'cid=' . $value ['cid'],
  6724. 'asArray' => true
  6725. ) );
  6726. $receiptDetail [$key] ['category'] = $category ['title'];
  6727. }
  6728. // print_r($receiptDetail);
  6729. $data ['receiptDetail'] = $receiptDetail;
  6730. $data ['memu'] = "receipt";
  6731. $data ['staff'] = $this->staff;
  6732. $data ['receiptMemu'] = 'saeaCreate';
  6733. $data ['verifyId'] = $this->verifyId;
  6734. $data ['executeId'] = $this->executeId;
  6735. $this->render ( "/admin/saea_confirm", $data );
  6736. }
  6737. function editReceipt() {
  6738. // edit status 4
  6739. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  6740. Doo::loadClass ( 'XDeode' );
  6741. $XDeode = new XDeode ( 7 );
  6742. $rid = $XDeode->decode ( $ridKey );
  6743. if (empty ( $rid ))
  6744. die ( 'illegal request' );
  6745. // echo $rid.'sd';
  6746. Doo::loadModel ( 'accountItem' );
  6747. Doo::loadModel ( 'verify' );
  6748. Doo::loadModel ( 'receipt' );
  6749. $receipt = new receipt ();
  6750. $verify = new verify ();
  6751. $accountItem = new accountItem ();
  6752. Doo::loadModel ( 'L_category' );
  6753. $lCategory = new L_category ();
  6754. Doo::loadModel ( "role" );
  6755. $role = new role ();
  6756. Doo::loadModel ( 'enclosur' );
  6757. $enclosur = new enclosur ();
  6758. $receiptDetail = $receipt->getOne ( array (
  6759. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  6760. 'asArray' => true
  6761. ) );
  6762. if (empty ( $receiptDetail ))
  6763. die ( 'illegal request' );
  6764. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  6765. $acItem = $accountItem->find ( array (
  6766. 'asArray' => true
  6767. ) );
  6768. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  6769. // 配置编辑信息
  6770. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  6771. foreach ( $acItem as $key => $value ) {
  6772. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  6773. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  6774. $acItem [$key] ['price'] = $v ['price'];
  6775. }
  6776. }
  6777. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  6778. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6779. $acItem [$key] ['price'] = $v ['price'];
  6780. }
  6781. }
  6782. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  6783. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  6784. $acItem [$key] ['price'] = $v ['price'];
  6785. }
  6786. }
  6787. //内训
  6788. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  6789. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  6790. $acItem [$key] ['price'] = $v ['price'];
  6791. }
  6792. }
  6793. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  6794. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  6795. $acItem [$key] ['price'] = $v ['price'];
  6796. }
  6797. }
  6798. }
  6799. $data ['category'] = $lCategory->find ( array (
  6800. 'asArray' => true
  6801. ) );
  6802. $data ['cSum'] = $accountItemList ['cSum'];
  6803. $data ['sum'] = $receiptDetail ['sum'];
  6804. $data ['enclosurList'] = $enclosurList;
  6805. $data ['receiptDetail'] = $receiptDetail;
  6806. $data ['veList'] = $veList;
  6807. $data ['acItem'] = $acItem;
  6808. $data ['memu'] = "receipt";
  6809. $data ['staff'] = $this->staff;
  6810. $data ['receiptMemu'] = 'saeaBorad';
  6811. $data ['verify'] = $receiptDetail ['verify'];
  6812. $data ['verifyId'] = $this->verifyId;
  6813. $data ['executeId'] = $this->executeId;
  6814. $data ['rid'] = $ridKey;
  6815. $this->render ( "/admin/saea_edit", $data );
  6816. }
  6817. function updateReceipt() {
  6818. $agency = $this->get_args ( 'agency' );
  6819. $travel = $this->get_args ( 'travel' );
  6820. $train = $this->get_args ( 'train' );
  6821. $other = $this->get_args ( 'other' );
  6822. $inttrain = $this->get_args ( 'inttrain' );
  6823. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  6824. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  6825. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  6826. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  6827. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  6828. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  6829. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  6830. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  6831. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  6832. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  6833. Doo::loadClass ( 'XDeode' );
  6834. $XDeode = new XDeode ( 7 );
  6835. $rid = $XDeode->decode ( $ridKey );
  6836. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  6837. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  6838. header ( 'Content-Type:text/html;charset=utf-8' );
  6839. die ( '请填写联行号' );
  6840. }
  6841. Doo::loadModel ( 'receipt' );
  6842. Doo::loadModel ( 'receiptDetail' );
  6843. Doo::loadModel ( 'accountItem' );
  6844. $accountItem = new accountItem ();
  6845. $receipt = new receipt ();
  6846. Doo::loadModel ( 'enclosur' );
  6847. Doo::loadModel ( 'execute' );
  6848. $execute = new execute ();
  6849. $receiptDetail = $receipt->getOne ( array (
  6850. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  6851. 'asArray' => true
  6852. ) );
  6853. if (empty ( $receiptDetail ))
  6854. return "/saeaBorad";
  6855. if ($receiptDetail ['Rtype'] == 1)
  6856. $executeDetail = $execute->getOne ( array (
  6857. 'where' => 'mold="借款费用执行人"',
  6858. 'asArray' => true
  6859. ) );
  6860. else
  6861. $executeDetail = $execute->getOne ( array (
  6862. 'where' => 'mold="报销单执行人"',
  6863. 'asArray' => true
  6864. ) );
  6865. $aItem = $accountItem->find ( array (
  6866. 'asArray' => true
  6867. ) );
  6868. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  6869. $ag = $tr = $ta = $ot = $it = 0 ;
  6870. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum = $otherSum = 0;
  6871. foreach ( $aItem as $key => $value ) {
  6872. if ($value ['category'] == $this->AGENCY) {
  6873. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  6874. array_push ( $accountJson [$this->AGENCY], array (
  6875. 'aid' => $value ['aid'],
  6876. 'name' => $value ['name'],
  6877. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  6878. ) );
  6879. $sum += $agency [$ag];
  6880. $agencySum += $agency [$ag];
  6881. }
  6882. $ag ++;
  6883. }
  6884. if ($value ['category'] == $this->TRAVEL) {
  6885. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  6886. array_push ( $accountJson [$this->TRAVEL], array (
  6887. 'aid' => $value ['aid'],
  6888. 'name' => $value ['name'],
  6889. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  6890. ) );
  6891. $sum += $travel [$tr];
  6892. $travelSum += $travel [$tr];
  6893. }
  6894. $tr ++;
  6895. }
  6896. if ($value ['category'] == $this->TRAIN) {
  6897. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  6898. array_push ( $accountJson [$this->TRAIN], array (
  6899. 'aid' => $value ['aid'],
  6900. 'name' => $value ['name'],
  6901. 'price' => number_format ( $train [$ta], 2, '.', '' )
  6902. ) );
  6903. $sum += $train [$ta];
  6904. $trainSum += $train [$ta];
  6905. }
  6906. $ta ++;
  6907. }
  6908. if ($value ['category'] == $this->INTTRAIN) {
  6909. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  6910. array_push ( $accountJson [$this->INTTRAIN], array (
  6911. 'aid' => $value ['aid'],
  6912. 'name' => $value ['name'],
  6913. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  6914. ) );
  6915. $sum += $inttrain [$it];
  6916. $inttrainSum += $inttrain [$it];
  6917. }
  6918. $it ++;
  6919. }
  6920. if ($value ['category'] == $this->OTHER) {
  6921. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  6922. array_push ( $accountJson [$this->OTHER], array (
  6923. 'aid' => $value ['aid'],
  6924. 'name' => $value ['name'],
  6925. 'price' => number_format ( $other [$ot], 2, '.', '' )
  6926. ) );
  6927. $sum += $other [$ot];
  6928. $otherSum += $other [$ot];
  6929. }
  6930. $ot ++;
  6931. }
  6932. }
  6933. $accountJson ['cSum'] = array (
  6934. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  6935. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  6936. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  6937. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  6938. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  6939. );
  6940. // 报销单
  6941. $rid = $receipt->rid = $receiptDetail ['rid'];
  6942. $receipt->accountItem = json_encode ( $accountJson );
  6943. $receipt->staff = $this->staff [0] ['sid'];
  6944. $receipt->sum = number_format ( $sum, 2, '.', '' );
  6945. $receipt->date = date ( "Y-m-d" );
  6946. $receipt->cid = $cid;
  6947. if (($receiptDetail ['status'] != 4)) {
  6948. if ($receiptDetail ['Rtype'] == 1)
  6949. $receipt->status = 7;
  6950. else
  6951. $receipt->status = 5;
  6952. }
  6953. if ($receiptDetail != 4 && ! empty ( $verify ))
  6954. $receipt->verify = $verify;
  6955. $receipt->executeCopy = $executeDetail ['staff'];
  6956. $order = array (
  6957. "\r\n",
  6958. "\n",
  6959. "\r"
  6960. );
  6961. $replace = '<br/>';
  6962. $explanation = str_replace ( $order, $replace, $explanation );
  6963. $receipt->explanation = $explanation;
  6964. $receipt->remittanceName = $remittanceName;
  6965. $receipt->bankName = $bankName;
  6966. $receipt->bankNumber = $bankNumber;
  6967. $receipt->remittanceBankType = $remittanceBankType;
  6968. if ($remittanceBankType == 1)
  6969. $receipt->coupletNumber = $coupletNumber;
  6970. $receipt->update ();
  6971. $receiptDetail = new receiptDetail ();
  6972. $receiptDetail->delete ( array (
  6973. 'where' => 'rid=' . $rid
  6974. ) );
  6975. // 报销详情
  6976. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  6977. $receiptDetail = new receiptDetail ();
  6978. $receiptDetail->staff = $this->staff [0] ['sid'];
  6979. $receiptDetail->item = $value ['name'];
  6980. $receiptDetail->itemCategory = $this->AGENCY;
  6981. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6982. $receiptDetail->date = date ( "Y-m-d" );
  6983. $receiptDetail->cid = $cid;
  6984. $receiptDetail->rid = $rid;
  6985. $receiptDetail->status = 4;
  6986. $receiptDetail->insert ();
  6987. }
  6988. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  6989. $receiptDetail = new receiptDetail ();
  6990. $receiptDetail->staff = $this->staff [0] ['sid'];
  6991. $receiptDetail->item = $value ['name'];
  6992. $receiptDetail->itemCategory = $this->TRAVEL;
  6993. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  6994. $receiptDetail->date = date ( "Y-m-d" );
  6995. $receiptDetail->cid = $cid;
  6996. $receiptDetail->rid = $rid;
  6997. $receiptDetail->status = 4;
  6998. $receiptDetail->insert ();
  6999. }
  7000. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  7001. $receiptDetail = new receiptDetail ();
  7002. $receiptDetail->staff = $this->staff [0] ['sid'];
  7003. $receiptDetail->item = $value ['name'];
  7004. $receiptDetail->itemCategory = $this->TRAIN;
  7005. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7006. $receiptDetail->date = date ( "Y-m-d" );
  7007. $receiptDetail->cid = $cid;
  7008. $receiptDetail->rid = $rid;
  7009. $receiptDetail->status = 4;
  7010. $receiptDetail->insert ();
  7011. }
  7012. //内训
  7013. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  7014. $receiptDetail = new receiptDetail ();
  7015. $receiptDetail->staff = $this->staff [0] ['sid'];
  7016. $receiptDetail->item = $value ['name'];
  7017. $receiptDetail->itemCategory = $this->INTTRAIN;
  7018. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7019. $receiptDetail->date = date ( "Y-m-d" );
  7020. $receiptDetail->cid = $cid;
  7021. $receiptDetail->rid = $rid;
  7022. $receiptDetail->status = 4;
  7023. $receiptDetail->insert ();
  7024. }
  7025. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  7026. $receiptDetail = new receiptDetail ();
  7027. $receiptDetail->staff = $this->staff [0] ['sid'];
  7028. $receiptDetail->item = $value ['name'];
  7029. $receiptDetail->itemCategory = $this->OTHER;
  7030. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  7031. $receiptDetail->date = date ( "Y-m-d" );
  7032. $receiptDetail->cid = $cid;
  7033. $receiptDetail->rid = $rid;
  7034. $receiptDetail->status = 4;
  7035. $receiptDetail->insert ();
  7036. }
  7037. // 附件
  7038. if (! empty ( $enclosurName )) {
  7039. $enclosurArray = explode ( '-', $enclosurName );
  7040. foreach ( $enclosurArray as $value ) {
  7041. $enclosur = new enclosur ();
  7042. $enclosur->name = $value;
  7043. $enclosur->rid = $rid;
  7044. $enclosur->insert ();
  7045. }
  7046. }
  7047. // return "/referReceipt/".$rid;
  7048. }
  7049. return "/saeaBorad";
  7050. }
  7051. function approvedReceipt() {
  7052. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7053. Doo::loadModel ( 'receipt' );
  7054. Doo::loadModel ( 'receiptDetail' );
  7055. $receipt = new receipt ();
  7056. $receiptDetail = new receiptDetail ();
  7057. Doo::loadModel ( 'statistics' );
  7058. Doo::loadModel ( 'itemStatistics' );
  7059. $statistics = new statistics ();
  7060. $itemStatistics = new itemStatistics ();
  7061. Doo::loadModel ( "verify" );
  7062. $verify = new verify ();
  7063. // 审批状态的判定
  7064. $receiptDetailList = $receipt->getOne ( array (
  7065. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7066. 'asArray' => true
  7067. ) );
  7068. if (empty ( $receiptDetailList ))
  7069. return "/saeaBorad";
  7070. $verifyDetail = $verify->getOne ( array (
  7071. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7072. 'asArray' => true
  7073. ) );
  7074. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7075. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7076. $nowStaff = "";
  7077. $nowStaffList = array ();
  7078. if ($verifyDetail [0] [1] == 'ROLE') {
  7079. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7080. foreach ( $vStaffString as $key => $value ) {
  7081. $staffK = explode ( "_", $value );
  7082. array_push ( $nowStaffList, $staffK [0] );
  7083. }
  7084. $nowStaff = implode ( ',', $nowStaffList );
  7085. } else {
  7086. $nowStaff = $verifyDetail [0] [0];
  7087. }
  7088. $receipt->nowStaff = $nowStaff;
  7089. }
  7090. // echo $nowStaff;
  7091. // print_r($verifyDetail);die;
  7092. $receipt->rid = $receiptDetailList ['rid'];
  7093. $receipt->date = date ( "Y-m-d" );
  7094. $receipt->status = 2;
  7095. $receipt->update ();
  7096. $receiptDetail->status = 2;
  7097. $receiptDetail->update ( array (
  7098. 'where' => 'rid=' . $receiptDetailList ['rid']
  7099. ) );
  7100. Doo::loadModel ( "receiptLog" );
  7101. $receiptLog = new receiptLog ();
  7102. Doo::loadModel ( "verify" );
  7103. $verify = new verify ();
  7104. $receiptInfo = $receipt->getOne ( array (
  7105. 'where' => 'rid=' . $rid,
  7106. 'asArray' => true
  7107. ) );
  7108. $vr = $verify->getOne ( array (
  7109. 'where' => 'vid=' . $receiptInfo ['verify'],
  7110. 'asArray' => true
  7111. ) );
  7112. $jd = json_decode ( $vr ['staff'] );
  7113. $roleId = 0;
  7114. foreach ( $jd as $key => $value ) {
  7115. if ($value [1] == 'ROLE') {
  7116. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7117. if ($pos !== false) {
  7118. $roleId = $value [0];
  7119. }
  7120. }
  7121. }
  7122. // 审批日志
  7123. // echo $roleId;die;
  7124. if (! empty ( $roleId )) {
  7125. Doo::loadModel ( "role" );
  7126. $role = new role ();
  7127. $roleInfo = $role->getOne ( array (
  7128. 'where' => 'rid=' . $roleId,
  7129. 'asArray' => true
  7130. ) );
  7131. // $receiptLog->rolename = $roleInfo ['name'];
  7132. }
  7133. $receiptLog->username = $this->staff [0] ['username'];
  7134. $receiptLog->uid = $this->staff [0] ['sid'];
  7135. $receiptLog->date = date ( "Y-m-d" );
  7136. $receiptLog->opinion = '提交审批';
  7137. $receiptLog->img = $this->staff [0] ['avatar'];
  7138. $receiptLog->status = 2;
  7139. $receiptLog->rid = $rid;
  7140. $receiptLog->insert ();
  7141. // statistics item
  7142. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7143. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7144. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7145. $stat = $statistics->getOne ( array (
  7146. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7147. 'asArray' => true
  7148. ) );
  7149. if (empty ( $stat )) {
  7150. $statistics->date = date ( "Y-m-d" );
  7151. $statistics->cid = $this->staff [0] ['cid'];
  7152. $statistics->staff = $this->staff [0] ['sid'];
  7153. $statistics->agPrice = 0;
  7154. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7155. $statistics->insert ();
  7156. } else {
  7157. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7158. $statistics->update ( array (
  7159. 'where' => 'sid=' . $stat ['sid']
  7160. ) );
  7161. }
  7162. return "/expenses";
  7163. }
  7164. function approval() {
  7165. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7166. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7167. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7168. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7169. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7170. if (empty ( $status ))
  7171. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7172. $vidList = array ();
  7173. $button = 0;
  7174. Doo::loadModel ( 'verify' );
  7175. $verify = new verify ();
  7176. Doo::loadModel ( 'receipt' );
  7177. $receipt = new receipt ();
  7178. Doo::loadModel ( 'staff' );
  7179. $staff = new staff ();
  7180. Doo::loadModel ( 'L_category' );
  7181. $Lcategory = new L_category ();
  7182. // user verify ID
  7183. $verifyDetail = $verify->find ( array (
  7184. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7185. 'asArray' => true
  7186. ) );
  7187. foreach ( $verifyDetail as $key => $value ) {
  7188. array_push ( $vidList, $value ['vid'] );
  7189. }
  7190. $vid = implode ( ",", $vidList );
  7191. if (empty ( $verifyDetail ))
  7192. $vid = 0;
  7193. /*
  7194. */
  7195. $dateCondition = " and Year(date) =" . $year;
  7196. if (! empty ( $month ))
  7197. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7198. $categoryList = $Lcategory->find ( array (
  7199. 'asArray' => true
  7200. ) );
  7201. $staffList = $staff->find ( array (
  7202. 'where' => 'cid=' . $cid,
  7203. 'asArray' => true
  7204. ) );
  7205. $cateCondition = "";
  7206. $staffCondition = "";
  7207. $approvalCondition = "";
  7208. if (! empty ( $cid ))
  7209. $cateCondition = ' and cid=' . $cid;
  7210. if (! empty ( $sid )) {
  7211. $staffCondition = ' and staff=' . $sid;
  7212. $cateCondition = "";
  7213. }
  7214. // elseif($status==1){
  7215. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7216. // }
  7217. if ($status == 2) {
  7218. // 查找角色审批人
  7219. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7220. }
  7221. $ap = "";
  7222. if ($status == 4) {
  7223. $ap = 4;
  7224. $status = 2;
  7225. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7226. }
  7227. if ($status == 5) {
  7228. $status = 4;
  7229. $ap = 5;
  7230. }
  7231. // echo $vid;
  7232. // get Receipt By verifyID status 2 .$approvalCondition
  7233. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7234. $receiptList = $receipt->find ( array (
  7235. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7236. 'desc' => 'rid',
  7237. 'asArray' => true
  7238. ) );
  7239. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7240. $Locate = 0;
  7241. if ($ap == 4)
  7242. $status = 4;
  7243. elseif ($ap == 5)
  7244. $status = 5;
  7245. foreach ( $receiptList as $key => $value ) {
  7246. $receiptList [$key] ['Locate'] = $Locate;
  7247. $Locate ++;
  7248. $receiptList [$key] ['reviseDetail'] = array ();
  7249. if (! empty ( $value ['reviseDetail'] ))
  7250. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7251. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7252. $categoryDetil = $Lcategory->getOne ( array (
  7253. 'where' => 'cid=' . $value ['cid'],
  7254. 'asArray' => true
  7255. ) );
  7256. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7257. $verifyList = $verify->getOne ( array (
  7258. 'where' => 'vid=' . $value ['verify'],
  7259. 'asArray' => true
  7260. ) );
  7261. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7262. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7263. foreach ( $verifyList as $k => $v ) {
  7264. // init verifyStaff
  7265. $verifyList [$k] ['date'] = "";
  7266. $verifyList [$k] ['opinion'] = "";
  7267. $verifyList [$k] ['status'] = "";
  7268. if (empty ( $verifyStaff )) {
  7269. $verifyList [$k] ['date'] = "";
  7270. $verifyList [$k] ['opinion'] = "";
  7271. if ($v [0] == $this->staff [0] ['sid']) {
  7272. $verifyList [$k] ['status'] = 4;
  7273. $button = 4;
  7274. }
  7275. } else {
  7276. $flag = true;
  7277. foreach ( $verifyStaff as $m => $u ) {
  7278. if ($v [0] == $m) {
  7279. $verifyList [$k] ['date'] = $u ['date'];
  7280. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7281. $verifyList [$k] ['status'] = $u ['status'];
  7282. $flag = false;
  7283. break;
  7284. }
  7285. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7286. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7287. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7288. }
  7289. if ($flag) { // 检测可编辑
  7290. if ($v [0] == $this->staff [0] ['sid']) {
  7291. $verifyList [$k] ['status'] = 4;
  7292. $button = 4;
  7293. }
  7294. }
  7295. }
  7296. }
  7297. $receiptList [$key] ['verifyList'] = $verifyList;
  7298. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7299. 'where' => 'sid=' . $value ['staff'],
  7300. 'asArray' => true
  7301. ) );
  7302. $receiptList [$key] ['button'] = $button;
  7303. }
  7304. // print_r($receiptList);die;
  7305. // $data['verifyDetail']=$verifyDetail;
  7306. $mothHtml = "";
  7307. for($i = 1; $i <= 12; $i ++) {
  7308. if ($month == $i)
  7309. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7310. else
  7311. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7312. }
  7313. $data ['mothHtml'] = $mothHtml;
  7314. $data ['receiptList'] = $receiptList;
  7315. $data ['receiptApprovalCount'] = count ( $receiptList );
  7316. $data ['status'] = $status;
  7317. $data ['year'] = $year;
  7318. $data ['categoryList'] = $categoryList;
  7319. $data ['staffList'] = $staffList;
  7320. $data ['cid'] = $cid;
  7321. $data ['sid'] = $sid;
  7322. $data ['ap'] = $ap;
  7323. $data ['memu'] = "receipt";
  7324. $data ['staff'] = $this->staff;
  7325. $data ['receiptMemu'] = 'approval';
  7326. $data ['verifyId'] = $this->verifyId;
  7327. $data ['executeId'] = $this->executeId;
  7328. $this->render ( "/admin/saea_reportList", $data );
  7329. }
  7330. function approvalDetails() {
  7331. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7332. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7333. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7334. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7335. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7336. Doo::loadModel ( 'verify' );
  7337. $verify = new verify ();
  7338. Doo::loadModel ( 'receipt' );
  7339. $receipt = new receipt ();
  7340. Doo::loadModel ( 'staff' );
  7341. $staff = new staff ();
  7342. Doo::loadModel ( 'L_category' );
  7343. $Lcategory = new L_category ();
  7344. Doo::loadModel ( 'enclosur' );
  7345. $enclosur = new enclosur ();
  7346. $vidList = array ();
  7347. $verifyDetail = $verify->find ( array (
  7348. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7349. 'asArray' => true
  7350. ) );
  7351. foreach ( $verifyDetail as $key => $value ) {
  7352. array_push ( $vidList, $value ['vid'] );
  7353. }
  7354. $vid = implode ( ",", $vidList );
  7355. if (empty ( $verifyDetail ))
  7356. $vid = 0;
  7357. $categoryList = $Lcategory->find ( array (
  7358. 'asArray' => true
  7359. ) );
  7360. $staffList = $staff->find ( array (
  7361. 'where' => 'cid=' . $cid,
  7362. 'asArray' => true
  7363. ) );
  7364. $ap = 0;
  7365. $receiptList = $receipt->find ( array (
  7366. 'where' => 'rid =' . $rid,
  7367. 'desc' => 'rid',
  7368. 'asArray' => true
  7369. ) );
  7370. $Locate = 0;
  7371. $roleId = 0;
  7372. $button = 0;
  7373. foreach ( $receiptList as $key => $value ) {
  7374. $receiptList [$key] ['Locate'] = $Locate;
  7375. $Locate ++;
  7376. $receiptList [$key] ['reviseDetail'] = array ();
  7377. if (! empty ( $value ['reviseDetail'] ))
  7378. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7379. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7380. $categoryDetil = $Lcategory->getOne ( array (
  7381. 'where' => 'cid=' . $value ['cid'],
  7382. 'asArray' => true
  7383. ) );
  7384. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7385. // 检测编辑状态
  7386. $verifyList = $verify->getOne ( array (
  7387. 'where' => 'vid=' . $value ['verify'],
  7388. 'asArray' => true
  7389. ) );
  7390. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7391. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7392. Doo::loadModel ( 'role' );
  7393. $role = new role ();
  7394. // print_r($verifyList);
  7395. $flag = true;
  7396. $roleKey = 0;
  7397. $endStaffArray = array ();
  7398. $roleArrayCopy = array ();
  7399. foreach ( $verifyList as $k => $v ) {
  7400. // init verifyStaff
  7401. if ($v [1] == 'ROLE') {
  7402. if (! empty ( $verifyStaff )) {
  7403. $endStaffArray = end ( $verifyStaff );
  7404. if ($v [0] == $endStaffArray ['nextStaff']) {
  7405. $roleId = $v [0];
  7406. }
  7407. }
  7408. $roleVerify = json_decode ( $v [3], true );
  7409. $roleKey = $k;
  7410. $roleArray = array ();
  7411. $rolename = $role->getOne ( array (
  7412. 'where' => 'rid=' . $v [0],
  7413. 'asArray' => true
  7414. ) );
  7415. foreach ( $roleVerify as $o => $p ) {
  7416. $staffID = explode ( '_', $p );
  7417. $staffInfo = $staff->getOne ( array (
  7418. 'where' => 'sid=' . $staffID [0],
  7419. 'asArray' => true
  7420. ) );
  7421. // print_r($staffID);
  7422. $exp = array (
  7423. 0 => $staffInfo ['sid'],
  7424. 1 => $staffID [1],
  7425. 2 => $staffInfo ['avatar'],
  7426. 'date' => '',
  7427. 'date' => '',
  7428. 'opinion' => '',
  7429. 'status' => '',
  7430. 'rolename' => $rolename ['name']
  7431. );
  7432. array_push ( $roleArray, $exp );
  7433. }
  7434. $roleArrayCopy [$v [0]] = $roleArray;
  7435. // $verifyList[$k]['roleArray']=$roleArray;
  7436. }
  7437. // print_r($roleArray);
  7438. $verifyList [$k] ['date'] = "";
  7439. $verifyList [$k] ['opinion'] = "";
  7440. $verifyList [$k] ['status'] = "";
  7441. if (empty ( $verifyStaff )) {
  7442. $verifyList [$k] ['date'] = "";
  7443. $verifyList [$k] ['opinion'] = "";
  7444. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7445. $verifyList [$k] ['status'] = 4;
  7446. $button = 4;
  7447. $flag = false;
  7448. }
  7449. } else {
  7450. foreach ( $verifyStaff as $m => $u ) {
  7451. if ($v [0] == $m) {
  7452. $verifyList [$k] ['date'] = $u ['date'];
  7453. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7454. $verifyList [$k] ['status'] = $u ['status'];
  7455. $flag = false;
  7456. break;
  7457. }
  7458. }
  7459. $endStaffArray = end ( $verifyStaff );
  7460. if (isset ( $endStaffArray ['ROLE'] )) {
  7461. } else {
  7462. $endKey = key ( $verifyStaff );
  7463. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7464. $button = 4;
  7465. $verifyList [$k] ['status'] = 4;
  7466. }
  7467. }
  7468. }
  7469. }
  7470. $rolename ['name'] = '';
  7471. if (! empty ( $roleId )) {
  7472. Doo::loadModel ( 'role' );
  7473. $role = new role ();
  7474. $rolename = $role->getOne ( array (
  7475. 'where' => 'rid=' . $roleId,
  7476. 'asArray' => true
  7477. ) );
  7478. }
  7479. if (! empty ( $verifyStaff ))
  7480. $endStaffArray = end ( $verifyStaff );
  7481. $KOP = false;
  7482. foreach ( $roleArrayCopy as $P => $A ) {
  7483. foreach ( $A as $MKI => $AVL ) {
  7484. if (! empty ( $verifyStaff )) {
  7485. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7486. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7487. $button = 4;
  7488. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7489. }
  7490. foreach ( $verifyStaff as $m => $u ) {
  7491. $AVLFK = $AVL [0] . '_R';
  7492. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7493. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7494. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7495. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7496. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7497. break;
  7498. }
  7499. }
  7500. } else {
  7501. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7502. $button = 4;
  7503. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7504. }
  7505. }
  7506. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7507. $KOP = true;
  7508. }
  7509. }
  7510. foreach ( $roleArrayCopy as $k => $v ) {
  7511. foreach ( $verifyList as $m => $n ) {
  7512. if ($n [0] == $k) {
  7513. array_splice ( $verifyList, $m, 1, $v );
  7514. }
  7515. }
  7516. }
  7517. $receiptList [$key] ['verifyList'] = $verifyList;
  7518. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7519. 'where' => 'sid=' . $value ['staff'],
  7520. 'asArray' => true
  7521. ) );
  7522. $receiptList [$key] ['button'] = $button;
  7523. }
  7524. $mothHtml = "";
  7525. for($i = 1; $i <= 12; $i ++) {
  7526. if ($month == $i)
  7527. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7528. else
  7529. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7530. }
  7531. // 获取审批日志
  7532. Doo::loadModel ( 'receiptLog' );
  7533. $receiptLog = new receiptLog ();
  7534. $rlList = array ();
  7535. $rlInfo = $receiptLog->getOne ( array (
  7536. 'where' => 'rid=' . $rid . ' and status=4',
  7537. 'asArray' => true
  7538. ) );
  7539. $tijdate = $receiptLog->getOne ( array (
  7540. 'where' => 'rid=' . $rid . ' and status=2',
  7541. 'asc' => 'rlid',
  7542. 'asArray' => true
  7543. ) );
  7544. if (! empty ( $rlInfo )) {
  7545. $rlList = $receiptLog->find ( array (
  7546. 'where' => 'rid=' . $rid,
  7547. 'asc' => 'rlid',
  7548. 'asArray' => true
  7549. ) );
  7550. }
  7551. $receiptList [0] ['rlList'] = $rlList;
  7552. $enclosurList = $enclosur->find ( array (
  7553. 'where' => 'rid=' . $rid,
  7554. 'asArray' => true
  7555. ) );
  7556. $enclosurHtml = '';
  7557. foreach ( $enclosurList as $value ) {
  7558. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7559. }
  7560. $data ['enclosurHtml'] = $enclosurHtml;
  7561. $data ['rolename'] = $rolename ['name'];
  7562. $data ['datetij'] = $tijdate ['date'];
  7563. $data ['mothHtml'] = $mothHtml;
  7564. $data ['receiptList'] = $receiptList;
  7565. $data ['receiptApprovalCount'] = count ( $receiptList );
  7566. $data ['year'] = $year;
  7567. $data ['categoryList'] = $categoryList;
  7568. $data ['staffList'] = $staffList;
  7569. $data ['cid'] = $cid;
  7570. $data ['sid'] = $sid;
  7571. $data ['status'] = 0;
  7572. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7573. $ap = 4;
  7574. } else
  7575. $data ['status'] = $receiptList [0] ['status'];
  7576. if ($receiptList [0] ['status'] == 4) {
  7577. $data ['status'] = 5;
  7578. $ap = 0;
  7579. }
  7580. $data ['ap'] = $ap;
  7581. $data ['memu'] = "receipt";
  7582. $data ['staff'] = $this->staff;
  7583. $data ['receiptMemu'] = 'approval';
  7584. $data ['verifyId'] = $this->verifyId;
  7585. $data ['executeId'] = $this->executeId;
  7586. $this->render ( "/admin/saeaReportListReport", $data );
  7587. }
  7588. function approvalEdi() {
  7589. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7590. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7591. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7592. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7593. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7594. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7595. if (empty ( $status ))
  7596. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7597. $vidList = array ();
  7598. $button = 0;
  7599. Doo::loadModel ( 'verify' );
  7600. Doo::loadModel ( 'receipt' );
  7601. Doo::loadModel ( 'staff' );
  7602. $staff = new staff ();
  7603. $receipt = new receipt ();
  7604. $verify = new verify ();
  7605. Doo::loadModel ( 'L_category' );
  7606. $Lcategory = new L_category ();
  7607. Doo::loadModel ( 'enclosur' );
  7608. $enclosur = new enclosur ();
  7609. // user verify ID
  7610. $verifyDetail = $verify->find ( array (
  7611. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7612. 'asArray' => true
  7613. ) );
  7614. foreach ( $verifyDetail as $key => $value ) {
  7615. array_push ( $vidList, $value ['vid'] );
  7616. }
  7617. $vid = implode ( ",", $vidList );
  7618. if (empty ( $verifyDetail ))
  7619. $vid = 0;
  7620. $categoryList = $Lcategory->find ( array (
  7621. 'asArray' => true
  7622. ) );
  7623. $staffList = $staff->find ( array (
  7624. 'where' => 'cid=' . $cid,
  7625. 'asArray' => true
  7626. ) );
  7627. $ap = "";
  7628. if ($status == 4) {
  7629. $ap = 4;
  7630. $status = 2;
  7631. }
  7632. // get Receipt By verifyID status 2
  7633. $receiptList = $receipt->find ( array (
  7634. 'where' => 'rid =' . $rid,
  7635. 'desc' => 'rid',
  7636. 'asArray' => true
  7637. ) );
  7638. $Locate = 0;
  7639. $roleId = 0;
  7640. if ($ap == 4)
  7641. $status = 4;
  7642. foreach ( $receiptList as $key => $value ) {
  7643. $receiptList [$key] ['Locate'] = $Locate;
  7644. $Locate ++;
  7645. $receiptList [$key] ['reviseDetail'] = array ();
  7646. if (! empty ( $value ['reviseDetail'] ))
  7647. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7648. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7649. $categoryDetil = $Lcategory->getOne ( array (
  7650. 'where' => 'cid=' . $value ['cid'],
  7651. 'asArray' => true
  7652. ) );
  7653. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7654. // 检测编辑状态
  7655. $verifyList = $verify->getOne ( array (
  7656. 'where' => 'vid=' . $value ['verify'],
  7657. 'asArray' => true
  7658. ) );
  7659. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7660. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7661. // print_r($verifyList);
  7662. //
  7663. // if (empty($verifyStaff)){
  7664. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7665. // $verifyList[0]['status']=4;$button=4;
  7666. // }
  7667. //
  7668. // }else{
  7669. //
  7670. // }
  7671. // die;
  7672. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  7673. // echo array_search("green",$a);
  7674. //
  7675. Doo::loadModel ( 'role' );
  7676. $role = new role ();
  7677. // print_r($verifyList);
  7678. $flag = true;
  7679. $roleKey = 0;
  7680. $endStaffArray = array ();
  7681. $roleArrayCopy = array ();
  7682. foreach ( $verifyList as $k => $v ) {
  7683. // init verifyStaff
  7684. if ($v [1] == 'ROLE') {
  7685. if (! empty ( $verifyStaff )) {
  7686. $endStaffArray = end ( $verifyStaff );
  7687. if ($v [0] == $endStaffArray ['nextStaff']) {
  7688. $roleId = $v [0];
  7689. }
  7690. }
  7691. $roleVerify = json_decode ( $v [3], true );
  7692. $roleKey = $k;
  7693. $roleArray = array ();
  7694. $rolename = $role->getOne ( array (
  7695. 'where' => 'rid=' . $v [0],
  7696. 'asArray' => true
  7697. ) );
  7698. foreach ( $roleVerify as $o => $p ) {
  7699. $staffID = explode ( '_', $p );
  7700. $staffInfo = $staff->getOne ( array (
  7701. 'where' => 'sid=' . $staffID [0],
  7702. 'asArray' => true
  7703. ) );
  7704. // print_r($staffID);
  7705. $exp = array (
  7706. 0 => $staffInfo ['sid'],
  7707. 1 => $staffID [1],
  7708. 2 => $staffInfo ['avatar'],
  7709. 'date' => '',
  7710. 'date' => '',
  7711. 'opinion' => '',
  7712. 'status' => '',
  7713. 'rolename' => $rolename ['name']
  7714. );
  7715. array_push ( $roleArray, $exp );
  7716. }
  7717. $roleArrayCopy [$v [0]] = $roleArray;
  7718. // $verifyList[$k]['roleArray']=$roleArray;
  7719. }
  7720. // print_r($roleArray);
  7721. $verifyList [$k] ['date'] = "";
  7722. $verifyList [$k] ['opinion'] = "";
  7723. $verifyList [$k] ['status'] = "";
  7724. if (empty ( $verifyStaff )) {
  7725. $verifyList [$k] ['date'] = "";
  7726. $verifyList [$k] ['opinion'] = "";
  7727. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7728. $verifyList [$k] ['status'] = 4;
  7729. $button = 4;
  7730. $flag = false;
  7731. }
  7732. } else {
  7733. foreach ( $verifyStaff as $m => $u ) {
  7734. if ($v [0] == $m) {
  7735. $verifyList [$k] ['date'] = $u ['date'];
  7736. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7737. $verifyList [$k] ['status'] = $u ['status'];
  7738. $flag = false;
  7739. break;
  7740. }
  7741. }
  7742. $endStaffArray = end ( $verifyStaff );
  7743. if (isset ( $endStaffArray ['ROLE'] )) {
  7744. } else {
  7745. $endKey = key ( $verifyStaff );
  7746. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7747. $button = 4;
  7748. $verifyList [$k] ['status'] = 4;
  7749. }
  7750. }
  7751. // print_r($endStaffArray);die;
  7752. // if (empty($verifyStaff)){
  7753. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  7754. // $verifyList[$k]['status']=4;$button=4;
  7755. // }
  7756. //
  7757. // }else{
  7758. //
  7759. // }
  7760. // if($flag){//检测可编辑
  7761. // if($v[0]==$this->staff[0]['sid']){
  7762. // $verifyList[$k]['status']=4;$button=4;
  7763. // }
  7764. // }
  7765. }
  7766. }
  7767. $rolename ['name'] = '';
  7768. if (! empty ( $roleId )) {
  7769. Doo::loadModel ( 'role' );
  7770. $role = new role ();
  7771. $rolename = $role->getOne ( array (
  7772. 'where' => 'rid=' . $roleId,
  7773. 'asArray' => true
  7774. ) );
  7775. }
  7776. if (! empty ( $verifyStaff ))
  7777. $endStaffArray = end ( $verifyStaff );
  7778. $KOP = false;
  7779. foreach ( $roleArrayCopy as $P => $A ) {
  7780. foreach ( $A as $MKI => $AVL ) {
  7781. if (! empty ( $verifyStaff )) {
  7782. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7783. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7784. $button = 4;
  7785. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7786. }
  7787. foreach ( $verifyStaff as $m => $u ) {
  7788. $AVLFK = $AVL [0] . '_R';
  7789. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7790. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7791. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7792. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7793. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7794. break;
  7795. }
  7796. }
  7797. } else {
  7798. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7799. $button = 4;
  7800. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7801. }
  7802. }
  7803. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7804. $KOP = true;
  7805. }
  7806. }
  7807. // print_r($roleArrayCopy);
  7808. // echo $roleKey;
  7809. foreach ( $roleArrayCopy as $k => $v ) {
  7810. foreach ( $verifyList as $m => $n ) {
  7811. if ($n [0] == $k) {
  7812. array_splice ( $verifyList, $m, 1, $v );
  7813. }
  7814. }
  7815. }
  7816. // if ($KOP)
  7817. // array_splice($verifyList,$roleKey,1,$roleArray);
  7818. // print_r($verifyList);
  7819. $receiptList [$key] ['verifyList'] = $verifyList;
  7820. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7821. 'where' => 'sid=' . $value ['staff'],
  7822. 'asArray' => true
  7823. ) );
  7824. $receiptList [$key] ['button'] = $button;
  7825. }
  7826. // $data['verifyDetail']=$verifyDetail;
  7827. $mothHtml = "";
  7828. for($i = 1; $i <= 12; $i ++) {
  7829. if ($month == $i)
  7830. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7831. else
  7832. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7833. }
  7834. // 获取审批日志
  7835. Doo::loadModel ( 'receiptLog' );
  7836. $receiptLog = new receiptLog ();
  7837. $rlList = array ();
  7838. $rlInfo = $receiptLog->getOne ( array (
  7839. 'where' => 'rid=' . $rid . ' and status=4',
  7840. 'asArray' => true
  7841. ) );
  7842. $tijdate = $receiptLog->getOne ( array (
  7843. 'where' => 'rid=' . $rid . ' and status=2',
  7844. 'asc' => 'rlid',
  7845. 'asArray' => true
  7846. ) );
  7847. if (! empty ( $rlInfo )) {
  7848. $rlList = $receiptLog->find ( array (
  7849. 'where' => 'rid=' . $rid,
  7850. 'asc' => 'rlid',
  7851. 'asArray' => true
  7852. ) );
  7853. }
  7854. $receiptList [0] ['rlList'] = $rlList;
  7855. $enclosurList = $enclosur->find ( array (
  7856. 'where' => 'rid=' . $rid,
  7857. 'asArray' => true
  7858. ) );
  7859. $enclosurHtml = '';
  7860. foreach ( $enclosurList as $value ) {
  7861. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7862. }
  7863. $data ['enclosurHtml'] = $enclosurHtml;
  7864. $data ['rolename'] = $rolename ['name'];
  7865. $data ['datetij'] = $tijdate ['date'];
  7866. $data ['mothHtml'] = $mothHtml;
  7867. $data ['receiptList'] = $receiptList;
  7868. $data ['receiptApprovalCount'] = count ( $receiptList );
  7869. $data ['status'] = $status;
  7870. $data ['year'] = $year;
  7871. $data ['categoryList'] = $categoryList;
  7872. $data ['staffList'] = $staffList;
  7873. $data ['cid'] = $cid;
  7874. $data ['sid'] = $sid;
  7875. $data ['ap'] = $ap;
  7876. $data ['memu'] = "receipt";
  7877. $data ['staff'] = $this->staff;
  7878. $data ['receiptMemu'] = 'approval';
  7879. $data ['verifyId'] = $this->verifyId;
  7880. $data ['executeId'] = $this->executeId;
  7881. $this->render ( "/admin/saeaReportListReport", $data );
  7882. }
  7883. function remittanceHky() {
  7884. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7885. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  7886. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  7887. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  7888. $page_size = 15;
  7889. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  7890. Doo::loadModel ( 'receipt' );
  7891. $receipt = new receipt ();
  7892. Doo::loadModel ( 'staff' );
  7893. $staff = new staff ();
  7894. $dateCondition = " and Year(executeDate) =" . $year;
  7895. if ($moth != 'MONTH')
  7896. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  7897. if ($day != 'DAY' && $moth != 'MONTH')
  7898. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  7899. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  7900. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  7901. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  7902. $limit = $pageinfo ['lower'] . ',' . $page_size;
  7903. $dayList = $receipt->find ( array (
  7904. 'select' => 'executeDate,sum(amount) as amount',
  7905. 'where' => $sql,
  7906. 'desc' => 'executeDate',
  7907. 'groupby' => 'executeDate',
  7908. 'limit' => $limit,
  7909. 'asArray' => true
  7910. ) );
  7911. // print_r($dayList);
  7912. foreach ( $dayList as $key => $value ) {
  7913. $remitString = "";
  7914. $receiptList = $receipt->find ( array (
  7915. 'select' => 'rid,executeDate,amount,staff,cid',
  7916. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  7917. 'desc' => 'executeDate',
  7918. 'asArray' => true
  7919. ) );
  7920. foreach ( $receiptList as $k => $v ) {
  7921. $sinfo = $staff->getOne ( array (
  7922. 'select' => 'username,category',
  7923. 'where' => ' sid=' . $v ['staff'],
  7924. 'asArray' => true
  7925. ) );
  7926. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  7927. }
  7928. $dayList [$key] ['staff'] = $remitString;
  7929. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  7930. }
  7931. // print_r($dayList);
  7932. $mothHtml = "";
  7933. for($i = 1; $i <= 12; $i ++) {
  7934. if ($moth == $i)
  7935. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7936. else
  7937. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7938. }
  7939. $dayHtml = "";
  7940. if ($day != "DAY" || $moth != "MONTH") {
  7941. for($i = 1; $i <= 31; $i ++) {
  7942. if ($day == $i)
  7943. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7944. else
  7945. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7946. }
  7947. }
  7948. $dateHtml = "";
  7949. $now = date ( "Y" );
  7950. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  7951. if ($YEARD <= $now) {
  7952. $dateHtml .= '<option ';
  7953. if ($year == $YEARD) {
  7954. $dateHtml .= 'selected ';
  7955. }
  7956. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  7957. }
  7958. }
  7959. $data ['dateHtml'] = $dateHtml;
  7960. $data ['page'] = $pageinfo;
  7961. $data ['year'] = $year;
  7962. $data ['moth'] = $moth;
  7963. $data ['day'] = $day;
  7964. $data ['get'] = $get;
  7965. $data ['dayHtml'] = $dayHtml;
  7966. $data ['mothHtml'] = $mothHtml;
  7967. $data ['receiptList'] = $dayList;
  7968. $data ['memu'] = "receipt";
  7969. $data ['staff'] = $this->staff;
  7970. $data ['receiptMemu'] = 'remittanceHky';
  7971. $data ['verifyId'] = $this->verifyId;
  7972. $data ['executeId'] = $this->executeId;
  7973. $this->render ( "/admin/remittanceHky", $data );
  7974. }
  7975. function remittancep() {
  7976. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  7977. Doo::loadModel ( 'receipt' );
  7978. $receipt = new receipt ();
  7979. Doo::loadModel ( 'staff' );
  7980. $staff = new staff ();
  7981. Doo::loadClass ( 'XDeode' );
  7982. $XDeode = new XDeode ( 5 );
  7983. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  7984. $rplist = $receipt->find ( array (
  7985. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7986. 'asArray' => true
  7987. ) );
  7988. $dayList = $receipt->find ( array (
  7989. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  7990. 'desc' => 'executeDate',
  7991. 'groupby' => 'staff',
  7992. 'asArray' => true
  7993. ) );
  7994. $html = '';
  7995. foreach ( $dayList as $key => $value ) {
  7996. $sinfo = $staff->getOne ( array (
  7997. 'select' => 'username,category',
  7998. 'where' => ' sid=' . $value ['staff'],
  7999. 'asArray' => true
  8000. ) );
  8001. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8002. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8003. $au = 0;
  8004. foreach ( $rplist as $k => $v ) {
  8005. if ($value ['staff'] == $v ['staff']) {
  8006. $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>';
  8007. $au += $v ['amount'];
  8008. }
  8009. }
  8010. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8011. }
  8012. $data ['html'] = $html;
  8013. $data ['memu'] = "receipt";
  8014. $data ['staff'] = $this->staff;
  8015. $data ['receiptMemu'] = 'remittanceHky';
  8016. $data ['verifyId'] = $this->verifyId;
  8017. $data ['executeId'] = $this->executeId;
  8018. $this->render ( "/admin/remittancep", $data );
  8019. }
  8020. function ajaxGetReceiptDetails() {
  8021. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8022. Doo::loadClass ( 'XDeode' );
  8023. $XDeode = new XDeode ( 5 );
  8024. $rid = $XDeode->decode ( $rid );
  8025. if (empty ( $rid )) {
  8026. echo json_encode ( array (
  8027. 'status' => 2,
  8028. 'msg' => 'illegal request'
  8029. ) );
  8030. die ();
  8031. }
  8032. Doo::loadModel ( 'receipt' );
  8033. $receipt = new receipt ();
  8034. Doo::loadModel ( 'staff' );
  8035. $staff = new staff ();
  8036. $rinfo = $receipt->getOne ( array (
  8037. 'where' => 'rid= ' . $rid,
  8038. 'asArray' => true
  8039. ) );
  8040. $sinfo = $staff->getOne ( array (
  8041. 'select' => 'username,category',
  8042. 'where' => ' sid=' . $rinfo ['staff'],
  8043. 'asArray' => true
  8044. ) );
  8045. $rinfo ['reviseDetail'] = array ();
  8046. if (! empty ( $rinfo ['reviseDetail'] ))
  8047. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8048. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8049. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8050. $rinfo ['category'] = $sinfo ['category'];
  8051. $verifyStaff = array ();
  8052. if (! empty ( $rinfo ['verifyStaff'] ))
  8053. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8054. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8055. $rinfo ['relust'] = $relust;
  8056. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8057. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8058. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8059. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8060. // 费用执行人相关数据
  8061. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8062. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8063. foreach ( $executeCopy as $k => $v ) {
  8064. $executeCopy [$k] ['date'] = '';
  8065. $executeCopy [$k] ['opinion'] = '';
  8066. $executeCopy [$k] ['status'] = '';
  8067. if (! empty ( $executeStaff ))
  8068. foreach ( $executeStaff as $m => $u ) {
  8069. if ($v [0] == $m) {
  8070. $executeCopy [$k] ['date'] = $u ['date'];
  8071. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8072. $executeCopy [$k] ['status'] = $u ['status'];
  8073. break;
  8074. }
  8075. }
  8076. }
  8077. $rinfo ['executeCopy'] = $executeCopy;
  8078. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8079. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8080. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8081. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8082. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8083. $html .= '<tr><th>' . $value ['name'] . '</th>
  8084. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8085. }
  8086. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8087. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8088. <tr><th class="taC" colspan="2">费用说明</th>
  8089. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8090. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8091. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8092. </tbody></table>';
  8093. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8094. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8095. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8096. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8097. $html .= '<tr><th>' . $value ['name'] . '</th>
  8098. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8099. }
  8100. $html .= '<tr><th class="taR">合计</th>
  8101. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8102. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8103. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8104. $html .= '<tr><th>' . $value ['name'] . '</th>
  8105. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8106. }
  8107. $html .= '<tr><th class="taR">合计</th>
  8108. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8109. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8110. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8111. $html .= '<tr><th>' . $value ['name'] . '</th>
  8112. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8113. }
  8114. $html .= '<tr><th class="taR">合计</th>
  8115. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8116. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8117. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8118. $html .= '<tr><th>' . $value ['name'] . '</th>
  8119. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8120. }
  8121. $html .= '<tr><th class="taR">合计</th>
  8122. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8123. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8124. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8125. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8126. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8127. }
  8128. $html .= '<tr><th class="taR">合计</th>
  8129. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8130. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8131. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8132. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8133. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8134. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8135. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8136. <tr';
  8137. if ($rinfo ['relust'] >= 0) {
  8138. $html .= 'class="success"';
  8139. } else {
  8140. $html .= 'class="error"';
  8141. }
  8142. $html .= '><td class="taR"><b>借款结余</b></td>
  8143. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8144. </tbody></table>
  8145. ';
  8146. }
  8147. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8148. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8149. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8150. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8151. $html .= '<tr><th>' . $value ['name'] . '</th>
  8152. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8153. }
  8154. $html .= '<tr><th class="taR">合计</th>
  8155. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8156. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8157. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8158. <tr><th class="taC" colspan="2">费用说明</th>
  8159. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8160. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8161. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8162. </tbody></table>';
  8163. } else {
  8164. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8165. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8166. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8167. $html .= '<tr><th>' . $value ['name'] . '</th>
  8168. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8169. }
  8170. $html .= '<tr><th class="taR">合计</th>
  8171. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8172. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8173. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8174. $html .= '<tr><th>' . $value ['name'] . '</th>
  8175. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8176. }
  8177. $html .= '<tr><th class="taR">合计</th>
  8178. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8179. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8180. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8181. $html .= '<tr><th>' . $value ['name'] . '</th>
  8182. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8183. }
  8184. $html .= '<tr><th class="taR">合计</th>
  8185. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8186. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8187. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8188. $html .= '<tr><th>' . $value ['name'] . '</th>
  8189. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8190. }
  8191. $html .= '<tr><th class="taR">合计</th>
  8192. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8193. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8194. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8195. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8196. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8197. }
  8198. $html .= '<tr><th class="taR">合计</th>
  8199. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8200. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8201. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8202. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8203. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8204. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8205. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8206. $html .= '</tbody></table>';
  8207. /*
  8208. * <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>
  8209. */
  8210. }
  8211. // print_r($verifyStaff);die;
  8212. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8213. foreach ( $verifyStaff as $key => $value ) {
  8214. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8215. $sinfo = $staff->getOne ( array (
  8216. 'select' => 'username',
  8217. 'where' => ' sid=' . $key,
  8218. 'asArray' => true
  8219. ) );
  8220. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8221. }
  8222. $html .= '</tbody></table>';
  8223. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8224. foreach ( $rinfo ['executeCopy'] as $value ) {
  8225. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8226. }
  8227. $html .= '</tbody></table>';
  8228. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8229. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8230. </tr></table>';
  8231. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8232. echo json_encode ( array (
  8233. 'status' => 1,
  8234. 'html' => $html
  8235. ) );
  8236. die ();
  8237. }
  8238. /**
  8239. * 删除附件
  8240. */
  8241. function ajaxRemEnclousur() {
  8242. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8243. if (empty ( $key ))
  8244. echo json_encode ( array (
  8245. 'status' => 2
  8246. ) );
  8247. Doo::loadModel ( 'enclosur' );
  8248. $enclosur = new enclosur ();
  8249. $enclosur->delEnclosurByEid ( $key );
  8250. echo json_encode ( array (
  8251. 'status' => 1
  8252. ) );
  8253. }
  8254. function remittance() {
  8255. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8256. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8257. Doo::loadModel ( 'receipt' );
  8258. $receipt = new receipt ();
  8259. Doo::loadModel ( 'staff' );
  8260. $staff = new staff ();
  8261. $dateCondition = " and Year(pastDate) =" . $year;
  8262. if (! empty ( $month ))
  8263. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8264. // get Receipt By verifyID status 1
  8265. $receiptList = $receipt->find ( array (
  8266. 'select' => 'sum(sum) as sum,staff,pastDate',
  8267. 'where' => ' status=1' . $dateCondition,
  8268. 'desc' => 'pastDate',
  8269. 'groupby' => 'staff,pastDate',
  8270. 'asArray' => true
  8271. ) );
  8272. $dateList = $receipt->find ( array (
  8273. 'select' => 'pastDate,verifyStaff',
  8274. 'where' => ' status=1' . $dateCondition,
  8275. 'desc' => 'pastDate',
  8276. 'groupby' => 'pastDate',
  8277. 'asArray' => true
  8278. ) );
  8279. $dataList = array ();
  8280. foreach ( $dateList as $d => $a ) {
  8281. $dataList [$a ['pastDate']] = array ();
  8282. $daySum = 0;
  8283. foreach ( $receiptList as $key => $value ) {
  8284. if ($a ['pastDate'] == $value ['pastDate']) {
  8285. $oderList = $receipt->find ( array (
  8286. 'select' => 'receiptOrder',
  8287. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8288. 'asArray' => true
  8289. ) );
  8290. $list = array ();
  8291. $html = "";
  8292. foreach ( $oderList as $v ) {
  8293. array_push ( $list, $v ['receiptOrder'] );
  8294. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8295. }
  8296. $receiptList [$key] ['receiptOrder'] = $html;
  8297. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8298. $sinfo = $staff->getOne ( array (
  8299. 'select' => 'username ',
  8300. 'where' => ' sid=' . $value ['staff'],
  8301. 'asArray' => true
  8302. ) );
  8303. $receiptList [$key] ['username'] = $sinfo ['username'];
  8304. $daySum += $value ['sum'];
  8305. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8306. }
  8307. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8308. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8309. }
  8310. }
  8311. // print_r($dataList);
  8312. $data ['dataList'] = $dataList;
  8313. $mothHtml = "";
  8314. for($i = 1; $i <= 12; $i ++) {
  8315. if ($month == $i)
  8316. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8317. else
  8318. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8319. }
  8320. $data ['year'] = $year;
  8321. $data ['mothHtml'] = $mothHtml;
  8322. $data ['memu'] = "receipt";
  8323. $data ['staff'] = $this->staff;
  8324. $data ['receiptMemu'] = 'approval';
  8325. $data ['verifyId'] = $this->verifyId;
  8326. $data ['executeId'] = $this->executeId;
  8327. $this->render ( "/admin/saeaReportListPay", $data );
  8328. }
  8329. /**
  8330. * 金额调整,提高稳定性
  8331. * @return string
  8332. */
  8333. function revocationAdjustment() {
  8334. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8335. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8336. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8337. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8338. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8339. Doo::loadClass ( 'XDeode' );
  8340. $XDeode = new XDeode ( 5 );
  8341. Doo::loadModel ( 'receipt' );
  8342. $receipt = new receipt ();
  8343. $sid = $XDeode->decode ( $sidKey );
  8344. $rid = $XDeode->decode ( $ridKey );
  8345. $reviseKey = $XDeode->decode ( $reviseKey );
  8346. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8347. die ( 'illegal request' );
  8348. $receiptDetail = $receipt->getOne ( array (
  8349. 'where' => 'rid=' . $rid,
  8350. 'asArray' => true
  8351. ) );
  8352. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8353. die ( 'illegal request' );
  8354. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8355. if (! isset ( $reviseDetail [$reviseKey] ))
  8356. die ( 'illegal request' );
  8357. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8358. unset ( $reviseDetail [$reviseKey] );
  8359. $revisePrice = 0;
  8360. foreach ( $reviseDetail as $key => $value ) {
  8361. $revisePrice += $value ['price'];
  8362. }
  8363. $reviseDetailString = json_encode ( $reviseDetail );
  8364. $receipt->reviseDetail = $reviseDetailString;
  8365. $receipt->sum = $receiptDetail ['sum'] - $price;
  8366. $receipt->revisePrice = $revisePrice;
  8367. $receipt->update ( array (
  8368. 'where' => 'rid=' . $rid
  8369. ) );
  8370. return '/receiptburEdi/' . $rid;
  8371. } else
  8372. die ( 'illegal request2' );
  8373. }
  8374. function updateApprovalReceipt() {
  8375. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8376. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8377. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8378. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8379. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8380. if (! empty ( $rid )) {
  8381. Doo::loadModel ( "verify" );
  8382. $verify = new verify ();
  8383. Doo::loadModel ( "receiptDetail" );
  8384. $receiptDetailObj = new receiptDetail ();
  8385. Doo::loadModel ( "itemStatistics" );
  8386. Doo::loadModel ( "statistics" );
  8387. $statistics = new statistics ();
  8388. $itemStatistics = new itemStatistics ();
  8389. Doo::loadModel ( "receipt" );
  8390. $receipt = new receipt ();
  8391. $receiptDetail = $receipt->getOne ( array (
  8392. 'where' => 'rid=' . $rid . ' and status=2 ',
  8393. 'asArray' => true
  8394. ) );
  8395. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8396. $nsflag = true;
  8397. foreach ( $nslist as $value ) {
  8398. if ($value == $this->staff ['0'] ['sid']) {
  8399. $nsflag = false;
  8400. break;
  8401. }
  8402. }
  8403. if (empty ( $receiptDetail ) || $nsflag)
  8404. return "/approvalExpenses/pendApproval";
  8405. $verifyDetail = $verify->getOne ( array (
  8406. 'where' => ' vid =' . $receiptDetail ['verify'],
  8407. 'asArray' => true
  8408. ) );
  8409. $verifyString = $verifyDetail ['staff'];
  8410. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8411. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8412. if (empty ( $opinion )) {
  8413. if ($status == 3)
  8414. $opinion = "终止";
  8415. else
  8416. $opinion = "同意支付";
  8417. }
  8418. $nowStaff = 0;
  8419. $nowStaffList = array ();
  8420. if (empty ( $verifyStaff )) {
  8421. // 还需加入是否已经进入角色审批
  8422. if ($verifyDetail [0] [1] == 'ROLE') {
  8423. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8424. foreach ( $vStaffString as $key => $value ) {
  8425. $staffK = explode ( "_", $value );
  8426. if ($staffK [0] != $this->staff [0] ['sid'])
  8427. array_push ( $nowStaffList, $staffK [0] );
  8428. }
  8429. // print_r($verifyDetail);
  8430. // die;
  8431. if (! empty ( $nowStaffList )) {
  8432. $nowStaff = implode ( ',', $nowStaffList );
  8433. $verifyStaff = array (
  8434. $this->staff [0] ['sid'] . "_R" => array (
  8435. 'date' => date ( 'Y-m-d' ),
  8436. 'opinion' => $opinion,
  8437. 'status' => $status,
  8438. 'nextStaff' => $verifyDetail [0] [0],
  8439. 'ROLE' => 1
  8440. )
  8441. );
  8442. } else {
  8443. $nowStaff = $verifyDetail [1] [0];
  8444. $verifyStaff = array (
  8445. $this->staff [0] ['sid'] . "_R" => array (
  8446. 'date' => date ( 'Y-m-d' ),
  8447. 'opinion' => $opinion,
  8448. 'status' => $status,
  8449. 'nextStaff' => $verifyDetail [1] [0]
  8450. )
  8451. );
  8452. }
  8453. } else {
  8454. if ($verifyDetail [1] [1] == 'ROLE') {
  8455. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8456. // echo "dd";
  8457. foreach ( $vStaffString as $key => $value ) {
  8458. $staffK = explode ( "_", $value );
  8459. array_push ( $nowStaffList, $staffK [0] );
  8460. }
  8461. $nowStaff = implode ( ',', $nowStaffList );
  8462. $verifyStaff = array (
  8463. $this->staff [0] ['sid'] => array (
  8464. 'date' => date ( 'Y-m-d' ),
  8465. 'opinion' => $opinion,
  8466. 'status' => $status,
  8467. 'nextStaff' => $verifyDetail [1] [0],
  8468. 'ROLE' => 1
  8469. )
  8470. );
  8471. } else {
  8472. $nowStaff = $verifyDetail [1] [0];
  8473. $verifyStaff = array (
  8474. $this->staff [0] ['sid'] => array (
  8475. 'date' => date ( 'Y-m-d' ),
  8476. 'opinion' => $opinion,
  8477. 'status' => $status,
  8478. 'nextStaff' => $verifyDetail [1] [0]
  8479. )
  8480. );
  8481. }
  8482. }
  8483. if ($status == 3)
  8484. $verifyStaff = array (
  8485. 'final' => $status,
  8486. $this->staff [0] ['sid'] => array (
  8487. 'date' => date ( 'Y-m-d' ),
  8488. 'opinion' => $opinion,
  8489. 'status' => $status
  8490. )
  8491. );
  8492. $vStaffString = json_encode ( $verifyStaff );
  8493. $receipt->nowStaff = $nowStaff;
  8494. $receipt->verifyStaff = $vStaffString;
  8495. } else {
  8496. $VS = end ( $verifyStaff );
  8497. // 非角色审批
  8498. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8499. $nextStaff = 0;
  8500. $roleSTF = false;
  8501. foreach ( $verifyDetail as $key => $value ) {
  8502. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8503. if (isset ( $verifyDetail [$key + 1] )) {
  8504. $nextStaff = $verifyDetail [$key + 1] [0];
  8505. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8506. $roleSTF = true;
  8507. }
  8508. break;
  8509. }
  8510. }
  8511. if (! $roleSTF) {
  8512. $nowStaff = $nextStaff;
  8513. $verifyStaff [$this->staff [0] ['sid']] = array (
  8514. 'date' => date ( 'Y-m-d' ),
  8515. 'opinion' => $opinion,
  8516. 'status' => $status,
  8517. 'nextStaff' => $nextStaff
  8518. );
  8519. } else {
  8520. // 获取角色下的所有用户ID
  8521. $nowStaffList = array ();
  8522. foreach ( $verifyDetail as $vfk ) {
  8523. if ($vfk [1] == 'ROLE') {
  8524. $vStaffString = json_decode ( $vfk [3] );
  8525. foreach ( $vStaffString as $key => $value ) {
  8526. $staffK = explode ( "_", $value );
  8527. array_push ( $nowStaffList, $staffK [0] );
  8528. }
  8529. }
  8530. }
  8531. $nowStaff = implode ( ',', $nowStaffList );
  8532. $verifyStaff [$this->staff [0] ['sid']] = array (
  8533. 'date' => date ( 'Y-m-d' ),
  8534. 'opinion' => $opinion,
  8535. 'status' => $status,
  8536. 'nextStaff' => $nextStaff,
  8537. 'ROLE' => 0
  8538. );
  8539. }
  8540. if ($status == 3) {
  8541. $verifyStaff ['final'] = $status;
  8542. $verifyStaff [$this->staff [0] ['sid']] = array (
  8543. 'date' => date ( 'Y-m-d' ),
  8544. 'opinion' => $opinion,
  8545. 'status' => $status
  8546. );
  8547. }
  8548. $vStaffString = json_encode ( $verifyStaff );
  8549. $receipt->nowStaff = $nowStaff;
  8550. $receipt->verifyStaff = $vStaffString;
  8551. }
  8552. // 角色审批
  8553. if (isset ( $VS ['ROLE'] )) {
  8554. // 找出角色人 当前审批角色组
  8555. $verifyJSStaff = array ();
  8556. $nowStaffList2 = array ();
  8557. foreach ( $verifyDetail as $key => $value ) {
  8558. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8559. $verifyJSStaff = json_decode ( $value [3] );
  8560. foreach ( $verifyJSStaff as $m ) {
  8561. $staffK = explode ( "_", $m );
  8562. array_push ( $nowStaffList2, $staffK [0] );
  8563. }
  8564. // print_r($nowStaffList2);
  8565. }
  8566. }
  8567. $RoleVerifyStaff = array ();
  8568. foreach ( $verifyStaff as $key => $value ) {
  8569. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8570. foreach ( $nowStaffList2 as $m ) {
  8571. if ($key == $m . "_R")
  8572. $RoleVerifyStaff [$key] = $value;
  8573. }
  8574. }
  8575. }
  8576. // print_r($verifyStaff);
  8577. // print_r($nowStaffList2);
  8578. // print_r($RoleVerifyStaff);
  8579. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8580. // print_r($verifyJSStaff);
  8581. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8582. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8583. // 下一个审批人ID
  8584. $nextStaff = 0;
  8585. $falg = false;
  8586. foreach ( $verifyDetail as $key => $value ) {
  8587. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  8588. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  8589. $falg = true;
  8590. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  8591. $nowStaffList = array ();
  8592. foreach ( $vStaffString as $v ) {
  8593. $staffK = explode ( "_", $v );
  8594. array_push ( $nowStaffList, $staffK [0] );
  8595. }
  8596. $nowStaff = implode ( ',', $nowStaffList );
  8597. $nextStaff = $verifyDetail [$key + 1] [0];
  8598. } elseif (isset ( $verifyDetail [$key + 1] )) {
  8599. $nextStaff = $verifyDetail [$key + 1] [0];
  8600. $nowStaff = $nextStaff;
  8601. } else
  8602. $nowStaff = '';
  8603. break;
  8604. }
  8605. }
  8606. if ($falg)
  8607. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8608. 'date' => date ( 'Y-m-d' ),
  8609. 'opinion' => $opinion,
  8610. 'status' => $status,
  8611. 'nextStaff' => $nextStaff,
  8612. 'ROLE' => 1
  8613. );
  8614. else
  8615. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8616. 'date' => date ( 'Y-m-d' ),
  8617. 'opinion' => $opinion,
  8618. 'status' => $status,
  8619. 'nextStaff' => $nextStaff
  8620. );
  8621. // print_r($verifyStaff);
  8622. // echo $nowStaff;die;
  8623. } else { // 进入下一个角色或者审批人
  8624. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  8625. //
  8626. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  8627. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  8628. 'date' => date ( 'Y-m-d' ),
  8629. 'opinion' => $opinion,
  8630. 'status' => $status,
  8631. 'nextStaff' => $VS ['nextStaff'],
  8632. 'ROLE' => 1
  8633. );
  8634. // print_r($verifyStaff);
  8635. // die;
  8636. }
  8637. if ($status == 3) {
  8638. $verifyStaff ['final'] = $status;
  8639. $verifyStaff [$this->staff [0] ['sid']] = array (
  8640. 'date' => date ( 'Y-m-d' ),
  8641. 'opinion' => $opinion,
  8642. 'status' => $status
  8643. );
  8644. }
  8645. $vStaffString = json_encode ( $verifyStaff );
  8646. $receipt->verifyStaff = $vStaffString;
  8647. $receipt->nowStaff = $nowStaff;
  8648. // die;
  8649. // }
  8650. // print_r($verifyStaff);
  8651. // die;
  8652. }
  8653. // print_r($verifyStaff);die;
  8654. }
  8655. // print_r($verifyDetail);
  8656. $roleKey = 0;
  8657. $roleId = 0;
  8658. $verifyDetailCopy = array ();
  8659. foreach ( $verifyDetail as $k => $v ) {
  8660. if ($v [1] == 'ROLE') {
  8661. $roleId = $v [0];
  8662. $roleVerify = json_decode ( $v [3], true );
  8663. $roleKey = $k;
  8664. $roleArray = array ();
  8665. foreach ( $roleVerify as $o => $p ) {
  8666. $staffID = explode ( '_', $p );
  8667. $exp = array (
  8668. 0 => $staffID [0],
  8669. 1 => $staffID [1]
  8670. );
  8671. array_push ( $roleArray, $exp );
  8672. }
  8673. $verifyDetailCopy [$v [0]] = $roleArray;
  8674. }
  8675. }
  8676. // print_r($verifyDetail);
  8677. foreach ( $verifyDetailCopy as $k => $v ) {
  8678. foreach ( $verifyDetail as $m => $n ) {
  8679. if ($n [0] == $k) {
  8680. array_splice ( $verifyDetail, $m, 1, $v );
  8681. }
  8682. }
  8683. }
  8684. // die;
  8685. // if (!empty($roleArray))
  8686. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  8687. // echo $roleId;
  8688. // print_r($verifyStaff);
  8689. // print_r($verifyDetail);
  8690. // die;
  8691. Doo::loadModel ( "receiptLog" );
  8692. $receiptLog = new receiptLog ();
  8693. // 审批日志
  8694. if (! isset ( $verifyStaff ['final'] )) {
  8695. if (! empty ( $roleId )) {
  8696. Doo::loadModel ( "role" );
  8697. $role = new role ();
  8698. $roleInfo = $role->getOne ( array (
  8699. 'where' => 'rid=' . $roleId,
  8700. 'asArray' => true
  8701. ) );
  8702. $receiptLog->rolename = $roleInfo ['name'];
  8703. }
  8704. $receiptLog->username = $this->staff [0] ['username'];
  8705. $receiptLog->uid = $this->staff [0] ['sid'];
  8706. $receiptLog->date = date ( "Y-m-d" );
  8707. $receiptLog->opinion = $opinion;
  8708. $receiptLog->img = $this->staff [0] ['avatar'];
  8709. $receiptLog->status = 1;
  8710. $receiptLog->rid = $rid;
  8711. $receiptLog->insert ();
  8712. }
  8713. if (isset ( $verifyStaff ['final'] )) { // rDetail
  8714. $receipt->verifyBreakup = $verifyString;
  8715. $receipt->status = 3;
  8716. $receiptDetailObj->status = 3;
  8717. $receiptDetailObj->update ( array (
  8718. 'where' => 'rid=' . $rid
  8719. ) );
  8720. if (! empty ( $roleId )) {
  8721. Doo::loadModel ( "role" );
  8722. $role = new role ();
  8723. $roleInfo = $role->getOne ( array (
  8724. 'where' => 'rid=' . $roleId,
  8725. 'asArray' => true
  8726. ) );
  8727. $receiptLog->rolename = $roleInfo ['name'];
  8728. }
  8729. $receiptLog->username = $this->staff [0] ['username'];
  8730. $receiptLog->uid = $this->staff [0] ['sid'];
  8731. $receiptLog->date = date ( "Y-m-d" );
  8732. $receiptLog->opinion = $opinion;
  8733. $receiptLog->img = $this->staff [0] ['avatar'];
  8734. $receiptLog->status = 3;
  8735. $receiptLog->rid = $rid;
  8736. $receiptLog->insert ();
  8737. // 微信企业号通知
  8738. $this->setWXMsg ( $rid, 3 );
  8739. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  8740. $receipt->status = 1;
  8741. $reviseSum = 0;
  8742. $receipt->verifyBreakup = $verifyString;
  8743. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  8744. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8745. foreach ( $reviseDetail as $key => $value ) {
  8746. $receiptDetailObj = new receiptDetail ();
  8747. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8748. $receiptDetailObj->item = $value ['description'];
  8749. $receiptDetailObj->itemCategory = "报销金额调整";
  8750. $receiptDetailObj->price = $value ['price'];
  8751. $receiptDetailObj->date = $receiptDetail ['date'];
  8752. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  8753. $receiptDetailObj->rid = $rid;
  8754. $receiptDetailObj->status = 1;
  8755. $receiptDetailObj->insert ();
  8756. $reviseSum += $value ['price'];
  8757. }
  8758. $itemStatistics = new itemStatistics ();
  8759. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8760. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8761. $itemStatistics->price = $reviseSum;
  8762. $itemStatistics->itemCategory = "报销金额调整";
  8763. $itemStatistics->date = $receiptDetail ['date'];
  8764. $itemStatistics->insert ();
  8765. }
  8766. $receiptDetailObj = new receiptDetail ();
  8767. $receiptDetailObj->status = 1;
  8768. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  8769. $receiptDetailObj->update ( array (
  8770. 'where' => 'rid=' . $rid
  8771. ) );
  8772. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8773. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8774. $stat = $statistics->getOne ( array (
  8775. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  8776. 'asArray' => true
  8777. ) );
  8778. if (empty ( $stat )) {
  8779. $statistics->date = $receiptDetail ['date'];
  8780. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  8781. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  8782. $statistics->agPrice = $receiptDetail ['sum'];
  8783. $statistics->rePrice = $reviseSum;
  8784. $statistics->insert ();
  8785. } else {
  8786. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  8787. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  8788. $statistics->update ( array (
  8789. 'where' => 'sid=' . $stat ['sid']
  8790. ) );
  8791. }
  8792. $dateArray = explode ( "-", $receiptDetail ['date'] );
  8793. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  8794. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  8795. foreach ( $accountItem ['cSum'] as $key => $value ) {
  8796. if ($key == "agencySum") {
  8797. $iStatistics = $itemStatistics->getOne ( array (
  8798. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  8799. 'asArray' => true
  8800. ) );
  8801. if (empty ( $iStatistics )) {
  8802. $itemStatistics->cid = $receiptDetail ['cid'];
  8803. ;
  8804. $itemStatistics->staff = $receiptDetail ['staff'];
  8805. $itemStatistics->price = $value;
  8806. $itemStatistics->itemCategory = $this->AGENCY;
  8807. $itemStatistics->date = $receiptDetail ['date'];
  8808. $itemStatistics->insert ();
  8809. } else {
  8810. if (! empty ( $value )) {
  8811. $itemStatistics->price = $value + $iStatistics ['price'];
  8812. $itemStatistics->update ( array (
  8813. 'where' => 'sid=' . $iStatistics ['sid']
  8814. ) );
  8815. }
  8816. }
  8817. } elseif ($key == "travelSum") {
  8818. $iStatistics = $itemStatistics->getOne ( array (
  8819. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  8820. 'asArray' => true
  8821. ) );
  8822. if (empty ( $iStatistics )) {
  8823. $itemStatistics->cid = $receiptDetail ['cid'];
  8824. $itemStatistics->staff = $receiptDetail ['staff'];
  8825. $itemStatistics->price = $value;
  8826. $itemStatistics->itemCategory = $this->TRAVEL;
  8827. $itemStatistics->date = $receiptDetail ['date'];
  8828. $itemStatistics->insert ();
  8829. } else {
  8830. if (! empty ( $value )) {
  8831. $itemStatistics->price = $value + $iStatistics ['price'];
  8832. $itemStatistics->update ( array (
  8833. 'where' => 'sid=' . $iStatistics ['sid']
  8834. ) );
  8835. }
  8836. }
  8837. } elseif ($key == "trainSum") {
  8838. $iStatistics = $itemStatistics->getOne ( array (
  8839. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  8840. 'asArray' => true
  8841. ) );
  8842. if (empty ( $iStatistics )) {
  8843. $itemStatistics->cid = $receiptDetail ['cid'];
  8844. $itemStatistics->staff = $receiptDetail ['staff'];
  8845. $itemStatistics->price = $value;
  8846. $itemStatistics->itemCategory = $this->TRAIN;
  8847. $itemStatistics->date = $receiptDetail ['date'];
  8848. $itemStatistics->insert ();
  8849. } else {
  8850. if (! empty ( $value )) {
  8851. $itemStatistics->price = $value + $iStatistics ['price'];
  8852. $itemStatistics->update ( array (
  8853. 'where' => 'sid=' . $iStatistics ['sid']
  8854. ) );
  8855. }
  8856. }
  8857. } elseif ($key == "otherSum") {
  8858. $iStatistics = $itemStatistics->getOne ( array (
  8859. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  8860. 'asArray' => true
  8861. ) );
  8862. if (empty ( $iStatistics )) {
  8863. $itemStatistics->cid = $receiptDetail ['cid'];
  8864. $itemStatistics->staff = $receiptDetail ['staff'];
  8865. $itemStatistics->price = $value;
  8866. $itemStatistics->itemCategory = $this->OTHER;
  8867. $itemStatistics->date = $receiptDetail ['date'];
  8868. $itemStatistics->insert ();
  8869. } else {
  8870. if (! empty ( $value )) {
  8871. $itemStatistics->price = $value + $iStatistics ['price'];
  8872. $itemStatistics->update ( array (
  8873. 'where' => 'sid=' . $iStatistics ['sid']
  8874. ) );
  8875. }
  8876. }
  8877. }
  8878. }
  8879. $receipt->pastDate = date ( "Y-m-d" );
  8880. // 微信企业号通知
  8881. $this->setWXMsg ( $rid, 1 );
  8882. }
  8883. //是否有流水
  8884. Doo::loadModel ( 'wasteBook' );
  8885. $wasteBook = new wasteBook ();
  8886. $accountType=3;
  8887. if ($receiptDetail['Rtype']==1){
  8888. $accountType=2;
  8889. }elseif($receiptDetail['Rtype']==2){
  8890. $accountType=4;
  8891. }
  8892. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  8893. if (empty($wbDetail)){
  8894. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  8895. $receipt->amount = $rsum;//$amount;
  8896. }
  8897. $receipt->update ( array (
  8898. 'where' => ' rid = ' . $rid
  8899. ) );
  8900. // 进入下一条审批费用新加需求
  8901. $vidList = array ();
  8902. $verifyDetail = $verify->find ( array (
  8903. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  8904. 'asArray' => true
  8905. ) );
  8906. foreach ( $verifyDetail as $key => $value ) {
  8907. array_push ( $vidList, $value ['vid'] );
  8908. }
  8909. $vid = implode ( ",", $vidList );
  8910. if (empty ( $verifyDetail ))
  8911. $vid = 0;
  8912. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  8913. $receipt = new receipt ();
  8914. $rd = $receipt->getOne ( array (
  8915. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  8916. 'asc' => 'rid',
  8917. 'asArray' => true
  8918. ) );
  8919. if (empty ( $rd )) {
  8920. return '/approvalExpenses/pendApproval';
  8921. }
  8922. if ($rd ['Rtype'] == 1) {
  8923. if ($rd ['isBK'] == 1) {
  8924. return '/receiptburEdi/' . $rd ['rid'];
  8925. } else {
  8926. return '/expensesEdi/' . $rd ['rid'];
  8927. }
  8928. } elseif ($rd ['Rtype'] == 2) {
  8929. return '/remitApproval/' . $rd ['rid'];
  8930. } else {
  8931. return '/receiptburEdi/' . $rd ['rid'];
  8932. }
  8933. // return "/approvalExpenses/pendApproval";
  8934. }
  8935. }
  8936. function expensesRetreats() {
  8937. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8938. if (! empty ( $rid )) {
  8939. // 操作记录
  8940. Doo::loadModel ( "receipt" );
  8941. $receipt = new receipt ();
  8942. Doo::loadModel ( "receiptLog" );
  8943. $receiptLog = new receiptLog ();
  8944. Doo::loadModel ( "verify" );
  8945. $verify = new verify ();
  8946. $receiptInfo = $receipt->getOne ( array (
  8947. 'where' => 'rid=' . $rid,
  8948. 'asArray' => true
  8949. ) );
  8950. $vr = $verify->getOne ( array (
  8951. 'where' => 'vid=' . $receiptInfo ['verify'],
  8952. 'asArray' => true
  8953. ) );
  8954. $jd = json_decode ( $vr ['staff'] );
  8955. $roleId = 0;
  8956. foreach ( $jd as $key => $value ) {
  8957. if ($value [1] == 'ROLE') {
  8958. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  8959. if ($pos !== false) {
  8960. $roleId = $value [0];
  8961. }
  8962. }
  8963. }
  8964. // 审批日志
  8965. // echo $roleId;die;
  8966. if (! empty ( $roleId )) {
  8967. Doo::loadModel ( "role" );
  8968. $role = new role ();
  8969. $roleInfo = $role->getOne ( array (
  8970. 'where' => 'rid=' . $roleId,
  8971. 'asArray' => true
  8972. ) );
  8973. $receiptLog->rolename = $roleInfo ['name'];
  8974. }
  8975. $receiptLog->username = $this->staff [0] ['username'];
  8976. $receiptLog->uid = $this->staff [0] ['sid'];
  8977. $receiptLog->date = date ( "Y-m-d" );
  8978. $receiptLog->opinion = '撤回';
  8979. $receiptLog->img = $this->staff [0] ['avatar'];
  8980. $receiptLog->status = 4;
  8981. $receiptLog->rid = $rid;
  8982. $receiptLog->insert ();
  8983. $receipt->status = 4;
  8984. $receipt->update ( array (
  8985. 'where' => 'rid=' . $rid
  8986. ) );
  8987. // 微信企业号通知
  8988. $this->setWXMsg ( $rid, 2 );
  8989. }
  8990. // echo "ddd";
  8991. return '/approvalExpenses/pendApproval';
  8992. }
  8993. function updateCheReceipt() {
  8994. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8995. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8996. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  8997. if (! empty ( $rid )) {
  8998. // 操作记录
  8999. Doo::loadModel ( "receipt" );
  9000. $receipt = new receipt ();
  9001. Doo::loadModel ( "receiptLog" );
  9002. $receiptLog = new receiptLog ();
  9003. Doo::loadModel ( "verify" );
  9004. $verify = new verify ();
  9005. $receiptInfo = $receipt->getOne ( array (
  9006. 'where' => 'rid=' . $rid . ' and status=2',
  9007. 'asArray' => true
  9008. ) );
  9009. if (empty ( $receiptInfo )) {
  9010. echo json_encode ( array (
  9011. 'status' => 2
  9012. ) );
  9013. die ();
  9014. }
  9015. $vr = $verify->getOne ( array (
  9016. 'where' => 'vid=' . $receiptInfo ['verify'],
  9017. 'asArray' => true
  9018. ) );
  9019. $jd = json_decode ( $vr ['staff'] );
  9020. $roleId = 0;
  9021. foreach ( $jd as $key => $value ) {
  9022. if ($value [1] == 'ROLE') {
  9023. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9024. if ($pos !== false) {
  9025. $roleId = $value [0];
  9026. }
  9027. }
  9028. }
  9029. // 审批日志
  9030. // echo $roleId;die;
  9031. if (! empty ( $roleId )) {
  9032. Doo::loadModel ( "role" );
  9033. $role = new role ();
  9034. $roleInfo = $role->getOne ( array (
  9035. 'where' => 'rid=' . $roleId,
  9036. 'asArray' => true
  9037. ) );
  9038. $receiptLog->rolename = $roleInfo ['name'];
  9039. }
  9040. $receiptLog->username = $this->staff [0] ['username'];
  9041. $receiptLog->uid = $this->staff [0] ['sid'];
  9042. $receiptLog->date = date ( "Y-m-d" );
  9043. $receiptLog->opinion = $opinion;
  9044. $receiptLog->img = $this->staff [0] ['avatar'];
  9045. $receiptLog->status = 4;
  9046. $receiptLog->rid = $rid;
  9047. $receiptLog->insert ();
  9048. $receipt->status = 4;
  9049. $receipt->update ( array (
  9050. 'where' => 'rid=' . $rid
  9051. ) );
  9052. // 微信企业号通知
  9053. $this->setWXMsg ( $rid, 2 );
  9054. echo json_encode ( array (
  9055. 'status' => 1
  9056. ) );
  9057. // Header("HTTP/1.1 303 See Other");
  9058. // Header("Location: /approvalExpenses/pendApproval");
  9059. die ();
  9060. }
  9061. echo json_encode ( array (
  9062. 'status' => 2
  9063. ) );
  9064. die ();
  9065. // echo "ddd";
  9066. // return '/saeaBorad';
  9067. }
  9068. function revisePrice() {
  9069. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9070. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9071. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9072. // echo $price;die;
  9073. if (! empty ( $rid )) {
  9074. Doo::loadModel ( "receipt" );
  9075. $receipt = new receipt ();
  9076. $receiptDetail = $receipt->getOne ( array (
  9077. 'where' => 'rid=' . $rid . ' and status=2 ',
  9078. 'asArray' => true
  9079. ) );
  9080. if (empty ( $receiptDetail ))
  9081. die ( 'illegal request' );
  9082. $reviseDetail = array ();
  9083. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9084. array_push ( $reviseDetail, array (
  9085. 'sid' => $this->staff [0] ['sid'],
  9086. 'name' => $this->staff [0] ['username'],
  9087. 'description' => $description,
  9088. 'price' => $price
  9089. ) );
  9090. $reviseDetailString = json_encode ( $reviseDetail );
  9091. $receipt->reviseDetail = $reviseDetailString;
  9092. $receipt->revisePrice = $price;
  9093. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9094. } else {
  9095. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9096. array_push ( $reviseDetail, array (
  9097. 'sid' => $this->staff [0] ['sid'],
  9098. 'name' => $this->staff [0] ['username'],
  9099. 'description' => $description,
  9100. 'price' => $price
  9101. ) );
  9102. $reviseDetailString = json_encode ( $reviseDetail );
  9103. $receipt->reviseDetail = $reviseDetailString;
  9104. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9105. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9106. }
  9107. $receipt->update ( array (
  9108. 'where' => 'rid=' . $rid
  9109. ) );
  9110. if ($receiptDetail ['Rtype'] == 1) {
  9111. if ($receiptDetail ['isBK'] == 1) {
  9112. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9113. }
  9114. } elseif ($receiptDetail ['Rtype'] == 2) {
  9115. } else {
  9116. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9117. }
  9118. }
  9119. die ( 'illegal request' );
  9120. }
  9121. function personalCollect() {
  9122. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9123. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9124. $this->showCache ( $path );
  9125. Doo::loadModel ( "receiptDetail" );
  9126. Doo::loadModel ( "itemStatistics" );
  9127. Doo::loadModel ( 'statistics' );
  9128. $statistics = new statistics ();
  9129. $itemStatistics = new itemStatistics ();
  9130. $receiptDetail = new receiptDetail ();
  9131. $receiptCollectList = $receiptDetail->find ( array (
  9132. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9133. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9134. 'groupby' => 'itemCategory,Month(date)',
  9135. 'asArray' => true
  9136. ) );
  9137. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9138. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9139. 'asArray' => true
  9140. ) );
  9141. // create collect html
  9142. $collectArray = array (
  9143. '日常相关费用' => array (),
  9144. '差旅相关费用' => array (),
  9145. '培训班费用' => array (),
  9146. '其他' => array ()
  9147. );
  9148. $adjustment = array ();
  9149. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9150. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9151. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9152. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9153. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9154. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9155. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9156. array_push ( $collectArray ['其他'], $collectHtml );
  9157. $data ['collectArray'] = $collectArray;
  9158. // statistics html
  9159. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9160. if (empty ( $stList ))
  9161. $stList = array (
  9162. 'rePrice' => 0,
  9163. 'agPrice' => 0
  9164. );
  9165. $data ['stList'] = array (
  9166. 'rePrice' => $stList ['rePrice'],
  9167. 'agPrice' => $stList ['agPrice'],
  9168. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9169. );
  9170. // Adjustment price html
  9171. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9172. array_push ( $adjustment, $collectHtml );
  9173. $data ['adjustment'] = $adjustment;
  9174. // total price html
  9175. $collectHtml = "";
  9176. $total = 0;
  9177. for($i = 1; $i <= 12; $i ++) {
  9178. $sumPrice = 0;
  9179. foreach ( $receiptCollectList as $key => $value ) {
  9180. if ($value ['month'] == $i) {
  9181. $sumPrice += $value ['price'];
  9182. }
  9183. }
  9184. if ($sumPrice == 0)
  9185. $collectHtml .= '<td class="taR">-</td>';
  9186. else
  9187. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9188. $total += $sumPrice;
  9189. }
  9190. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9191. $data ['totalPrice'] = $collectHtml;
  9192. $dateHtml = "";
  9193. $now = date ( "Y" );
  9194. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9195. if ($YEARD <= $now) {
  9196. $dateHtml .= '<option ';
  9197. if ($year == $YEARD) {
  9198. $dateHtml .= 'selected ';
  9199. }
  9200. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9201. }
  9202. }
  9203. $data ['dateHtml'] = $dateHtml;
  9204. $data ['year'] = $year;
  9205. $data ['totalYear'] = $total;
  9206. $data ['memu'] = "receipt";
  9207. $data ['staff'] = $this->staff;
  9208. $data ['receiptMemu'] = 'personalCollect';
  9209. $data ['verifyId'] = $this->verifyId;
  9210. $data ['executeId'] = $this->executeId;
  9211. // year staff status 2,4
  9212. if ($year < date ( "Y" )) {
  9213. Doo::loadModel ( 'receipt' );
  9214. $receipt = new receipt ();
  9215. $receiptList = $receipt->find ( array (
  9216. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9217. 'asArray' => true
  9218. ) );
  9219. if (empty ( $receiptList )) {
  9220. ob_start ();
  9221. $this->render ( "/admin/saea_slist_collect", $data );
  9222. $this->cacheFile ( $path );
  9223. die ();
  9224. }
  9225. }
  9226. $this->render ( "/admin/saea_slist_collect", $data );
  9227. }
  9228. function personalCollectDetail() {
  9229. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9230. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9231. $this->showCache ( $path );
  9232. Doo::loadModel ( "receiptDetail" );
  9233. Doo::loadModel ( "itemStatistics" );
  9234. Doo::loadModel ( 'statistics' );
  9235. Doo::loadModel ( 'accountItem' );
  9236. $accountItem = new accountItem ();
  9237. $statistics = new statistics ();
  9238. $itemStatistics = new itemStatistics ();
  9239. $receiptDetail = new receiptDetail ();
  9240. $receiptCollectList = $receiptDetail->find ( array (
  9241. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9242. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9243. 'groupby' => 'item,Month(date)',
  9244. 'asArray' => true
  9245. ) );
  9246. $accountList = $accountItem->find ( array (
  9247. 'asArray' => true
  9248. ) );
  9249. // create CollectDetail HTML
  9250. $collectHtml = array ();
  9251. foreach ( $accountList as $key => $value ) {
  9252. $html = "";
  9253. $asum = 0;
  9254. for($i = 1; $i <= 12; $i ++) {
  9255. $falg = true;
  9256. foreach ( $receiptCollectList as $v ) {
  9257. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9258. $asum += $v ['price'];
  9259. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9260. $falg = false;
  9261. break;
  9262. }
  9263. }
  9264. if ($falg)
  9265. $html .= '<td class="taR">-</td>';
  9266. }
  9267. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9268. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9269. }
  9270. $data ['collectHtml'] = $collectHtml;
  9271. // create Adjustment price html
  9272. $receiptCollectList = $receiptDetail->find ( array (
  9273. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9274. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9275. 'groupby' => 'itemCategory,Month(date)',
  9276. 'asArray' => true
  9277. ) );
  9278. $adjustment = array ();
  9279. $collectArray = array (
  9280. '日常相关费用' => array (),
  9281. '差旅相关费用' => array (),
  9282. '培训班费用' => array (),
  9283. '其他' => array ()
  9284. );
  9285. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9286. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9287. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9288. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9289. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9290. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9291. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9292. array_push ( $collectArray ['其他'], $collectHtml );
  9293. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9294. array_push ( $adjustment, $collectHtml );
  9295. // total price html
  9296. $collectHtml = "";
  9297. $total = 0;
  9298. for($i = 1; $i <= 12; $i ++) {
  9299. $sumPrice = 0;
  9300. foreach ( $receiptCollectList as $key => $value ) {
  9301. if ($value ['month'] == $i) {
  9302. $sumPrice += $value ['price'];
  9303. }
  9304. }
  9305. if ($sumPrice == 0)
  9306. $collectHtml .= '<td class="taR">-</td>';
  9307. else
  9308. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9309. $total += $sumPrice;
  9310. }
  9311. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9312. // statistics html
  9313. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9314. if (empty ( $stList ))
  9315. $stList = array (
  9316. 'rePrice' => 0,
  9317. 'agPrice' => 0
  9318. );
  9319. $data ['stList'] = array (
  9320. 'rePrice' => $stList ['rePrice'],
  9321. 'agPrice' => $stList ['agPrice'],
  9322. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9323. );
  9324. $data ['collectArray'] = $collectArray;
  9325. $data ['adjustment'] = $adjustment;
  9326. $data ['totalPrice'] = $collectHtml;
  9327. $data ['totalYear'] = $total;
  9328. $data ['year'] = $year;
  9329. $dateHtml = "";
  9330. $now = date ( "Y" );
  9331. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9332. if ($YEARD <= $now) {
  9333. $dateHtml .= '<option ';
  9334. if ($year == $YEARD) {
  9335. $dateHtml .= 'selected ';
  9336. }
  9337. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9338. }
  9339. }
  9340. $data ['dateHtml'] = $dateHtml;
  9341. $data ['memu'] = "receipt";
  9342. $data ['staff'] = $this->staff;
  9343. $data ['receiptMemu'] = 'personalCollect';
  9344. $data ['verifyId'] = $this->verifyId;
  9345. $data ['executeId'] = $this->executeId;
  9346. // year staff status 2,4
  9347. if ($year < date ( "Y" )) {
  9348. Doo::loadModel ( 'receipt' );
  9349. $receipt = new receipt ();
  9350. $receiptList = $receipt->find ( array (
  9351. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9352. 'asArray' => true
  9353. ) );
  9354. if (empty ( $receiptList )) {
  9355. ob_start ();
  9356. $this->render ( "/admin/saeaCollectArticles", $data );
  9357. $this->cacheFile ( $path );
  9358. die ();
  9359. }
  9360. }
  9361. $this->render ( "/admin/saeaCollectArticles", $data );
  9362. }
  9363. function companyCategoryCollect() {
  9364. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9365. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9366. $this->showCache ( $path );
  9367. Doo::loadModel ( 'L_category' );
  9368. Doo::loadModel ( 'itemStatistics' );
  9369. Doo::loadModel ( 'statistics' );
  9370. $statistics = new statistics ();
  9371. $Lcategory = new L_category ();
  9372. $itemStatistics = new itemStatistics ();
  9373. Doo::loadModel ( "receiptAuthorityManage" );
  9374. $receiptAuthorityManage = new receiptAuthorityManage ();
  9375. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9376. $cidList = array ();
  9377. foreach ( $imcStaff as $key => $value ) {
  9378. array_push ( $cidList, $value ['cid'] );
  9379. }
  9380. $cidString = implode ( ',', $cidList );
  9381. $LcategoryList = $Lcategory->find ( array (
  9382. 'where' => ' cid in (' . $cidString . ')',
  9383. 'asArray' => true
  9384. ) ); // 'staff='.$this->staff[0]['sid']." and
  9385. $itemStatisticsList = $itemStatistics->find ( array (
  9386. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9387. 'where' => " Year(date)=" . $year,
  9388. 'groupby' => 'cid,Month(date)',
  9389. 'asArray' => true
  9390. ) );
  9391. // ceatre companyCollectHtml
  9392. foreach ( $LcategoryList as $value ) {
  9393. $html = "";
  9394. $asum = 0;
  9395. for($i = 1; $i <= 12; $i ++) {
  9396. $falg = true;
  9397. foreach ( $itemStatisticsList as $v ) {
  9398. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9399. $asum += $v ['price'];
  9400. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9401. $falg = false;
  9402. break;
  9403. }
  9404. }
  9405. if ($falg)
  9406. $html .= '<td class="taR">-</td>';
  9407. }
  9408. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9409. $collectHtml [$value ['title']] = array (
  9410. 'html' => $html,
  9411. 'cid' => $value ['cid']
  9412. );
  9413. }
  9414. $data ['companyHtml'] = $collectHtml;
  9415. // total price html
  9416. $collectHtml = "";
  9417. $total = 0;
  9418. for($i = 1; $i <= 12; $i ++) {
  9419. $sumPrice = 0;
  9420. foreach ( $itemStatisticsList as $key => $value ) {
  9421. if ($value ['month'] == $i) {
  9422. $sumPrice += $value ['price'];
  9423. }
  9424. }
  9425. if ($sumPrice == 0)
  9426. $collectHtml .= '<td class="taR">-</td>';
  9427. else
  9428. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9429. $total += $sumPrice;
  9430. }
  9431. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9432. $data ['companyTotalHtml'] = $collectHtml;
  9433. $data ['total'] = $total;
  9434. // statistics html
  9435. // echo $cidString;
  9436. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9437. if (empty ( $stList ))
  9438. $stList = array (
  9439. 'rePrice' => 0,
  9440. 'agPrice' => 0
  9441. );
  9442. $data ['stList'] = array (
  9443. 'rePrice' => $stList ['rePrice'],
  9444. 'agPrice' => $stList ['agPrice'],
  9445. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9446. );
  9447. $data ['year'] = $year;
  9448. $data ['memu'] = "receipt";
  9449. $data ['staff'] = $this->staff;
  9450. $data ['receiptMemu'] = 'companyCategoryCollect';
  9451. $data ['verifyId'] = $this->verifyId;
  9452. $data ['executeId'] = $this->executeId;
  9453. $dateHtml = "";
  9454. $now = date ( "Y" );
  9455. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9456. if ($YEARD <= $now) {
  9457. $dateHtml .= '<option ';
  9458. if ($year == $YEARD) {
  9459. $dateHtml .= 'selected ';
  9460. }
  9461. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9462. }
  9463. }
  9464. $data ['dateHtml'] = $dateHtml;
  9465. // year staff status 2,4
  9466. if ($year < date ( "Y" )) {
  9467. Doo::loadModel ( 'receipt' );
  9468. $receipt = new receipt ();
  9469. $receiptList = $receipt->find ( array (
  9470. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9471. 'asArray' => true
  9472. ) );
  9473. if (empty ( $receiptList )) {
  9474. ob_start ();
  9475. $this->render ( "/admin/saeaCompanyCollect", $data );
  9476. $this->cacheFile ( $path );
  9477. die ();
  9478. }
  9479. }
  9480. $this->render ( "/admin/saeaCompanyCollect", $data );
  9481. }
  9482. function categoryCollectDetail() {
  9483. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9484. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9485. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9486. $this->showCache ( $path );
  9487. Doo::loadModel ( 'statistics' );
  9488. $statistics = new statistics ();
  9489. Doo::loadModel ( "receiptDetail" );
  9490. $receiptDetail = new receiptDetail ();
  9491. Doo::loadModel ( 'L_category' );
  9492. $Lcategory = new L_category ();
  9493. Doo::loadModel ( 'accountItem' );
  9494. $accountItem = new accountItem ();
  9495. Doo::loadModel ( "receiptAuthorityManage" );
  9496. $receiptAuthorityManage = new receiptAuthorityManage ();
  9497. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9498. $cidList = array ();
  9499. foreach ( $imcStaff as $key => $value ) {
  9500. array_push ( $cidList, $value ['cid'] );
  9501. }
  9502. $cidString = implode ( ',', $cidList );
  9503. $LcategoryList = $Lcategory->find ( array (
  9504. 'where' => 'cid in (' . $cidString . ')',
  9505. 'asArray' => true
  9506. ) );
  9507. if ($cid == 0) {
  9508. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9509. if ($cid == 0)
  9510. $cid = $LcategoryList [0] ['cid'];
  9511. }
  9512. $data ['LcategoryList'] = $LcategoryList;
  9513. $receiptCollectList = $receiptDetail->find ( array (
  9514. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9515. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9516. 'groupby' => 'item,Month(pastDate)',
  9517. 'asArray' => true
  9518. ) );
  9519. $accountList = $accountItem->find ( array (
  9520. 'asArray' => true
  9521. ) );
  9522. // create CollectDetail HTML
  9523. $collectHtml = array ();
  9524. foreach ( $accountList as $key => $value ) {
  9525. $html = "";
  9526. $asum = 0;
  9527. for($i = 1; $i <= 12; $i ++) {
  9528. $falg = true;
  9529. foreach ( $receiptCollectList as $v ) {
  9530. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9531. $asum += $v ['price'];
  9532. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9533. $falg = false;
  9534. break;
  9535. }
  9536. }
  9537. if ($falg)
  9538. $html .= '<td class="taR">-</td>';
  9539. }
  9540. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9541. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9542. }
  9543. $data ['collectHtml'] = $collectHtml;
  9544. // create Adjustment price html
  9545. $receiptCollectList = $receiptDetail->find ( array (
  9546. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9547. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9548. 'groupby' => 'itemCategory,Month(pastDate)',
  9549. 'asArray' => true
  9550. ) );
  9551. $adjustment = array ();
  9552. $collectArray = array (
  9553. '日常相关费用' => array (),
  9554. '差旅相关费用' => array (),
  9555. '培训班费用' => array (),
  9556. '内部培训费用'=>array(),
  9557. '其他' => array ()
  9558. );
  9559. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9560. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9561. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9562. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9563. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9564. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9565. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9566. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9567. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9568. array_push ( $collectArray ['其他'], $collectHtml );
  9569. $data ['collectArray'] = $collectArray;
  9570. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9571. array_push ( $adjustment, $collectHtml );
  9572. $data ['adjustment'] = $adjustment;
  9573. // total price html
  9574. $collectHtml = "";
  9575. $total = 0;
  9576. for($i = 1; $i <= 12; $i ++) {
  9577. $sumPrice = 0;
  9578. foreach ( $receiptCollectList as $key => $value ) {
  9579. if ($value ['month'] == $i) {
  9580. $sumPrice += $value ['price'];
  9581. }
  9582. }
  9583. if ($sumPrice == 0)
  9584. $collectHtml .= '<td class="taR">-</td>';
  9585. else
  9586. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9587. $total += $sumPrice;
  9588. }
  9589. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9590. // statistics html
  9591. $stList = $statistics->statisticsByCid ( $year, $cid );
  9592. if (empty ( $stList ))
  9593. $stList = array (
  9594. 'rePrice' => 0,
  9595. 'agPrice' => 0
  9596. );
  9597. $data ['stList'] = array (
  9598. 'rePrice' => $stList ['rePrice'],
  9599. 'agPrice' => $stList ['agPrice'],
  9600. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9601. );
  9602. $data ['totalYear'] = $total;
  9603. $data ['year'] = $year;
  9604. $data ['cid'] = $cid;
  9605. $data ['memu'] = "receipt";
  9606. $data ['staff'] = $this->staff;
  9607. $data ['receiptMemu'] = 'companyCategoryCollect';
  9608. $data ['verifyId'] = $this->verifyId;
  9609. $data ['executeId'] = $this->executeId;
  9610. // year staff status 2,4
  9611. if ($year < date ( "Y" )) {
  9612. Doo::loadModel ( 'receipt' );
  9613. $receipt = new receipt ();
  9614. $receiptList = $receipt->find ( array (
  9615. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  9616. 'asArray' => true
  9617. ) );
  9618. if (empty ( $receiptList )) {
  9619. ob_start ();
  9620. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9621. $this->cacheFile ( $path );
  9622. die ();
  9623. }
  9624. }
  9625. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  9626. }
  9627. function staffCollect() {
  9628. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9629. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  9630. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  9631. // $this->showCache($path);
  9632. Doo::loadModel ( 'statistics' );
  9633. $statistics = new statistics ();
  9634. Doo::loadModel ( "receiptDetail" );
  9635. $receiptDetail = new receiptDetail ();
  9636. Doo::loadModel ( 'L_category' );
  9637. $Lcategory = new L_category ();
  9638. Doo::loadModel ( 'accountItem' );
  9639. $accountItem = new accountItem ();
  9640. Doo::loadModel ( 'staff' );
  9641. $staff = new staff ();
  9642. Doo::loadModel ( 'itemStatistics' );
  9643. $itemStatistics = new itemStatistics ();
  9644. Doo::loadModel ( "receiptAuthorityManage" );
  9645. $receiptAuthorityManage = new receiptAuthorityManage ();
  9646. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9647. $cidList = array ();
  9648. foreach ( $imcStaff as $key => $value ) {
  9649. array_push ( $cidList, $value ['cid'] );
  9650. }
  9651. $cidString = implode ( ',', $cidList );
  9652. $naturecon='';
  9653. if ($nature=='ONJOB'){
  9654. $naturecon=' and (nature!=4 )';
  9655. }elseif($nature=='LEAVEJOB'){
  9656. $naturecon=' and (nature=4 )';
  9657. }else{
  9658. die ( 'illegal request--nature' );
  9659. }
  9660. // statistics html
  9661. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9662. if (empty ( $stList ))
  9663. $stList = array (
  9664. 'rePrice' => 0,
  9665. 'agPrice' => 0
  9666. );
  9667. $data ['stList'] = array (
  9668. 'rePrice' => $stList ['rePrice'],
  9669. 'agPrice' => $stList ['agPrice'],
  9670. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9671. );
  9672. // ---
  9673. $staffList = $staff->find ( array (
  9674. 'where' => 'username !="admin" '.$naturecon,
  9675. 'asArray' => true
  9676. ) );
  9677. $LcategoryList = $Lcategory->find ( array (
  9678. 'asArray' => true
  9679. ) ); // 'staff='.$this->staff[0]['sid']." and
  9680. $itemStatisticsList = $itemStatistics->find ( array (
  9681. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9682. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  9683. 'groupby' => 'staff,Month(date)',
  9684. 'asArray' => true
  9685. ) );
  9686. $categoryList = $staff->find ( array (
  9687. 'select' => 'COUNT(*) as count,cid,category',
  9688. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  9689. 'groupby' => 'cid',
  9690. 'asArray' => true
  9691. ) );
  9692. // print_r($itemStatisticsList);die;
  9693. // ceatre companyCollectHtml
  9694. foreach ( $categoryList as $vlu ) {
  9695. $count = $vlu ['count'] + 1;
  9696. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  9697. $m1 = 0;
  9698. $m2 = 0;
  9699. $m3 = 0;
  9700. $m4 = 0;
  9701. $m5 = 0;
  9702. $m6 = 0;
  9703. $m7 = 0;
  9704. $m8 = 0;
  9705. $m9 = 0;
  9706. $m10 = 0;
  9707. $m11 = 0;
  9708. $m12 = 0;
  9709. $m13 = 0;
  9710. foreach ( $staffList as $value ) {
  9711. if ($vlu ['cid'] == $value ['cid']) {
  9712. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  9713. $asum = 0;
  9714. for($i = 1; $i <= 12; $i ++) {
  9715. $falg = true;
  9716. foreach ( $itemStatisticsList as $v ) {
  9717. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  9718. if ($v ['month'] == 1)
  9719. $m1 += $v ['price'];
  9720. if ($v ['month'] == 2)
  9721. $m2 += $v ['price'];
  9722. if ($v ['month'] == 3)
  9723. $m3 += $v ['price'];
  9724. if ($v ['month'] == 4)
  9725. $m4 += $v ['price'];
  9726. if ($v ['month'] == 5)
  9727. $m5 += $v ['price'];
  9728. if ($v ['month'] == 6)
  9729. $m6 += $v ['price'];
  9730. if ($v ['month'] == 7)
  9731. $m7 += $v ['price'];
  9732. if ($v ['month'] == 8)
  9733. $m8 += $v ['price'];
  9734. if ($v ['month'] == 9)
  9735. $m9 += $v ['price'];
  9736. if ($v ['month'] == 10)
  9737. $m10 += $v ['price'];
  9738. if ($v ['month'] == 11)
  9739. $m11 += $v ['price'];
  9740. if ($v ['month'] == 12)
  9741. $m12 += $v ['price'];
  9742. $asum += $v ['price'];
  9743. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9744. $falg = false;
  9745. break;
  9746. }
  9747. }
  9748. if ($falg)
  9749. $html .= '<td class="taR">-</td>';
  9750. }
  9751. $m13 += $asum;
  9752. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9753. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  9754. 'html' => $html,
  9755. 'sid' => $value ['sid']
  9756. );
  9757. $html = "";
  9758. }
  9759. }
  9760. $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>
  9761. <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>
  9762. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  9763. $collectHtml [$vlu ['cid']] = array (
  9764. 'html' => $hl,
  9765. 'sid' => ''
  9766. );
  9767. }
  9768. $data ['companyHtml'] = $collectHtml;
  9769. // total price html
  9770. $collectHtml = "";
  9771. $total = 0;
  9772. for($i = 1; $i <= 12; $i ++) {
  9773. $sumPrice = 0;
  9774. foreach ( $itemStatisticsList as $key => $value ) {
  9775. if ($value ['month'] == $i) {
  9776. $sumPrice += $value ['price'];
  9777. }
  9778. }
  9779. if ($sumPrice == 0)
  9780. $collectHtml .= '<td class="taR">-</td>';
  9781. else
  9782. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9783. $total += $sumPrice;
  9784. }
  9785. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9786. $data ['companyTotalHtml'] = $collectHtml;
  9787. $data ['total'] = $total;
  9788. $data ['nature'] =$nature;
  9789. $data ['year'] = $year;
  9790. $data ['memu'] = "receipt";
  9791. $data ['staff'] = $this->staff;
  9792. $data ['receiptMemu'] = 'companyCategoryCollect';
  9793. $data ['verifyId'] = $this->verifyId;
  9794. $data ['executeId'] = $this->executeId;
  9795. if ($year <= date ( "Y" )) {
  9796. Doo::loadModel ( 'receipt' );
  9797. $receipt = new receipt ();
  9798. $receiptList = $receipt->find ( array (
  9799. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  9800. 'asArray' => true
  9801. ) );
  9802. if (empty ( $receiptList )) { // generated files
  9803. ob_start ();
  9804. $this->render ( "/admin/saeaStaffCollectB", $data );
  9805. $this->cacheFile ( $path );
  9806. die ();
  9807. }
  9808. }
  9809. $this->render ( "/admin/saeaStaffCollectB", $data );
  9810. }
  9811. function staffCollectBak() {
  9812. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9813. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  9814. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  9815. $this->showCache ( $path );
  9816. Doo::loadModel ( 'statistics' );
  9817. $statistics = new statistics ();
  9818. Doo::loadModel ( "receiptDetail" );
  9819. $receiptDetail = new receiptDetail ();
  9820. Doo::loadModel ( 'L_category' );
  9821. $Lcategory = new L_category ();
  9822. Doo::loadModel ( 'accountItem' );
  9823. $accountItem = new accountItem ();
  9824. Doo::loadModel ( 'staff' );
  9825. $staff = new staff ();
  9826. Doo::loadModel ( 'itemStatistics' );
  9827. $itemStatistics = new itemStatistics ();
  9828. $itemStatisticsList = $itemStatistics->find ( array (
  9829. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9830. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9831. 'groupby' => 'staff,itemCategory,Month(date)',
  9832. 'asArray' => true
  9833. ) );
  9834. $itemCategoryList = $itemStatistics->find ( array (
  9835. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9836. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  9837. 'groupby' => 'cid,itemCategory,Month(date)',
  9838. 'asArray' => true
  9839. ) );
  9840. $LcategoryList = $Lcategory->find ( array (
  9841. 'asArray' => true
  9842. ) );
  9843. $staffList = $staff->find ( array (
  9844. 'asArray' => true
  9845. ) );
  9846. $htmlArray = array ();
  9847. foreach ( $LcategoryList as $value ) {
  9848. $htmlArray [$value ['title']] = array ();
  9849. foreach ( $staffList as $v ) {
  9850. if ($value ['cid'] == $v ['cid']) {
  9851. $html = "";
  9852. $falg = true;
  9853. $staffSumPrice = 0;
  9854. foreach ( $itemStatisticsList as $a ) {
  9855. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  9856. if (empty ( $a ['price'] )) {
  9857. $html .= '<td class="taR">-</td>';
  9858. $falg = false;
  9859. break;
  9860. } else {
  9861. $staffSumPrice += $a ['price'];
  9862. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9863. $falg = false;
  9864. break;
  9865. }
  9866. }
  9867. }
  9868. if ($falg) {
  9869. $html .= '<td class="taR">-</td>';
  9870. $falg = true;
  9871. }
  9872. $falg = true;
  9873. foreach ( $itemStatisticsList as $a ) {
  9874. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  9875. if (empty ( $a ['price'] )) {
  9876. $html .= '<td class="taR">-</td>';
  9877. $falg = false;
  9878. break;
  9879. } else {
  9880. $staffSumPrice += $a ['price'];
  9881. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9882. $falg = false;
  9883. break;
  9884. }
  9885. }
  9886. }
  9887. if ($falg) {
  9888. $html .= '<td class="taR">-</td>';
  9889. $falg = true;
  9890. }
  9891. $falg = true;
  9892. foreach ( $itemStatisticsList as $a ) {
  9893. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  9894. if (empty ( $a ['price'] )) {
  9895. $html .= '<td class="taR">-</td>';
  9896. $falg = false;
  9897. break;
  9898. } else {
  9899. $staffSumPrice += $a ['price'];
  9900. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9901. $falg = false;
  9902. break;
  9903. }
  9904. }
  9905. }
  9906. if ($falg) {
  9907. $html .= '<td class="taR">-</td>';
  9908. $falg = true;
  9909. }
  9910. $falg = true;
  9911. foreach ( $itemStatisticsList as $a ) {
  9912. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  9913. if (! empty ( $a ['price'] )) {
  9914. $staffSumPrice += $a ['price'];
  9915. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9916. $falg = false;
  9917. break;
  9918. } else {
  9919. $html .= '<td class="taR">-</td>';
  9920. $falg = false;
  9921. break;
  9922. }
  9923. }
  9924. }
  9925. if ($falg) {
  9926. $html .= '<td class="taR">-</td>';
  9927. $falg = true;
  9928. }
  9929. $falg = true;
  9930. foreach ( $itemStatisticsList as $a ) {
  9931. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  9932. if (! empty ( $a ['price'] )) {
  9933. $staffSumPrice += $a ['price'];
  9934. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  9935. $falg = false;
  9936. break;
  9937. } else {
  9938. $html .= '<td class="taR">-</td>';
  9939. $falg = false;
  9940. break;
  9941. }
  9942. }
  9943. }
  9944. if ($falg) {
  9945. $html .= '<td class="taR">-</td>';
  9946. $falg = true;
  9947. }
  9948. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  9949. $htmlArray [$value ['title']] [$v ['username']] = $html;
  9950. }
  9951. }
  9952. /* -- --- */
  9953. // 合计费用
  9954. $cateHtml = "";
  9955. $catePrice = 0;
  9956. $cateFalg = true;
  9957. foreach ( $itemCategoryList as $l ) {
  9958. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  9959. if (empty ( $l ['price'] )) {
  9960. $cateHtml .= '<td class="colGreen taR">-</td>';
  9961. $cateFalg = false;
  9962. break;
  9963. } else {
  9964. $catePrice += $l ['price'];
  9965. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9966. $cateFalg = false;
  9967. break;
  9968. }
  9969. }
  9970. }
  9971. if ($cateFalg) {
  9972. $cateHtml .= '<td class="colGreen taR">-</td>';
  9973. $cateFalg = true;
  9974. }
  9975. $cateFalg = true;
  9976. foreach ( $itemCategoryList as $l ) {
  9977. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  9978. if (empty ( $l ['price'] )) {
  9979. $cateHtml .= '<td class="colGreen taR">-</td>';
  9980. $cateFalg = false;
  9981. break;
  9982. } else {
  9983. $catePrice += $l ['price'];
  9984. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  9985. $cateFalg = false;
  9986. break;
  9987. }
  9988. }
  9989. }
  9990. if ($cateFalg) {
  9991. $cateHtml .= '<td class="colGreen taR">-</td>';
  9992. $cateFalg = true;
  9993. }
  9994. $cateFalg = true;
  9995. foreach ( $itemCategoryList as $l ) {
  9996. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  9997. if (empty ( $l ['price'] )) {
  9998. $cateHtml .= '<td class="colGreen taR">-</td>';
  9999. $cateFalg = false;
  10000. break;
  10001. } else {
  10002. $catePrice += $l ['price'];
  10003. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10004. $cateFalg = false;
  10005. break;
  10006. }
  10007. }
  10008. }
  10009. if ($cateFalg) {
  10010. $cateHtml .= '<td class="colGreen taR">-</td>';
  10011. $cateFalg = true;
  10012. }
  10013. $cateFalg = true;
  10014. foreach ( $itemCategoryList as $l ) {
  10015. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10016. if (empty ( $l ['price'] )) {
  10017. $cateHtml .= '<td class="colGreen taR">-</td>';
  10018. $cateFalg = false;
  10019. break;
  10020. } else {
  10021. $catePrice += $l ['price'];
  10022. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10023. $cateFalg = false;
  10024. break;
  10025. }
  10026. }
  10027. }
  10028. if ($cateFalg) {
  10029. $cateHtml .= '<td class="colGreen taR">-</td>';
  10030. $cateFalg = true;
  10031. }
  10032. $cateFalg = true;
  10033. foreach ( $itemCategoryList as $l ) {
  10034. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10035. if (empty ( $l ['price'] )) {
  10036. $cateHtml .= '<td class="colGreen taR">-</td>';
  10037. $cateFalg = false;
  10038. break;
  10039. } else {
  10040. $catePrice += $l ['price'];
  10041. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10042. $cateFalg = false;
  10043. break;
  10044. }
  10045. }
  10046. }
  10047. if ($cateFalg) {
  10048. $cateHtml .= '<td class="colGreen taR">-</td>';
  10049. $cateFalg = true;
  10050. }
  10051. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10052. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10053. /* -- --- */
  10054. }
  10055. // print_r($htmlArray);die;
  10056. $data ['htmlArray'] = $htmlArray;
  10057. // statistics html
  10058. $stList = $statistics->getOne ( array (
  10059. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10060. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10061. 'groupby' => 'Month(date)',
  10062. 'asArray' => true
  10063. ) );
  10064. if (empty ( $stList ))
  10065. $stList = array (
  10066. 'rePrice' => 0,
  10067. 'agPrice' => 0
  10068. );
  10069. $data ['stList'] = array (
  10070. 'rePrice' => $stList ['rePrice'],
  10071. 'agPrice' => $stList ['agPrice'],
  10072. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10073. );
  10074. $monthHtml = "";
  10075. for($i = 1; $i <= 12; $i ++) {
  10076. if ($i == $month)
  10077. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10078. else
  10079. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10080. }
  10081. $data ['monthHtml'] = $monthHtml;
  10082. $data ['year'] = $year;
  10083. $data ['month'] = $month;
  10084. $data ['memu'] = "receipt";
  10085. $data ['staff'] = $this->staff;
  10086. $data ['receiptMemu'] = 'companyCategoryCollect';
  10087. $data ['verifyId'] = $this->verifyId;
  10088. $data ['executeId'] = $this->executeId;
  10089. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10090. Doo::loadModel ( 'receipt' );
  10091. $receipt = new receipt ();
  10092. $receiptList = $receipt->find ( array (
  10093. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10094. 'asArray' => true
  10095. ) );
  10096. if (empty ( $receiptList )) { // generated files
  10097. ob_start ();
  10098. $this->render ( "/admin/saeaStaffCollect", $data );
  10099. $this->cacheFile ( $path );
  10100. die ();
  10101. }
  10102. }
  10103. $this->render ( "/admin/saeaStaffCollect", $data );
  10104. }
  10105. /**
  10106. * 日常收支
  10107. */
  10108. function payments() {
  10109. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10110. Doo::loadModel ( "execute" );
  10111. $execute = new execute ();
  10112. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10113. die ( 'illegal request' );
  10114. }
  10115. Doo::loadModel ( "accountBook" );
  10116. $accountBook = new accountBook ();
  10117. Doo::loadModel ( "accountBookStatistics" );
  10118. $accountBookStatistics = new accountBookStatistics ();
  10119. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10120. $list = $accountBook->getAccountBookByLimit ( 10 );
  10121. $data ['date'] = date ( "Y-m-d" );
  10122. $data ['statisticsList'] = $statisticsList;
  10123. $data ['list'] = $list;
  10124. $data ['memu'] = "receipt";
  10125. $data ['staff'] = $this->staff;
  10126. $data ['receiptMemu'] = 'payments';
  10127. $data ['verifyId'] = $this->verifyId;
  10128. $data ['executeId'] = $this->executeId;
  10129. $this->render ( "/expenses/payments", $data );
  10130. }
  10131. function paymentsIncomeDo() {
  10132. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10133. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10134. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10135. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10136. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10137. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10138. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10139. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10140. Doo::loadClass ( 'XDeode' );
  10141. $XDeode = new XDeode ( 5 );
  10142. Doo::loadModel ( "accountBook" );
  10143. Doo::loadModel ( "accountBookStatistics" );
  10144. Doo::loadModel ( 'wasteBook' );
  10145. // 记录流水时银行的转换
  10146. $accountBank = '';
  10147. if ($receivedBank == '纵横广发') {
  10148. $accountBank = 'CGBDeposit';
  10149. } elseif ($receivedBank == '纵横工行') {
  10150. $accountBank = 'ICBCDeposit';
  10151. } elseif ($receivedBank == '华润银行') {
  10152. $accountBank = 'HUADeposit';
  10153. } elseif ($receivedBank == '个人广发') {
  10154. $accountBank = 'PersonalDeposit';
  10155. }
  10156. if (empty ( $accountBank ))
  10157. die ( 'illegal request' );
  10158. // 收入为理财时特殊处理
  10159. if ($accountType == 7 || $accountType == 9) {
  10160. if ($receivedBank == '个人广发') {
  10161. die ( '个人广发 illegal request' );
  10162. }
  10163. // 添加一条收入
  10164. $accountBook = new accountBook ();
  10165. $accountBook->accountType = 10;
  10166. $accountBook->accountMsg = $accountMsg;
  10167. $accountBook->receivedPrice = $receivedPrice;
  10168. $accountBook->receivedMsg = $receivedMsg;
  10169. $accountBook->receivedBank = $receivedBank;
  10170. $accountBook->receivedDate = $receivedDate;
  10171. $accountBook->remarks = $remarks;
  10172. $accountBook->expensesType = 1;
  10173. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10174. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10175. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10176. $inComeId = $accountBook->insert ();
  10177. // 收支汇总-添加一条收入日常汇总
  10178. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10179. $accountBookStatistics = new accountBookStatistics ();
  10180. $item = array (
  10181. 'date' => date ( "Y-m-d" ),
  10182. 'accountType' => $abDetail ['accountType'],
  10183. 'accountMsg' => $abDetail ['accountMsg'],
  10184. 'aid' => $abDetail ['aid'],
  10185. 'inComePrice' => $abDetail ['receivedPrice'],
  10186. 'expensesType' => $abDetail ['expensesType']
  10187. );
  10188. $accountBookStatistics->setAccountBookStatistics ( $item );
  10189. // 添加收入流水
  10190. $wasteBook = new wasteBook ();
  10191. $itemWaste = array (
  10192. 'accountPriceShow' => $receivedPrice,
  10193. 'accountPrice' => $receivedPrice,
  10194. 'expensesType' => 1,
  10195. 'accountType' => 6, // 流水类型
  10196. 'dataID' => $inComeId,
  10197. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10198. 'accountBank' => $accountBank,
  10199. 'category' => $this->staff [0] ['category'],
  10200. 'cid' => $this->staff [0] ['cid'],
  10201. 'name' => $this->staff [0] ['username'],
  10202. 'sid' => $this->staff [0] ['sid'],
  10203. 'inputDate' => date ( "Y-m-d H:i:s" )
  10204. );
  10205. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10206. // 添加一条理财支出
  10207. $accountBank = 'CGBDeposit';
  10208. $expenditureBank = '纵横广发';
  10209. $dailyExpenditureType = 4;
  10210. if ($accountType == 9) {
  10211. $accountBank = 'ICBCDeposit';
  10212. $expenditureBank = '纵横工行';
  10213. $dailyExpenditureType = 6;
  10214. }
  10215. $accountBook = new accountBook ();
  10216. $accountBook->expensesType = 2;
  10217. $accountBook->expenditureType = $dailyExpenditureType;
  10218. $accountBook->expenditureMsg = $accountMsg;
  10219. $accountBook->expenditurePrice = $receivedPrice;
  10220. $accountBook->expenditureBank = $expenditureBank;
  10221. $accountBook->expenditureDate = $receivedDate;
  10222. $accountBook->remarks = $remarks;
  10223. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10224. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10225. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10226. $id = $accountBook->insert ();
  10227. // 收支汇总-添加一条理财支出汇总
  10228. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10229. $accountBookStatistics = new accountBookStatistics ();
  10230. $item = array (
  10231. 'date' => date ( "Y-m-d" ),
  10232. 'accountType' => $abDetail ['accountType'],
  10233. 'accountMsg' => $abDetail ['accountMsg'],
  10234. 'aid' => $abDetail ['aid'],
  10235. 'financingPrice' => - $receivedPrice,
  10236. 'expensesType' => 3
  10237. );
  10238. $accountBookStatistics->setAccountBookStatistics ( $item );
  10239. // 添加一条支出理财流水
  10240. $accountTypeWaste = 5;
  10241. if ($accountMsg == '公司固定') {
  10242. $accountTypeWaste = 9;
  10243. } elseif ($accountMsg == '公司活期') {
  10244. $accountTypeWaste = 10;
  10245. } elseif ($accountMsg == '个人(GR)') {
  10246. $accountBank = 'PersonalDeposit';
  10247. }
  10248. $itemWaste = array (
  10249. 'expensesType' => 2,
  10250. 'accountType' => $accountTypeWaste,
  10251. 'accountPriceShow' => $receivedPrice,
  10252. 'accountPrice' => - $receivedPrice,
  10253. 'dataID' => $id,
  10254. 'dailyExpenditureType' => $dailyExpenditureType,
  10255. 'accountBank' => $accountBank,
  10256. 'category' => $this->staff [0] ['category'],
  10257. 'cid' => $this->staff [0] ['cid'],
  10258. 'name' => $this->staff [0] ['username'],
  10259. 'sid' => $this->staff [0] ['sid'],
  10260. 'inputDate' => date ( "Y-m-d H:i:s" )
  10261. );
  10262. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10263. } elseif ($accountType == 1) {
  10264. if ($receivedBank == '个人广发')
  10265. die ( 'illegal request' );
  10266. // 添加一条收入
  10267. $accountBook = new accountBook ();
  10268. $accountBook->accountType = $accountType;
  10269. $accountBook->accountMsg = $accountMsg;
  10270. $accountBook->receivedPrice = $receivedPrice;
  10271. $accountBook->receivedMsg = $receivedMsg;
  10272. $accountBook->receivedBank = $receivedBank;
  10273. $accountBook->receivedDate = $receivedDate;
  10274. $accountBook->remarks = $remarks;
  10275. $accountBook->expensesType = 1;
  10276. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10277. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10278. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10279. $id = $accountBook->insert ();
  10280. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10281. // 收支汇总-添加一条收入日常汇总
  10282. $accountBookStatistics = new accountBookStatistics ();
  10283. $item = array (
  10284. 'date' => date ( "Y-m-d" ),
  10285. 'accountType' => $abDetail ['accountType'],
  10286. 'accountMsg' => $abDetail ['accountMsg'],
  10287. 'aid' => $abDetail ['aid'],
  10288. 'expensesType' => $abDetail ['expensesType']
  10289. );
  10290. if ($abDetail ['accountType'] == 8) {
  10291. $item += array (
  10292. 'inComePrice' => $abDetail ['receivedPrice']
  10293. );
  10294. } else {
  10295. $item += array (
  10296. 'inComePrice' => $abDetail ['receivedPrice']
  10297. );
  10298. }
  10299. $accountBookStatistics->setAccountBookStatistics ( $item );
  10300. // 流水存储方向
  10301. $itemWaste = array (
  10302. 'accountType' => 6
  10303. ); // 流水类型
  10304. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10305. // }else
  10306. if ($accountMsg == '活期理财收益') {
  10307. $itemWaste = array (
  10308. 'accountType' => 10
  10309. ); // 流水类型
  10310. }
  10311. // 添加收入流水
  10312. $wasteBook = new wasteBook ();
  10313. $itemWaste += array (
  10314. 'accountPrice' => $receivedPrice,
  10315. 'accountPriceShow' => $receivedPrice,
  10316. 'expensesType' => 1,
  10317. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10318. 'dataID' => $id,
  10319. 'accountBank' => $accountBank,
  10320. 'category' => $this->staff [0] ['category'],
  10321. 'cid' => $this->staff [0] ['cid'],
  10322. 'name' => $this->staff [0] ['username'],
  10323. 'sid' => $this->staff [0] ['sid'],
  10324. 'inputDate' => date ( "Y-m-d H:i:s" )
  10325. );
  10326. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10327. } else { // 普通日常收入处理
  10328. // 添加一条收入
  10329. $accountBook = new accountBook ();
  10330. $accountBook->accountType = $accountType;
  10331. $accountBook->accountMsg = $accountMsg;
  10332. $accountBook->receivedPrice = $receivedPrice;
  10333. $accountBook->receivedMsg = $receivedMsg;
  10334. $accountBook->receivedBank = $receivedBank;
  10335. $accountBook->receivedDate = $receivedDate;
  10336. $accountBook->remarks = $remarks;
  10337. $accountBook->expensesType = 1;
  10338. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10339. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10340. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10341. $id = $accountBook->insert ();
  10342. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10343. // 收支汇总-添加一条收入日常汇总
  10344. $accountBookStatistics = new accountBookStatistics ();
  10345. $item = array (
  10346. 'date' => date ( "Y-m-d" ),
  10347. 'accountType' => $abDetail ['accountType'],
  10348. 'accountMsg' => $abDetail ['accountMsg'],
  10349. 'aid' => $abDetail ['aid'],
  10350. 'expensesType' => $abDetail ['expensesType']
  10351. );
  10352. if ($abDetail ['accountType'] == 8) {
  10353. $item += array (
  10354. 'inComePrice' => $abDetail ['receivedPrice']
  10355. );
  10356. } else {
  10357. $item += array (
  10358. 'inComePrice' => $abDetail ['receivedPrice']
  10359. );
  10360. }
  10361. $accountBookStatistics->setAccountBookStatistics ( $item );
  10362. // 添加收入流水
  10363. $itemWaste = array (
  10364. 'accountPrice' => $receivedPrice
  10365. );
  10366. if ($receivedBank == '个人广发') {
  10367. $itemWaste = array (
  10368. 'accountPrice' => - $receivedPrice
  10369. );
  10370. }
  10371. $wasteBook = new wasteBook ();
  10372. $itemWaste += array (
  10373. 'accountPriceShow' => $receivedPrice,
  10374. 'expensesType' => 1,
  10375. 'accountType' => 6, // 流水类型
  10376. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10377. 'dataID' => $id,
  10378. 'accountBank' => $accountBank,
  10379. 'category' => $this->staff [0] ['category'],
  10380. 'cid' => $this->staff [0] ['cid'],
  10381. 'name' => $this->staff [0] ['username'],
  10382. 'sid' => $this->staff [0] ['sid'],
  10383. 'inputDate' => date ( "Y-m-d H:i:s" )
  10384. );
  10385. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10386. }
  10387. }
  10388. return '/payments';
  10389. }
  10390. /**
  10391. * 添加收入
  10392. * @return string
  10393. */
  10394. function paymentsIncomeDo_() {
  10395. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10396. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10397. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10398. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10399. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10400. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10401. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10402. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10403. Doo::loadClass ( 'XDeode' );
  10404. $XDeode = new XDeode ( 5 );
  10405. Doo::loadModel ( "accountBook" );
  10406. $accountBook = new accountBook ();
  10407. $accountBank = '';
  10408. $accountTypeWaste = 6;
  10409. if ($receivedBank == '纵横广发') {
  10410. $accountBank = 'CGBDeposit';
  10411. } elseif ($receivedBank == '纵横工行') {
  10412. $accountBank = 'ICBCDeposit';
  10413. } elseif ($receivedBank == '华润银行') {
  10414. $accountBank = 'HUADeposit';
  10415. } elseif ($receivedBank == '个人广发') {
  10416. $accountBank = 'PersonalDeposit';
  10417. }
  10418. if (empty ( $accountBank ))
  10419. die ( 'illegal request' );
  10420. $dailyIncomeType = '';
  10421. $itemWaste = array (
  10422. 'accountPrice' => $receivedPrice,
  10423. 'expensesType' => 1
  10424. );
  10425. if ($receivedBank == '个人广发') {
  10426. $itemWaste = array (
  10427. 'accountPrice' => - $receivedPrice,
  10428. 'expensesType' => 1
  10429. );
  10430. }
  10431. if ($accountType == 4) {
  10432. $dailyIncomeType = 4;
  10433. } elseif ($accountType == 1) {
  10434. $dailyIncomeType = 1;
  10435. } elseif ($accountType == 2) {
  10436. $dailyIncomeType = 2;
  10437. } elseif ($accountType == 3) {
  10438. $dailyIncomeType = 3;
  10439. } elseif ($accountType == 5) {
  10440. $dailyIncomeType = 5;
  10441. } elseif ($accountType == 6) {
  10442. $dailyIncomeType = 6;
  10443. } elseif ($accountType == 7 || $accountType == 9) {
  10444. $dailyIncomeType = 7;
  10445. if ($accountMsg == '公司固定') {
  10446. $accountTypeWaste = 9;
  10447. } elseif ($accountMsg == '公司活期') {
  10448. $accountTypeWaste = 10;
  10449. } elseif ($accountMsg == '个人(GR)') {
  10450. $accountBank = 'PersonalDeposit';
  10451. }
  10452. $itemWaste = array (
  10453. 'accountPrice' => - $receivedPrice,
  10454. 'expensesType' => 2
  10455. );
  10456. } elseif ($accountType == 8) {
  10457. $dailyIncomeType = 8;
  10458. }
  10459. if (empty ( $dailyIncomeType ))
  10460. die ( 'illegal request' );
  10461. $accountBook->accountType = $accountType;
  10462. $accountBook->accountMsg = $accountMsg;
  10463. $accountBook->receivedPrice = $receivedPrice;
  10464. $accountBook->receivedMsg = $receivedMsg;
  10465. $accountBook->receivedBank = $receivedBank;
  10466. $accountBook->receivedDate = $receivedDate;
  10467. $accountBook->remarks = $remarks;
  10468. $accountBook->expensesType = 1;
  10469. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10470. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10471. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10472. $id = $accountBook->insert ();
  10473. //
  10474. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10475. // 收支汇总
  10476. Doo::loadModel ( "accountBookStatistics" );
  10477. $accountBookStatistics = new accountBookStatistics ();
  10478. $item = array (
  10479. 'date' => date ( "Y-m-d" ),
  10480. 'accountType' => $abDetail ['accountType'],
  10481. 'accountMsg' => $abDetail ['accountMsg'],
  10482. 'aid' => $abDetail ['aid']
  10483. );
  10484. if ($abDetail ['expensesType'] == 1) {
  10485. if ($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) {
  10486. $item += array (
  10487. 'financingPrice' => - $receivedPrice,
  10488. 'expensesType' => 3
  10489. );
  10490. } else if ($abDetail ['accountType'] == 8) {
  10491. $item += array (
  10492. 'inComePrice' => - $abDetail ['receivedPrice'],
  10493. 'expensesType' => $abDetail ['expensesType']
  10494. );
  10495. } else {
  10496. $item += array (
  10497. 'inComePrice' => $abDetail ['receivedPrice'],
  10498. 'expensesType' => $abDetail ['expensesType']
  10499. );
  10500. }
  10501. }
  10502. $accountBookStatistics->setAccountBookStatistics ( $item );
  10503. // 为理财时需添加一条日常支出
  10504. if ($accountType == 7 || $accountType == 9) {
  10505. }
  10506. // 公司流水记录
  10507. Doo::loadModel ( 'wasteBook' );
  10508. $wasteBook = new wasteBook ();
  10509. // 银行
  10510. // if (empty($abDetail)){
  10511. $itemWaste += array (
  10512. 'accountPriceShow' => $receivedPrice,
  10513. 'dataID' => $id,
  10514. 'accountType' => $accountTypeWaste,
  10515. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10516. 'accountBank' => $accountBank,
  10517. 'category' => $this->staff [0] ['category'],
  10518. 'cid' => $this->staff [0] ['cid'],
  10519. 'name' => $this->staff [0] ['username'],
  10520. 'sid' => $this->staff [0] ['sid'],
  10521. 'inputDate' => date ( "Y-m-d H:i:s" )
  10522. );
  10523. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10524. // }
  10525. // 类型为理财7或者9 要添加一笔理财支出
  10526. if ($accountType == 7 || $accountType == 9) {
  10527. $accountBank = 'CGBDeposit';
  10528. $expenditureBank = '纵横广发';
  10529. $dailyExpenditureType = 4;
  10530. if ($accountType == 9) {
  10531. $accountBank = 'ICBCDeposit';
  10532. $expenditureBank = '纵横工行';
  10533. $dailyExpenditureType = 6;
  10534. }
  10535. // 添加一条支出
  10536. $accountBook = new accountBook ();
  10537. $accountBook->expenditureType = $dailyExpenditureType;
  10538. $accountBook->expenditureMsg = $accountMsg;
  10539. $accountBook->expenditurePrice = $receivedPrice;
  10540. $accountBook->expenditureBank = $expenditureBank;
  10541. $accountBook->expenditureDate = $receivedDate;
  10542. $accountBook->remarks = $remarks;
  10543. $accountBook->expensesType = 2;
  10544. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10545. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10546. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10547. $id = $accountBook->insert ();
  10548. // 添加一条收入流水
  10549. $itemWaste = array (
  10550. 'accountPriceShow' => $receivedPrice,
  10551. 'accountPrice' => $receivedPrice,
  10552. 'dataID' => $id,
  10553. 'expensesType' => 2,
  10554. 'accountType' => $accountTypeWaste,
  10555. 'dailyExpenditureType' => $dailyExpenditureType,
  10556. 'accountBank' => $accountBank,
  10557. 'category' => $this->staff [0] ['category'],
  10558. 'cid' => $this->staff [0] ['cid'],
  10559. 'name' => $this->staff [0] ['username'],
  10560. 'sid' => $this->staff [0] ['sid'],
  10561. 'inputDate' => date ( "Y-m-d H:i:s" )
  10562. );
  10563. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10564. }
  10565. }
  10566. return '/payments';
  10567. }
  10568. function paymentsExpenditureDo() {
  10569. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10570. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10571. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10572. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10573. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10574. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10575. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10576. // 理财支出特殊处理
  10577. Doo::loadModel ( "accountBook" );
  10578. Doo::loadModel ( "accountBookStatistics" );
  10579. Doo::loadModel ( 'wasteBook' );
  10580. $accountBank = '';
  10581. if ($expenditureBank == '纵横广发') {
  10582. $accountBank = 'CGBDeposit';
  10583. } elseif ($expenditureBank == '纵横工行') {
  10584. $accountBank = 'ICBCDeposit';
  10585. } elseif ($expenditureBank == '华润银行') {
  10586. $accountBank = 'HUADeposit';
  10587. } elseif ($expenditureBank == '个人广发') {
  10588. $accountBank = 'PersonalDeposit';
  10589. }
  10590. if (empty ( $accountBank ))
  10591. die ( 'illegal request' );
  10592. if ($expenditureType == 4 || $expenditureType == 6) {
  10593. if ($expenditureBank == '个人广发') {
  10594. die ( '个人广发 illegal request' );
  10595. }
  10596. // 添加一笔日常支出
  10597. $accountBook = new accountBook ();
  10598. $accountBook->expensesType = 2;
  10599. $accountBook->expenditureType = 7;
  10600. $accountBook->expenditureMsg = $expenditureMsg;
  10601. $accountBook->expenditurePrice = $expenditurePrice;
  10602. $accountBook->expenditureBank = $expenditureBank;
  10603. $accountBook->expenditureDate = $expenditureDate;
  10604. $accountBook->remarks = $remarks;
  10605. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10606. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10607. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10608. $expenditureId = $accountBook->insert ();
  10609. // 添加日常支出汇总
  10610. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10611. $accountBookStatistics = new accountBookStatistics ();
  10612. $item = array (
  10613. 'date' => date ( "Y-m-d" ),
  10614. 'expenditureType' => $abDetail ['expenditureType'],
  10615. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10616. 'aid' => $abDetail ['aid'],
  10617. 'payPrice' => $abDetail ['expenditurePrice'],
  10618. 'expensesType' => $abDetail ['expensesType']
  10619. );
  10620. $accountBookStatistics->setAccountBookStatistics ( $item );
  10621. // 公司日常支出流水
  10622. $wasteBook = new wasteBook ();
  10623. $itemWaste = array (
  10624. 'accountPrice' => - $expenditurePrice
  10625. );
  10626. if ($expenditureBank == '个人广发') {
  10627. $itemWaste = array (
  10628. 'accountPrice' => $expenditurePrice
  10629. );
  10630. }
  10631. $itemWaste += array (
  10632. 'expensesType' => 2,
  10633. 'accountType' => 5,
  10634. 'dailyExpenditureType' => $expenditureType,
  10635. 'accountPriceShow' => $expenditurePrice,
  10636. 'accountPrice' => - $expenditurePrice,
  10637. 'dataID' => $expenditureId,
  10638. 'accountBank' => $accountBank,
  10639. 'category' => $this->staff [0] ['category'],
  10640. 'cid' => $this->staff [0] ['cid'],
  10641. 'name' => $this->staff [0] ['username'],
  10642. 'sid' => $this->staff [0] ['sid'],
  10643. 'inputDate' => date ( "Y-m-d H:i:s" )
  10644. );
  10645. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10646. // 添加一笔理财收入
  10647. $accountBank = 'CGBDeposit';
  10648. $dailyIncomeType = 7;
  10649. $receivedBank = '纵横广发';
  10650. if ($expenditureType == 6) {
  10651. $accountBank = 'ICBCDeposit';
  10652. $receivedBank = '纵横工行';
  10653. $dailyIncomeType = 9;
  10654. }
  10655. $accountBook = new accountBook ();
  10656. $accountBook->expensesType = 1;
  10657. $accountBook->accountType = $dailyIncomeType;
  10658. $accountBook->accountMsg = $expenditureMsg;
  10659. $accountBook->receivedPrice = $expenditurePrice;
  10660. $accountBook->receivedBank = $receivedBank;
  10661. $accountBook->receivedDate = $expenditureDate;
  10662. $accountBook->remarks = $remarks;
  10663. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10664. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10665. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10666. $id = $accountBook->insert ();
  10667. // 添加日常理财收入汇总
  10668. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10669. $accountBookStatistics = new accountBookStatistics ();
  10670. $item = array (
  10671. 'date' => date ( "Y-m-d" ),
  10672. 'expenditureType' => $abDetail ['expenditureType'],
  10673. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10674. 'aid' => $abDetail ['aid'],
  10675. 'financingPrice' => $expenditurePrice,
  10676. 'expensesType' => 3
  10677. );
  10678. $accountBookStatistics->setAccountBookStatistics ( $item );
  10679. // 添加一笔收入流水
  10680. if ($expenditureMsg == '公司固定') {
  10681. $accountTypeWaste = 9;
  10682. } elseif ($expenditureMsg == '公司活期') {
  10683. $accountTypeWaste = 10;
  10684. } elseif ($expenditureMsg == '个人(GR)') {
  10685. $accountBank = 'PersonalDeposit';
  10686. }
  10687. $itemWaste = array (
  10688. 'expensesType' => 1,
  10689. 'accountType' => $accountTypeWaste,
  10690. 'accountPriceShow' => $expenditurePrice,
  10691. 'accountPrice' => $expenditurePrice,
  10692. 'dataID' => $id,
  10693. 'dailyIncomeType' => $dailyIncomeType,
  10694. 'accountBank' => $accountBank,
  10695. 'category' => $this->staff [0] ['category'],
  10696. 'cid' => $this->staff [0] ['cid'],
  10697. 'name' => $this->staff [0] ['username'],
  10698. 'sid' => $this->staff [0] ['sid'],
  10699. 'inputDate' => date ( "Y-m-d H:i:s" )
  10700. );
  10701. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10702. } else {
  10703. // 添加一笔日常支出
  10704. $accountBook = new accountBook ();
  10705. $accountBook->expensesType = 2;
  10706. $accountBook->expenditureType = $expenditureType;
  10707. $accountBook->expenditureMsg = $expenditureMsg;
  10708. $accountBook->expenditurePrice = $expenditurePrice;
  10709. $accountBook->expenditureBank = $expenditureBank;
  10710. $accountBook->expenditureDate = $expenditureDate;
  10711. $accountBook->remarks = $remarks;
  10712. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10713. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10714. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10715. $id = $accountBook->insert ();
  10716. // 添加日常支出汇总
  10717. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10718. $accountBookStatistics = new accountBookStatistics ();
  10719. $item = array (
  10720. 'date' => date ( "Y-m-d" ),
  10721. 'expenditureType' => $abDetail ['expenditureType'],
  10722. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10723. 'aid' => $abDetail ['aid'],
  10724. 'expensesType' => $abDetail ['expensesType']
  10725. );
  10726. if ($expenditureType == 5) {
  10727. $item += array (
  10728. 'payPrice' => - $abDetail ['expenditurePrice']
  10729. );
  10730. } else {
  10731. $item += array (
  10732. 'payPrice' => $abDetail ['expenditurePrice']
  10733. );
  10734. }
  10735. $accountBookStatistics->setAccountBookStatistics ( $item );
  10736. // 公司日常支出流水
  10737. $wasteBook = new wasteBook ();
  10738. $itemWaste = array (
  10739. 'accountPrice' => - $expenditurePrice
  10740. );
  10741. if ($expenditureBank == '个人广发') {
  10742. $itemWaste = array (
  10743. 'accountPrice' => $expenditurePrice
  10744. );
  10745. }
  10746. $itemWaste += array (
  10747. 'expensesType' => 2,
  10748. 'accountType' => 5,
  10749. 'accountPriceShow' => $expenditurePrice,
  10750. 'dataID' => $id,
  10751. 'dailyExpenditureType' => $expenditureType,
  10752. 'accountBank' => $accountBank,
  10753. 'category' => $this->staff [0] ['category'],
  10754. 'cid' => $this->staff [0] ['cid'],
  10755. 'name' => $this->staff [0] ['username'],
  10756. 'sid' => $this->staff [0] ['sid'],
  10757. 'inputDate' => date ( "Y-m-d H:i:s" )
  10758. );
  10759. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10760. }
  10761. }
  10762. return '/payments';
  10763. }
  10764. /**
  10765. * 添加支出
  10766. */
  10767. function paymentsExpenditureDo_() {
  10768. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10769. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10770. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10771. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10772. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10773. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10774. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10775. $dailyExpenditureType = '';
  10776. $accountTypeWaste = 5;
  10777. $accountBank = '';
  10778. if ($expenditureBank == '纵横广发') {
  10779. $accountBank = 'CGBDeposit';
  10780. } elseif ($expenditureBank == '纵横工行') {
  10781. $accountBank = 'ICBCDeposit';
  10782. } elseif ($expenditureBank == '华润银行') {
  10783. $accountBank = 'HUADeposit';
  10784. } elseif ($expenditureBank == '个人广发') {
  10785. $accountBank = 'PersonalDeposit';
  10786. }
  10787. if (empty ( $accountBank ))
  10788. die ( 'illegal request' );
  10789. $itemWaste = array (
  10790. 'accountPrice' => - $expenditurePrice
  10791. );
  10792. if ($expenditureBank == '个人广发') {
  10793. $itemWaste = array (
  10794. 'accountPrice' => $expenditurePrice
  10795. );
  10796. }
  10797. if ($expenditureType == 4 || $expenditureType == 6) {
  10798. $dailyExpenditureType = 4;
  10799. if ($expenditureMsg == '公司固定') {
  10800. $accountTypeWaste = 9;
  10801. } elseif ($expenditureMsg == '公司活期') {
  10802. $accountTypeWaste = 10;
  10803. } elseif ($expenditureMsg == '个人(GR)') {
  10804. $accountBank = 'PersonalDeposit';
  10805. }
  10806. $itemWaste = array (
  10807. 'accountPrice' => $expenditurePrice
  10808. );
  10809. } elseif ($expenditureType == 1) {
  10810. $dailyExpenditureType = 1;
  10811. } elseif ($expenditureType == 2) {
  10812. $dailyExpenditureType = 2;
  10813. } elseif ($expenditureType == 3) {
  10814. $dailyExpenditureType = 3;
  10815. } elseif ($expenditureType == 5) {
  10816. $dailyExpenditureType = 5;
  10817. }
  10818. if (empty ( $dailyExpenditureType ))
  10819. die ( 'illegal request' );
  10820. Doo::loadModel ( "accountBook" );
  10821. $accountBook = new accountBook ();
  10822. $accountBook->expenditureType = $expenditureType;
  10823. $accountBook->expenditureMsg = $expenditureMsg;
  10824. $accountBook->expenditurePrice = $expenditurePrice;
  10825. $accountBook->expenditureBank = $expenditureBank;
  10826. $accountBook->expenditureDate = $expenditureDate;
  10827. $accountBook->remarks = $remarks;
  10828. $accountBook->expensesType = 2;
  10829. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10830. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10831. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10832. $id = $accountBook->insert ();
  10833. //
  10834. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10835. Doo::loadModel ( "accountBookStatistics" );
  10836. $accountBookStatistics = new accountBookStatistics ();
  10837. $item = array (
  10838. 'date' => date ( "Y-m-d" ),
  10839. 'expenditureType' => $abDetail ['expenditureType'],
  10840. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10841. 'aid' => $abDetail ['aid']
  10842. );
  10843. if ($abDetail ['expensesType'] == 2) {
  10844. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  10845. $item += array (
  10846. 'financingPrice' => $expenditurePrice,
  10847. 'expensesType' => 3
  10848. );
  10849. } elseif ($abDetail ['expenditureType'] == 5) {
  10850. $item += array (
  10851. 'payPrice' => $abDetail ['expenditurePrice'],
  10852. 'expensesType' => $abDetail ['expensesType']
  10853. );
  10854. } else {
  10855. $item += array (
  10856. 'payPrice' => $abDetail ['expenditurePrice'],
  10857. 'expensesType' => $abDetail ['expensesType']
  10858. );
  10859. }
  10860. }
  10861. $accountBookStatistics->setAccountBookStatistics ( $item );
  10862. // 公司流水记录
  10863. Doo::loadModel ( 'wasteBook' );
  10864. $wasteBook = new wasteBook ();
  10865. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  10866. // 银行
  10867. if (empty ( $abDetail )) {
  10868. $itemWaste += array (
  10869. 'accountPriceShow' => $expenditurePrice,
  10870. 'dataID' => $id,
  10871. 'expensesType' => 2,
  10872. 'accountType' => $accountTypeWaste,
  10873. 'dailyExpenditureType' => $expenditureType,
  10874. 'accountBank' => $accountBank,
  10875. 'category' => $this->staff [0] ['category'],
  10876. 'cid' => $this->staff [0] ['cid'],
  10877. 'name' => $this->staff [0] ['username'],
  10878. 'sid' => $this->staff [0] ['sid'],
  10879. 'inputDate' => date ( "Y-m-d H:i:s" )
  10880. );
  10881. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10882. }
  10883. // 支出类型为4或者6 需要添加一笔收入和收入流水
  10884. if ($expenditureType == 4 || $expenditureType == 6) {
  10885. $accountBank = 'CGBDeposit';
  10886. $dailyIncomeType = 7;
  10887. $receivedBank = '纵横广发';
  10888. if ($expenditureType == 6) {
  10889. $accountBank = 'ICBCDeposit';
  10890. $receivedBank = '纵横工行';
  10891. $dailyIncomeType = 9;
  10892. }
  10893. // 添加一笔收入
  10894. $accountBook = new accountBook ();
  10895. $accountBook->accountType = $dailyIncomeType;
  10896. $accountBook->accountMsg = $expenditureMsg;
  10897. $accountBook->receivedPrice = $expenditurePrice;
  10898. $accountBook->receivedBank = $receivedBank;
  10899. $accountBook->receivedDate = $expenditureDate;
  10900. $accountBook->remarks = $remarks;
  10901. $accountBook->expensesType = 1;
  10902. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10903. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10904. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10905. $id = $accountBook->insert ();
  10906. // 添加一笔收入流水
  10907. $itemWaste = array (
  10908. 'accountPriceShow' => $expenditurePrice,
  10909. 'accountPrice' => - $expenditurePrice,
  10910. 'dataID' => $id,
  10911. 'expensesType' => 1,
  10912. 'accountType' => $accountTypeWaste,
  10913. 'dailyIncomeType' => $dailyIncomeType,
  10914. 'accountBank' => $accountBank,
  10915. 'category' => $this->staff [0] ['category'],
  10916. 'cid' => $this->staff [0] ['cid'],
  10917. 'name' => $this->staff [0] ['username'],
  10918. 'sid' => $this->staff [0] ['sid'],
  10919. 'inputDate' => date ( "Y-m-d H:i:s" )
  10920. );
  10921. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10922. }
  10923. }
  10924. return '/payments';
  10925. }
  10926. /**
  10927. * 所有收支
  10928. */
  10929. function paymentsAchieve() {
  10930. $page_size = 12;
  10931. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  10932. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  10933. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  10934. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  10935. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10936. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10937. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10938. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  10939. Doo::loadModel ( "accountBookStatistics" );
  10940. $accountBookStatistics = new accountBookStatistics ();
  10941. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10942. $data ['statisticsList'] = $statisticsList;
  10943. Doo::loadModel ( "accountBook" );
  10944. $accountBook = new accountBook ();
  10945. $con = '';
  10946. if ($expensesType == 'INCOME')
  10947. $con = ' and expensesType=1 ';
  10948. elseif ($expensesType == 'PAY')
  10949. $con = ' and expensesType=2 ';
  10950. $dateArr = explode ( ':', $date );
  10951. $D1 = $dateString = '';
  10952. $D2 = '';
  10953. if (! empty ( $date )) {
  10954. $D1 = $dateArr [0];
  10955. if (isset ( $dateArr [1] ))
  10956. $D2 = $dateArr [1];
  10957. else
  10958. $D2 = '';
  10959. $dateString = $D1 . " : " . $D2;
  10960. }
  10961. if (! empty ( $D1 ) && ! empty ( $D2 ))
  10962. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  10963. elseif (! empty ( $D1 ) && empty ( $D2 ))
  10964. $con .= ' and inputDate like "%' . $D1 . '%" ';
  10965. if (! empty ( $price ))
  10966. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  10967. if ($submitType == 1) {
  10968. if ($accountType != '') {
  10969. $expenditureType = '';
  10970. $con .= ' and accountType=' . $accountType;
  10971. if (! empty ( $accountMsg ))
  10972. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  10973. }
  10974. } elseif ($submitType == 2) {
  10975. if ($expenditureType != '') {
  10976. $accountType = $accountMsg = '';
  10977. $con .= ' and expenditureType=' . $expenditureType;
  10978. }
  10979. } else {
  10980. $accountType = $accountMsg = $expenditureType = '';
  10981. }
  10982. $sql = "" . $con;
  10983. $action = "paymentsAchieve";
  10984. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  10985. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  10986. $limit = $pageinfo ['lower'] . ',' . $page_size;
  10987. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  10988. $data ['expenditureType'] = $expenditureType;
  10989. $data ['accountMsg'] = $accountMsg;
  10990. $data ['accountType'] = $accountType;
  10991. $data ['inputDate'] = $date;
  10992. $data ['price'] = $price;
  10993. $data ['expensesType'] = $expensesType;
  10994. $data ['page'] = $pageinfo;
  10995. $data ['list'] = $list;
  10996. $data ['memu'] = "receipt";
  10997. $data ['staff'] = $this->staff;
  10998. $data ['receiptMemu'] = 'payments';
  10999. $data ['verifyId'] = $this->verifyId;
  11000. $data ['executeId'] = $this->executeId;
  11001. $this->render ( "/expenses/paymentsAchieve", $data );
  11002. }
  11003. function paymentsIncomeUpdateDo() {
  11004. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11005. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11006. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11007. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11008. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11009. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11010. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11011. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11012. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11013. Doo::loadClass ( 'XDeode' );
  11014. $XDeode = new XDeode ( 5 );
  11015. $aid = $XDeode->decode ( $aidKey );
  11016. Doo::loadModel ( "accountBook" );
  11017. $accountBook = new accountBook ();
  11018. //
  11019. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11020. $price = $receivedPrice - $abDetail [inComePrice];
  11021. Doo::loadModel ( "accountBookStatistics" );
  11022. $accountBookStatistics = new accountBookStatistics ();
  11023. if ($abDetail ['accountType'] == 7) {
  11024. $item += array (
  11025. 'date' => date ( "Y-m-d" ),
  11026. 'financingPrice' => - $price,
  11027. 'expensesType' => 3,
  11028. 'aid' => $abDetail ['aid']
  11029. );
  11030. } elseif ($abDetail ['accountType'] == 8) {
  11031. $item += array (
  11032. 'date' => date ( "Y-m-d" ),
  11033. 'expensesType' => $abDetail ['expensesType'],
  11034. 'inComePrice' => - $price,
  11035. 'aid' => $abDetail ['aid']
  11036. );
  11037. } else {
  11038. $item = array (
  11039. 'date' => date ( "Y-m-d" ),
  11040. 'expensesType' => $abDetail ['expensesType'],
  11041. 'inComePrice' => $price,
  11042. 'aid' => $abDetail ['aid']
  11043. );
  11044. }
  11045. $accountBookStatistics->setAccountBookStatistics ( $item );
  11046. $accountBook->accountType = $accountType;
  11047. $accountBook->accountMsg = $accountMsg;
  11048. $accountBook->receivedPrice = $receivedPrice;
  11049. $accountBook->receivedMsg = $receivedMsg;
  11050. $accountBook->receivedBank = $receivedBank;
  11051. $accountBook->receivedDate = $receivedDate;
  11052. $accountBook->remarks = $remarks;
  11053. $accountBook->aid = $aid;
  11054. $accountBook->update ();
  11055. }
  11056. return '/paymentsAchieve';
  11057. }
  11058. function paymentsExpenditureEdiDo() {
  11059. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11060. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11061. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11062. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11063. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11064. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11065. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11066. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11067. Doo::loadClass ( 'XDeode' );
  11068. $XDeode = new XDeode ( 5 );
  11069. $aid = $XDeode->decode ( $aidKey );
  11070. Doo::loadModel ( "accountBook" );
  11071. $accountBook = new accountBook ();
  11072. // 汇总信息
  11073. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11074. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11075. Doo::loadModel ( "accountBookStatistics" );
  11076. $accountBookStatistics = new accountBookStatistics ();
  11077. if ($abDetail ['expenditureType'] == 4) {
  11078. $item += array (
  11079. 'date' => date ( "Y-m-d" ),
  11080. 'financingPrice' => $price,
  11081. 'expensesType' => 3,
  11082. 'aid' => $abDetail ['aid']
  11083. );
  11084. } elseif ($abDetail ['expenditureType'] == 5) {
  11085. $item += array (
  11086. 'date' => date ( "Y-m-d" ),
  11087. 'expensesType' => $abDetail ['expensesType'],
  11088. 'payPrice' => $price,
  11089. 'aid' => $abDetail ['aid']
  11090. );
  11091. } else {
  11092. $item = array (
  11093. 'date' => date ( "Y-m-d" ),
  11094. 'expensesType' => $abDetail ['expensesType'],
  11095. 'payPrice' => $price,
  11096. 'aid' => $abDetail ['aid']
  11097. );
  11098. }
  11099. $accountBookStatistics->setAccountBookStatistics ( $item );
  11100. //
  11101. $accountBook->expenditureType = $expenditureType;
  11102. $accountBook->expenditureMsg = $expenditureMsg;
  11103. $accountBook->expenditurePrice = $expenditurePrice;
  11104. $accountBook->expenditureBank = $expenditureBank;
  11105. $accountBook->remarks = $remarks;
  11106. $accountBook->expenditureDate = $expenditureDate;
  11107. $accountBook->aid = $aid;
  11108. $id = $accountBook->update ();
  11109. }
  11110. return '/paymentsAchieve';
  11111. }
  11112. function paymentsDelDo() {
  11113. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11114. if (! empty ( $aidKey )) {
  11115. Doo::loadClass ( 'XDeode' );
  11116. $XDeode = new XDeode ( 5 );
  11117. $aid = $XDeode->decode ( $aidKey );
  11118. Doo::loadModel ( "accountBook" );
  11119. $accountBook = new accountBook ();
  11120. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11121. if (empty ( $abDetail ))
  11122. die ( 'illegal request' );
  11123. // 删除收支
  11124. Doo::loadModel ( "accountBookStatistics" );
  11125. $accountBookStatistics = new accountBookStatistics ();
  11126. $item = array (
  11127. 'date' => date ( "Y-m-d" ),
  11128. 'aid' => $abDetail ['aid']
  11129. );
  11130. $accountType = '';
  11131. if ($abDetail ['expensesType'] == 1) {
  11132. $accountType = 6;
  11133. if ($abDetail ['accountType'] != 7) {
  11134. $item += array (
  11135. 'expensesType' => $abDetail ['expensesType'],
  11136. 'inComePrice' => - $abDetail ['receivedPrice']
  11137. );
  11138. } else {
  11139. $item += array (
  11140. 'financingPrice' => $abDetail ['receivedPrice'],
  11141. 'expensesType' => 3
  11142. );
  11143. }
  11144. } elseif ($abDetail ['expensesType'] == 2) {
  11145. $accountType = 5;
  11146. if ($abDetail ['accountType'] != 7) {
  11147. $item += array (
  11148. 'expensesType' => $abDetail ['expensesType'],
  11149. 'payPrice' => - $abDetail ['expenditurePrice']
  11150. );
  11151. } else {
  11152. $item += array (
  11153. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11154. 'expensesType' => 3
  11155. );
  11156. }
  11157. }
  11158. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11159. if ($abDetail ['expenditureMsg'] == '公司固定')
  11160. $accountType = 9;
  11161. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11162. $accountType = 10;
  11163. }
  11164. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11165. if ($abDetail ['accountMsg'] == '公司固定')
  11166. $accountType = 9;
  11167. elseif ($abDetail ['accountMsg'] == '公司活期')
  11168. $accountType = 10;
  11169. }
  11170. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11171. $accountType = 10;
  11172. }
  11173. $accountBookStatistics->setAccountBookStatistics ( $item );
  11174. $accountBook->delete ( array (
  11175. 'where' => 'aid=' . $aid,
  11176. 'limit' => 1
  11177. ) );
  11178. // 删除收入流水
  11179. if (! empty ( $accountType )) {
  11180. Doo::loadModel ( 'wasteBook' );
  11181. $wasteBook = new wasteBook ();
  11182. $wasteBook->delete ( array (
  11183. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11184. 'limit' => 1
  11185. ) );
  11186. }
  11187. }
  11188. return '/paymentsAchieve';
  11189. }
  11190. function paymentsCollect() {
  11191. Doo::loadModel ( "execute" );
  11192. $execute = new execute ();
  11193. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11194. die ( 'illegal request' );
  11195. }
  11196. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11197. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11198. Doo::loadModel ( "accountBookStatistics" );
  11199. $accountBookStatistics = new accountBookStatistics ();
  11200. Doo::loadClass ( 'receipt.func' );
  11201. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11202. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11203. $data ['html'] = $html ['html'];
  11204. $data ['inSum'] = $html ['sum'];
  11205. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11206. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11207. $data ['payHtml'] = $html ['html'];
  11208. $data ['paySum'] = $html ['sum'];
  11209. // 余额统计
  11210. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11211. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11212. include './protected/config/wasteBook.conf.php';
  11213. Doo::loadModel ( 'wasteBook' );
  11214. $wasteBook = new wasteBook ();
  11215. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11216. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11217. // 获得年份之前所有金额
  11218. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11219. // print_r($detail);
  11220. // $waste['total'];
  11221. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11222. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11223. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11224. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11225. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11226. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11227. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11228. if (date ( 'Y' ) > $year) {
  11229. $limitMonth = 12;
  11230. }
  11231. for($i = 1; $i <= 12; $i ++) {
  11232. $inComeA = $payB = 0;
  11233. $falg = true;
  11234. foreach ( $inComePay as $key => $value ) {
  11235. if ($value ['month'] == $i) {
  11236. $falg = false;
  11237. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11238. $inSum += $value ['accountPrice'];
  11239. $showInSum += $value ['accountPriceShow'];
  11240. $inComeA = $value ['accountPrice'];
  11241. break;
  11242. }
  11243. }
  11244. if ($falg)
  11245. $inComeHtml .= '<td class="taR">-</td>';
  11246. $payFalg = true;
  11247. foreach ( $pay as $key => $value ) {
  11248. if ($value ['month'] == $i) {
  11249. $payFalg = false;
  11250. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11251. $paySum += $value ['accountPrice'];
  11252. $showPaySum += $value ['accountPriceShow'];
  11253. $payB = $value ['accountPrice'];
  11254. break;
  11255. }
  11256. }
  11257. if ($payFalg)
  11258. $payHtml .= '<td class="taR">-</td>';
  11259. if (empty ( $balanceC ) || $limitMonth < $i)
  11260. $lastBalanceHtml .= '<td class="taR">-</td>';
  11261. else
  11262. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11263. $balanceC = $balanceC + $inComeA + $payB;
  11264. $balanceSum += $balanceC;
  11265. if (empty ( $balanceC ) || $limitMonth < $i)
  11266. $BalanceHtml .= '<td class="taR">-</td>';
  11267. else
  11268. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11269. // 余额统计
  11270. }
  11271. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11272. $data ['inComeHtml'] = $inComeHtml;
  11273. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11274. $data ['payBalanceHtml'] = $payHtml;
  11275. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11276. $data ['BalanceHtml'] = $BalanceHtml;
  11277. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11278. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11279. $mothHtml = "";
  11280. for($i = 1; $i <= 12; $i ++) {
  11281. if ($moth == $i)
  11282. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11283. else
  11284. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11285. }
  11286. $data ['mothHtml'] = $mothHtml;
  11287. $dateHtml = "";
  11288. $now = date ( "Y" );
  11289. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11290. if ($YEARD <= $now) {
  11291. $dateHtml .= '<option ';
  11292. if ($year == $YEARD) {
  11293. $dateHtml .= 'selected ';
  11294. }
  11295. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11296. }
  11297. }
  11298. $data ['dateHtml'] = $dateHtml;
  11299. $data ['year'] = $year;
  11300. $data ['memu'] = "receipt";
  11301. $data ['staff'] = $this->staff;
  11302. $data ['receiptMemu'] = 'paymentsCollect';
  11303. $data ['verifyId'] = $this->verifyId;
  11304. $data ['executeId'] = $this->executeId;
  11305. $this->render ( "/expenses/paymentsCollect", $data );
  11306. }
  11307. function paymentsCollectDay() {
  11308. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11309. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11310. if (empty ( $moth ))
  11311. return 'paymentsCollect';
  11312. Doo::loadModel ( "accountBookStatistics" );
  11313. $accountBookStatistics = new accountBookStatistics ();
  11314. $i = 2;
  11315. $y = 2013;
  11316. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11317. Doo::loadClass ( 'receipt.func' );
  11318. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11319. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11320. $data ['html'] = $html ['html'];
  11321. $data ['inSum'] = $html ['sum'];
  11322. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11323. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11324. $data ['payHtml'] = $html ['html'];
  11325. $data ['paySum'] = $html ['sum'];
  11326. $mothHtml = "";
  11327. for($i = 1; $i <= 12; $i ++) {
  11328. if ($moth == $i)
  11329. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11330. else
  11331. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11332. }
  11333. $data ['mothHtml'] = $mothHtml;
  11334. $data ['year'] = $year;
  11335. // 余额
  11336. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11337. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11338. include './protected/config/wasteBook.conf.php';
  11339. Doo::loadModel ( 'wasteBook' );
  11340. $wasteBook = new wasteBook ();
  11341. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11342. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11343. // 获得年份之前所有金额
  11344. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11345. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11346. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11347. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11348. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11349. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11350. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11351. // $balanceC = 0;
  11352. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11353. $limitDay = date ( 'd' );
  11354. $monthLK = ( int ) date ( 'm' );
  11355. if (date ( 'Y' ) > $year) {
  11356. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11357. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11358. $limitDay = 0;
  11359. }
  11360. for($i = 1; $i <= $day; $i ++) {
  11361. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11362. $inComeA = $payB = 0;
  11363. $falg = true;
  11364. foreach ( $inComePay as $key => $value ) {
  11365. if ($value ['day'] == $i) {
  11366. $falg = false;
  11367. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11368. $inSum += $value ['accountPrice'];
  11369. $showInSum += $value ['accountPriceShow'];
  11370. $inComeA = $value ['accountPrice'];
  11371. break;
  11372. }
  11373. }
  11374. if ($falg)
  11375. $inComeHtml .= '<td class="taR">-</td>';
  11376. $payFalg = true;
  11377. foreach ( $pay as $key => $value ) {
  11378. if ($value ['day'] == $i) {
  11379. $payFalg = false;
  11380. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11381. $paySum += $value ['accountPrice'];
  11382. $showPaySum += $value ['accountPriceShow'];
  11383. $payB = $value ['accountPrice'];
  11384. break;
  11385. }
  11386. }
  11387. if ($payFalg)
  11388. $payHtml .= '<td class="taR">-</td>';
  11389. if (empty ( $balanceC ) || $limitDay < $i)
  11390. $lastBalanceHtml .= '<td class="taR">-</td>';
  11391. else
  11392. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11393. $balanceC = $balanceC + $inComeA + $payB;
  11394. $balanceSum += $balanceC;
  11395. if (empty ( $balanceC ) || $limitDay < $i)
  11396. $BalanceHtml .= '<td class="taR">-</td>';
  11397. else
  11398. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11399. }
  11400. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11401. $data ['inComeHtml'] = $inComeHtml;
  11402. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11403. $data ['payBalanceHtml'] = $payHtml;
  11404. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11405. $data ['BalanceHtml'] = $BalanceHtml;
  11406. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11407. $data ['dayHtml'] = $dayHtml;
  11408. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11409. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11410. $dateHtml = "";
  11411. $now = date ( "Y" );
  11412. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11413. if ($YEARD <= $now) {
  11414. $dateHtml .= '<option ';
  11415. if ($year == $YEARD) {
  11416. $dateHtml .= 'selected ';
  11417. }
  11418. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11419. }
  11420. }
  11421. $data ['dateHtml'] = $dateHtml;
  11422. $data ['memu'] = "receipt";
  11423. $data ['staff'] = $this->staff;
  11424. $data ['receiptMemu'] = 'paymentsCollect';
  11425. $data ['verifyId'] = $this->verifyId;
  11426. $data ['executeId'] = $this->executeId;
  11427. $this->render ( "/expenses/paymentsCollectDay", $data );
  11428. }
  11429. // 公司流水
  11430. function wasteBook() {
  11431. Doo::loadModel ( "execute" );
  11432. $execute = new execute ();
  11433. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11434. die ( 'illegal request' );
  11435. }
  11436. include './protected/config/wasteBook.conf.php';
  11437. Doo::loadModel ( 'wasteBook' );
  11438. $wasteBook = new wasteBook ();
  11439. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11440. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11441. $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'];
  11442. // print_r($waste);
  11443. $data ['waste'] = $waste;
  11444. $data ['total'] = $total;
  11445. // 月流水数据结构
  11446. $monthStatistics = array ();
  11447. $incomeMothStatistics = array ();
  11448. $expenditureMothStatistics = array ();
  11449. for($i = 1; $i <= 12; $i ++) {
  11450. $month = date ( 'Y' ) . '-' . $i;
  11451. if ($i < 10)
  11452. $month = date ( 'Y' ) . '-0' . $i;
  11453. array_push ( $monthStatistics, $month );
  11454. }
  11455. foreach ( $monthStatistics as $value ) {
  11456. $falg = true;
  11457. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11458. if ($value == $v ['inputDate']) {
  11459. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11460. $falg = false;
  11461. }
  11462. }
  11463. if ($falg) {
  11464. array_push ( $incomeMothStatistics, '' );
  11465. }
  11466. $falgEx = true;
  11467. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11468. if ($value == $v ['inputDate']) {
  11469. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11470. $falg = false;
  11471. }
  11472. }
  11473. if ($falgEx) {
  11474. array_push ( $expenditureMothStatistics, '' );
  11475. }
  11476. }
  11477. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11478. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11479. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11480. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11481. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11482. // print_r($incomeList);
  11483. $data ['expenditureList'] = $expenditureList;
  11484. $data ['incomeList'] = $incomeList;
  11485. $data ['memu'] = "receipt";
  11486. $data ['staff'] = $this->staff;
  11487. $data ['receiptMemu'] = 'wasteBook';
  11488. $data ['verifyId'] = $this->verifyId;
  11489. $data ['executeId'] = $this->executeId;
  11490. $this->render ( "/expenses/wasteBook", $data );
  11491. }
  11492. function wasteBookIncome() {
  11493. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11494. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11495. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11496. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11497. $data ['dailyIncomeType'] = $dailyIncomeType;
  11498. Doo::loadModel ( 'wasteBook' );
  11499. $wasteBook = new wasteBook ();
  11500. Doo::loadModel ( 'L_category' );
  11501. $L_category = new L_category ();
  11502. Doo::loadClass ( 'XDeode' );
  11503. $XDeode = new XDeode ( 5 );
  11504. // echo $XDeode->encode(1).'<br>';
  11505. // echo $XDeode->encode(2).'<br>';
  11506. // echo $XDeode->encode(3).'<br>';
  11507. // echo $XDeode->encode(4).'<br>';
  11508. // echo $XDeode->encode(5).'<br>';
  11509. // echo $XDeode->encode(6).'<br>';
  11510. // echo $XDeode->encode(7).'<br>';
  11511. // echo $XDeode->encode(8).'<br>';
  11512. // echo $XDeode->encode(9).'<br>';
  11513. // echo $XDeode->encode(10).'<br>';
  11514. $dateArr = explode ( ':', $date );
  11515. $D1 = '';
  11516. $D2 = '';
  11517. $con = '';
  11518. if (! empty ( $date )) {
  11519. $D1 = $dateArr [0];
  11520. $D2 = $dateArr [1];
  11521. }
  11522. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11523. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11524. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11525. $con = ' and inputDate = "' . $D1 . '"';
  11526. if ($cid != 'ALL') {
  11527. $cid = $XDeode->decode ( $cid );
  11528. $con .= ' and cid = "' . $cid . '"';
  11529. }
  11530. if ($accountType != 'ALL') {
  11531. if ($accountType == 'INVOICE') {
  11532. $con .= ' and (accountType = 7 or accountType = 8)';
  11533. } elseif ($accountType == 'PAYMENTS') {
  11534. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11535. if ($dailyIncomeType != 'ALL') {
  11536. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11537. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11538. }
  11539. }
  11540. }
  11541. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11542. $sum = 0;
  11543. foreach ( $incomeList as $key => $value ) {
  11544. $sum += $value ['accountPrice'];
  11545. }
  11546. // print_r($incomeList);
  11547. // 获得办事和部门
  11548. $categoryList = $L_category->getCategory ();
  11549. $data ['accountType'] = $accountType;
  11550. $data ['cid'] = $cid;
  11551. $data ['categoryList'] = $categoryList;
  11552. $data ['sum'] = $sum;
  11553. $data ['incomeList'] = $incomeList;
  11554. $data ['inputDate'] = $date;
  11555. $data ['memu'] = "receipt";
  11556. $data ['staff'] = $this->staff;
  11557. $data ['receiptMemu'] = 'wasteBook';
  11558. $data ['verifyId'] = $this->verifyId;
  11559. $data ['executeId'] = $this->executeId;
  11560. $this->render ( "/expenses/wasteBookIncome", $data );
  11561. }
  11562. /**
  11563. * 所有支出
  11564. */
  11565. function wasteBookExpenditure() {
  11566. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11567. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11568. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11569. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  11570. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  11571. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  11572. $data ['receiptType'] = $receiptType;
  11573. Doo::loadModel ( 'wasteBook' );
  11574. $wasteBook = new wasteBook ();
  11575. Doo::loadModel ( 'L_category' );
  11576. $L_category = new L_category ();
  11577. Doo::loadClass ( 'XDeode' );
  11578. $XDeode = new XDeode ( 5 );
  11579. $dateArr = explode ( ':', $date );
  11580. $D1 = '';
  11581. $D2 = '';
  11582. $con = '';
  11583. if (! empty ( $date )) {
  11584. $D1 = $dateArr [0];
  11585. $D2 = $dateArr [1];
  11586. }
  11587. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11588. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11589. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11590. $con = ' and inputDate = "' . $D1 . '"';
  11591. if ($cid != 'ALL') {
  11592. $cid = $XDeode->decode ( $cid );
  11593. $con .= ' and cid = "' . $cid . '"';
  11594. }
  11595. if ($accountType != 'ALL') {
  11596. if ($accountType == 'INVOICE') {
  11597. $con .= ' and accountType = 11';
  11598. } elseif ($accountType == 'PAYMENTS') {
  11599. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  11600. if ($dailyExpenditureType != 'ALL') {
  11601. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  11602. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  11603. }
  11604. } elseif ($accountType == 'RECEIPT') {
  11605. if ($receiptType == 'ALL') {
  11606. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  11607. } else {
  11608. $receiptType = $XDeode->decode ( $receiptType );
  11609. echo $receiptType;
  11610. if ($receiptType == 1) {
  11611. $con .= ' and (accountType = 1 or accountType=2)';
  11612. } else {
  11613. $con .= ' and accountType = ' . $receiptType;
  11614. }
  11615. }
  11616. }
  11617. }
  11618. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  11619. $sum = 0;
  11620. foreach ( $incomeList as $key => $value ) {
  11621. $sum += $value ['accountPriceShow'];
  11622. }
  11623. // print_r($incomeList);
  11624. // 获得办事和部门
  11625. $categoryList = $L_category->getCategory ();
  11626. $data ['accountType'] = $accountType;
  11627. $data ['cid'] = $cid;
  11628. $data ['categoryList'] = $categoryList;
  11629. $data ['sum'] = $sum;
  11630. $data ['incomeList'] = $incomeList;
  11631. $data ['inputDate'] = $date;
  11632. $data ['memu'] = "receipt";
  11633. $data ['staff'] = $this->staff;
  11634. $data ['receiptMemu'] = 'wasteBook';
  11635. $data ['verifyId'] = $this->verifyId;
  11636. $data ['executeId'] = $this->executeId;
  11637. $this->render ( "/expenses/wasteBookExpenditure", $data );
  11638. }
  11639. function ajaxGetWasteinvoiceReceivables() {
  11640. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11641. Doo::loadClass ( 'XDeode' );
  11642. $XDeode = new XDeode ( 5 );
  11643. $irid = $XDeode->decode ( $serial );
  11644. Doo::loadModel ( 'invoiceReceivables' );
  11645. $invoiceReceivables = new invoiceReceivables ();
  11646. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  11647. echo json_encode ( array (
  11648. 'status' => 1,
  11649. 'detail' => $detail
  11650. ) );
  11651. }
  11652. function ajaxGetPaymentsByAid() {
  11653. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11654. Doo::loadModel ( "accountBook" );
  11655. $accountBook = new accountBook ();
  11656. $detail = $accountBook->getAccountBookByAid ( $serial );
  11657. echo json_encode ( array (
  11658. 'status' => 1,
  11659. 'detail' => $detail
  11660. ) );
  11661. }
  11662. function ajaxGetWasteInvoice() {
  11663. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11664. Doo::loadModel ( 'invoice' );
  11665. $invoice = new invoice ();
  11666. Doo::loadModel ( 'invoiceReceivables' );
  11667. $invoiceReceivables = new invoiceReceivables ();
  11668. $detail = $invoice->getInvoiceByIid ( $serial );
  11669. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  11670. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  11671. echo json_encode ( array (
  11672. 'status' => 1,
  11673. 'detail' => $detail
  11674. ) );
  11675. }
  11676. /**
  11677. */
  11678. function ajaxGetWasteReceipt() {
  11679. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  11680. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  11681. Doo::loadModel ( 'receipt' );
  11682. $receipt = new receipt ();
  11683. Doo::loadClass ( 'XDeode' );
  11684. $XDeode = new XDeode ( 5 );
  11685. $rid = $XDeode->decode ( $serial );
  11686. $accountType= $XDeode->decode ( $accountTypeKey );
  11687. // 获得个数据
  11688. $detail = $receipt->getReceiptByRid ( $rid );
  11689. // 初始化
  11690. $detail ['reviseDetail'] = array ();
  11691. if (! empty ( $value ['reviseDetail'] ))
  11692. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  11693. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  11694. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  11695. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  11696. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  11697. // 获得费用html
  11698. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  11699. // 获得费用审批人数据
  11700. $detail = $this->getReceiptApproverHtml ( $detail );
  11701. // 审批执行
  11702. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11703. <th class="taC" width="90">审批人</th>
  11704. <th class="taC">审批意见</th></tr>';
  11705. foreach ( $detail ['verifyList'] as $key => $value ) {
  11706. $html .= '<tr>
  11707. <td>' . $value [1] . '</td>
  11708. <td>' . $value ['opinion'] . '</td>
  11709. </tr>
  11710. ';
  11711. }
  11712. $html .= ' </tbody></table>';
  11713. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  11714. <th class="taC" width="90">执行人</th>
  11715. <th class="taC">执行意见</th></tr>';
  11716. foreach ( $detail ['executeCopy'] as $key => $value ) {
  11717. $html .= '<tr>
  11718. <td>' . $value [1] . '</td>
  11719. <td>' . $value ['opinion'] . '</td>
  11720. </tr>
  11721. ';
  11722. }
  11723. $html .= ' </tbody></table>';
  11724. if($accountType==1){
  11725. Doo::loadModel ( 'loanReceipt' );
  11726. $loanReceipt = new loanReceipt ();
  11727. $loanList = $loanReceipt->getOne ( array (
  11728. 'where' => 'rid=' . $detail ['loanRid'],
  11729. 'desc' => 'rid',
  11730. 'asArray' => true
  11731. ) );
  11732. $html .= '<table class="table table-bordered table-condensed">
  11733. <tr class="warning">
  11734. <td class="taR"><b>汇款金额</b></td>
  11735. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  11736. </tr>
  11737. </table>';
  11738. }else{
  11739. $html .= '<table class="table table-bordered table-condensed">
  11740. <tr class="warning">
  11741. <td class="taR"><b>汇款金额</b></td>
  11742. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  11743. </tr>
  11744. </table>';
  11745. }
  11746. // print_r($detail['verifyList']);
  11747. // header ( 'Content-Type:text/html;charset=utf-8' );
  11748. // echo $html;
  11749. echo json_encode ( array (
  11750. 'status' => 1,
  11751. 'html' => $html,
  11752. 'detail' => $detail
  11753. ) );
  11754. }
  11755. function getReceiptApproverHtml($detail = array()) {
  11756. Doo::loadModel ( 'loanReceipt' );
  11757. $loanReceipt = new loanReceipt ();
  11758. Doo::loadModel ( 'verify' );
  11759. $verify = new verify ();
  11760. Doo::loadModel ( 'staff' );
  11761. $staff = new staff ();
  11762. if (empty ( $detail ))
  11763. return array ();
  11764. $loanList = $loanReceipt->getOne ( array (
  11765. 'where' => 'rid=' . $detail ['loanRid'],
  11766. 'desc' => 'rid',
  11767. 'asArray' => true
  11768. ) );
  11769. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  11770. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  11771. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  11772. else
  11773. $verifyList ['staff'] = $detail ['verifyBreakup'];
  11774. } else
  11775. $verifyList = $verify->getOne ( array (
  11776. 'where' => 'vid=' . $detail ['verify'],
  11777. 'asArray' => true
  11778. ) );
  11779. $verifyList = json_decode ( $verifyList ['staff'], true );
  11780. Doo::loadModel ( 'role' );
  11781. $role = new role ();
  11782. $roleId = 0;
  11783. $flag = true;
  11784. $roleKey = 0;
  11785. $endStaffArray = array ();
  11786. $roleArrayCopy = array ();
  11787. foreach ( $verifyList as $k => $v ) {
  11788. // init verifyStaff
  11789. if ($v [1] == 'ROLE') {
  11790. if (! empty ( $verifyStaff )) {
  11791. $endStaffArray = end ( $verifyStaff );
  11792. }
  11793. $roleVerify = json_decode ( $v [3], true );
  11794. $roleKey = $k;
  11795. $roleArray = array ();
  11796. $rolename = $role->getOne ( array (
  11797. 'where' => 'rid=' . $v [0],
  11798. 'asArray' => true
  11799. ) );
  11800. foreach ( $roleVerify as $o => $p ) {
  11801. $staffID = explode ( '_', $p );
  11802. $staffInfo = $staff->getOne ( array (
  11803. 'where' => 'sid=' . $staffID [0],
  11804. 'asArray' => true
  11805. ) );
  11806. // print_r($staffID);
  11807. $exp = array (
  11808. 0 => $staffInfo ['sid'],
  11809. 1 => $staffID [1],
  11810. 2 => $staffInfo ['avatar'],
  11811. 'date' => '',
  11812. 'date' => '',
  11813. 'opinion' => '',
  11814. 'status' => '',
  11815. 'rolename' => $rolename ['name']
  11816. );
  11817. array_push ( $roleArray, $exp );
  11818. }
  11819. $roleArrayCopy [$v [0]] = $roleArray;
  11820. // $verifyList[$k]['roleArray']=$roleArray;
  11821. }
  11822. $verifyList [$k] ['date'] = "";
  11823. $verifyList [$k] ['opinion'] = "";
  11824. $verifyList [$k] ['status'] = "";
  11825. if (empty ( $verifyStaff )) {
  11826. $verifyList [$k] ['date'] = "";
  11827. $verifyList [$k] ['opinion'] = "";
  11828. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  11829. $verifyList [$k] ['status'] = 4;
  11830. $flag = false;
  11831. }
  11832. } else {
  11833. foreach ( $verifyStaff as $m => $u ) {
  11834. if ($v [0] == $m) {
  11835. $verifyList [$k] ['date'] = $u ['date'];
  11836. $verifyList [$k] ['opinion'] = $u ['opinion'];
  11837. $verifyList [$k] ['status'] = $u ['status'];
  11838. $flag = false;
  11839. break;
  11840. }
  11841. }
  11842. $endStaffArray = end ( $verifyStaff );
  11843. }
  11844. }
  11845. $rolename ['name'] = '';
  11846. if (! empty ( $roleId )) {
  11847. Doo::loadModel ( 'role' );
  11848. $role = new role ();
  11849. $rolename = $role->getOne ( array (
  11850. 'where' => 'rid=' . $roleId,
  11851. 'asArray' => true
  11852. ) );
  11853. }
  11854. if (! empty ( $verifyStaff ))
  11855. $endStaffArray = end ( $verifyStaff );
  11856. $KOP = false;
  11857. foreach ( $roleArrayCopy as $P => $A ) {
  11858. foreach ( $A as $MKI => $AVL ) {
  11859. if (! empty ( $verifyStaff )) {
  11860. // &&$rolename['rid']==$endStaffArray['nextStaff']
  11861. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  11862. $button = 4;
  11863. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11864. }
  11865. foreach ( $verifyStaff as $m => $u ) {
  11866. $AVLFK = $AVL [0] . '_R';
  11867. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  11868. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  11869. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  11870. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  11871. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  11872. break;
  11873. }
  11874. }
  11875. } else {
  11876. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  11877. $button = 4;
  11878. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  11879. }
  11880. }
  11881. // $roleArray[$MKI]['rolename']=$rolename['name'];
  11882. $KOP = true;
  11883. }
  11884. }
  11885. foreach ( $roleArrayCopy as $k => $v ) {
  11886. foreach ( $verifyList as $m => $n ) {
  11887. if ($n [0] == $k) {
  11888. array_splice ( $verifyList, $m, 1, $v );
  11889. }
  11890. }
  11891. }
  11892. // 费用执行人相关数据
  11893. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  11894. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  11895. foreach ( $executeCopy as $k => $v ) {
  11896. $executeCopy [$k] ['date'] = '';
  11897. $executeCopy [$k] ['opinion'] = '';
  11898. $executeCopy [$k] ['status'] = '';
  11899. if (! empty ( $executeStaff ))
  11900. foreach ( $executeStaff as $m => $u ) {
  11901. if ($v [0] == $m) {
  11902. $executeCopy [$k] ['date'] = $u ['date'];
  11903. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  11904. $executeCopy [$k] ['status'] = $u ['status'];
  11905. break;
  11906. }
  11907. }
  11908. }
  11909. $detail ['executeCopy'] = $executeCopy;
  11910. $detail ['verifyList'] = $verifyList;
  11911. return $detail;
  11912. }
  11913. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  11914. if (empty ( $detail ))
  11915. return '';
  11916. $html = '';
  11917. if ($detail ['Rtype'] == 0) { // 报销单
  11918. $html .= '<table class="table table-bordered table-condensed">
  11919. <tbody>
  11920. <tr>
  11921. <th colspan="2" class="taC">日常相关费用</th>
  11922. </tr>';
  11923. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  11924. $html .= '
  11925. <tr>
  11926. <th>' . $value ['name'] . '</th>
  11927. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11928. </tr>';
  11929. }
  11930. $html .= '
  11931. <tr>
  11932. <th class="taR">合计</th>
  11933. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  11934. </tr>';
  11935. $html .= '<tr>
  11936. <th colspan="2" class="taC">差旅相关费用</th>
  11937. </tr>';
  11938. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  11939. $html .= '
  11940. <tr>
  11941. <th>' . $value ['name'] . '</th>
  11942. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11943. </tr>';
  11944. }
  11945. $html .= '
  11946. <tr>
  11947. <th class="taR">合计</th>
  11948. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  11949. </tr>';
  11950. if(isset($detail ['accountItem'] ['内部培训费用'])){
  11951. $html .= '<tr>
  11952. <th colspan="2" class="taC">内部培训费用</th>
  11953. </tr>';
  11954. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  11955. $html .= '
  11956. <tr>
  11957. <th>' . $value ['name'] . '</th>
  11958. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11959. </tr>';
  11960. }
  11961. $html .= '
  11962. <tr>
  11963. <th class="taR">合计</th>
  11964. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  11965. </tr>';
  11966. }
  11967. $html .= '<tr>
  11968. <th colspan="2" class="taC">其他</th>
  11969. </tr>';
  11970. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  11971. $html .= '
  11972. <tr>
  11973. <th>' . $value ['name'] . '</th>
  11974. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11975. </tr>';
  11976. }
  11977. $html .= '
  11978. <tr>
  11979. <th class="taR">合计</th>
  11980. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  11981. </tr>';
  11982. $html .= '<tr>
  11983. <th colspan="2" class="taC">报销金额调整</th>
  11984. </tr>';
  11985. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  11986. $html .= '
  11987. <tr>
  11988. <th>' . $value ['name'] . '</th>
  11989. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  11990. </tr>';
  11991. }
  11992. $html .= '
  11993. <tr>
  11994. <th class="taR">合计</th>
  11995. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  11996. </tr>';
  11997. $html .= '
  11998. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  11999. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12000. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12001. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12002. <tr class="warning">
  12003. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12004. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12005. </tr>
  12006. </tbody>
  12007. </table>';
  12008. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12009. $html .= '
  12010. <table class="table table-bordered table-condensed">
  12011. <tbody>
  12012. <tr>
  12013. <th colspan="2" class="taC">办事处相关费用</th>
  12014. </tr>';
  12015. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12016. $html .= '
  12017. <tr>
  12018. <th>' . $value ['name'] . '</th>
  12019. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12020. </tr>';
  12021. }
  12022. $html .= '
  12023. <tr>
  12024. <th class="taR">合计</th>
  12025. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12026. </tr>';
  12027. $html .= '
  12028. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12029. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12030. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12031. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12032. <tr class="warning">
  12033. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12034. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12035. </tr>
  12036. </tbody>
  12037. </table>';
  12038. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12039. Doo::loadModel ( 'loanReceipt' );
  12040. $loanReceipt = new loanReceipt ();
  12041. $loanList = $loanReceipt->getOne ( array (
  12042. 'where' => 'rid=' . $detail ['loanRid'],
  12043. 'desc' => 'rid',
  12044. 'asArray' => true
  12045. ) );
  12046. // print_r($loanList);
  12047. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12048. $html .= '<table class="table table-bordered table-condensed">
  12049. <tbody>
  12050. <tr>
  12051. <th colspan="2" class="taC">借款费用</th>
  12052. </tr>';
  12053. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12054. $html .= '<tr>
  12055. <th>' . $value ['name'] . '</th>
  12056. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12057. </tr>';
  12058. }
  12059. $html .= '<tr>
  12060. <th class="taC" colspan="2">产生费用所在办事处</th>
  12061. </tr>
  12062. <tr>
  12063. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12064. </tr>
  12065. <tr>
  12066. <th class="taC" colspan="2">费用说明</th>
  12067. </tr>
  12068. <tr>
  12069. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12070. </tr>
  12071. <tr class="warning">
  12072. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12073. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12074. </tr>
  12075. </tbody>
  12076. </table>
  12077. ';
  12078. if ( $accountType==2) {
  12079. $balance=$detail ['sum']-$loanList ['sum'];
  12080. $balanceCN=$this->num_to_rmb($balance);
  12081. $html .= '<table class="table table-bordered table-condensed">
  12082. <tbody>
  12083. <tr>
  12084. <th colspan="2" class="taC">日常相关费用</th>
  12085. </tr>';
  12086. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12087. $html .= '
  12088. <tr>
  12089. <th>' . $value ['name'] . '</th>
  12090. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12091. </tr>';
  12092. }
  12093. $html .= '
  12094. <tr>
  12095. <th class="taR">合计</th>
  12096. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12097. </tr>';
  12098. $html .= '<tr>
  12099. <th colspan="2" class="taC">差旅相关费用</th>
  12100. </tr>';
  12101. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12102. $html .= '
  12103. <tr>
  12104. <th>' . $value ['name'] . '</th>
  12105. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12106. </tr>';
  12107. }
  12108. $html .= '
  12109. <tr>
  12110. <th class="taR">合计</th>
  12111. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12112. </tr>';
  12113. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12114. $html .= '<tr>
  12115. <th colspan="2" class="taC">内部培训费用</th>
  12116. </tr>';
  12117. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12118. $html .= '
  12119. <tr>
  12120. <th>' . $value ['name'] . '</th>
  12121. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12122. </tr>';
  12123. }
  12124. $html .= '
  12125. <tr>
  12126. <th class="taR">合计</th>
  12127. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12128. </tr>';
  12129. }
  12130. $html .= '<tr>
  12131. <th colspan="2" class="taC">其他</th>
  12132. </tr>';
  12133. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12134. $html .= '
  12135. <tr>
  12136. <th>' . $value ['name'] . '</th>
  12137. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12138. </tr>';
  12139. }
  12140. $html .= '
  12141. <tr>
  12142. <th class="taR">合计</th>
  12143. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12144. </tr>';
  12145. $html .= '<tr>
  12146. <th colspan="2" class="taC">报销金额调整</th>
  12147. </tr>';
  12148. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12149. $html .= '
  12150. <tr>
  12151. <th>' . $value ['name'] . '</th>
  12152. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12153. </tr>';
  12154. }
  12155. $html .= '
  12156. <tr>
  12157. <th class="taR">合计</th>
  12158. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12159. </tr>';
  12160. $html .= '
  12161. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12162. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12163. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12164. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12165. <tr class="warning">
  12166. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12167. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12168. </tr>
  12169. <tr class="success">
  12170. <td class="taR"><b>借款结余</b></td>
  12171. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12172. </tr>
  12173. </tbody>
  12174. </table>';
  12175. }
  12176. }
  12177. return $html;
  12178. }
  12179. /**
  12180. * 计算流水
  12181. */
  12182. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12183. $bakWaste ['bank'] = array (
  12184. 'CGBDeposit' => 0,
  12185. 'ICBCDeposit' => 0,
  12186. 'HUADeposit' => 0,
  12187. 'PersonalDeposit' => 0
  12188. );
  12189. $bakWaste ['financial'] = array (
  12190. 'current' => array (
  12191. 'CGBDeposit' => 0,
  12192. 'ICBCDeposit' => 0
  12193. ),
  12194. 'fixed' => array (
  12195. 'CGBDeposit' => 0,
  12196. 'ICBCDeposit' => 0
  12197. )
  12198. );
  12199. // 存款
  12200. foreach ( $waste ['bank'] as $key => $value ) {
  12201. // 收入
  12202. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12203. // 广发
  12204. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12205. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12206. }
  12207. // 工商
  12208. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12209. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12210. }
  12211. // 华润
  12212. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12213. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12214. }
  12215. // 个人
  12216. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12217. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12218. }
  12219. }
  12220. }
  12221. foreach ( $waste ['bank'] as $key => $value ) {
  12222. // 支出
  12223. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12224. // 广发
  12225. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12226. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12227. }
  12228. // 工商
  12229. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12230. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12231. }
  12232. // 华润
  12233. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12234. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12235. }
  12236. // 个人
  12237. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12238. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12239. }
  12240. }
  12241. }
  12242. // 活期
  12243. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12244. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12245. // 广发
  12246. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12247. $waste ['financial'] ['current'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12248. }
  12249. // 工商
  12250. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12251. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12252. }
  12253. // 个人
  12254. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12255. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12256. }
  12257. }
  12258. }
  12259. // print_r($inComeStatistics ['fixedStatistics']);
  12260. // 固期
  12261. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12262. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12263. // 广发
  12264. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12265. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value ['CGBDeposit'] + $v ['accountPrice'];
  12266. }
  12267. // 工商
  12268. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12269. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value ['ICBCDeposit'] + $v ['accountPrice'];
  12270. }
  12271. // 个人
  12272. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12273. $waste ['bank'] ['PersonalDeposit'] = $value ['PersonalDeposit'] + $v ['accountPrice'];
  12274. }
  12275. }
  12276. }
  12277. return $waste;
  12278. }
  12279. function lyt() {
  12280. Doo::loadModel ( "receiptDetail" );
  12281. $receiptDetail = new receiptDetail ();
  12282. $receiptCollectList = $receiptDetail->find ( array (
  12283. 'where' => 'status=1 ',
  12284. 'asArray' => true
  12285. ) );
  12286. foreach ( $receiptCollectList as $key => $value ) {
  12287. $receiptDetail = new receiptDetail ();
  12288. $receiptDetail->pastDate = $value ['date'];
  12289. $receiptDetail->update ( array (
  12290. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12291. ) );
  12292. }
  12293. }
  12294. function staffCollectMonthDetail() {
  12295. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12296. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12297. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12298. if (! $year)
  12299. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12300. if (! $month)
  12301. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12302. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12303. if (! $nature){
  12304. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12305. }
  12306. Doo::loadModel ( 'staff' );
  12307. $staff = new staff ();
  12308. Doo::loadModel ( "receiptDetail" );
  12309. $receiptDetail = new receiptDetail ();
  12310. Doo::loadModel ( 'accountItem' );
  12311. $accountItem = new accountItem ();
  12312. Doo::loadModel ( 'statistics' );
  12313. $statistics = new statistics ();
  12314. Doo::loadModel ( "receiptAuthorityManage" );
  12315. $receiptAuthorityManage = new receiptAuthorityManage ();
  12316. $aiList=$accountItem->getAccountItem();
  12317. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12318. $cidList = array ();
  12319. foreach ( $imcStaff as $key => $value ) {
  12320. array_push ( $cidList, $value ['cid'] );
  12321. }
  12322. $cidString = implode ( ',', $cidList );
  12323. $naturecon='';
  12324. if ($nature=='ONJOB'){
  12325. $naturecon=' and (nature!=4 )';
  12326. }elseif($nature=='LEAVEJOB'){
  12327. $naturecon=' and (nature=4 )';
  12328. }else{
  12329. die ( 'illegal request--nature' );
  12330. }
  12331. $staffList = $staff->find ( array (
  12332. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12333. 'asArray' => true
  12334. ) );
  12335. $categoryList = $staff->find ( array (
  12336. 'select' => 'COUNT(*) as count,cid,category',
  12337. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12338. 'groupby' => 'cid',
  12339. 'asArray' => true
  12340. ) );
  12341. $list = array ();
  12342. foreach($aiList as $key=>$value){
  12343. foreach ($value as $v){
  12344. $subtotal[$key][$v['name']]=0;
  12345. }
  12346. }
  12347. foreach ( $categoryList as $vlu ) {
  12348. $s1 = 0;
  12349. $m1 = 0;
  12350. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12351. foreach ( $staffList as $value ) {
  12352. if ($vlu ['cid'] == $value ['cid']) {
  12353. // pastDate
  12354. $receiptCollectList = $receiptDetail->find ( array (
  12355. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12356. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12357. 'groupby' => 'item,Month(pastDate),itemCategory',
  12358. 'asArray' => true
  12359. ) );
  12360. if (! empty ( $receiptCollectList )) {
  12361. $receiptL = array (
  12362. '日常相关费用' => array (),
  12363. '差旅相关费用' => array (),
  12364. '内部培训费用' => array (),
  12365. '培训班费用' => array (),
  12366. '其他' => array ()
  12367. );
  12368. $html = "";
  12369. $psum = 0;
  12370. foreach ( $aiList[$this->AGENCY] as $va ) {
  12371. $falg = true;
  12372. foreach ( $receiptCollectList as $v ) {
  12373. if ($v ['itemCategory'] == '日常相关费用') {
  12374. if ($v ['item'] == $va['name']) {
  12375. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12376. $psum += $v ['price'];
  12377. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12378. $falg = false;
  12379. break;
  12380. }
  12381. }
  12382. }
  12383. if ($falg)
  12384. $html .= '<td class="taR">-</td>';
  12385. }
  12386. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12387. if (! empty ( $psum ))
  12388. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12389. else
  12390. $psum = '<td class="colGreen taR">-</td>';
  12391. $receiptL ['日常相关费用'] = $psum . $html;
  12392. /* ----------------------------------- */
  12393. $html = "";
  12394. $psum = 0;
  12395. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12396. $falg = true;
  12397. foreach ( $receiptCollectList as $v ) {
  12398. if ($v ['itemCategory'] == '差旅相关费用') {
  12399. if ($v ['item'] == $va['name']) {
  12400. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12401. $psum += $v ['price'];
  12402. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12403. $falg = false;
  12404. break;
  12405. }
  12406. }
  12407. }
  12408. if ($falg)
  12409. $html .= '<td class="taR">-</td>';
  12410. }
  12411. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12412. if (! empty ( $psum ))
  12413. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12414. else
  12415. $psum = '<td class="colGreen taR">-</td>';
  12416. $receiptL ['差旅相关费用'] = $psum . $html;
  12417. /* ------------------------------------- */
  12418. $html = "";
  12419. $psum = 0;
  12420. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12421. $falg = true;
  12422. foreach ( $receiptCollectList as $v ) {
  12423. if ($v ['itemCategory'] == '内部培训费用') {
  12424. if ($v ['item'] == $va['name']) {
  12425. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12426. $psum += $v ['price'];
  12427. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12428. $falg = false;
  12429. break;
  12430. }
  12431. }
  12432. }
  12433. if ($falg)
  12434. $html .= '<td class="taR">-</td>';
  12435. }
  12436. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12437. if (! empty ( $psum ))
  12438. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12439. else
  12440. $psum = '<td class="colGreen taR">-</td>';
  12441. $receiptL ['内部培训费用'] = $psum . $html;
  12442. /* ----------------------------------- */
  12443. $html = "";
  12444. $psum = 0;
  12445. foreach ( $aiList[$this->TRAIN] as $va ) {
  12446. $falg = true;
  12447. foreach ( $receiptCollectList as $v ) {
  12448. if ($v ['itemCategory'] == '培训班费用') {
  12449. if ($v ['item'] == $va['name']) {
  12450. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12451. $psum += $v ['price'];
  12452. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12453. $falg = false;
  12454. break;
  12455. }
  12456. }
  12457. }
  12458. if ($falg)
  12459. $html .= '<td class="taR">-</td>';
  12460. }
  12461. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12462. if (! empty ( $psum ))
  12463. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12464. else
  12465. $psum = '<td class="colGreen taR">-</td>';
  12466. $receiptL ['培训班费用'] = $psum . $html;
  12467. /* ------------------------------------- */
  12468. $html = "";
  12469. $psum = 0;
  12470. foreach ( $aiList[$this->OTHER] as $va ) {
  12471. $falg = true;
  12472. foreach ( $receiptCollectList as $v ) {
  12473. if ($v ['itemCategory'] == '其他') {
  12474. if (trim ( $v ['item'] ) == $va['name']) {
  12475. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12476. $psum += $v ['price'];
  12477. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12478. $falg = false;
  12479. break;
  12480. }
  12481. }
  12482. }
  12483. if ($falg)
  12484. $html .= '<td class="taR">-</td>';
  12485. }
  12486. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12487. if (! empty ( $psum ))
  12488. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12489. else
  12490. $psum = '<td class="colGreen taR">-</td>';
  12491. $receiptL ['其他'] = $psum . $html;
  12492. /* ------------------------------------- */
  12493. $html = "";
  12494. $psum = 0;
  12495. foreach ( $receiptCollectList as $v ) {
  12496. if ($v ['itemCategory'] == '报销金额调整') {
  12497. if (! empty ( $v ['price'] )) {
  12498. $psum += $v ['price'];
  12499. }
  12500. }
  12501. }
  12502. $s1 += $psum;
  12503. if (! empty ( $psum ))
  12504. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12505. else
  12506. $psum = '<td class="taR colOrange">-</td>';
  12507. $receiptL ['报销金额调整'] = $psum . $html;
  12508. } else {
  12509. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12510. foreach ( $aiList[$this->AGENCY] as $va ) {
  12511. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12512. }
  12513. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12514. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12515. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12516. }
  12517. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12518. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12519. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12520. }
  12521. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12522. foreach ( $aiList[$this->TRAIN] as $va ) {
  12523. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12524. }
  12525. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12526. foreach ( $aiList[$this->OTHER] as $va ) {
  12527. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12528. }
  12529. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12530. }
  12531. $monthStaffPrice = $receiptDetail->find ( array (
  12532. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12533. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12534. 'groupby' => 'Month(pastDate)',
  12535. 'asArray' => true
  12536. ) );
  12537. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12538. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12539. $m1 += $monthStaffPrice [0] ['price'];
  12540. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12541. } else
  12542. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12543. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12544. $list [$value ['username']] = $receiptL;
  12545. }
  12546. }
  12547. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  12548. foreach ( $aiList[$this->AGENCY] as $va ) {
  12549. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  12550. $subtotal[$this->AGENCY][$va['name']]=0;
  12551. }
  12552. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  12553. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12554. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  12555. $subtotal[$this->TRAVEL][$va['name']]=0;
  12556. }
  12557. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  12558. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12559. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  12560. $subtotal[$this->INTTRAIN][$va['name']]=0;
  12561. }
  12562. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  12563. foreach ( $aiList[$this->TRAIN] as $va ) {
  12564. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  12565. $subtotal[$this->TRAIN][$va['name']]=0;
  12566. }
  12567. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  12568. foreach ( $aiList[$this->OTHER] as $va ) {
  12569. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  12570. $subtotal[$this->OTHER][$va['name']]=0;
  12571. }
  12572. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12573. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12574. $receiptL ['usernameEn'] =false;
  12575. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12576. }
  12577. $data ['list'] = $list;
  12578. // print_r($list);
  12579. $receiptCollectList = $receiptDetail->find ( array (
  12580. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12581. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12582. 'groupby' => 'item,Month(pastDate),itemCategory',
  12583. 'asArray' => true
  12584. ) );
  12585. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  12586. // statistics html
  12587. $stList = $statistics->getOne ( array (
  12588. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12589. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12590. 'groupby' => 'Month(date)',
  12591. 'asArray' => true
  12592. ) );
  12593. if (empty ( $stList ))
  12594. $stList = array (
  12595. 'rePrice' => 0,
  12596. 'agPrice' => 0
  12597. );
  12598. $data ['stList'] = array (
  12599. 'rePrice' => $stList ['rePrice'],
  12600. 'agPrice' => $stList ['agPrice'],
  12601. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12602. );
  12603. $monthHtml = "";
  12604. for($i = 1; $i <= 12; $i ++) {
  12605. if ($i == $month)
  12606. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12607. else
  12608. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12609. }
  12610. $data ['monthHtml'] = $monthHtml;
  12611. $data ['year'] = $year;
  12612. $data ['month'] = $month;
  12613. $data ['nature'] = $nature;
  12614. $data ['aiList'] = $aiList;
  12615. $data ['memu'] = "receipt";
  12616. $data ['staff'] = $this->staff;
  12617. $data ['receiptMemu'] = 'companyCategoryCollect';
  12618. $data ['verifyId'] = $this->verifyId;
  12619. $data ['executeId'] = $this->executeId;
  12620. $this->render ( "/admin/staffCollectMonthDetail", $data );
  12621. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12622. }
  12623. function staffCollectMonthDetail2() {
  12624. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12625. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12626. if (! $year)
  12627. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12628. if (! $month)
  12629. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12630. Doo::loadModel ( 'staff' );
  12631. $staff = new staff ();
  12632. Doo::loadModel ( "receiptDetail" );
  12633. $receiptDetail = new receiptDetail ();
  12634. Doo::loadModel ( 'accountItem' );
  12635. $accountItem = new accountItem ();
  12636. Doo::loadModel ( 'statistics' );
  12637. $statistics = new statistics ();
  12638. Doo::loadModel ( 'L_category' );
  12639. $lCategory = new L_category ();
  12640. $staffList = $staff->find ( array (
  12641. 'where' => 'username!="admin"',
  12642. 'asArray' => true
  12643. ) );
  12644. $categoryList = $staff->find ( array (
  12645. 'select' => 'COUNT(*) as count,cid,category',
  12646. 'where' => 'username !="admin"',
  12647. 'groupby' => 'cid',
  12648. 'asArray' => true
  12649. ) );
  12650. $list = array ();
  12651. foreach ( $categoryList as $vlu ) {
  12652. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  12653. $r1 = 0;
  12654. $r2 = 0;
  12655. $r3 = 0;
  12656. $r4 = 0;
  12657. $r5 = 0;
  12658. $r6 = 0;
  12659. $r7 = 0;
  12660. $r8 = 0;
  12661. $r9 = 0;
  12662. $r10 = 0;
  12663. $r11 = 0;
  12664. $r12 = 0;
  12665. $r13 = 0;
  12666. $r14 = 0;
  12667. $r15 = 0;
  12668. $c1 = 0;
  12669. $c2 = 0;
  12670. $c3 = 0;
  12671. $c4 = 0;
  12672. $c5 = 0;
  12673. $c6 = 0;
  12674. $p1 = 0;
  12675. $p2 = 0;
  12676. $p3 = 0;
  12677. $p4 = 0;
  12678. $p5 = 0;
  12679. $p6 = 0;
  12680. $p7 = 0;
  12681. $p8 = 0;
  12682. $p9 = 0;
  12683. $t1 = 0;
  12684. $t2 = 0;
  12685. $t3 = 0;
  12686. $t4 = 0;
  12687. $t5 = 0;
  12688. $s1 = 0;
  12689. $m1 = 0;
  12690. foreach ( $staffList as $value ) {
  12691. if ($vlu ['cid'] == $value ['cid']) {
  12692. $receiptCollectList = $receiptDetail->find ( array (
  12693. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12694. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12695. 'groupby' => 'item,Month(date),itemCategory',
  12696. 'asArray' => true
  12697. ) );
  12698. if (! empty ( $receiptCollectList )) {
  12699. $receiptL = array (
  12700. '日常相关费用' => array (),
  12701. '差旅相关费用' => array (),
  12702. '培训班费用' => array (),
  12703. '其他' => array ()
  12704. );
  12705. $html = "";
  12706. $psum = 0;
  12707. $item = array (
  12708. '市内交通费',
  12709. '市内出租费',
  12710. '办事处房租',
  12711. '电话费',
  12712. '水费',
  12713. '电费',
  12714. '办公费用',
  12715. '邮寄费',
  12716. '其他费用',
  12717. '车辆费用',
  12718. '广告费',
  12719. '团队建设费',
  12720. '物业管理费',
  12721. '宽带费'
  12722. );
  12723. foreach ( $item as $va ) {
  12724. $falg = true;
  12725. foreach ( $receiptCollectList as $v ) {
  12726. if ($v ['itemCategory'] == '日常相关费用') {
  12727. if ($v ['item'] == $va) {
  12728. if ($va == '市内交通费')
  12729. $r1 += $v ['price'];
  12730. if ($va == '市内出租费')
  12731. $r2 += $v ['price'];
  12732. if ($va == '办事处房租')
  12733. $r3 += $v ['price'];
  12734. if ($va == '电话费')
  12735. $r4 += $v ['price'];
  12736. if ($va == '水费')
  12737. $r5 += $v ['price'];
  12738. if ($va == '电费')
  12739. $r6 += $v ['price'];
  12740. if ($va == '办公费用')
  12741. $r7 += $v ['price'];
  12742. if ($va == '邮寄费')
  12743. $r8 += $v ['price'];
  12744. if ($va == '其他费用')
  12745. $r9 += $v ['price'];
  12746. if ($va == '车辆费用')
  12747. $r10 += $v ['price'];
  12748. if ($va == '广告费')
  12749. $r11 += $v ['price'];
  12750. if ($va == '团队建设费')
  12751. $r13 += $v ['price'];
  12752. if ($va == '物业管理费')
  12753. $r14 += $v ['price'];
  12754. if ($va == '宽带费')
  12755. $r15 += $v ['price'];
  12756. $psum += $v ['price'];
  12757. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12758. $falg = false;
  12759. break;
  12760. }
  12761. }
  12762. }
  12763. if ($falg)
  12764. $html .= '<td class="taR">-</td>';
  12765. }
  12766. $r12 += $psum;
  12767. if (! empty ( $psum ))
  12768. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12769. else
  12770. $psum = '<td class="colGreen taR">-</td>';
  12771. $receiptL ['日常相关费用'] = $psum . $html;
  12772. /* ----------------------------------- */
  12773. $html = "";
  12774. $psum = 0;
  12775. $item = array (
  12776. '往来交通费',
  12777. '市内交通费',
  12778. '出差住宿费',
  12779. '出差补助',
  12780. '其他费用'
  12781. );
  12782. foreach ( $item as $va ) {
  12783. $falg = true;
  12784. foreach ( $receiptCollectList as $v ) {
  12785. if ($v ['itemCategory'] == '差旅相关费用') {
  12786. if ($v ['item'] == $va) {
  12787. if ($va == '往来交通费')
  12788. $c1 += $v ['price'];
  12789. if ($va == '市内交通费')
  12790. $c2 += $v ['price'];
  12791. if ($va == '出差住宿费')
  12792. $c3 += $v ['price'];
  12793. if ($va == '出差补助')
  12794. $c4 += $v ['price'];
  12795. if ($va == '其他费用')
  12796. $c5 += $v ['price'];
  12797. $psum += $v ['price'];
  12798. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12799. $falg = false;
  12800. break;
  12801. }
  12802. }
  12803. }
  12804. if ($falg)
  12805. $html .= '<td class="taR">-</td>';
  12806. }
  12807. $c6 += $psum;
  12808. if (! empty ( $psum ))
  12809. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12810. else
  12811. $psum = '<td class="colGreen taR">-</td>';
  12812. $receiptL ['差旅相关费用'] = $psum . $html;
  12813. /* ------------------------------------- */
  12814. $html = "";
  12815. $psum = 0;
  12816. $item = array (
  12817. '场租费',
  12818. '薪酬',
  12819. '住宿费',
  12820. '交通费',
  12821. '餐饮费',
  12822. '办公费',
  12823. '公关费',
  12824. '其他'
  12825. );
  12826. foreach ( $item as $va ) {
  12827. $falg = true;
  12828. foreach ( $receiptCollectList as $v ) {
  12829. if ($v ['itemCategory'] == '培训班费用') {
  12830. if ($v ['item'] == $va) {
  12831. if ($va == '场租费')
  12832. $p1 += $v ['price'];
  12833. if ($va == '薪酬')
  12834. $p2 += $v ['price'];
  12835. if ($va == '住宿费')
  12836. $p3 += $v ['price'];
  12837. if ($va == '交通费')
  12838. $p4 += $v ['price'];
  12839. if ($va == '餐饮费')
  12840. $p5 += $v ['price'];
  12841. if ($va == '办公费')
  12842. $p6 += $v ['price'];
  12843. if ($va == '公关费')
  12844. $p7 += $v ['price'];
  12845. if ($va == '其他')
  12846. $p8 += $v ['price'];
  12847. $psum += $v ['price'];
  12848. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12849. $falg = false;
  12850. break;
  12851. }
  12852. }
  12853. }
  12854. if ($falg)
  12855. $html .= '<td class="taR">-</td>';
  12856. }
  12857. $p9 += $psum;
  12858. if (! empty ( $psum ))
  12859. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12860. else
  12861. $psum = '<td class="colGreen taR">-</td>';
  12862. $receiptL ['培训班费用'] = $psum . $html;
  12863. /* ------------------------------------- */
  12864. $html = "";
  12865. $psum = 0;
  12866. $item = array (
  12867. '公关费',
  12868. '广告费',
  12869. '借款',
  12870. '可自加费用'
  12871. );
  12872. foreach ( $item as $va ) {
  12873. $falg = true;
  12874. foreach ( $receiptCollectList as $v ) {
  12875. if ($v ['itemCategory'] == '其他') {
  12876. if ($v ['item'] == $va) {
  12877. if ($va == '公关费')
  12878. $t1 += $v ['price'];
  12879. if ($va == '广告费')
  12880. $t2 += $v ['price'];
  12881. if ($va == '借款')
  12882. $t3 += $v ['price'];
  12883. if ($va == '可自加费用')
  12884. $t4 += $v ['price'];
  12885. $psum += $v ['price'];
  12886. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12887. $falg = false;
  12888. break;
  12889. }
  12890. }
  12891. }
  12892. if ($falg)
  12893. $html .= '<td class="taR">-</td>';
  12894. }
  12895. $t5 += $psum;
  12896. if (! empty ( $psum ))
  12897. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12898. else
  12899. $psum = '<td class="colGreen taR">-</td>';
  12900. $receiptL ['其他'] = $psum . $html;
  12901. /* ------------------------------------- */
  12902. $html = "";
  12903. $psum = 0;
  12904. foreach ( $receiptCollectList as $v ) {
  12905. if ($v ['itemCategory'] == '报销金额调整') {
  12906. if (! empty ( $v ['price'] )) {
  12907. $psum += $v ['price'];
  12908. }
  12909. }
  12910. }
  12911. $s1 += $psum;
  12912. if (! empty ( $psum ))
  12913. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12914. else
  12915. $psum = '<td class="taR colOrange">-</td>';
  12916. $receiptL ['报销金额调整'] = $psum . $html;
  12917. } else {
  12918. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12919. <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>';
  12920. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  12921. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12922. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  12923. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12924. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  12925. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12926. }
  12927. $monthStaffPrice = $receiptDetail->find ( array (
  12928. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12929. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12930. 'asArray' => true
  12931. ) );
  12932. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12933. $m1 += $monthStaffPrice [0] ['price'];
  12934. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12935. } else
  12936. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12937. $list [$value ['username']] = $receiptL;
  12938. }
  12939. }
  12940. $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>
  12941. <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>
  12942. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  12943. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  12944. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  12945. $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>
  12946. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  12947. $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>';
  12948. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  12949. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  12950. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  12951. }
  12952. $data ['list'] = $list;
  12953. $receiptCollectList = $receiptDetail->find ( array (
  12954. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  12955. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  12956. 'groupby' => 'item,Month(date),itemCategory',
  12957. 'asArray' => true
  12958. ) );
  12959. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  12960. // statistics html
  12961. $stList = $statistics->getOne ( array (
  12962. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  12963. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  12964. 'groupby' => 'Month(date)',
  12965. 'asArray' => true
  12966. ) );
  12967. if (empty ( $stList ))
  12968. $stList = array (
  12969. 'rePrice' => 0,
  12970. 'agPrice' => 0
  12971. );
  12972. $data ['stList'] = array (
  12973. 'rePrice' => $stList ['rePrice'],
  12974. 'agPrice' => $stList ['agPrice'],
  12975. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  12976. );
  12977. $monthHtml = "";
  12978. for($i = 1; $i <= 12; $i ++) {
  12979. if ($i == $month)
  12980. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  12981. else
  12982. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  12983. }
  12984. $data ['monthHtml'] = $monthHtml;
  12985. $data ['year'] = $year;
  12986. $data ['month'] = $month;
  12987. $data ['memu'] = "receipt";
  12988. $data ['staff'] = $this->staff;
  12989. $data ['receiptMemu'] = 'companyCategoryCollect';
  12990. $data ['verifyId'] = $this->verifyId;
  12991. $data ['executeId'] = $this->executeId;
  12992. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  12993. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  12994. }
  12995. /**
  12996. * 用户报销单列表
  12997. */
  12998. function receiptStatisticsStaffDetail() {
  12999. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13000. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13001. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13002. Doo::loadModel ( "receipt" );
  13003. $receipt = new receipt ();
  13004. Doo::loadModel ( "receiptDetail" );
  13005. $receiptDetail = new receiptDetail ();
  13006. Doo::loadModel ( 'staff' );
  13007. $staff = new staff ();
  13008. Doo::loadModel ( 'accountItem' );
  13009. $accountItem = new accountItem ();
  13010. Doo::loadModel ( 'statistics' );
  13011. $statistics = new statistics ();
  13012. if (! empty ( $username )) {
  13013. $username = addslashes ( urldecode ( $username ) );
  13014. $staffDetail = $staff->getStaffByName ( $username );
  13015. if (empty ( $staffDetail ))
  13016. die ( 'illegal request' );
  13017. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13018. $itemList = $accountItem->getAccountItem ();
  13019. $itemHtml = '';
  13020. $categoryHtml = '';
  13021. $itemKeyList = array_keys ( $itemList );
  13022. $revisePrice = 0;
  13023. // 报销单内容详情
  13024. foreach ( $list as $key => $value ) {
  13025. $accountItemList = json_decode ( $value ['accountItem'], true );
  13026. $list [$key] ['accountItemList'] = $accountItemList;
  13027. $receiptItemHtml = '';
  13028. foreach ( $itemKeyList as $v ) {
  13029. if ($v == '日常相关费用')
  13030. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13031. elseif ($v == '差旅相关费用')
  13032. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13033. elseif ($v == '培训班费用')
  13034. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13035. elseif ($v == '内部培训费用'){
  13036. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13037. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13038. }else{
  13039. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13040. }
  13041. }elseif ($v == '其他')
  13042. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13043. foreach ( $itemList [$v] as $ke => $va ) {
  13044. $falg = true;
  13045. if (! empty ( $accountItemList [$v] )) {
  13046. foreach ( $accountItemList [$v] as $ve ) {
  13047. if ($va ['name'] == $ve ['name']) {
  13048. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13049. $falg = false;
  13050. break;
  13051. }
  13052. }
  13053. }
  13054. if ($falg)
  13055. $receiptItemHtml .= '<td class="taR"></td>';
  13056. }
  13057. }
  13058. // 金额调整和费用查看
  13059. $revisePrice += $value ['revisePrice'];
  13060. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13061. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13062. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13063. }
  13064. // 报销单合计
  13065. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13066. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13067. $receiptTotalHtml = '';
  13068. // 报销单项目抬头
  13069. foreach ( $itemKeyList as $value ) {
  13070. $count = count ( $itemList [$value] ) + 1;
  13071. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13072. $categoryHtml .= '<th class="taC">合计</th>';
  13073. $sumfalg=true;
  13074. foreach ( $rtl as $rtlValue ) {
  13075. if ($rtlValue ['itemCategory'] == $value) {
  13076. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13077. $sumfalg=false;
  13078. break;
  13079. }
  13080. }
  13081. if ($sumfalg)
  13082. $receiptTotalHtml .= '<th></th>';
  13083. foreach ( $itemList [$value] as $k => $v ) {
  13084. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13085. // 合计
  13086. $falg = true;
  13087. foreach ( $receiptTotalList as $ve ) {
  13088. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13089. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13090. $falg = false;
  13091. break;
  13092. }
  13093. }
  13094. if ($falg)
  13095. $receiptTotalHtml .= '<th></th>';
  13096. }
  13097. }
  13098. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13099. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13100. if (empty ( $stList ))
  13101. $stList = array (
  13102. 'rePrice' => 0,
  13103. 'agPrice' => 0
  13104. );
  13105. $data ['stList'] = array (
  13106. 'rePrice' => $stList ['rePrice'],
  13107. 'agPrice' => $stList ['agPrice'],
  13108. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13109. );
  13110. $monthHtml = "";
  13111. for($i = 1; $i <= 12; $i ++) {
  13112. if ($i == $month)
  13113. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13114. else
  13115. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13116. }
  13117. $data ['username'] = urlencode ( $username );
  13118. $data ['usernameEN'] = $username;
  13119. $data ['monthHtml'] = $monthHtml;
  13120. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13121. $data ['list'] = $list;
  13122. $data ['categoryHtml'] = $categoryHtml;
  13123. $data ['itemHtml'] = $itemHtml;
  13124. $data ['itemList'] = $itemList;
  13125. $data ['year'] = $year;
  13126. $data ['month'] = $month;
  13127. $data ['memu'] = "receipt";
  13128. $data ['staff'] = $this->staff;
  13129. $data ['receiptMemu'] = 'companyCategoryCollect';
  13130. $data ['verifyId'] = $this->verifyId;
  13131. $data ['executeId'] = $this->executeId;
  13132. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13133. }
  13134. die ( 'illegal request' );
  13135. }
  13136. function companyMonthCollectDetail() {
  13137. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13138. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13139. if (! $year)
  13140. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13141. if (! $month)
  13142. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13143. Doo::loadModel ( 'staff' );
  13144. $staff = new staff ();
  13145. Doo::loadModel ( "receiptDetail" );
  13146. $receiptDetail = new receiptDetail ();
  13147. Doo::loadModel ( 'accountItem' );
  13148. $accountItem = new accountItem ();
  13149. Doo::loadModel ( 'statistics' );
  13150. $statistics = new statistics ();
  13151. Doo::loadModel ( 'L_category' );
  13152. $lCategory = new L_category ();
  13153. $staffList = $staff->find ( array (
  13154. 'where' => 'username!="admin"',
  13155. 'asArray' => true
  13156. ) );
  13157. $categoryList = $lCategory->find ( array (
  13158. 'asArray' => true
  13159. ) );
  13160. $aiList=$accountItem->getAccountItem();
  13161. $list = array ();
  13162. foreach ( $categoryList as $value ) {
  13163. $receiptCollectList = $receiptDetail->find ( array (
  13164. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13165. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13166. 'groupby' => 'item,Month(pastDate),itemCategory',
  13167. 'asArray' => true
  13168. ) );
  13169. if (! empty ( $receiptCollectList )) {
  13170. $receiptL = array (
  13171. '日常相关费用' => array (),
  13172. '差旅相关费用' => array (),
  13173. '内部培训费用' => array (),
  13174. '培训班费用' => array (),
  13175. '其他' => array ()
  13176. );
  13177. $html = "";
  13178. $psum = 0;
  13179. foreach ( $aiList[$this->AGENCY] as $va ) {
  13180. $falg = true;
  13181. foreach ( $receiptCollectList as $v ) {
  13182. if ($v ['itemCategory'] == $this->AGENCY) {
  13183. if ($v ['item'] == $va['name']) {
  13184. $psum += $v ['price'];
  13185. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13186. $falg = false;
  13187. break;
  13188. }
  13189. }
  13190. }
  13191. if ($falg)
  13192. $html .= '<td class="taR">-</td>';
  13193. }
  13194. if (! empty ( $psum ))
  13195. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13196. else
  13197. $psum = '<td class="colGreen taR">-</td>';
  13198. $receiptL [$this->AGENCY] = $psum . $html;
  13199. /* ----------------------------------- */
  13200. $html = "";
  13201. $psum = 0;
  13202. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13203. $falg = true;
  13204. foreach ( $receiptCollectList as $v ) {
  13205. if ($v ['itemCategory'] == $this->TRAVEL) {
  13206. if ($v ['item'] == $va['name']) {
  13207. $psum += $v ['price'];
  13208. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13209. $falg = false;
  13210. break;
  13211. }
  13212. }
  13213. }
  13214. if ($falg)
  13215. $html .= '<td class="taR">-</td>';
  13216. }
  13217. if (! empty ( $psum ))
  13218. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13219. else
  13220. $psum = '<td class="colGreen taR">-</td>';
  13221. $receiptL [$this->TRAVEL] = $psum . $html;
  13222. /* ------------------------------------- */
  13223. $html = "";
  13224. $psum = 0;
  13225. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13226. $falg = true;
  13227. foreach ( $receiptCollectList as $v ) {
  13228. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13229. if ($v ['item'] == $va['name']) {
  13230. $psum += $v ['price'];
  13231. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13232. $falg = false;
  13233. break;
  13234. }
  13235. }
  13236. }
  13237. if ($falg)
  13238. $html .= '<td class="taR">-</td>';
  13239. }
  13240. if (! empty ( $psum ))
  13241. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13242. else
  13243. $psum = '<td class="colGreen taR">-</td>';
  13244. $receiptL [$this->INTTRAIN] = $psum . $html;
  13245. /* ------------------------------------- */
  13246. $html = "";
  13247. $psum = 0;
  13248. foreach ( $aiList[$this->TRAIN] as $va ) {
  13249. $falg = true;
  13250. foreach ( $receiptCollectList as $v ) {
  13251. if ($v ['itemCategory'] == $this->TRAIN) {
  13252. if ($v ['item'] == $va['name']) {
  13253. $psum += $v ['price'];
  13254. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13255. $falg = false;
  13256. break;
  13257. }
  13258. }
  13259. }
  13260. if ($falg)
  13261. $html .= '<td class="taR">-</td>';
  13262. }
  13263. if (! empty ( $psum ))
  13264. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13265. else
  13266. $psum = '<td class="colGreen taR">-</td>';
  13267. $receiptL [$this->TRAIN] = $psum . $html;
  13268. /* ------------------------------------- */
  13269. $html = "";
  13270. $psum = 0;
  13271. foreach ( $aiList[$this->OTHER] as $va ) {
  13272. $falg = true;
  13273. foreach ( $receiptCollectList as $v ) {
  13274. if ($v ['itemCategory'] == $this->OTHER) {
  13275. if ($v ['item'] == $va['name']) {
  13276. $psum += $v ['price'];
  13277. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13278. $falg = false;
  13279. break;
  13280. }
  13281. }
  13282. }
  13283. if ($falg)
  13284. $html .= '<td class="taR">-</td>';
  13285. }
  13286. if (! empty ( $psum ))
  13287. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13288. else
  13289. $psum = '<td class="colGreen taR">-</td>';
  13290. $receiptL [$this->OTHER] = $psum . $html;
  13291. /* ------------------------------------- */
  13292. $html = "";
  13293. $psum = 0;
  13294. foreach ( $receiptCollectList as $v ) {
  13295. if ($v ['itemCategory'] == '报销金额调整') {
  13296. if (! empty ( $v ['price'] ))
  13297. $psum += $v ['price'];
  13298. }
  13299. }
  13300. if (! empty ( $psum ))
  13301. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13302. else
  13303. $psum = '<td class="taR colOrange">-</td>';
  13304. $receiptL ['报销金额调整'] = $psum . $html;
  13305. } else {
  13306. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13307. foreach ( $aiList[$this->AGENCY] as $va ) {
  13308. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13309. }
  13310. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13311. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13312. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13313. }
  13314. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13315. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13316. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13317. }
  13318. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13319. foreach ( $aiList[$this->TRAIN] as $va ) {
  13320. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13321. }
  13322. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13323. foreach ( $aiList[$this->OTHER] as $va ) {
  13324. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13325. }
  13326. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13327. }
  13328. $monthStaffPrice = $receiptDetail->find ( array (
  13329. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13330. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13331. 'asArray' => true
  13332. ) );
  13333. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13334. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13335. else
  13336. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13337. $list [$value ['title']] = $receiptL;
  13338. }
  13339. $data ['list'] = $list;
  13340. $receiptCollectList = $receiptDetail->find ( array (
  13341. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13342. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13343. 'groupby' => 'item,Month(pastDate),itemCategory',
  13344. 'asArray' => true
  13345. ) );
  13346. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13347. //print_r($data['monthPriceHtml']);
  13348. // foreach ($data['monthPriceHtml'] as $value){
  13349. // echo $value;
  13350. // }
  13351. // die;
  13352. // statistics html
  13353. $stList = $statistics->getOne ( array (
  13354. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13355. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13356. 'groupby' => 'Month(date)',
  13357. 'asArray' => true
  13358. ) );
  13359. if (empty ( $stList ))
  13360. $stList = array (
  13361. 'rePrice' => 0,
  13362. 'agPrice' => 0
  13363. );
  13364. $data ['stList'] = array (
  13365. 'rePrice' => $stList ['rePrice'],
  13366. 'agPrice' => $stList ['agPrice'],
  13367. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13368. );
  13369. $monthHtml = "";
  13370. for($i = 1; $i <= 12; $i ++) {
  13371. if ($i == $month)
  13372. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13373. else
  13374. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13375. }
  13376. $data ['aiList'] = $aiList;
  13377. $data ['monthHtml'] = $monthHtml;
  13378. $data ['year'] = $year;
  13379. $data ['month'] = $month;
  13380. $data ['memu'] = "receipt";
  13381. $data ['staff'] = $this->staff;
  13382. $data ['receiptMemu'] = 'companyCategoryCollect';
  13383. $data ['verifyId'] = $this->verifyId;
  13384. $data ['executeId'] = $this->executeId;
  13385. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13386. }
  13387. function staffCollectDetail() {
  13388. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13389. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13390. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13391. if (! $staffname) {
  13392. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13393. $staffname = urldecode ( $staffname );
  13394. }
  13395. Doo::loadModel ( 'staff' );
  13396. $staff = new staff ();
  13397. Doo::loadModel ( "receiptDetail" );
  13398. $receiptDetail = new receiptDetail ();
  13399. Doo::loadModel ( 'accountItem' );
  13400. $accountItem = new accountItem ();
  13401. Doo::loadModel ( 'statistics' );
  13402. $statistics = new statistics ();
  13403. Doo::loadModel ( 'L_category' );
  13404. $lCategory = new L_category ();
  13405. Doo::loadModel ( "receiptAuthorityManage" );
  13406. $receiptAuthorityManage = new receiptAuthorityManage ();
  13407. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13408. $cidList = array ();
  13409. foreach ( $imcStaff as $key => $value ) {
  13410. array_push ( $cidList, $value ['cid'] );
  13411. }
  13412. $cidString = implode ( ',', $cidList );
  13413. $staffList = $staff->find ( array (
  13414. 'where' => ' cid in (' . $cidString . ')',
  13415. 'asArray' => true
  13416. ) );
  13417. $stHtml = '';
  13418. $stTitle = "";
  13419. $staffId = 0;
  13420. $cid = 0;
  13421. $ocid = 0;
  13422. foreach ( $staffList as $value ) {
  13423. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13424. $stTitle = $value ['category'] . '-' . $value ['username'];
  13425. $staffId = $value ['sid'];
  13426. $cid = $value ['cid'];
  13427. $ocid = $value ['cid'];
  13428. if (! empty ( $value ['othercid'] ))
  13429. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13430. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13431. } elseif ($value ['username'] != 'admin')
  13432. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13433. }
  13434. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13435. 'where' => 'cid in(' . $cid . ')',
  13436. 'asArray' => true
  13437. ) );
  13438. if (empty ( $pcid ))
  13439. $pcid = $ocid;
  13440. $data ['ocid'] = $pcid;
  13441. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13442. $this->showCache ( $path );
  13443. //
  13444. $receiptCollectList = $receiptDetail->find ( array (
  13445. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13446. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13447. 'groupby' => 'item,Month(pastDate),itemCategory',
  13448. 'asArray' => true
  13449. ) );
  13450. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13451. // print_r($receiptCollectList);
  13452. $accountList = $accountItem->find ( array (
  13453. 'asArray' => true
  13454. ) );
  13455. // create CollectDetail HTML
  13456. $collectHtml = array ();
  13457. foreach ( $accountList as $key => $value ) {
  13458. $html = "";
  13459. $asum = 0;
  13460. for($i = 1; $i <= 12; $i ++) {
  13461. $falg = true;
  13462. foreach ( $receiptCollectList as $v ) {
  13463. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13464. if ($v ['item'] == '可自加费用') {
  13465. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13466. }
  13467. $asum += $v ['price'];
  13468. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13469. $falg = false;
  13470. break;
  13471. }
  13472. }
  13473. if ($falg)
  13474. $html .= '<td class="taR">-</td>';
  13475. }
  13476. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13477. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13478. }
  13479. $data ['collectHtml'] = $collectHtml;
  13480. // print_r($collectHtml);
  13481. // create Adjustment price html
  13482. $receiptCollectList = $receiptDetail->find ( array (
  13483. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13484. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13485. 'groupby' => 'itemCategory,Month(pastDate)',
  13486. 'asArray' => true
  13487. ) );
  13488. $adjustment = array ();
  13489. $collectArray = array (
  13490. '日常相关费用' => array (),
  13491. '差旅相关费用' => array (),
  13492. '培训班费用' => array (),
  13493. '内部培训费用'=>array(),
  13494. '其他' => array ()
  13495. );
  13496. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13497. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13498. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13499. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13500. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13501. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13502. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13503. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13504. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13505. array_push ( $collectArray ['其他'], $collectHtml );
  13506. $data ['collectArray'] = $collectArray;
  13507. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13508. array_push ( $adjustment, $collectHtml );
  13509. $data ['adjustment'] = $adjustment;
  13510. // total price html
  13511. $collectHtml = "";
  13512. $total = 0;
  13513. for($i = 1; $i <= 12; $i ++) {
  13514. $sumPrice = 0;
  13515. foreach ( $receiptCollectList as $key => $value ) {
  13516. if ($value ['month'] == $i) {
  13517. $sumPrice += $value ['price'];
  13518. }
  13519. }
  13520. if ($sumPrice == 0)
  13521. $collectHtml .= '<td class="taR">-</td>';
  13522. else
  13523. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13524. $total += $sumPrice;
  13525. }
  13526. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13527. // statistics html
  13528. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13529. if (empty ( $stList ))
  13530. $stList = array (
  13531. 'rePrice' => 0,
  13532. 'agPrice' => 0
  13533. );
  13534. $data ['stList'] = array (
  13535. 'rePrice' => $stList ['rePrice'],
  13536. 'agPrice' => $stList ['agPrice'],
  13537. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13538. );
  13539. $data ['totalPrice'] = $collectHtml;
  13540. $data ['totalYear'] = $total;
  13541. $data ['stHtml'] = $stHtml;
  13542. $data ['year'] = $year;
  13543. $data ['stTitle'] = $stTitle;
  13544. $data ['staffname'] = urlencode ( $staffname );
  13545. $data ['memu'] = "receipt";
  13546. $data ['staff'] = $this->staff;
  13547. $data ['receiptMemu'] = 'companyCategoryCollect';
  13548. $data ['verifyId'] = $this->verifyId;
  13549. $data ['executeId'] = $this->executeId;
  13550. if ($year < date ( "Y" )) {
  13551. Doo::loadModel ( 'receipt' );
  13552. $receipt = new receipt ();
  13553. $receiptList = $receipt->find ( array (
  13554. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  13555. 'asArray' => true
  13556. ) );
  13557. if (empty ( $receiptList )) { // generated files
  13558. ob_start ();
  13559. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13560. $this->cacheFile ( $path );
  13561. die ();
  13562. }
  13563. }
  13564. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13565. }
  13566. function BUGFLAG() {
  13567. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  13568. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  13569. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13570. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  13571. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  13572. if (empty ( $status ))
  13573. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  13574. $page_size = 12;
  13575. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  13576. $vidList = array ();
  13577. $button = 0;
  13578. Doo::loadModel ( 'verify' );
  13579. $verify = new verify ();
  13580. Doo::loadModel ( 'receipt' );
  13581. $receipt = new receipt ();
  13582. Doo::loadModel ( 'staff' );
  13583. $staff = new staff ();
  13584. Doo::loadModel ( 'L_category' );
  13585. $Lcategory = new L_category ();
  13586. $dateCondition = " and Year(date) =" . $year;
  13587. if (! empty ( $month ))
  13588. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  13589. $categoryList = $Lcategory->find ( array (
  13590. 'asArray' => true
  13591. ) );
  13592. $staffList = $staff->find ( array (
  13593. 'where' => 'cid=' . $cid,
  13594. 'asArray' => true
  13595. ) );
  13596. $cateCondition = "";
  13597. $staffCondition = "";
  13598. $approvalCondition = "";
  13599. if (! empty ( $cid ))
  13600. $cateCondition = ' and cid=' . $cid;
  13601. if (! empty ( $sid )) {
  13602. $staffCondition = ' and staff=' . $sid;
  13603. $cateCondition = "";
  13604. }
  13605. $approvalCondition = " and status=" . $status;
  13606. if ($status == 2) {
  13607. // 查找角色审批人
  13608. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  13609. }
  13610. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  13611. $approvalCondition = ' and status=2 ';
  13612. }
  13613. if ($status == 1) {
  13614. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  13615. }
  13616. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  13617. $pageinfo ['page'] = array (
  13618. 'previous' => ''
  13619. );
  13620. if ($status == 0) {
  13621. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  13622. $receiptList = $receipt->find ( array (
  13623. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  13624. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  13625. 'desc' => 'rid',
  13626. 'asArray' => true
  13627. ) );
  13628. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13629. } else
  13630. $receiptList = $receipt->find ( array (
  13631. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  13632. 'desc' => 'rid',
  13633. 'asArray' => true
  13634. ) );
  13635. $rLRes = $receipt->find ( array (
  13636. '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,
  13637. 'desc' => 'rid',
  13638. 'asArray' => true
  13639. ) );
  13640. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  13641. // print_r($pageinfo);
  13642. $Locate = 0;
  13643. foreach ( $receiptList as $key => $value ) {
  13644. $receiptList [$key] ['Locate'] = $Locate;
  13645. $Locate ++;
  13646. $receiptList [$key] ['reviseDetail'] = array ();
  13647. if (! empty ( $value ['reviseDetail'] ))
  13648. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  13649. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  13650. $categoryDetil = $Lcategory->getOne ( array (
  13651. 'where' => 'cid=' . $value ['cid'],
  13652. 'asArray' => true
  13653. ) );
  13654. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  13655. $verifyList = $verify->getOne ( array (
  13656. 'where' => 'vid=' . $value ['verify'],
  13657. 'asArray' => true
  13658. ) );
  13659. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  13660. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  13661. foreach ( $verifyList as $k => $v ) {
  13662. // init verifyStaff
  13663. $verifyList [$k] ['date'] = "";
  13664. $verifyList [$k] ['opinion'] = "";
  13665. $verifyList [$k] ['status'] = "";
  13666. if (empty ( $verifyStaff )) {
  13667. $verifyList [$k] ['date'] = "";
  13668. $verifyList [$k] ['opinion'] = "";
  13669. if ($v [0] == $this->staff [0] ['sid']) {
  13670. $verifyList [$k] ['status'] = 4;
  13671. $button = 4;
  13672. }
  13673. } else {
  13674. $flag = true;
  13675. foreach ( $verifyStaff as $m => $u ) {
  13676. if ($v [0] == $m) {
  13677. $verifyList [$k] ['date'] = $u ['date'];
  13678. $verifyList [$k] ['opinion'] = $u ['opinion'];
  13679. $verifyList [$k] ['status'] = $u ['status'];
  13680. $flag = false;
  13681. break;
  13682. }
  13683. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  13684. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  13685. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  13686. }
  13687. if ($flag) { // 检测可编辑
  13688. if ($v [0] == $this->staff [0] ['sid']) {
  13689. $verifyList [$k] ['status'] = 4;
  13690. $button = 4;
  13691. }
  13692. }
  13693. }
  13694. }
  13695. $receiptList [$key] ['verifyList'] = $verifyList;
  13696. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  13697. 'where' => 'sid=' . $value ['staff'],
  13698. 'asArray' => true
  13699. ) );
  13700. $receiptList [$key] ['button'] = $button;
  13701. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  13702. }
  13703. // print_r($receiptList);die;
  13704. // $data['verifyDetail']=$verifyDetail;
  13705. $mothHtml = "";
  13706. for($i = 1; $i <= 12; $i ++) {
  13707. if ($month == $i)
  13708. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  13709. else
  13710. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  13711. }
  13712. $data ['mothHtml'] = $mothHtml;
  13713. $data ['page'] = $pageinfo;
  13714. $data ['receiptList'] = $receiptList;
  13715. $data ['receiptApprovalCount'] = count ( $rLRes );
  13716. $data ['status'] = $status;
  13717. $data ['year'] = $year;
  13718. $data ['categoryList'] = $categoryList;
  13719. $data ['staffList'] = $staffList;
  13720. $data ['cid'] = $cid;
  13721. $data ['sid'] = $sid;
  13722. // print_r($receiptList);
  13723. $data ['memu'] = "receipt";
  13724. $data ['staff'] = $this->staff;
  13725. $data ['receiptMemu'] = 'approvalExpenses';
  13726. $data ['verifyId'] = $this->verifyId;
  13727. $data ['executeId'] = $this->executeId;
  13728. $this->render ( "/admin/FALG", $data );
  13729. }
  13730. function ajaxGetReceiptOrder() {
  13731. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  13732. if (! empty ( $receiptOrder )) {
  13733. Doo::loadModel ( 'receipt' );
  13734. $receipt = new receipt ();
  13735. Doo::loadModel ( 'staff' );
  13736. $staff = new staff ();
  13737. $receiptInfo = $receipt->getOne ( array (
  13738. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  13739. 'asArray' => true
  13740. ) );
  13741. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  13742. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  13743. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  13744. </tbody></table><table class="table table table-bordered"><tbody>';
  13745. foreach ( $verifyStaff as $key => $value ) {
  13746. $staffInfo = $staff->getOne ( array (
  13747. 'select' => 'username',
  13748. 'where' => ' sid="' . $key . '"',
  13749. 'asArray' => true
  13750. ) );
  13751. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  13752. }
  13753. $html .= '</tbody></table></div></div>';
  13754. echo json_encode ( array (
  13755. 'status' => 1,
  13756. 'receiptHtml' => $html
  13757. ) );
  13758. die ();
  13759. }
  13760. echo json_encode ( array (
  13761. 'status' => 2,
  13762. 'receiptHtml' => ''
  13763. ) );
  13764. die ();
  13765. }
  13766. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  13767. if (! empty ( $receiptCollectList )) {
  13768. $receiptL = array (
  13769. '日常相关费用' => array (),
  13770. '差旅相关费用' => array (),
  13771. '内部培训费用'=>array(),
  13772. '培训班费用' => array (),
  13773. '其他' => array ()
  13774. );
  13775. $html = "";
  13776. $psum = 0;
  13777. foreach ( $aiList[$this->AGENCY] as $value ) {
  13778. $falg = true;
  13779. foreach ( $receiptCollectList as $v ) {
  13780. if ($v ['itemCategory'] == '日常相关费用') {
  13781. if ($v ['item'] == $value['name']) {
  13782. $psum += $v ['price'];
  13783. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13784. $falg = false;
  13785. break;
  13786. }
  13787. }
  13788. }
  13789. if ($falg)
  13790. $html .= '<td class="taR">-</td>';
  13791. }
  13792. if (! empty ( $psum ))
  13793. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13794. else
  13795. $psum = '<td class="colGreen taR">-</td>';
  13796. $receiptL ['日常相关费用'] = $psum . $html;
  13797. /* ----------------------------------- */
  13798. $html = "";
  13799. $psum = 0;
  13800. foreach ( $aiList[$this->TRAVEL] as $value ) {
  13801. $falg = true;
  13802. foreach ( $receiptCollectList as $v ) {
  13803. if ($v ['itemCategory'] == '差旅相关费用') {
  13804. if ($v ['item'] == $value['name']) {
  13805. $psum += $v ['price'];
  13806. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13807. $falg = false;
  13808. break;
  13809. }
  13810. }
  13811. }
  13812. if ($falg)
  13813. $html .= '<td class="taR">-</td>';
  13814. }
  13815. if (! empty ( $psum ))
  13816. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13817. else
  13818. $psum = '<td class="colGreen taR">-</td>';
  13819. $receiptL ['差旅相关费用'] = $psum . $html;
  13820. /* ----------------------------------- */
  13821. $html = "";
  13822. $psum = 0;
  13823. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  13824. $falg = true;
  13825. foreach ( $receiptCollectList as $v ) {
  13826. if ($v ['itemCategory'] == '内部培训费用') {
  13827. if ($v ['item'] == $value['name']) {
  13828. $psum += $v ['price'];
  13829. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13830. $falg = false;
  13831. break;
  13832. }
  13833. }
  13834. }
  13835. if ($falg)
  13836. $html .= '<td class="taR">-</td>';
  13837. }
  13838. if (! empty ( $psum ))
  13839. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13840. else
  13841. $psum = '<td class="colGreen taR">-</td>';
  13842. $receiptL ['内部培训费用'] = $psum . $html;
  13843. /* ------------------------------------- */
  13844. $html = "";
  13845. $psum = 0;
  13846. foreach ( $aiList[$this->TRAIN] as $value ) {
  13847. $falg = true;
  13848. foreach ( $receiptCollectList as $v ) {
  13849. if ($v ['itemCategory'] == '培训班费用') {
  13850. if ($v ['item'] == $value['name']) {
  13851. $psum += $v ['price'];
  13852. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13853. $falg = false;
  13854. break;
  13855. }
  13856. }
  13857. }
  13858. if ($falg)
  13859. $html .= '<td class="taR">-</td>';
  13860. }
  13861. if (! empty ( $psum ))
  13862. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13863. else
  13864. $psum = '<td class="colGreen taR">-</td>';
  13865. $receiptL ['培训班费用'] = $psum . $html;
  13866. /* ------------------------------------- */
  13867. $html = "";
  13868. $psum = 0;
  13869. foreach ( $aiList[$this->OTHER] as $value ) {
  13870. $falg = true;
  13871. foreach ( $receiptCollectList as $v ) {
  13872. if ($v ['itemCategory'] == '其他') {
  13873. if ($v ['item'] == $value['name']) {
  13874. $psum += $v ['price'];
  13875. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13876. $falg = false;
  13877. break;
  13878. }
  13879. }
  13880. }
  13881. if ($falg)
  13882. $html .= '<td class="taR">-</td>';
  13883. }
  13884. if (! empty ( $psum ))
  13885. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13886. else
  13887. $psum = '<td class="colGreen taR">-</td>';
  13888. $receiptL ['其他'] = $psum . $html;
  13889. /* ------------------------------------- */
  13890. $html = "";
  13891. $psum = 0;
  13892. foreach ( $receiptCollectList as $v ) {
  13893. if ($v ['itemCategory'] == '报销金额调整') {
  13894. if (! empty ( $v ['price'] ))
  13895. $psum += $v ['price'];
  13896. }
  13897. }
  13898. if (! empty ( $psum ))
  13899. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13900. else
  13901. $psum = '<td class="taR colOrange">-</td>';
  13902. $receiptL ['报销金额调整'] = $psum . $html;
  13903. } else {
  13904. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13905. foreach ( $aiList[$this->AGENCY] as $va ) {
  13906. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13907. }
  13908. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13909. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13910. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13911. }
  13912. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13913. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13914. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13915. }
  13916. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13917. foreach ( $aiList[$this->TRAIN] as $va ) {
  13918. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13919. }
  13920. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13921. foreach ( $aiList[$this->OTHER] as $va ) {
  13922. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13923. }
  13924. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13925. }
  13926. return $receiptL;
  13927. }
  13928. function eMail() {
  13929. Doo::loadModel ( 'staff' );
  13930. $staff = new staff ();
  13931. Doo::loadModel ( 'receipt' );
  13932. $receipt = new receipt ();
  13933. Doo::loadModel ( 'L_category' );
  13934. $Lcategory = new L_category ();
  13935. Doo::loadModel ( "verify" );
  13936. $verify = new verify ();
  13937. $staffList = $staff->find ( array (
  13938. 'asArray' => true
  13939. ) );
  13940. foreach ( $staffList as $key => $value ) {
  13941. if ($value ['username'] != 'admin') {
  13942. // 提交人
  13943. $receiptList = $receipt->find ( array (
  13944. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  13945. 'asArray' => true
  13946. ) );
  13947. if (! empty ( $receiptList )) {
  13948. $html = '<br><div><style></style>
  13949. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  13950. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  13951. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  13952. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  13953. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  13954. <tbody><tr>
  13955. <td style="padding: 0 40px;" align="left">
  13956. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  13957. </td></tr><tr>
  13958. <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>
  13959. </tr>
  13960. </tbody> </table></td> </tr> <tr><td>
  13961. <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">
  13962. <tbody> <tr><td>
  13963. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  13964. 以下报销单完成了审批,等着收款吧:</p>
  13965. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  13966. foreach ( $receiptList as $k => $v ) {
  13967. $category = $Lcategory->getOne ( array (
  13968. 'where' => 'cid=' . $v ['cid'],
  13969. 'asArray' => true
  13970. ) );
  13971. $html .= '
  13972. <tr>
  13973. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  13974. <td align="left">
  13975. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  13976. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  13977. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  13978. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  13979. </tr>';
  13980. }
  13981. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  13982. <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>
  13983. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  13984. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  13985. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  13986. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13987. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  13988. $receipt = new receipt ();
  13989. $receipt->notice = 1;
  13990. $receipt->update ( array (
  13991. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  13992. ) );
  13993. }
  13994. }
  13995. // 审批人
  13996. $verifyList = $verify->find ( array (
  13997. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  13998. 'asArray' => true
  13999. ) );
  14000. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14001. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14002. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14003. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14004. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14005. <tbody><tr><td style="padding: 0 40px;" align="left">
  14006. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14007. </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>
  14008. </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">
  14009. <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>
  14010. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14011. foreach ( $verifyList as $k => $v ) {
  14012. $receiptList = $receipt->find ( array (
  14013. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14014. 'asArray' => true
  14015. ) );
  14016. foreach ( $receiptList as $r => $l ) {
  14017. $category = $Lcategory->getOne ( array (
  14018. 'where' => 'cid=' . $l ['cid'],
  14019. 'asArray' => true
  14020. ) );
  14021. $staffDetile = $staff->getOne ( array (
  14022. 'where' => 'sid=' . $l ['staff'],
  14023. 'asArray' => true
  14024. ) );
  14025. $html .= '
  14026. <tr>
  14027. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14028. <td align="left">
  14029. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14030. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14031. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14032. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14033. </tr>';
  14034. }
  14035. }
  14036. $html .= '
  14037. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14038. <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>
  14039. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14040. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14041. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14042. // $receipt=new receipt();
  14043. // $receipt->notice=1;
  14044. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14045. }
  14046. }
  14047. }
  14048. }
  14049. function setWXMsg($rid, $type) {
  14050. Doo::loadModel ( "receipt" );
  14051. $receipt = new receipt ();
  14052. $receiptDetail = $receipt->getOne ( array (
  14053. 'where' => 'rid=' . $rid,
  14054. 'asArray' => true
  14055. ) );
  14056. if (! empty ( $receiptDetail )) {
  14057. Doo::loadModel ( 'staff' );
  14058. $staff = new staff ();
  14059. $staffmsg = $staff->getOne ( array (
  14060. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14061. 'asArray' => TRUE
  14062. ) );
  14063. if (! empty ( $staffmsg ['wxid'] )) {
  14064. require_once (SITE_PATH . '/protected/class/client.php');
  14065. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14066. $user = $staffmsg ['wxid'];
  14067. $receiptName = '';
  14068. $msg = '';
  14069. switch ($receiptDetail ['Rtype']) {
  14070. case 0 :
  14071. $receiptName = '报销';
  14072. break;
  14073. case 1 :
  14074. $receiptName = '借款';
  14075. break;
  14076. case 2 :
  14077. $receiptName = '对公汇款';
  14078. break;
  14079. }
  14080. switch ($type) {
  14081. case 1 :
  14082. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14083. break;
  14084. case 2 :
  14085. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14086. break;
  14087. case 3 :
  14088. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14089. break;
  14090. }
  14091. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14092. }
  14093. }
  14094. }
  14095. // Email发送函数
  14096. function SMail($toemail, $subject, $contents) {
  14097. Doo::loadClass ( 'class.phpmailer' );
  14098. $mail = new PHPMailer ();
  14099. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14100. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14101. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14102. $mail->Password = "cDO1GjtY1seH"; // 密码
  14103. $mail->CharSet = "UTF8";
  14104. $mail->SMTPAuth = true;
  14105. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14106. $mail->Mailer = "smtp";
  14107. $mail->Port = 25;
  14108. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14109. $mail->MsgHTML ( $contents );
  14110. $mail->AddAddress ( $toemail );
  14111. $mail->CharSet = "UTF-8";
  14112. return $mail->Send ();
  14113. }
  14114. function h5Upload() {
  14115. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14116. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14117. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14118. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14119. header ( "HTTP/1.1 500 Internal Server Error" );
  14120. echo "POST exceeded maximum allowed size.";
  14121. exit ( 0 );
  14122. }
  14123. // Settings
  14124. $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)
  14125. $upload_name = "Filedata";
  14126. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14127. $extension_whitelist = array (
  14128. "doc",
  14129. "txt",
  14130. "jpg",
  14131. "gif",
  14132. "png"
  14133. ); // Allowed file extensions
  14134. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14135. // Other variables
  14136. $MAX_FILENAME_LENGTH = 260;
  14137. $file_name = "";
  14138. $file_extension = "";
  14139. $uploadErrors = array (
  14140. 0 => "文件上传成功",
  14141. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14142. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14143. 3 => "上传的文件仅为部分文件",
  14144. 4 => "没有文件上传",
  14145. 6 => "缺少临时文件夹"
  14146. );
  14147. $nk = time ();
  14148. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14149. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14150. echo "文件无法保存.";
  14151. exit ( 0 );
  14152. }
  14153. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14154. echo json_encode ( array (
  14155. 'filename' => $file_name,
  14156. 'id' => $nk
  14157. ) );
  14158. exit ( 0 );
  14159. }
  14160. function swfupload() {
  14161. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14162. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14163. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14164. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14165. header ( "HTTP/1.1 500 Internal Server Error" );
  14166. echo "POST exceeded maximum allowed size.";
  14167. exit ( 0 );
  14168. }
  14169. // Settings
  14170. $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)
  14171. $upload_name = "Filedata";
  14172. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14173. $extension_whitelist = array (
  14174. "doc",
  14175. "txt",
  14176. "jpg",
  14177. "gif",
  14178. "png"
  14179. ); // Allowed file extensions
  14180. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14181. // Other variables
  14182. $MAX_FILENAME_LENGTH = 260;
  14183. $file_name = "";
  14184. $file_extension = "";
  14185. $uploadErrors = array (
  14186. 0 => "文件上传成功",
  14187. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14188. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14189. 3 => "上传的文件仅为部分文件",
  14190. 4 => "没有文件上传",
  14191. 6 => "缺少临时文件夹"
  14192. );
  14193. $nk = time ();
  14194. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14195. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14196. echo "文件无法保存.";
  14197. exit ( 0 );
  14198. }
  14199. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14200. echo json_encode ( array (
  14201. 'filename' => $file_name,
  14202. 'id' => $nk
  14203. ) );
  14204. exit ( 0 );
  14205. }
  14206. function _GetFileEXT($filename) {
  14207. $pics = explode ( '.', $filename );
  14208. $num = count ( $pics );
  14209. return $pics [$num - 1];
  14210. }
  14211. /**
  14212. * 获取get或者POST值
  14213. * @param string $name 属性名称
  14214. * @return fixed 值
  14215. */
  14216. function get_args($name) {
  14217. if (isset ( $_GET [$name] )) {
  14218. if (is_array ( $_GET [$name] ))
  14219. return $_GET [$name];
  14220. else
  14221. return addslashes ( $_GET [$name] );
  14222. } elseif (isset ( $_POST [$name] )) {
  14223. if (is_array ( $_POST [$name] ))
  14224. return $_POST [$name];
  14225. else
  14226. return addslashes ( $_POST [$name] );
  14227. } else
  14228. return false;
  14229. }
  14230. function num_to_rmb($num) {
  14231. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14232. $c2 = "分角元拾佰仟万拾佰仟亿";
  14233. // 精确到分后面就不要了,所以只留两个小数位
  14234. $num = round ( $num, 2 );
  14235. // 将数字转化为整数
  14236. $num = $num * 100;
  14237. if (strlen ( $num ) > 10) {
  14238. return "金额太大,请检查";
  14239. }
  14240. $i = 0;
  14241. $c = "";
  14242. while ( 1 ) {
  14243. if ($i == 0) {
  14244. // 获取最后一位数字
  14245. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14246. } else {
  14247. $n = $num % 10;
  14248. }
  14249. // 每次将最后一位数字转化为中文
  14250. $p1 = substr ( $c1, 3 * $n, 3 );
  14251. $p2 = substr ( $c2, 3 * $i, 3 );
  14252. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14253. $c = $p1 . $p2 . $c;
  14254. } else {
  14255. $c = $p1 . $c;
  14256. }
  14257. $i = $i + 1;
  14258. // 去掉数字最后一位了
  14259. $num = $num / 10;
  14260. // echo $num.'</br>';
  14261. $num = ( int ) $num;
  14262. // $num =floor($num);
  14263. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14264. // echo $num.'</br>';
  14265. // 结束循环
  14266. if ($num == 0) {
  14267. break;
  14268. }
  14269. }
  14270. // echo $c.'</br>';
  14271. $j = 0;
  14272. $slen = strlen ( $c );
  14273. while ( $j < $slen ) {
  14274. // utf8一个汉字相当3个字符
  14275. $m = substr ( $c, $j, 6 );
  14276. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14277. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14278. $left = substr ( $c, 0, $j );
  14279. $right = substr ( $c, $j + 3 );
  14280. $c = $left . $right;
  14281. $j = $j - 3;
  14282. $slen = $slen - 3;
  14283. }
  14284. $j = $j + 3;
  14285. }
  14286. // 这个是为了去掉类似23.0中最后一个“零”字
  14287. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14288. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14289. }
  14290. // 将处理的汉字加上“整”
  14291. if (empty ( $c )) {
  14292. return "零元整";
  14293. } else {
  14294. return $c . "整";
  14295. }
  14296. }
  14297. /**
  14298. * 获得分页数据
  14299. * @param unknown_type $table
  14300. * @param unknown_type $condition
  14301. * @param unknown_type $on_page
  14302. * @param unknown_type $page_size
  14303. */
  14304. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14305. $page_c = "";
  14306. $page ['previous'] = $this->get_previous ( $on_page );
  14307. $page ['on_page'] = $on_page;
  14308. $total_count = $this->get_table_count ( $table, $condition );
  14309. $total = intval ( $total_count / $page_size );
  14310. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14311. $page ['total_data'] = $total_count;
  14312. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14313. $i = 1;
  14314. $page_max = 1;
  14315. $page_width = 3;
  14316. if ($on_page >= $page_width) {
  14317. $page_max = intval ( $on_page / $page_width ) + 1;
  14318. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14319. }
  14320. for(; $i <= $page ['total_page']; $i ++) {
  14321. if ($i == $on_page)
  14322. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14323. else
  14324. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14325. if ($i == ($page_width * $page_max))
  14326. break;
  14327. }
  14328. $page ['page'] = $page_c;
  14329. $page ['lower'] = (-- $on_page) * $page_size;
  14330. return $page;
  14331. }
  14332. /**
  14333. * 获取总页数
  14334. * @param unknown_type $table
  14335. * @param unknown_type $condition
  14336. */
  14337. public function get_table_count($table = "", $condition = "") {
  14338. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14339. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14340. // echo $sql;die;
  14341. $query = Doo::db ()->query ( $sql );
  14342. $result = $query->fetch ();
  14343. return $result ['count'];
  14344. }
  14345. /**
  14346. * 获取上一页
  14347. * @param unknown_type $on_page
  14348. */
  14349. function get_previous($on_page = 1) {
  14350. return $on_page != 0 ? $on_page - 1 : $on_page;
  14351. }
  14352. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14353. // 收入合计
  14354. Doo::loadModel ( 'invoiceTraining' );
  14355. $invoiceTraining = new invoiceTraining ();
  14356. Doo::loadModel ( 'receipt' );
  14357. $receipt = new receipt ();
  14358. $invoiceTrainingDetail = array (
  14359. 'invoiceArriveAmount' => '0.00',
  14360. 'RIAmount' => '0.00',
  14361. 'invoiceTotalAmount' => '0.00',
  14362. 'invoiceCompanyAmount' => '0.00',
  14363. 'invoiceArriveAmountM'=>'0.00',
  14364. 'invoiceCompanyAmountM'=>'0.00'
  14365. );
  14366. if ($invoiceTrainId != 0) {
  14367. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14368. }
  14369. $invoiceArriveAmount = $RIAmount = 0;
  14370. if (! empty ( $invoiceTrainingDetail )) {
  14371. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14372. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14373. }
  14374. // 备用金
  14375. $sum = 0;
  14376. if (! empty ( $value ['trainLoanRid'] )) {
  14377. $receiptLoanDetailBak = $receipt->getReceiptByRid ( trainLoanRid );
  14378. $sum = $receiptLoanDetailBak ['sum'];
  14379. }
  14380. // 支出项金额详情
  14381. // 项目金额合计
  14382. Doo::loadModel ( 'RItem' );
  14383. $RItem = new RItem ();
  14384. Doo::loadModel ( 'accountItem' );
  14385. $accountItem = new accountItem ();
  14386. // 讲师获得
  14387. Doo::loadModel ( 'RILecturer' );
  14388. $RILecturer = new RILecturer ();
  14389. $RItemList = $RItem->getRItemByRid ($rid );
  14390. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14391. // 支出项金额详情
  14392. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14393. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14394. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14395. return $payment;
  14396. }
  14397. }
  14398. ?>